|
10 | 10 | import six # for python2 back-compatibility in printing messages using print as a function |
11 | 11 | import random |
12 | 12 | import sys |
| 13 | +import os |
13 | 14 |
|
14 | 15 | version = 2 # API version |
15 | 16 |
|
16 | 17 | # use a testnet api key here, say, dogecoin |
17 | | -block_io = BlockIo('Your API Key', 'Your Secret PIN', version) |
| 18 | +block_io = BlockIo(os.environ.get('BLOCK_IO_API_KEY'), os.environ.get('BLOCK_IO_PIN'), version) |
18 | 19 | getcontext().prec = 8 # coins are 8 decimal places at most |
19 | 20 |
|
20 | 21 | # create a new address with a random label |
21 | 22 | address_label = 'dtrust'+str(int(random.random()*10000)) |
22 | 23 |
|
23 | 24 | # create the key objects for each private key |
24 | | -keys = [ BlockIo.Key.from_passphrase('alpha1alpha2alpha3alpha4'), BlockIo.Key.from_passphrase('alpha2alpha3alpha4alpha1'), BlockIo.Key.from_passphrase('alpha3alpha4alpha1alpha2'), BlockIo.Key.from_passphrase('alpha4alpha1alpha2alpha3') ] |
| 25 | +keys = [ BlockIo.Key.from_passphrase('alpha1alpha2alpha3alpha4'.encode('utf-8')), BlockIo.Key.from_passphrase('alpha2alpha3alpha4alpha1'.encode('utf-8')), BlockIo.Key.from_passphrase('alpha3alpha4alpha1alpha2'.encode('utf-8')), BlockIo.Key.from_passphrase('alpha4alpha1alpha2alpha3'.encode('utf-8')) ] |
25 | 26 |
|
26 | 27 | pubkeys = [] |
27 | 28 |
|
28 | 29 | for key in keys: |
29 | | - pubkeys.insert(len(pubkeys), key.pubkey_hex()) |
| 30 | + pubkeys.insert(len(pubkeys), key.pubkey_hex().decode("utf-8")) |
30 | 31 | six.print_(key.pubkey_hex()) |
31 | 32 |
|
32 | 33 | # create a dTrust address that requires 4 out of 5 keys (4 of ours, 1 at Block.io). |
33 | 34 | # Block.io automatically adds +1 to specified required signatures because of its own key |
34 | 35 |
|
35 | | -print "* Creating a new 4 of 5 MultiSig address for DOGETEST" |
| 36 | +six.print_("* Creating a new 4 of 5 MultiSig address for DOGETEST") |
36 | 37 | six.print_(','.join(str(x) for x in pubkeys)) |
37 | 38 | response = block_io.get_new_dtrust_address(label=address_label,public_keys=','.join(str(x) for x in pubkeys),required_signatures=3) |
38 | 39 |
|
|
89 | 90 | # sign the withdrawal request, one signature at a time |
90 | 91 |
|
91 | 92 | for key in keys: |
| 93 | + |
| 94 | + pub_hex = key.pubkey_hex().decode("utf-8") |
92 | 95 |
|
93 | 96 | for input in response['data']['inputs']: |
94 | 97 |
|
|
97 | 100 | # find the object to put our signature in |
98 | 101 | for signer in input['signers']: |
99 | 102 |
|
100 | | - if signer['signer_public_key'] == key.pubkey_hex(): |
| 103 | + if signer['signer_public_key'] == pub_hex: |
101 | 104 | # found it, let's add the signature to this object |
102 | | - signer['signed_data'] = key.sign_hex(data_to_sign) |
| 105 | + signer['signed_data'] = key.sign_hex(data_to_sign).decode("utf-8") |
103 | 106 |
|
104 | | - six.print_("* Data Signed By:", key.pubkey_hex()) |
| 107 | + six.print_("* Data Signed By:", pub_hex) |
105 | 108 |
|
106 | 109 | # let's have Block.io record this signature we just created |
107 | 110 | block_io.sign_transaction(signature_data=json.dumps(response['data'])) |
108 | | - six.print_(">> Signatures relayed to Block.io for Public Key=", key.pubkey_hex()) |
| 111 | + six.print_(">> Signatures relayed to Block.io for Public Key=", pub_hex) |
109 | 112 |
|
110 | 113 | # finalize the transaction now that's it been signed by all our keys |
111 | 114 | six.print_("* Finalizing transaction") |
|
0 commit comments