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

[statequery] query with real trie key bytes instead of variable string names #84

Merged
merged 2 commits into from Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions chain/chainservice.go
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/aergoio/aergo/contract/name"
"github.com/aergoio/aergo/contract/system"
"github.com/aergoio/aergo/fee"
"github.com/aergoio/aergo/internal/common"
"github.com/aergoio/aergo/internal/enc"
"github.com/aergoio/aergo/message"
"github.com/aergoio/aergo/pkg/component"
Expand Down Expand Up @@ -781,8 +780,7 @@ func (cw *ChainWorker) Receive(context actor.Context) {
} else if contractProof.Inclusion {
contractTrieRoot := contractProof.State.StorageRoot
for _, storageKey := range msg.StorageKeys {
trieKey := common.Hasher([]byte(storageKey))
varProof, err := cw.sdb.GetStateDB().GetVarAndProof(trieKey, contractTrieRoot, msg.Compressed)
varProof, err := cw.sdb.GetStateDB().GetVarAndProof(storageKey, contractTrieRoot, msg.Compressed)
varProof.Key = storageKey
varProofs = append(varProofs, varProof)
if err != nil {
Expand Down
20 changes: 11 additions & 9 deletions cmd/aergocli/cmd/contract.go
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/aergoio/aergo/cmd/aergocli/util"
luacEncoding "github.com/aergoio/aergo/cmd/aergoluac/encoding"
"github.com/aergoio/aergo/internal/common"
"github.com/aergoio/aergo/types"
"github.com/mr-tron/base58/base58"
"github.com/spf13/cobra"
Expand All @@ -33,10 +34,10 @@ func init() {
}

deployCmd := &cobra.Command{
Use: "deploy [flags] --payload 'payload string' creator\n aergocli contract deploy [flags] creator bcfile abifile",
Short: "Deploy a compiled contract to the server",
Args: cobra.MinimumNArgs(1),
Run: runDeployCmd,
Use: "deploy [flags] --payload 'payload string' creator\n aergocli contract deploy [flags] creator bcfile abifile",
Short: "Deploy a compiled contract to the server",
Args: cobra.MinimumNArgs(1),
Run: runDeployCmd,
DisableFlagsInUseLine: true,
}
deployCmd.PersistentFlags().StringVar(&data, "payload", "", "result of compiling a contract")
Expand Down Expand Up @@ -328,15 +329,16 @@ func runQueryStateCmd(cmd *cobra.Command, args []string) {
return
}
}
storageKey := bytes.NewBufferString("_sv_")
storageKey.WriteString(args[1])
storageKeyPlain := bytes.NewBufferString("_sv_")
storageKeyPlain.WriteString(args[1])
if len(args) > 2 {
storageKey.WriteString("-")
storageKey.WriteString(args[2])
storageKeyPlain.WriteString("-")
storageKeyPlain.WriteString(args[2])
}
storageKey := common.Hasher([]byte(storageKeyPlain.Bytes()))
stateQuery := &types.StateQuery{
ContractAddress: contract,
StorageKeys: []string{storageKey.String()},
StorageKeys: [][]byte{storageKey},
Root: root,
Compressed: compressed,
}
Expand Down
2 changes: 1 addition & 1 deletion message/blockchainmsg.go
Expand Up @@ -96,7 +96,7 @@ type GetQueryRsp struct {
}
type GetStateQuery struct {
ContractAddress []byte
StorageKeys []string
StorageKeys [][]byte
Root []byte
Compressed bool
}
Expand Down
20 changes: 10 additions & 10 deletions types/account.pb.go

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