Files
Dena/docs/zagros/withdraw/withdraw-coin.md
2026-08-13 19:50:53 +03:30

59 lines
2.6 KiB
Markdown

# Blockchain Withdraw: Coin
###### Sprint: 7
### Outcome:
Users can do coin withdrawal from any wallet to favorite address
#### File destination:
- {$Dena_Path}/app/model/withdraw.rb
- {$Dena_Path}/app/workers/amqp/withdraw_coin.rb
### Implementation description:
after withdraw was created by the user through the API,
the hooked method will be called and send the hash message (withdraw data) to RabbitMq relevant queue.<br />
the class is responsible to handle the hash message is: `WithdrawCoin`
1- finding the Withdraw by the id in the hash message if not, an error will be logged that not found a record in DB and exit
2- locking the Withdraw
3- check state of the Withdraw is processing, if not, an error will be logged and exit
4- check destination address was present, if not, an error will be logged, the Withdraw will be failed and exit
5- logging warning message that withdraw is ready for sending to blockchain
6- find an active hot wallet, if not, an error will be logged, the Withdraw will be skipped, and exit
7- check the balance of the active hot wallet, if not appropriate log error, skip the Withdraw and exit
8- create an object from WalletService by the active hot wallet
9- **WalletService** call `build_withdrawal!` for the withdraw and return transaction
10- the `txid` of the Withdraw being update by the Hash of the transaction
11- changing withdraw the state from `processing` to `confirming` with `dispatch` function
12- save the Withdraw in DB
```mermaid
graph TD
A[API] --> |post request| B[withdraw model]
B --> |hooked method| C(RabbitMq)
D(withdraw coin) --> |hash message in queue| C
D --> E((WalletService))
```
#### WalletService
this class using as a middleman for connecting to every coin wallet.<br />
In the time of creation object, the adapter (the hand of this class to talk the crypto coin wallet) receives its config.<br />
The aim of WalletService class is to union and structurize all crypto coin wallets implemented in the Peatio.<br />
##### build_withdrawal! function
this method create transaction on blockchain by the help of adapter and specific its config
```mermaid
graph LR
A(Peatio) -->|Blockchain stuffs| B[BlockchainService using adapter]
A --> |Wallet Deposit/Withdraw| C[WalletService using adapter]
B --> |Blockchain stuffs| D((Btc Blockchain))
B --> |Blockchain stuffs| E((Eth Blockchain))
B --> |Blockchain stuffs| F((...))
B --> A
C --> |Wallet Deposit/Withdraw| G((Btc Wallet))
C --> |Wallet Deposit/Withdraw| H((Eth Wallet))
C --> |Wallet Deposit/Withdraw| I((...))
C --> A
```