protected override async Task <TypedActionHandlerResult <PSBT> > Execute(Dictionary <string, object> data, RecipeAction recipeAction, NBXplorerSignPSBTData actionData) { var externalService = await recipeAction.GetExternalService(); var walletService = new NBXplorerWalletService(externalService, _nbXplorerPublicWalletProvider, _derivationSchemeParser, _derivationStrategyFactoryProvider, _nbXplorerClientProvider); var walletData = walletService.GetData(); var wallet = await walletService.ConstructClient(); var psbt = PSBT.Parse(actionData.PSBT); var tx = psbt.ExtractTX(); var tBuilder = await wallet.CreateTransactionBuilder(); tBuilder = tBuilder.ContinueToBuild(tx); foreach (var privateKeyDetails in walletData.PrivateKeys) { await wallet.SignTransaction(tBuilder, privateKeyDetails); } psbt = PSBT.FromTransaction( tBuilder.BuildTransaction(true)); return(new NBXplorerActionHandlerResult <PSBT>(_nbXplorerClientProvider.GetClient(walletData.CryptoCode)) { Executed = true, TypedData = psbt, Result = $"signed psbt: {psbt}" }); }
protected override async Task <TypedActionHandlerResult <BroadcastResult> > Execute( Dictionary <string, object> data, RecipeAction recipeAction, SendTransactionData actionData) { var externalService = await recipeAction.GetExternalService(); var walletService = new NBXplorerWalletService(externalService, _nbXplorerPublicWalletProvider, _derivationSchemeParser, _derivationStrategyFactoryProvider, _nbXplorerClientProvider); var wallet = await walletService.ConstructClient(); var walletData = walletService.GetData(); var explorerClient = _nbXplorerClientProvider.GetClient(walletData.CryptoCode); var tx = await wallet.BuildTransaction(actionData.Outputs.Select(output => (Money.Parse(InterpolateString(output.Amount, data)), (IDestination)BitcoinAddress.Create(InterpolateString(output.DestinationAddress, data), explorerClient.Network.NBitcoinNetwork), output.SubtractFeesFromOutput)), walletData.PrivateKeys, actionData.FeeSatoshiPerByte != null ?new FeeRate(Money.Satoshis(actionData.FeeSatoshiPerByte.Value), 1) : null, actionData.Fee.HasValue?new Money(actionData.Fee.Value, MoneyUnit.BTC) : null); var result = await wallet.BroadcastTransaction(tx); return(new NBXplorerActionHandlerResult <BroadcastResult>( _nbXplorerClientProvider.GetClient(walletData.CryptoCode)) { Executed = result.Success, TypedData = result, Result = $"Tx broadcasted, {(result.Success ? "Successful" : "Unsuccessful")}, {result.RPCMessage}, {tx}" }); }
protected override async Task <TypedActionHandlerResult <PSBT> > Execute( Dictionary <string, object> data, RecipeAction recipeAction, NBXplorerCreatePSBTData actionData) { var externalService = await recipeAction.GetExternalService(); var walletService = new NBXplorerWalletService(externalService, _nbXplorerPublicWalletProvider, _derivationSchemeParser, _derivationStrategyFactoryProvider, _nbXplorerClientProvider); var wallet = await walletService.ConstructClient(); var walletData = walletService.GetData(); var explorerClient = _nbXplorerClientProvider.GetClient(walletData.CryptoCode); var tx = await wallet.BuildTransaction(actionData.Outputs.Select(output => (Money.Parse(InterpolateString(output.Amount, data)), (IDestination)BitcoinAddress.Create(InterpolateString(output.DestinationAddress, data), explorerClient.Network.NBitcoinNetwork), output.SubtractFeesFromOutput)), walletData.PrivateKeys); var psbt = PSBT.FromTransaction(tx); return(new NBXplorerActionHandlerResult <PSBT>( _nbXplorerClientProvider.GetClient(walletData.CryptoCode)) { Executed = true, TypedData = psbt, Result = $"PSBT created {psbt}" }); }
protected override async Task <TypedActionHandlerResult <Money> > Execute(Dictionary <string, object> data, RecipeAction recipeAction, NBXplorerGetBalanceData actionData) { var externalService = await recipeAction.GetExternalService(); var walletService = new NBXplorerWalletService(externalService, _nbXplorerPublicWalletProvider, _derivationSchemeParser, _nbXplorerClientProvider); var walletData = walletService.GetData(); var wallet = await walletService.ConstructClient(); var result = await wallet.GetBalance(); return(new NBXplorerActionHandlerResult <Money>(_nbXplorerClientProvider.GetClient(walletData.CryptoCode)) { Executed = true, TypedData = result, Result = $"Balance: {result}" }); }
protected override async Task <TypedActionHandlerResult <BitcoinAddress> > Execute(Dictionary <string, object> data, RecipeAction recipeAction, GenerateNextAddressData actionData) { var externalService = await recipeAction.GetExternalService(); var walletService = new NBXplorerWalletService(externalService, _nbXplorerPublicWalletProvider, _derivationSchemeParser, _derivationStrategyFactoryProvider, _nbXplorerClientProvider); var walletData = walletService.GetData(); var wallet = await walletService.ConstructClient(); var result = await wallet.GetNextAddress(); return(new NBXplorerActionHandlerResult <BitcoinAddress>(_nbXplorerClientProvider.GetClient(walletData.CryptoCode)) { Executed = true, TypedData = result, Result = $"Next address: {result}" }); }