Skip to content

Commit fa1eef3

Browse files
committed
Update name_ant_workflow.py.
Upstream bitcoin/bitcoin#17211 solved a long-standing issue for doing atomic trades with names (namely that the buyer's wallet was not able to directly fund a transaction with the non-wallet name input in it). Based on this, we can now streamline name_ant_workflow.py to make use of this new feature. This allows us to properly use fundrawtransaction to fund the final transaction including already the name input and output, and thus with correct fee estimation done. (Previously we just funded a dummy transaction with a guessed higher fee, and then added in the name input and output manually, hoping the fee would still be fine.)
1 parent a3776da commit fa1eef3

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

test/functional/name_ant_workflow.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2020 Daniel Kraft
2+
# Copyright (c) 2020-2021 Daniel Kraft
33
# Distributed under the MIT/X11 software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

@@ -28,31 +28,43 @@ def run_test (self):
2828
self.sync_blocks ()
2929
self.checkName (0, "x/name", "value", None, False)
3030

31-
# fundrawtransaction and friends does not support non-wallet provided
32-
# inputs. Thus we have to first build up the funded transaction without
33-
# the name coins and a slightly higher fee, and then combine it with the
34-
# name input/output to obtain the final raw transaction.
35-
addrPayment = self.nodes[0].getnewaddress ()
36-
outs = [{addrPayment: 10}]
37-
options = {
38-
"fee_rate": 100,
39-
}
40-
part1 = self.nodes[1].walletcreatefundedpsbt ([], outs, 0, options)["psbt"]
31+
# We construct the base transaction first, with just the name input,
32+
# name output (including the operation) and the payment output.
33+
# We then apply fundrawtransaction to add the necessary input and change
34+
# for the payment; this needs solving data for the non-wallet input
35+
# (the name) to be passed in, which in this case is the pubkey for the
36+
# name input address.
4137

38+
addrPayment = self.nodes[0].getnewaddress ()
4239
addrNm = self.nodes[1].getnewaddress ()
40+
4341
nmData = self.nodes[0].name_show ("x/name")
44-
part2 = self.nodes[0].createpsbt ([nmData], [{addrNm: 0.01}])
42+
addrNmOld = nmData["address"]
43+
pubKey = self.nodes[0].getaddressinfo (addrNmOld)["pubkey"]
44+
45+
tx = self.nodes[1].createrawtransaction ([nmData], {
46+
addrPayment: 10,
47+
addrNm: 0.01,
48+
})
49+
vout = self.rawtxOutputIndex (1, tx, addrNm)
4550
nameOp = {
4651
"op": "name_update",
4752
"name": "x/name",
4853
"value": "updated",
4954
}
50-
part2 = self.nodes[1].namepsbt (part2, 0, nameOp)["psbt"]
51-
combined = self.nodes[1].joinpsbts ([part1, part2])
55+
tx = self.nodes[1].namerawtransaction (tx, vout, nameOp)["hex"]
56+
57+
options = {
58+
"solving_data": {
59+
"pubkeys": [pubKey],
60+
},
61+
}
62+
tx = self.nodes[1].fundrawtransaction (tx, options)["hex"]
63+
psbt = self.nodes[1].converttopsbt (tx)
5264

5365
# Sign and broadcast the partial tx.
54-
sign1 = self.nodes[0].walletprocesspsbt (combined)
55-
sign2 = self.nodes[1].walletprocesspsbt (combined)
66+
sign1 = self.nodes[0].walletprocesspsbt (psbt)
67+
sign2 = self.nodes[1].walletprocesspsbt (psbt)
5668
combined = self.nodes[1].combinepsbt ([sign1["psbt"], sign2["psbt"]])
5769
tx = self.nodes[1].finalizepsbt (combined)
5870
assert_equal (tx["complete"], True)

0 commit comments

Comments
 (0)