Skip to content
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

feat(core): add transaction to send mutations and myupdates #3619

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading