Skip to content

Commit

Permalink
Getting started
Browse files Browse the repository at this point in the history
  • Loading branch information
habibitcoin committed Oct 25, 2022
1 parent 314ecd7 commit dbd8496
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 0 deletions.
43 changes: 43 additions & 0 deletions cmd/tarocli/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 Down Expand Up @@ -72,6 +73,48 @@ func verifyProof(ctx *cli.Context) error {
return nil
}

var decodeProofCommand = cli.Command{
Name: "decode",
ShortName: "d",
Description: "decode a taro 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",
},
},
Action: decodeProof,
}

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

switch {
case ctx.String(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)
}

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

printRespJSON(resp)
return nil
}

const (
scriptKeyName = "script_key"
)
Expand Down
1 change: 1 addition & 0 deletions proof.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0000000002fd03f9002448111086af28efe79c757029b5702c3382fc8971946895e6a695a1319c3d3c2400000001015000e0ff3f36ada3dd0409af3eb4227f417de98c1bd1091c1f725c68600e2281a200000000015edd15c5e8b46926bab35c5594cd164af822b288a820f40f97fb79ff59c86c64263e6301943319d5538f0802fd01020200000000010148111086af28efe79c757029b5702c3382fc8971946895e6a695a1319c3d3c2401000000171600147b0b78901f72a592e5537cb366d3009f4ef4fc14ffffffff02e803000000000000225120394407310a673dd8fda9becbd374e5a7c6c75038a7edea0c98b7e48b6eef76b33c6601000000000016001486bb211c75393f108d32302bbd1103165a70bfa102483045022100f182e3384e46cbd15deee2ce4b240146f5b68bf1f9be108650da43c8c479f2fe02202051e662439bb9af6e39a2f1fdb45481b670c81a4fe2613df53e996ea28c9ff001210320e58e2d618859c06d9ce7f32ffc17259875483c9168ca0b69cf72cb6caaabf80000000003fd01020870f584d7a613b4bff12631b7893c8d3b7f906675f74d4c48f110feff99f9be8864722bce1f907cce6f7c4405ecac9e4820a11aecd4a05307381b3e19c85064d851099d770fa3c6647b604822fe6daa215da0e9aad2b56255cda0bb09147adb12d2a97f4257c7aa55235cb1b9dd059cfc8d1c2c31e1b96667609ab7efc39259c11d044ab661f816f8471ee3322ae6c75afc7190a24de391884d0127bc0b26f8f457567daadfa19a1b5ba59dfae828a00a38b21f2ee46649280100914ad94aa7c7e2ed40ae21b524d6c6e5f53c640bfdf90c6714b54a5be358ed5a72f1c574868df2a83313fd2caa57b39749b30b39c03e8b72e469897e3057312143b154a8682dfb04d3000100013848111086af28efe79c757029b5702c3382fc8971946895e6a695a1319c3d3c24000000010d68616269626974636f696e333100000000000002010003016406680166006400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080200000920ebdba03c3fa7b632ab74a616576a1857f7f248cfafba5f68351080b7ec57ae83059e00040000000001203066ca6db1524b1abaa467d88a688a1ae8fe9d91bee4286624e116a857b09ee4027400490001000120053213305c845d9c165d879b07a06086229602571144a2540cc30a820a935b9f02220000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff012700010001220000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff395c50d3745ec037bd96c4f63d2f3b51d206513f04c7d3cfdb88c46b0fbad613fd056f00243b5bb4093b1ff043b880994a0a591dc562b8ee4fe9dc9eee52fb397b4b8b3a880000000001500000602007f98b39f776c480b0c16e3b22e76034cdf0f1175c16bab979d4e2e300000000aacebca571e710eb10571d3b8472862b6a1afbfda4f289f35e27cfb91a3fed97fc0b3f63019433193bc8892e02fd018002000000000102243db7ffd73780a0e90ea135eb8007e4956b9aaebf23f991c4d548ba9d065f280200000000ffffffff3b5bb4093b1ff043b880994a0a591dc562b8ee4fe9dc9eee52fb397b4b8b3a8800000000000000000003e80300000000000022512054a6d051500eaaa53282547ca92d7455cf434c4691789e8f23ef51f988a606fce803000000000000225120ac2807b5865be44065aadafc8d5321138adb9fba472f25f7cdee25bb2c2222f2e658070000000000160014397c45c35699368398cc840a1ac6cf792c1139d70247304402200422761b4e1823a30d068f4f03ec1c233f5511e283680bca1464d7d1b4eb5e25022008686a31635d51ff797d517fbcccbdb81200377f1c81252a86fa2edb12bafd6501210333a2ae8d01f17759e9af10879655d669d2b4faf6cd968c1cb4708277c8227af20140b899e5158657f6c90a0f9bc1120d8995bb1b3898f57c005388070faa2735706bcdfd953507a9b1b07b1d5ec82147cdecdd5bf34d85f360bdb29bd835194a0e2a0000000003c20687dc02a1a3d973a9a898106118d76da362ff4cabf2b988bd3088ccccd0f649281aa6a11f02cd0487c3a72f228cbbc28259311dcf5a1ff17432c06eec84a049e897cf970a67b2cf497ff00c794fda8bca6ce2b60fd5428f45470b8c284c15a5ab884b468f4805ee9ad55d964b0ca7ad69ff729cfeb03ca74dba1af703ad72fc32a1495de6823e6bc03043e95d015ee04366624c3f01d6038f138976756a1ad1ae4d28f72bde5c2f93df7682d3446ec0736c455505b19475059943ed3c977e2bca3804fd0141000100013848111086af28efe79c757029b5702c3382fc8971946895e6a695a1319c3d3c24000000010d68616269626974636f696e333100000000000002010003016306ac01aa00643b5bb4093b1ff043b880994a0a591dc562b8ee4fe9dc9eee52fb397b4b8b3a8800000000053213305c845d9c165d879b07a06086229602571144a2540cc30a820a935b9febdba03c3fa7b632ab74a616576a1857f7f248cfafba5f68351080b7ec57ae8301420140b4a04d1e5055e49f2a2c0000d441c46330e5c739a2f7b210abdee46de4f47f15395bbea087bfcef59559cf74a1ec0c51ba0a1a462d66a342df01572af7751c620728af1826b300ba2e9db2893d8f076059b7615667732d03f138e7a7a997f82294b80000000000000064080200000920c6d6013c205194f1eba1ab672f6a74f8b90f226070c0500fee65d02013414941059e0004000000000120aa4cbafa680197d1c18c2273eee8170a109c1c5fc7ef6e376a0cfcd754e26b22027400490001000120053213305c845d9c165d879b07a06086229602571144a2540cc30a820a935b9f02220000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff012700010001220000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff06c801c60004000000010120da415d4d671cc4312ea0e729b5a40197980fe039bee46db98a70b62ee9cf1650029c00710001000120053213305c845d9c165d879b07a06086229602571144a2540cc30a820a935b9f024a0001af9f80873c8f2d4df3991a20c5f72740c3d5fdbbef5ed23aa2867cb948ff4b750000000000000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdf012700010001220000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff52d709b716147d330977b83d8432e8409a213fe3aeeed99c3f9ada950e46bf62
29 changes: 29 additions & 0 deletions proof/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
log2 "log"
"runtime"
"sync"

Expand All @@ -13,6 +14,7 @@ import (
"github.com/lightninglabs/taro/asset"
"github.com/lightninglabs/taro/commitment"
"github.com/lightninglabs/taro/vm"
"github.com/lightningnetwork/lnd/tlv"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -342,3 +344,30 @@ func (f *File) Verify(ctx context.Context) (*AssetSnapshot, error) {

return prev, nil
}

func (f *File) ProofBytes(ctx context.Context) (proofBytes []tlv.Record, err error) {
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}

for idx := range f.proofs {
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}

decodedProof, err := f.ProofAt(uint32(idx))
if err != nil {
return nil, err
}

log2.Println(decodedProof)

proofBytes = append(proofBytes, decodedProof.DecodeRecords()[0])
}

return proofBytes, nil
}
Binary file added proof_2.json
Binary file not shown.
34 changes: 34 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/hex"
"fmt"
"log"
"net/http"
"strings"
"sync"
Expand Down Expand Up @@ -84,6 +85,10 @@ var (
Entity: "proofs",
Action: "read",
}},
"/tarorpc.Taro/DecodeProof": {{
Entity: "proofs",
Action: "read",
}},
"/tarorpc.Taro/ExportProof": {{
Entity: "proofs",
Action: "read",
Expand Down Expand Up @@ -708,6 +713,35 @@ func (r *rpcServer) VerifyProof(ctx context.Context,
}, nil
}

// DecodeProof attempts to decode a given proof file that claims to be anchored
// at the specified genesis point.
func (r *rpcServer) DecodeProof(ctx context.Context,
in *tarorpc.ProofFile) (*tarorpc.ProofFile, error) {

if len(in.RawProof) == 0 {
return nil, fmt.Errorf("proof file must be specified")
}

var proofFile proof.File
err := proofFile.Decode(bytes.NewReader(in.RawProof))
if err != nil {
return nil, fmt.Errorf("unable to decode proof file: %w", err)
}

select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}

proofBytes, err := proofFile.ProofBytes(ctx)
log.Println(proofBytes)

return &tarorpc.ProofFile{
TVLRecords: "text",
}, nil
}

// ExportProof exports the latest raw proof file anchored at the specified
// script_key.
func (r *rpcServer) ExportProof(ctx context.Context,
Expand Down
1 change: 1 addition & 0 deletions tarorpc/taro.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions tarorpc/taro.pb.json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tarorpc/taro.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ http:
post: "/v1/taro/proofs/verify"
body: "*"

- selector: tarorpc.Taro.DecodeProof
post: "/v1/taro/proofs/decode"
body: "*"

- selector: tarorpc.Taro.ExportProof
post: "/v1/taro/proofs/export"
body: "*"
Expand Down
36 changes: 36 additions & 0 deletions tarorpc/taro_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dbd8496

Please sign in to comment.