scale_rb 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/console +0 -0
- data/examples/http_client_3.rb +84 -0
- data/exe/metadata +1 -1
- data/lib/scale_rb/call_helper.rb +5 -5
- data/lib/scale_rb/client/{client_ext.rb → client_share.rb} +12 -6
- data/lib/scale_rb/client/http_client.rb +2 -2
- data/lib/scale_rb/client/ws_client.rb +2 -2
- data/lib/scale_rb/decode.rb +17 -0
- data/lib/scale_rb/extrinsic_helper.rb +50 -0
- data/lib/scale_rb/metadata/metadata.rb +213 -65
- data/lib/scale_rb/metadata/metadata_v10.rb +40 -40
- data/lib/scale_rb/metadata/metadata_v11.rb +44 -44
- data/lib/scale_rb/metadata/metadata_v12.rb +22 -22
- data/lib/scale_rb/metadata/metadata_v13.rb +45 -45
- data/lib/scale_rb/metadata/metadata_v14.rb +123 -117
- data/lib/scale_rb/metadata/metadata_v9.rb +56 -56
- data/lib/scale_rb/old_registry.rb +552 -0
- data/lib/scale_rb/portable_registry.rb +30 -12
- data/lib/scale_rb/storage_helper.rb +9 -5
- data/lib/scale_rb/types.rb +9 -2
- data/lib/scale_rb/version.rb +1 -1
- data/lib/scale_rb.rb +3 -1
- metadata +7 -6
- data/lib/scale_rb/metadata/registry.rb +0 -263
- data/lib/scale_rb/metadata/type_exp.rb +0 -286
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8d513edcbe185b4b84fa7e7f9a89f9787e658e79a42aac9843d0d225f5f1ecd
|
4
|
+
data.tar.gz: 14ed9841bb41104aa9a064b45f3f170c77f4c8aeb1eddd015d4cc62587c8d0e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1488b38cb5b710b3f438508c14a6aff777d7374d12c25badbdf05ff8dd745ad64512b4e0dddbcc718a0e344aa518de50b95f9d0594a0e55f15981d7043f85672
|
7
|
+
data.tar.gz: 5ee07ecf3b77535a52944ee1f68fb49558f4a0b276727121e029c19e73faff2eb48be6598ea91b82aac0477075c4f76f8b962c9dddd9ecef3a2d1514ae041b24
|
data/bin/console
CHANGED
File without changes
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'scale_rb'
|
2
|
+
|
3
|
+
client = ScaleRb::HttpClient.new('https://polkadot-rpc.dwellir.com')
|
4
|
+
puts format('%20s: %s', 'supported_methods', client.supported_methods.join(', '))
|
5
|
+
|
6
|
+
block_number = 22_931_689
|
7
|
+
puts format('%20s: %d', 'block_number', block_number)
|
8
|
+
|
9
|
+
block_hash = client.chain_getBlockHash(block_number)
|
10
|
+
puts format('%20s: %s', 'block_hash', block_hash)
|
11
|
+
|
12
|
+
runtime_version = client.state_getRuntimeVersion(block_hash)
|
13
|
+
puts format('%20s: %s', 'spec_name', runtime_version[:specName])
|
14
|
+
puts format('%20s: %s', 'spec_version', runtime_version[:specVersion])
|
15
|
+
|
16
|
+
metadata = client.get_metadata(block_hash)
|
17
|
+
|
18
|
+
######################################
|
19
|
+
# Events
|
20
|
+
######################################
|
21
|
+
events = client.get_storage('System', 'Events', block_hash:, metadata:)
|
22
|
+
events.each_with_index do |event, index|
|
23
|
+
puts format('%20s: %d', 'event index', index)
|
24
|
+
puts format('%20s: %s', 'event', event)
|
25
|
+
end
|
26
|
+
|
27
|
+
######################################
|
28
|
+
# Validators
|
29
|
+
######################################
|
30
|
+
validators = client.get_storage('Session', 'Validators', block_hash:, metadata:)
|
31
|
+
validators.each_with_index do |validator, index|
|
32
|
+
puts format('%20s: %d', 'validator index', index)
|
33
|
+
puts format('%20s: %s', 'validator', ScaleRb::Utils.u8a_to_hex(validator))
|
34
|
+
end
|
35
|
+
|
36
|
+
######################################
|
37
|
+
# Block
|
38
|
+
######################################
|
39
|
+
blockResult = client.chain_getBlock(block_hash)
|
40
|
+
|
41
|
+
block = blockResult[:block]
|
42
|
+
justifications = blockResult[:justifications]
|
43
|
+
puts format('%20s: %s', 'justifications', justifications)
|
44
|
+
|
45
|
+
header = block[:header]
|
46
|
+
|
47
|
+
parent_hash = header[:parentHash]
|
48
|
+
puts format('%20s: %s', 'parent_hash', parent_hash)
|
49
|
+
|
50
|
+
state_root = header[:stateRoot]
|
51
|
+
puts format('%20s: %s', 'state_root', state_root)
|
52
|
+
|
53
|
+
extrinsics_root = header[:extrinsicsRoot]
|
54
|
+
puts format('%20s: %s', 'extrinsics_root', extrinsics_root)
|
55
|
+
|
56
|
+
digest_logs = header[:digest][:logs]
|
57
|
+
pre_runtime_log = nil
|
58
|
+
digest_logs.each_with_index do |digest_log, index|
|
59
|
+
decoded, = ScaleRb::Codec.decode(
|
60
|
+
metadata.digest_item_type_id,
|
61
|
+
ScaleRb::Utils.hex_to_u8a(digest_log),
|
62
|
+
metadata.registry
|
63
|
+
)
|
64
|
+
puts format('%20s: %d', 'log index', index)
|
65
|
+
puts format('%20s: %s', 'log', decoded)
|
66
|
+
|
67
|
+
# check if decoded has a key of "PreRuntime"
|
68
|
+
pre_runtime_log = decoded[:PreRuntime] if decoded.key?(:PreRuntime)
|
69
|
+
end
|
70
|
+
|
71
|
+
engine = pre_runtime_log[0]
|
72
|
+
puts format('%20s: %s', 'engine', ScaleRb::Utils.u8a_to_utf8(engine))
|
73
|
+
data = pre_runtime_log[1] # if engine is BABE, data's type is sp_consensus_babe::digests::PreDigest
|
74
|
+
authority_index, = ScaleRb::CodecUtils.decode_uint('U32', data[1..]) # we don't need to decode the data, but get the authority_index
|
75
|
+
puts format('%20s: %d', 'authority_index', authority_index)
|
76
|
+
author = validators[authority_index]
|
77
|
+
puts format('%20s: %s', 'author', ScaleRb::Utils.u8a_to_hex(author))
|
78
|
+
|
79
|
+
extrinsics = block[:extrinsics]
|
80
|
+
extrinsics.each_with_index do |extrinsic, index|
|
81
|
+
puts format('%20s: %d', 'extrinsic index', index)
|
82
|
+
decoded = ScaleRb::ExtrinsicHelper.decode_extrinsic(ScaleRb::Utils.hex_to_u8a(extrinsic), metadata)
|
83
|
+
puts format('%20s: %s', 'extrinsic', decoded)
|
84
|
+
end
|
data/exe/metadata
CHANGED
data/lib/scale_rb/call_helper.rb
CHANGED
@@ -9,7 +9,7 @@ module ScaleRb
|
|
9
9
|
# "0x05000a1287977578f888bdc1c7627781af1cc000e6ab1300004c31b8d9a798"._to_bytes
|
10
10
|
def self.decode_call(callbytes, metadata)
|
11
11
|
pallet_index = callbytes[0]
|
12
|
-
pallet =
|
12
|
+
pallet = metadata.pallet_by_index(pallet_index)
|
13
13
|
|
14
14
|
# Remove the pallet_index
|
15
15
|
# The callbytes we used below should not contain the pallet index.
|
@@ -20,7 +20,7 @@ module ScaleRb
|
|
20
20
|
decoded = Codec.decode(
|
21
21
|
calls_type_id,
|
22
22
|
callbytes_without_pallet_index,
|
23
|
-
|
23
|
+
metadata.build_registry
|
24
24
|
)&.first
|
25
25
|
|
26
26
|
{
|
@@ -34,9 +34,9 @@ module ScaleRb
|
|
34
34
|
# {:pallet_name=>"Deposit", :call_name=>"claim", :call=>:claim]}
|
35
35
|
# {:pallet_name=>"Balances", :call_name=>"transfer", :call=>{:transfer=>{:dest=>[10, 18, 135, 151, 117, 120, 248, 136, 189, 193, 199, 98, 119, 129, 175, 28, 192, 0, 230, 171], :value=>11000000000000000000}}]}
|
36
36
|
def self.encode_call(call, metadata)
|
37
|
-
calls_type_id =
|
38
|
-
pallet_index =
|
39
|
-
[pallet_index] + Codec.encode(calls_type_id, call[:call],
|
37
|
+
calls_type_id = metadata.calls_type_id(call[:pallet_name])
|
38
|
+
pallet_index = metadata.pallet(call[:pallet_name])[:index]
|
39
|
+
[pallet_index] + Codec.encode(calls_type_id, call[:call], metadata.build_registry)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module ScaleRb
|
2
2
|
# This module is used to add extra methods to both the ScaleRb::WsClient ScaleRb::HttpClient
|
3
|
-
module
|
3
|
+
module ClientShare
|
4
4
|
# get decoded metadata at block_hash
|
5
5
|
def get_metadata(block_hash = nil)
|
6
6
|
block_hash ||= chain_getHead
|
7
7
|
metadata_hex = state_getMetadata(block_hash)
|
8
|
-
Metadata.
|
8
|
+
Metadata::Metadata.from_hex(metadata_hex)
|
9
9
|
end
|
10
10
|
|
11
11
|
# Get decoded storage at block_hash
|
@@ -30,6 +30,14 @@ module ScaleRb
|
|
30
30
|
)
|
31
31
|
end
|
32
32
|
|
33
|
+
def respond_to_missing?(*_args)
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
def method_missing(method, *args)
|
38
|
+
request(method.to_s, args)
|
39
|
+
end
|
40
|
+
|
33
41
|
private
|
34
42
|
|
35
43
|
def query_storage_at(block_hash, storage_keys, type_id, default, registry)
|
@@ -134,10 +142,8 @@ module ScaleRb
|
|
134
142
|
def get_storage2(block_hash, pallet_name, item_name, params, metadata)
|
135
143
|
raise 'Metadata should not be nil' if metadata.nil?
|
136
144
|
|
137
|
-
registry =
|
138
|
-
item =
|
139
|
-
pallet_name, item_name, metadata
|
140
|
-
)
|
145
|
+
registry = metadata.registry
|
146
|
+
item = metadata.storage(pallet_name, item_name)
|
141
147
|
raise "No such storage item: `#{pallet_name}`.`#{item_name}`" if item.nil?
|
142
148
|
|
143
149
|
modifier = item._get(:modifier) # Default | Optional
|
@@ -4,11 +4,11 @@ require 'uri'
|
|
4
4
|
require 'net/http'
|
5
5
|
require 'json'
|
6
6
|
|
7
|
-
require_relative '
|
7
|
+
require_relative 'client_share'
|
8
8
|
|
9
9
|
module ScaleRb
|
10
10
|
class HttpClient
|
11
|
-
include
|
11
|
+
include ClientShare
|
12
12
|
attr_accessor :supported_methods
|
13
13
|
|
14
14
|
def initialize(url)
|
@@ -2,7 +2,7 @@ require 'async'
|
|
2
2
|
require 'async/websocket/client'
|
3
3
|
require 'async/http/endpoint'
|
4
4
|
|
5
|
-
require_relative '
|
5
|
+
require_relative 'client_share'
|
6
6
|
|
7
7
|
module ScaleRb
|
8
8
|
class WsClient
|
@@ -52,7 +52,7 @@ end
|
|
52
52
|
|
53
53
|
module ScaleRb
|
54
54
|
class WsClient
|
55
|
-
include
|
55
|
+
include ClientShare
|
56
56
|
attr_accessor :supported_methods
|
57
57
|
|
58
58
|
def initialize(connection)
|
data/lib/scale_rb/decode.rb
CHANGED
@@ -19,6 +19,7 @@ module ScaleRb
|
|
19
19
|
when CompactType then decode_compact(bytes)
|
20
20
|
when ArrayType then decode_array(type, bytes, registry)
|
21
21
|
when SequenceType then decode_sequence(type, bytes, registry)
|
22
|
+
when BitSequenceType then decode_bit_sequence(type, bytes)
|
22
23
|
when TupleType then decode_tuple(type, bytes, registry)
|
23
24
|
when StructType then decode_struct(type, bytes, registry)
|
24
25
|
when UnitType then [[], bytes]
|
@@ -65,6 +66,22 @@ module ScaleRb
|
|
65
66
|
_decode_types([sequence_type.type] * len, remaining_bytes, registry)
|
66
67
|
end
|
67
68
|
|
69
|
+
__ :decode_bit_sequence, { sequence_type: BitSequenceType, bytes: U8Array }, DecodeResult[TypedArray[Any]]
|
70
|
+
def decode_bit_sequence(sequence_type, bytes)
|
71
|
+
ScaleRb.logger.debug("Decoding bit sequence: #{sequence_type}, bytes: #{bytes.length} bytes")
|
72
|
+
|
73
|
+
bit_len, remaining_bytes = decode_compact(bytes)
|
74
|
+
byte_len = (bit_len / 8.0).ceil
|
75
|
+
the_bytes, remaining_bytes = [remaining_bytes[0...byte_len], remaining_bytes[byte_len..]]
|
76
|
+
[
|
77
|
+
{
|
78
|
+
bytes: the_bytes,
|
79
|
+
bit_len: bit_len
|
80
|
+
},
|
81
|
+
remaining_bytes
|
82
|
+
]
|
83
|
+
end
|
84
|
+
|
68
85
|
__ :decode_tuple, { tuple_type: TupleType, bytes: U8Array, registry: Registry }, DecodeResult[TypedArray[Any] | Any]
|
69
86
|
def decode_tuple(tuple_type, bytes, registry)
|
70
87
|
ScaleRb.logger.debug("Decoding tuple: #{tuple_type}, bytes: #{bytes.length} bytes")
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ScaleRb
|
4
|
+
module ExtrinsicHelper
|
5
|
+
class << self
|
6
|
+
def decode_extrinsic(bytes, metadata)
|
7
|
+
extrinsic_hash = "0x#{Blake2b.hex(bytes, 32)}"
|
8
|
+
|
9
|
+
_, remaining_bytes = ScaleRb::Codec.decode_compact(bytes)
|
10
|
+
meta, remaining_bytes = [remaining_bytes[0], remaining_bytes[1..]]
|
11
|
+
signed = (meta & 0x80) == 0x80
|
12
|
+
version = (meta & 0x7f)
|
13
|
+
|
14
|
+
raise "Unsupported version: #{version}" unless version == 4
|
15
|
+
|
16
|
+
if signed
|
17
|
+
# puts "signed"
|
18
|
+
signature, remaining_bytes = ScaleRb::Codec.decode(
|
19
|
+
metadata.signature_type_id,
|
20
|
+
remaining_bytes,
|
21
|
+
metadata.registry
|
22
|
+
)
|
23
|
+
call, = ScaleRb::Codec.decode(
|
24
|
+
metadata.runtime_call_type_id,
|
25
|
+
remaining_bytes,
|
26
|
+
metadata.registry
|
27
|
+
)
|
28
|
+
{
|
29
|
+
version: 4,
|
30
|
+
signature: signature,
|
31
|
+
call: call,
|
32
|
+
extrinsic_hash: extrinsic_hash
|
33
|
+
}
|
34
|
+
else
|
35
|
+
# puts "unsigned"
|
36
|
+
call, = ScaleRb::Codec.decode(
|
37
|
+
metadata.runtime_call_type_id,
|
38
|
+
remaining_bytes,
|
39
|
+
metadata.registry
|
40
|
+
)
|
41
|
+
{
|
42
|
+
version: 4,
|
43
|
+
call: call,
|
44
|
+
extrinsic_hash: extrinsic_hash
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative './registry'
|
4
|
-
|
5
3
|
require_relative './metadata_v9'
|
6
4
|
require_relative './metadata_v10'
|
7
5
|
require_relative './metadata_v11'
|
@@ -13,95 +11,245 @@ require_relative './metadata_v14'
|
|
13
11
|
# https://github.com/paritytech/frame-metadata/blob/main/frame-metadata/src/lib.rs#L85
|
14
12
|
module ScaleRb
|
15
13
|
module Metadata
|
16
|
-
class
|
17
|
-
|
18
|
-
|
14
|
+
class Metadata
|
15
|
+
attr_reader :magic_number, :version, :metadata, :registry, :address_type_id, :runtime_call_type_id, :digest_type_id,
|
16
|
+
:digest_item_type_id, :event_record_list_type_id, :event_record_type_id, :event_type_id, :signature_type_id
|
17
|
+
|
18
|
+
# Runtime type ids
|
19
|
+
attr_reader :unchecked_extrinsic_type_id
|
20
|
+
|
21
|
+
def initialize(metadata_prefixed, unchecked_extrinsic_type_id = nil)
|
22
|
+
@metadata_prefixed = metadata_prefixed
|
23
|
+
@magic_number = @metadata_prefixed[:magicNumber]
|
24
|
+
metadata = @metadata_prefixed[:metadata]
|
25
|
+
@version = metadata.keys.first
|
26
|
+
raise "Unsupported metadata version: #{@version}" unless :V14 == @version
|
27
|
+
|
28
|
+
@metadata = metadata[@version]
|
29
|
+
@registry = ScaleRb::PortableRegistry.new(@metadata.dig(:lookup, :types))
|
30
|
+
|
31
|
+
# Runtime type ids
|
32
|
+
@unchecked_extrinsic_type_id = unchecked_extrinsic_type_id || find_unchecked_extrinsic_type_id
|
33
|
+
@address_type_id = find_address_type_id
|
34
|
+
@runtime_call_type_id = find_runtime_call_type_id
|
35
|
+
|
36
|
+
@digest_type_id = find_digest_type_id
|
37
|
+
@digest_item_type_id = find_digest_item_type_id
|
38
|
+
|
39
|
+
@event_record_list_type_id = find_event_record_list_type_id
|
40
|
+
@event_record_type_id = find_event_record_type_id
|
41
|
+
@event_type_id = find_event_type_id
|
42
|
+
|
43
|
+
@signature_type_id = build_signature_type_id
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.from_hex(hex)
|
47
|
+
metadata_prefixed, = ScaleRb::Codec.decode('MetadataPrefixed', Utils.hex_to_u8a(hex), OldRegistry.new(TYPES))
|
48
|
+
Metadata.new(metadata_prefixed)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.from_json(str)
|
52
|
+
metadata_prefixed = JSON.parse(str, symbolize_names: true)
|
53
|
+
Metadata.new(metadata_prefixed)
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_json(*_args)
|
57
|
+
JSON.pretty_generate(@metadata_prefixed)
|
58
|
+
end
|
59
|
+
|
60
|
+
def pallet(pallet_name)
|
61
|
+
@metadata[:pallets].find do |pallet|
|
62
|
+
pallet[:name] == pallet_name
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def pallet_by_index(pallet_index)
|
67
|
+
@metadata[:pallets].find do |pallet|
|
68
|
+
pallet[:index] == pallet_index
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def storage(pallet_name, item_name)
|
73
|
+
pallet = pallet(pallet_name)
|
74
|
+
raise "Pallet `#{pallet_name}` not found" if pallet.nil?
|
75
|
+
|
76
|
+
pallet.dig(:storage, :items).find do |item|
|
77
|
+
item[:name] == item_name
|
78
|
+
end
|
79
|
+
end
|
19
80
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
81
|
+
def error(pallet_index, error_index)
|
82
|
+
pallet = pallet_by_index(pallet_index)
|
83
|
+
raise "Pallet `#{pallet_index}` not found" if pallet.nil?
|
84
|
+
|
85
|
+
errors_type_id = pallet.dig(:errors, :type)
|
86
|
+
errors_type = @registry[errors_type_id]
|
87
|
+
error_variant = errors_type.variants.find do |variant|
|
88
|
+
variant.index == error_index
|
89
|
+
end
|
90
|
+
raise "Error `#{error_index}` not found" if errors_type.nil?
|
91
|
+
|
92
|
+
[
|
93
|
+
pallet[:name], error_variant.name.to_s
|
94
|
+
]
|
95
|
+
end
|
96
|
+
|
97
|
+
#########################################################################
|
98
|
+
|
99
|
+
# % pallet_call_type :: [String, String] -> SimpleVariant | TupleVariant | StructVariant
|
100
|
+
def pallet_call_type(pallet_name, call_name)
|
101
|
+
calls_type_id = pallet_calls_type_id(pallet_name)
|
102
|
+
|
103
|
+
calls_type = @registry[calls_type_id] # #<ScaleRb::Types::VariantType ...>
|
104
|
+
raise 'Calls type is not correct' if calls_type.nil?
|
105
|
+
|
106
|
+
calls_type.variants.find do |variant|
|
107
|
+
variant.name.to_s.downcase == call_name.downcase
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def pallet_call_names(pallet_name)
|
112
|
+
calls_type_id = pallet_calls_type_id(pallet_name)
|
113
|
+
return [] if calls_type_id.nil?
|
114
|
+
|
115
|
+
calls_type = @registry[calls_type_id] # #<ScaleRb::Types::VariantType ...>
|
116
|
+
raise 'Calls type is not correct' if calls_type.nil?
|
117
|
+
|
118
|
+
calls_type.variants.map do |variant|
|
119
|
+
variant.name.to_s
|
120
|
+
end
|
24
121
|
end
|
25
122
|
|
26
|
-
|
27
|
-
|
28
|
-
|
123
|
+
private
|
124
|
+
|
125
|
+
def find_unchecked_extrinsic_type_id
|
126
|
+
@registry.types.each_with_index do |type, index|
|
127
|
+
return index if type.path.first == 'sp_runtime' && type.path.last == 'UncheckedExtrinsic'
|
128
|
+
end
|
29
129
|
end
|
30
130
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
131
|
+
def find_address_type_id
|
132
|
+
@registry[@unchecked_extrinsic_type_id].params.find do |param|
|
133
|
+
param.name.downcase == 'address'
|
134
|
+
end.type
|
135
|
+
end
|
35
136
|
|
36
|
-
|
137
|
+
def find_runtime_call_type_id
|
138
|
+
@registry[@unchecked_extrinsic_type_id].params.find do |param|
|
139
|
+
param.name.downcase == 'call'
|
140
|
+
end.type
|
37
141
|
end
|
38
142
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
|
143
|
+
def find_extrinsic_signature_type_id
|
144
|
+
@registry[@unchecked_extrinsic_type_id].params.find do |param|
|
145
|
+
param.name.downcase == 'signature'
|
146
|
+
end.type
|
147
|
+
end
|
43
148
|
|
44
|
-
|
149
|
+
def find_digest_type_id
|
150
|
+
storage_item = storage('System', 'Digest')
|
151
|
+
storage_item.dig(:type, :plain)
|
45
152
|
end
|
46
153
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
154
|
+
def find_digest_item_type_id
|
155
|
+
# #<ScaleRb::Types::StructType registry=a_portable_registry path=["sp_runtime", "generic", "digest", "Digest"] params=[] fields=[#<ScaleRb::Types::Field name="logs" type=14>]>
|
156
|
+
digest_type = @registry[@digest_type_id]
|
157
|
+
|
158
|
+
field = digest_type.fields.find do |field|
|
159
|
+
field.name == 'logs'
|
160
|
+
end
|
161
|
+
seq = @registry[field.type]
|
162
|
+
raise 'Type is not correct' unless seq.is_a?(ScaleRb::Types::SequenceType)
|
163
|
+
|
164
|
+
seq.type
|
165
|
+
end
|
51
166
|
|
52
|
-
|
167
|
+
def find_event_record_list_type_id
|
168
|
+
storage_item = storage('System', 'Events')
|
169
|
+
storage_item.dig(:type, :plain)
|
53
170
|
end
|
54
171
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
raise NotImplementedError, version unless %i[V14].include?(version)
|
172
|
+
def find_event_record_type_id
|
173
|
+
seq = @registry[@event_record_list_type_id]
|
174
|
+
raise 'Type is not correct' unless seq.is_a?(ScaleRb::Types::SequenceType)
|
59
175
|
|
60
|
-
|
176
|
+
seq.type
|
61
177
|
end
|
62
178
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
179
|
+
def find_event_type_id
|
180
|
+
@registry[@event_record_type_id].fields.find do |field|
|
181
|
+
field.name == 'event'
|
182
|
+
end.type
|
183
|
+
end
|
184
|
+
|
185
|
+
def build_signature_type_id
|
186
|
+
signed_extensions_type = ScaleRb::Types::StructType.new(
|
187
|
+
path: ['SignedExtensions'],
|
188
|
+
fields: @metadata[:extrinsic][:signedExtensions].map do |signed_extension|
|
189
|
+
ScaleRb::Types::Field.new(
|
190
|
+
name: signed_extension[:identifier],
|
191
|
+
type: signed_extension[:type]
|
192
|
+
)
|
193
|
+
end,
|
194
|
+
registry: @registry
|
195
|
+
)
|
196
|
+
|
197
|
+
signed_extensions_type_id = @registry.add_type(signed_extensions_type)
|
67
198
|
|
68
|
-
|
199
|
+
signature_type = ScaleRb::Types::StructType.new(
|
200
|
+
path: ['ExtrinsicSignature'],
|
201
|
+
fields: [
|
202
|
+
ScaleRb::Types::Field.new(name: 'address', type: @address_type_id),
|
203
|
+
ScaleRb::Types::Field.new(name: 'signature', type: find_extrinsic_signature_type_id),
|
204
|
+
ScaleRb::Types::Field.new(name: 'signedExtensions', type: signed_extensions_type_id)
|
205
|
+
],
|
206
|
+
registry: @registry
|
207
|
+
)
|
208
|
+
|
209
|
+
@registry.add_type(signature_type)
|
69
210
|
end
|
70
211
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
212
|
+
# equals to:
|
213
|
+
# pallet = pallet(pallet_name)
|
214
|
+
# raise "Pallet `#{pallet_name}` not found" if pallet.nil?
|
215
|
+
# pallet.dig(:calls, :type)
|
216
|
+
def pallet_calls_type_id(pallet_name)
|
217
|
+
runtime_call_type = @registry[@runtime_call_type_id]
|
218
|
+
v = runtime_call_type.variants.find do |variant|
|
219
|
+
variant.name.to_s.downcase == pallet_name.downcase
|
220
|
+
end
|
75
221
|
|
76
|
-
|
222
|
+
v&.tuple&.tuple&.first
|
77
223
|
end
|
78
224
|
end
|
79
225
|
|
226
|
+
#########################################################################
|
227
|
+
|
80
228
|
TYPES = {
|
81
|
-
Type
|
82
|
-
Bytes
|
83
|
-
MetadataPrefixed
|
84
|
-
magicNumber
|
85
|
-
metadata
|
229
|
+
'Type' => 'Str',
|
230
|
+
'Bytes' => 'Vec<u8>',
|
231
|
+
'MetadataPrefixed' => {
|
232
|
+
'magicNumber' => 'U32',
|
233
|
+
'metadata' => 'Metadata'
|
86
234
|
},
|
87
|
-
Placeholder
|
88
|
-
Metadata
|
89
|
-
_enum
|
90
|
-
V0
|
91
|
-
V1
|
92
|
-
V2
|
93
|
-
V3
|
94
|
-
V4
|
95
|
-
V5
|
96
|
-
V6
|
97
|
-
V7
|
98
|
-
V8
|
99
|
-
V9
|
100
|
-
V10
|
101
|
-
V11
|
102
|
-
V12
|
103
|
-
V13
|
104
|
-
V14
|
235
|
+
'Placeholder' => 'Null',
|
236
|
+
'Metadata' => {
|
237
|
+
'_enum' => {
|
238
|
+
'V0' => 'Placeholder',
|
239
|
+
'V1' => 'Placeholder',
|
240
|
+
'V2' => 'Placeholder',
|
241
|
+
'V3' => 'Placeholder',
|
242
|
+
'V4' => 'Placeholder',
|
243
|
+
'V5' => 'Placeholder',
|
244
|
+
'V6' => 'Placeholder',
|
245
|
+
'V7' => 'Placeholder',
|
246
|
+
'V8' => 'Placeholder',
|
247
|
+
'V9' => 'MetadataV9',
|
248
|
+
'V10' => 'MetadataV10',
|
249
|
+
'V11' => 'MetadataV11',
|
250
|
+
'V12' => 'MetadataV12',
|
251
|
+
'V13' => 'MetadataV13',
|
252
|
+
'V14' => 'MetadataV14'
|
105
253
|
}
|
106
254
|
}
|
107
255
|
}.merge(MetadataV14::TYPES)
|