-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathprove.go
104 lines (88 loc) · 2.77 KB
/
prove.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package eth
import (
"fmt"
ks "github.com/FourthState/plasma-mvp-sidechain/client/store"
"github.com/FourthState/plasma-mvp-sidechain/plasma"
// "github.com/FourthState/plasma-mvp-sidechain/store"
// "github.com/cosmos/cosmos-sdk/client/context"
ethcmn "github.com/ethereum/go-ethereum/common"
// "github.com/ethereum/go-ethereum/rlp"
"github.com/spf13/cobra"
tm "github.com/tendermint/tendermint/rpc/core/types"
)
func ProveCmd() *cobra.Command {
return proveCmd
}
var proveCmd = &cobra.Command{
Use: "prove <account> <position>",
Short: "Prove transaction inclusion: prove <account> <position>",
Args: cobra.ExactArgs(2),
Long: "Returns proof for transaction inclusion. Use to exit transactions in the smart contract",
RunE: func(cmd *cobra.Command, args []string) error {
addr, err := ks.GetAccount(args[0])
if err != nil {
return fmt.Errorf("failed to retrieve account: { %s }", err)
}
// parse position
position, err := plasma.FromPositionString(args[1])
if err != nil {
return err
}
result, sigs, err := getProof(addr, position)
if err != nil {
return err
}
// print meta data
fmt.Printf("Roothash: 0x%x\n", result.Proof.RootHash)
fmt.Printf("Total: %d\n", result.Proof.Proof.Total)
fmt.Printf("LeafHash: 0x%x\n", result.Proof.Proof.LeafHash)
fmt.Printf("TxBytes: 0x%x\n", []byte(result.Tx))
switch len(sigs) {
case 65:
fmt.Printf("Confirmation Signatures: 0x%x\n", sigs[:])
case 130:
fmt.Printf("Confirmation Signatures: 0x%x, 0x%x\n", sigs[:65], sigs[65:])
}
// flatten aunts
var proof []byte
for _, aunt := range result.Proof.Proof.Aunts {
proof = append(proof, aunt...)
}
if len(proof) == 0 {
if result.Proof.Proof.Total == 1 {
fmt.Println("No proof required since this was the only transaction in the block")
} else {
fmt.Printf("Proof: nil\n")
}
} else {
fmt.Printf("Proof: 0x%x\n", proof)
}
return nil
},
}
// Returns transaction results for given position
// Trusts connected full node
//TODO: REDO
func getProof(addr ethcmn.Address, position plasma.Position) (*tm.ResultTx, []byte, error) {
/* ctx := context.NewCLIContext().WithTrustNode(true)
// query for the output
key := append(store.Key, position.Bytes()...)
res, err := ctx.QueryStore(key, "outputs")
if err != nil {
return &tm.ResultTx{}, nil, err
}
utxo := store.Output{}
if err := rlp.DecodeBytes(res, &utxo); err != nil {
return &tm.ResultTx{}, nil, err
}
// query tm node for information about this tx
result, err := ctx.Client.Tx(utxo.MerkleHash, true)
if err != nil {
return &tm.ResultTx{}, nil, err
}
// Look for confirmation signatures
key = append([]byte("confirmSignature"), utxo.Position.Bytes()...)
sigs, err := ctx.QueryStore(key, "plasma")
*/
return &tm.ResultTx{}, []byte{}, nil
}