-
-
Save JonnyLatte/6d43bb674d736afa39208f7982e299fc to your computer and use it in GitHub Desktop.
Tezos fundraiser python experiments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bitcoin | |
from pyblake2 import blake2b | |
import py2specials | |
import hashlib | |
def foundation_bitcoin_keys(): | |
return [ | |
'\x02\xc0T!\xaa\x00\x13\xee\xd38T#\xb6<\xd2\x89' + | |
'\xc3BR\x118\xaa\xffj\x91U\xb3\xc7\xc8t\xc3\x1e\xa9', | |
'\x03\xb3\xb1|\xe2\x13\xe4\xed\xb9\xf1\x7f\x0e\x11' + | |
'\xf5h\x80\xa8\x96r\xd2 4\x83\xbb\x7fu\xb1\x1a%_\x08\xdc\x96' | |
] | |
def fundraiser_script(tezos_pkh): | |
return bitcoin.serialize_script([tezos_pkh, 117, 2] + foundation_bitcoin_keys() + [2, 174]) | |
def fundraiser_address(tezos_pkh): | |
return bitcoin.p2sh_scriptaddr(fundraiser_script(tezos_pkh)) | |
def fundraiser_160(tezos_pkh): | |
return bitcoin.bin_hash160(fundraiser_script(tezos_pkh)) | |
def tz_pkh_2_address(tezos_pkh): | |
return py2specials.bin_to_b58check(digest,magicbyte=434591) | |
def tz_address_2_pkh(address): | |
return py2specials.changebase(address, 58,256)[3:23] | |
def tz_address_2_fundraiser_address(address): | |
return fundraiser_address(tz_address_2_pkh(address)) | |
def tz_address_2_fundraiser_160(address): | |
return fundraiser_160(tz_address_2_pkh(address)) | |
#--------------------------------------------------- | |
# tests | |
def t1(): | |
print 'Testing a fundraiser hash160 is equal to the base58 encoded address hash of the same' | |
tezos_pkh = '0000000000000000000000000000000000000000'.decode('hex') | |
if fundraiser_address(tezos_pkh) == py2specials.bin_to_b58check(fundraiser_160(tezos_pkh),5): | |
print 'Pass' | |
else: | |
print 'Fail' | |
print '\n' | |
def t2(): | |
print 'Demonstrating how fundraiser payment script bytes are packed:' | |
print fundraiser_script('0000000000000000000000000000000000000000'.decode('hex')).encode('hex') | |
print fundraiser_script('1111111111111111111111111111111111111111'.decode('hex')).encode('hex') | |
print '\n' | |
def t3(): | |
print 'Testing dummy allocation mapping' | |
# generate fundraiser payment address / 160 values for 'unknown' tezos public key hashes: | |
#print fundraiser_160('0000000000000000000000000000000000000001'.decode('hex')).encode('hex') | |
#print fundraiser_160('0000000000000000000000000000000000000002'.decode('hex')).encode('hex') | |
#print fundraiser_160('0000000000000000000000000000000000000003'.decode('hex')).encode('hex') | |
#print fundraiser_160('0000000000000000000000000000000000000004'.decode('hex')).encode('hex') | |
allocations = { | |
'4917f875eed47f7c0b9eafe6527c32b2bb4b6d23'.decode('hex'):1, | |
'd048f95b82c784ab66277ad5b2b932822655cb9e'.decode('hex'):2, | |
'b487f4b286f82d96aa0540c02e8d765760aedff3'.decode('hex'):3, | |
'e2d133eeef2f8c76da487da743a423164f9aa919'.decode('hex'):4 | |
} | |
def getAllocation(tzpkh): | |
return allocations[fundraiser_160(tzpkh)] | |
pkh1 = '0000000000000000000000000000000000000002'.decode('hex') | |
print 'User submitted pkh: ' + pkh1.encode('hex') | |
print 'This resolves to payment address ' + fundraiser_address(pkh1) + " / not needed on chain " | |
print 'With hash160: ' + fundraiser_160(pkh1).encode('hex') | |
print 'User Funds in dummy allocation: ' , getAllocation(pkh1) | |
t2() | |
t3() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment