scale.rb 0.2.10 → 0.2.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/scale/types.rb +43 -31
- data/lib/scale/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcfbe30b0f6a51793d9e977e362c34b213e04ee040f7d6961cde355b1e6cb8d0
|
4
|
+
data.tar.gz: 310f9fcab5186b0366e4a12da5790f77bfe81aa148684d1946d3a7f07ef57c60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14545046f43e403d84a492905b9aa9928024b0310aa2ae8dca927dd98e9d0b4415dcffa5a3364e85af2e13ef1ef4808fdb704462c8687fcb30336fa631a2ca9f
|
7
|
+
data.tar.gz: 23224a2ff2578fb4c49a12bc1317ae645fb5a2237f4f8f9f312585a53b849abd78ca455c86c68f9f6c2f22c3e6dd837638e6644245c66e25674b701e39de08e5
|
data/Gemfile.lock
CHANGED
data/lib/scale/types.rb
CHANGED
@@ -225,59 +225,71 @@ module Scale
|
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
228
|
-
class
|
228
|
+
class GenericAddress
|
229
229
|
include SingleValue
|
230
|
-
attr_accessor :account_length, :account_index, :account_id, :account_idx
|
231
230
|
|
231
|
+
# https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)
|
232
|
+
# base58encode ( concat ( <address-type>, <address>, <checksum> ) )
|
233
|
+
# ^^^^^^^^^
|
234
|
+
# the <address> is 32 byte account id or 1, 2, 4, 8 byte account index
|
235
|
+
# scale_bytes: account length byte + <address>'s bytes
|
232
236
|
def self.decode(scale_bytes)
|
233
237
|
account_length = scale_bytes.get_next_bytes(1).first
|
234
238
|
|
235
|
-
if account_length == 0xff #
|
239
|
+
if account_length == 0xff # 32 bytes address(Public key)
|
236
240
|
account_id = scale_bytes.get_next_bytes(32).bytes_to_hex
|
237
|
-
account_length = account_length.
|
238
|
-
|
241
|
+
account_length = [account_length].bytes_to_hex
|
242
|
+
|
243
|
+
Address.new({
|
244
|
+
account_id: account_id,
|
245
|
+
account_length: account_length
|
246
|
+
})
|
239
247
|
else
|
240
248
|
account_index =
|
241
|
-
if account_length == 0xfc
|
249
|
+
if account_length == 0xfc # 2 bytes address(account index)
|
242
250
|
scale_bytes.get_next_bytes(2).bytes_to_hex
|
243
|
-
elsif account_length == 0xfd
|
251
|
+
elsif account_length == 0xfd # 4 bytes address(account index)
|
244
252
|
scale_bytes.get_next_bytes(4).bytes_to_hex
|
245
|
-
elsif account_length == 0xfe
|
253
|
+
elsif account_length == 0xfe # 8 bytes address(account index)
|
246
254
|
scale_bytes.get_next_bytes(8).bytes_to_hex
|
247
255
|
else
|
248
256
|
[account_length].bytes_to_hex
|
249
257
|
end
|
250
|
-
# account_idx
|
251
|
-
account_length = account_length.
|
252
|
-
|
258
|
+
# TODO: add account_idx
|
259
|
+
account_length = [account_length].bytes_to_hex
|
260
|
+
|
261
|
+
Address.new({
|
262
|
+
account_index: account_index,
|
263
|
+
account_length: account_length
|
264
|
+
})
|
253
265
|
end
|
254
266
|
end
|
255
267
|
|
256
|
-
def encode
|
257
|
-
if value
|
258
|
-
|
259
|
-
::Address.encode(value, addr_type)
|
260
|
-
else
|
261
|
-
prefix = if value.length == 66
|
262
|
-
"ff"
|
263
|
-
elsif value.length == 6
|
264
|
-
"fc"
|
265
|
-
elsif value.length == 10
|
266
|
-
"fd"
|
267
|
-
elsif value.length == 18
|
268
|
-
"fe"
|
269
|
-
else
|
270
|
-
""
|
271
|
-
end
|
272
|
-
"#{prefix}#{value[2..]}"
|
273
|
-
end
|
268
|
+
def encode
|
269
|
+
if self.value[:account_id]
|
270
|
+
"#{self.value[:account_length][2..]}#{self.value[:account_id][2..]}"
|
274
271
|
else
|
275
|
-
|
272
|
+
"#{self.value[:account_length][2..]}#{self.value[:account_index][2..]}"
|
276
273
|
end
|
277
274
|
end
|
278
275
|
end
|
279
276
|
|
280
|
-
class
|
277
|
+
class Address < GenericAddress; end
|
278
|
+
|
279
|
+
class RawAddress < GenericAddress; end
|
280
|
+
|
281
|
+
class AccountIdAddress < GenericAddress
|
282
|
+
def self.decode(scale_bytes)
|
283
|
+
AccountIdAddress.new({
|
284
|
+
account_id: AccountId.decode(scale_bytes).value,
|
285
|
+
account_length: "0xff"
|
286
|
+
})
|
287
|
+
end
|
288
|
+
|
289
|
+
def encode
|
290
|
+
"ff#{self.value[:account_id][2..]}"
|
291
|
+
end
|
292
|
+
end
|
281
293
|
|
282
294
|
class AccountId < H256; end
|
283
295
|
|
data/lib/scale/version.rb
CHANGED