Class: Peatio::Dash::Wallet

Inherits:
Wallet::Abstract
  • Object
show all
Defined in:
lib/peatio/dash/wallet.rb

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Wallet

Returns a new instance of Wallet.



6
7
8
# File 'lib/peatio/dash/wallet.rb', line 6

def initialize(settings={})
  @settings = settings
end

Instance Method Details

#configure(settings = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/peatio/dash/wallet.rb', line 10

def configure(settings={})
  # Clean client state during configure.
  @client = nil

  @settings.merge!(settings.slice(*SUPPORTED_SETTINGS))

  @wallet = @settings.fetch(:wallet) {
    raise Peatio::Wallet::MissingSettingError, :wallet
  }.slice(:uri, :address)

  @currency = @settings.fetch(:currency) {
    raise Peatio::Wallet::MissingSettingError, :currency
  }.slice(:id, :base_factor, :options)
end

#create_address!(_options = {}) ⇒ Object



25
26
27
28
29
# File 'lib/peatio/dash/wallet.rb', line 25

def create_address!(_options={})
  {address: client.json_rpc(:getnewaddress)}
rescue Dash::Client::Error => e
  raise Peatio::Wallet::ClientError, e
end

#create_transaction!(transaction, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/peatio/dash/wallet.rb', line 31

def create_transaction!(transaction, options={})
  txid = client.json_rpc(:sendtoaddress,
                         [
                           transaction.to_address,
                           transaction.amount,
                           "",
                           "",
                           options[:subtract_fee].to_s == "true" # subtract fee from transaction amount.
                         ])
  transaction.hash = txid
  transaction
rescue Dash::Client::Error => e
  raise Peatio::Wallet::ClientError, e
end

#load_balance!Object



46
47
48
49
50
# File 'lib/peatio/dash/wallet.rb', line 46

def load_balance!
  client.json_rpc(:getbalance).to_d
rescue Dash::Client::Error => e
  raise Peatio::Wallet::ClientError, e
end