Skip to content

Commit d3adc11

Browse files
committed
multi: add new UnpackProofFile RPC and cli counterpart
To allow RPC users to convert from a single proof file to individual raw proofs without needing to use Golang code, we create a new UnpackProofFile RPC method that just does the decode/parse. This will be useful to convert from a file as it can be exported by the ExportProof RPC to individual proofs that are required for importing into the universe InsertProof RPC.
1 parent 974a500 commit d3adc11

File tree

10 files changed

+990
-538
lines changed

10 files changed

+990
-538
lines changed

cmd/commands/proofs.go

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var proofCommands = []cli.Command{
2222
Subcommands: []cli.Command{
2323
verifyProofCommand,
2424
decodeProofCommand,
25+
unpackProofFileCommand,
2526
exportProofCommand,
2627
proveOwnershipCommand,
2728
verifyOwnershipCommand,
@@ -145,7 +146,56 @@ func decodeProof(ctx *cli.Context) error {
145146

146147
resp, err := client.DecodeProof(ctxc, req)
147148
if err != nil {
148-
return fmt.Errorf("unable to verify file: %w", err)
149+
return fmt.Errorf("unable to decode file: %w", err)
150+
}
151+
152+
printRespJSON(resp)
153+
return nil
154+
}
155+
156+
var unpackProofFileCommand = cli.Command{
157+
Name: "unpack",
158+
ShortName: "u",
159+
Usage: "unpack a Taproot Asset proof file into individual raw " +
160+
"proofs",
161+
Description: `
162+
Unpacks a taproot asset proof file that contains the full provenance of
163+
an asset into its individual raw proofs, in the order they appear in the
164+
proof file.
165+
`,
166+
Flags: []cli.Flag{
167+
cli.StringFlag{
168+
Name: proofPathName,
169+
Usage: "the path to the proof file on disk; use the " +
170+
"dash character (-) to read from stdin instead",
171+
},
172+
},
173+
Action: unpackProofFile,
174+
}
175+
176+
func unpackProofFile(ctx *cli.Context) error {
177+
ctxc := getContext()
178+
client, cleanUp := getClient(ctx)
179+
defer cleanUp()
180+
181+
if !ctx.IsSet(proofPathName) {
182+
_ = cli.ShowCommandHelp(ctx, "unpack")
183+
return nil
184+
}
185+
186+
filePath := lncfg.CleanAndExpandPath(ctx.String(proofPathName))
187+
rawFile, err := readFile(filePath)
188+
if err != nil {
189+
return fmt.Errorf("unable to read proof file: %w", err)
190+
}
191+
192+
resp, err := client.UnpackProofFile(
193+
ctxc, &taprpc.UnpackProofFileRequest{
194+
RawProofFile: rawFile,
195+
},
196+
)
197+
if err != nil {
198+
return fmt.Errorf("unable to unpack file: %w", err)
149199
}
150200

151201
printRespJSON(resp)

perms/perms.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ var (
6464
Entity: "proofs",
6565
Action: "read",
6666
}},
67+
"/taprpc.TaprootAssets/UnpackProofFile": {{
68+
Entity: "proofs",
69+
Action: "read",
70+
}},
6771
"/taprpc.TaprootAssets/ExportProof": {{
6872
Entity: "proofs",
6973
Action: "read",

rpcserver.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,32 @@ func (r *rpcServer) DecodeProof(ctx context.Context,
17171717
}, nil
17181718
}
17191719

1720+
// UnpackProofFile unpacks a proof file into a list of the individual raw
1721+
// proofs in the proof chain.
1722+
func (r *rpcServer) UnpackProofFile(_ context.Context,
1723+
req *taprpc.UnpackProofFileRequest) (*taprpc.UnpackProofFileResponse,
1724+
error) {
1725+
1726+
blob := proof.Blob(req.RawProofFile)
1727+
file, err := blob.AsFile()
1728+
if err != nil {
1729+
return nil, fmt.Errorf("unable to decode proof file: %w", err)
1730+
}
1731+
1732+
proofBlobs := make([][]byte, file.NumProofs())
1733+
for i := 0; i < file.NumProofs(); i++ {
1734+
proofBlobs[i], err = file.RawProofAt(uint32(i))
1735+
if err != nil {
1736+
return nil, fmt.Errorf("unable to extract proof: %w",
1737+
err)
1738+
}
1739+
}
1740+
1741+
return &taprpc.UnpackProofFileResponse{
1742+
RawProofs: proofBlobs,
1743+
}, nil
1744+
}
1745+
17201746
// marshalProof turns a transition proof into an RPC DecodedProof.
17211747
func (r *rpcServer) marshalProof(ctx context.Context, p *proof.Proof,
17221748
withPrevWitnesses, withMetaReveal bool) (*taprpc.DecodedProof, error) {

0 commit comments

Comments
 (0)