public IActionResult GetOnChainPaymentMethodPreview(
            string storeId,
            string cryptoCode,
            int offset = 0, int amount = 10)
        {
            AssertCryptoCodeWallet(cryptoCode, out var network, out _);

            var paymentMethod = GetExistingBtcLikePaymentMethod(cryptoCode);

            if (string.IsNullOrEmpty(paymentMethod?.DerivationScheme))
            {
                throw ErrorPaymentMethodNotConfigured();
            }

            try
            {
                var strategy = DerivationSchemeSettings.Parse(paymentMethod.DerivationScheme, network);
                var deposit  = new NBXplorer.KeyPathTemplates(null).GetKeyPathTemplate(DerivationFeature.Deposit);

                var line   = strategy.AccountDerivation.GetLineFor(deposit);
                var result = new OnChainPaymentMethodPreviewResultData();
                for (var i = offset; i < amount; i++)
                {
                    var address = line.Derive((uint)i);
                    result.Addresses.Add(
                        new OnChainPaymentMethodPreviewResultData.OnChainPaymentMethodPreviewResultAddressItem()
                    {
                        KeyPath = deposit.GetKeyPath((uint)i).ToString(),
                        Address = address.ScriptPubKey.GetDestinationAddress(strategy.Network.NBitcoinNetwork)
                                  .ToString()
                    });
                }

                return(Ok(result));
            }
            catch
            {
                ModelState.AddModelError(nameof(OnChainPaymentMethodData.DerivationScheme),
                                         "Invalid Derivation Scheme");
                return(this.CreateValidationError(ModelState));
            }
        }
예제 #2
0
        public static IEnumerable <ISupportedPaymentMethod> GetSupportedPaymentMethods(this StoreData storeData, BTCPayNetworkProvider networks)
        {
            if (storeData == null)
            {
                throw new ArgumentNullException(nameof(storeData));
            }
            networks = networks.UnfilteredNetworks;
#pragma warning disable CS0618
            bool btcReturned = false;

            // Legacy stuff which should go away
            if (!string.IsNullOrEmpty(storeData.DerivationStrategy))
            {
                btcReturned = true;
                yield return(DerivationSchemeSettings.Parse(storeData.DerivationStrategy, networks.BTC));
            }


            if (!string.IsNullOrEmpty(storeData.DerivationStrategies))
            {
                JObject strategies = JObject.Parse(storeData.DerivationStrategies);
                foreach (var strat in strategies.Properties())
                {
                    var paymentMethodId = PaymentMethodId.Parse(strat.Name);
                    var network         = networks.GetNetwork <BTCPayNetworkBase>(paymentMethodId.CryptoCode);
                    if (network != null)
                    {
                        if (network == networks.BTC && paymentMethodId.PaymentType == PaymentTypes.BTCLike && btcReturned)
                        {
                            continue;
                        }
                        if (strat.Value.Type == JTokenType.Null)
                        {
                            continue;
                        }
                        yield return
                            (paymentMethodId.PaymentType.DeserializeSupportedPaymentMethod(network, strat.Value));
                    }
                }
            }
#pragma warning restore CS0618
        }
예제 #3
0
        public IEnumerable <ISupportedPaymentMethod> GetSupportedPaymentMethods(BTCPayNetworkProvider networks)
        {
#pragma warning disable CS0618
            bool btcReturned = false;

            // Legacy stuff which should go away
            if (!string.IsNullOrEmpty(DerivationStrategy))
            {
                if (networks.BTC != null)
                {
                    btcReturned = true;
                    yield return(DerivationSchemeSettings.Parse(DerivationStrategy, networks.BTC));
                }
            }


            if (!string.IsNullOrEmpty(DerivationStrategies))
            {
                JObject strategies = JObject.Parse(DerivationStrategies);
                foreach (var strat in strategies.Properties())
                {
                    var paymentMethodId = PaymentMethodId.Parse(strat.Name);
                    var network         = networks.GetNetwork <BTCPayNetwork>(paymentMethodId.CryptoCode);
                    if (network != null)
                    {
                        if (network == networks.BTC && paymentMethodId.PaymentType == PaymentTypes.BTCLike && btcReturned)
                        {
                            continue;
                        }
                        if (strat.Value.Type == JTokenType.Null)
                        {
                            continue;
                        }
                        yield return
                            (PaymentMethodHandlerDictionary[paymentMethodId]
                             .DeserializeSupportedPaymentMethod(paymentMethodId, strat.Value));
                    }
                }
            }
#pragma warning restore CS0618
        }
예제 #4
0
        public override ISupportedPaymentMethod DeserializeSupportedPaymentMethod(BTCPayNetworkBase network, JToken value)
        {
            if (network == null)
            {
                throw new ArgumentNullException(nameof(network));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            var net = (BTCPayNetwork)network;

            if (value is JObject jobj)
            {
                var scheme = net.NBXplorerNetwork.Serializer.ToObject <DerivationSchemeSettings>(jobj);
                scheme.Network = net;
                return(scheme);
            }
            // Legacy
            return(DerivationSchemeSettings.Parse(((JValue)value).Value <string>(), net));
        }
예제 #5
0
        public ActionResult <OnChainPaymentMethodPreviewResultData> GetOnChainPaymentMethodPreview(
            string cryptoCode,
            int offset = 0, int amount = 10)
        {
            if (!GetCryptoCodeWallet(cryptoCode, out var network, out BTCPayWallet _))
            {
                return(NotFound());
            }

            var paymentMethod = GetExistingBtcLikePaymentMethod(cryptoCode);

            if (string.IsNullOrEmpty(paymentMethod?.DerivationScheme))
            {
                return(NotFound());
            }

            var strategy = DerivationSchemeSettings.Parse(paymentMethod.DerivationScheme, network);
            var deposit  = new NBXplorer.KeyPathTemplates(null).GetKeyPathTemplate(DerivationFeature.Deposit);

            var line   = strategy.AccountDerivation.GetLineFor(deposit);
            var result = new OnChainPaymentMethodPreviewResultData();

            for (var i = offset; i < amount; i++)
            {
                var address = line.Derive((uint)i);
                result.Addresses.Add(
                    new OnChainPaymentMethodPreviewResultData.OnChainPaymentMethodPreviewResultAddressItem()
                {
                    KeyPath = deposit.GetKeyPath((uint)i).ToString(),
                    Address = address.ScriptPubKey.GetDestinationAddress(strategy.Network.NBitcoinNetwork)
                              .ToString()
                });
            }

            return(Ok(result));
        }