Module: BitShares

Defined in:
lib/bitshares.rb,
lib/bitshares/asset.rb,
lib/bitshares/wallet.rb,
lib/bitshares/account.rb,
lib/bitshares/wsocket.rb

Defined Under Namespace

Modules: WSocket Classes: Account, Asset, Wallet

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loginObject

Returns the value of attribute login.



11
12
13
# File 'lib/bitshares.rb', line 11

def 
  @login
end

.passObject

Returns the value of attribute pass.



11
12
13
# File 'lib/bitshares.rb', line 11

def pass
  @pass
end

Class Method Details

.account(name) ⇒ Object



37
38
39
40
41
# File 'lib/bitshares.rb', line 37

def  name
  answer = WSocket.send id: 2, method: "call", params: [database_id,"get_account_by_name",[name]]
  raise 'Bad request...' if answer.key? 'error'
  .new answer['result']
end

.assets(*ids) ⇒ Object



49
50
51
52
53
# File 'lib/bitshares.rb', line 49

def assets *ids
  answer = WSocket.send id: 2, method: 'call', params: [database_id,'get_assets',[ids]]
  raise 'Bad request...' if answer.key? 'error'
  answer['result'].inject([]) {|m,a| m << Asset.new(a) }
end

.balance(name, *ids) ⇒ Object



43
44
45
46
47
# File 'lib/bitshares.rb', line 43

def balance name,*ids
  answer = WSocket.send id: 2, method: "call", params: [database_id,"get_named_account_balances",[name,ids]]
  raise 'Bad request...' if answer.key? 'error'
  answer['result'].inject([]) { |m,w| m << Wallet.new(w) } 
end

.config(autoconnect = true, &block) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/bitshares.rb', line 13

def config autoconnect=true, &block
  @node = 'wss://node.testnet.bitshares.eu'
  @login = ''
  @pass = ''
  instance_eval(&block) if block_given?
  start if autoconnect
end

.database_idObject



33
34
35
# File 'lib/bitshares.rb', line 33

def database_id
  @database_id ||= WSocket.send(id: 2, method: 'call', params: [1,'database',[]])['result']
end

.list_assets(name, limit = 10) ⇒ Object



55
56
57
58
59
# File 'lib/bitshares.rb', line 55

def list_assets name, limit=10
  answer = WSocket.send id: 2, method: 'call', params: [database_id,'list_assets',[name,limit]]
  raise "Bad request...#{answer}" if answer.key? 'error'
  answer['result'].inject([]) {|m,a| m << Asset.new(a) }
end

.node(n = nil) ⇒ Object



21
22
23
24
# File 'lib/bitshares.rb', line 21

def node n=nil
  n ||= @node
  @node = n
end

.startObject



26
27
28
29
# File 'lib/bitshares.rb', line 26

def start
  WSocket.start
  WSocket.send id: 2, method: 'call', params: [1,'login',[@login,@pass]]
end

.stopObject



31
# File 'lib/bitshares.rb', line 31

def stop() WSocket.stop end

.subscribe_callback(id, clear_filter = true) ⇒ Object



61
62
63
64
65
# File 'lib/bitshares.rb', line 61

def subscribe_callback id, clear_filter=true
  answer = WSocket.send id: 2, method: 'call', params: [database_id,'set_subscribe_callback',[id,clear_filter]]
  raise "Bad request...#{answer}" if answer.key? 'error'
  answer['result']
end