Skip to content

Commit

Permalink
Fix expanding the new queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jklein24 committed May 17, 2024
1 parent 67f4ce3 commit 5a697dc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
6 changes: 4 additions & 2 deletions scripts/invoice_for_payment_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ query InvoiceForPaymentHash($payment_hash: String!) {
invoice_for_payment_hash(input: {
payment_hash: $payment_hash
}) {
...InvoiceForPaymentHashOutputFragment
invoice {
...InvoiceFragment
}
}
}
` + objects.InvoiceForPaymentHashOutputFragment
` + objects.InvoiceFragment
6 changes: 4 additions & 2 deletions scripts/outgoing_payment_for_idempotency_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ query OutgoingPaymentForIdempotencyKey(
outgoing_payment_for_idempotency_key(input: {
idempotency_key: $idempotency_key
}) {
...OutgoingPaymentForIdempotencyKeyOutputFragment
payment {
...OutgoingPaymentFragment
}
}
}
` + objects.OutgoingPaymentForIdempotencyKeyOutputFragment
` + objects.OutgoingPaymentFragment
6 changes: 4 additions & 2 deletions scripts/outgoing_payments_for_payment_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ query OutgoingPaymentsForPaymentHash(
payment_hash: $payment_hash
statuses: $statuses
}) {
...OutgoingPaymentsForPaymentHashQueryOutputFragment
payments {
...OutgoingPaymentFragment
}
}
}
` + objects.OutgoingPaymentsForPaymentHashQueryOutputFragment
` + objects.OutgoingPaymentFragment
43 changes: 27 additions & 16 deletions services/lightspark_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ func (client *LightsparkClient) FetchIncomingPaymentsByInvoice(invoiceId string,
func (client *LightsparkClient) FetchOutgoingPaymentsByPaymentHash(
paymentHash string,
statuses *[]objects.TransactionStatus,
) (*objects.OutgoingPaymentsForPaymentHashQueryOutput, error) {
) (*[]objects.OutgoingPayment, error) {
variables := map[string]interface{}{
"payment_hash": paymentHash,
"statuses": statuses,
Expand All @@ -1165,16 +1165,21 @@ func (client *LightsparkClient) FetchOutgoingPaymentsByPaymentHash(
}

output := response["outgoing_payments_for_payment_hash"].(map[string]interface{})
var payments objects.OutgoingPaymentsForPaymentHashQueryOutput
paymentsJson, err := json.Marshal(output)
if err != nil {
return nil, errors.New("error parsing payments")
paymentsJson := output["payments"].([]map[string]interface{})
var payments []objects.OutgoingPayment
for _, paymentMap := range paymentsJson {
var payment objects.OutgoingPayment
paymentJson, err := json.Marshal(paymentMap)
if err != nil {
return nil, errors.New("error parsing payment")
}
json.Unmarshal(paymentJson, &payment)
payments = append(payments, payment)
}
json.Unmarshal(paymentsJson, &payments)
return &payments, nil
}

func (client *LightsparkClient) FetchOutgoingPaymentsByIdempotencyKey(idempotencyKey string) (*objects.OutgoingPaymentForIdempotencyKeyOutput, error) {
func (client *LightsparkClient) FetchOutgoingPaymentsByIdempotencyKey(idempotencyKey string) (*objects.OutgoingPayment, error) {
variables := map[string]interface{}{
"idempotency_key": idempotencyKey,
}
Expand All @@ -1185,16 +1190,19 @@ func (client *LightsparkClient) FetchOutgoingPaymentsByIdempotencyKey(idempotenc
}

output := response["outgoing_payment_for_idempotency_key"].(map[string]interface{})
var payments objects.OutgoingPaymentForIdempotencyKeyOutput
paymentsJson, err := json.Marshal(output)
if output["payment"] == nil {
return nil, errors.New("payment not found")
}
var payment objects.OutgoingPayment
paymentJson, err := json.Marshal(output["payment"].(map[string]interface{}))
if err != nil {
return nil, errors.New("error parsing payments")
}
json.Unmarshal(paymentsJson, &payments)
return &payments, nil
json.Unmarshal(paymentJson, &payment)
return &payment, nil
}

func (client *LightsparkClient) FetchInvoiceByPaymentHash(paymentHash string) (*objects.InvoiceForPaymentHashOutput, error) {
func (client *LightsparkClient) FetchInvoiceByPaymentHash(paymentHash string) (*objects.Invoice, error) {
variables := map[string]interface{}{
"payment_hash": paymentHash,
}
Expand All @@ -1205,13 +1213,16 @@ func (client *LightsparkClient) FetchInvoiceByPaymentHash(paymentHash string) (*
}

output := response["invoice_for_payment_hash"].(map[string]interface{})
var payments objects.InvoiceForPaymentHashOutput
paymentsJson, err := json.Marshal(output)
if output["invoice"] == nil {
return nil, errors.New("invoice not found")
}
var invoice objects.Invoice
invoiceJson, err := json.Marshal(output["invoice"].(map[string]interface{}))
if err != nil {
return nil, errors.New("error parsing invoice response")
}
json.Unmarshal(paymentsJson, &payments)
return &payments, nil
json.Unmarshal(invoiceJson, &invoice)
return &invoice, nil
}

func (client *LightsparkClient) FailHtlc(invoiceId string, cancelInvoice bool) (*objects.FailHtlcsOutput, error) {
Expand Down

0 comments on commit 5a697dc

Please sign in to comment.