Beispiel #1
0
def _tx_in_boilerplate(unspent, output, script_code, construct_output_block_f):
    script = hex_to_bytes(unspent.script)
    script_len = int_to_unknown_bytes(len(script), byteorder='little')
    tx_id = hex_to_bytes(unspent.txid)[::-1]
    tx_index = unspent.txindex.to_bytes(4, byteorder='little')
    amount = unspent.amount.to_bytes(8, byteorder='little')
    tx_in = TxIn(script, script_len, tx_id, tx_index, amount)

    hash_previous_outputs = double_sha256(tx_id + tx_index)
    hash_sequence = double_sha256(SEQUENCE)

    output_block = construct_output_block_f([output])
    hash_outputs = double_sha256(output_block)

    to_be_hashed = (VERSION_1 + hash_previous_outputs + hash_sequence +
                    tx_in.txid + tx_in.txindex +
                    int_to_varint(len(script_code)) + script_code +
                    tx_in.amount + SEQUENCE + hash_outputs + LOCK_TIME +
                    HASH_TYPE)
    hashed = sha256(to_be_hashed)  # BIP-143: Used for Bitcoin Cash
    return tx_in, hashed, output_block
Beispiel #2
0
 def test_equality(self):
     txin1 = TxIn(b'script', b'\x06', b'txid', b'\x04', 0)
     txin2 = TxIn(b'script', b'\x06', b'txid', b'\x04', 0)
     txin3 = TxIn(b'script', b'\x06', b'txi', b'\x03', 0)
     assert txin1 == txin2
     assert txin1 != txin3
Beispiel #3
0
 def test_repr(self):
     txin = TxIn(b'script', b'\x06', b'txid', b'\x04', 0)
     assert repr(txin) == "TxIn(b'script', {}, b'txid', {}, 0)" \
                          "".format(repr(b'\x06'), repr(b'\x04'))
Beispiel #4
0
 def test_init(self):
     txin = TxIn(b'script', b'\x06', b'txid', b'\x04', 0)
     assert txin.script == b'script'
     assert txin.script_len == b'\x06'
     assert txin.txid == b'txid'
     assert txin.txindex == b'\x04'
Beispiel #5
0
              '3c2da23adf3010000008a47304402204d6f28d77fa31cfc6c13bb1bda2628f2'
              '237e2630e892dc62bb319eb75dc7f9310220741f4df7d9460daa844389eb23f'
              'b318dd674967144eb89477608b10e03c175034141043d5c2875c9bd116875a7'
              '1a5db64cffcb13396b163d039b1d932782489180433476a4352a2add00ebb0d'
              '5c94c515b72eb10f1fd8f3f03b42f4a2b255bfc9aa9e3ffffffff0250c30000'
              '000000001976a914e7c1345fc8f87c68170b3aa798a956c2fe6a9eff88ac088'
              '8fc04000000001976a91492461bde6283b461ece7ddf4dbf1e0a48bd113d888'
              'ac00000000')
INPUTS = [
    TxIn(
        (b"G0D\x02 E\xb7C\xdb\xaa\xaa,\xd1\xef\x0b\x914oVD\xe3-\xc7\x0c\xde\x05\t"
         b"\x1b7b\xd4\xca\xbbn\xbdq\x1a\x02 tF\x10V\xc2n\xfe\xac\x0bD\x8e\x7f\xa7"
         b"iw=\xd6\xe4Cl\xdeP\\\x8fl\xa60>\xfe1\xf0\x95\x01A\x04=\\(u\xc9\xbd\x11"
         b"hu\xa7\x1a]\xb6L\xff\xcb\x139k\x16=\x03\x9b\x1d\x93'\x82H\x91\x80C4v"
         b"\xa45**\xdd\x00\xeb\xb0\xd5\xc9LQ[r\xeb\x10\xf1\xfd\x8f?\x03\xb4/J+%["
         b"\xfc\x9a\xa9\xe3"),
        b'\x8a',
        (b"\x88x9\x9d\x83\xec%\xc6'\xcf\xbfu?\xf9\xca6\x027>"
         b"\xacCz\xb2gaT\xa3\xc2\xda#\xad\xf3"),
        b'\x01\x00\x00\x00',
        0
    )
]
INPUT_BLOCK = ('8878399d83ec25c627cfbf753ff9ca3602373eac437ab2676154a3c2da23adf30'
               '10000008a473044022045b743dbaaaa2cd1ef0b91346f5644e32dc70cde05091b'
               '3762d4cabb6ebd711a022074461056c26efeac0b448e7fa769773dd6e4436cde5'
               '05c8f6ca6303efe31f0950141043d5c2875c9bd116875a71a5db64cffcb13396b'
               '163d039b1d932782489180433476a4352a2add00ebb0d5c94c515b72eb10f1fd8'
               'f3f03b42f4a2b255bfc9aa9e3ffffffff')
UNSPENTS = [
    Unspent(83727960,
Beispiel #6
0
 def test_init(self):
     txin = TxIn(b"script", b"\x06", b"txid", b"\x04", 0)
     assert txin.script == b"script"
     assert txin.script_len == b"\x06"
     assert txin.txid == b"txid"
     assert txin.txindex == b"\x04"
Beispiel #7
0
 def test_repr(self):
     txin = TxIn(b"script", b"\x06", b"txid", b"\x04", 0)
     assert repr(txin) == "TxIn(b'script', {}, b'txid', {}, 0)" "".format(
         repr(b"\x06"), repr(b"\x04"))
Beispiel #8
0
 def test_equality(self):
     txin1 = TxIn(b"script", b"\x06", b"txid", b"\x04", 0)
     txin2 = TxIn(b"script", b"\x06", b"txid", b"\x04", 0)
     txin3 = TxIn(b"script", b"\x06", b"txi", b"\x03", 0)
     assert txin1 == txin2
     assert txin1 != txin3