Skip to content

Commit

Permalink
[statequery] query with real trie key bytes instead of variable strin…
Browse files Browse the repository at this point in the history
…g names (#84)

* [statequery] query with real trie key bytes instead of variable string names to support non utf-8 bytes "_sv_VarName-Mapey" => sha256(bytes("_sv_VarName-Mapey"))

* [cli] improve naming
  • Loading branch information
paouvrard authored and ashen1dev committed Jun 14, 2019
1 parent b50b5ee commit c9cc37b
Show file tree
Hide file tree
Showing 12 changed files with 703 additions and 708 deletions.
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.

0 comments on commit c9cc37b

Please sign in to comment.