scale_rb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +42 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/metadata +41 -0
- data/bin/setup +8 -0
- data/lib/client/client.rb +76 -0
- data/lib/client/rpc.rb +60 -0
- data/lib/codec.rb +387 -0
- data/lib/hasher.rb +54 -0
- data/lib/metadata.rb +199 -0
- data/lib/metadata_v14.rb +21 -0
- data/lib/monkey_patching.rb +113 -0
- data/lib/portable_codec.rb +251 -0
- data/lib/registry.rb +13 -0
- data/lib/scale_rb/version.rb +3 -0
- data/lib/scale_rb.rb +39 -0
- data/lib/storage_helper.rb +38 -0
- data/scale_rb.gemspec +31 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9c3aee2a13ae3b588fe3d5509baa64a5e094f854909b96281b9e5f188af78334
|
4
|
+
data.tar.gz: 537c85eac26ca0875a09ec86f94529c990d4ce372a88958cc84e4afaf580008e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d71fd420377e34be29f01a776513900a2645f66011eb5a68844bffc42f7336cd1dab13c3c54dbda1a942c011876886037d97f6c77e93009c618836b8b47c9ee5
|
7
|
+
data.tar.gz: 6d9629f27133339142312f47e8d2c06b01c6956bcdc3a1d5cff9c49a692821211762ac41eda1a7ae6b338f6791b6f79aa24c411413d3a0de58832a1d51594dde
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at aki.wu@itering.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
scale_rb (0.1.0)
|
5
|
+
blake2b_rs (~> 0.1.2)
|
6
|
+
xxhash
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
blake2b_rs (0.1.3)
|
12
|
+
ffi (~> 1.0)
|
13
|
+
thermite (~> 0)
|
14
|
+
diff-lcs (1.5.0)
|
15
|
+
ffi (1.15.5)
|
16
|
+
minitar (0.9)
|
17
|
+
rake (12.3.3)
|
18
|
+
rspec (3.11.0)
|
19
|
+
rspec-core (~> 3.11.0)
|
20
|
+
rspec-expectations (~> 3.11.0)
|
21
|
+
rspec-mocks (~> 3.11.0)
|
22
|
+
rspec-core (3.11.0)
|
23
|
+
rspec-support (~> 3.11.0)
|
24
|
+
rspec-expectations (3.11.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.11.0)
|
27
|
+
rspec-mocks (3.11.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.11.0)
|
30
|
+
rspec-support (3.11.0)
|
31
|
+
thermite (0.13.0)
|
32
|
+
minitar (~> 0.5)
|
33
|
+
rake (>= 10)
|
34
|
+
tomlrb (~> 1.2)
|
35
|
+
tomlrb (1.3.0)
|
36
|
+
xxhash (0.5.0)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
rake (~> 12.0)
|
43
|
+
rspec (~> 3.0)
|
44
|
+
scale_rb!
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Aki Wu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# ScaleRb
|
2
|
+
|
3
|
+
*WARNING: UNDER DEVELOPMENT*
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'scale_rb'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install scale_rb
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wuminzhe/scale_rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/wuminzhe/scale_rb/blob/master/CODE_OF_CONDUCT.md).
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
39
|
+
|
40
|
+
## Code of Conduct
|
41
|
+
|
42
|
+
Everyone interacting in the ScaleRb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/scale_rb/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "scale_rb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/metadata
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'scale_rb'
|
5
|
+
require 'json'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
def print_metadata(url, at = nil)
|
9
|
+
puts JSON.pretty_generate(Client.get_metadata(url, at))
|
10
|
+
end
|
11
|
+
|
12
|
+
# ./bin/metadata http://g2.dev.darwinia.network:2234 -b 0x23ebddd6519aaf1b7fc916c3709af13d7a4010943fb53038406581171000a58e
|
13
|
+
# ./bin/metadata https://rpc.darwinia.network -b 10511703
|
14
|
+
# ./bin/metadata https://pangoro-rpc.darwinia.network
|
15
|
+
@options = {}
|
16
|
+
parser = OptionParser.new do |opts|
|
17
|
+
opts.banner = 'Usage: metadata [url] [options]'
|
18
|
+
opts.on('-bNUMBERORHASH', '--block=NUMBERORHASH', 'Block number or hash') do |value|
|
19
|
+
@options[:block] = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if ARGV.empty?
|
24
|
+
puts parser
|
25
|
+
else
|
26
|
+
parser.parse!
|
27
|
+
url = ARGV[0]
|
28
|
+
|
29
|
+
if @options[:block]
|
30
|
+
if @options[:block].length == 66
|
31
|
+
block_hash = @options[:block]
|
32
|
+
else
|
33
|
+
block_number = @options[:block].to_i
|
34
|
+
block_hash = RPC.chain_getBlockHash url, block_number
|
35
|
+
end
|
36
|
+
else
|
37
|
+
block_hash = RPC.chain_getBlockHash url
|
38
|
+
end
|
39
|
+
|
40
|
+
print_metadata url, block_hash
|
41
|
+
end
|
data/bin/setup
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Client
|
4
|
+
class << self
|
5
|
+
def get_metadata(url, at = nil)
|
6
|
+
hex = RPC.state_getMetadata(url, at)
|
7
|
+
Metadata.decode_metadata(hex.strip.to_bytes)
|
8
|
+
end
|
9
|
+
|
10
|
+
# type_id: result type id
|
11
|
+
def get_storage(url, storage_key, type_id, default, registry, at = nil)
|
12
|
+
data = RPC.state_getStorage(url, storage_key, at) || default
|
13
|
+
return nil if data.nil?
|
14
|
+
|
15
|
+
PortableCodec.decode(type_id, data.to_bytes, registry)[0]
|
16
|
+
end
|
17
|
+
|
18
|
+
# key: { value: .., type: 0, hashers: ['Blake2128Concat'] } | nil
|
19
|
+
# value: { type: 3, modifier: 'Default', callback: '' }
|
20
|
+
#
|
21
|
+
# example:
|
22
|
+
# 'System',
|
23
|
+
# 'Account',
|
24
|
+
# key = {
|
25
|
+
# value: [['0x724d50824542b56f422588421643c4a162b90b5416ef063f2266a1eae6651641'.to_bytes]], # [AccountId]
|
26
|
+
# type: 0,
|
27
|
+
# hashers: ['Blake2128Concat']
|
28
|
+
# },
|
29
|
+
# value = {
|
30
|
+
# type: 3,
|
31
|
+
# modifier: 'Default',
|
32
|
+
# callback: '0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
|
33
|
+
# },
|
34
|
+
# ..
|
35
|
+
def get_storage2(url, pallet_name, item_name, key, value, registry, at = nil)
|
36
|
+
params = (StorageHelper.build_params(key[:value], key[:type], key[:hashers], registry) if key)
|
37
|
+
|
38
|
+
storage_key = StorageHelper.encode_storage_key(pallet_name, item_name, params, registry).to_hex
|
39
|
+
get_storage(
|
40
|
+
url,
|
41
|
+
storage_key,
|
42
|
+
value[:type],
|
43
|
+
value[:modifier] == 'Default' ? value[:fallback] : nil,
|
44
|
+
registry,
|
45
|
+
at
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_storage3(url, pallet_name, item_name, key_value, metadata, at = nil)
|
50
|
+
registry = Metadata.build_registry(metadata)
|
51
|
+
item = Metadata.get_storage_item(pallet_name, item_name, metadata)
|
52
|
+
|
53
|
+
modifier = item._get(:modifier) # Default | Optional
|
54
|
+
fallback = item._get(:fallback)
|
55
|
+
type = item._get(:type)
|
56
|
+
|
57
|
+
plain = type._get(:plain)
|
58
|
+
map = type._get(:map)
|
59
|
+
key, value =
|
60
|
+
if plain
|
61
|
+
[
|
62
|
+
nil,
|
63
|
+
{ type: plain, modifier: modifier, fallback: fallback }
|
64
|
+
]
|
65
|
+
elsif map
|
66
|
+
[
|
67
|
+
{ value: key_value, type: map._get(:key), hashers: map._get(:hashers) },
|
68
|
+
{ type: map._get(:value), modifier: modifier, fallback: fallback }
|
69
|
+
]
|
70
|
+
else
|
71
|
+
raise 'NoSuchStorageType'
|
72
|
+
end
|
73
|
+
get_storage2(url, pallet_name, item_name, key, value, registry, at)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/client/rpc.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module RPC
|
8
|
+
class << self
|
9
|
+
def json_rpc_call(method, params, url)
|
10
|
+
uri = URI(url)
|
11
|
+
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
12
|
+
req.body = {
|
13
|
+
'id' => 1,
|
14
|
+
'jsonrpc' => '2.0',
|
15
|
+
'method' => method,
|
16
|
+
'params' => params.all?(nil) ? [] : params
|
17
|
+
}.to_json
|
18
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
19
|
+
http.use_ssl = true if uri.instance_of? URI::HTTPS
|
20
|
+
res = http.request(req)
|
21
|
+
# puts res unless res.is_a?(Net::HTTPSuccess)
|
22
|
+
|
23
|
+
result = JSON.parse(res.body)
|
24
|
+
raise result['error'] if result['error']
|
25
|
+
|
26
|
+
result['result']
|
27
|
+
end
|
28
|
+
|
29
|
+
def chain_getBlockHash(url, block_number = nil)
|
30
|
+
json_rpc_call('chain_getBlockHash', [block_number], url)
|
31
|
+
end
|
32
|
+
|
33
|
+
def chain_getBlock(url, at = nil)
|
34
|
+
json_rpc_call('chain_getBlock', [at], url)
|
35
|
+
end
|
36
|
+
|
37
|
+
def state_getRuntimeVersion(url, at = nil)
|
38
|
+
json_rpc_call('state_getRuntimeVersion', [at], url)
|
39
|
+
end
|
40
|
+
|
41
|
+
def state_getMetadata(url, at = nil)
|
42
|
+
json_rpc_call('state_getMetadata', [at], url)
|
43
|
+
end
|
44
|
+
|
45
|
+
def state_getStorage(url, key, at = nil)
|
46
|
+
json_rpc_call('state_getStorage', [key, at], url)
|
47
|
+
end
|
48
|
+
|
49
|
+
def eth_call(url, to, data, at_block_number = nil)
|
50
|
+
json_rpc_call('eth_call', [
|
51
|
+
{
|
52
|
+
'from' => nil,
|
53
|
+
'to' => to,
|
54
|
+
'data' => data
|
55
|
+
},
|
56
|
+
at_block_number
|
57
|
+
], url)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|