CoinRPC#sendtoaddress requires real number with maximum 8 decimal places but Peatio may send more (withdraw)
- https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list
- https://en.bitcoin.it/wiki/Proper_Money_Handling_(JSON-RPC)
To reproduce:
- Put
binding.pryat 33-th line atapp/models/worker/withdraw_coin.rb. - Edit
config/currencies.ymland setquick_withdraw_maxto 1 or something greater. - Run app & daemons, manually stop
amqp:withdraw_coin:god stop amqp:withdraw_coinand run manuallyRAILS_ROOT=$(pwd) bundle exec ruby lib/daemons/amqp_daemon.rb withdraw_coin(this is required to make REPL work). - Deposit BTC.
- Generate Bitcoin Testnet address outside of Peatio hot wallet.
- Create withdraw for 0.5 BTC to that address.
- Wait a minute than back to shell – you should be in REPL shell.
- Examine variables
balance,fee,withdraw.amount.
Result of execution of this line of code
Withdraws::Satoshi.new("fund_source"=>3, "member_id"=>7, "currency"=>"btc", "sum"=>0.5)
Is
id: nil,
sn: nil,
account_id: nil,
member_id: 7,
currency: 2,
amount: nil,
fee: nil,
fund_uid: nil,
fund_extra: nil,
created_at: nil,
updated_at: nil,
done_at: nil,
txid: nil,
aasm_state: nil,
sum: 0.5000000000000001e0,
type: "Withdraws::Satoshi">
Here we can find that sum is 0.5000000000000001e0 instead of 0.5
@yssavchuk So we have some issues with numbers since 0.5 becomes 0.5000000000000001
Finally I found this method to be responsible for withdraw precision
def fix_precision
binding.pry
if sum && currency_obj.precision
self.sum = sum.round(currency_obj.precision, BigDecimal::ROUND_DOWN)
end
end
That's why we can add this line to currencies.yml
precision: 8 #or less
This will solve our problem until we have withdraw fee hardcoded
def set_fee
self.fee = "0.0001".to_d
end
What is more I think we need to provide input validation of amount because user can input 0.0010000000000001
@yivo ping
@yssavchuk What is the default value for precision in currencies.yml?
it is not provided for coins
@yssavchuk We can check user input like so:
n = 0.0010000000000001
valid = n.to_s.split('.').last == n.to_s.split('.').last[0...8]
@yssavchuk Can you set precision to 8 in currencies.yml and test?
Progress in #315.
this will help https://github.com/amarian12/nlexch.com/commit/be2f7bdb30e48686ec9472ed6dfb7def6152e993