Initial commit

This commit is contained in:
Yaser
2026-08-13 19:50:53 +03:30
commit 38084458fe
879 changed files with 95198 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
# Withdraw: Coin
###### Sprint: 7
### Outcome:
Users can do coin withdrawal from any wallet to favorite address
### Implementation description:
#### Endpoints:
POST {$domain}/api/v2/peatio/account/withdraws
#### File destination:
{$Dena_Path}/app/api/v2/account/withdraws.rb
#### Commits:
016303d1<br />
cc565d9e<br />
12322261<br />
#### What did we implement:
we add controlling step before withdraw creation, so at first check 2fa (if was enabled),<br />
the check auth code that was sent to the email
```mermaid
sequenceDiagram
Title: Withdraw Coin
User->>Ranj:select favorite beneficiary
Ranj->>User:Ask OTP code for confirming
User-->>Ranj:if OTP code not received, try for resend after 120 seconds
Ranj-->>Dena: Ask for sending OTP code again
Dena-->>User:2xx send otp to his or her email
note over User,Ranj:note parameter is optioanl
User->>Ranj:otp, beneficiary_id, currency, amount, **note**
Ranj->>Dena:POST: after client side checking
Dena->>Ranj:4xx if lose any required parameters
Dena->>Ranj:4xx if the config variable: **ENABLE_ACCOUNT_WITHDRAWAL_API** is FALSE
Dena->>Ranj:4xx if enter 2fa code wrong (will be check if 2fa is activated before)
Dena->>Ranj:4xx if OTP code expired
Dena->>Ranj:4xx if beneficiary is not active
Dena->>Ranj:4xx if withdrawal is disabled for the currency
note over Dena,Blockchain:The Blockchain service has own documentation
note over Dena,Blockchain:The Blockchain service trigged by hook method in withdraw model
Dena->>Blockchain:coin withdraw record created and balance locked
Dena->>Ranj:2xx coin withdraw created
Ranj->>User: notify user that new withdraw created
```

View File

@@ -0,0 +1,57 @@
# Withdraw: Fiat
###### Sprint: 5
### Outcome:
Users can do fiat withdrawal with the Help of the Vandar service.
### Implementation description:
#### Endpoints:
POST {$domain}/api/v2/peatio/account/withdraws/fiat <br/>
POST {$domain}/api/v2/peatio/account/withdraws/confirm
#### File destination:
{$Dena_Path}/app/api/v2/account/withdraws.rb
#### Commits:
2cd9b4ad<br />
cc7ce09c<br />
2826a52c<br />
b9154ef8<br />
79d4b137<br />
807f350b<br />
638b493c<br />
7769e86a<br />
14fdfd2a<br />
#### What did we implement:
we implemented a new client route for user, to they can withdraw their money after entering valid 2fa and also,
auth code that was sent to the email
```mermaid
sequenceDiagram
Title: Withdraw Fiat
note over User,Ranj:note parameter is optioanl
User->>Ranj:amount, iban, currency, **note**
Ranj->>Dena:POST: after client side checking
Dena->>Ranj:4xx if lose any required parameters
note over Dena,Vandar:The Vandar service has own documentation
Dena->>Ranj:4xx if the config variable: **ENABLE_ACCOUNT_WITHDRAWAL_API** is FALSE
Dena->>Ranj:4xx if enter 2fa code wrong (will be check if 2fa is activated before)
Dena->>Ranj:4xx if entered IBAN not exist in current user valid IBAN list
Dena->>User:2xx withdraw record created and send otp to his or her mail
Ranj->>User:Ask OTP code for confirming
User-->>Ranj:if OTP code not received, try for resend after 120 seconds
Ranj-->>Dena: Ask for sending OTP code again
Dena-->>User:2xx send otp to his or her email
User->>Ranj: enter OTP code
Ranj->>Dena:Post : OTP code for checking
Dena->>Ranj:4xx if OTP code expired
Dena->>Vandar:2xx account balance locked
Dena->>Vandar:POST track_id, amount, IBAN
Vandar->>Dena:200 new withdraw with transaction_id was created for sending the Bank
Dena->>Ranj:withdraw will be rejected if the status of the Vandar response is false \n or withdraw will be confirmed and updated transaction_id if the status of the response is true
Ranj->>User: show The vandar response
```

View File

@@ -0,0 +1,58 @@
# 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
```