bitsharesws 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffb09945dec4ea9a6dd1eabdd6a0662ec78a65bb
4
- data.tar.gz: a0d483783cbb4684639b97bd8154ee27372fceab
3
+ metadata.gz: 7374bf44acc25661affc59bbd6676466e8bff951
4
+ data.tar.gz: 1ff5e2a204e88b253c2382c290c9b6fee050651c
5
5
  SHA512:
6
- metadata.gz: 38dacfaddff43e177c58d2c1b266aa477009013a0214255792231d8bbd3488c237972c9cd51dbbcaaa6dea8a5b1bf5614fa9905e1f7885b7f015ad7e06c84880
7
- data.tar.gz: a79875860e1a4ab9a7b829d8425acfe533134a343f3703b4c5027dd0e355600cbebc328e6540f6a44e5a20390bd8cc14e588ea971557785a7756a560188c952f
6
+ metadata.gz: ea17326e699b71ee702a82181f7363a2f12f99c7f552323dcde94fbe0a7328ce47b3f9eeff2f8f95cbb222b22f0e04c4bf7d7bb9f4e5dc2c8127877b86e50455
7
+ data.tar.gz: 619f64a211bfa852fb2a9adca9f77f32138332aa36fbdce8b9309930f05208899a4ac6574d14d433154285edad6a2f4d8706803fa68669ad2754eab4efa7e17c
@@ -5,7 +5,7 @@ require "bitshares/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "bitsharesws"
8
- spec.version = Bitshares::VERSION
8
+ spec.version = BitShares::VERSION
9
9
  spec.authors = ["scientistnik"]
10
10
  spec.email = ["nozdrin.plotnitsky@gmail.com"]
11
11
 
@@ -2,13 +2,14 @@ require 'bitshares/version'
2
2
 
3
3
  module BitShares
4
4
  autoload :WSocket, 'bitshares/wsocket'
5
+ autoload :RPC, 'bitshares/rpc'
6
+ autoload :API, 'bitshares/api'
5
7
  autoload :Wallet, 'bitshares/wallet'
6
8
  autoload :Asset, 'bitshares/asset'
7
9
  autoload :Account, 'bitshares/account'
8
10
 
9
- class << self
10
11
 
11
- attr_accessor :login, :pass
12
+ class << self
12
13
 
13
14
  def config autoconnect=true, &block
14
15
  @node = 'wss://node.testnet.bitshares.eu'
@@ -18,50 +19,39 @@ module BitShares
18
19
  start if autoconnect
19
20
  end
20
21
 
21
- def node n=nil
22
- n ||= @node
23
- @node = n
24
- end
22
+ def node(n=nil) n ||= @node; @node = n; end
23
+ def login(n=nil) n ||= @login; @login = n; end
24
+ def pass(n=nil) n ||= @pass; @pass = n; end
25
25
 
26
26
  def start
27
27
  WSocket.start
28
- WSocket.send id: 2, method: 'call', params: [1,'login',[@login,@pass]]
28
+ RPC.new(1,'login',[@login,@pass]).send
29
29
  end
30
30
 
31
31
  def stop() WSocket.stop end
32
32
 
33
- def database_id
34
- @database_id ||= WSocket.send(id: 2, method: 'call', params: [1,'database',[]])['result']
35
- end
36
-
37
33
  def account name
38
- answer = WSocket.send id: 2, method: "call", params: [database_id,"get_account_by_name",[name]]
39
- raise 'Bad request...' if answer.key? 'error'
40
- Account.new answer['result']
34
+ Account[name]
41
35
  end
42
36
 
43
37
  def balance name,*ids
44
- answer = WSocket.send id: 2, method: "call", params: [database_id,"get_named_account_balances",[name,ids]]
45
- raise 'Bad request...' if answer.key? 'error'
46
- answer['result'].inject([]) { |m,w| m << Wallet.new(w) }
38
+ Wallet[name,*ids]
47
39
  end
48
40
 
49
41
  def assets *ids
50
- answer = WSocket.send id: 2, method: 'call', params: [database_id,'get_assets',[ids]]
51
- raise 'Bad request...' if answer.key? 'error'
52
- answer['result'].inject([]) {|m,a| m << Asset.new(a) }
42
+ Asset[*ids]
53
43
  end
54
44
 
55
- def list_assets name, limit=10
56
- answer = WSocket.send id: 2, method: 'call', params: [database_id,'list_assets',[name,limit]]
57
- raise "Bad request...#{answer}" if answer.key? 'error'
58
- answer['result'].inject([]) {|m,a| m << Asset.new(a) }
45
+ def list_assets name, limit=1
46
+ Asset.search name, limit
59
47
  end
60
48
 
