Skip to content

Commit

Permalink
tapcli: implement proof decode command
Browse files Browse the repository at this point in the history
  • Loading branch information
habibitcoin committed May 28, 2023
1 parent 8c4fe73 commit 409e7ce
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions cmd/tapcli/proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var proofCommands = []cli.Command{
Category: "Proofs",
Subcommands: []cli.Command{
verifyProofCommand,
decodeProofCommand,
exportProofCommand,
importProofCommand,
},
Expand All @@ -28,6 +29,9 @@ var proofCommands = []cli.Command{

const (
proofPathName = "proof_file"

proofAtDepthName = "proof_at_depth"
withPrevWitnessesName = "latest_proof"
)

var verifyProofCommand = cli.Command{
Expand Down Expand Up @@ -71,6 +75,62 @@ func verifyProof(ctx *cli.Context) error {
return nil
}

var decodeProofCommand = cli.Command{
Name: "decode",
ShortName: "d",
Description: "decode a Taproot Asset proof",
Flags: []cli.Flag{
cli.StringFlag{
Name: proofPathName,
Usage: "the path to the proof file on disk; use the " +
"dash character (-) to read from stdin instead",
},
cli.Int64Flag{
Name: proofAtDepthName,
Value: 0,
Usage: "the index depth of the decoded proof to fetch " +
"with 0 being the latest proof",
},
cli.BoolFlag{
Name: withPrevWitnessesName,
Usage: "if true, previous witnesses will be returned",
},
},
Action: decodeProof,
}

func decodeProof(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()

switch {
case !ctx.IsSet(proofPathName):
_ = cli.ShowCommandHelp(ctx, "decode")
return nil
}

filePath := lncfg.CleanAndExpandPath(ctx.String(proofPathName))
rawFile, err := readFile(filePath)
if err != nil {
return fmt.Errorf("unable to read proof file: %w", err)
}

req := &taprpc.DecodeProofRequest{
RawProof: rawFile,
ProofAtDepth: ctx.Int64(proofAtDepthName),
WithPrevWitnesses: ctx.Bool(withPrevWitnessesName),
}

resp, err := client.DecodeProof(ctxc, req)
if err != nil {
return fmt.Errorf("unable to verify file: %w", err)
}

printRespJSON(resp)
return nil
}

const (
scriptKeyName = "script_key"
)
Expand Down

0 comments on commit 409e7ce

Please sign in to comment.