Class: Peatio::Dash::Wallet

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

Constant Summary collapse

DEFAULT_FEATURES =
{ skip_deposit_collection: false }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(custom_features = {}) ⇒ Wallet

Returns a new instance of Wallet.



8
9
10
11
# File 'lib/peatio/dash/wallet.rb', line 8

def initialize(custom_features = {})
  @features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES)
  @settings = {}
end

Instance Method Details

#configure(settings = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/peatio/dash/wallet.rb', line 13

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



28
29
30
31
32
# File 'lib/peatio/dash/wallet.rb', line 28

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/peatio/dash/wallet.rb', line 34

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



49
50
51
52
53
# File 'lib/peatio/dash/wallet.rb', line 49

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