mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 23:48:12 +00:00
defs: generate wip coindefs in defs/coins/combine.py
This commit is contained in:
parent
7e39981133
commit
f20e374fcc
2
defs/.gitignore
vendored
2
defs/.gitignore
vendored
@ -1 +1 @@
|
|||||||
coins.json
|
*.json
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
import json
|
import json
|
||||||
import glob
|
import glob
|
||||||
import re
|
import re
|
||||||
|
from hashlib import sha256
|
||||||
|
import ed25519
|
||||||
|
|
||||||
|
|
||||||
def check_type(val, types, nullable=False, empty=False, regex=None, choice=None):
|
def check_type(val, types, nullable=False, empty=False, regex=None, choice=None):
|
||||||
@ -78,18 +80,36 @@ def validate_coin(coin):
|
|||||||
assert not bc.endswith('/')
|
assert not bc.endswith('/')
|
||||||
|
|
||||||
|
|
||||||
|
def serialize(coin):
|
||||||
|
# TODO: replace with protobuf serialization
|
||||||
|
return json.dumps(coin).encode()
|
||||||
|
|
||||||
|
|
||||||
|
def sign(data):
|
||||||
|
h = sha256(data).digest()
|
||||||
|
sign_key = ed25519.SigningKey(b'A' * 32)
|
||||||
|
return sign_key.sign(h)
|
||||||
|
|
||||||
|
|
||||||
def process_json(fn):
|
def process_json(fn):
|
||||||
print(fn, end=' ... ')
|
print(fn, end=' ... ')
|
||||||
j = json.load(open(fn))
|
j = json.load(open(fn))
|
||||||
validate_coin(j)
|
validate_coin(j)
|
||||||
|
ser = serialize(j)
|
||||||
|
sig = sign(ser)
|
||||||
|
definition = (sig + ser).hex()
|
||||||
print('OK')
|
print('OK')
|
||||||
return j
|
return j, definition
|
||||||
|
|
||||||
|
|
||||||
coins = {}
|
coins = {}
|
||||||
|
defs = {}
|
||||||
for fn in glob.glob('*.json'):
|
for fn in glob.glob('*.json'):
|
||||||
c = process_json(fn)
|
c, d = process_json(fn)
|
||||||
n = c['coin_name']
|
n = c['coin_name']
|
||||||
coins[n] = c
|
coins[n] = c
|
||||||
|
defs[n] = d
|
||||||
|
|
||||||
|
|
||||||
json.dump(coins, open('../coins.json', 'w'), indent=4, sort_keys=True)
|
json.dump(coins, open('../coins.json', 'w'), indent=4, sort_keys=True)
|
||||||
|
json.dump(defs, open('../coindefs.json', 'w'), indent=4, sort_keys=True)
|
||||||
|
@ -22,8 +22,8 @@ message CoinDef {
|
|||||||
optional uint32 fork_id = 20;
|
optional uint32 fork_id = 20;
|
||||||
optional bool force_bip143 = 21;
|
optional bool force_bip143 = 21;
|
||||||
optional uint64 dust_limit = 22;
|
optional uint64 dust_limit = 22;
|
||||||
optional uint32 blocktime_seconds = 23;
|
optional string address_prefix = 23;
|
||||||
optional string address_prefix = 24;
|
optional uint32 min_address_length = 24;
|
||||||
optional uint32 min_address_length = 25;
|
optional uint32 max_address_length = 25;
|
||||||
optional uint32 max_address_length = 26;
|
optional bytes icon = 26;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user