Class: Peatio::Decredcoin::Wallet

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

Constant Summary collapse

DEFAULT_FEATURES =
{ skip_deposit_collection: false }.freeze
SUPPORTED_FEATURES =
{case_sensitive: true, cash_addr_format: 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/decredcoin/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/decredcoin/wallet.rb', line 13

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

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

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

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

#create_address!(_options = {}) ⇒ Object



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

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

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



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/peatio/decredcoin/wallet.rb', line 48

def create_transaction!(transaction, options = {})
  # create a transaction
  txid = client.json_rpc(:sendtoaddress,
                         [
                             transaction.to_address,
                             transaction.amount.to_f
                         ])
  transaction.hash = txid
  transaction
rescue Decredcoin::Client::Error => e
  raise Peatio::Wallet::ClientError, e
end

#load_balance!(account_name = 'default') ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/peatio/decredcoin/wallet.rb', line 61

def load_balance!( = 'default')
  response = client.json_rpc(:getbalance)
   = response['balances'].find { |k| k['accountname'].eql?  }

  raise Decredcoin::Client::Error.new 'account does not exists' unless 

  ['total'].to_d
rescue Decredcoin::Client::Error => e
  raise Peatio::Wallet::ClientError, e
end

#unlock_wallet!(passphrase, timeout = 15) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/peatio/decredcoin/wallet.rb', line 36

def unlock_wallet!(passphrase, timeout = 15)
  # unlock wallet for 10 seconds
  client.json_rpc(:walletpassphrase,
                  [
                      passphrase,
                      timeout
                  ])
rescue Decredcoin::Client::Error => e
  raise Peatio::Wallet::ClientError, e
end