Skip to content

Commit

Permalink
cmd/tapcli: allow proof file or single proof on insert
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guggero committed Mar 25, 2024
1 parent 6494258 commit 674fb37
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions cmd/tapcli/universe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -539,28 +538,29 @@ func universeProofInsert(ctx *cli.Context) error {
client, cleanUp := getUniverseClient(ctx)
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)
}
// The server always expects the raw state transition proof, so
// depending on the input we get, we either need to extract the last
// state transition proof or can use it directly.
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{
Expand All @@ -569,7 +569,6 @@ func universeProofInsert(ctx *cli.Context) error {
LeafKey: assetKey,
},
AssetLeaf: &unirpc.AssetLeaf{
Asset: rpcAsset,
Proof: rawProof,
},
}
Expand Down

0 comments on commit 674fb37

Please sign in to comment.