Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions examples/remote-signing-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/lightsparkdev/go-sdk/webhooks"
)

const hardcodedPreimage = "00000000000000000000000000000000000000000000000000000000deadbeef"

/**
* This is a simple Gin server (https://gin-gonic.com) that implements a simple remote-signer using
* the Lightspark SDK.
Expand Down Expand Up @@ -101,6 +103,18 @@ func main() {
log.Printf("Webhook complete")
}

c.Status(http.StatusNoContent)
}
case objects.WebhookEventTypeHoldInvoiceAccepted:
resp, err := lsClient.ReleasePaymentPreimage(event.EntityId, hardcodedPreimage)
if err != nil {
log.Printf("ERROR: Unable to handle remote signing webhook: %s", err)
c.AbortWithStatus(http.StatusInternalServerError)
return
}
if resp != nil {
c.JSON(http.StatusOK, resp.Invoice)
} else {
c.Status(http.StatusNoContent)
}
default:
Expand Down
6 changes: 6 additions & 0 deletions objects/webhook_event_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const (
WebhookEventTypeHighBalance

WebhookEventTypeChannelOpeningFees

WebhookEventTypeHoldInvoiceAccepted
)

func (a *WebhookEventType) UnmarshalJSON(b []byte) error {
Expand Down Expand Up @@ -80,6 +82,8 @@ func (a *WebhookEventType) UnmarshalJSON(b []byte) error {
*a = WebhookEventTypeHighBalance
case "CHANNEL_OPENING_FEES":
*a = WebhookEventTypeChannelOpeningFees
case "HOLD_INVOICE_ACCEPTED":
*a = WebhookEventTypeHoldInvoiceAccepted

}
return nil
Expand Down Expand Up @@ -120,6 +124,8 @@ func (a WebhookEventType) StringValue() string {
s = "HIGH_BALANCE"
case WebhookEventTypeChannelOpeningFees:
s = "CHANNEL_OPENING_FEES"
case WebhookEventTypeHoldInvoiceAccepted:
s = "HOLD_INVOICE_ACCEPTED"

}
return s
Expand Down
19 changes: 19 additions & 0 deletions services/lightspark_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,25 @@ func (client *LightsparkClient) PayOffer(nodeId string, encodedOffer string, tim
return &payment, nil
}

func (client *LightsparkClient) ReleasePaymentPreimage(invoiceId string, paymentPreimage string) (*objects.ReleasePaymentPreimageOutput, error) {
variables := map[string]interface{}{
"invoice_id": invoiceId,
"payment_preimage": paymentPreimage,
}

response, err := client.ExecuteGraphql(scripts.RELEASE_PAYMENT_PREIMAGE_MUTATION, variables, nil)
if err != nil {
return nil, err
}
outputJson, err := json.Marshal(response["release_payment_preimage"].(map[string]interface{}))
if err != nil {
return nil, errors.New("error parsing response")
}
var output objects.ReleasePaymentPreimageOutput
json.Unmarshal(outputJson, &output)
return &output, nil
}

// RequestWithdrawal withdraws funds from the account and sends it to the requested
// bitcoin address. Depending on the chosen mode, it will first take the funds from
// the wallet, and if applicable, close channels appropriately to recover enough
Expand Down