2.8 KiB
Spread between wallets method
files:
- {$Dena_path}/app/workers/daemons/deposit.rb
- {$Dena_path}/app/models/deposit.rb
implementation
If you have read the deposit doc, you know this function where is called.
spread_between_wallets! function
- Will Return to ex-process if the Spread column had value.
- Finding the Deposit wallet form currency and pass it as input param to the WalletService class to create the object.
- Calling
spread_depositfunction from WalletService class for the deposit record - Update the spread column for DB record with return value from step 3.
spread_deposit function
- The Adapter will be configured with the wallet record data and the relevant blockchain and currency setting
- Array list by data of the withdraw wallet form DB (HOT WARM COLD)
- Map them to new data by name destination_wallets:
address: the wallet addressbalance: the current coin balance of walletmax_balance: how many coins the wallet can hostmin_collection_amount: the minimum of accepted deposit (set in the Admin panel)skip_deposit_collection: boolean type to skip deposit or not (set in the Admin panel)
- Set the zero the balance for the last wallet. Since last wallet is considered to be the most secure we need always. All money which doesn't fit to other wallets will be collected to last wallet.
- Call
spread_between_walletsfrom WalletService with the deposit record and the destination_wallets
spread_between_wallets function
-
Returning empty array if deposit amount smaller than the minimum of
min_collection amountof wallets. -
left_amount variable is initialized with amount of the deposit (original_amount)
-
starting a loop on
destination_wallets. -
amount_for_wallet= choose the minimum value between available wallet balance and left_amount -
Setting zero for
amount_for_walletif this variable smaller thanmin_collection_amount -
left_amountwill equal to (left_amountminusamount_for_wallet) -
If amount left is too small we will not able to collect it.So we collect everything to current wallet.<br/ >
amount_for_wallet=amount_for_wallet+left_amountandleft_amount= 0 -
Creating
Peatio::Transactionobject:- to_address :
to_addressfrom destination_wallets - amount :
amount_for_wallet - currency_id: currency_id of the deposit record
- status : :skipped if
skip_deposit_collectionis true
- to_address :
-
Ending the loop on
destination_walletsand now we havespreadvariable that includes transactions. -
If deposit amount doesn't fit to any wallet, collect it to the last one. (
left_amountdoesnt become zero). -
Remove zero and skipped transactions from spread.
-
Return
spreadvariable.