-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathspend_non_std_tx.py
52 lines (42 loc) · 1.83 KB
/
spend_non_std_tx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Copyright (C) 2018-2020 The python-litecoin-utils developers
#
# This file is part of python-litecoin-utils
#
# It is subject to the license terms in the LICENSE file found in the top-level
# directory of this distribution.
#
# No part of python-litecoin-utils, including this file, may be copied,
# modified, propagated, or distributed except according to the terms contained
# in the LICENSE file.
from litecoinutils.setup import setup
from litecoinutils.utils import to_satoshis
from litecoinutils.transactions import Transaction, TxInput, TxOutput
from litecoinutils.keys import P2pkhAddress
from litecoinutils.script import Script
#
# Note that a non-standard transaction can only be included in a block if a
# miner agrees with it. For this to work one needs to use a node setup up
# for regtest so that you can mine your own blocks; unless you mine your own
# testnet/mainnet blocks.
# Node's config file requires:
# regtest=1
# acceptnonstdtxn=1
#
def main():
# always remember to setup the network
setup('regtest')
# create transaction input from tx id of UTXO (contained 0.4 tBTC)
txin = TxInput('4d9a6baf45d4b57c875fe83d5e0834568eae4b5ef6e61d13720ef6685168e663', 0)
# provide unlocking script
# note that no signing is required to unlock: OP_ADD OP_5 OP_EQUAL
txin.script_sig = Script(['OP_2', 'OP_3'])
# create transaction output using P2PKH scriptPubKey (locking script)
addr = P2pkhAddress('mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r')
# locking script expects 2 numbers that when added equal 5 (silly example)
txout = TxOutput(to_satoshis(0.8), addr.to_script_pub_key() )
# create transaction from inputs/outputs -- default locktime is used
tx = Transaction([txin], [txout])
# print raw transaction
print("\nRaw transaction:\n" + tx.serialize())
if __name__ == "__main__":
main()