bit4sat/lndrpc/commands.go

85 lines
1.4 KiB
Go
Raw Permalink Normal View History

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()
2019-04-03 22:12:03 +00:00
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()
2019-04-03 22:12:03 +00:00
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
}
2019-04-03 22:12:03 +00:00
func LookupInvoiceRhashStr(rhash string) (*lnrpc.Invoice, error) {
ctxb := context.Background()
2019-04-03 22:12:03 +00:00
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()
2019-04-03 22:12:03 +00:00
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)
}