lib/peatio/bitgo/wallet.rb in peatio-bitgo-2.6.8 vs lib/peatio/bitgo/wallet.rb in peatio-bitgo-3.1.0
- old
+ new
@@ -58,18 +58,24 @@
baseFeeInfo = fee.dig('feeInfo','fee')
fee = baseFeeInfo.present? ? baseFeeInfo : fee.dig('txInfo','Fee')
amount -= fee.to_i
end
- txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
+ response = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
address: normalize_address(transaction.to_address.to_s),
amount: amount.to_s,
walletPassphrase: bitgo_wallet_passphrase,
memo: xlm_memo(transaction.to_address.to_s)
- }.compact).fetch('txid')
+ }.compact)
- transaction.hash = normalize_txid(txid)
+ if response['feeString'].present?
+ fee = convert_from_base_unit(response['feeString'])
+ transaction.fee = fee
+ end
+
+ transaction.hash = normalize_txid(response['txid'])
+ transaction.fee_currency_id = erc20_currency_id
transaction
end
rescue Bitgo::Client::Error => e
raise Peatio::Wallet::ClientError, e
end
@@ -94,20 +100,26 @@
options[:gas_price] = transaction.options[:gas_price]
else
options[:gas_price] = fee_estimate['minGasPrice'].to_i
end
- txid = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
+ response = client.rest_api(:post, "#{currency_id}/wallet/#{wallet_id}/sendcoins", {
address: transaction.to_address.to_s,
amount: amount.to_s,
walletPassphrase: bitgo_wallet_passphrase,
gas: options.fetch(:gas_limit).to_i,
gasPrice: options.fetch(:gas_price).to_i,
hop: hop
- }.compact).fetch('txid')
+ }.compact)
- transaction.hash = normalize_txid(txid)
+ if response['feeString'].present?
+ fee = convert_from_base_unit(response['feeString'])
+ transaction.fee = fee
+ end
+
+ transaction.hash = normalize_txid(response['txid'])
+ transaction.fee_currency_id = erc20_currency_id
transaction.options = options
transaction
end
def fee_estimate(amount, hop)
@@ -178,12 +190,18 @@
if response['outputs'].present?
output = response['outputs'].find { |out| out['address'] == to_address }
txout = output['index'] if output.present?
end
+ if response['feeString'].present?
+ fee = convert_from_base_unit(response['feeString']) / response['entries'].count
+ end
+
transaction = Peatio::Transaction.new(
currency_id: @currency.fetch(:id),
amount: convert_from_base_unit(entry['valueString']),
+ fee: fee,
+ fee_currency_id: erc20_currency_id,
hash: normalize_txid(response['txid']),
to_address: to_address,
block_number: response['height'],
txout: txout.to_i,
status: state