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 4413640
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 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 @@ -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{
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 4413640

Please sign in to comment.