From 4280822ecf3828a1488f2e3d967b91cafa3995c0 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Tue, 21 Jan 2020 10:17:38 +0100 Subject: [PATCH] switch to json crypto definitions (#246) --- build.ps1 | 1 + build.sh | 1 + .../crypto-definitions.json | 86 +++++++++++++ .../src/CryptoDefinition.cs | 120 ++---------------- docker-compose-generator/src/Program.cs | 14 +- 5 files changed, 107 insertions(+), 115 deletions(-) create mode 100644 docker-compose-generator/crypto-definitions.json diff --git a/build.ps1 b/build.ps1 index 2e72e99..ba81a28 100755 --- a/build.ps1 +++ b/build.ps1 @@ -10,6 +10,7 @@ If ($BTCPAYGEN_DOCKER_IMAGE -eq "btcpayserver/docker-compose-generator:local"){ docker run -v "$(Get-Location)\Generated:/app/Generated" ` -v "$(Get-Location)\docker-compose-generator\docker-fragments:/app/docker-fragments" ` + -v "$(Get-Location)\docker-compose-generator\crypto-definitions.json:/app/crypto-definitions.json" ` -e "BTCPAYGEN_CRYPTO1=$BTCPAYGEN_CRYPTO1" ` -e "BTCPAYGEN_CRYPTO2=$BTCPAYGEN_CRYPTO2" ` -e "BTCPAYGEN_CRYPTO3=$BTCPAYGEN_CRYPTO3" ` diff --git a/build.sh b/build.sh index 9879e4e..75fa9a5 100755 --- a/build.sh +++ b/build.sh @@ -16,6 +16,7 @@ fi # This script will run docker-compose-generator in a container to generate the yml files docker run -v "$(pwd)/Generated:/app/Generated" \ -v "$(pwd)/docker-compose-generator/docker-fragments:/app/docker-fragments" \ + -v "$(pwd)/docker-compose-generator/crypto-definitions.json:/app/crypto-definitions.json" \ -e "BTCPAYGEN_CRYPTO1=$BTCPAYGEN_CRYPTO1" \ -e "BTCPAYGEN_CRYPTO2=$BTCPAYGEN_CRYPTO2" \ -e "BTCPAYGEN_CRYPTO3=$BTCPAYGEN_CRYPTO3" \ diff --git a/docker-compose-generator/crypto-definitions.json b/docker-compose-generator/crypto-definitions.json new file mode 100644 index 0000000..a863c71 --- /dev/null +++ b/docker-compose-generator/crypto-definitions.json @@ -0,0 +1,86 @@ +[ + { + "Crypto": "ltc", + "CryptoFragment": "litecoin", + "CLightningFragment": "litecoin-clightning", + "LNDFragment": "litecoin-lnd", + "EclairFragment": null + }, + { + "Crypto": "btc", + "CryptoFragment": "bitcoin", + "CLightningFragment": "bitcoin-clightning", + "LNDFragment": "bitcoin-lnd", + "EclairFragment": "bitcoin-eclair" + }, + { + "Crypto": "btx", + "CryptoFragment": "bitcore", + "CLightningFragment": null, + "LNDFragment": null, + "EclairFragment": null + }, + { + "Crypto": "btg", + "CryptoFragment": "bgold", + "CLightningFragment": null, + "LNDFragment": "bgold-lnd", + "EclairFragment": null + }, + { + "Crypto": "ftc", + "CryptoFragment": "feathercoin", + "CLightningFragment": null, + "LNDFragment": null, + "EclairFragment": null + }, + { + "Crypto": "grs", + "CryptoFragment": "groestlcoin", + "CLightningFragment": "groestlcoin-clightning", + "LNDFragment": null, + "EclairFragment": null + }, + { + "Crypto": "via", + "CryptoFragment": "viacoin", + "CLightningFragment": null, + "LNDFragment": null, + "EclairFragment": null + }, + { + "Crypto": "dash", + "CryptoFragment": "dash", + "CLightningFragment": null, + "LNDFragment": null, + "EclairFragment": null + }, + { + "Crypto": "doge", + "CryptoFragment": "dogecoin", + "CLightningFragment": null, + "LNDFragment": null, + "EclairFragment": null + }, + { + "Crypto": "mona", + "CryptoFragment": "monacoin", + "CLightningFragment": null, + "LNDFragment": null, + "EclairFragment": null + }, + { + "Crypto": "xmr", + "CryptoFragment": "monero", + "CLightningFragment": null, + "LNDFragment": null, + "EclairFragment": null + }, + { + "Crypto": "lbtc", + "CryptoFragment": "liquid", + "CLightningFragment": null, + "LNDFragment": null, + "EclairFragment": null + } +] \ No newline at end of file diff --git a/docker-compose-generator/src/CryptoDefinition.cs b/docker-compose-generator/src/CryptoDefinition.cs index baf8f32..f4d1ae4 100644 --- a/docker-compose-generator/src/CryptoDefinition.cs +++ b/docker-compose-generator/src/CryptoDefinition.cs @@ -1,111 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace DockerGenerator +namespace DockerGenerator { - public class CryptoDefinition - { - public string Crypto - { - get; - private set; - } - public string CryptoFragment - { - get; - private set; - } - public string CLightningFragment - { - get; - private set; - } - public string LNDFragment - { - get; - private set; - } - - public string EclairFragment - { - get; - private set; - } - - public static CryptoDefinition[] GetDefinitions() - { - return new[] - { - new CryptoDefinition() - { - Crypto = "ltc", - CryptoFragment = "litecoin", - CLightningFragment = "litecoin-clightning", - LNDFragment = "litecoin-lnd" - }, - new CryptoDefinition() - { - Crypto = "btc", - CryptoFragment = "bitcoin", - CLightningFragment = "bitcoin-clightning", - LNDFragment = "bitcoin-lnd", - EclairFragment = "bitcoin-eclair" - }, - new CryptoDefinition() - { - Crypto = "btx", - CryptoFragment = "bitcore", - }, - new CryptoDefinition() - { - Crypto = "btg", - CryptoFragment = "bgold", - LNDFragment = "bgold-lnd" - }, - new CryptoDefinition() - { - Crypto = "ftc", - CryptoFragment = "feathercoin" - }, - new CryptoDefinition() - { - Crypto = "grs", - CryptoFragment = "groestlcoin", - CLightningFragment = "groestlcoin-clightning", - LNDFragment = "groestlcoin-lnd" - }, - new CryptoDefinition() - { - Crypto = "via", - CryptoFragment = "viacoin" - }, - new CryptoDefinition() - { - Crypto = "dash", - CryptoFragment = "dash" - }, - new CryptoDefinition() - { - Crypto = "doge", - CryptoFragment = "dogecoin" - }, - new CryptoDefinition() - { - Crypto = "mona", - CryptoFragment = "monacoin" - }, - new CryptoDefinition() - { - Crypto = "xmr", - CryptoFragment = "monero" - }, - new CryptoDefinition() - { - Crypto = "lbtc", - CryptoFragment = "liquid" - } - }; - } - } -} + public class CryptoDefinition + { + public string Crypto { get; set; } + public string CryptoFragment { get; set; } + public string CLightningFragment { get; set; } + public string LNDFragment { get; set; } + public string EclairFragment { get; set; } + } +} \ No newline at end of file diff --git a/docker-compose-generator/src/Program.cs b/docker-compose-generator/src/Program.cs index e46e651..e44baec 100644 --- a/docker-compose-generator/src/Program.cs +++ b/docker-compose-generator/src/Program.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.Json; using YamlDotNet.Serialization; namespace DockerGenerator @@ -35,10 +36,12 @@ namespace DockerGenerator private void Run(DockerComposition composition, string name, string output) { - var fragmentLocation = Environment.GetEnvironmentVariable("INSIDE_CONTAINER") == "1" ? "app" : "docker-compose-generator"; - fragmentLocation = FindRoot(fragmentLocation); - fragmentLocation = Path.GetFullPath(Path.Combine(fragmentLocation, "docker-fragments")); - + var root = Environment.GetEnvironmentVariable("INSIDE_CONTAINER") == "1" ? "app" : "docker-compose-generator"; + root = FindRoot(root); + var fragmentLocation = Path.GetFullPath(Path.Combine(root, "docker-fragments")); + var cryptoDefinitionsLocation = Path.GetFullPath(Path.Combine(root, "crypto-definitions.json")); + var cryptoDefinitions = + JsonSerializer.Deserialize(File.ReadAllText(cryptoDefinitionsLocation)); var fragments = new HashSet(); switch (composition.SelectedProxy) { @@ -55,7 +58,8 @@ namespace DockerGenerator break; } fragments.Add("btcpayserver"); - foreach (var crypto in CryptoDefinition.GetDefinitions()) + + foreach (var crypto in cryptoDefinitions) { if (!composition.SelectedCryptos.Contains(crypto.Crypto)) continue;