Skip to content

Optional op_return output for generate_and_send_coins #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,10 @@ def is_null(self):
class CTxInWitness:
__slots__ = ("scriptWitness",)

def __init__(self, witness_stack):
def __init__(self, witness_stack=None):
self.scriptWitness = CScriptWitness()
self.scriptWitness.stack = witness_stack
if witness_stack:
self.scriptWitness.stack = witness_stack

def deserialize(self, f):
self.scriptWitness.stack = deser_string_vector(f)
Expand Down
12 changes: 8 additions & 4 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,17 @@ def __getattr__(self, name):
def __setattr__(self, name):
return setattr(self.instance, name)

def generate_and_send_coins(node, address):
def generate_and_send_coins(node, address, data=None):
"""Generate blocks on node and then send 1 BTC to address.

No change output is added to the transaction.
Return a CTransaction object."""
version = node.getnetworkinfo()['subversion']
print("\nClient version is {}\n".format(version))

# Generate 101 blocks
node.generate(101)
# Generate 101 blocks and send reward to bech32 address
reward_address = node.getnewaddress(address_type="bech32")
node.generatetoaddress(101, reward_address)
balance = node.getbalance()
print("Balance: {}\n".format(balance))

Expand All @@ -170,7 +171,10 @@ def generate_and_send_coins(node, address):
# Create a raw transaction sending 1 BTC to the address, then sign and send it.
# We won't create a change output, so maxfeerate must be set to 0
# to allow any fee rate.
tx_hex = node.createrawtransaction(inputs=inputs, outputs=[{address: 1}])

# An OP_RETURN output is added at index 1 if data is provided.
outputs = [{address: 1}, {"data": data}] if data else [{address: 1}]
tx_hex = node.createrawtransaction(inputs=inputs, outputs=outputs)

res = node.signrawtransactionwithwallet(hexstring=tx_hex)

Expand Down