Skip to content

Commit 611747b

Browse files
committed
implemented Coin::opreturn method
1 parent e83d33c commit 611747b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pacli/coin.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pypeerassets.networks import net_query
66
from pypeerassets.transactions import (tx_output,
77
p2pkh_script,
8+
nulldata_script,
89
make_raw_transaction,
910
Locktime)
1011

@@ -55,3 +56,36 @@ def sendto(self, address: Union[str], amount: Union[float],
5556
signedtx = sign_transaction(provider, unsigned_tx, Settings.key)
5657

5758
return sendtx(signedtx)
59+
60+
def opreturn(self, string: hex, locktime: int=0) -> str:
61+
'''send op_return transaction'''
62+
63+
network_params = net_query(Settings.network)
64+
65+
inputs = provider.select_inputs(Settings.key.address, 0.01)
66+
67+
outs = [tx_output(network=provider.network,
68+
value=Decimal(0), n=1,
69+
script=nulldata_script(bytes.fromhex(string))
70+
)
71+
]
72+
73+
# first round of txn making is done by presuming minimal fee
74+
change_sum = Decimal(inputs['total'] - network_params.min_tx_fee)
75+
76+
outs.append(
77+
tx_output(network=provider.network,
78+
value=change_sum, n=len(outs)+1,
79+
script=p2pkh_script(address=Settings.key.address,
80+
network=provider.network))
81+
)
82+
83+
unsigned_tx = make_raw_transaction(network=provider.network,
84+
inputs=inputs['utxos'],
85+
outputs=outs,
86+
locktime=Locktime(locktime)
87+
)
88+
89+
signedtx = sign_transaction(provider, unsigned_tx, Settings.key)
90+
91+
return sendtx(signedtx)

0 commit comments

Comments
 (0)