61
49
  def subscribe_callback id, clear_filter=true
62
- answer = WSocket.send id: 2, method: 'call', params: [database_id,'set_subscribe_callback',[id,clear_filter]]
63
- raise "Bad request...#{answer}" if answer.key? 'error'
64
- answer['result']
50
+ RPC.new('set_subscribe_callback', [id, clear_filter]).send
51
+ end
52
+
53
+ def transfer that, amount, from, to
54
+ RPC.new 'transfer',[]
65
55
  end
66
56
 
67
57
  end
@@ -9,5 +9,15 @@ module BitShares
9
9
  end
10
10
 
11
11
  def to_s() @name end
12
+
13
+ def balance *ids
14
+ Wallet[@name,*ids]
15
+ end
16
+
17
+ class << self
18
+ def [] name
19
+ new RPC.new('get_account_by_name',[name]).send
20
+ end
21
+ end
12
22
  end
13
23
  end
@@ -0,0 +1,143 @@
1
+ module BitShares
2
+ class Api < Array
3
+ attr_reader :name
4
+
5
+ def initialize name, arr
6
+ @name = name
7
+ self.concat arr
8
+ end
9
+
10
+ def id
11
+ @id ||= RPC.new(1, @name, [[]]).send
12
+ end
13
+
14
+ def rpc method, params
15
+ RPC.new id, method, params
16
+ end
17
+
18
+ class << self
19
+
20
+ def init
21
+ return @apis unless @apis.nil?
22
+
23
+ @apis = []
24
+ @apis << API.new('database',
25
+ %w(
26
+ get_objects
27
+ set_subscribe_callback
28
+ set_pending_transaction_callback
29
+ set_block_applied_callback
30
+ cancel_all_subscriptions
31
+ get_block_header
32
+ get_block
33
+ get_transaction
34
+ get_recent_transaction_by_id
35
+ get_chain_properties
36
+ get_global_properties
37
+ get_config
38
+ get_chain_id
39
+ get_dynamic_global_properties
40
+ get_key_references
41
+ get_accounts
42
+ get_full_accounts
43
+ get_account_by_name
44
+ get_account_references
45
+ lookup_account_names
46
+ lookup_accounts
47
+ get_account_count
48
+ get_account_balances
49
+ get_named_account_balances
50
+ get_balance_objects
51
+ get_vested_balances
52
+ get_vesting_balances
53
+ get_assets
54
+ list_assets
55
+ lookup_asset_symbols
56
+ get_order_book
57
+ get_limit_orders
58
+ get_call_orders
59
+ get_settle_orders
60
+ get_margin_positions
61
+ subscribe_to_market
62
+ unsubscribe_from_market
63
+ get_ticker
64
+ get_24_volume
65
+ get_trade_history
66
+ get_witnesses
67
+ get_witness_by_account
68
+ lookup_witness_accounts
69
+ get_witness_count
70
+ get_committee_members
71
+ get_committee_member_by_account
72
+ lookup_committee_member_accounts
73
+ get_workers_by_account
74
+ lookup_vote_ids
75
+ get_transaction_hex
76
+ get_required_signatures
77
+ get_potential_signatures
78
+ get_potential_address_signatures
79
+ verify_authority
80
+ verify_account_authority
81
+ validate_transaction
82
+ get_required_fees
83
+ get_proposed_transactions
84
+ get_blinded_balances
85
+ ))
86
+
87
+ @apis << API.new('history',
88
+ %w(
89
+ get_account_history
90
+ get_fill_order_history
91
+ get_market_history
92
+ get_market_history_buckets
93
+ ))
94
+
95
+ @apis << API.new('network_broadcast',
96
+ %w(
97
+ broadcast_transaction
98
+ broadcast_transaction_with_callback
99
+ broadcast_block
100
+ ))
101
+
102
+ @apis << API.new('crypto',
103
+ %w(
104
+ blind_sign
105
+ unblind_signature
106
+ blind
107
+ blind_sum
108
+ range_get_info
109
+ range_proof_sign
110
+ verify_sum
111
+ verify_range
112
+ verify_range_proof_rewind
113
+ ))
114
+ @apis
115
+ end
116
+
117
+ def get_id_by_name name
118
+ @apis ||= init
119
+ @apis.each do |api|
120
+ return(api.id) if api.include? name
121
+ end
122
+ nil
123
+ end
124
+
125
+ def rpc method, params
126
+ @apis ||= init
127
+ RPC.new get_id_by_name(method), method, params
128
+ end
129
+
130
+ def [] name
131
+ @apis ||= init
132
+ @apis.each do |api|
133
+ return api if api.name == name
134
+ end
135
+ nil
136
+ end
137
+
138
+ end
139
+ end
140
+
141
+ API = Api
142
+
143
+ end
@@ -14,17 +14,28 @@ module BitShares
14
14
  end
