require_relative "btc_base_wallet_client" module PortalConnectors class CoinWalletClient < BaseClient def send_withdrawal(coin:, address:, amount:, payment_id:, token_id: nil, **extras) params = { nonce: next_nonce, coin: coin, token_id: token_id, amount: amount, payment_id: payment_id, address: address }.merge(extras.except(:skip_ssl)) url = "#{host}/api/v1/withdrawals/request" res = post_with_signature(url, params, skip_ssl: extras[:skip_ssl]) [JSON.parse(res.body_str), res.response_code == 201] rescue => e return_error e end def cancel_withdrawal(coin:, payment_id:) params = { nonce: next_nonce, coin: coin, payment_id: payment_id } url = "#{host}/api/v1/withdrawals/cancel" res = post_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 201] rescue => e return_error e end def fetch_deposit(coin:, tx_hash:, out_index:, skip_ssl: false) params = { nonce: next_nonce, coin: coin, tx_hash: tx_hash, out_index: out_index } url = "#{host}/api/v1/deposits" res = get_with_signature(url, params, skip_ssl: skip_ssl) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def get_address(coin:, account_id:, address_type: nil, skip_ssl: false) params = { nonce: next_nonce, coin: coin, account_id: account_id, address_type: address_type, } url = "#{host}/api/v1/coin_addresses/get_coin_address" res = get_with_signature(url, params, skip_ssl: skip_ssl) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def get_address_name(coin:, address:) params = { nonce: next_nonce, coin: coin, address: address } url = "#{host}/api/v1/coin_addresses/get_address_name" res = get_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def repost_deposits(coin:, address:) params = { nonce: next_nonce, coin: coin, address: address } url = "#{host}/api/v1/coin_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:, report_time: Time.current, start_report_time: nil) params = { nonce: next_nonce, coin: coin, 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) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def list_deposit_keys(coin:, from_time: Time.current, to_time: Time.current.beginning_of_day) params = { nonce: next_nonce, coin: coin, 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(coin:, from_time: Time.current, to_time: Time.current.beginning_of_day) params = { nonce: next_nonce, coin: coin, 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 fetch_restrictions(coin:, address:) params = { nonce: next_nonce, coin: coin, address: address, } url = "#{host}/api/v1/restrictions" res = get_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def fetch_block(coin:, block_height:) params = { nonce: next_nonce, coin: coin, block_height: block_height, } url = "#{host}/api/v1/blocks/find" res = get_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def fetch_tx(chain:, tx_hash:) params = { nonce: next_nonce, chain: chain, tx_hash: tx_hash, } url = "#{host}/api/v1/transactions/find" res = get_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 200] rescue => e return_error e end def decode_invoice(bolt11:) params = { bolt11: bolt11, nonce: next_nonce } url = "#{host}/api/v1/invoices/decode" res = post_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 201] rescue StandardError => e return_error e end def request_invoice(account_id:, amount_btc:) params = { account_id: account_id, amount_btc: amount_btc, nonce: next_nonce } url = "#{host}/api/v1/invoices/request" res = post_with_signature(url, params) [JSON.parse(res.body_str), res.response_code == 201] rescue StandardError => e return_error e end protected def postback_url(type) "#{PortalConnectors.postbacks.coin_wallet}/#{type}" end end end