class Peatio::Decredcoin::Wallet
Constants
- DEFAULT_FEATURES
- SUPPORTED_FEATURES
Public Class Methods
new(custom_features = {})
click to toggle source
# File lib/peatio/decredcoin/wallet.rb, line 8 def initialize(custom_features = {}) @features = DEFAULT_FEATURES.merge(custom_features).slice(*SUPPORTED_FEATURES) @settings = {} end
Public Instance Methods
configure(settings = {})
click to toggle source
# 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, :passphrase) @currency = @settings.fetch(:currency) do raise Peatio::Wallet::MissingSettingError, :currency end.slice(:id, :base_factor, :options) end
create_address!(_options = {})
click to toggle source
# 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 = {})
click to toggle source
create a transaction
# File lib/peatio/decredcoin/wallet.rb, line 35 def create_transaction!(transaction, options = {}) unlock_wallet!(options[:timeout]) 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')
click to toggle source
# File lib/peatio/decredcoin/wallet.rb, line 48 def load_balance!(account_name = 'default') response = client.json_rpc(:getbalance) account = response['balances'].find { |k| k['accountname'].eql? account_name } raise Decredcoin::Client::Error.new 'account does not exists' unless account account['total'].to_d rescue Decredcoin::Client::Error => e raise Peatio::Wallet::ClientError, e end
Private Instance Methods
client()
click to toggle source
# File lib/peatio/decredcoin/wallet.rb, line 72 def client uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri } @client ||= Client.new(uri) end
unlock_wallet!(timeout = 15)
click to toggle source
unlock wallet for 15 seconds
# File lib/peatio/decredcoin/wallet.rb, line 62 def unlock_wallet!(timeout = 15) client.json_rpc(:walletpassphrase, [ @wallet.fetch(:passphrase), timeout ]) rescue Decredcoin::Client::Error => e raise Peatio::Wallet::ClientError, e end