Commit 52d13650 authored by linj's avatar linj Committed by 33cn

fix local key prefix

parent a6d08daa
package executor
import (
"strings"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
ptypes "github.com/33cn/plugin/plugin/dapp/js/types"
"github.com/33cn/plugin/plugin/dapp/js/types/jsproto"
)
func (c *js) userExecName(name string) string {
execer := types.ExecName("user." + ptypes.JsX + "." + name)
if types.IsPara() {
execer = types.GetTitle() + execer
func (c *js) userExecName(name string, local bool) string {
execer := "user." + ptypes.JsX + "." + name
if local {
execer = types.ExecName(execer)
}
return execer
}
func (c *js) chechJsName(name string) bool {
func (c *js) checkJsName(name string) bool {
if types.IsPara() {
return name == types.GetTitle()+ptypes.JsX
}
return name == ptypes.JsX
}
func (c *js) checkJsPrefix(name string) bool {
if types.IsPara() {
return strings.HasPrefix(name, types.GetTitle()+"user."+ptypes.JsX)
}
return strings.HasPrefix(name, "user."+ptypes.JsX)
}
func (c *js) Exec_Create(payload *jsproto.Create, tx *types.Transaction, index int) (*types.Receipt, error) {
err := checkPriv(tx.From(), ptypes.JsCreator, c.GetStateDB())
if err != nil {
return nil, err
}
execer := c.userExecName(payload.Name)
if !c.chechJsName(string(tx.Execer)) {
execer := c.userExecName(payload.Name, false)
if !c.checkJsName(string(tx.Execer)) {
return nil, types.ErrExecNameNotMatch
}
c.prefix = types.CalcStatePrefix([]byte(execer))
......@@ -56,8 +65,8 @@ func (c *js) Exec_Create(payload *jsproto.Create, tx *types.Transaction, index i
}
func (c *js) Exec_Call(payload *jsproto.Call, tx *types.Transaction, index int) (*types.Receipt, error) {
execer := c.userExecName(payload.Name)
if !c.chechJsName(string(tx.Execer)) {
execer := c.userExecName(payload.Name, false)
if !c.checkJsPrefix(string(tx.Execer)) {
return nil, types.ErrExecNameNotMatch
}
c.prefix = types.CalcStatePrefix([]byte(execer))
......
......@@ -2,7 +2,6 @@ package executor
import (
"github.com/33cn/chain33/types"
ptypes "github.com/33cn/plugin/plugin/dapp/js/types"
"github.com/33cn/plugin/plugin/dapp/js/types/jsproto"
)
......@@ -11,7 +10,7 @@ func (c *js) ExecDelLocal_Create(payload *jsproto.Create, tx *types.Transaction,
}
func (c *js) ExecDelLocal_Call(payload *jsproto.Call, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
execer := types.ExecName("user." + ptypes.JsX + "." + payload.Name)
execer := c.userExecName(payload.Name, true)
r := &types.LocalDBSet{}
c.prefix = types.CalcLocalPrefix([]byte(execer))
kvs, err := c.DelRollbackKV(tx, []byte(execer))
......
......@@ -2,7 +2,6 @@ package executor
import (
"github.com/33cn/chain33/types"
ptypes "github.com/33cn/plugin/plugin/dapp/js/types"
"github.com/33cn/plugin/plugin/dapp/js/types/jsproto"
)
......@@ -11,7 +10,7 @@ func (c *js) ExecLocal_Create(payload *jsproto.Create, tx *types.Transaction, re
}
func (c *js) ExecLocal_Call(payload *jsproto.Call, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
execer := types.ExecName("user." + ptypes.JsX + "." + payload.Name)
execer := c.userExecName(payload.Name, true)
c.prefix = types.CalcLocalPrefix([]byte(execer))
jsvalue, err := c.callVM("execlocal", payload, tx, index, receiptData)
if err != nil {
......
......@@ -8,7 +8,7 @@ import (
)
func (c *js) Query_Query(payload *jsproto.Call) (types.Message, error) {
execer := c.userExecName(payload.Name)
execer := c.userExecName(payload.Name, true)
c.prefix = types.CalcLocalPrefix([]byte(execer))
jsvalue, err := c.callVM("query", payload, nil, 0, nil)
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment