コード例 #1
0
ファイル: txnUtils.py プロジェクト: 64octets/bitcoin-code-1
    def test_makeSignedTransaction(self):
        # Transaction from
        # https://blockchain.info/tx/901a53e7a3ca96ed0b733c0233aad15f11b0c9e436294aa30c367bf06c3b7be8
        # From 133t to 1KKKK
        privateKey = keyUtils.wifToPrivateKey(
            "5Kb6aGpijtrb8X28GzmWtbcGZCG8jHQWFJcWugqo3MwKRvC8zyu")  #133t

        signed_txn = makeSignedTransaction(
            privateKey,
            "c39e394d41e6be2ea58c2d3a78b8c644db34aeff865215c633fe6937933078a9",  # output (prev) transaction hash
            0,  # sourceIndex
            keyUtils.addrHashToScriptPubKey(
                "133txdxQmwECTmXqAr9RWNHnzQ175jGb7e"),
            [
                [
                    24321,  #satoshis
                    keyUtils.addrHashToScriptPubKey(
                        "1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa")
                ],
                [
                    20000,
                    keyUtils.addrHashToScriptPubKey(
                        "15nhZbXnLMknZACbb3Jrf1wPCD9DWAcqd7")
                ]
            ])

        verifyTxnSignature(signed_txn)
コード例 #2
0
ファイル: txnUtils.py プロジェクト: shirriff/bitcoin-code
    def test_makeSignedTransaction(self):
        # Transaction from
        # https://blockchain.info/tx/901a53e7a3ca96ed0b733c0233aad15f11b0c9e436294aa30c367bf06c3b7be8
        # From 133t to 1KKKK
        privateKey = keyUtils.wifToPrivateKey("5Kb6aGpijtrb8X28GzmWtbcGZCG8jHQWFJcWugqo3MwKRvC8zyu") #133t

        signed_txn = makeSignedTransaction(privateKey,
            "c39e394d41e6be2ea58c2d3a78b8c644db34aeff865215c633fe6937933078a9", # output (prev) transaction hash
            0, # sourceIndex
            keyUtils.addrHashToScriptPubKey("133txdxQmwECTmXqAr9RWNHnzQ175jGb7e"),
            [[24321, #satoshis
            keyUtils.addrHashToScriptPubKey("1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa")],
             [20000,            keyUtils.addrHashToScriptPubKey("15nhZbXnLMknZACbb3Jrf1wPCD9DWAcqd7")]]
            )

        verifyTxnSignature(signed_txn)
コード例 #3
0
    def test_makeSignedTransaction(self):
        privateKey = keyUtils.wifToPrivateKey(
            "5KawhzxJoVhw1hw75WTtXPUtsLVXFHLYZXDAWGRQxo597X4EwFX")

        signed_txn = makeSignedTransaction(
            privateKey,
            "c39e394d41e6be2ea58c2d3a78b8c644db34aeff865215c633fe6937933078a9",  # output (prev) transaction hash
            0,
            keyUtils.addrHashToScriptPubKey(
                "167WXe5yJXqsX8bcmPUMR3CzMib89NU3da"),  #input address
            [[
                00001,
                keyUtils.addrHashToScriptPubKey(
                    "1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa")
            ]  #output address
             #,           [20000,
             #           keyUtils.addrHashToScriptPubKey("15nhZbXnLMknZACbb3Jrf1wPCD9DWAcqd7")]
             ])
        showTxn(signed_txn)
コード例 #4
0
import utils
import keyUtils
import txnUtils

privateKey = keyUtils.wifToPrivateKey(
    "5HusYj2b2x4nroApgfvaSfKYZhRbKFH41bVyPooymbC6KfgSXdD")  #1MMMM

signed_txn = txnUtils.makeSignedTransaction(
    privateKey,
    "81b4c832d70cb56ff957589752eb4125a4cab78a25a8fc52d6a09e5bd4404d48",  # output (prev) transaction hash
    0,  # sourceIndex
    keyUtils.addrHashToScriptPubKey("1MMMMSUb1piy2ufrSguNUdFmAcvqrQF8M5"),
    [[
        91234,  #satoshis
        keyUtils.addrHashToScriptPubKey("1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa")
    ]])

