Skip to content

Commit 2e635c0

Browse files
committed
Add optional op_return to generate_and_send_coins
1 parent 6f414c6 commit 2e635c0

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

util.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def __getattr__(self, name):
149149
def __setattr__(self, name):
150150
return setattr(self.instance, name)
151151

152-
def generate_and_send_coins(node, address):
152+
def generate_and_send_coins(node, address, data=None):
153153
"""Generate blocks on node and then send 1 BTC to address.
154154
155155
No change output is added to the transaction.
@@ -171,7 +171,10 @@ def generate_and_send_coins(node, address):
171171
# Create a raw transaction sending 1 BTC to the address, then sign and send it.
172172
# We won't create a change output, so maxfeerate must be set to 0
173173
# to allow any fee rate.
174-
tx_hex = node.createrawtransaction(inputs=inputs, outputs=[{address: 1}])
174+
175+
# An OP_RETURN output is added at index 1 if data is provided.
176+
outputs = [{address: 1}, {"data": data}] if data else [{address: 1}]
177+
tx_hex = node.createrawtransaction(inputs=inputs, outputs=outputs)
175178

176179
res = node.signrawtransactionwithwallet(hexstring=tx_hex)
177180

0 commit comments

Comments
 (0)