scale_rb 0.1.3 → 0.1.5

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.
data/lib/metadata.rb DELETED
@@ -1,199 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Metadata
4
- class << self
5
- def decode_metadata(bytes)
6
- metadata, = ScaleRb.decode('MetadataTop', bytes, TYPES)
7
- metadata
8
- end
9
-
10
- def build_registry(metadata)
11
- raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless metadata._get(:metadata)._key?(:v14)
12
-
13
- metadata_v14 = metadata._get(:metadata)._get(:v14)
14
- MetadataV14.build_registry(metadata_v14)
15
- end
16
-
17
- def get_storage_item(pallet_name, item_name, metadata)
18
- raise ScaleRb::NotImplemented, metadata._get(:metadata).keys.first unless metadata._get(:metadata)._key?(:v14)
19
-
20
- metadata_v14 = metadata._get(:metadata)._get(:v14)
21
- MetadataV14.get_storage_item(pallet_name, item_name, metadata_v14)
22
- end
23
- end
24
-
25
- TYPES = {
26
- 'MetadataTop' => {
27
- magicNumber: 'U32',
28
- metadata: 'Metadata'
29
- },
30
- 'Metadata' => {
31
- _enum: {
32
- v0: 'MetadataV0',
33
- v1: 'MetadataV1',
34
- v2: 'MetadataV2',
35
- v3: 'MetadataV3',
36
- v4: 'MetadataV4',
37
- v5: 'MetadataV5',
38
- v6: 'MetadataV6',
39
- v7: 'MetadataV7',
40
- v8: 'MetadataV8',
41
- v9: 'MetadataV9',
42
- v10: 'MetadataV10',
43
- v11: 'MetadataV11',
44
- v12: 'MetadataV12',
45
- v13: 'MetadataV13',
46
- v14: 'MetadataV14'
47
- }
48
- },
49
-
50
- 'MetadataV14' => {
51
- lookup: 'PortableRegistry',
52
- pallets: 'Vec<PalletMetadataV14>',
53
- extrinsic: 'ExtrinsicMetadataV14',
54
- type: 'SiLookupTypeId'
55
- },
56
-
57
- # PortableRegistry begin
58
- 'PortableRegistry' => {
59
- types: 'Vec<PortableTypeV14>'
60
- },
61
- 'PortableTypeV14' => {
62
- id: 'Si1LookupTypeId',
63
- type: 'Si1Type'
64
- },
65
- 'Si1LookupTypeId' => 'Compact',
66
- 'Si1Type' => {
67
- path: 'Si1Path',
68
- params: 'Vec<Si1TypeParameter>',
69
- def: 'Si1TypeDef',
70
- docs: 'Vec<Text>'
71
- },
72
- 'Si1Path' => 'Vec<Text>',
73
- 'Si1TypeParameter' => {
74
- name: 'Text',
75
- type: 'Option<Si1LookupTypeId>'
76
- },
77
- 'Si1TypeDef' => {
78
- _enum: {
79
- composite: 'Si1TypeDefComposite',
80
- variant: 'Si1TypeDefVariant',
81
- sequence: 'Si1TypeDefSequence',
82
- array: 'Si1TypeDefArray',
83
- tuple: 'Si1TypeDefTuple',
84
- primitive: 'Si1TypeDefPrimitive',
85
- compact: 'Si1TypeDefCompact',
86
- bitSequence: 'Si1TypeDefBitSequence',
87
- historicMetaCompat: 'Text' # TODO: sanitize?
88
- }
89
- },
90
- 'Si1TypeDefComposite' => {
91
- fields: 'Vec<Si1Field>'
92
- },
93
- 'Si1Field' => {
94
- name: 'Option<Text>',
95
- type: 'Si1LookupTypeId',
96
- typeName: 'Option<Text>',
97
- docs: 'Vec<Text>'
98
- },
99
- 'Si1TypeDefVariant' => {
100
- variants: 'Vec<Si1Variant>'
101
- },
102
- 'Si1Variant' => {
103
- name: 'Text',
104
- fields: 'Vec<Si1Field>',
105
- index: 'u8',
106
- docs: 'Vec<Text>'
107
- },
108
- 'Si1TypeDefSequence' => {
109
- type: 'Si1LookupTypeId'
110
- },
111
- 'Si1TypeDefArray' => {
112
- len: 'u32',
113
- type: 'Si1LookupTypeId'
114
- },
115
- 'Si1TypeDefTuple' => 'Vec<Si1LookupTypeId>',
116
- 'Si1TypeDefPrimitive' => {
117
- _enum: %w[
118
- Bool Char Str U8 U16 U32 U64 U128 U256 I8 I16 I32 I64 I128 I256
119
- ]
120
- },
121
- 'Si1TypeDefCompact' => {
122
- type: 'Si1LookupTypeId'
123
- },
124
- 'Si1TypeDefBitSequence' => {
125
- bitStoreType: 'Si1LookupTypeId',
126
- bitOrderType: 'Si1LookupTypeId'
127
- },
128
- # PortableRegistry end
129
-
130
- # PalletMetadataV14 begin
131
- 'PalletMetadataV14' => {
132
- name: 'Text',
133
- storage: 'Option<PalletStorageMetadataV14>',
134
- calls: 'Option<PalletCallMetadataV14>',
135
- events: 'Option<PalletEventMetadataV14>',
136
- constants: 'Vec<PalletConstantMetadataV14>',
137
- errors: 'Option<PalletErrorMetadataV14>',
138
- index: 'U8'
139
- },
140
- 'PalletStorageMetadataV14' => {
141
- prefix: 'Text',
142
- items: 'Vec<StorageEntryMetadataV14>'
143
- },
144
- 'StorageEntryMetadataV14' => {
145
- name: 'Text',
146
- modifier: 'StorageEntryModifierV14',
147
- type: 'StorageEntryTypeV14',
148
- fallback: 'Bytes',
149
- docs: 'Vec<Text>'
150
- },
151
- 'StorageEntryModifierV14' => {
152
- _enum: %w[Optional Default Required]
153
- },
154
- 'StorageEntryTypeV14' => {
155
- _enum: {
156
- plain: 'SiLookupTypeId',
157
- map: {
158
- hashers: 'Vec<StorageHasherV14>',
159
- key: 'SiLookupTypeId',
160
- value: 'SiLookupTypeId'
161
- }
162
- }
163
- },
164
- 'StorageHasherV14' => {
165
- _enum: %w[Blake2128 Blake2256 Blake2128Concat Twox128 Twox256 Twox64Concat Identity]
166
- },
167
- 'PalletCallMetadataV14' => {
168
- type: 'Si1LookupTypeId'
169
- },
170
- 'PalletEventMetadataV14' => {
171
- type: 'SiLookupTypeId'
172
- },
173
- 'PalletConstantMetadataV14' => {
174
- name: 'Text',
175
- type: 'SiLookupTypeId',
176
- value: 'Bytes',
177
- docs: 'Vec<Text>'
178
- },
179
- 'PalletErrorMetadataV14' => {
180
- type: 'SiLookupTypeId'
181
- },
182
- # PalletMetadataV14 end
183
-
184
- # ExtrinsicMetadataV14 begin
185
- 'ExtrinsicMetadataV14' => {
186
- type: 'SiLookupTypeId',
187
- version: 'u8',
188
- signedExtensions: 'Vec<SignedExtensionMetadataV14>'
189
- },
190
- 'SignedExtensionMetadataV14' => {
191
- identifier: 'Text',
192
- type: 'SiLookupTypeId',
193
- additionalSigned: 'SiLookupTypeId'
194
- },
195
- # ExtrinsicMetadataV14 end
196
-
197
- 'SiLookupTypeId' => 'Compact'
198
- }.freeze
199
- end
data/lib/metadata_v14.rb DELETED
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MetadataV14
4
- class << self
5
- def build_registry(metadata)
6
- types = metadata._get(:lookup)._get(:types)
7
- types.map { |type| [type._get(:id), type._get(:type)] }.to_h
8
- end
9
-
10
- def get_storage_item(pallet_name, item_name, metadata)
11
- pallet =
12
- metadata._get(:pallets).find do |p|
13
- p._get(:name) == pallet_name
14
- end
15
-
16
- pallet._get(:storage)._get(:items).find do |item|
17
- item._get(:name) == item_name
18
- end
19
- end
20
- end
21
- end
data/lib/substrate/rpc.rb DELETED
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'uri'
4
- require 'net/http'
5
- require 'json'
6
-
7
- module Substrate
8
- module RPC
9
- class << self
10
- def json_rpc_call(method, params, url)
11
- uri = URI(url)
12
- req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
13
- req.body = {
14
- 'id' => 1,
15
- 'jsonrpc' => '2.0',
16
- 'method' => method,
17
- 'params' => params.reject(&:nil?)
18
- }.to_json
19
- http = Net::HTTP.new(uri.host, uri.port)
20
- http.use_ssl = true if uri.instance_of? URI::HTTPS
21
- res = http.request(req)
22
- # puts res unless res.is_a?(Net::HTTPSuccess)
23
-
24
- result = JSON.parse(res.body)
25
- raise result['error'] if result['error']
26
-
27
- result['result']
28
- end
29
-
30
- def chain_getBlockHash(url, block_number = nil)
31
- json_rpc_call('chain_getBlockHash', [block_number], url)
32
- end
33
-
34
- def chain_getBlock(url, at = nil)
35
- json_rpc_call('chain_getBlock', [at], url)
36
- end
37
-
38
- def state_getRuntimeVersion(url, at = nil)
39
- json_rpc_call('state_getRuntimeVersion', [at], url)
40
- end
41
-
42
- def state_getMetadata(url, at = nil)
43
- json_rpc_call('state_getMetadata', [at], url)
44
- end
45
-
46
- def state_getStorage(url, key, at = nil)
47
- json_rpc_call('state_getStorage', [key, at], url)
48
- end
49
-
50
- def state_queryStorageAt(url, keys, at = nil)
51
- json_rpc_call('state_queryStorageAt', [keys, at], url)
52
- end
53
-
54
- def state_getKeysPaged(url, key, count, start_key = nil, at = nil)
55
- json_rpc_call('state_getKeysPaged', [key, count, start_key, at], url)
56
- end
57
-
58
- def eth_call(url, to, data, at_block_number = nil)
59
- json_rpc_call('eth_call', [
60
- {
61
- 'from' => nil,
62
- 'to' => to,
63
- 'data' => data
64
- },
65
- at_block_number
66
- ], url)
67
- end
68
- end
69
- end
70
- end