-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add transactionsByPaymentRequest query
- Loading branch information
Showing
7 changed files
with
196 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
query transactionsForWalletByPaymentRequest( | ||
$walletId: WalletId! | ||
$paymentRequest: PaymentRequest! | ||
) { | ||
me { | ||
defaultAccount { | ||
displayCurrency | ||
walletById(walletId: $walletId) { | ||
id | ||
transactionsByPaymentRequest(paymentRequest: $paymentRequest) { | ||
__typename | ||
id | ||
status | ||
direction | ||
memo | ||
createdAt | ||
settlementAmount | ||
settlementFee | ||
settlementDisplayAmount | ||
settlementDisplayFee | ||
settlementDisplayCurrency | ||
settlementCurrency | ||
settlementPrice { | ||
base | ||
offset | ||
} | ||
initiationVia { | ||
__typename | ||
... on InitiationViaIntraLedger { | ||
counterPartyWalletId | ||
counterPartyUsername | ||
} | ||
... on InitiationViaLn { | ||
paymentHash | ||
paymentRequest | ||
} | ||
... on InitiationViaOnChain { | ||
address | ||
} | ||
} | ||
settlementVia { | ||
__typename | ||
... on SettlementViaIntraLedger { | ||
counterPartyWalletId | ||
counterPartyUsername | ||
} | ||
... on SettlementViaLn { | ||
preImage | ||
} | ||
... on SettlementViaOnChain { | ||
transactionHash | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
core/api/src/app/wallets/get-transactions-by-payment-request.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
getTransactionsByHash, | ||
getTransactionsForWalletByPaymentHash, | ||
} from "./get-transactions-by-hash" | ||
|
||
import { decodeInvoice } from "@/domain/bitcoin/lightning" | ||
|
||
export const getTransactionsForWalletByPaymentRequest = async ({ | ||
walletId, | ||
uncheckedPaymentRequest, | ||
}: { | ||
walletId: WalletId | ||
uncheckedPaymentRequest: string | ||
}): Promise<WalletTransaction[] | ApplicationError> => { | ||
const decodedInvoice = decodeInvoice(uncheckedPaymentRequest) | ||
if (decodedInvoice instanceof Error) return decodedInvoice | ||
|
||
return getTransactionsForWalletByPaymentHash({ | ||
walletId, | ||
paymentHash: decodedInvoice.paymentHash, | ||
}) | ||
} | ||
|
||
export const getTransactionsByPaymentRequest = async ({ | ||
uncheckedPaymentRequest, | ||
}: { | ||
uncheckedPaymentRequest: string | ||
}): Promise<WalletTransaction[] | ApplicationError> => { | ||
const decodedInvoice = decodeInvoice(uncheckedPaymentRequest) | ||
if (decodedInvoice instanceof Error) return decodedInvoice | ||
|
||
return getTransactionsByHash(decodedInvoice.paymentHash) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
core/api/src/graphql/admin/root/query/transactions-by-payment-request.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { GT } from "@/graphql/index" | ||
|
||
import { Wallets } from "@/app" | ||
import { mapError } from "@/graphql/error-map" | ||
import Transaction from "@/graphql/shared/types/object/transaction" | ||
import LnPaymentRequest from "@/graphql/shared/types/scalar/ln-payment-request" | ||
|
||
const TransactionsByPaymentRequestQuery = GT.Field({ | ||
type: GT.List(Transaction), | ||
args: { | ||
paymentRequest: { type: GT.NonNull(LnPaymentRequest) }, | ||
}, | ||
resolve: async (_, { paymentRequest }) => { | ||
if (paymentRequest instanceof Error) throw paymentRequest | ||
|
||
const ledgerTxs = await Wallets.getTransactionsByPaymentRequest({ | ||
uncheckedPaymentRequest: paymentRequest, | ||
}) | ||
if (ledgerTxs instanceof Error) { | ||
throw mapError(ledgerTxs) | ||
} | ||
|
||
return ledgerTxs | ||
}, | ||
}) | ||
|
||
export default TransactionsByPaymentRequestQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters