You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.6 KiB
Python
71 lines
1.6 KiB
Python
11 years ago
|
import trezor_pb2 as proto
|
||
12 years ago
|
|
||
|
map_type_to_class = {
|
||
11 years ago
|
0: proto.Initialize,
|
||
|
1: proto.Ping,
|
||
|
2: proto.Success,
|
||
|
3: proto.Failure,
|
||
11 years ago
|
#4: proto.GetUID,
|
||
|
#5: proto.UUID,
|
||
11 years ago
|
9: proto.GetEntropy,
|
||
|
10: proto.Entropy,
|
||
|
11: proto.GetMasterPublicKey,
|
||
|
12: proto.MasterPublicKey,
|
||
|
13: proto.LoadDevice,
|
||
|
14: proto.ResetDevice,
|
||
|
15: proto.SignTx,
|
||
11 years ago
|
16: proto.SimpleSignTx,
|
||
11 years ago
|
17: proto.Features,
|
||
|
18: proto.PinMatrixRequest,
|
||
|
19: proto.PinMatrixAck,
|
||
|
20: proto.PinMatrixCancel,
|
||
|
21: proto.TxRequest,
|
||
|
# 22: proto.OutputRequest,
|
||
|
23: proto.TxInput,
|
||
|
24: proto.TxOutput,
|
||
11 years ago
|
25: proto.ApplySettings,
|
||
11 years ago
|
26: proto.ButtonRequest,
|
||
|
27: proto.ButtonAck,
|
||
|
28: proto.ButtonCancel,
|
||
|
29: proto.GetAddress,
|
||
|
30: proto.Address,
|
||
11 years ago
|
31: proto.SettingsType,
|
||
|
32: proto.XprvType,
|
||
|
33: proto.CoinType,
|
||
11 years ago
|
100: proto.DebugLinkDecision,
|
||
|
101: proto.DebugLinkGetState,
|
||
|
102: proto.DebugLinkState,
|
||
|
103: proto.DebugLinkStop,
|
||
12 years ago
|
}
|
||
|
|
||
|
map_class_to_type = {}
|
||
|
|
||
11 years ago
|
|
||
12 years ago
|
def get_type(msg):
|
||
|
return map_class_to_type[msg.__class__]
|
||
|
|
||
11 years ago
|
|
||
12 years ago
|
def get_class(t):
|
||
|
return map_type_to_class[t]
|
||
|
|
||
11 years ago
|
|
||
12 years ago
|
def build_index():
|
||
|
for k, v in map_type_to_class.items():
|
||
|
map_class_to_type[v] = k
|
||
11 years ago
|
|
||
|
|
||
12 years ago
|
def check_missing():
|
||
|
from google.protobuf import reflection
|
||
11 years ago
|
|
||
|
types = [proto.__dict__[item] for item in dir(proto)
|
||
|
if issubclass(proto.__dict__[item].__class__, reflection.GeneratedProtocolMessageType)]
|
||
|
|
||
12 years ago
|
missing = list(set(types) - set(map_type_to_class.values()))
|
||
|
|
||
|
if len(missing):
|
||
|
raise Exception("Following protobuf messages are not defined in mapping: %s" % missing)
|
||
|
|
||
11 years ago
|
|
||
12 years ago
|
check_missing()
|
||
|
build_index()
|