scale.rb 0.2.5 → 0.2.10

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.
@@ -23,27 +23,35 @@ require "metadata/metadata_v8"
23
23
  require "metadata/metadata_v9"
24
24
  require "metadata/metadata_v10"
25
25
  require "metadata/metadata_v11"
26
+ require "metadata/metadata_v12"
26
27
 
27
28
  module Scale
28
29
  class Error < StandardError; end
29
30
 
30
31
  class TypeRegistry
31
32
  include Singleton
32
- attr_accessor :types, :versioning
33
- attr_accessor :spec_version, :metadata
34
- attr_accessor :custom_types
33
+ attr_reader :spec_name, :types, :versioning, :custom_types
34
+ attr_accessor :spec_version
35
+ attr_accessor :metadata
35
36
 
36
- def load(spec_name = nil, custom_types = nil)
37
- default_types, _ = load_chain_spec_types("default")
37
+ def load(spec_name: nil, custom_types: nil)
38
+ @spec_name = nil
39
+ @types = nil
40
+ @versioning = nil
41
+ @custom_types = nil
42
+
43
+ default_types, _, _ = load_chain_spec_types("default")
38
44
 
39
45
  if spec_name.nil? || spec_name == "default"
46
+ @spec_name = "default"
40
47
  @types = default_types
41
48
  else
42
- spec_types, @versioning = load_chain_spec_types(spec_name)
49
+ @spec_name = spec_name
50
+ spec_types, @versioning, @spec_version = load_chain_spec_types(spec_name)
43
51
  @types = default_types.merge(spec_types)
44
52
  end
45
53
 
46
- @custom_types = custom_types.stringify_keys if custom_types.nil? && custom_types.class.name == "Hash"
54
+ self.custom_types = custom_types
47
55
  true
48
56
  end
49
57
 
@@ -67,27 +75,30 @@ module Scale
67
75
  Scale::Types.constantize(type)
68
76
  end
69
77
 
70
- def load_chain_spec_types(spec_name)
71
- file = File.join File.expand_path("../..", __FILE__), "lib", "type_registry", "#{spec_name}.json"
72
- json_string = File.open(file).read
73
- json = JSON.parse(json_string)
78
+ def custom_types=(custom_types)
79
+ @custom_types = custom_types.stringify_keys if (not custom_types.nil?) && custom_types.class.name == "Hash"
80
+ end
74
81
 
75
- runtime_id = json["runtime_id"]
82
+ private
76
83
 
77
- [json["types"], json["versioning"]]
78
- end
84
+ def load_chain_spec_types(spec_name)
85
+ file = File.join File.expand_path("../..", __FILE__), "lib", "type_registry", "#{spec_name}.json"
86
+ json_string = File.open(file).read
87
+ json = JSON.parse(json_string)
79
88
 
80
- def type_traverse(type, types)
81
- if types.has_key?(type)
82
- type_traverse(types[type], types)
83
- else
84
- if type.class == ::String
85
- rename(type)
89
+ runtime_id = json["runtime_id"]
90
+
91
+ [json["types"], json["versioning"], runtime_id]
92
+ end
93
+
94
+ def type_traverse(type, types)
95
+ type = rename(type) if type.class == ::String
96
+ if types.has_key?(type) && types[type] != type
97
+ type_traverse(types[type], types)
86
98
  else
87
99
  type
88
100
  end
89
101
  end
90
- end
91
102
  end
92
103
 
93
104
  # TODO: == implement
@@ -323,6 +334,7 @@ def rename(type)
323
334
  return "Compact" if type == "<Balance as HasCompact>::Type"
324
335
  return "Compact" if type == "<BlockNumber as HasCompact>::Type"
325
336
  return "Compact" if type == "Compact<Balance>"
337
+ return "Compact" if type == "Compact<BlockNumber>"
326
338
  return "CompactMoment" if type == "<Moment as HasCompact>::Type"
327
339
  return "CompactMoment" if type == "Compact<Moment>"
328
340
  return "InherentOfflineReport" if type == "<InherentOfflineReport as InherentOfflineReport>::Inherent"
