eosrb 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/eosrb.rb +93 -0
  3. data/specs/chain.json +256 -0
  4. metadata +87 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7598c6caa2c1cad37e830b00d9cb4145651d2b49
4
+ data.tar.gz: 0b892b725a102df4320da694d1dbf033eff98e85
5
+ SHA512:
6
+ metadata.gz: beb87797ce6eda04f77fdaf5741442a5a9b5a3d42e0e4b68ed1f7d406655da7d7b6b6b586738b43b125c6c07a0fd03f31a64976eb08edb4d56e21601d8d3440a
7
+ data.tar.gz: d6926c88cb4822566910182089a2365d10775ead8e4e7ce79274215a2af997080cf3cb0c625155ed56462198b8bb17e2a47f959d48338867988d7c0de37f24ae
data/lib/eosrb.rb ADDED
@@ -0,0 +1,93 @@
1
+ require 'json'
2
+ require 'faraday'
3
+
4
+ module EOS
5
+ class Client
6
+
7
+ def initialize(server='http://localhost:8888', hc=false)
8
+ @server = server
9
+ @hc = hc
10
+ load_specs
11
+ end
12
+
13
+ def self.ar
14
+ new('https://api.eosargentina.io')
15
+ end
16
+
17
+ private
18
+
19
+ def connection
20
+ @connection ||= Faraday.new(@server){|f| f.adapter :net_http_persistent }
21
+ end
22
+
23
+ def version
24
+ 'v1'
25
+ end
26
+
27
+ # Load API specification from spec files
28
+
29
+ def load_specs
30
+ @specs = {}
31
+ spec_files.each do |name|
32
+ @specs[name] = read_spec(name)
33
+ end
34
+ end
35
+
36
+ def specs_path
37
+ "#{File.dirname __dir__}/specs/"
38
+ end
39
+
40
+ def spec_files
41
+ Dir["#{specs_path}*"].map{|filename| File.basename(filename, '.json') }.compact
42
+ end
43
+
44
+ def read_spec(name)
45
+ JSON.parse(File.read("#{specs_path}#{name}.json"))
46
+ end
47
+
48
+ # Add API methods to class for seamless usage
49
+
50
+ def method_missing(method_name, *args, &block)
51
+ if respond_to_missing?(method_name)
52
+ api_call(method_name, args.first)
53
+ else
54
+ super
55
+ end
56
+ end
57
+
58
+ def respond_to_missing?(method_name, include_private = false)
59
+ return true if @hc
60
+ api, endpoint = extract_endpoint(method_name)
61
+ @specs.key?(api) && @specs[api].key?(endpoint)
62
+ end
63
+
64
+ def extract_endpoint(name)
65
+ name.to_s.split('_',2)
66
+ end
67
+
68
+ def known_params(method_name)
69
+ api, endpoint = extract_endpoint(method_name)
70
+ return {} unless @specs[api] && @specs[api][endpoint]
71
+ @specs[api][endpoint]['params'] || {}
72
+ end
73
+
74
+ def path(method_name)
75
+ api, endpoint = extract_endpoint(method_name)
76
+ "/#{version}/#{api}/#{endpoint}"
77
+ end
78
+
79
+ # The actual http call
80
+ def api_call(method_name, args)
81
+ args ||= {}
82
+ known = known_params(method_name)
83
+ body = @hc ? args : args.select{ |key, _| known.include?(key.to_s) }
84
+ post path(method_name), body
85
+ end
86
+
87
+ def post(path, body)
88
+ headers = {'Content-Type' => 'application/json'}
89
+ response = connection.post path, body.to_json, headers
90
+ JSON.parse(response.body)
91
+ end
92
+ end
93
+ end
data/specs/chain.json ADDED
@@ -0,0 +1,256 @@
1
+ {
2
+ "abi_bin_to_json": {
3
+ "brief": "Convert bin hex back into Abi json definition.",
4
+ "params": {
5
+ "code": "name",
6
+ "action": "name",
7
+ "binargs": "bytes"
8
+ },
9
+ "results": {
10
+ "args": "bytes",
11
+ "required_scope": "name[]",
12
+ "required_auth": "name[]"
13
+ }
14
+ },
15
+
16
+ "abi_json_to_bin": {
17
+ "brief": "Manually serialize json into binary hex. The binayargs is usually stored in Message.data.",
18
+ "params": {
19
+ "code": "name",
20
+ "action": "name",
21
+ "args": "bytes"
22
+ },
23
+ "results": {
24
+ "binargs": "bytes"
25
+ }
26
+ },
27
+
28
+ "get_abi": {
29
+ "params": {
30
+ "account_name": "name"
31
+ },
32
+ "results": {
33
+ "account_name": "name",
34
+ "abi": "abi_def?"
35
+ }
36
+ },
37
+
38
+ "get_account": {
39
+ "brief": "Fetch a blockchain account",
40
+ "params": {
41
+ "account_name": "name"
42
+ },
43
+ "results": {
44
+ "account_name": "name",
45
+ "privileged": "bool",
46
+ "last_code_update": "time_point",
47
+ "created": "time_point",
48
+ "ram_quota": "int64",
49
+ "net_weight": "int64",
50
+ "cpu_weight": "int64",
51
+ "net_limit": "int64",
52
+ "cpu_limit": "int64",
53
+ "ram_usage": "int64",
54
+ "permissions": "vector<permission>"
55
+ }
56
+ },
57
+
58
+ "get_block": {
59
+ "brief": "Fetch a block from the blockchain.",
60
+ "params": {
61
+ "block_num_or_id": "string"
62
+ },
63
+ "results": {
64
+ "previous":"block_id",
65
+ "timestamp":"time",
66
+ "transaction_mroot":"checksum256",
67
+ "action_mroot":"checksum256",
68
+ "producer": "account_name",
69
+ "schedule_version":"uint32",
70
+ "producer_signature":"signature",
71
+ "transactions": "transaction[]",
72
+ "id": "fixed_bytes33",
73
+ "block_num": "uint32",
74
+ "ref_block_prefix": "uint32"
75
+ },
76
+ "errors": {
77
+ "unknown block": null
78
+ }
79
+ },
80
+ "get_block_header_state": {
81
+ "brief": "Fetch the minimum state necessary to validate transaction headers.",
82
+ "params": {
83
+ "block_num_or_id": "string"
84
+ },
85
+ "results": "string",
86
+ "errors": {
87
+ "block_id_type_exception": "Invalid block ID",
88
+ "unknown_block_exception": "Could not find reversible block"
89
+ }
90
+ },
91
+ "get_code": {
92
+ "brief": "Fetch smart contract code",
93
+ "params": {
94
+ "account_name": "name"
95
+ },
96
+ "results": {
97
+ "account_name": "name",
98
+ "wast": "string",
99
+ "code_hash": "sha256",
100
+ "abi": "optional<abi_def>"
101
+ }
102
+ },
103
+
104
+ "get_currency_balance": {
105
+ "params": {
106
+ "code": "name",
107
+ "account": "name",
108
+ "symbol": "optional<string>"
109
+ },
110
+ "results": "asset[]"
111
+ },
112
+
113
+ "get_currency_stats": {
114
+ "params": {
115
+ "code": "name",
116
+ "symbol": "string"
117
+ },
118
+ "results": {
119
+ "supply": "asset",
120
+ "max_supply": "asset",
121
+ "issuer": "account_name"
122
+ }
123
+ },
124
+
125
+ "get_info": {
126
+ "brief": "Return general network information.",
127
+ "params": null,
128
+ "results": {
129
+ "server_version" : "string",
130
+ "head_block_num" : "uint32",
131
+ "last_irreversible_block_num" : "uint32",
132
+ "last_irreversible_block_id" : "block_id",
133
+ "head_block_id" : "block_id",
134
+ "head_block_time" : "time_point_sec",
135
+ "head_block_producer" : "account_name",
136
+ "virtual_block_cpu_limit" : "uint64",
137
+ "virtual_block_net_limit" : "uint64",
138
+ "block_cpu_limit" : "uint64",
139
+ "block_net_limit" : "uint64"
140
+ }
141
+ },
142
+ "get_producers": {
143
+ "brief": "Fetch smart contract data from producer.",
144
+ "params": {
145
+ "json": { "type": "bool", "default": false},
146
+ "lower_bound": "string",
147
+ "limit": {"type": "uint32", "default": "10"}
148
+ },
149
+ "results": {
150
+ "rows": {
151
+ "type": "vector",
152
+ "doc": "one row per item, either encoded as hex String or JSON object"
153
+ },
154
+ "total_producer_vote_weight": {
155
+ "type": "float64",
156
+ "doc": "total vote"
157
+ },
158
+ "more": {
159
+ "type": "string",
160
+ "doc": "fill lower_bound with this value to fetch more rows"
161
+ }
162
+ }
163
+ },
164
+ "get_producer_schedule": {
165
+ "brief": "",
166
+ "params": {},
167
+ "results": {
168
+ "vector": "active",
169
+ "vector": "pending",
170
+ "vector": "proposed"
171
+ }
172
+ },
173
+ "get_raw_code_and_abi": {
174
+ "params": {
175
+ "account_name": "name"
176
+ },
177
+ "results": {
178
+ "account_name": "name",
179
+ "wasm": "bytes",
180
+ "abi": "abi_def?"
181
+ }
182
+ },
183
+ "get_required_keys": {
184
+ "params": {
185
+ "transaction": "transaction",
186
+ "available_keys": "set[public_key]"
187
+ },
188
+ "results": "Set[public_key]"
189
+ },
190
+ "get_scheduled_transactions": {
191
+ "brief": "",
192
+ "params": {
193
+ "json": { "type": "bool", "default": false},
194
+ "lower_bound": {"type": "string", "doc": "timestamp OR transaction ID"},
195
+ "limit": {"type": "uint32", "default": "50"}
196
+ },
197
+ "results": {
198
+ "vector": "transactions",
199
+ "more": {
200
+ "type": "string",
201
+ "doc": "fill lower_bound with this to fetch next set of transactions"
202
+ }
203
+ }
204
+ },
205
+ "get_table_rows": {
206
+ "brief": "Fetch smart contract data from an account.",
207
+ "params": {
208
+ "json": { "type": "bool", "default": false},
209
+ "code": "name",
210
+ "scope": "name",
211
+ "table": "name",
212
+ "table_key": "string",
213
+ "lower_bound": {"type": "string", "default": "0"},
214
+ "upper_bound": {"type": "string", "default": "-1"},
215
+ "limit": {"type": "uint32", "default": "10"}
216
+ },
217
+ "results": {
218
+ "rows": {
219
+ "type": "vector",
220
+ "doc": "one row per item, either encoded as hex String or JSON object"
221
+ },
222
+ "more": {
223
+ "type": "bool",
224
+ "doc": "true if last element"
225
+ }
226
+ }
227
+ },
228
+
229
+ "push_block": {
230
+ "brief": "Append a block to the chain database.",
231
+ "params": {
232
+ "block": "signed_block"
233
+ },
234
+ "results": null
235
+ },
236
+
237
+ "push_transaction": {
238
+ "brief": "Attempts to push the transaction into the pending queue.",
239
+ "params": {
240
+ "signed_transaction": "signed_transaction"
241
+ },
242
+ "results": {
243
+ "transaction_id": "fixed_bytes32",
244
+ "processed": "bytes"
245
+ }
246
+ },
247
+
248
+ "push_transactions": {
249
+ "brief": "Attempts to push transactions into the pending queue.",
250
+ "params": {
251
+ "signed_transaction[]": "signed_transaction"
252
+ },
253
+ "results": "vector[push_transaction.results]"
254
+ }
255
+
256
+ }
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eosrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - RNGLab
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-http-persistent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Easily interact with the EOS blockchain-
56
+ email: root@rnglab.org
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/eosrb.rb
62
+ - specs/chain.json
63
+ homepage: http://github.com/EOSArgentina/eosrb
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.6.14
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: EOS RPC-API client
87
+ test_files: []