コード例 #1
0
# - Choose the transaction destination address.
# - Build the transaction using the basic constructor.
# - Sign and broadcast the transaction.
# ---------------------------------------------------------------------------------------------------------------------

# Reference to the previous transaction output that will be used to redeem and spend the funds, consisting on an id and
# an output index.
prev_tx_id = "7767a9eb2c8adda3ffce86c06689007a903b6f7e78dbc049ef0dbaf9eeebe075"
prev_out_index = 0

# Amount to be spent, in Satoshis, and the fee to be deduced (should be calculated).
value = 6163910
fee = 230 * 240

# Destination Bitcoin address where the value in bitcoins will be sent and locked until the owner redeems it.
destination_btc_addr = "miWdbNn9zDLnKpcNuCLdfRiJx59c93bT8t"

# First, we  build our transaction from io (input/output) using the previous transaction references, the value, and the
# destination.
tx = TX.build_from_io(prev_tx_id, prev_out_index, value - fee,
                      destination_btc_addr)
# Finally, the transaction is signed using the private key associated with the Bitcoin address from each input.
# Input 0 will be signed, since we have only created one.
tx.sign(sk, 0)

# Once created we can display the serialized transaction. Transaction is now ready to be broadcast.
print "hex: " + tx.serialize()

# Finally, we can analyze each field of the transaction.
tx.display()
コード例 #2
0
from bitcoin_tools.core.transaction import TX

#################################################
#           Hex transaction analysis            #
#################################################

# ---------------------------------------------------------------------------------------------------------------------
# The following piece of code parses a serialized transaction (hex encoded) transaction and displays all the information
#  related to it.
# - Leftmost displayed transaction shows data as should be interpreted (human-readable), while rightmost
# (surrounded by parenthesis) shows it as it is in the serialize transaction (can be used to identify it inside the
# transaction)
# - You should change the hex_tx for the one you'd like to deserialize. Serialized transaction can be obtain though
# block explorers such as blockchyper or blockr.io, or by building a transaction using some of the library tools.
# ---------------------------------------------------------------------------------------------------------------------

# First a transaction object is created (through the deserialize constructor) by deserializing the hex transaction we
# have selected.
hex_tx = "01000000013ca58d2f6fac36602d831ee0cf2bc80031c7472e80a322b57f614c5ce9142b71000000006b483045022100f0331d85cb7f7ec1bedc41f50c695d654489458e88aec0076fbad5d8aeda1673022009e8ca2dda1d6a16bfd7133b0008720145dacccb35c0d5c9fc567e52f26ca5f7012103a164209a7c23227fcd6a71c51efc5b6eb25407f4faf06890f57908425255e42bffffffff0241a20000000000001976a914e44839239ab36f5bc67b2079de00ecf587233ebe88ac74630000000000001976a914dc7016484646168d99e49f907c86c271299441c088ac00000000"
tx = TX.deserialize(hex_tx)

# Then, the transaction can be displayed using the display method to analyze how it's been constructed.
tx.display()
コード例 #3
0
            tmpHex = tmpHex.decode('hex')
            tmpHex = hashlib.new('sha256', tmpHex).digest()
            tmpHex = hashlib.new('sha256', tmpHex).digest()
            tmpHex = tmpHex.encode('hex')
            tmpHex = tmpHex.upper()
            tmpHex = reverse(tmpHex)
            resList.append('TX hash = ' + tmpHex)
            # test for first reqular transaction
            #if tmpHex == 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16'.upper() :
            #    txJson = publicKeyDecode();
            #    resList.append('Tx detail = ' + txJson)
            tx_hashes.append(tmpHex)
            tmpHex = ''
            resList.append('')
            resList.append('Raw Tx = ' + RawTX)
            tx = TX.deserialize(RawTX)
            tx.display()
            #resList.append('decoded Tx = ' + str(tx.display()))
            RawTX = ''

        a += 1
        tx_hashes = [h.decode('hex') for h in tx_hashes]
        if MerkleRoot != '0000000000000000000000000000000000000000000000000000000000000000':
            tmpHex = merkle_root(tx_hashes).encode('hex').upper()
            if tmpHex != MerkleRoot:
                print('Merkle roots does not match! >', MerkleRoot, tmpHex)
            tmpHex = ''
        else:
            break
    f.close()
    f = open(dirB + nameRes, 'w')
コード例 #4
0
    sks.append(sk)
    pks.append(pk)

for i in range(3):
    if i is 0:
        print "\n#############\n# FROM P2PK #\n#############"
        sk = sks[i]
    elif i is 1:
        print "##############\n# FROM P2PKH #\n##############"
        sk = sks[i]
    elif i is 2:
        print "#############\n# FROM P2MS #\n#############"
        sk = sks[:i]
    for j in range(3):
        if j is 0:
            print "\nTO: P2PK\n"
            dest = serialize_pk(pks[j])
        elif j is 1:
            print "\nTO: P2PKH\n"
            dest = btc_addrs[j]
        elif j is 2:
            print "\nTO: P2MS\n"
            dest = [2, serialize_pk(pks[0]), serialize_pk(pks[1])]

        tx = TX.build_from_io(prev_tx_ids[i], prev_out_index[i], value, dest)
        tx.sign(sk, 0)
        print tx.serialize()
        tx.display()

    print "\n---------------------------------------------------------------------------------------------\n"