Sha256: 7400311168023ee21d94f6a968cc8fcf2e5059b3711814ccbd8dba7aeb8ecdec

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

module Peatio
  module Goldcash
    class Wallet < Peatio::Wallet::Abstract
      DEFAULT_FEATURES = { skip_deposit_collection: false }.freeze

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

      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

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

      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 Goldcash::Client::Error => e
        raise Peatio::Wallet::ClientError, e
      end

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

      private

      def client
        uri = @wallet.fetch(:uri) { raise Peatio::Wallet::MissingSettingError, :uri }
        @client ||= Client.new(uri)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
peatio-goldcash-2.6.7 lib/peatio/goldcash/wallet.rb