scale.rb 0.2.13 → 0.2.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -228,7 +228,7 @@
228
228
  ]
229
229
  ]
230
230
  },
231
- "RefCount": "u8",
231
+ "RefCount": "u32",
232
232
  "Moment": "u64",
233
233
  "AccountData": {
234
234
  "type": "struct",
@@ -259,7 +259,7 @@
259
259
  "Index"
260
260
  ],
261
261
  [
262
- "refcount",
262
+ "c",
263
263
  "RefCount"
264
264
  ],
265
265
  [
@@ -0,0 +1,332 @@
1
+ {
2
+ "types": {
3
+ "BalanceLock": {
4
+ "type": "struct",
5
+ "type_mapping": [
6
+ ["id", "LockIdentifier"],
7
+ ["lock_for", "LockFor"],
8
+ ["lock_reasons", "LockReasons"],
9
+ ["amount", "Balance"],
10
+ ["reasons", "Reasons"]
11
+ ]
12
+ },
13
+ "LockFor": {
14
+ "type": "enum",
15
+ "type_mapping": [
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
+ ["misc_frozen", "Balance"],
56
+ ["fee_frozen", "Balance"]
57
+ ]
58
+ },
59
+ "RingBalance": "Balance",
60
+ "KtonBalance": "Balance",
61
+ "TsInMs": "u64",
62
+ "Power": "u32",
63
+ "DepositId": "U256",
64
+ "StakingBalanceT": {
65
+ "type": "enum",
66
+ "type_mapping": [
67
+ ["RingBalance", "Balance"],
68
+ ["KtonBalance", "Balance"]
69
+ ]
70
+ },
71
+ "StakingLedgerT": {
72
+ "type": "struct",
73
+ "type_mapping": [
74
+ ["stash", "AccountId"],
75
+ ["active_ring", "Compact<Balance>"],
76
+ ["active_deposit_ring", "Compact<Balance>"],
77
+ ["active_kton", "Compact<Balance>"],
78
+ ["deposit_items", "Vec<TimeDepositItem>"],
79
+ ["ring_staking_lock", "StakingLock"],
80
+ ["kton_staking_lock", "StakingLock"],
81
+ ["claimed_rewards", "Vec<EraIndex>"],
82
+ ["total", "Compact<Balance>"],
83
+ ["active", "Compact<Balance>"],
84
+ ["unlocking", "Vec<UnlockChunk>"]
85
+ ]
86
+ },
87
+ "TimeDepositItem": {
88
+ "type": "struct",
89
+ "type_mapping": [
90
+ ["value", "Compact<Balance>"],
91
+ ["start_time", "Compact<TsInMs>"],
92
+ ["expire_time", "Compact<TsInMs>"]
93
+ ]
94
+ },
95
+ "ExposureT": {
96
+ "type": "struct",
97
+ "type_mapping": [
98
+ ["own_ring_balance", "Compact<Balance>"],
99
+ ["own_kton_balance", "Compact<Balance>"],
100
+ ["own_power", "Power"],
101
+ ["total_power", "Power"],
102
+ ["others", "Vec<IndividualExposure>"]
103
+ ]
104
+ },
105
+ "IndividualExposure": {
106
+ "type": "struct",
107
+ "type_mapping": [
108
+ ["who", "AccountId"],
109
+ ["ring_balance", "Compact<Balance>"],
110
+ ["kton_balance", "Compact<Balance>"],
111
+ ["power", "Power"],
112
+ ["value", "Compact<Balance>"]
113
+ ]
114
+ },
115
+ "ElectionResultT": {
116
+ "type": "struct",
117
+ "type_mapping": [
118
+ ["elected_stashes", "Vec<AccountId>"],
119
+ ["exposures", "Vec<(AccountId, ExposureT)>"],
120
+ ["compute", "ElectionCompute"]
121
+ ]
122
+ },
123
+ "RKT": {
124
+ "type": "struct",
125
+ "type_mapping": [
126
+ ["r", "Balance"],
127
+ ["k", "Balance"]
128
+ ]
129
+ },
130
+ "SpanRecord": {
131
+ "type": "struct",
132
+ "type_mapping": [
133
+ ["slashed", "RKT"],
134
+ ["paid_out", "RKT"]
135
+ ]
136
+ },
137
+ "UnappliedSlash": {
138
+ "type": "struct",
139
+ "type_mapping": [
140
+ ["validator", "AccountId"],
141
+ ["own", "RKT"],
142
+ ["others", "Vec<(AccountId, RKT)>"],
143
+ ["reporters", "Vec<AccountId>"],
144
+ ["payout", "RKT"]
145
+ ]
146
+ },
147
+ "TreasuryProposal": {
148
+ "type": "struct",
149
+ "type_mapping": [
150
+ ["proposer", "AccountId"],
151
+ ["beneficiary", "AccountId"],
152
+ ["ring_value", "Balance"],
153
+ ["kton_value", "Balance"],
154
+ ["ring_bond", "Balance"],
155
+ ["kton_bond", "Balance"]
156
+ ]
157
+ },
158
+ "MappedRing": "u128",
159
+ "EthereumTransactionIndex": "(H256, u64)",
160
+ "EthereumBlockNumber": "u64",
161
+ "EthereumHeader": {
162
+ "type": "struct",
163
+ "type_mapping": [
164
+ ["parent_hash", "H256"],
165
+ ["timestamp", "u64"],
166
+ ["number", "EthereumBlockNumber"],
167
+ ["author", "EthereumAddress"],
168
+ ["transactions_root", "H256"],
169
+ ["uncles_hash", "H256"],
170
+ ["extra_data", "Bytes"],
171
+ ["state_root", "H256"],
172
+ ["receipts_root", "H256"],
173
+ ["log_bloom", "Bloom"],
174
+ ["gas_used", "U256"],
175
+ ["gas_limit", "U256"],
176
+ ["difficulty", "U256"],
177
+ ["seal", "Vec<Bytes>"],
178
+ ["hash", "Option<H256>"]
179
+ ]
180
+ },
181
+ "EthereumAddress": "H160",
182
+ "EcdsaMessage": "[u8; 32]",
183
+ "Bloom": "[u8; 256]",
184
+ "H128": "[u8; 16]",
185
+ "EthashProof": {
186
+ "type": "struct",
187
+ "type_mapping": [
188
+ ["dag_nodes", "(H512, H512)"],
189
+ ["proof", "Vec<H128>"]
190
+ ]
191
+ },
192
+ "EthereumReceipt": {
193
+ "type": "struct",
194
+ "type_mapping": [
195
+ ["gas_used", "U256"],
196
+ ["log_bloom", "Bloom"],
197
+ ["logs", "Vec<LogEntry>"],
198
+ ["outcome", "TransactionOutcome"]
199
+ ]
200
+ },
201
+ "EthereumNetworkType": {
202
+ "type": "enum",
203
+ "type_mapping": [
204
+ ["Mainnet", "Null"],
205
+ ["Ropsten", "Null"]
206
+ ]
207
+ },
208
+ "RedeemFor": {
209
+ "type": "enum",
210
+ "type_mapping": [
211
+ ["Token", "Null"],
212
+ ["Deposit", "Null"]
213
+ ]
214
+ },
215
+ "EthereumReceiptProof": {
216
+ "type": "struct",
217
+ "type_mapping": [
218
+ ["index", "u64"],
219
+ ["proof", "Bytes"],
220
+ ["header_hash", "H256"]
221
+ ]
222
+ },
223
+ "EthereumReceiptProofThing": "(EthereumHeader, EthereumReceiptProof, MMRProof)",
224
+ "MMRProof": {
225
+ "type": "struct",
226
+ "type_mapping": [
227
+ ["member_leaf_index", "u64"],
228
+ ["last_leaf_index", "u64"],
229
+ ["proof", "Vec<H256>"]
230
+ ]
231
+ },
232
+ "EthereumRelayHeaderParcel": {
233
+ "type": "struct",
234
+ "type_mapping": [
235
+ ["header", "EthereumHeader"],
236
+ ["parent_mmr_root", "H256"]
237
+ ]
238
+ },
239
+ "EthereumRelayProofs": {
240
+ "type": "struct",
241
+ "type_mapping": [
242
+ ["ethash_proof", "Vec<EthashProof>"],
243
+ ["mmr_proof", "Vec<H256>"]
244
+ ]
245
+ },
246
+ "RelayAuthoritySigner": "EthereumAddress",
247
+ "RelayAuthorityMessage": "EcdsaMessage",
248
+ "RelayAuthoritySignature": "EcdsaSignature",
249
+ "OtherSignature": {
250
+ "type": "enum",
251
+ "type_mapping": [
252
+ ["Eth", "EcdsaSignature"],
253
+ ["Tron", "EcdsaSignature"]
254
+ ]
255
+ },
256
+ "EcdsaSignature": "[u8; 65]",
257
+ "OtherAddress": {
258
+ "type": "enum",
259
+ "type_mapping": [
260
+ ["Eth", "[u8; 20]"],
261
+ ["Tron", "[u8; 20]"]
262
+ ]
263
+ },
264
+ "AddressT": "[u8; 20]",
265
+ "MerkleMountainRangeRootLog": {
266
+ "type": "struct",
267
+ "type_mapping": [
268
+ ["prefix", "[u8; 4]"],
269
+ ["parent_mmr_root", "Hash"]
270
+ ]
271
+ },
272
+ "OpCode": "[u8; 4]",
273
+ "Term": "u32",
274
+ "RelayHeaderId": "EthereumBlockNumber",
275
+ "RelayHeaderParcel": "EthereumRelayHeaderParcel",
276
+ "RelayProofs": "EthereumRelayProofs",
277
+ "RelayAffirmationId": {
278
+ "type": "struct",
279
+ "type_mapping": [
280
+ ["game_id", "EthereumBlockNumber"],
281
+ ["round", "u32"],
282
+ ["index", "u32"]
283
+ ]
284
+ },
285
+ "RelayAffirmationT": {
286
+ "type": "struct",
287
+ "type_mapping": [
288
+ ["relayer", "AccountId"],
289
+ ["relay_header_parcels", "EthereumRelayHeaderParcel"],
290
+ ["bond", "Balance"],
291
+ ["maybe_extended_relay_affirmation_id", "Option<RelayAffirmationId>"],
292
+ ["verified", "bool"]
293
+ ]
294
+ },
295
+ "RelayVotingState": {
296
+ "type": "struct",
297
+ "type_mapping": [
298
+ ["ayes", "Vec<AccountId>"],
299
+ ["nays", "Vec<AccountId>"]
300
+ ]
301
+ },
302
+ "RelayAuthorityT": {
303
+ "type": "struct",
304
+ "type_mapping": [
305
+ ["account_id", "AccountId"],
306
+ ["signer", "Signer"],
307
+ ["stake", "Balance"],
308
+ ["term", "BlockNumber"]
309
+ ]
310
+ },
311
+ "ScheduledAuthoritiesChangeT": {
312
+ "type": "struct",
313
+ "type_mapping": [
314
+ ["next_authorities", "Vec<RelayAuthorityT>"],
315
+ ["deadline", "BlockNumber"]
316
+ ]
317
+ },
318
+ "MMRRoot": "Hash",
319
+ "BalancesRuntimeDispatchInfo": {
320
+ "type": "struct",
321
+ "type_mapping": [
322
+ ["usable_balance", "Balance"]
323
+ ]
324
+ },
325
+ "StakingRuntimeDispatchInfo": {
326
+ "type": "struct",
327
+ "type_mapping": [
328
+ ["power", "Power"]
329
+ ]
330
+ }
331
+ }
332
+ }
data/scale.gemspec CHANGED
@@ -33,14 +33,16 @@ Gem::Specification.new do |spec|
33
33
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
34
  spec.require_paths = ["lib"]
35
35
 
36
- spec.add_dependency "substrate_common.rb", "~> 0.1.9"
36
+ spec.add_dependency "blake2b_rs", "~> 0.1.2"
37
+ spec.add_dependency "xxhash"
38
+ spec.add_dependency "base58"
37
39
  spec.add_dependency "json", "~> 2.3.0"
38
- spec.add_dependency "activesupport", ">= 4.0.0"
39
- spec.add_dependency "thor", "~> 0.19.0"
40
+ spec.add_dependency "faye-websocket"
41
+ spec.add_dependency "thor", '~> 1.0'
40
42
 
41
- spec.add_development_dependency "bundler", "~> 1.17"
43
+ spec.add_development_dependency "bundler"
42
44
  spec.add_development_dependency "pry"
43
45
  spec.add_development_dependency "rake", "~> 13.0"
44
46
  spec.add_development_dependency "rspec", "~> 3.2"
45
- spec.add_development_dependency "ffi", "~> 1.12"
47
+ spec.add_development_dependency "ffi", "~> 1.15.0"
46
48
  end
@@ -2,7 +2,6 @@ require "scale"
2
2
 
3
3
 
4
4
  client = SubstrateClient.new("ws://127.0.0.1:9944/")
5
- client.init
6
5
  metadata = client.get_metadata nil
7
6
 
8
7
  the_module = metadata.get_module("CertificateModule")
@@ -23,7 +22,7 @@ puts "CertificateModule storages:"
23
22
  puts "---------------------------------------"
24
23
  puts the_module[:storage][:items]
25
24
 
26
- # Scale::TypeRegistry.instance.metadata = metadata.value
25
+ # Scale::TypeRegistry.instance.metadata = metadata
27
26
  # puts metadata.value.event_index["0400"][1]
28
27
  # puts metadata.value.event_index["0401"][1]
29
28
  # puts metadata.value.event_index["0402"][1]
@@ -31,4 +30,4 @@ puts the_module[:storage][:items]
31
30
  # scale_bytes = Scale::Bytes.new(hex_events)
32
31
  # Scale::Types.get("Vec<EventRecord>").decode(scale_bytes).value.each do |er|
33
32
  # puts er.value
34
- # end
33
+ # end
data/src/lib.rs CHANGED
@@ -1,6 +1,17 @@
1
1
  extern crate parity_scale_codec;
2
2
  use std::slice;
3
- use parity_scale_codec::{Decode};
3
+ use parity_scale_codec::{Encode, Decode};
4
+ use frame_support::Twox128;
5
+ use frame_support::Blake2_128Concat;
6
+ use frame_support::StorageHasher;
7
+
8
+ fn to_u8_vec(v_pointer: *const u8, len: usize) -> Vec<u8> {
9
+ let data_slice = unsafe {
10
+ assert!(!v_pointer.is_null());
11
+ slice::from_raw_parts(v_pointer, len)
12
+ };
13
+ data_slice.to_vec()
14
+ }
4
15
 
5
16
  fn decode_from_raw_parts<T: Decode + PartialEq + std::fmt::Debug>(v_pointer: *const u8, len: usize) -> T {
6
17
  let data_slice = unsafe {
@@ -49,6 +60,36 @@ pub extern fn parse_opt_bool(v_pointer: *const u8, len: usize, inner_value: bool
49
60
  assert_eq!(decode_from_raw_parts::<Option<bool>>(v_pointer, len), expectation);
50
61
  }
51
62
 
63
+ #[no_mangle]
64
+ pub extern fn assert_storage_key_for_value(
65
+ mv_pointer: *const u8, mv_len: usize,
66
+ sv_pointer: *const u8, sv_len: usize,
67
+ ev_pointer: *const u8, ev_len: usize
68
+ ) {
69
+ let m = to_u8_vec(mv_pointer, mv_len);
70
+ let s = to_u8_vec(sv_pointer, sv_len);
71
+ let e = to_u8_vec(ev_pointer, ev_len);
72
+
73
+ let k = [Twox128::hash(&m), Twox128::hash(&s)].concat();
74
+ assert_eq!(k, e);
75
+ }
76
+
77
+ #[no_mangle]
78
+ pub extern fn assert_storage_key_for_map_black2128concat(
79
+ mv_pointer: *const u8, mv_len: usize,
80
+ sv_pointer: *const u8, sv_len: usize,
81
+ pv_pointer: *const u8, pv_len: usize,
82
+ ev_pointer: *const u8, ev_len: usize,
83
+ ) {
84
+ let m = to_u8_vec(mv_pointer, mv_len);
85
+ let s = to_u8_vec(sv_pointer, sv_len);
86
+ let p = to_u8_vec(pv_pointer, pv_len);
87
+ let e = to_u8_vec(ev_pointer, ev_len);
88
+ let mut k = [Twox128::hash(&m), Twox128::hash(&s)].concat();
89
+ k.extend(p.using_encoded(Blake2_128Concat::hash));
90
+ assert_eq!(k, e);
91
+ }
92
+
52
93
  #[test]
53
94
  fn opt_bool_is_broken()
54
95
  {