-
Notifications
You must be signed in to change notification settings - Fork 25
/
invoice.go
50 lines (44 loc) · 1.27 KB
/
invoice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package account
import (
"context"
"fmt"
"log"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/zpay32"
)
func (a *Service) generateInvoiceWithNewAmount(payReq string, newAmount int64) (string, []byte, error) {
invoice, err := zpay32.Decode(payReq, a.activeParams)
if err != nil {
return "", nil, fmt.Errorf("zpay32.Decode() error: %w", err)
}
signerClient := a.daemonAPI.SignerClient()
if signerClient == nil {
return "", nil, fmt.Errorf("API is not ready")
}
m := lnwire.MilliSatoshi(newAmount)
invoice.MilliSat = &m
signer := zpay32.MessageSigner{SignCompact: func(msg []byte) ([]byte, error) {
kl := signrpc.KeyLocator{
KeyFamily: int32(keychain.KeyFamilyNodeKey),
KeyIndex: 0,
}
r, err := signerClient.SignMessage(context.Background(),
&signrpc.SignMessageReq{
Msg: msg,
KeyLoc: &kl,
CompactSig: true,
DoubleHash: false,
})
if err != nil {
return nil, fmt.Errorf("m.client.SignMessage() error: %w", err)
}
return r.Signature, nil
}}
newInvoice, err := invoice.Encode(signer)
if err != nil {
log.Printf("invoice.Encode() error: %v", err)
}
return newInvoice, (*invoice.PaymentAddr)[:], err
}