@@ -96,9 +96,10 @@ module Scale
96
96
  # decode params
97
97
  result[:params_raw] = scale_bytes.get_remaining_bytes.bytes_to_hex
98
98
  result[:params] = call[:args].map do |arg|
99
- type = Scale::Types.get(arg[:type])
100
- arg_obj = type.decode(scale_bytes)
101
- {name: arg[:name], type: arg[:type], scale_type: type, value: arg_obj.value }
99
+ type = arg[:type]
100
+ scale_type = Scale::Types.get(type)
101
+ obj = scale_type.decode(scale_bytes)
102
+ {name: arg[:name], type: type, scale_type: scale_type, value: obj.value }
102
103
  end
103
104
  end
104
105
 
@@ -123,6 +124,24 @@ module Scale
123
124
  end
124
125
  end
125
126
 
127
+ class Phase
128
+ include Enum
129
+ items isApplyExtrinsic: "Bool", asApplyExtrinsic: "U32", isFinalization: "Bool", isInitialization: "Bool"
130
+ end
131
+
132
+ class EventRecords
133
+ include SingleValue
134
+
135
+ def self.decode(scale_bytes)
136
+
137
+ length = Compact.decode(scale_bytes).value
138
+
139
+ length.times do |i|
140
+ ev = EventRecord.decode(scale_bytes)
141
+ end
142
+ end
143
+ end
144
+
126
145
  class EventRecord
127
146
  include SingleValue
128
147
 
@@ -1,3 +1,3 @@
1
1
  module Scale
2
- VERSION = "0.2.5".freeze
2
+ VERSION = "0.2.10".freeze
3
3
  end
@@ -1,119 +1,300 @@
1
1
  {
2
2
  "types": {
3
- "EpochDuration": "u64",
4
- "EraIndex": "u32",
5
- "Index": "U64",
6
- "RingBalanceOf": "u128",
7
- "KtonBalanceOf": "u128",
8
- "ExtendedBalance": "u128",
9
- "Keys": {
3
+ "Address": "AccountId",
4
+ "LookupSource": "AccountId",
5
+ "BalanceLock": {
10
6
  "type": "struct",
11
7
  "type_mapping": [
12
- ["grandpa", "AccountId"],
13
- ["babe", "AccountId"]
8
+ ["id", "LockIdentifier"],
9
+ ["lock_for", "LockFor"],
10
+ ["lock_reasons", "LockReasons"]
14
11
  ]
15
12
  },
16
- "ValidatorPrefs": "ValidatorPrefsLegacy",
17
- "StakingBalance": {
13
+ "LockFor": {
18
14
  "type": "enum",
19
15
  "type_mapping": [
20
- ["Ring", "RingBalanceOf"],
21
- ["Kton", "KtonBalanceOf"]
16
+ ["Common", "Common"],
17
+ ["Staking", "StakingLock"]
18
+ ]
19
+ },
20
+ "Common": {
21
+ "type": "struct",
22
+ "type_mapping": [
23
+ ["amount", "Balance"]
24
+ ]
25
+ },
26
+ "StakingLock": {
27
+ "type": "struct",
28
+ "type_mapping": [
29
+ ["staking_amount", "Balance"],
30
+ ["unbondings", "Vec<Unbonding>"]
31
+ ]
32
+ },
33
+ "LockReasons": {
34
+ "type": "enum",
35
+ "type_mapping": [
36
+ ["Fee", "Null"],
37
+ ["Misc", "Null"],
38
+ ["All", "Null"]
39
+ ]
40
+ },
41
+ "Unbonding": {
42
+ "type": "struct",
43
+ "type_mapping": [
44
+ ["amount", "Balance"],
45
+ ["until", "BlockNumber"]
46
+ ]
47
+ },
48
+ "AccountData": {
49
+ "type": "struct",
50
+ "type_mapping": [
51
+ ["free", "Balance"],
52
+ ["reserved", "Balance"],
53
+ ["free_kton", "Balance"],
54
+ ["reserved_kton", "Balance"]
55
+ ]
56
+ },
57
+ "RingBalance": "Balance",
58
+ "KtonBalance": "Balance",
59
+ "TsInMs": "u64",
60
+ "Power": "u32",
61
+ "DepositId": "U256",
62
+ "StakingBalanceT": {
63
+ "type": "enum",
64
+ "type_mapping": [
65
+ ["RingBalance", "Balance"],
66
+ ["KtonBalance", "Balance"]
67
+ ]
68
+ },
69
+ "StakingLedgerT": {
70
+ "type": "struct",
71
+ "type_mapping": [
72
+ ["stash", "AccountId"],
73
+ ["active_ring", "Compact<Balance>"],
74
+ ["active_deposit_ring", "Compact<Balance>"],
75
+ ["active_kton", "Compact<Balance>"],
76
+ ["deposit_items", "Vec<TimeDepositItem>"],
77
+ ["ring_staking_lock", "StakingLock"],
78
+ ["kton_staking_lock", "StakingLock"],
79
+ ["claimed_rewards", "Vec<EraIndex>"]
22
80
  ]
23
81
  },
24
82
  "TimeDepositItem": {
25
83
  "type": "struct",
26
84
  "type_mapping": [
27
- ["value", "Compact<RingBalanceOf>"],
28
- ["start_time", "Compact<Moment>"],
29
- ["expire_time", "Compact<Moment>"]
85
+ ["value", "Compact<Balance>"],
86
+ ["start_time", "Compact<TsInMs>"],
87
+ ["expire_time", "Compact<TsInMs>"]
88
+ ]
89
+ },
90
+ "ExposureT": {
91
+ "type": "struct",
92
+ "type_mapping": [
93
+ ["own_ring_balance", "Compact<Balance>"],
94
+ ["own_kton_balance", "Compact<Balance>"],
95
+ ["own_power", "Power"],
96
+ ["total_power", "Power"],
97
+ ["others", "Vec<IndividualExposure>"]
30
98
  ]
31
99
  },
32
- "UnlockChunk": {
100
+ "IndividualExposure": {
33
101
  "type": "struct",
34
102
  "type_mapping": [
35
- ["value", "StakingBalance"],
36
- ["era", "Compact<EraIndex>"],
37
- ["is_time_deposit", "bool"]
103
+ ["who", "AccountId"],
104
+ ["ring_balance", "Compact<Balance>"],
105
+ ["kton_balance", "Compact<Balance>"],
106
+ ["power", "Power"]
38
107
  ]
39
108
  },
40
- "StakingLedgers": {
109
+ "ElectionResultT": {
41
110
  "type": "struct",
42
111
  "type_mapping": [
43
- ["stash", "AccountId"],
44
- ["total_ring", "Compact<RingBalanceOf>"],
45
- ["total_deposit_ring", "Compact<RingBalanceOf>"],
46
- ["active_ring", "Compact<RingBalanceOf>"],
47
- ["active_deposit_ring", "Compact<RingBalanceOf>"],
48
- ["total_kton", "Compact<KtonBalanceOf>"],
49
- ["active_kton", "Compact<KtonBalanceOf>"],
50
- ["deposit_items", "Vec<TimeDepositItem>"],
51
- ["unlocking", "Vec<UnlockChunk>"]
112
+ ["elected_stashes", "Vec<AccountId>"],
113
+ ["exposures", "Vec<(AccountId, ExposureT)>"],
114
+ ["compute", "ElectionCompute"]
52
115
  ]
53
116
  },
54
- "IndividualExpo": {
117
+ "RKT": {
55
118
  "type": "struct",
56
119
  "type_mapping": [
57
- ["who", "AccountId"],
58
- ["value", "ExtendedBalance"]
120
+ ["r", "Balance"],
121
+ ["k", "Balance"]
59
122
  ]
60
123
  },
61
- "Exposures": {
124
+ "SpanRecord": {
62
125
  "type": "struct",
63
126
  "type_mapping": [
64
- ["total", "ExtendedBalance"],
65
- ["own", "ExtendedBalance"],
66
- ["others", "Vec<IndividualExpo>"]
127
+ ["slashed", "RKT"],
128
+ ["paid_out", "RKT"]
67
129
  ]
68
130
  },
69
- "TokenBalance": "u128",
70
- "Currency": "u128",
71
- "CurrencyOf": "u128",
72
- "Auction": {
131
+ "UnappliedSlash": {
73
132
  "type": "struct",
74
133
  "type_mapping": [
75
- ["seller", "AccountId"],
76
- ["startAt", "Moment"],
77
- ["duration", "u64"],
78
- ["startingPrice", "TokenBalance"],
79
- ["endingPrice", "TokenBalance"],
80
- ["lastRecord", "TokenBalance"],
81
- ["lastBidder", "AccountId"],
82
- ["lastBidStartAt", "Moment"]
134
+ ["validator", "AccountId"],
135
+ ["own", "RKT"],
136
+ ["others", "Vec<(AccountId, RKT)>"],
137
+ ["reporters", "Vec<AccountId>"],
138
+ ["payout", "RKT"]
83
139
  ]
84
140
  },
85
- "DepositInfo": {
141
+ "TreasuryProposal": {
86
142
  "type": "struct",
87
143
  "type_mapping": [
88
- ["month", "Moment"],
89
- ["start_at", "Moment"],
90
- ["value", "CurrencyOf"],
91
- ["unit_interest", "u64"],
92
- ["claimed", "bool"]
144
+ ["proposer", "AccountId"],
145
+ ["beneficiary", "AccountId"],
146
+ ["ring_value", "Balance"],
147
+ ["kton_value", "Balance"],
148
+ ["ring_bond", "Balance"],
149
+ ["kton_bond", "Balance"]
93
150
  ]
94
151
  },
95
- "Deposit": {
152
+ "MappedRing": "u128",
153
+ "EthereumTransactionIndex": "(H256, u64)",
154
+ "EthereumHeaderBrief": {
96
155
  "type": "struct",
97
156
  "type_mapping": [
98
- ["total_deposit", "CurrencyOf"],
99
- ["deposit_list", "Vec<DepositInfo>"]
157
+ ["total_difficulty", "U256"],
158
+ ["parent_hash", "H256"],
159
+ ["number", "EthereumBlockNumber"],
160
+ ["relayer", "AccountId"]
100
161
  ]
101
162
  },
102
- "Revenue": {
163
+ "EthereumBlockNumber": "u64",
164
+ "EthereumHeaderThingWithProof": {
103
165
  "type": "struct",
104
166
  "type_mapping": [
105
- ["team", "TokenBalance"],
106
- ["contribution", "TokenBalance"],
107
- ["ktoner", "TokenBalance"],
108
- ["lottery", "TokenBalance"]
167
+ ["header", "EthereumHeader"],
168
+ ["ethash_proof", "Vec<EthashProof>"],
169
+ ["mmr_root", "H256"],
170
+ ["mmr_proof", "Vec<H256>"]
109
171
  ]
110
172
  },
111
- "DoubleNodeWithMerkleProof": {
173
+ "EthereumHeaderThing": {
112
174
  "type": "struct",
113
175
  "type_mapping": [
114
- ["dag_nodes", "VecH512Length2"],
176
+ ["header", "EthereumHeader"],
177
+ ["mmr_root", "H256"]
178
+ ]
179
+ },
180
+ "EthereumHeader": {
181
+ "type": "struct",
182
+ "type_mapping": [
183
+ ["parent_hash", "H256"],
184
+ ["timestamp", "u64"],
185
+ ["number", "EthereumBlockNumber"],
186
+ ["author", "EthereumAddress"],
187
+ ["transactions_root", "H256"],
188
+ ["uncles_hash", "H256"],
189
+ ["extra_data", "Bytes"],
190
+ ["state_root", "H256"],
191
+ ["receipts_root", "H256"],
192
+ ["log_bloom", "Bloom"],
193
+ ["gas_used", "U256"],
194
+ ["gas_limit", "U256"],
195
+ ["difficulty", "U256"],
196
+ ["seal", "Vec<Bytes>"],
197
+ ["hash", "Option<H256>"]
198
+ ]
199
+ },
200
+ "EthereumAddress": "H160",
201
+ "Bloom": "[u8; 256]",
202
+ "H128": "[u8; 16]",
203
+ "EthashProof": {
204
+ "type": "struct",
205
+ "type_mapping": [
206
+ ["dag_nodes", "(H512, H512)"],
115
207
  ["proof", "Vec<H128>"]
116
208
  ]
209
+ },
210
+ "EthereumReceipt": {
211
+ "type": "struct",
212
+ "type_mapping": [
213
+ ["gas_used", "U256"],
214
+ ["log_bloom", "Bloom"],
215
+ ["logs", "Vec<LogEntry>"],
216
+ ["outcome", "TransactionOutcome"]
217
+ ]
218
+ },
219
+ "EthereumNetworkType": {
220
+ "type": "enum",
221
+ "type_mapping": [
222
+ ["Mainnet", "Null"],
223
+ ["Ropsten", "Null"]
224
+ ]
225
+ },
226
+ "RedeemFor": {
227
+ "type": "enum",
228
+ "type_mapping": [
229
+ ["Token", "Null"],
230
+ ["Deposit", "Null"]
231
+ ]
232
+ },
233
+ "EthereumReceiptProof": {
234
+ "type": "struct",
235
+ "type_mapping": [
236
+ ["index", "u64"],
237
+ ["proof", "Bytes"],
238
+ ["header_hash", "H256"]
239
+ ]
240
+ },
241
+ "EthereumReceiptProofThing": "(EthereumHeader, EthereumReceiptProof, MMRProof)",
242
+ "MMRProof": {
243
+ "type": "struct",
244
+ "type_mapping": [
245
+ ["member_leaf_index", "u64"],
246
+ ["last_leaf_index", "u64"],
247
+ ["proof", "Vec<H256>"]
248
+ ]
249
+ },
250
+ "OtherSignature": {
251
+ "type": "enum",
252
+ "type_mapping": [
253
+ ["Eth", "EcdsaSignature"],
254
+ ["Tron", "EcdsaSignature"]
255
+ ]
256
+ },
257
+ "EcdsaSignature": "[u8; 65]",
258
+ "OtherAddress": {
259
+ "type": "enum",
260
+ "type_mapping": [
261
+ ["Eth", "[u8; 20]"],
262
+ ["Tron", "[u8; 20]"]
263
+ ]
264
+ },
265
+ "AddressT": "[u8; 20]",
266
+ "MerkleMountainRangeRootLog": {
267
+ "type": "struct",
268
+ "type_mapping": [
269
+ ["prefix", "[u8; 4]"],
270
+ ["mmr_root", "Hash"]
271
+ ]
272
+ },
273
+ "Round": "u64",
274
+ "TcHeaderThingWithProof": "EthereumHeaderThingWithProof",
275
+ "TcHeaderThing": "EthereumHeaderThing",
276
+ "TcBlockNumber": "u64",
277
+ "TcHeaderHash": "H256",
278
+ "GameId": "TcBlockNumber",
279
+ "RelayProposalT": {
280
+ "type": "struct",
281
+ "type_mapping": [
282
+ ["relayer", "AccountId"],
283
+ ["bonded_proposal", "Vec<(Balance, TcHeaderThing)>"],
284
+ ["extend_from_header_hash", "Option<TcHeaderHash>"]
285
+ ]
286
+ },
287
+ "BalancesRuntimeDispatchInfo": {
288
+ "type": "struct",
289
+ "type_mapping": [
290
+ ["usable_balance", "Balance"]
291
+ ]
292
+ },
293
+ "StakingRuntimeDispatchInfo": {
294
+ "type": "struct",
295
+ "type_mapping": [
296
+ ["power", "Power"]
297
+ ]
117
298
  }
118
299
  }
119
300
  }