From 43bd594dc37d3ce25ef8ced01ded8e806c10dfd5 Mon Sep 17 00:00:00 2001 From: Claus-Peter Huebner Date: Wed, 23 Aug 2023 01:19:19 +0200 Subject: [PATCH] commit wip --- .../federation/client/1_0/SendCoinsClient.ts | 18 +++++++++++++ .../client/1_0/query/commitSendCoins.ts | 25 +++++++++++++++++++ database/entity/PendingTransaction.ts | 2 +- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 backend/src/federation/client/1_0/query/commitSendCoins.ts diff --git a/backend/src/federation/client/1_0/SendCoinsClient.ts b/backend/src/federation/client/1_0/SendCoinsClient.ts index 0362d9c27..0264d8b70 100644 --- a/backend/src/federation/client/1_0/SendCoinsClient.ts +++ b/backend/src/federation/client/1_0/SendCoinsClient.ts @@ -5,6 +5,7 @@ import { LogError } from '@/server/LogError' import { backendLogger as logger } from '@/server/logger' import { SendCoinsArgs } from './model/SendCoinsArgs' +import { commitSendCoins } from './query/commitSendCoins' import { revertSendCoins } from './query/revertSendCoins' import { voteForSendCoins } from './query/voteForSendCoins' @@ -66,4 +67,21 @@ export class SendCoinsClient { throw new LogError(`X-Com: revertSendCoins failed for endpoint=${this.endpoint}`, err) } } + + commitSendCoins = async (args: SendCoinsArgs): Promise => { + logger.debug(`X-Com: commitSendCoins against endpoint='${this.endpoint}'...`) + try { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const { data } = await this.client.rawRequest(commitSendCoins, { args }) + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + if (!data?.commitSendCoins?.acknowledged) { + logger.warn('X-Com: commitSendCoins without response data from endpoint', this.endpoint) + return false + } + logger.debug(`X-Com: commitSendCoins successful from endpoint=${this.endpoint}`) + return true + } catch (err) { + throw new LogError(`X-Com: commitSendCoins failed for endpoint=${this.endpoint}`, err) + } + } } diff --git a/backend/src/federation/client/1_0/query/commitSendCoins.ts b/backend/src/federation/client/1_0/query/commitSendCoins.ts new file mode 100644 index 000000000..eea934d00 --- /dev/null +++ b/backend/src/federation/client/1_0/query/commitSendCoins.ts @@ -0,0 +1,25 @@ +import { gql } from 'graphql-request' + +export const commitSendCoins = gql` + mutation ( + $communityReceiverIdentifier: String! + $userReceiverIdentifier: String! + $amount: Decimal! + $memo: String! + $communitySenderIdentifier: String! + $userSenderIdentifier: String! + $userSenderName: String! + ) { + commitSendCoins( + communityReceiverIdentifier: $communityReceiverIdentifier + userReceiverIdentifier: $userReceiverIdentifier + amount: $amount + memo: $memo + communitySenderIdentifier: $communitySenderIdentifier + userSenderIdentifier: $userSenderIdentifier + userSenderName: $userSenderName + ) { + acknowledged + } + } +` diff --git a/database/entity/PendingTransaction.ts b/database/entity/PendingTransaction.ts index 5ae28c2cd..dbd6f0c74 100644 --- a/database/entity/PendingTransaction.ts +++ b/database/entity/PendingTransaction.ts @@ -1 +1 @@ -export { Transaction } from './0071-add-pending_transactions-table/PendingTransaction' +export { PendingTransaction } from './0071-add-pending_transactions-table/PendingTransaction'