-
Notifications
You must be signed in to change notification settings - Fork 30
feat: Automatically approve blocked deposits #2198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { createHmac } from 'crypto' | ||
| import { | ||
| HTTP_METHODS, | ||
| IApprovePendingTransaction, | ||
| IApproveUserToGatewayRequest, | ||
| IApproveUserToGatewayResponse, | ||
| IConnectUserToGatewayResponse, | ||
|
|
@@ -17,6 +18,7 @@ import { | |
| IGetWalletResponse, | ||
| IOverrideUserRiskLevelRequest, | ||
| IOverrideUserRiskLevelResponse, | ||
| IPendingTransaction, | ||
| IRatesResponse, | ||
| ITokenRequest, | ||
| ITokenResponse, | ||
|
|
@@ -335,6 +337,53 @@ export class GateHubClient { | |
| return response | ||
| } | ||
|
|
||
| async approvePendingTransactions( | ||
| transactionUuid: string | ||
| ): Promise<IApprovePendingTransaction> { | ||
| const url = `${this.apiUrl}/core/v1/transactions/${transactionUuid}/serviceStatus` | ||
| const body = { | ||
| serviceStatus: 3, | ||
| substatus: 0, | ||
| reason: 'test' | ||
| } | ||
| const response = await this.request<IApprovePendingTransaction>( | ||
| 'PUT', | ||
| url, | ||
| JSON.stringify(body) | ||
| ) | ||
| if (response.state !== 4) { | ||
| throw new Error(`Approval failed, transactionUuid: ${transactionUuid}`) | ||
| } | ||
| return response | ||
| } | ||
|
|
||
| async getPendingTransactions(): Promise<IPendingTransaction[]> { | ||
| const url = `${this.apiUrl}/core/v1/gateways/${this.env.GATEHUB_GATEWAY_UUID}/transactions` | ||
| const payload = { | ||
| filters: { | ||
| state: { | ||
| value: 3 | ||
| }, | ||
| created_at: {}, | ||
| amount: {}, | ||
| define_range: { | ||
| offset: 0, | ||
| limit: 20 | ||
| }, | ||
| order: { | ||
| field: 'id', | ||
| direction: 'desc' | ||
| } | ||
| } | ||
| } | ||
| const response = await this.request<IPendingTransaction[]>( | ||
| 'GET', | ||
| url, | ||
| JSON.stringify(payload) | ||
| ) | ||
| return response | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leave a new line between blocks and returns for better readability |
||
| } | ||
|
|
||
| async getWallet( | ||
| userUuid: string, | ||
| walletId: string | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,6 +203,28 @@ export class TransactionService implements ITransactionService { | |
| } | ||
| } | ||
|
|
||
| async approveTransactions() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. asa the trx are GateHub trx, I think it should be in gatehub service |
||
| try { | ||
| const transactions = await this.gateHubClient.getPendingTransactions() | ||
| const pendingTransactions = transactions.filter( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this filter necessary?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, getPendingTransactions should already filter for state=3 |
||
| (transaction) => transaction.state === 3 | ||
| ) | ||
| if (!pendingTransactions.length) { | ||
| console.log('No pending Transactions!') | ||
| return | ||
| } | ||
| for (const transaction of pendingTransactions) { | ||
| try { | ||
| await this.gateHubClient.approvePendingTransactions(transaction.uuid) | ||
| } catch (err) { | ||
| console.error(`Error: ${err}`) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
| } | ||
| } | ||
| } catch (err) { | ||
| console.error(`Automatic approval failed - ${err}`) | ||
| } | ||
| } | ||
|
|
||
| async processPendingIncomingPayments(): Promise<string | undefined> { | ||
| return this.knex.transaction(async (trx) => { | ||
| // Giving a Rafiki a little more time to process the payments before we process them. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the same approach with
setTimeoutafter getting a response, this why the next processing will be set only after the previous one finishes and it will avoid parallel processing in case of slow responses