Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions cmd/litcli/ln.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ var addInvoiceCommand = cli.Command{
Taproot Assets.
`,
ArgsUsage: "[--asset_id=X | --group_key=X] --asset_amount=Y " +
"[--rfq_peer_pubkey=Z] ",
"[--rfq_peer_pubkey=Z] [--price_oracle_metadata=...]",
Flags: append(
commands.AddInvoiceCommand.Flags,
cli.StringFlag{
Expand All @@ -726,6 +726,12 @@ var addInvoiceCommand = cli.Command{
"are multiple channels with the same " +
"asset ID present",
},
cli.StringFlag{
Name: "price_oracle_metadata",
Usage: "(optional) opaque metadata forwarded to the " +
"price oracle when creating the invoice; JSON " +
"is recommended. Maximum length is 32768 bytes",
},
),
Action: addInvoice,
}
Expand Down Expand Up @@ -789,7 +795,7 @@ func addInvoice(cli *cli.Context) error {
defer cleanup()

channelsClient := tchrpc.NewTaprootAssetChannelsClient(tapdConn)
resp, err := channelsClient.AddInvoice(ctx, &tchrpc.AddInvoiceRequest{
addReq := &tchrpc.AddInvoiceRequest{
AssetId: assetIDBytes,
GroupKey: groupKeyBytes,
AssetAmount: assetAmount,
Expand All @@ -805,7 +811,16 @@ func addInvoice(cli *cli.Context) error {
Private: cli.Bool("private"),
IsAmp: cli.Bool("amp"),
},
})
}
if cli.IsSet("price_oracle_metadata") {
metadata := cli.String("price_oracle_metadata")
if err := ValidatePriceOracleMetadata(metadata); err != nil {
return err
}
addReq.PriceOracleMetadata = metadata
}

resp, err := channelsClient.AddInvoice(ctx, addReq)
if err != nil {
return fmt.Errorf("error adding invoice: %w", err)
}
Expand Down
16 changes: 16 additions & 0 deletions cmd/litcli/price_oracle_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import "fmt"

const maxPriceOracleMetadataBytes = 32768

// ValidatePriceOracleMetadata checks that metadata for AddInvoice stays within
// tapd's documented maximum size.
func ValidatePriceOracleMetadata(s string) error {
if len(s) > maxPriceOracleMetadataBytes {
return fmt.Errorf("price_oracle_metadata exceeds maximum length "+
"of %d bytes (got %d)", maxPriceOracleMetadataBytes, len(s))
}

return nil
}
47 changes: 47 additions & 0 deletions cmd/litcli/price_oracle_metadata_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"strings"
"testing"
)

func TestValidatePriceOracleMetadata(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input string
wantErr bool
}{
{
name: "empty",
input: "",
wantErr: false,
},
{
name: "at limit",
input: strings.Repeat("a", maxPriceOracleMetadataBytes),
wantErr: false,
},
{
name: "over limit",
input: strings.Repeat("a", maxPriceOracleMetadataBytes+1),
wantErr: true,
},
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

err := ValidatePriceOracleMetadata(tc.input)
if tc.wantErr && err == nil {
t.Fatal("expected error")
}
if !tc.wantErr && err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
}
}
2 changes: 2 additions & 0 deletions itest/assertions.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dev

package itest

import (
Expand Down
2 changes: 2 additions & 0 deletions itest/litd_accounts_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dev

package itest

import (
Expand Down
2 changes: 2 additions & 0 deletions itest/litd_firewall_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dev

package itest

import (
Expand Down
2 changes: 2 additions & 0 deletions itest/litd_mode_integrated_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dev

package itest

import (
Expand Down
2 changes: 2 additions & 0 deletions itest/litd_mode_remote_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dev

package itest

import (
Expand Down
2 changes: 2 additions & 0 deletions itest/litd_node.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dev

package itest

import (
Expand Down
2 changes: 2 additions & 0 deletions itest/litd_stateless_init_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dev

package itest

import (
Expand Down
2 changes: 2 additions & 0 deletions itest/litd_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dev

package itest

import (
Expand Down
2 changes: 1 addition & 1 deletion itest/litd_test_list_off_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !itest
//go:build dev && !itest

package itest

Expand Down
2 changes: 1 addition & 1 deletion itest/litd_test_list_on_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build itest
//go:build dev && itest

package itest

Expand Down
2 changes: 2 additions & 0 deletions itest/log.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dev

package itest

import (
Expand Down
2 changes: 2 additions & 0 deletions itest/network_harness.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dev

package itest

import (
Expand Down
2 changes: 2 additions & 0 deletions itest/server_harness.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dev

package itest

import (
Expand Down
2 changes: 2 additions & 0 deletions itest/test_harness.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build dev

package itest

import (
Expand Down
25 changes: 4 additions & 21 deletions perms/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package perms
import (
"net"

"github.com/lightningnetwork/lnd/autopilot"
"github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/autopilotrpc"
"github.com/lightningnetwork/lnd/lnrpc/chainrpc"
Expand All @@ -19,9 +17,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
"github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/routing"
"github.com/lightningnetwork/lnd/sweep"
)

// mockConfig implements lnrpc.SubServerConfigDispatcher. It provides the
Expand Down Expand Up @@ -50,14 +46,9 @@ func (t *mockConfig) FetchConfig(subServerName string) (interface{}, bool) {
},
}, true
case "AutopilotRPC":
return &autopilotrpc.Config{
Manager: &autopilot.Manager{},
}, true
return &autopilotrpc.Config{}, true
case "ChainRPC":
return &chainrpc.Config{
ChainNotifier: &chainreg.NoChainBackend{},
Chain: &mock.ChainIO{},
}, true
return &chainrpc.Config{}, true
case "DevRPC":
return &devrpc.Config{}, true
case "NeutrinoKitRPC":
Expand All @@ -69,17 +60,9 @@ func (t *mockConfig) FetchConfig(subServerName string) (interface{}, bool) {
Router: &routing.ChannelRouter{},
}, true
case "SignRPC":
return &signrpc.Config{
Signer: &mock.DummySigner{},
}, true
return &signrpc.Config{}, true
case "WalletKitRPC":
return &walletrpc.Config{
FeeEstimator: &chainreg.NoChainBackend{},
Wallet: &mock.WalletController{},
KeyRing: &mock.SecretKeyRing{},
Sweeper: &sweep.UtxoSweeper{},
Chain: &mock.ChainIO{},
}, true
return &walletrpc.Config{}, true
case "WatchtowerRPC":
return &watchtowerrpc.Config{}, true
default:
Expand Down