scale.rb 0.1.0 → 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.
@@ -0,0 +1,39 @@
1
+ {
2
+ "types": {
3
+ "Keys": "SessionKeysSubstrate",
4
+ "Index": "U64",
5
+ "LiabilityIndex": "U64",
6
+ "Order": {
7
+ "type": "struct",
8
+ "type_mapping": [
9
+ ["models", "Vec<u8>"],
10
+ ["objective", "Vec<u8>"],
11
+ ["cost", "Balance"],
12
+ ["custodian", "Option<AccountId>"]
13
+ ]
14
+ },
15
+ "Offer": {
16
+ "type": "struct",
17
+ "type_mapping": [
18
+ ["order", "Order"],
19
+ ["sender", "AccountId"]
20
+ ]
21
+ },
22
+ "Demand": {
23
+ "type": "struct",
24
+ "type_mapping": [
25
+ ["order", "Order"],
26
+ ["sender", "AccountId"]
27
+ ]
28
+ },
29
+ "Liability": {
30
+ "type": "struct",
31
+ "type_mapping": [
32
+ ["order", "Order"],
33
+ ["promisee", "AccountId"],
34
+ ["promisor", "AccountId"],
35
+ ["result", "Option<Vec<u8>>"]
36
+ ]
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "types": {
3
+ "BlockNumber": "U64",
4
+ "SpecificTestType": "u32",
5
+ "DigestItem": {
6
+ "type": "enum",
7
+ "type_mapping": [
8
+ ["Other", "Vec<u8>"],
9
+ ["AuthoritiesChange", "Vec<AuthorityId>"],
10
+ ["ChangesTrieRoot", "Hash"],
11
+ ["SealV0", "SealV0"],
12
+ ["Consensus", "Consensus"],
13
+ ["Seal", "Seal"],
14
+ ["PreRuntime", "PreRuntime"]
15
+ ]
16
+ },
17
+ "IdentityFields": {
18
+ "type": "set",
19
+ "value_list": {
20
+ "Display": 1,
21
+ "Legal": 2,
22
+ "Web": 4,
23
+ "Riot": 8,
24
+ "Email": 16,
25
+ "PgpFingerprint": 32,
26
+ "Image": 64,
27
+ "Twitter": 128
28
+ }
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "runtime_id": 1000,
3
+ "types": {
4
+ "BlockNumber": "U32",
5
+ "LeasePeriod": "BlockNumber",
6
+ "SessionKeysPolkadot": {
7
+ "type": "struct",
8
+ "type_mapping": [
9
+ ["grandpa", "AccountId"],
10
+ ["babe", "AccountId"],
11
+ ["im_online", "AccountId"],
12
+ ["authority_discovery", "AccountId"],
13
+ ["parachains", "AccountId"]
14
+ ]
15
+ },
16
+ "Keys": "SessionKeysPolkadot"
17
+ }
18
+ }
@@ -1,18 +1,17 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "scale/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "scale.rb"
8
- spec.version = Scale::VERSION
9
- spec.authors = ["Wu Minzhe"]
10
- spec.email = ["wuminzhe@gmail.com"]
6
+ spec.name = "scale.rb"
7
+ spec.version = Scale::VERSION
8
+ spec.authors = ["Wu Minzhe"]
9
+ spec.email = ["wuminzhe@gmail.com"]
11
10
 
12
- spec.summary = %q{Ruby implementation of the parity SCALE data format}
13
- spec.description = %q{SCALE - Simple Concatenating Aggregated Little Endians}
14
- spec.homepage = "https://github.com/itering/scale.rb"
15
- spec.license = "MIT"
11
+ spec.summary = "Ruby SCALE Codec Library"
12
+ spec.description = "Ruby implementation of the parity SCALE data format"
13
+ spec.homepage = "https://github.com/itering/scale.rb"
14
+ spec.license = "MIT"
16
15
 
17
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
17
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -27,17 +26,21 @@ Gem::Specification.new do |spec|
27
26
 
28
27
  # Specify which files should be added to the gem when it is released.
29
28
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
30
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
31
  end
33
- spec.bindir = "exe"
34
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
34
  spec.require_paths = ["lib"]
36
35
 
37
- spec.add_dependency "substrate_common.rb", "~> 0.1.3"
36
+ spec.add_dependency "substrate_common.rb", "~> 0.1.8"
37
+ spec.add_dependency "json", "~> 2.3.0"
38
+ spec.add_dependency "activesupport", ">= 4.0.0"
39
+ spec.add_dependency "thor", "~> 0.20.3"
38
40
 
39
41
  spec.add_development_dependency "bundler", "~> 1.17"
42
+ spec.add_development_dependency "pry"
40
43
  spec.add_development_dependency "rake", "~> 13.0"
41
44
  spec.add_development_dependency "rspec", "~> 3.2"
42
- spec.add_development_dependency "pry"
45
+ spec.add_development_dependency "ffi", "~> 1.12"
43
46
  end
@@ -0,0 +1,74 @@
1
+ extern crate parity_scale_codec;
2
+ use std::slice;
3
+ use parity_scale_codec::{Decode};
4
+
5
+ fn decode_from_raw_parts<T: Decode + PartialEq + std::fmt::Debug>(v_pointer: *const u8, len: usize) -> T {
6
+ let data_slice = unsafe {
7
+ assert!(!v_pointer.is_null());
8
+ slice::from_raw_parts(v_pointer, len)
9
+ };
10
+ let v = data_slice.to_vec();
11
+ <T>::decode(&mut &v[..]).unwrap()
12
+ }
13
+
14
+ #[no_mangle]
15
+ pub extern fn parse_u64(v_pointer: *const u8, len: usize, expectation: u64) {
16
+ assert_eq!(decode_from_raw_parts::<u64>(v_pointer, len), expectation);
17
+ }
18
+
19
+ #[no_mangle]
20
+ pub extern fn parse_u32(v_pointer: *const u8, len: usize, expectation: u32) {
21
+ assert_eq!(decode_from_raw_parts::<u32>(v_pointer, len), expectation);
22
+ }
23
+
24
+ #[no_mangle]
25
+ pub extern fn parse_u8(v_pointer: *const u8, len: usize, expectation: u8) {
26
+ assert_eq!(decode_from_raw_parts::<u8>(v_pointer, len), expectation);
27
+ }
28
+
29
+ #[no_mangle]
30
+ pub extern fn parse_bool(v_pointer: *const u8, len: usize, expectation: bool) {
31
+ assert_eq!(decode_from_raw_parts::<bool>(v_pointer, len), expectation);
32
+ }
33
+
34
+ #[no_mangle]
35
+ pub extern fn parse_opt_u32(v_pointer: *const u8, len: usize, inner_value: u32, option: bool) {
36
+ let expectation = match option {
37
+ true => Some(inner_value),
38
+ false => None,
39
+ };
40
+ assert_eq!(decode_from_raw_parts::<Option<u32>>(v_pointer, len), expectation);
41
+ }
42
+
43
+ #[no_mangle]
44
+ pub extern fn parse_opt_bool(v_pointer: *const u8, len: usize, inner_value: bool, option: bool) {
45
+ let expectation = match option {
46
+ true => Some(inner_value),
47
+ false => None,
48
+ };
49
+ assert_eq!(decode_from_raw_parts::<Option<bool>>(v_pointer, len), expectation);
50
+ }
51
+
52
+ #[test]
53
+ fn opt_bool_is_broken()
54
+ {
55
+ // does not conform to boolean specification in https://substrate.dev/docs/en/conceptual/core/codec#options
56
+ let v = vec![1, 1];
57
+ assert_eq!(<Option<bool>>::decode(&mut &v[..]).unwrap(), Some(true));
58
+
59
+ //this does
60
+ let v = vec![0];
61
+ assert_eq!(<Option<bool>>::decode(&mut &v[..]).unwrap(), None);
62
+
63
+ //this does not
64
+ let v = vec![0, 0, 0, 0];
65
+ assert_eq!(<Option<bool>>::decode(&mut &v[..]).unwrap(), None);
66
+
67
+ //this does not
68
+ let v = vec![1];
69
+ assert!(<Option<bool>>::decode(&mut &v[..]).is_err());
70
+
71
+ //this does not
72
+ let v = vec![2];
73
+ assert!(<Option<bool>>::decode(&mut &v[..]).is_err())
74
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scale.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wu Minzhe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-11 00:00:00.000000000 Z
11
+ date: 2020-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: substrate_common.rb
@@ -16,14 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.3
19
+ version: 0.1.8
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.3
26
+ version: 0.1.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.20.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.20.3
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: bundler
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +80,20 @@ dependencies:
38
80
  - - "~>"
39
81
  - !ruby/object:Gem::Version
40
82
  version: '1.17'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
41
97
  - !ruby/object:Gem::Dependency
42
98
  name: rake
43
99
  requirement: !ruby/object:Gem::Requirement
@@ -67,48 +123,72 @@ dependencies:
67
123
  - !ruby/object:Gem::Version
68
124
  version: '3.2'
69
125
  - !ruby/object:Gem::Dependency
70
- name: pry
126
+ name: ffi
71
127
  requirement: !ruby/object:Gem::Requirement
72
128
  requirements:
73
- - - ">="
129
+ - - "~>"
74
130
  - !ruby/object:Gem::Version
75
- version: '0'
131
+ version: '1.12'
76
132
  type: :development
77
133
  prerelease: false
78
134
  version_requirements: !ruby/object:Gem::Requirement
79
135
  requirements:
80
- - - ">="
136
+ - - "~>"
81
137
  - !ruby/object:Gem::Version
82
- version: '0'
83
- description: SCALE - Simple Concatenating Aggregated Little Endians
138
+ version: '1.12'
139
+ description: Ruby implementation of the parity SCALE data format
84
140
  email:
85
141
  - wuminzhe@gmail.com
86
- executables: []
142
+ executables:
143
+ - scale
87
144
  extensions: []
88
145
  extra_rdoc_files: []
89
146
  files:
90
147
  - ".DS_Store"
91
148
  - ".gitignore"
149
+ - Cargo.lock
150
+ - Cargo.toml
92
151
  - Dockerfile
93
152
  - Gemfile
94
153
  - Gemfile.lock
95
154
  - LICENSE.txt
155
+ - Makefile
96
156
  - README.md
97
157
  - Rakefile
98
158
  - bin/console
99
159
  - bin/setup
160
+ - exe/scale
100
161
  - grants_badge.png
101
162
  - lib/metadata/metadata.rb
163
+ - lib/metadata/metadata_v0.rb
164
+ - lib/metadata/metadata_v1.rb
102
165
  - lib/metadata/metadata_v10.rb
166
+ - lib/metadata/metadata_v11.rb
167
+ - lib/metadata/metadata_v2.rb
103
168
  - lib/metadata/metadata_v3.rb
169
+ - lib/metadata/metadata_v4.rb
170
+ - lib/metadata/metadata_v5.rb
171
+ - lib/metadata/metadata_v6.rb
104
172
  - lib/metadata/metadata_v7.rb
105
173
  - lib/metadata/metadata_v8.rb
106
174
  - lib/metadata/metadata_v9.rb
107
175
  - lib/scale.rb
108
176
  - lib/scale/base.rb
177
+ - lib/scale/block.rb
109
178
  - lib/scale/types.rb
110
179
  - lib/scale/version.rb
180
+ - lib/type_registry/darwinia.json
181
+ - lib/type_registry/default.json
182
+ - lib/type_registry/edgeware.json
183
+ - lib/type_registry/joystream.json
184
+ - lib/type_registry/kulupu.json
185
+ - lib/type_registry/kusama.json
186
+ - lib/type_registry/plasm.json
187
+ - lib/type_registry/robonomics.json
188
+ - lib/type_registry/test.json
189
+ - lib/type_registry/westend.json
111
190
  - scale.gemspec
191
+ - src/lib.rs
112
192
  homepage: https://github.com/itering/scale.rb
113
193
  licenses:
114
194
  - MIT
@@ -133,5 +213,5 @@ requirements: []
133
213
  rubygems_version: 3.0.6
134
214
  signing_key:
135
215
  specification_version: 4
136
- summary: Ruby implementation of the parity SCALE data format
216
+ summary: Ruby SCALE Codec Library
137
217
  test_files: []