class Peatio::Coinpaymentnew::Wallet

Constants

DEFAULT_FEATURES

Public Class Methods

new(custom_features = {}) click to toggle source
# File lib/peatio/coinpaymentnew/wallet.rb, line 7
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/coinpaymentnew/wallet.rb, line 12
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 = {}) click to toggle source
# File lib/peatio/coinpaymentnew/wallet.rb, line 27
def create_address!(_options = {})
  r = Coinpayments.get_callback_address(currency_id.upcase, {ipn_url: "https://v2app.rokes.exchange/api/v2/peatio/public/webhooks/deposit"})
  { address: r[:address] }
rescue Coinpaymentnew::Client::Error => e
  raise Peatio::Wallet::ClientError, e
end
create_transaction!(transaction, options = {}) click to toggle source
# File lib/peatio/coinpaymentnew/wallet.rb, line 34
def create_transaction!(transaction, options = {})
  res = Coinpayments.create_transaction(transaction.amount, "USD", currency_id, {buyer_email: "joshirockstar007@gmail.com", address: transaction.to_address, ipn_url: "https://v2app.rokes.exchange/api/v2/peatio/public/webhooks/deposit"})
  # txid = client.json_rpc(:sendtoaddress,
  #                        [
  #                          transaction.to_address,
  #                          transaction.amount,
  #                          '',
  #                          '',
  #                          options[:subtract_fee].to_s == 'true' # subtract fee from transaction amount.
  #                        ])
  transaction.hash = res[:txn_id]
  transaction
rescue Coinpaymentnew::Client::Error => e
  raise Peatio::Wallet::ClientError, e
end
load_balance!() click to toggle source
# File lib/peatio/coinpaymentnew/wallet.rb, line 50
def load_balance!
  client.json_rpc(:getbalance).to_d

rescue Coinpaymentnew::Client::Error => e
  raise Peatio::Wallet::ClientError, e
end

Private Instance Methods

client() click to toggle source
# File lib/peatio/coinpaymentnew/wallet.rb, line 59
def client
  uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
  @client ||= Client.new(uri)
end
currency_id() click to toggle source
# File lib/peatio/coinpaymentnew/wallet.rb, line 64
def currency_id
  @currency.fetch(:id) { raise Peatio::Wallet::MissingSettingError, :id }
end