forked from keepkey/python-keepkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmayachain.py
More file actions
57 lines (49 loc) · 1.38 KB
/
Copy pathmayachain.py
File metadata and controls
57 lines (49 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import base64
import schema
import copy
tx_schema = schema.Schema({
"tx": schema.Schema({
"fee": schema.Schema({
"amount": schema.Schema([{
"denom": "cacao",
"amount": str
}]),
"gas": str
}),
"memo": str,
# NOTE: this needs to be 'msgs' when signing, but 'msg' when broadcasting.
"msg": schema.Schema([{
"type": "mayachain/MsgSend",
"value": schema.Schema({
"from_address": str,
"to_address": str,
"amount": schema.Schema([{
"denom": str,
"amount": str
}])
})
}]),
schema.Optional("signatures"): None,
}),
"type": "cosmos-sdk/StdTx",
"mode": "sync"
})
def mayachain_parse_tx(tx):
validated = tx_schema.validate(tx)
stdtx = validated['tx']
return {
'fee': stdtx['fee']['amount'][0]['amount'],
'gas': stdtx['fee']['gas'],
'msgs': stdtx['msg'],
'memo': stdtx['memo']
}
def mayachain_append_sig(tx, public_key, signature):
tx = copy.deepcopy(tx)
tx['tx']['signatures'] = [{
"pub_key": {
"type": "tendermint/PubKeySecp256k1",
"value": base64.b64encode(public_key)
},
"signature": base64.b64encode(signature)
}]
return tx