Skip to content

Commit

Permalink
chore: use interface for invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi committed Oct 17, 2023
1 parent 0a75077 commit b7cc761
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 51 deletions.
28 changes: 19 additions & 9 deletions core/api/dev/apollo-federation/supergraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ type BTCWallet implements Wallet
"""An unconfirmed incoming onchain balance."""
pendingIncomingBalance: SignedAmount!
transactionById(transactionId: ID!): Transaction!
transactionByPaymentHash(paymentHash: PaymentHash!): Transaction!
transactionByPaymentHash(paymentHash: PaymentHash!): Transaction

"""A list of BTC transactions associated with this wallet."""
transactions(
Expand Down Expand Up @@ -550,11 +550,19 @@ input IntraLedgerUsdPaymentSendInput
walletId: WalletId!
}

union Invoice
"""A lightning invoice."""
interface Invoice
@join__type(graph: PUBLIC)
@join__unionMember(graph: PUBLIC, member: "LnInvoice")
@join__unionMember(graph: PUBLIC, member: "LnNoAmountInvoice")
= LnInvoice | LnNoAmountInvoice
{
"""The payment hash of the lightning invoice."""
paymentHash: PaymentHash!

"""The bolt11 invoice to be paid."""
paymentRequest: LnPaymentRequest!

"""The payment secret of the lightning invoice."""
paymentSecret: LnPaymentSecret!
}

enum InvoicePaymentStatus
@join__type(graph: PUBLIC)
Expand Down Expand Up @@ -587,7 +595,8 @@ enum link__Purpose {
EXECUTION
}

type LnInvoice
type LnInvoice implements Invoice
@join__implements(graph: PUBLIC, interface: "Invoice")
@join__type(graph: PUBLIC)
{
paymentHash: PaymentHash!
Expand Down Expand Up @@ -671,7 +680,8 @@ type LnInvoicePaymentStatusPayload
status: InvoicePaymentStatus
}

type LnNoAmountInvoice
type LnNoAmountInvoice implements Invoice
@join__implements(graph: PUBLIC, interface: "Invoice")
@join__type(graph: PUBLIC)
{
paymentHash: PaymentHash!
Expand Down Expand Up @@ -1598,7 +1608,7 @@ type UsdWallet implements Wallet
"""An unconfirmed incoming onchain balance."""
pendingIncomingBalance: SignedAmount!
transactionById(transactionId: ID!): Transaction!
transactionByPaymentHash(paymentHash: PaymentHash!): Transaction!
transactionByPaymentHash(paymentHash: PaymentHash!): Transaction
transactions(
"""Returns the items in the list that come after the specified cursor."""
after: String
Expand Down Expand Up @@ -1919,7 +1929,7 @@ interface Wallet
transactionByPaymentHash(
"""The payment hash of the lightning invoice paid in this transaction."""
paymentHash: PaymentHash!
): Transaction!
): Transaction

"""
Transactions are ordered anti-chronologically,
Expand Down
31 changes: 14 additions & 17 deletions core/api/src/graphql/admin/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type BTCWallet implements Wallet {
"""An unconfirmed incoming onchain balance."""
pendingIncomingBalance: SignedAmount!
transactionById(transactionId: ID!): Transaction!
transactionByPaymentHash(paymentHash: PaymentHash!): Transaction!
transactionByPaymentHash(paymentHash: PaymentHash!): Transaction

"""A list of BTC transactions associated with this wallet."""
transactions(
Expand Down Expand Up @@ -175,7 +175,17 @@ type InitiationViaOnChain {
address: OnChainAddress!
}

union Invoice = LnInvoice | LnNoAmountInvoice
"""A lightning invoice."""
interface Invoice {
"""The payment hash of the lightning invoice."""
paymentHash: PaymentHash!

"""The bolt11 invoice to be paid."""
paymentRequest: LnPaymentRequest!

"""The payment secret of the lightning invoice."""
paymentSecret: LnPaymentSecret!
}

scalar Language

Expand All @@ -201,19 +211,6 @@ type LightningPayment {
status: LnPaymentStatus
}

type LnInvoice {
paymentHash: PaymentHash!
paymentRequest: LnPaymentRequest!
paymentSecret: LnPaymentSecret!
satoshis: SatAmount
}

type LnNoAmountInvoice {
paymentHash: PaymentHash!
paymentRequest: LnPaymentRequest!
paymentSecret: LnPaymentSecret!
}

scalar LnPaymentPreImage

"""BOLT11 lightning invoice payment request with the amount included"""
Expand Down Expand Up @@ -416,7 +413,7 @@ type UsdWallet implements Wallet {
"""An unconfirmed incoming onchain balance."""
pendingIncomingBalance: SignedAmount!
transactionById(transactionId: ID!): Transaction!
transactionByPaymentHash(paymentHash: PaymentHash!): Transaction!
transactionByPaymentHash(paymentHash: PaymentHash!): Transaction
transactions(
"""Returns the items in the list that come after the specified cursor."""
after: String
Expand Down Expand Up @@ -475,7 +472,7 @@ interface Wallet {
transactionByPaymentHash(
"""The payment hash of the lightning invoice paid in this transaction."""
paymentHash: PaymentHash!
): Transaction!
): Transaction

"""
Transactions are ordered anti-chronologically,
Expand Down
22 changes: 16 additions & 6 deletions core/api/src/graphql/public/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ type BTCWallet implements Wallet {
"""An unconfirmed incoming onchain balance."""
pendingIncomingBalance: SignedAmount!
transactionById(transactionId: ID!): Transaction!
transactionByPaymentHash(paymentHash: PaymentHash!): Transaction!
transactionByPaymentHash(paymentHash: PaymentHash!): Transaction

"""A list of BTC transactions associated with this wallet."""
transactions(
Expand Down Expand Up @@ -420,7 +420,17 @@ input IntraLedgerUsdPaymentSendInput {
walletId: WalletId!
}

union Invoice = LnInvoice | LnNoAmountInvoice
"""A lightning invoice."""
interface Invoice {
"""The payment hash of the lightning invoice."""
paymentHash: PaymentHash!

"""The bolt11 invoice to be paid."""
paymentRequest: LnPaymentRequest!

"""The payment secret of the lightning invoice."""
paymentSecret: LnPaymentSecret!
}

enum InvoicePaymentStatus {
EXPIRED
Expand All @@ -430,7 +440,7 @@ enum InvoicePaymentStatus {

scalar Language

type LnInvoice {
type LnInvoice implements Invoice {
paymentHash: PaymentHash!
paymentRequest: LnPaymentRequest!
paymentSecret: LnPaymentSecret!
Expand Down Expand Up @@ -498,7 +508,7 @@ type LnInvoicePaymentStatusPayload {
status: InvoicePaymentStatus
}

type LnNoAmountInvoice {
type LnNoAmountInvoice implements Invoice {
paymentHash: PaymentHash!
paymentRequest: LnPaymentRequest!
paymentSecret: LnPaymentSecret!
Expand Down Expand Up @@ -1255,7 +1265,7 @@ type UsdWallet implements Wallet {
"""An unconfirmed incoming onchain balance."""
pendingIncomingBalance: SignedAmount!
transactionById(transactionId: ID!): Transaction!
transactionByPaymentHash(paymentHash: PaymentHash!): Transaction!
transactionByPaymentHash(paymentHash: PaymentHash!): Transaction
transactions(
"""Returns the items in the list that come after the specified cursor."""
after: String
Expand Down Expand Up @@ -1508,7 +1518,7 @@ interface Wallet {
transactionByPaymentHash(
"""The payment hash of the lightning invoice paid in this transaction."""
paymentHash: PaymentHash!
): Transaction!
): Transaction

"""
Transactions are ordered anti-chronologically,
Expand Down
27 changes: 21 additions & 6 deletions core/api/src/graphql/shared/types/abstract/invoice.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import LnInvoice from "../object/ln-invoice"
import PaymentHash from "../scalar/payment-hash"
import LnPaymentRequest from "../scalar/ln-payment-request"

import { GT } from "@/graphql/index"
import LnPaymentSecret from "../scalar/ln-payment-secret"

import LnNoAmountInvoice from "@/graphql/shared/types/object/ln-noamount-invoice"
import { GT } from "@/graphql/index"

const Invoice = GT.Union({
const IInvoice = GT.Interface({
name: "Invoice",
types: () => [LnInvoice, LnNoAmountInvoice],
description: "A lightning invoice.",
fields: () => ({
paymentRequest: {
type: GT.NonNull(LnPaymentRequest),
description: "The bolt11 invoice to be paid.",
},
paymentHash: {
type: GT.NonNull(PaymentHash),
description: "The payment hash of the lightning invoice.",
},
paymentSecret: {
type: GT.NonNull(LnPaymentSecret),
description: "The payment secret of the lightning invoice.",
},
}),
})

export default Invoice
export default IInvoice
6 changes: 3 additions & 3 deletions core/api/src/graphql/shared/types/abstract/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SignedAmount from "../scalar/signed-amount"
import OnChainAddress from "../scalar/on-chain-address"
import PaymentHash from "../scalar/payment-hash"

import Invoice from "./invoice"
import IInvoice from "./invoice"

import { connectionArgs } from "@/graphql/connections"
import { GT } from "@/graphql/index"
Expand Down Expand Up @@ -49,7 +49,7 @@ const IWallet = GT.Interface({
},
},
invoiceByPaymentHash: {
type: GT.NonNull(Invoice),
type: GT.NonNull(IInvoice),
args: {
paymentHash: {
type: GT.NonNull(PaymentHash),
Expand All @@ -59,7 +59,7 @@ const IWallet = GT.Interface({
},
},
transactionByPaymentHash: {
type: GT.NonNull(Transaction),
type: Transaction,
args: {
paymentHash: {
type: GT.NonNull(PaymentHash),
Expand Down
6 changes: 3 additions & 3 deletions core/api/src/graphql/shared/types/object/btc-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import OnChainAddress from "../scalar/on-chain-address"

import PaymentHash from "../scalar/payment-hash"

import Invoice from "../abstract/invoice"
import IInvoice from "../abstract/invoice"

import Transaction, { TransactionConnection } from "./transaction"

Expand Down Expand Up @@ -130,7 +130,7 @@ const BtcWallet = GT.Object<Wallet>({
},
},
invoiceByPaymentHash: {
type: GT.NonNull(Invoice),
type: GT.NonNull(IInvoice),
args: {
paymentHash: {
type: GT.NonNull(PaymentHash),
Expand All @@ -153,7 +153,7 @@ const BtcWallet = GT.Object<Wallet>({
},
},
transactionByPaymentHash: {
type: GT.NonNull(Transaction),
type: Transaction,
args: {
paymentHash: {
type: GT.NonNull(PaymentHash),
Expand Down
3 changes: 3 additions & 0 deletions core/api/src/graphql/shared/types/object/ln-invoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import PaymentHash from "../scalar/payment-hash"
import LnPaymentSecret from "../scalar/ln-payment-secret"
import SatAmount from "../scalar/sat-amount"

import IInvoice from "../abstract/invoice"

import { GT } from "@/graphql/index"

const LnInvoice = GT.Object<WalletInvoice>({
name: "LnInvoice",
interfaces: () => [IInvoice],
isTypeOf: (source) => !!source.lnInvoice.amount,
fields: () => ({
paymentRequest: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import LnPaymentRequest from "../scalar/ln-payment-request"
import PaymentHash from "../scalar/payment-hash"
import LnPaymentSecret from "../scalar/ln-payment-secret"

import IInvoice from "../abstract/invoice"

import { GT } from "@/graphql/index"
// import InvoicePaymentStatus from "../scalar/invoice-payment-status"

const LnNoAmountInvoice = GT.Object<WalletInvoice>({
name: "LnNoAmountInvoice",
interfaces: () => [IInvoice],
isTypeOf: (source) => !source.lnInvoice.amount,
fields: () => ({
paymentRequest: {
Expand Down
6 changes: 3 additions & 3 deletions core/api/src/graphql/shared/types/object/usd-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import OnChainAddress from "../scalar/on-chain-address"

import PaymentHash from "../scalar/payment-hash"

import Invoice from "../abstract/invoice"
import IInvoice from "../abstract/invoice"

import Transaction, { TransactionConnection } from "./transaction"

Expand Down Expand Up @@ -128,7 +128,7 @@ const UsdWallet = GT.Object<Wallet>({
},
},
invoiceByPaymentHash: {
type: GT.NonNull(Invoice),
type: GT.NonNull(IInvoice),
args: {
paymentHash: {
type: GT.NonNull(PaymentHash),
Expand All @@ -151,7 +151,7 @@ const UsdWallet = GT.Object<Wallet>({
},
},
transactionByPaymentHash: {
type: GT.NonNull(Transaction),
type: Transaction,
args: {
paymentHash: {
type: GT.NonNull(PaymentHash),
Expand Down
6 changes: 2 additions & 4 deletions core/api/test/bats/gql/invoice-for-wallet-by-payment-hash.gql
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ query me($walletId: WalletId!, $paymentHash: PaymentHash!) {
walletById(walletId: $walletId) {
id
invoiceByPaymentHash(paymentHash: $paymentHash) {
paymentHash
... on LnInvoice {
paymentHash
}
... on LnNoAmountInvoice {
paymentHash
satoshis
}
}
}
Expand Down

0 comments on commit b7cc761

Please sign in to comment.