scale.rb 0.2.16 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Cargo.lock +8 -4
  4. data/Cargo.toml +2 -3
  5. data/Dockerfile +4 -1
  6. data/Gemfile.lock +43 -35
  7. data/README.md +44 -1
  8. data/Rakefile +6 -0
  9. data/exe/scale +39 -79
  10. data/lib/address.rb +3 -0
  11. data/lib/common.rb +163 -0
  12. data/lib/helper.rb +25 -8
  13. data/lib/metadata/metadata.rb +28 -18
  14. data/lib/metadata/metadata_v0.rb +24 -20
  15. data/lib/metadata/metadata_v1.rb +13 -9
  16. data/lib/metadata/metadata_v10.rb +2 -2
  17. data/lib/metadata/metadata_v11.rb +2 -2
  18. data/lib/metadata/metadata_v12.rb +9 -8
  19. data/lib/metadata/metadata_v13.rb +161 -0
  20. data/lib/metadata/metadata_v2.rb +2 -2
  21. data/lib/metadata/metadata_v3.rb +2 -2
  22. data/lib/metadata/metadata_v4.rb +21 -11
  23. data/lib/metadata/metadata_v5.rb +21 -11
  24. data/lib/metadata/metadata_v6.rb +9 -9
  25. data/lib/metadata/metadata_v7.rb +26 -15
  26. data/lib/metadata/metadata_v8.rb +9 -9
  27. data/lib/metadata/metadata_v9.rb +2 -2
  28. data/lib/scale.rb +41 -341
  29. data/lib/scale/base.rb +177 -95
  30. data/lib/scale/block.rb +17 -13
  31. data/lib/scale/trie.rb +1 -1
  32. data/lib/scale/types.rb +139 -40
  33. data/lib/scale/version.rb +1 -1
  34. data/lib/scale_bytes.rb +63 -0
  35. data/lib/substrate_client.rb +31 -17
  36. data/lib/type_builder.rb +279 -0
  37. data/lib/type_registry.rb +91 -0
  38. data/lib/type_registry/crab.json +676 -595
  39. data/lib/type_registry/darwinia.json +730 -554
  40. data/lib/type_registry/default.json +3 -2
  41. data/lib/type_registry/pangolin.json +771 -0
  42. data/scale.gemspec +7 -5
  43. data/scripts/mmr_root_to_sign.rb +10 -0
  44. data/src/lib.rs +80 -25
  45. metadata +59 -30
  46. data/lib/type_registry/edgeware.json +0 -124
  47. data/lib/type_registry/joystream.json +0 -49
  48. data/lib/type_registry/kulupu.json +0 -15
  49. data/lib/type_registry/plasm.json +0 -89
  50. data/lib/type_registry/robonomics.json +0 -39
  51. data/lib/type_registry/westend.json +0 -63
  52. data/src/storage_key.rs +0 -41
