Class: Bcoin::Client::Wallet

Inherits:
Base
  • Object
show all
Defined in:
lib/bcoin/client/wallet.rb

Overview

The primary bcoin.io Wallet object.

Instance Attribute Summary

Attributes inherited from Base

#attributes, #client

Instance Method Summary collapse

Methods inherited from Base

#error=, #initialize, #inspect, #refresh!, #token=, #wallet_token

Methods included from HttpMethods

#delete, #get, #post, #put, #wallet_token

Constructor Details

This class inherits a constructor from Bcoin::Client::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Bcoin::Client::Base

Instance Method Details

#accountBcoin::Client::Account

Access the default account without making another network request.



27
28
29
# File 'lib/bcoin/client/wallet.rb', line 27

def 
  @account ||= Account.new(self, @attributes[:account])
end

#accountsBcoin::Client::Accounts

Retrieve a list of acounts with details.



20
21
22
# File 'lib/bcoin/client/wallet.rb', line 20

def accounts
  @accounts ||= Accounts.new(self).refresh!
end

#balanceBcoin::Client::Balance

Retrieve balance information for this wallet.



33
34
35
# File 'lib/bcoin/client/wallet.rb', line 33

def balance
  @balance ||= Balance.new(self).refresh!
end

#base_pathObject



14
15
16
# File 'lib/bcoin/client/wallet.rb', line 14

def base_path
  '/wallet/' + id.to_s
end

#error?true, false

Checks for an error returned during a request.

Returns:

  • (true, false)


112
113
114
# File 'lib/bcoin/client/wallet.rb', line 112

def error?
  @attributes[:error] ? true : false
end

#fee(blocks = 1) ⇒ Float

Check the current fee for processing a transaction within x number of blocks.

Returns:

  • (Float)

    Rate



97
98
99
# File 'lib/bcoin/client/wallet.rb', line 97

def fee blocks = 1
  client.fee blocks
end

#idObject



10
11
12
# File 'lib/bcoin/client/wallet.rb', line 10

def id
  @attributes[:id]
end

#locktrue, false

Locks the wallet master key.

Returns:

  • (true, false)

    True if succesful.



64
65
66
67
# File 'lib/bcoin/client/wallet.rb', line 64

def lock
  post '/lock'
  !error?
end

#masterBcoin::Client::Master

Retrieves the wallet HD Master Key.

Returns:



71
72
73
74
75
76
# File 'lib/bcoin/client/wallet.rb', line 71

def master
  @master ||= begin
    response = get '/master'
    Master.new self, response
  end
end

#passphrase(options = {}) ⇒ true, false

Reset the wallet passphrase. Useful for locking and unlocking the the master key and wallet coins.

Parameters:

  • opts (Hash)

    The options for resetting the wallet passphrase.

Returns:

  • (true, false)

    True if successful.



44
45
46
47
# File 'lib/bcoin/client/wallet.rb', line 44

def passphrase options = {}
  post '/passphrase', options
  !error?
end

#retokenHash

Retrieves a new wallet API token.

Parameters:

  • opts (Hash)

    a customizable set of options

Returns:

  • (Hash)

    opts



81
82
83
84
85
86
87
88
89
90
# File 'lib/bcoin/client/wallet.rb', line 81

def retoken
  response = post '/retoken'

  if error?
    false
  else
    @attributes[:token] = response['token']
    true
  end
end

#send(options = {}) ⇒ Object

Create, sign, and send a new transaction.

Parameters:

  • opts (Hash)

    a customizable set of options



105
106
107
108
# File 'lib/bcoin/client/wallet.rb', line 105

def send options = {}
  response = post '/send', options
  error? ? false : response
end

#unlock(options = {}) ⇒ true, false

Unlock the wallet master key for retrieval of the wallet mnemonic, and key in plain text for ‘timeout’ number of seconds.

Parameters:

  • opts (Hash)

    a customizable set of options

Returns:

  • (true, false)

    True if succesful.



57
58
59
60
# File 'lib/bcoin/client/wallet.rb', line 57

def unlock options = {}
  post '/unlock', options
  !error?
end