class Peatio::Ndex::Client::ResponseError

Public Class Methods

new(code, msg) click to toggle source
# File lib/peatio/ndex/client.rb, line 12
def initialize(code, msg)
  @code = code
  @msg = msg
end

Public Instance Methods

create_address!(options = {}) click to toggle source
# File lib/peatio/ndex/client.rb, line 22
def create_address!(options = {})
  secret = options.fetch(:secret) { Passgen.generate(length: 64, symbols: true) }
  {
    address: normalize_address(json_rpc({requestType: 'getAccountId', secretPhrase: secret}).fetch('accountRS')),
    secret:  secret
  }
end
create_withdrawal!(issuer, recipient, amount, options = {}) click to toggle source
# File lib/peatio/ndex/client.rb, line 30
def create_withdrawal!(issuer, recipient, amount, options = {})
  withdrawal_request(issuer, recipient, amount, options).fetch('transactionJSON').yield_self do |txn|
    normalize_txid(txn['transaction'])
  end
end
get_txn_fee(issuer, recipient, amount, options = {}) click to toggle source
# File lib/peatio/ndex/client.rb, line 36
def get_txn_fee(issuer, recipient, amount, options = {})
  withdrawal_request(issuer, recipient, amount, options).fetch('transactionJSON').yield_self do |txn|
    convert_from_base_unit(txn['feeNQT'])
  end
end
inspect_address!(address) click to toggle source
# File lib/peatio/ndex/client.rb, line 42
def inspect_address!(address)
  { address:  normalize_address(address),
    is_valid: true }
end
normalize_address(address) click to toggle source
# File lib/peatio/ndex/client.rb, line 47
def normalize_address(address)
  address.upcase
end
normalize_txid(txid) click to toggle source
# File lib/peatio/ndex/client.rb, line 51
def normalize_txid(txid)
  txid.downcase
end

Protected Instance Methods

connection() click to toggle source
# File lib/peatio/ndex/client.rb, line 58
def connection
  Faraday.new(@json_rpc_endpoint).tap do |connection|
    unless @json_rpc_endpoint.user.blank?
      connection.basic_auth(@json_rpc_endpoint.user, @json_rpc_endpoint.password)
    end
  end
end
json_rpc(params = {}) click to toggle source
# File lib/peatio/ndex/client.rb, line 67
def json_rpc(params = {})
  response = connection.post do |req|
    req.url '/nxt?',
    req.body = params
  end
  response.assert_success!
  response = JSON.parse(response.body)
  response['errorDescription'].tap { |error| raise Error, error.inspect if error }
  response
end
withdrawal_request(issuer, recipient, amount, options = {}) click to toggle source
# File lib/peatio/ndex/client.rb, line 78
def withdrawal_request(issuer, recipient, amount, options = {})
  json_rpc(
      {
          requestType:  'sendMoney',
          secretPhrase: issuer.fetch(:secret),
          recipient:    normalize_address(recipient.fetch(:address)),
          amountNQT:    convert_to_base_unit!(amount),
          deadline:     60,
          feeNQT:       options.has_key?(:feeNQT) ? options[:feeNQT] : 0,
          broadcast:    options.has_key?(:broadcast) ? options[:broadcast] : true
      }
  )
end