@@ -1,49 +0,0 @@
1
- {
2
- "runtime_id": 4,
3
- "types": {
4
- "ValidatorPrefs": "ValidatorPrefsLegacy",
5
- "Index": "U64",
6
- "<T as DDTrait>::ContentId": "ContentId",
7
- "RoleParameters": {
8
- "type": "struct",
9
- "type_mapping": [
10
- ["min_stake", "BalanceOf"],
11
- ["min_actors", "u32"],
12
- ["max_actors", "u32"],
13
- ["reward", "BalanceOf"],
14
- ["reward_period", "BlockNumber"],
15
- ["bonding_period", "BlockNumber"],
16
- ["unbonding_period", "BlockNumber"],
17
- ["min_service_period", "BlockNumber"],
18
- ["startup_grace_period", "BlockNumber"],
19
- ["entry_request_fee", "BalanceOf"]
20
- ]
21
- },
22
- "Actor": {
23
- "type": "struct",
24
- "type_mapping": [
25
- ["member_id", "MemberId"],
26
- ["role", "Role"],
27
- ["account", "AccountId"],
28
- ["joined_at", "BlockNumber"]
29
- ]
30
- },
31
- "DataObjectStorageRelationship": {
32
- "type": "struct",
33
- "type_mapping": [
34
- ["content_id", "ContentId"],
35
- ["storage_provider", "AccountId"],
36
- ["ready", "bool"]
37
- ]
38
- },
39
- "DataObjectType": {
40
- "type": "struct",
41
- "type_mapping": [
42
- ["description", "Vec<u8>"],
43
- ["active", "bool"]
44
- ]
45
- },
46
- "DataObjectTypeId": "u64",
47
- "<T as DOTRTrait>::DataObjectTypeId": "u64"
48
- }
49
- }
@@ -1,15 +0,0 @@
1
- {
2
- "runtime_id": 3,
3
- "types": {
4
- "BlockNumber": "U32",
5
- "Weight": "u64",
6
- "DispatchInfo": {
7
- "type": "struct",
8
- "type_mapping": [
9
- ["weight", "Weight"],
10
- ["class", "DispatchClass"],
11
- ["paysFee", "Pays"]
12
- ]
13
- }
14
- }
15
- }
@@ -1,89 +0,0 @@
1
- {
2
- "types": {
3
- "Keys": {
4
- "type": "struct",
5
- "type_mapping": [
6
- ["grandpa", "AccountId"],
7
- ["babe", "AccountId"]
8
- ]
9
- },
10
- "Balance": "u128",
11
- "Index": "U32",
12
- "Era": "[u8; 2]",
13
- "BlockNumber": "U32",
14
- "Range": {
15
- "type": "struct",
16
- "type_mapping": [
17
- ["start", "u128"],
18
- ["end", "u128"]
19
- ]
20
- },
21
- "StateObject": {
22
- "type": "struct",
23
- "type_mapping": [
24
- ["predicate", "AccountId"],
25
- ["data", "Vec<u8>"]
26
- ]
27
- },
28
- "StateUpdate": {
29
- "type": "struct",
30
- "type_mapping": [
31
- ["range", "Range"],
32
- ["state_object", "StateObject"],
33
- ["plasma_block_number", "BlockNumber"]
34
- ]
35
- },
36
- "Checkpoint": {
37
- "type": "struct",
38
- "type_mapping": [
39
- ["state_update", "StateUpdate"],
40
- ["sub_range", "Range"]
41
- ]
42
- },
43
- "Transaction": {
44
- "type": "struct",
45
- "type_mapping": [
46
- ["predicate", "AccountId"],
47
- ["range", "Range"],
48
- ["body", "Range"]
49
- ]
50
- },
51
- "TransactionBody": {
52
- "type": "struct",
53
- "type_mapping": [
54
- ["new_state", "StateObject"],
55
- ["origin_block", "BlockNumber"],
56
- ["max_block", "BlockNumber"]
57
- ]
58
- },
59
- "Challenge": {
60
- "type": "struct",
61
- "type_mapping": [
62
- ["challenged_checkpoint", "Checkpoint"],
63
- ["challenging_checkpoint", "Checkpoint"]
64
- ]
65
- },
66
- "MerkleIntervalTreeInternalNode": {
67
- "type": "struct",
68
- "type_mapping": [
69
- ["index", "Index"],
70
- ["hash", "Hash"]
71
- ]
72
- },
73
- "InclusionProof": {
74
- "type": "struct",
75
- "type_mapping": [
76
- ["proofs", "Vec<MerkleIntervalTreeInternalNode>"],
77
- ["idx", "u128"]
78
- ]
79
- },
80
- "Parameters": {
81
- "type": "struct",
82
- "type_mapping": [
83
- ["can_be_nominated", "bool"],
84
- ["option_expired", "u128"],
85
- ["option_p", "u32"]
86
- ]
87
- }
88
- }
89
- }
@@ -1,39 +0,0 @@
1
- {
2
- "types": {
3
- "Keys": "SessionKeysSubstrate",
4
- "Index": "U64",
5
- "LiabilityIndex": "U64",
6
- "Order": {
7
- "type": "struct",
8
- "type_mapping": [
9
- ["models", "Vec<u8>"],
10
- ["objective", "Vec<u8>"],
11
- ["cost", "Balance"],
12
- ["custodian", "Option<AccountId>"]
13
- ]
14
- },
15
- "Offer": {
16
- "type": "struct",
17
- "type_mapping": [
18
- ["order", "Order"],
19
- ["sender", "AccountId"]
20
- ]
21
- },
22
- "Demand": {
23
- "type": "struct",
24
- "type_mapping": [
25
- ["order", "Order"],
26
- ["sender", "AccountId"]
27
- ]
28
- },
29
- "Liability": {
30
- "type": "struct",
31
- "type_mapping": [
32
- ["order", "Order"],
33
- ["promisee", "AccountId"],
34
- ["promisor", "AccountId"],
35
- ["result", "Option<Vec<u8>>"]
36
- ]
37
- }
38
- }
39
- }
@@ -1,63 +0,0 @@
1
- {
2
- "runtime_id": 23,
3
- "types": {
4
- "Address": "AccountIdAddress",
5
- "BlockNumber": "U32",
6
- "LeasePeriod": "BlockNumber",
7
- "SessionKeysPolkadot": {
8
- "type": "struct",
9
- "type_mapping": [
10
- ["grandpa", "AccountId"],
11
- ["babe", "AccountId"],
12
- ["im_online", "AccountId"],
13
- ["authority_discovery", "AccountId"],
14
- ["parachains", "AccountId"]
15
- ]
16
- },
17
- "Keys": "SessionKeysPolkadot",
18
- "ProxyType": {
19
- "type": "enum",
20
- "value_list": [
21
- "Any",
22
- "NonTransfer",
23
- "Staking",
24
- "SudoBalances",
25
- "IdentityJudgement"
26
- ]
27
- }
28
- },
29
- "versioning": [
30
- {
31
- "runtime_range": [3, 22],
32
- "types": {
33
- "OpenTip": {
34
- "type": "struct",
35
- "type_mapping": [
36
- ["reason", "Hash"],
37
- ["who", "AccountId"],
38
- ["finder", "Option<OpenTipFinder>"],
39
- ["closes", "Option<BlockNumber>"],
40
- ["tips", "Vec<OpenTipTip>"]
41
- ]
42
- }
43
- }
44
- },
45
- {
46
- "runtime_range": [23, null],
47
- "types": {
48
- "OpenTip": {
49
- "type": "struct",
50
- "type_mapping": [
51
- ["reason", "Hash"],
52
- ["who", "AccountId"],
53
- ["finder", "AccountId"],
54
- ["deposit", "Balance"],
55
- ["closes", "Option<BlockNumber>"],
56
- ["tips", "Vec<OpenTipTip>"],
57
- ["findersFee", "bool"]
58
- ]
59
- }
60
- }
61
- }
62
- ]
63
- }
data/src/storage_key.rs DELETED
@@ -1,41 +0,0 @@
1
- use frame_support::Twox128;
2
- use parity_scale_codec::Encode;
3
- use frame_support::{Identity, Blake2_128Concat, Twox64Concat};
4
- use frame_support::StorageHasher;
5
-
6
- pub fn to_hex_string(bytes: Vec<u8>) -> String {
7
- let strs: Vec<String> = bytes.iter()
8
- .map(|b| format!("{:02x}", b))
9
- .collect();
10
- strs.join("")
11
- }
12
-
13
- fn main() {
14
- // value
15
- let k = [Twox128::hash(b"Sudo"), Twox128::hash(b"Key")].concat();
16
- println!("{}", to_hex_string(k));
17
-
18
- // map
19
- let mut k = [Twox128::hash(b"ModuleAbc"), Twox128::hash(b"Map1")].concat();
20
- k.extend(vec![1u8, 0, 0, 0].using_encoded(Blake2_128Concat::hash));
21
- println!("{}", to_hex_string(k));
22
-
23
- let mut k = [Twox128::hash(b"ModuleAbc"), Twox128::hash(b"Map2")].concat();
24
- k.extend(1u32.using_encoded(Twox64Concat::hash));
25
- println!("{}", to_hex_string(k));
26
-
27
- let mut k = [Twox128::hash(b"ModuleAbc"), Twox128::hash(b"Map3")].concat();
28
- k.extend(1u32.using_encoded(Identity::hash));
29
- println!("{}", to_hex_string(k));
30
-
31
- // double map
32
- let mut k = [Twox128::hash(b"ModuleAbc"), Twox128::hash(b"DoubleMap1")].concat();
33
- k.extend(1u32.using_encoded(Blake2_128Concat::hash));
34
- k.extend(2u32.using_encoded(Blake2_128Concat::hash));
35
- println!("{}", to_hex_string(k));
36
-
37
- let mut k = [Twox128::hash(b"ModuleAbc"), Twox128::hash(b"DoubleMap2")].concat();
38
- k.extend(1u32.using_encoded(Blake2_128Concat::hash));
39
- k.extend(2u32.using_encoded(Twox64Concat::hash));
40
- println!("{}", to_hex_string(k));
41
- }