2019-04-03 18:18:51 +00:00
|
|
|
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()
|
2019-04-03 18:18:51 +00:00
|
|
|
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()
|
2019-04-03 18:18:51 +00:00
|
|
|
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) {
|
2019-04-03 18:18:51 +00:00
|
|
|
|
|
|
|
ctxb := context.Background()
|
2019-04-03 22:12:03 +00:00
|
|
|
client, cleanUp := GetClient()
|
2019-04-03 18:18:51 +00:00
|
|
|
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()
|
2019-04-03 18:18:51 +00:00
|
|
|
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)
|
|
|
|
}
|