public async Task <IActionResult> UpdateOnChainPaymentMethod( string storeId, string cryptoCode, [FromBody] UpdateOnChainPaymentMethodRequest request) { var id = new PaymentMethodId(cryptoCode, PaymentTypes.BTCLike); if (!GetCryptoCodeWallet(cryptoCode, out var network, out var wallet)) { return(NotFound()); } if (string.IsNullOrEmpty(request?.DerivationScheme)) { ModelState.AddModelError(nameof(OnChainPaymentMethodData.DerivationScheme), "Missing derivationScheme"); } if (!ModelState.IsValid) { return(this.CreateValidationError(ModelState)); } try { var store = Store; var storeBlob = store.GetStoreBlob(); var strategy = DerivationSchemeSettings.Parse(request.DerivationScheme, network); if (strategy != null) { await wallet.TrackAsync(strategy.AccountDerivation); } strategy.Label = request.Label; var signing = strategy.GetSigningAccountKeySettings(); if (request.AccountKeyPath is RootedKeyPath r) { signing.AccountKeyPath = r.KeyPath; signing.RootFingerprint = r.MasterFingerprint; } else { signing.AccountKeyPath = null; signing.RootFingerprint = null; } store.SetSupportedPaymentMethod(id, strategy); storeBlob.SetExcluded(id, !request.Enabled); store.SetStoreBlob(storeBlob); await _storeRepository.UpdateStore(store); return(Ok(GetExistingBtcLikePaymentMethod(cryptoCode, store))); } catch { ModelState.AddModelError(nameof(OnChainPaymentMethodData.DerivationScheme), "Invalid Derivation Scheme"); return(this.CreateValidationError(ModelState)); } }
public IActionResult GetProposedOnChainPaymentMethodPreview( string storeId, string cryptoCode, [FromBody] UpdateOnChainPaymentMethodRequest paymentMethodData, int offset = 0, int amount = 10) { if (!GetCryptoCodeWallet(cryptoCode, out var network, out BTCPayWallet _)) { return(NotFound()); } if (string.IsNullOrEmpty(paymentMethodData?.DerivationScheme)) { ModelState.AddModelError(nameof(OnChainPaymentMethodData.DerivationScheme), "Missing derivationScheme"); } if (!ModelState.IsValid) { return(this.CreateValidationError(ModelState)); } DerivationSchemeSettings strategy; try { strategy = DerivationSchemeSettings.Parse(paymentMethodData.DerivationScheme, network); } catch { ModelState.AddModelError(nameof(OnChainPaymentMethodData.DerivationScheme), "Invalid Derivation Scheme"); return(this.CreateValidationError(ModelState)); } 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 derivation = line.Derive((uint)i); result.Addresses.Add( new OnChainPaymentMethodPreviewResultData. OnChainPaymentMethodPreviewResultAddressItem() { KeyPath = deposit.GetKeyPath((uint)i).ToString(), Address = strategy.Network.NBXplorerNetwork.CreateAddress(strategy.AccountDerivation, line.KeyPathTemplate.GetKeyPath((uint)i), derivation.ScriptPubKey).ToString() }); } return(Ok(result)); }
PreviewProposedStoreOnChainPaymentMethodAddresses( string storeId, string cryptoCode, UpdateOnChainPaymentMethodRequest paymentMethod, int offset = 0, int amount = 10, CancellationToken token = default) { var response = await _httpClient.SendAsync( CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/preview", bodyPayload : paymentMethod, queryPayload : new Dictionary <string, object>() { { "offset", offset }, { "amount", amount } }, method : HttpMethod.Post), token); return(await HandleResponse <OnChainPaymentMethodPreviewResultData>(response)); }
public virtual async Task <OnChainPaymentMethodData> UpdateStoreOnChainPaymentMethod(string storeId, string cryptoCode, UpdateOnChainPaymentMethodRequest paymentMethod, CancellationToken token = default) { var response = await _httpClient.SendAsync( CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}", bodyPayload : paymentMethod, method : HttpMethod.Put), token); return(await HandleResponse <OnChainPaymentMethodData>(response)); }