|
|
@ -73,6 +73,12 @@ class MiniWallet:
|
|
|
|
|
|
|
|
|
|
|
|
def send_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None):
|
|
|
|
def send_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None):
|
|
|
|
"""Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
|
|
|
|
"""Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
|
|
|
|
|
|
|
|
tx = self.create_self_transfer(fee_rate=fee_rate, from_node=from_node, utxo_to_spend=utxo_to_spend)
|
|
|
|
|
|
|
|
self.sendrawtransaction(from_node=from_node, tx_hex=tx['hex'])
|
|
|
|
|
|
|
|
return tx
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None, mempool_valid=True):
|
|
|
|
|
|
|
|
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
|
|
|
|
self._utxos = sorted(self._utxos, key=lambda k: k['value'])
|
|
|
|
self._utxos = sorted(self._utxos, key=lambda k: k['value'])
|
|
|
|
utxo_to_spend = utxo_to_spend or self._utxos.pop() # Pick the largest utxo (if none provided) and hope it covers the fee
|
|
|
|
utxo_to_spend = utxo_to_spend or self._utxos.pop() # Pick the largest utxo (if none provided) and hope it covers the fee
|
|
|
|
vsize = Decimal(96)
|
|
|
|
vsize = Decimal(96)
|
|
|
@ -88,9 +94,10 @@ class MiniWallet:
|
|
|
|
tx_hex = tx.serialize().hex()
|
|
|
|
tx_hex = tx.serialize().hex()
|
|
|
|
|
|
|
|
|
|
|
|
tx_info = from_node.testmempoolaccept([tx_hex])[0]
|
|
|
|
tx_info = from_node.testmempoolaccept([tx_hex])[0]
|
|
|
|
self.sendrawtransaction(from_node=from_node, tx_hex=tx_hex)
|
|
|
|
assert_equal(mempool_valid, tx_info['allowed'])
|
|
|
|
assert_equal(tx_info['vsize'], vsize)
|
|
|
|
if mempool_valid:
|
|
|
|
assert_equal(tx_info['fees']['base'], fee)
|
|
|
|
assert_equal(tx_info['vsize'], vsize)
|
|
|
|
|
|
|
|
assert_equal(tx_info['fees']['base'], fee)
|
|
|
|
return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex}
|
|
|
|
return {'txid': tx_info['txid'], 'wtxid': tx_info['wtxid'], 'hex': tx_hex}
|
|
|
|
|
|
|
|
|
|
|
|
def sendrawtransaction(self, *, from_node, tx_hex):
|
|
|
|
def sendrawtransaction(self, *, from_node, tx_hex):
|
|
|
|