Skip to content

Commit c7416c7

Browse files
committed
ls client + make use of in remote signing server
1 parent cfc3874 commit c7416c7

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

examples/remote-signing-server/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/lightsparkdev/go-sdk/webhooks"
1313
)
1414

15+
const hardcodedPreimage = "00000000000000000000000000000000000000000000000000000000deadbeef"
16+
1517
/**
1618
* This is a simple Gin server (https://gin-gonic.com) that implements a simple remote-signer using
1719
* the Lightspark SDK.
@@ -103,6 +105,8 @@ func main() {
103105

104106
c.Status(http.StatusNoContent)
105107
}
108+
case objects.WebhookEventTypeHoldInvoiceAccepted:
109+
lsClient.ReleasePaymentPreimage(event.EntityId, hardcodedPreimage)
106110
default:
107111
c.Status(http.StatusNoContent)
108112
}

objects/webhook_event_type.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const (
4040
WebhookEventTypeHighBalance
4141

4242
WebhookEventTypeChannelOpeningFees
43+
44+
WebhookEventTypeHoldInvoiceAccepted
4345
)
4446

4547
func (a *WebhookEventType) UnmarshalJSON(b []byte) error {
@@ -80,6 +82,8 @@ func (a *WebhookEventType) UnmarshalJSON(b []byte) error {
8082
*a = WebhookEventTypeHighBalance
8183
case "CHANNEL_OPENING_FEES":
8284
*a = WebhookEventTypeChannelOpeningFees
85+
case "HOLD_INVOICE_ACCEPTED":
86+
*a = WebhookEventTypeHoldInvoiceAccepted
8387

8488
}
8589
return nil
@@ -120,6 +124,8 @@ func (a WebhookEventType) StringValue() string {
120124
s = "HIGH_BALANCE"
121125
case WebhookEventTypeChannelOpeningFees:
122126
s = "CHANNEL_OPENING_FEES"
127+
case WebhookEventTypeHoldInvoiceAccepted:
128+
s = "HOLD_INVOICE_ACCEPTED"
123129

124130
}
125131
return s

services/lightspark_client.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,25 @@ func (client *LightsparkClient) PayOffer(nodeId string, encodedOffer string, tim
815815
return &payment, nil
816816
}
817817

818+
func (client *LightsparkClient) ReleasePaymentPreimage(invoiceId string, paymentPreimage string) (*objects.ReleasePaymentPreimageOutput, error) {
819+
variables := map[string]interface{}{
820+
"invoice_id": invoiceId,
821+
"payment_preimage": paymentPreimage,
822+
}
823+
824+
response, err := client.ExecuteGraphql(scripts.RELEASE_PAYMENT_PREIMAGE_MUTATION, variables, nil)
825+
if err != nil {
826+
return nil, err
827+
}
828+
outputJson, err := json.Marshal(response["release_payment_preimage"].(map[string]interface{}))
829+
if err != nil {
830+
return nil, errors.New("error parsing response")
831+
}
832+
var output objects.ReleasePaymentPreimageOutput
833+
json.Unmarshal(outputJson, &output)
834+
return &output, nil
835+
}
836+
818837
// RequestWithdrawal withdraws funds from the account and sends it to the requested
819838
// bitcoin address. Depending on the chosen mode, it will first take the funds from
820839
// the wallet, and if applicable, close channels appropriately to recover enough

0 commit comments

Comments
 (0)