From 72a89520d4372036472239b36e2db2e7871ef0ad Mon Sep 17 00:00:00 2001 From: ffranr Date: Wed, 14 Jun 2023 13:52:06 +0100 Subject: [PATCH 1/2] walletrpc: export unmarshall lnrpc.OutPoint functionality --- lnrpc/walletrpc/walletkit_server.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index 9b6974fd7..36a48a5aa 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -464,7 +464,7 @@ func (w *WalletKit) LeaseOutput(ctx context.Context, return nil, errors.New("reserved id cannot be used") } - op, err := unmarshallOutPoint(req.Outpoint) + op, err := UnmarshallOutPoint(req.Outpoint) if err != nil { return nil, err } @@ -505,7 +505,7 @@ func (w *WalletKit) ReleaseOutput(ctx context.Context, var lockID wtxmgr.LockID copy(lockID[:], req.Id) - op, err := unmarshallOutPoint(req.Outpoint) + op, err := UnmarshallOutPoint(req.Outpoint) if err != nil { return nil, err } @@ -807,9 +807,9 @@ func (w *WalletKit) PendingSweeps(ctx context.Context, }, nil } -// unmarshallOutPoint converts an outpoint from its lnrpc type to its canonical +// UnmarshallOutPoint converts an outpoint from its lnrpc type to its canonical // type. -func unmarshallOutPoint(op *lnrpc.OutPoint) (*wire.OutPoint, error) { +func UnmarshallOutPoint(op *lnrpc.OutPoint) (*wire.OutPoint, error) { if op == nil { return nil, fmt.Errorf("empty outpoint provided") } @@ -851,7 +851,7 @@ func (w *WalletKit) BumpFee(ctx context.Context, in *BumpFeeRequest) (*BumpFeeResponse, error) { // Parse the outpoint from the request. - op, err := unmarshallOutPoint(in.Outpoint) + op, err := UnmarshallOutPoint(in.Outpoint) if err != nil { return nil, err } @@ -1125,7 +1125,7 @@ func (w *WalletKit) FundPsbt(_ context.Context, txIn := make([]*wire.OutPoint, len(tpl.Inputs)) for idx, in := range tpl.Inputs { - op, err := unmarshallOutPoint(in) + op, err := UnmarshallOutPoint(in) if err != nil { return nil, fmt.Errorf("error parsing "+ "outpoint: %v", err) From 51e2da6fbc47061bdb87e32d94d44f4ccbc952ae Mon Sep 17 00:00:00 2001 From: ffranr Date: Wed, 14 Jun 2023 14:07:04 +0100 Subject: [PATCH 2/2] walletrpc: allow both txid fields populated during OutPoint unmarshall --- lnrpc/walletrpc/walletkit_server.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index 36a48a5aa..9fff649ee 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -816,12 +816,10 @@ func UnmarshallOutPoint(op *lnrpc.OutPoint) (*wire.OutPoint, error) { var hash chainhash.Hash switch { + // Return an error if both txid fields are unpopulated. case len(op.TxidBytes) == 0 && len(op.TxidStr) == 0: - fallthrough - - case len(op.TxidBytes) != 0 && len(op.TxidStr) != 0: - return nil, fmt.Errorf("either TxidBytes or TxidStr must be " + - "specified, but not both") + return nil, fmt.Errorf("TxidBytes and TxidStr are both " + + "unspecified") // The hash was provided as raw bytes. case len(op.TxidBytes) != 0: