import bitcoind import base58 from crypto import Key from bitcoinutils import sendToMultiSigPubKey from bitcoinutils import makeSpendMultiSigTransaction, signMultiSigTransaction, applyMultiSigSignatures s = settings.Settings("../amikopay.conf") d = bitcoind.Bitcoind(s) #(these addresses are mine - thanks for donating :-P) keyHash1 = binascii.unhexlify("fd5627c5eff58991dec54877272e82f758ea8b65") keyHash2 = binascii.unhexlify("ab22c699d3e72f2c1e4896508bf9d8d7910104d0") address1 = base58.encodeBase58Check(keyHash1, 0) address2 = base58.encodeBase58Check(keyHash2, 0) print address1 print address2 #Note: this will fail, unless you change toe above addresses to some of your own privKey1 = base58.decodeBase58Check(d.getPrivateKey(address1), 128) privKey2 = base58.decodeBase58Check(d.getPrivateKey(address2), 128) key1 = Key() key1.setPrivateKey(privKey1) key2 = Key() key2.setPrivateKey(privKey2) print key1.getPublicKey().encode("hex") print key2.getPublicKey().encode("hex")
def getTraditionalAddress(key): publicKeyHash = RIPEMD160(SHA256(key.getPublicKey())) return base58.encodeBase58Check(publicKeyHash, 0) #PUBKEY_ADDRESS = 0
import base58 # translate Bitpay address format to traditional address format bitpay_address = 'CQ6BSmiDScwR3HX3pLaDdMjcMdz8byfKRo' public_key_hash = base58.decodeBase58Check(bitpay_address,28) trad_address = base58.encodeBase58Check(public_key_hash,0) print "Traditional Address: ", trad_address
def decode(args): s = args[0] amounts = [int(decimal.Decimal(a) * BCC) for a in args[1:]] serialized = binascii.unhexlify(s) tx = btx.Transaction.deserialize(serialized) print 'lockTime: ', tx.lockTime for i in range(len(tx.tx_in)): tx_in = tx.tx_in[i] print 'TxIn:' print ' amount: %s BCC' % str(decimal.Decimal(amounts[i]) / BCC) print ' prevOutputHash: ', tx_in.previousOutputHash.encode("hex") print ' prevOutputIndex: ', tx_in.previousOutputIndex print ' sequenceNumber: 0x%08x' % tx_in.sequenceNumber print ' script:' for e in tx_in.scriptSig.elements: if isinstance(e, str): s = e.encode("hex") else: s = str(e) print ' ', s signature, pubKey = tx_in.scriptSig.elements hashType = ord(signature[-1]) signature = signature[:-1] k = Key() k.setPublicKey(pubKey) address = getAddress(k) hash = base58.decodeBase58Check(address, 0) #PUBKEY_ADDRESS = 0 scriptPubKey = btx.Script.standardPubKey(hash) sigHash = tx.getSignatureBodyHash(i, scriptPubKey, hashType, amount=amounts[i]) print ' pubKey: ', pubKey.encode('hex') print ' signature: ', signature.encode('hex') print ' hashType: 0x%0x' % hashType print ' address: ', address print ' sigHash: ', sigHash.encode('hex') print ' valid: ', k.verify(sigHash, signature) print '' for tx_out in tx.tx_out: print 'TxOut:' print ' amount: %s BCC' % str(decimal.Decimal(tx_out.amount) / BCC) elements = tx_out.scriptPubKey.elements print ' script:' for e in elements: if isinstance(e, str): s = e.encode("hex") else: s = '0x%0x' % e print ' ', s if len(elements) == 5 and \ elements[0:2] == [btx.OP.DUP, btx.OP.HASH160] and \ elements[3:5] == [btx.OP.EQUALVERIFY, btx.OP.CHECKSIG] and \ isinstance(elements[2], str): address = base58.encodeBase58Check(elements[2], 0) #PUBKEY_ADDRESS = 0 print ' Address: ', address else: print ' Unrecognized script type' print '' fee = sum(amounts) - sum([tx_out.amount for tx_out in tx.tx_out]) print 'Tx fee: %s BCC' % str(decimal.Decimal(fee) / BCC)
import base58 # translate traditional address to Bitpay address format trad_address = '19oCM37SX7R7ctVPwv1pQ2RckTM3TmU9dS' public_key_hash = base58.decodeBase58Check(trad_address, 0) bitpay_address = base58.encodeBase58Check(public_key_hash, 28) print "Copay Address: ", bitpay_address