txnUtils.verifyTxnSignature(signed_txn)
print 'SIGNED TXN', signed_txn
コード例 #5
0
print "privateKey", [privateKey]

# signed_txn = makeSignedTransaction(privateKey,
#         "c0e9e5a845cf222cc78220685fcc295db73608c64bde5d32689ef85e27c72fb5", # output (prev) transaction hash
#         0, # sourceIndex
#         keyUtils.addrHashToScriptPubKey("mxh1vzqUYPT3Udi8c7u2Gu62uj3CnQX5cG"),
#         [[30000000, #satoshis
#           keyUtils.addrHashToScriptPubKey("mrWrZGUatJUdcuF3hcnQSjZVcLaw3g1VAi")],
#          [550000000,
#           keyUtils.addrHashToScriptPubKey("mxh1vzqUYPT3Udi8c7u2Gu62uj3CnQX5cG")]]
#         )
signed_txn = makeSignedTransaction(
    privateKey,
    "73cb8c38c3f0ea7a022bc3d93a78d2b45fc2ed0b44664c17c0225c59f06f490d",  # output (prev) transaction hash
    0,  # sourceIndex
    keyUtils.addrHashToScriptPubKey("myskqqCrQtvfMDS7nwyrbvm71dCtNzCybU"),
    [
        [
            149000000,  #satoshis
            keyUtils.addrHashToScriptPubKey(
                "myskqqCrQtvfMDS7nwyrbvm71dCtNzCybU")
        ],
        [
            100000000,
            keyUtils.addrHashToScriptPubKey(
                "n2zpHDvYkFucM7XP8UdYMMKyq4L18UThf2")
        ]
    ])

print signed_txn
コード例 #6
0
ファイル: tester.py プロジェクト: gitonio/bitcoin-code
my_list = [0,17, 34, 51, 68,85,102,119,-120,-103,-86,-69,-52,-35,-18,-1]
digits = "0123456789abcdef"
for nums in my_list:
    print(nums, nums&0xff, nums&0xff >>4, (nums&0xff)&0xf, digits[nums&0xff >>4], digits[(nums&0xff)&0xf],0xff >>4, 0xf )











keyUtils.addrHashToScriptPubKey("mwAnSj8gvAkDHbW5wTN67DRQETdmTVDdHz").decode()
keyUtils.addrHashToScriptPubKey("moRsbz4GMe99KFSzq8XsSfkS2gmPfQ3GpC").decode()
k=keyUtils.wifToPrivateKey("5J3mBbAH58CpQ3Y5RNJpUKPE62SQ5tfcvU2JpbnkeyhfsYB1Jcn")
print('privk ', codecs.encode(k,'hex').decode().upper())
print('pk', keyUtils.privateKeyToPublicKey(codecs.encode(k,'hex').decode()) )
pk = keyUtils.privateKeyToPublicKey(codecs.encode(k,'hex').decode()) 
print('pubk ',  codecs.encode(pk, 'hex').decode() )

print('addr ', keyUtils.keyToAddr("754580de93eea21579441b58e0c9b09f54f6005fc71135f5cfac027394b22caa"))


k=keyUtils.wifToPrivateKey("KzTg2wn6Z8s7ai5NA9MVX4vstHRsqP26QKJCzLg4JvFrp6mMaGB9")
print('privk ', codecs.encode(k,'hex').decode().upper())
#print('pk', keyUtils.privateKeyToPublicKey(codecs.encode(k,'hex').decode()) )
pk = keyUtils.privateKeyToPublicKey(codecs.encode(k,'hex').decode()) 
print('pubk ',  codecs.encode(pk, 'hex').decode() )
コード例 #7
0
	#Crear una transaccion a manopla

	# Lista de las outputs no gastadas: (UTXO)
	#https://blockchain.info/unspent?address=<Direccion bitcoin>
	#https://blockchain.info/unspent?address=17uTeJWWH1LVuMkTwvsv9oJebDn9C4biCG


	#Armando los inputs
	#Tomar tx_hash_big_endian
	output_transaction_hash = "f71b711388d3e19343cd3a895a27246ce6b4ae69b2bbe265a1d39ccc826065c0" 

	sourceIndex = 1

	#Armando los outputs
	destination_address = "14hNkmnypQ4yns5nyj8KLh6mysNxr7XGHi"
	scriptPubKeyDestination = keyUtils.addrHashToScriptPubKey(destination_address) #calcula el scriptPubKey
	satoshis_output = 205305 #satoshi = 20.5305 mBTC, desde la lista de UTXO
	fee_transaction = 10000 #satoshi = 0.0001 BTC
	satoshi_destination_amount = satoshis_output-fee_transaction
	#OJO: bien calcular el vuelto sino el minero se queda con la diferencia!!!

	outputs = [[satoshi_destination_amount,scriptPubKeyDestination]] #Podrian haber mas

	#Armando la transaccion no firmada
	scriptPubKeyPreviousOutput = keyUtils.addrHashToScriptPubKey(bitcoin_address)
	transaction_no_firmada = txnUtils.makeRawTransaction(output_transaction_hash , 
												sourceIndex, 
												scriptPubKeyPreviousOutput,  
												outputs) + "01000000" # hash code

	#ENREDO => como firmar la transaccion si la transaccion ya tiene la firma... 
コード例 #8
0
print "Sender's Public Key: ", pubKey

#public keys is hashed
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(hashlib.sha256(pubKey.decode('hex')).digest())
digest = (ripemd160.digest()).encode('hex')
print "Digest:", digest  #167c74f7491fe552ce9e1912810a984355b8ee07

#scriptPubKey from hash public key
scriptPubKey = '76a914' + digest + '88ac'

#public key is hashed and then base58 encoded
publKeyToAddress = utils.base58CheckEncode(0, digest.decode('hex'))
pubKeyToAddress = keyUtils.pubKeyToAddr(pubKey)
print "publKeyToAddress: ", publKeyToAddress  #133txdxQmwECTmXqAr9RWNHnzQ175jGb7e
print "pubKeyToAddress:  ", pubKeyToAddress  #133txdxQmwECTmXqAr9RWNHnzQ175jGb7e

signed_txn = txnUtils.makeSignedTransaction(
    privateKey, outputTransactionHash, 0, scriptPubKey,
    [[00001, keyUtils.addrHashToScriptPubKey(addrHash)]])

txnBuffer.append(signed_txn)
#fo = open("txnBuffer.txt","wb")
#for item in txnBuffer:
#  fo.write("%s\n" % item)

#itemlist = ['a','b','c']

with open('txnBuffer.txt', 'wb') as fp:
    pickle.dump(txnBuffer, fp)
コード例 #9
0
import keyUtils
import txnUtils


privateKey = keyUtils.wifToPrivateKey("5HusYj2b2x4nroApgfvaSfKYZhRbKFH41bVyPooymbC6KfgSXdD")  # 1MMMM

signed_txn = txnUtils.makeSignedTransaction(privateKey,
                                            "81b4c832d70cb56ff957589752eb4125a4cab78a25a8fc52d6a09e5bd4404d48",
                                            # output (prev) transaction hash
                                            0,  # sourceIndex
                                            keyUtils.addrHashToScriptPubKey("1MMMMSUb1piy2ufrSguNUdFmAcvqrQF8M5"),
                                            [[91234,  # satoshis
                                              keyUtils.addrHashToScriptPubKey("1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa")]]
)

txnUtils.verifyTxnSignature(signed_txn)
print 'SIGNED TXN', signed_txn
コード例 #10
0
import utils
import keyUtils
import txnUtils
import codecs
import binascii

privateKey = codecs.encode(keyUtils.wifToPrivateKey("5HusYj2b2x4nroApgfvaSfKYZhRbKFH41bVyPooymbC6KfgSXdD"),'hex').decode() #1MMMM
print('privateKey', privateKey)
signed_txn = txnUtils.makeSignedTransaction( privateKey,
        "81b4c832d70cb56ff957589752eb4125a4cab78a25a8fc52d6a09e5bd4404d48", # output (prev) transaction hash
        0, # sourceIndex
        keyUtils.addrHashToScriptPubKey("1MMMMSUb1piy2ufrSguNUdFmAcvqrQF8M5", net='main', compressed='no').decode(),
        [[91234, #satoshis
        keyUtils.addrHashToScriptPubKey("1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa", net='main', compressed='no').decode()]]
        )
    
txnUtils.verifyTxnSignature(signed_txn)
print ('SIGNED TXN', signed_txn)




コード例 #11
0
import utils, codecs, struct, hashlib, base58, keyUtils, binascii, ecdsa, txnUtils

my_list = [
    0, 17, 34, 51, 68, 85, 102, 119, -120, -103, -86, -69, -52, -35, -18, -1
]
digits = "0123456789abcdef"
for nums in my_list:
    print(nums, nums & 0xff, nums & 0xff >> 4, (nums & 0xff) & 0xf,
          digits[nums & 0xff >> 4], digits[(nums & 0xff) & 0xf], 0xff >> 4,
          0xf)

keyUtils.addrHashToScriptPubKey("mwAnSj8gvAkDHbW5wTN67DRQETdmTVDdHz").decode()
keyUtils.addrHashToScriptPubKey("moRsbz4GMe99KFSzq8XsSfkS2gmPfQ3GpC").decode()
k = keyUtils.wifToPrivateKey(
    "5J3mBbAH58CpQ3Y5RNJpUKPE62SQ5tfcvU2JpbnkeyhfsYB1Jcn")
print('privk ', codecs.encode(k, 'hex').decode().upper())
print('pk', keyUtils.privateKeyToPublicKey(codecs.encode(k, 'hex').decode()))
pk = keyUtils.privateKeyToPublicKey(codecs.encode(k, 'hex').decode())
print('pubk ', codecs.encode(pk, 'hex').decode())

print(
    'addr ',
    keyUtils.keyToAddr(
        "754580de93eea21579441b58e0c9b09f54f6005fc71135f5cfac027394b22caa"))

k = keyUtils.wifToPrivateKey(
    "KzTg2wn6Z8s7ai5NA9MVX4vstHRsqP26QKJCzLg4JvFrp6mMaGB9")
print('privk ', codecs.encode(k, 'hex').decode().upper())
#print('pk', keyUtils.privateKeyToPublicKey(codecs.encode(k,'hex').decode()) )
pk = keyUtils.privateKeyToPublicKey(codecs.encode(k, 'hex').decode())
print('pubk ', codecs.encode(pk, 'hex').decode())
コード例 #12
0
privateKey = codecs.encode(
    keyUtils.wifToPrivateKey(
        "cQFK8Vqwanamn194EscN3zUMyvPTVc39Dubx5BYccvjXjrwS9mBG"),
    'hex').decode()  #1MMMM
privateKey = codecs.encode(
    keyUtils.wifToPrivateKey(
        "92BwrjLFBNf1dUfyvSWmC6miTVQfdPSQcYrc8kAt7nFcy3JDoL8"),
    'hex').decode()  #1MMMM
print('privateKey: ', privateKey)  #1MMMM
#F01E3C2210E1DD106399CD20D2D059412EEC856ABB3AD63E66749F24B6AA9DF
signed_txn = txnUtils.makeSignedTransaction(
    privateKey,
    "acf7496e7262fb977e78bd3c0692722b428bf828c8c2033caa859f8ed582f8b1",  # output (prev) transaction hash
    0,  # sourceIndex
    keyUtils.addrHashToScriptPubKey("muwc2rRij1XuJZ5JqsevtjCvqMw9CenJfK",
                                    net='test',
                                    compressed='yes').decode(),
    #keyUtils.addrHashToScriptPubKey("mpCWzuKvmqHSoyPo3BQzsaSSp3hqqZEfic", net='test', compressed='no').decode(), #Source of funds
    [[
        100000,  #satoshis
        keyUtils.addrHashToScriptPubKey("n22NLZeQMATUChs2BDPrKC8RJbgHTewjm7",
                                        net='test',
                                        compressed='yes').decode()
    ]],
    net='test',  #Destination of funds
    #keyUtils.addrHashToScriptPubKey("mtv5Zge8zK8r3UCb1ZVC5P3JkDccJEEB21", net='test', compressed='no').decode()]],net='test',
    compressed='yes')

#txnUtils.verifyTxnSignature(signed_txn)
print('SIGNED TXN', signed_txn)
コード例 #13
0
import utils
import keyUtils
import txnUtils
import codecs
import binascii

privateKey = codecs.encode(
    keyUtils.wifToPrivateKey(
        "5HusYj2b2x4nroApgfvaSfKYZhRbKFH41bVyPooymbC6KfgSXdD"),
    'hex').decode()  #1MMMM
print('privateKey', privateKey)
signed_txn = txnUtils.makeSignedTransaction(
    privateKey,
    "81b4c832d70cb56ff957589752eb4125a4cab78a25a8fc52d6a09e5bd4404d48",  # output (prev) transaction hash
    0,  # sourceIndex
    keyUtils.addrHashToScriptPubKey("1MMMMSUb1piy2ufrSguNUdFmAcvqrQF8M5",
                                    net='main',
                                    compressed='no').decode(),
    [[
        91234,  #satoshis
        keyUtils.addrHashToScriptPubKey("1KKKK6N21XKo48zWKuQKXdvSsCf95ibHFa",
                                        net='main',
                                        compressed='no').decode()
    ]])

txnUtils.verifyTxnSignature(signed_txn)
print('SIGNED TXN', signed_txn)
コード例 #14
0
import utils
import keyUtils
import txnUtils
import codecs
import binascii

privateKey = codecs.encode(keyUtils.wifToPrivateKey("cQFK8Vqwanamn194EscN3zUMyvPTVc39Dubx5BYccvjXjrwS9mBG"),'hex').decode() #1MMMM
privateKey = codecs.encode(keyUtils.wifToPrivateKey("92BwrjLFBNf1dUfyvSWmC6miTVQfdPSQcYrc8kAt7nFcy3JDoL8"),'hex').decode() #1MMMM
print('privateKey: ', privateKey)  #1MMMM
#F01E3C2210E1DD106399CD20D2D059412EEC856ABB3AD63E66749F24B6AA9DF
signed_txn = txnUtils.makeSignedTransaction(privateKey,
        "acf7496e7262fb977e78bd3c0692722b428bf828c8c2033caa859f8ed582f8b1", # output (prev) transaction hash
        0, # sourceIndex
        keyUtils.addrHashToScriptPubKey("muwc2rRij1XuJZ5JqsevtjCvqMw9CenJfK", net='test', compressed='yes').decode(),
        #keyUtils.addrHashToScriptPubKey("mpCWzuKvmqHSoyPo3BQzsaSSp3hqqZEfic", net='test', compressed='no').decode(), #Source of funds
        [[100000, #satoshis
        keyUtils.addrHashToScriptPubKey("n22NLZeQMATUChs2BDPrKC8RJbgHTewjm7", net='test', compressed='yes').decode()]],net='test', #Destination of funds
        #keyUtils.addrHashToScriptPubKey("mtv5Zge8zK8r3UCb1ZVC5P3JkDccJEEB21", net='test', compressed='no').decode()]],net='test',
        compressed='yes'
        )
    
#txnUtils.verifyTxnSignature(signed_txn)
print ('SIGNED TXN', signed_txn)