Skip to content

Commit 8c5c2f0

Browse files
author
Arjan Zijderveld
committed
Added Centrifuge type registry
1 parent 4fe452c commit 8c5c2f0

File tree

4 files changed

+75
-9
lines changed

4 files changed

+75
-9
lines changed
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"runtime_id": 198,
3+
"types": {
4+
"BlockNumber": "u32",
5+
"Index": "u64",
6+
"Keys": {
7+
"type": "struct",
8+
"type_mapping": [
9+
["grandpa", "AccountId"],
10+
["babe", "AccountId"],
11+
["im_online", "AccountId"],
12+
["authority_discovery", "AccountId"]
13+
]
14+
},
15+
"Fee<Hash, Balance>": {
16+
"type": "struct",
17+
"type_mapping": [
18+
["key", "Hash"],
19+
["price", "Balance"]
20+
]
21+
},
22+
"PreCommitData<Hash, AccountId, BlockNumber>": {
23+
"type": "struct",
24+
"type_mapping": [
25+
["signing_root", "Hash"],
26+
["identity", "AccountId"],
27+
["expiration_block", "BlockNumber"]
28+
]
29+
},
30+
"Proof": {
31+
"type": "struct",
32+
"type_mapping": [
33+
["leaf_hash", "H256"],
34+
["sorted_hashes", "Vec<H256>"]
35+
]
36+
}
37+
}
38+
}

scalecodec/types.py

+31-8
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,18 @@ def process_encode(self, value):
425425
return ScaleBytes(value)
426426

427427

428+
class VecU8Length20(ScaleType):
429+
type_string = '[u8; 20]'
430+
431+
def process(self):
432+
return '0x{}'.format(self.get_next_bytes(20).hex())
433+
434+
def process_encode(self, value):
435+
if value[0:2] != '0x' and len(value) == 42:
436+
raise ValueError('Value should start with "0x" and should be 20 bytes long')
437+
return ScaleBytes(value)
438+
439+
428440
class VecU8Length16(ScaleType):
429441
type_string = '[u8; 16]'
430442

@@ -489,6 +501,25 @@ def process_encode(self, value):
489501
return ScaleBytes(value)
490502

491503

504+
class VecH256Length3(ScaleType):
505+
type_string = '[H256; 3]'
506+
507+
def process(self):
508+
return [self.process_type('H256').value, self.process_type('H256').value, self.process_type('H256').value]
509+
510+
def process_encode(self, value):
511+
if type(value) is not list:
512+
raise ValueError("Provided value is not a list")
513+
514+
data = None
515+
516+
for element in value:
517+
element_obj = self.get_decoder_class('H256', metadata=self.metadata)
518+
data += element_obj.encode(element)
519+
520+
return data
521+
522+
492523
class Struct(ScaleType):
493524

494525
def __init__(self, data, type_mapping=None, **kwargs):
@@ -782,18 +813,10 @@ class BalanceOf(Balance):
782813
pass
783814

784815

785-
class BlockNumber(U64):
786-
pass
787-
788-
789816
class NewAccountOutcome(CompactU32):
790817
type_string = 'NewAccountOutcome'
791818

792819

793-
class Index(U64):
794-
pass
795-
796-
797820
class Vec(ScaleType):
798821

799822
def __init__(self, data=None, **kwargs):

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# For a discussion on single-sourcing the version across setup.py and the
4444
# project code, see
4545
# https://packaging.python.org/en/latest/single_source_version.html
46-
version='0.9.8', # Required
46+
version='0.9.9', # Required
4747

4848
# This is a one-line description or tagline of what your project does. This
4949
# corresponds to the "Summary" metadata field:

test/test_scale_types.py

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def test_compact_u32_remaining_bytes(self):
5252
obj = ScaleDecoder.get_decoder_class('Compact<u32>', ScaleBytes("0x02093d0001"))
5353
self.assertRaises(RemainingScaleBytesNotEmptyException, obj.decode)
5454

55+
def test_compact_u32_invalid(self):
56+
obj = ScaleDecoder.get_decoder_class('Compact<u32>', ScaleBytes("0x"))
57+
self.assertRaises(InvalidScaleTypeValueException, obj.decode)
58+
59+
5560
def test_u16(self):
5661
obj = ScaleDecoder.get_decoder_class('u16', ScaleBytes("0x2efb"))
5762
obj.decode()

0 commit comments

Comments
 (0)