Skip to content

Commit

Permalink
Rewrite fail htlcs mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenlu authored May 4, 2024
1 parent 650b5a6 commit d46980c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
12 changes: 9 additions & 3 deletions scripts/fail_htlcs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package scripts

import "github.com/lightsparkdev/go-sdk/objects"

const FAIL_HTLCS_MUTATION = `
mutation FailHtlcs($invoice_id: ID!) {
fail_htlcs(input: { invoice_id: $invoice_id })
}`
mutation FailHtlcs($invoice_id: ID!, $cancel_invoice: Boolean!) {
fail_htlcs(input: { invoice_id: $invoice_id, cancel_invoice: $cancel_invoice}) {
...FailHtlcsOutputFragment
}
}
` + objects.FailHtlcsOutputFragment
20 changes: 16 additions & 4 deletions services/lightspark_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,16 +1058,28 @@ func (client *LightsparkClient) FetchIncomingPaymentsByInvoice(invoiceId string,
return &payments, nil
}

func (client *LightsparkClient) FailHtlc(invoiceId string) (error) {
func (client *LightsparkClient) FailHtlc(invoiceId string, cancelInvoice bool) (*objects.FailHtlcsOutput, error) {
variables := map[string]interface{}{
"invoice_id": invoiceId,
"cancel_invoice": cancelInvoice,
}

_, err := client.Requester.ExecuteGraphql(scripts.FAIL_HTLCS_MUTATION, variables, nil)
response, err := client.Requester.ExecuteGraphql(scripts.FAIL_HTLCS_MUTATION, variables, nil)
if err != nil {
return err
return nil, err
}

output := response["fail_htlcs"].(map[string]interface{})
var failHtlcs objects.FailHtlcsOutput
failHtlcsJson, err := json.Marshal(output)
if err != nil {
return nil, errors.New("error parsing fail htlcs")
}
err = json.Unmarshal(failHtlcsJson, &failHtlcs)
if err != nil {
return nil, err
}
return nil
return &failHtlcs, nil
}

func hashPhoneNumber(e614PhoneNumber string) (*string, error) {
Expand Down

0 comments on commit d46980c

Please sign in to comment.