From 44136402458cddd96738f1c2c51879e5683c174c Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 25 Mar 2024 15:03:49 +0100 Subject: [PATCH] cmd/tapcli: allow proof file or single proof on insert In order to be able to directly import a proof leaf that was previously exported with `tapcli universe leaves` directly into the universe, we allow the proof to either be a proof file or a single transition proof. --- cmd/tapcli/universe.go | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/cmd/tapcli/universe.go b/cmd/tapcli/universe.go index 6c933a138..1c349e8a0 100644 --- a/cmd/tapcli/universe.go +++ b/cmd/tapcli/universe.go @@ -9,7 +9,6 @@ import ( tap "github.com/lightninglabs/taproot-assets" "github.com/lightninglabs/taproot-assets/fn" "github.com/lightninglabs/taproot-assets/proof" - "github.com/lightninglabs/taproot-assets/taprpc" unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc" "github.com/lightninglabs/taproot-assets/universe" "github.com/lightningnetwork/lnd/lncfg" @@ -540,27 +539,28 @@ func universeProofInsert(ctx *cli.Context) error { defer cleanUp() // The input should be the raw state transition proof, so we'll - // partially parse the proof so we can hand the raw proof bytes - // (without the checksum) to the server. - var proofFile proof.File - if err := proofFile.Decode(bytes.NewReader(rawFile)); err != nil { - return fmt.Errorf("unable to decode proof file: %w", err) - } + // partially parse the proof, so we can hand the raw proof bytes + // (without the checksum) to the server, depending on the input we get. + var rawProof []byte + switch { + case proof.IsProofFile(rawFile): + var proofFile proof.File + err := proofFile.Decode(bytes.NewReader(rawFile)) + if err != nil { + return fmt.Errorf("unable to decode proof file: %w", + err) + } - assetProof, err := proofFile.LastProof() - if err != nil { - return err - } - rpcAsset, err := taprpc.MarshalAsset( - ctxc, &assetProof.Asset, false, true, nil, - ) - if err != nil { - return err - } + rawProof, err = proofFile.RawLastProof() + if err != nil { + return err + } - rawProof, err := proofFile.RawLastProof() - if err != nil { - return err + case proof.IsSingleProof(rawFile): + rawProof = rawFile + + default: + return fmt.Errorf("invalid proof file format") } req := &unirpc.AssetProof{ @@ -569,7 +569,6 @@ func universeProofInsert(ctx *cli.Context) error { LeafKey: assetKey, }, AssetLeaf: &unirpc.AssetLeaf{ - Asset: rpcAsset, Proof: rawProof, }, }