You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
1.8 KiB
Go
100 lines
1.8 KiB
Go
package lndrpc
|
|
|
|
import (
|
|
"log"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
lnrpc "github.com/lightningnetwork/lnd/lnrpc"
|
|
)
|
|
|
|
func GetInfo() error {
|
|
log.Println("get info")
|
|
ctxb := context.Background()
|
|
client, cleanUp := getClient()
|
|
defer cleanUp()
|
|
|
|
req := &lnrpc.GetInfoRequest{}
|
|
resp, err := client.GetInfo(ctxb, req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Println(resp)
|
|
|
|
return nil
|
|
}
|
|
|
|
func lookupInvoiceRhash(rhash []byte) (*lnrpc.Invoice, error) {
|
|
ctxb := context.Background()
|
|
client, cleanUp := getClient()
|
|
defer cleanUp()
|
|
|
|
req := &lnrpc.PaymentHash{
|
|
RHash: rhash,
|
|
}
|
|
|
|
// Get back the invoice
|
|
createdInvoice, err := client.LookupInvoice(ctxb, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return createdInvoice, nil
|
|
}
|
|
|
|
func lookupInvoiceRhashStr(rhash string) (*lnrpc.Invoice, error) {
|
|
|
|
ctxb := context.Background()
|
|
client, cleanUp := getClient()
|
|
defer cleanUp()
|
|
|
|
req := &lnrpc.PaymentHash{
|
|
RHashStr: rhash,
|
|
}
|
|
|
|
// Get back the invoice
|
|
createdInvoice, err := client.LookupInvoice(ctxb, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return createdInvoice, nil
|
|
|
|
}
|
|
|
|
func AddInvoiceSat(desc string, satVal int64) (*lnrpc.Invoice, error) {
|
|
ctxb := context.Background()
|
|
client, cleanUp := getClient()
|
|
defer cleanUp()
|
|
|
|
invoice := &lnrpc.Invoice{
|
|
Memo: desc,
|
|
|
|
// Value in satoshis
|
|
Value: satVal,
|
|
}
|
|
|
|
resp, err := client.AddInvoice(ctxb, invoice)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return lookupInvoiceRhash(resp.RHash)
|
|
}
|
|
|
|
// Blocks until the invoice is paid or expired
|
|
func WatchInvoice(addIndex uint64) (*lnrpc.Invoice, error) {
|
|
ctxb := context.Background()
|
|
client, cleanUp := getClient()
|
|
defer cleanUp()
|
|
|
|
subscription := &lnrpc.InvoiceSubscription{}
|
|
|
|
subscriptionClient, err := client.SubscribeInvoices(ctxb, subscription)
|
|
if err != nil {
|
|
//return nil, err
|
|
}
|
|
|
|
}
|