steem-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,61 @@
1
+ module Steem
2
+ module Type
3
+
4
+ # See: https://github.com/xeroc/piston-lib/blob/34a7525cee119ec9b24a99577ede2d54466fca0e/steembase/operations.py
5
+ class Amount < BaseType
6
+ def self.to_nia(amount)
7
+ new(amount).to_nia
8
+ end
9
+
10
+ def self.to_s(amount)
11
+ new(amount).to_s
12
+ end
13
+
14
+ def initialize(value)
15
+ super(:amount, value)
16
+
17
+ case value
18
+ when Array
19
+ a, p, t = value
20
+ @asset = case t
21
+ when '@@000000013' then 'SBD'
22
+ when '@@000000021' then 'STEEM'
23
+ when '@@000000037' then 'VESTS'
24
+ else; raise TypeError, "Asset #{@asset} unknown."
25
+ end
26
+ @precision = p
27
+ @amount = "%.#{p}f" % (a.to_f / 10 ** p)
28
+ else
29
+ @amount, @asset = value.strip.split(' ') rescue ['', '']
30
+ @precision = case @asset
31
+ when 'STEEM' then 3
32
+ when 'VESTS' then 6
33
+ when 'SBD' then 3
34
+ else; raise TypeError, "Asset #{@asset} unknown."
35
+ end
36
+ end
37
+ end
38
+
39
+ def to_bytes
40
+ asset = @asset.ljust(7, "\x00")
41
+ amount = (@amount.to_f * 10 ** @precision).round
42
+
43
+ [amount].pack('q') +
44
+ [@precision].pack('c') +
45
+ asset
46
+ end
47
+
48
+ def to_nia
49
+ case @asset
50
+ when 'STEEM' then [(@amount.to_f * 1000).to_i.to_s, 3, '@@000000021']
51
+ when 'VESTS' then [(@amount.to_f * 1000000).to_i.to_s, 6, '@@000000037']
52
+ when 'SBD' then [(@amount.to_f * 1000).to_i.to_s, 3, '@@000000013']
53
+ end
54
+ end
55
+
56
+ def to_s
57
+ "#{@amount} #{@asset}"
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,10 @@
1
+ module Steem
2
+ module Type
3
+ class BaseType
4
+ def initialize(key, value)
5
+ @key = key
6
+ @value = value
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ module Steem
2
+ module Utils
3
+ def hexlify(s)
4
+ a = []
5
+ if s.respond_to? :each_byte
6
+ s.each_byte { |b| a << sprintf('%02X', b) }
7
+ else
8
+ s.each { |b| a << sprintf('%02X', b) }
9
+ end
10
+ a.join.downcase
11
+ end
12
+
13
+ def unhexlify(s)
14
+ s.split.pack('H*')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module Steem
2
+ VERSION = '0.1.0'
3
+ AGENT_ID = "steem-ruby/#{VERSION}"
4
+ end
data/lib/steem.rb ADDED
@@ -0,0 +1,35 @@
1
+ # encoding: UTF-8
2
+ require 'json' unless defined?(JSON)
3
+ require 'net/https'
4
+
5
+ require 'hashie'
6
+ require 'steem/version'
7
+ require 'steem/utils'
8
+ require 'steem/base_error'
9
+ require 'steem/mixins/retriable'
10
+ require 'steem/chain_config'
11
+ require 'steem/type/base_type'
12
+ require 'steem/type/amount'
13
+ require 'steem/transaction_builder'
14
+ require 'steem/rpc/base_client'
15
+ require 'steem/rpc/thread_safe_client'
16
+ require 'steem/api'
17
+ require 'steem/jsonrpc'
18
+ require 'steem/block_api'
19
+ require 'steem/formatter'
20
+ require 'steem/broadcast'
21
+
22
+ module Steem
23
+ def self.api_classes
24
+ @api_classes ||= {}
25
+ end
26
+
27
+ def self.const_missing(api_name)
28
+ api = api_classes[api_name]
29
+ api ||= Api.clone(freeze: true)
30
+ api.api_name = api_name
31
+ api_classes[api_name] = api
32
+ end
33
+ end
34
+
35
+ Hashie.logger = Logger.new(ENV['HASHIE_LOGGER'])
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'steem/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'steem-ruby'
8
+ spec.version = Steem::VERSION
9
+ spec.authors = ['Anthony Martin']
10
+ spec.email = ['anthony@steem.com']
11
+
12
+ spec.summary = %q{Steem Ruby Client}
13
+ spec.description = %q{Client for accessing the Steem blockchain.}
14
+ spec.homepage = 'https://github.com/steem/steem-ruby'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.16', '>= 1.16.1'
21
+ spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.0'
22
+ spec.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.3'
23
+ spec.add_development_dependency 'minitest-line', '~> 0.6', '>= 0.6.4'
24
+ spec.add_development_dependency 'minitest-proveit', '~> 1.0', '>= 1.0.0'
25
+ spec.add_development_dependency 'webmock', '~> 3.3', '>= 3.3.0'
26
+ spec.add_development_dependency 'simplecov', '~> 0.15', '>= 0.15.1'
27
+ spec.add_development_dependency 'vcr', '~> 4.0', '>= 4.0.0'
28
+ spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.12'
29
+ spec.add_development_dependency 'pry', '~> 0.11', '>= 0.11.3'
30
+ spec.add_development_dependency 'awesome_print', '~> 1.8', '>= 1.8.0'
31
+
32
+ spec.add_dependency 'json', '~> 2.1', '>= 2.1.0'
33
+ spec.add_dependency 'logging', '~> 2.2', '>= 2.2.0'
34
+ spec.add_dependency 'hashie', '~> 3.5', '>= 3.5.7'
35
+ spec.add_dependency 'bitcoin-ruby', '~> 0.0', '>= 0.0.18'
36
+ spec.add_dependency 'ffi', '~> 1.9', '>= 1.9.23'
37
+ end
metadata ADDED
@@ -0,0 +1,390 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steem-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Martin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.16.1
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.16'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.16.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '12.3'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 12.3.0
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '12.3'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 12.3.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: minitest
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '5.10'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 5.10.3
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '5.10'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 5.10.3
73
+ - !ruby/object:Gem::Dependency
74
+ name: minitest-line
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.6'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.6.4
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.6'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 0.6.4
93
+ - !ruby/object:Gem::Dependency
94
+ name: minitest-proveit
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.0'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.0.0
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.0'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 1.0.0
113
+ - !ruby/object:Gem::Dependency
114
+ name: webmock
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '3.3'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 3.3.0
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '3.3'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 3.3.0
133
+ - !ruby/object:Gem::Dependency
134
+ name: simplecov
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.15'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 0.15.1
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '0.15'
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 0.15.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: vcr
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '4.0'
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: 4.0.0
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: '4.0'
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: 4.0.0
173
+ - !ruby/object:Gem::Dependency
174
+ name: yard
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '0.9'
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: 0.9.12
183
+ type: :development
184
+ prerelease: false
185
+ version_requirements: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - "~>"
188
+ - !ruby/object:Gem::Version
189
+ version: '0.9'
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: 0.9.12
193
+ - !ruby/object:Gem::Dependency
194
+ name: pry
195
+ requirement: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - "~>"
198
+ - !ruby/object:Gem::Version
199
+ version: '0.11'
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: 0.11.3
203
+ type: :development
204
+ prerelease: false
205
+ version_requirements: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - "~>"
208
+ - !ruby/object:Gem::Version
209
+ version: '0.11'
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: 0.11.3
213
+ - !ruby/object:Gem::Dependency
214
+ name: awesome_print
215
+ requirement: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - "~>"
218
+ - !ruby/object:Gem::Version
219
+ version: '1.8'
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: 1.8.0
223
+ type: :development
224
+ prerelease: false
225
+ version_requirements: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '1.8'
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ version: 1.8.0
233
+ - !ruby/object:Gem::Dependency
234
+ name: json
235
+ requirement: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - "~>"
238
+ - !ruby/object:Gem::Version
239
+ version: '2.1'
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: 2.1.0
243
+ type: :runtime
244
+ prerelease: false
245
+ version_requirements: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - "~>"
248
+ - !ruby/object:Gem::Version
249
+ version: '2.1'
250
+ - - ">="
251
+ - !ruby/object:Gem::Version
252
+ version: 2.1.0
253
+ - !ruby/object:Gem::Dependency
254
+ name: logging
255
+ requirement: !ruby/object:Gem::Requirement
256
+ requirements:
257
+ - - "~>"
258
+ - !ruby/object:Gem::Version
259
+ version: '2.2'
260
+ - - ">="
261
+ - !ruby/object:Gem::Version
262
+ version: 2.2.0
263
+ type: :runtime
264
+ prerelease: false
265
+ version_requirements: !ruby/object:Gem::Requirement
266
+ requirements:
267
+ - - "~>"
268
+ - !ruby/object:Gem::Version
269
+ version: '2.2'
270
+ - - ">="
271
+ - !ruby/object:Gem::Version
272
+ version: 2.2.0
273
+ - !ruby/object:Gem::Dependency
274
+ name: hashie
275
+ requirement: !ruby/object:Gem::Requirement
276
+ requirements:
277
+ - - "~>"
278
+ - !ruby/object:Gem::Version
279
+ version: '3.5'
280
+ - - ">="
281
+ - !ruby/object:Gem::Version
282
+ version: 3.5.7
283
+ type: :runtime
284
+ prerelease: false
285
+ version_requirements: !ruby/object:Gem::Requirement
286
+ requirements:
287
+ - - "~>"
288
+ - !ruby/object:Gem::Version
289
+ version: '3.5'
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: 3.5.7
293
+ - !ruby/object:Gem::Dependency
294
+ name: bitcoin-ruby
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - "~>"
298
+ - !ruby/object:Gem::Version
299
+ version: '0.0'
300
+ - - ">="
301
+ - !ruby/object:Gem::Version
302
+ version: 0.0.18
303
+ type: :runtime
304
+ prerelease: false
305
+ version_requirements: !ruby/object:Gem::Requirement
306
+ requirements:
307
+ - - "~>"
308
+ - !ruby/object:Gem::Version
309
+ version: '0.0'
310
+ - - ">="
311
+ - !ruby/object:Gem::Version
312
+ version: 0.0.18
313
+ - !ruby/object:Gem::Dependency
314
+ name: ffi
315
+ requirement: !ruby/object:Gem::Requirement
316
+ requirements:
317
+ - - "~>"
318
+ - !ruby/object:Gem::Version
319
+ version: '1.9'
320
+ - - ">="
321
+ - !ruby/object:Gem::Version
322
+ version: 1.9.23
323
+ type: :runtime
324
+ prerelease: false
325
+ version_requirements: !ruby/object:Gem::Requirement
326
+ requirements:
327
+ - - "~>"
328
+ - !ruby/object:Gem::Version
329
+ version: '1.9'
330
+ - - ">="
331
+ - !ruby/object:Gem::Version
332
+ version: 1.9.23
333
+ description: Client for accessing the Steem blockchain.
334
+ email:
335
+ - anthony@steem.com
336
+ executables: []
337
+ extensions: []
338
+ extra_rdoc_files: []
339
+ files:
340
+ - ".gitignore"
341
+ - CONTRIBUTING.md
342
+ - Gemfile
343
+ - Gemfile.lock
344
+ - LICENSE
345
+ - README.md
346
+ - Rakefile
347
+ - gource.sh
348
+ - images/Anthony Martin.png
349
+ - lib/steem.rb
350
+ - lib/steem/api.rb
351
+ - lib/steem/base_error.rb
352
+ - lib/steem/block_api.rb
353
+ - lib/steem/broadcast.rb
354
+ - lib/steem/chain_config.rb
355
+ - lib/steem/formatter.rb
356
+ - lib/steem/jsonrpc.rb
357
+ - lib/steem/mixins/retriable.rb
358
+ - lib/steem/rpc/base_client.rb
359
+ - lib/steem/rpc/thread_safe_client.rb
360
+ - lib/steem/transaction_builder.rb
361
+ - lib/steem/type/amount.rb
362
+ - lib/steem/type/base_type.rb
363
+ - lib/steem/utils.rb
364
+ - lib/steem/version.rb
365
+ - steem-ruby.gemspec
366
+ homepage: https://github.com/steem/steem-ruby
367
+ licenses:
368
+ - MIT
369
+ metadata: {}
370
+ post_install_message:
371
+ rdoc_options: []
372
+ require_paths:
373
+ - lib
374
+ required_ruby_version: !ruby/object:Gem::Requirement
375
+ requirements:
376
+ - - ">="
377
+ - !ruby/object:Gem::Version
378
+ version: '0'
379
+ required_rubygems_version: !ruby/object:Gem::Requirement
380
+ requirements:
381
+ - - ">="
382
+ - !ruby/object:Gem::Version
383
+ version: '0'
384
+ requirements: []
385
+ rubyforge_project:
386
+ rubygems_version: 2.6.14
387
+ signing_key:
388
+ specification_version: 4
389
+ summary: Steem Ruby Client
390
+ test_files: []