private static void AssertFullySigned(HwiTester tester, PSBT psbt) { var txbuilder = tester.Network.CreateTransactionBuilder(); txbuilder.AddCoins(psbt.Inputs.Select(i => i.GetCoin())); Assert.True(txbuilder.Verify(psbt.ExtractTransaction()), "The transaction should be fully signed"); }
async Task <HwiTester> CreateTester(bool needDevice = true) { var tester = await HwiTester.CreateAsync(LoggerFactory); if (needDevice) { await tester.EnsureHasDevice(); } return(tester); }
private async Task <PSBT> CreatePSBT(HwiTester tester, ScriptPubKeyType addressType) { var accountKeyPath = new RootedKeyPath(tester.Device.Fingerprint.Value, GetKeyPath(addressType)); var accountKey = await tester.Device.GetXPubAsync(accountKeyPath.KeyPath); Logger.LogInformation($"Signing with xpub {accountKeyPath}: {accountKey}..."); List <Transaction> knownTransactions = new List <Transaction>(); TransactionBuilder builder = accountKey.Network.CreateTransactionBuilder(); CreateCoin(builder, knownTransactions, addressType, Money.Coins(1.0m), accountKey, "0/0"); CreateCoin(builder, knownTransactions, addressType, Money.Coins(1.2m), accountKey, "0/1"); builder.Send(new Key().PubKey.GetScriptPubKey(addressType), Money.Coins(2.0m)); builder.SetChange(accountKey.Derive(new KeyPath("1/0")).ExtPubKey.PubKey.GetScriptPubKey(addressType)); builder.SendEstimatedFees(new FeeRate(1.0m)); var psbt = builder.BuildPSBT(false); psbt.AddTransactions(knownTransactions.ToArray()); psbt.AddKeyPath(accountKey, new KeyPath[] { new KeyPath("0/0"), new KeyPath("0/1"), new KeyPath("1/0") }); psbt.RebaseKeyPaths(accountKey, accountKeyPath); return(psbt); }