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 +4 -4
- data/bitsharesws.gemspec +1 -1
- data/lib/bitshares.rb +17 -27
- data/lib/bitshares/account.rb +10 -0
- data/lib/bitshares/api.rb +143 -0
- data/lib/bitshares/asset.rb +15 -4
- data/lib/bitshares/rpc.rb +24 -0
- data/lib/bitshares/version.rb +2 -2
- data/lib/bitshares/wallet.rb +6 -0
- data/lib/bitshares/wsocket.rb +12 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7374bf44acc25661affc59bbd6676466e8bff951
|
4
|
+
data.tar.gz: 1ff5e2a204e88b253c2382c290c9b6fee050651c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea17326e699b71ee702a82181f7363a2f12f99c7f552323dcde94fbe0a7328ce47b3f9eeff2f8f95cbb222b22f0e04c4bf7d7bb9f4e5dc2c8127877b86e50455
|
7
|
+
data.tar.gz: 619f64a211bfa852fb2a9adca9f77f32138332aa36fbdce8b9309930f05208899a4ac6574d14d433154285edad6a2f4d8706803fa68669ad2754eab4efa7e17c
|
data/bitsharesws.gemspec
CHANGED
data/lib/bitshares.rb
CHANGED
@@ -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
|
-
|
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
|
22
|
-
|
23
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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=
|
56
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
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
|
data/lib/bitshares/account.rb
CHANGED
@@ -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
|
data/lib/bitshares/asset.rb
CHANGED
@@ -14,17 +14,28 @@ module BitShares
|
|
14
14
|
end
|
15
15
|
|
16
16
|
class << self
|
17
|
-
def []
|
17
|
+
def [] *ids
|
18
|
+
id = ids.first
|
18
19
|
if /^\d\.\d*\.\d*/.match(id)
|
19
|
-
|
20
|
-
|
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
|
-
|
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
|
data/lib/bitshares/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.0.
|
1
|
+
module BitShares
|
2
|
+
VERSION = "0.0.4"
|
3
3
|
end
|
data/lib/bitshares/wallet.rb
CHANGED
data/lib/bitshares/wsocket.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
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.
|
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-
|
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
|