@@ -101,6 +101,9 @@ def __init__(self, test_node, *, mode=MiniWalletMode.ADDRESS_OP_TRUE):
101
101
self ._address , self ._internal_key = create_deterministic_address_bcrt1_p2tr_op_true ()
102
102
self ._scriptPubKey = bytes .fromhex (self ._test_node .validateaddress (self ._address )['scriptPubKey' ])
103
103
104
+ def _create_utxo (self , * , txid , vout , value , height ):
105
+ return {"txid" : txid , "vout" : vout , "value" : value , "height" : height }
106
+
104
107
def get_balance (self ):
105
108
return sum (u ['value' ] for u in self ._utxos )
106
109
@@ -110,13 +113,13 @@ def rescan_utxos(self):
110
113
res = self ._test_node .scantxoutset (action = "start" , scanobjects = [self .get_descriptor ()])
111
114
assert_equal (True , res ['success' ])
112
115
for utxo in res ['unspents' ]:
113
- self ._utxos .append ({ ' txid' : utxo [' txid' ], ' vout' : utxo [' vout' ], ' value' : utxo [' amount' ], ' height' : utxo [' height' ]} )
116
+ self ._utxos .append (self . _create_utxo ( txid = utxo [" txid" ], vout = utxo [" vout" ], value = utxo [" amount" ], height = utxo [" height" ]) )
114
117
115
118
def scan_tx (self , tx ):
116
119
"""Scan the tx for self._scriptPubKey outputs and add them to self._utxos"""
117
120
for out in tx ['vout' ]:
118
121
if out ['scriptPubKey' ]['hex' ] == self ._scriptPubKey .hex ():
119
- self ._utxos .append ({ ' txid' : tx [' txid' ], ' vout' : out ['n' ], ' value' : out [' value' ], ' height' : 0 } )
122
+ self ._utxos .append (self . _create_utxo ( txid = tx [" txid" ], vout = out ["n" ], value = out [" value" ], height = 0 ) )
120
123
121
124
def sign_tx (self , tx , fixed_length = True ):
122
125
"""Sign tx that has been created by MiniWallet in P2PK mode"""
@@ -140,7 +143,7 @@ def generate(self, num_blocks, **kwargs):
140
143
for b in blocks :
141
144
block_info = self ._test_node .getblock (blockhash = b , verbosity = 2 )
142
145
cb_tx = block_info ['tx' ][0 ]
143
- self ._utxos .append ({ ' txid' : cb_tx [' txid' ], ' vout' : 0 , ' value' : cb_tx [' vout' ][0 ][' value' ], ' height' : block_info [' height' ]} )
146
+ self ._utxos .append (self . _create_utxo ( txid = cb_tx [" txid" ], vout = 0 , value = cb_tx [" vout" ][0 ][" value" ], height = block_info [" height" ]) )
144
147
return blocks
145
148
146
149
def get_scriptPubKey (self ):
@@ -264,12 +267,12 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), utxo_to_spend=None,
264
267
vsize = Decimal (168 ) # P2PK (73 bytes scriptSig + 35 bytes scriptPubKey + 60 bytes other)
265
268
else :
266
269
assert False
267
- send_value = int ( COIN * ( utxo_to_spend [' value' ] - fee_rate * ( vsize / 1000 )) )
270
+ send_value = utxo_to_spend [" value" ] - ( fee_rate * vsize / 1000 )
268
271
assert send_value > 0
269
272
270
273
tx = CTransaction ()
271
274
tx .vin = [CTxIn (COutPoint (int (utxo_to_spend ['txid' ], 16 ), utxo_to_spend ['vout' ]), nSequence = sequence )]
272
- tx .vout = [CTxOut (send_value , self ._scriptPubKey )]
275
+ tx .vout = [CTxOut (int ( COIN * send_value ) , self ._scriptPubKey )]
273
276
tx .nLockTime = locktime
274
277
if self ._mode == MiniWalletMode .RAW_P2PK :
275
278
self .sign_tx (tx )
@@ -283,8 +286,9 @@ def create_self_transfer(self, *, fee_rate=Decimal("0.003"), utxo_to_spend=None,
283
286
tx_hex = tx .serialize ().hex ()
284
287
285
288
assert_equal (tx .get_vsize (), vsize )
289
+ new_utxo = self ._create_utxo (txid = tx .rehash (), vout = 0 , value = send_value , height = 0 )
286
290
287
- return {' txid' : tx . rehash (), ' wtxid' : tx .getwtxid (), ' hex' : tx_hex , 'tx' : tx }
291
+ return {" txid" : new_utxo [ "txid" ], " wtxid" : tx .getwtxid (), " hex" : tx_hex , "tx" : tx , "new_utxo" : new_utxo }
288
292
289
293
def sendrawtransaction (self , * , from_node , tx_hex , maxfeerate = 0 , ** kwargs ):
290
294
txid = from_node .sendrawtransaction (hexstring = tx_hex , maxfeerate = maxfeerate , ** kwargs )
0 commit comments