@@ -142,7 +142,10 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_
142
142
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
143
143
self ._utxos = sorted (self ._utxos , key = lambda k : k ['value' ])
144
144
utxo_to_spend = utxo_to_spend or self ._utxos .pop () # Pick the largest utxo (if none provided) and hope it covers the fee
145
- vsize = Decimal (96 )
145
+ if self ._priv_key is None :
146
+ vsize = Decimal (96 ) # anyone-can-spend
147
+ else :
148
+ vsize = Decimal (168 ) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
146
149
send_value = satoshi_round (utxo_to_spend ['value' ] - fee_rate * (vsize / 1000 ))
147
150
fee = utxo_to_spend ['value' ] - send_value
148
151
assert send_value > 0
@@ -167,10 +170,7 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_
167
170
tx_info = from_node .testmempoolaccept ([tx_hex ])[0 ]
168
171
assert_equal (mempool_valid , tx_info ['allowed' ])
169
172
if mempool_valid :
170
- # TODO: for P2PK, vsize is not constant due to varying scriptSig length,
171
- # so only check this for anyone-can-spend outputs right now
172
- if self ._priv_key is None :
173
- assert_equal (tx_info ['vsize' ], vsize )
173
+ assert_equal (tx_info ['vsize' ], vsize )
174
174
assert_equal (tx_info ['fees' ]['base' ], fee )
175
175
return {'txid' : tx_info ['txid' ], 'wtxid' : tx_info ['wtxid' ], 'hex' : tx_hex , 'tx' : tx }
176
176
0 commit comments