Skip to content

Commit

Permalink
feat(core): add transaction to send mutations and myupdates (#3619)
Browse files Browse the repository at this point in the history
* feat(core): add transaction to send mutations and myupdates

* chore(core): update graphql schemas

* fix: integration tests

* fix: legacy integration tests

---------

Co-authored-by: vindard <[email protected]>
  • Loading branch information
dolcalmi and vindard authored Nov 30, 2023
1 parent 16e01b6 commit 81e1678
Show file tree
Hide file tree
Showing 26 changed files with 544 additions and 134 deletions.
22 changes: 13 additions & 9 deletions core/api/dev/apollo-federation/supergraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,12 @@ input IntraLedgerPaymentSendInput
type IntraLedgerUpdate
@join__type(graph: PUBLIC)
{
amount: SatAmount!
displayCurrencyPerSat: Float!
amount: SatAmount! @deprecated(reason: "Deprecated in favor of transaction")
displayCurrencyPerSat: Float! @deprecated(reason: "Deprecated in favor of transaction")
transaction: Transaction!
txNotificationType: TxNotificationType!
usdPerSat: Float! @deprecated(reason: "updated over displayCurrencyPerSat")
walletId: WalletId!
walletId: WalletId! @deprecated(reason: "Deprecated in favor of transaction")
}

input IntraLedgerUsdPaymentSendInput
Expand Down Expand Up @@ -917,9 +918,10 @@ scalar LnPaymentSecret
type LnUpdate
@join__type(graph: PUBLIC)
{
paymentHash: PaymentHash!
paymentHash: PaymentHash! @deprecated(reason: "Deprecated in favor of transaction")
status: InvoicePaymentStatus!
walletId: WalletId!
transaction: Transaction!
walletId: WalletId! @deprecated(reason: "Deprecated in favor of transaction")
}

input LnUsdInvoiceBtcDenominatedCreateOnBehalfOfRecipientInput
Expand Down Expand Up @@ -1240,12 +1242,13 @@ scalar OnChainTxHash
type OnChainUpdate
@join__type(graph: PUBLIC)
{
amount: SatAmount!
displayCurrencyPerSat: Float!
txHash: OnChainTxHash!
amount: SatAmount! @deprecated(reason: "Deprecated in favor of transaction")
displayCurrencyPerSat: Float! @deprecated(reason: "Deprecated in favor of transaction")
transaction: Transaction!
txHash: OnChainTxHash! @deprecated(reason: "Deprecated in favor of transaction")
txNotificationType: TxNotificationType!
usdPerSat: Float! @deprecated(reason: "updated over displayCurrencyPerSat")
walletId: WalletId!
walletId: WalletId! @deprecated(reason: "Deprecated in favor of transaction")
}

input OnChainUsdPaymentSendAsBtcDenominatedInput
Expand Down Expand Up @@ -1321,6 +1324,7 @@ type PaymentSendPayload
{
errors: [Error!]!
status: PaymentSendResult
transaction: Transaction
}

enum PaymentSendResult
Expand Down
4 changes: 4 additions & 0 deletions core/api/src/app/payments/index.types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type PaymentSendResult = {
status: PaymentSendStatus
transaction: WalletTransaction
}
19 changes: 11 additions & 8 deletions core/api/src/app/payments/send-intraledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const intraledgerPaymentSendWalletId = async ({
amount: uncheckedAmount,
memo,
senderWalletId: uncheckedSenderWalletId,
}: IntraLedgerPaymentSendWalletIdArgs): Promise<PaymentSendStatus | ApplicationError> => {
}: IntraLedgerPaymentSendWalletIdArgs): Promise<PaymentSendResult | ApplicationError> => {
const validatedPaymentInputs = await validateIntraledgerPaymentInputs({
uncheckedSenderWalletId,
uncheckedRecipientWalletId,
Expand Down Expand Up @@ -117,15 +117,15 @@ const intraledgerPaymentSendWalletId = async ({
"payment.finalRecipient": JSON.stringify(paymentFlow.recipientWalletDescriptor()),
})

const paymentSendStatus = await executePaymentViaIntraledger({
const paymentSendResult = await executePaymentViaIntraledger({
paymentFlow,
senderAccount,
senderWallet,
recipientAccount,
recipientWallet,
memo,
})
if (paymentSendStatus instanceof Error) return paymentSendStatus
if (paymentSendResult instanceof Error) return paymentSendResult

if (senderAccount.id !== recipientAccount.id) {
const addContactResult = await addContactsAfterSend({
Expand All @@ -137,19 +137,19 @@ const intraledgerPaymentSendWalletId = async ({
}
}

return paymentSendStatus
return paymentSendResult
}

export const intraledgerPaymentSendWalletIdForBtcWallet = async (
args: IntraLedgerPaymentSendWalletIdArgs,
): Promise<PaymentSendStatus | ApplicationError> => {
): Promise<PaymentSendResult | ApplicationError> => {
const validated = await validateIsBtcWallet(args.senderWalletId)
return validated instanceof Error ? validated : intraledgerPaymentSendWalletId(args)
}

export const intraledgerPaymentSendWalletIdForUsdWallet = async (
args: IntraLedgerPaymentSendWalletIdArgs,
): Promise<PaymentSendStatus | ApplicationError> => {
): Promise<PaymentSendResult | ApplicationError> => {
const validated = await validateIsUsdWallet(args.senderWalletId)
return validated instanceof Error ? validated : intraledgerPaymentSendWalletId(args)
}
Expand Down Expand Up @@ -219,7 +219,7 @@ const executePaymentViaIntraledger = async <
recipientAccount: Account
recipientWallet: WalletDescriptor<R>
memo: string | null
}): Promise<PaymentSendStatus | ApplicationError> => {
}): Promise<PaymentSendResult | ApplicationError> => {
addAttributesToCurrentSpan({
"payment.settlement_method": SettlementMethod.IntraLedger,
})
Expand Down Expand Up @@ -398,6 +398,9 @@ const executePaymentViaIntraledger = async <
})
}

return PaymentSendStatus.Success
return {
status: PaymentSendStatus.Success,
transaction: senderWalletTransaction,
}
})
}
Loading

0 comments on commit 81e1678

Please sign in to comment.