15
15
 
16
16
  class << self
17
- def [] id
17
+ def [] *ids
18
+ id = ids.first
18
19
  if /^\d\.\d*\.\d*/.match(id)
19
- BitShares.assets id unless hash.key? id
20
- hash[id]
20
+ unless hash.key? id
21
+ arr = RPC.new('get_assets',[[id]]).send.inject([]) {|m,a| m << Asset.new(a) }
22
+ end
23
+ (ids.size == 1) ? (hash[ida]) : (arr)
21
24
  else
25
+ arr = []
22
26
  hash.each_pair do |k,v|
23
- return v if v.name == id
27
+ if ids.include? v.name
28
+ (ids.size == 1) ? (return v) : (arr << v)
29
+ end
24
30
  end
31
+ arr
25
32
  end
26
33
  end
27
34
 
35
+ def search name, limit=1
36
+ Rpc.new('list_assets',[name,limit]).send.inject([]) {|m,a| m << Asset.new(a) }
37
+ end
38
+
28
39
  def add h
29
40
  hash[h.id] = h unless hash.key? h.id
30
41
  end
@@ -0,0 +1,24 @@
1
+ module BitShares
2
+ class Rpc < Hash
3
+
4
+ def initialize *args, name, params
5
+ id, api_id = *args
6
+ if api_id.nil?
7
+ api_id = id
8
+ id = 1
9
+ end
10
+ self[:method] = 'call'
11
+ self[:id] = id
12
+ self[:jsonrpc] = '2.0'
13
+ self[:params] = [api_id || API.get_id_by_name(name), name, params]
14
+ end
15
+
16
+ def send
17
+ WSocket.send self
18
+ end
19
+
20
+ end
21
+
22
+ RPC = Rpc
23
+
24
+ end
@@ -1,3 +1,3 @@
1
- module Bitshares
2
- VERSION = "0.0.3"
1
+ module BitShares
2
+ VERSION = "0.0.4"
3
3
  end
@@ -5,5 +5,11 @@ module BitShares
5
5
  @amount = hash['amount']
6
6
  @asset = BitShares::Asset[hash['asset_id']]
7
7
  end
8
+
9
+ class << self
10
+ def [] name, *ids
11
+ RPC.new('get_named_account_balances',[name,ids]).send.inject([]) {|m,a| m << Wallet.new(a) }
12
+ end
13
+ end
8
14
  end
9
15
  end
@@ -23,6 +23,7 @@ module BitShares
23
23
  end
24
24
 
25
25
  def thread() @thread end
26
+ def msgs() @msgs ||= {} end
26
27
 
27
28
  def stop
28
29
  EventMachine.stop
@@ -31,12 +32,18 @@ module BitShares
31
32
  def send hash
32
33
  id = hash[:id]
33
34
  count = 0
34
- while @msgs[id] != nil do
35
+ while msgs[id] != nil do
35
36
  sleep 0.1
36
37
  count += 1
37
38
  raise "TimeoutError..." if count > 100
38
39
  end
39
- @thread[:ws].send hash.to_json if @status == :connected
40
+
41
+ if @status == :connected
42
+ @thread[:ws].send hash.to_json
43
+ else
44
+ return nil
45
+ end
46
+
40
47
  count = 0
41
48
  while @msgs[id].nil? and @status == :connected do
42
49
  sleep 0.1
@@ -48,13 +55,14 @@ module BitShares
48
55
  lock.synchronize do
49
56
  @msgs[id] = nil
50
57
  end
51
- result
58
+ raise("Bad request...#{result}") if result.nil? || result.key?('error')
59
+ result['result']
52
60
  end
53
61
 
54
62
  def lock() @lock ||= Mutex.new end
55
63
 
56
64
  def get_notice
57
- if @msgs.key?('notice') && !@msgs['notice'].nil?
65
+ if msgs.key?('notice') && !@msgs['notice'].nil?
58
66
  msg = @msgs['notice']
59
67
  lock.synchronize do
60
68
  @msgs['notice'] = nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitsharesws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - scientistnik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-15 00:00:00.000000000 Z
11
+ date: 2017-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -99,7 +99,9 @@ files:
99
99
  - bitsharesws.gemspec
100
100
  - lib/bitshares.rb
101
101
  - lib/bitshares/account.rb
102
+ - lib/bitshares/api.rb
102
103
  - lib/bitshares/asset.rb
104
+ - lib/bitshares/rpc.rb
103
105
  - lib/bitshares/version.rb
104
106
  - lib/bitshares/wallet.rb
105
107
  - lib/bitshares/wsocket.rb