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.
bit4sat/lndrpc/commands.go

85 lines
1.4 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)
}