scale_rb 0.1.15 → 0.2.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/address.rb +85 -89
- data/lib/client/abstract_ws_client.rb +85 -81
- data/lib/client/http_client.rb +1 -0
- data/lib/client/http_client_metadata.rb +1 -1
- data/lib/client/http_client_storage.rb +6 -6
- data/lib/client/rpc_request_builder.rb +44 -42
- data/lib/codec.rb +11 -11
- data/lib/hasher.rb +39 -37
- data/lib/metadata/metadata.rb +130 -122
- data/lib/metadata/metadata_v10.rb +72 -69
- data/lib/metadata/metadata_v11.rb +78 -75
- data/lib/metadata/metadata_v12.rb +42 -39
- data/lib/metadata/metadata_v13.rb +71 -68
- data/lib/metadata/metadata_v14.rb +185 -181
- data/lib/metadata/metadata_v9.rb +92 -89
- data/lib/monkey_patching.rb +22 -22
- data/lib/portable_codec.rb +236 -232
- data/lib/scale_rb/version.rb +1 -1
- data/lib/scale_rb.rb +0 -1
- data/lib/storage_helper.rb +52 -50
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9857ea16c7327b90a598f40ce8afe919ee3db3a1fada67ba9e1a5ee768c50fdf
|
4
|
+
data.tar.gz: 7bd319b972c1c4aa13f4f24c6af525294bcbd8b6361423db66ac6038e44ad990
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db6452725e87b88cd0bdffe419588c8b9b8cfe892bdac01df226e9008bf02e45d56c9c25447a932d8ddf43bdfecf6ade0095710c9e056ee14ef2813f7b500b75
|
7
|
+
data.tar.gz: 2c6d01fd6726cc7ff5ed7c303b5e3c7ffe48347267a7b6989a6cda032741c47cfe339fa4c51871166b78f794a999cf8b0e6104cf44d013912bf5dbac0599cb45
|
data/Gemfile.lock
CHANGED
data/lib/address.rb
CHANGED
@@ -1,105 +1,101 @@
|
|
1
1
|
require 'base58'
|
2
2
|
|
3
3
|
# Warning: Just for test
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# raise "Invalid decoded address checksum" unless is_valid_checksum && ignore_checksum
|
57
|
-
|
58
|
-
decoded[1...size].unpack1('H*')
|
59
|
-
end
|
60
|
-
|
61
|
-
def encode(pubkey, addr_type = 42)
|
62
|
-
pubkey = pubkey[2..-1] if pubkey =~ /^0x/i
|
63
|
-
key = [pubkey].pack('H*')
|
4
|
+
module ScaleRb
|
5
|
+
class Address
|
6
|
+
SS58_PREFIX = 'SS58PRE'
|
7
|
+
|
8
|
+
TYPES = [
|
9
|
+
# Polkadot Live (SS58, AccountId)
|
10
|
+
0, 1,
|
11
|
+
# Polkadot Canary (SS58, AccountId)
|
12
|
+
2, 3,
|
13
|
+
# Kulupu (SS58, Reserved)
|
14
|
+
16, 17,
|
15
|
+
# Darwinia Live
|
16
|
+
18,
|
17
|
+
# Dothereum (SS58, AccountId)
|
18
|
+
20, 21,
|
19
|
+
# Generic Substrate wildcard (SS58, AccountId)
|
20
|
+
42, 43,
|
21
|
+
|
22
|
+
# Schnorr/Ristretto 25519 ("S/R 25519") key
|
23
|
+
48,
|
24
|
+
# Edwards Ed25519 key
|
25
|
+
49,
|
26
|
+
# ECDSA SECP256k1 key
|
27
|
+
50,
|
28
|
+
|
29
|
+
# Reserved for future address format extensions.
|
30
|
+
*64..255
|
31
|
+
]
|
32
|
+
|
33
|
+
class << self
|
34
|
+
def decode(address, addr_type = 42, _ignore_checksum = true)
|
35
|
+
decoded = Base58.base58_to_binary(address, :bitcoin)
|
36
|
+
is_pubkey = decoded.size == 35
|
37
|
+
|
38
|
+
size = decoded.size - (is_pubkey ? 2 : 1)
|
39
|
+
|
40
|
+
prefix = decoded[0, 1].unpack1('C*')
|
41
|
+
|
42
|
+
raise 'Invalid address type' unless TYPES.include?(addr_type)
|
43
|
+
|
44
|
+
hash_bytes = make_hash(decoded[0, size])
|
45
|
+
is_valid_checksum =
|
46
|
+
if is_pubkey
|
47
|
+
decoded[-2].unpack1('C*') == hash_bytes[0] && decoded[-1].unpack1('C*') == hash_bytes[1]
|
48
|
+
else
|
49
|
+
decoded[-1].unpack1('C*') == hash_bytes[0]
|
50
|
+
end
|
51
|
+
|
52
|
+
# raise "Invalid decoded address checksum" unless is_valid_checksum && ignore_checksum
|
53
|
+
|
54
|
+
decoded[1...size].unpack1('H*')
|
55
|
+
end
|
64
56
|
|
65
|
-
|
57
|
+
def encode(pubkey, addr_type = 42)
|
58
|
+
pubkey = pubkey[2..-1] if pubkey =~ /^0x/i
|
59
|
+
key = [pubkey].pack('H*')
|
66
60
|
|
67
|
-
|
68
|
-
when 32, 33
|
69
|
-
2
|
70
|
-
when 1, 2, 4, 8
|
71
|
-
1
|
72
|
-
else
|
73
|
-
raise 'Invalid pubkey length'
|
74
|
-
end
|
61
|
+
pubkey_bytes = key.bytes
|
75
62
|
|
76
|
-
|
77
|
-
|
63
|
+
checksum_length = case pubkey_bytes.length
|
64
|
+
when 32, 33
|
65
|
+
2
|
66
|
+
when 1, 2, 4, 8
|
67
|
+
1
|
78
68
|
else
|
79
|
-
|
80
|
-
((ss58_format & 0b0000_0000_1111_1100) >> 2) | 0b0100_0000,
|
81
|
-
(ss58_format >> 8) | ((ss58_format & 0b0000_0000_0000_0011) << 6)
|
82
|
-
].pack('C*')
|
69
|
+
raise 'Invalid pubkey length'
|
83
70
|
end
|
84
71
|
|
85
|
-
|
86
|
-
|
72
|
+
ss58_format_bytes = if addr_type < 64
|
73
|
+
[addr_type].pack('C*')
|
74
|
+
else
|
75
|
+
[
|
76
|
+
((ss58_format & 0b0000_0000_1111_1100) >> 2) | 0b0100_0000,
|
77
|
+
(ss58_format >> 8) | ((ss58_format & 0b0000_0000_0000_0011) << 6)
|
78
|
+
].pack('C*')
|
79
|
+
end
|
87
80
|
|
88
|
-
|
89
|
-
|
81
|
+
input_bytes = ss58_format_bytes.bytes + pubkey_bytes
|
82
|
+
checksum = Blake2b.hex(SS58_PREFIX.bytes + input_bytes, 64)._to_bytes
|
90
83
|
|
91
|
-
|
92
|
-
|
93
|
-
end
|
84
|
+
Base58.binary_to_base58((input_bytes + checksum[0...checksum_length]).pack('C*'), :bitcoin)
|
85
|
+
end
|
94
86
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
87
|
+
def make_hash(body)
|
88
|
+
Blake2b.hex("#{SS58_PREFIX}#{body}".bytes, 64)
|
89
|
+
end
|
90
|
+
|
91
|
+
def is_ss58_address?(address)
|
92
|
+
begin
|
93
|
+
decode(address)
|
94
|
+
rescue StandardError
|
95
|
+
return false
|
96
|
+
end
|
97
|
+
true
|
100
98
|
end
|
101
|
-
true
|
102
99
|
end
|
103
100
|
end
|
104
101
|
end
|
105
|
-
|
@@ -1,100 +1,104 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
require_relative './rpc_request_builder'
|
4
|
+
|
5
|
+
module ScaleRb
|
6
|
+
class AbstractWsClient
|
7
|
+
extend RpcRequestBuilder
|
8
|
+
attr_accessor :metadata, :registry
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@id = 0
|
12
|
+
@metadata = nil
|
13
|
+
@registry = nil
|
14
|
+
@callbacks = {}
|
15
|
+
@subscription_callbacks = {}
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
def send_json_rpc(_body)
|
19
|
+
raise 'WsClient is a abstract base class for websocket client, please use its sub-class'
|
20
|
+
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
22
|
+
# changes: [
|
23
|
+
# [
|
24
|
+
# "0x26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7", # storage key
|
25
|
+
# "0x0400000000000000d887690900000000020000" # change
|
26
|
+
# ]
|
27
|
+
# ]
|
28
|
+
def process(resp)
|
29
|
+
# handle id
|
30
|
+
@callbacks[resp['id']]&.call(resp['id'], resp) if resp['id']
|
31
|
+
|
32
|
+
# handle storage subscription
|
33
|
+
return unless resp['params'] && resp['params']['subscription']
|
34
|
+
return unless @metadata && @registry
|
35
|
+
|
36
|
+
subscription = resp['params']['subscription']
|
37
|
+
changes = resp['params']['result']['changes']
|
38
|
+
block = resp['params']['result']['block']
|
39
|
+
p "block: #{block}"
|
40
|
+
|
41
|
+
return unless @subscription_callbacks[subscription]
|
42
|
+
|
43
|
+
pallet_name, item_name, subscription_callback = @subscription_callbacks[subscription]
|
44
|
+
storage_item = Metadata.get_storage_item(pallet_name, item_name, @metadata)
|
45
|
+
storages = decode_storages(changes.map(&:last), storage_item, registry)
|
46
|
+
subscription_callback.call(storages)
|
47
|
+
end
|
45
48
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def get_metadata(callback = nil)
|
50
|
+
if callback.nil?
|
51
|
+
callback = lambda do |id, resp|
|
52
|
+
return unless resp['id'] && resp['result']
|
53
|
+
return if resp['id'] != id
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
metadata_hex = resp['result']
|
56
|
+
metadata = Metadata.decode_metadata(metadata_hex.strip._to_bytes)
|
57
|
+
return unless metadata
|
55
58
|
|
56
|
-
|
57
|
-
|
59
|
+
@metadata = metadata
|
60
|
+
@registry = Metadata.build_registry(@metadata)
|
61
|
+
end
|
58
62
|
end
|
59
|
-
end
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
64
|
+
id = bind_id_to(callback)
|
65
|
+
body = state_getMetadata(id)
|
66
|
+
send_json_rpc(body)
|
67
|
+
end
|
65
68
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
def subscribe_storage(pallet_name, item_name, subscription_callback, key = nil, registry = nil)
|
70
|
+
callback = create_callback_for_subscribe_storage(pallet_name, item_name, subscription_callback)
|
71
|
+
id = bind_id_to(callback)
|
72
|
+
body = derived_state_subscribe_storage(id, pallet_name, item_name, key, registry)
|
73
|
+
send_json_rpc(body)
|
74
|
+
end
|
72
75
|
|
73
|
-
|
76
|
+
private
|
74
77
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
def bind_id_to(callback)
|
79
|
+
@callbacks[@id] = callback
|
80
|
+
old = @id
|
81
|
+
@id += 1
|
82
|
+
old
|
83
|
+
end
|
81
84
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
+
def decode_storages(datas, storage_item, registry)
|
86
|
+
datas.map do |data|
|
87
|
+
StorageHelper.decode_storage2(data, storage_item, registry)
|
88
|
+
end
|
85
89
|
end
|
86
|
-
end
|
87
90
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
91
|
+
def create_callback_for_subscribe_storage(pallet_name, item_name, subscription_callback)
|
92
|
+
lambda do |id, resp|
|
93
|
+
return unless resp['id'] && resp['result']
|
94
|
+
return if resp['id'] != id
|
92
95
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
@subscription_callbacks[resp['result']] = [
|
97
|
+
pallet_name,
|
98
|
+
item_name,
|
99
|
+
subscription_callback
|
100
|
+
]
|
101
|
+
end
|
98
102
|
end
|
99
103
|
end
|
100
104
|
end
|
data/lib/client/http_client.rb
CHANGED
@@ -35,7 +35,7 @@ module ScaleRb
|
|
35
35
|
item['changes'].map do |change|
|
36
36
|
storage_key = change[0]
|
37
37
|
data = change[1] || default
|
38
|
-
storage = data.nil? ? nil : PortableCodec.decode(type_id, data.
|
38
|
+
storage = data.nil? ? nil : PortableCodec.decode(type_id, data._to_bytes, registry)[0]
|
39
39
|
{ storage_key: storage_key, storage: storage }
|
40
40
|
end
|
41
41
|
end.flatten
|
@@ -80,7 +80,7 @@ module ScaleRb
|
|
80
80
|
# 'System',
|
81
81
|
# 'Account',
|
82
82
|
# key = {
|
83
|
-
# value: [['0x724d50824542b56f422588421643c4a162b90b5416ef063f2266a1eae6651641'.
|
83
|
+
# value: [['0x724d50824542b56f422588421643c4a162b90b5416ef063f2266a1eae6651641'._to_bytes]], # [AccountId]
|
84
84
|
# type: 0,
|
85
85
|
# hashers: ['Blake2128Concat']
|
86
86
|
# },
|
@@ -96,7 +96,7 @@ module ScaleRb
|
|
96
96
|
if key
|
97
97
|
if key[:value].nil? || key[:value].empty?
|
98
98
|
# map, but no key's value provided. get all storages under the partial storage key
|
99
|
-
partial_storage_key = StorageHelper.encode_storage_key(pallet_name, item_name).
|
99
|
+
partial_storage_key = StorageHelper.encode_storage_key(pallet_name, item_name)._to_hex
|
100
100
|
get_storages_by_partial_key(
|
101
101
|
url,
|
102
102
|
partial_storage_key,
|
@@ -107,7 +107,7 @@ module ScaleRb
|
|
107
107
|
)
|
108
108
|
elsif key[:value].length != key[:hashers].length
|
109
109
|
# map with multi parts, but not have all values
|
110
|
-
partial_storage_key = StorageHelper.encode_storage_key(pallet_name, item_name, key, registry).
|
110
|
+
partial_storage_key = StorageHelper.encode_storage_key(pallet_name, item_name, key, registry)._to_hex
|
111
111
|
get_storages_by_partial_key(
|
112
112
|
url,
|
113
113
|
partial_storage_key,
|
@@ -118,7 +118,7 @@ module ScaleRb
|
|
118
118
|
)
|
119
119
|
end
|
120
120
|
else
|
121
|
-
storage_key = StorageHelper.encode_storage_key(pallet_name, item_name, key, registry).
|
121
|
+
storage_key = StorageHelper.encode_storage_key(pallet_name, item_name, key, registry)._to_hex
|
122
122
|
data = state_getStorage(url, storage_key, at)
|
123
123
|
StorageHelper.decode_storage(data, value[:type], value[:modifier] == 'Optional', value[:fallback], registry)
|
124
124
|
end
|
@@ -168,7 +168,7 @@ module ScaleRb
|
|
168
168
|
# convert key to byte array
|
169
169
|
def c(key)
|
170
170
|
if key.start_with?('0x')
|
171
|
-
key.
|
171
|
+
key._to_bytes
|
172
172
|
elsif key.to_i.to_s == key # check if key is a number
|
173
173
|
key.to_i
|
174
174
|
else
|
@@ -2,52 +2,54 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
module ScaleRb
|
6
|
+
module RpcRequestBuilder
|
7
|
+
def build_json_rpc_body(method, params, id)
|
8
|
+
{
|
9
|
+
'id' => id,
|
10
|
+
'jsonrpc' => '2.0',
|
11
|
+
'method' => method,
|
12
|
+
'params' => params.reject(&:nil?)
|
13
|
+
}.to_json
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def respond_to_missing?(*_args)
|
17
|
+
true
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
# example:
|
21
|
+
# state_getStorage(1, '0x363a..', 563_868)
|
22
|
+
#
|
23
|
+
# ==
|
24
|
+
#
|
25
|
+
# build_json_rpc_body('state_getStorage', ['0x363a..', 563_868], 1)
|
26
|
+
def method_missing(method, *args)
|
27
|
+
build_json_rpc_body(method, args[1..], args[0])
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
###################################
|
31
|
+
# derived functions
|
32
|
+
###################################
|
33
|
+
def derived_state_get_storage(rpc_id, pallet_name, item_name, key = nil, registry = nil)
|
34
|
+
storage_key = StorageHelper.encode_storage_key(pallet_name, item_name, key, registry)._to_hex
|
35
|
+
state_getStorage(rpc_id, [storage_key])
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
def derived_state_subscribe_storage(rpc_id, pallet_name, item_name, key = nil, registry = nil)
|
39
|
+
storage_key = StorageHelper.encode_storage_key(pallet_name, item_name, key, registry)._to_hex
|
40
|
+
state_subscribeStorage(rpc_id, [storage_key])
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
def derived_eth_call(rpc_id, to, data, at = nil)
|
44
|
+
eth_call(
|
45
|
+
rpc_id,
|
46
|
+
[
|
47
|
+
{
|
48
|
+
'from' => nil, 'to' => to, 'data' => data
|
49
|
+
},
|
50
|
+
at
|
51
|
+
]
|
52
|
+
)
|
53
|
+
end
|
52
54
|
end
|
53
55
|
end
|
data/lib/codec.rb
CHANGED
@@ -145,12 +145,12 @@ module ScaleRb
|
|
145
145
|
when 0
|
146
146
|
[bytes[0] >> 2, bytes[1..]]
|
147
147
|
when 1
|
148
|
-
[bytes[0..1].
|
148
|
+
[bytes[0..1]._flip._to_uint >> 2, bytes[2..]]
|
149
149
|
when 2
|
150
|
-
[bytes[0..3].
|
150
|
+
[bytes[0..3]._flip._to_uint >> 2, bytes[4..]]
|
151
151
|
when 3
|
152
152
|
length = 4 + (bytes[0] >> 2)
|
153
|
-
[bytes[1..length].
|
153
|
+
[bytes[1..length]._flip._to_uint, bytes[length + 1..]]
|
154
154
|
else
|
155
155
|
raise Unreachable, 'type: Compact'
|
156
156
|
end
|
@@ -220,7 +220,7 @@ module ScaleRb
|
|
220
220
|
|
221
221
|
def decode_bytes(bytes)
|
222
222
|
length, remaining_bytes = _do_decode_compact(bytes)
|
223
|
-
value = remaining_bytes[0...length].
|
223
|
+
value = remaining_bytes[0...length]._to_hex
|
224
224
|
# debug 'length', length
|
225
225
|
# debug 'value', value
|
226
226
|
[
|
@@ -246,7 +246,7 @@ module ScaleRb
|
|
246
246
|
length, remaining_bytes = _do_decode_compact(bytes)
|
247
247
|
raise NotEnoughBytesError, 'type: String' if remaining_bytes.length < length
|
248
248
|
|
249
|
-
value = remaining_bytes[0...length].
|
249
|
+
value = remaining_bytes[0...length]._to_utf8
|
250
250
|
# debug 'byte length', length
|
251
251
|
# debug 'value', value.inspect
|
252
252
|
[
|
@@ -260,7 +260,7 @@ module ScaleRb
|
|
260
260
|
byte_length = bit_length / 8
|
261
261
|
raise NotEnoughBytesError, "type: #{type}" if bytes.length < byte_length
|
262
262
|
|
263
|
-
value = bytes[0...byte_length].
|
263
|
+
value = bytes[0...byte_length]._flip._to_int(bit_length)
|
264
264
|
# debug 'value', value
|
265
265
|
[
|
266
266
|
value,
|
@@ -273,7 +273,7 @@ module ScaleRb
|
|
273
273
|
byte_length = bit_length / 8
|
274
274
|
raise NotEnoughBytesError, "type: #{type_def}" if bytes.length < byte_length
|
275
275
|
|
276
|
-
value = bytes[0...byte_length].
|
276
|
+
value = bytes[0...byte_length]._flip._to_uint
|
277
277
|
# debug 'value', value
|
278
278
|
[
|
279
279
|
value,
|
@@ -396,16 +396,16 @@ module ScaleRb
|
|
396
396
|
|
397
397
|
def encode_compact(value)
|
398
398
|
return [value << 2] if (value >= 0) && (value < 64)
|
399
|
-
return ((value << 2) + 1).
|
400
|
-
return ((value << 2) + 2).
|
399
|
+
return ((value << 2) + 1)._to_bytes._flip if value < 2**14
|
400
|
+
return ((value << 2) + 2)._to_bytes._flip if value < 2**30
|
401
401
|
|
402
|
-
bytes = value.
|
402
|
+
bytes = value._to_bytes._flip
|
403
403
|
[(((bytes.length - 4) << 2) + 3)] + bytes
|
404
404
|
end
|
405
405
|
|
406
406
|
def encode_uint(type, value)
|
407
407
|
bit_length = type[1..].to_i
|
408
|
-
value.
|
408
|
+
value._to_bytes(bit_length)._flip
|
409
409
|
end
|
410
410
|
|
411
411
|
def encode_option(type, value, registry = {})
|