Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plasmacli confirmsig query #185

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"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"
"math/big"
)

Expand Down Expand Up @@ -154,3 +155,48 @@ func Blocks(ctx context.CLIContext, startingHeight *big.Int) ([]store.Block, err

return blocks, nil
}

// Returns confirm sig results for given position
// Trusts connected full node
func Signatures(ctx context.CLIContext, position plasma.Position) ([]byte, error) {
wesgraham marked this conversation as resolved.
Show resolved Hide resolved
key := store.GetOutputKey(position)
hash, err := ctx.QueryStore(key, store.DataStoreName)
if err != nil {
return nil, err
}

txKey := store.GetTxKey(hash)
txBytes, err := ctx.QueryStore(txKey, store.DataStoreName)

var tx store.Transaction
if err := rlp.DecodeBytes(txBytes, &tx); err != nil {
return nil, fmt.Errorf("transaction decoding failed: %s", err.Error())
}

// Look for confirmation signatures
// Ignore error if no confirm sig currently exists in store
var sigs []byte
if len(tx.SpenderTxs[position.OutputIndex]) > 0 {
queryPath := fmt.Sprintf("custom/%s/%s/%s",
store.QuerierRouteName, store.QueryTx, tx.SpenderTxs[position.OutputIndex])
data, err := ctx.Query(queryPath, nil)
if err != nil {
wesgraham marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}

var spenderTx store.Transaction
if err := json.Unmarshal(data, &spenderTx); err != nil {
return nil, fmt.Errorf("unmarshaling json query response: %s", err)
}
wesgraham marked this conversation as resolved.
Show resolved Hide resolved
for _, input := range spenderTx.Transaction.Inputs {
if input.Position.String() == position.String() {
for _, sig := range input.ConfirmSignatures {
sigs = append(sigs, sig[:]...)
}
}
}
}

return sigs, nil
}

54 changes: 5 additions & 49 deletions cmd/plasmacli/subcmd/eth/query/confirmsig.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package query

import (
"encoding/json"
"fmt"
"github.com/FourthState/plasma-mvp-sidechain/client"
"github.com/FourthState/plasma-mvp-sidechain/cmd/plasmacli/config"
"github.com/FourthState/plasma-mvp-sidechain/plasma"
"github.com/FourthState/plasma-mvp-sidechain/store"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/ethereum/go-ethereum/rlp"
"github.com/spf13/cobra"
)

// SigCmd returns the query confirm sig command
func SigCmd() *cobra.Command {
config.AddPersistentTMFlags(sigCmd)
sigCmd.Flags().Bool(useNodeF, false, "trust connected full node")
return sigCmd
}

Expand All @@ -31,12 +28,14 @@ var sigCmd = &cobra.Command{

wesgraham marked this conversation as resolved.
Show resolved Hide resolved
var sigs []byte
ctx := context.NewCLIContext()
sigs, err = getSigs(ctx, pos)
sigs, err = client.Signatures(ctx, pos)
if err != nil {
return fmt.Errorf("failed to retrieve confirm signature information: %s", err)
}

wesgraham marked this conversation as resolved.
Show resolved Hide resolved
switch len(sigs) {
case 0:
fmt.Printf("No Confirm Signatures Found")
case 65:
fmt.Printf("Confirmation Signatures: 0x%x\n", sigs[:])
case 130:
Expand All @@ -45,47 +44,4 @@ var sigCmd = &cobra.Command{

return nil
},
}

// Returns confirm sig results for given position
// Trusts connected full node
func getSigs(ctx context.CLIContext, position plasma.Position) ([]byte, error) {
key := store.GetOutputKey(position)
hash, err := ctx.QueryStore(key, store.DataStoreName)
if err != nil {
return nil, err
}

txKey := store.GetTxKey(hash)
txBytes, err := ctx.QueryStore(txKey, store.DataStoreName)

var tx store.Transaction
if err := rlp.DecodeBytes(txBytes, &tx); err != nil {
return nil, fmt.Errorf("transaction decoding failed: %s", err.Error())
}

// Look for confirmation signatures
// Ignore error if no confirm sig currently exists in store
var sigs []byte
if len(tx.SpenderTxs[position.OutputIndex]) > 0 {
queryPath := fmt.Sprintf("custom/data/tx/%s", tx.SpenderTxs[position.OutputIndex])
data, err := ctx.Query(queryPath, nil)
if err != nil {
return nil, err
}

var spenderTx store.Transaction
if err := json.Unmarshal(data, &spenderTx); err != nil {
return nil, fmt.Errorf("unmarshaling json query response: %s", err)
}
for _, input := range spenderTx.Transaction.Inputs {
if input.Position.String() == position.String() {
for _, sig := range input.ConfirmSignatures {
sigs = append(sigs, sig[:]...)
}
}
}
}

return sigs, nil
}
}
1 change: 0 additions & 1 deletion cmd/plasmacli/subcmd/eth/query/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var (
indexF = "index"
limitF = "limit"
positionF = "position"
useNodeF = "use-node"
)

// RootCmd returns the eth query command
Expand Down