require_relative "base_client" module PortalConnectors class BtcBaseWalletClient < BaseClient def send_withdrawal(address:, amount:, identifier:, **extras) params = { nonce: next_nonce, amount: amount, identifier: identifier, postback_url: postback_url("withdrawal"), address: address }.merge(extras) url = "#{host}/api/v1/withdrawals/request" res = post_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 201] rescue => e return_error e end def fetch_deposit(tx_hash:, out_index:) params = { nonce: next_nonce, tx_hash: tx_hash, out_index: out_index } url = "#{host}/api/v1/deposits" res = get_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def get_address(account_type:, account_id:) params = { nonce: next_nonce, account_type: account_type, account_id: account_id } url = "#{host}/api/v1/btc_addresses/get_btc_address" res = get_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def repost_deposits(address:) params = { nonce: next_nonce, address: address } url = "#{host}/api/v1/btc_addresses/repost_deposits" res = post_with_signature(url, params) [JSON.parse(res.body_str), %w[200 201].include?(res.response_code.to_s)] rescue => e return_error e end def fetch_stocks(coin: "btc", report_time: Time.current, start_report_time: nil) params = { nonce: next_nonce, report_time: report_time.to_i, } params[:start_report_time] = start_report_time.to_i if start_report_time url = "#{host}/api/v1/stocks" res = get_with_signature(url, params) json_stocks = JSON.parse(res.body_str) self.class.cached_stocks = json_stocks (json_stocks.try(:[], "fees") || []).each do |date_key, net_fee| self.class.net_fee_nest.hset(date_key, net_fee) end [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def list_deposit_keys(from_time=Time.current, to_time=Time.current.beginning_of_day) params = { nonce: next_nonce, from_time: from_time.to_i, to_time: to_time.to_i, } url = "#{host}/api/v1/deposits/list_keys" res = get_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def list_withdraw_keys(from_time=Time.current, to_time=Time.current.beginning_of_day) params = { nonce: next_nonce, from_time: from_time.to_i, to_time: to_time.to_i, } url = "#{host}/api/v1/withdrawals/list_keys" res = get_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def self.net_fee_nest @net_fee_nest ||= nest[:net_fee] end def self.nest @nest ||= RedisFactory.nest(self.to_s) end protected def postback_url(type) raise NotImplementedError end end end