forked from TrueCloudLab/neoneo-go
Merge pull request #1636 from nspcc-dev/states_fixes
core: preview4 compatibility fixes
This commit is contained in:
commit
9fcee12276
6 changed files with 51 additions and 33 deletions
|
@ -64,7 +64,7 @@ func newManagement() *Management {
|
||||||
}
|
}
|
||||||
|
|
||||||
desc := newDescriptor("getContract", smartcontract.ArrayType,
|
desc := newDescriptor("getContract", smartcontract.ArrayType,
|
||||||
manifest.NewParameter("hash", smartcontract.Hash160Type))
|
manifest.NewParameter("hash", smartcontract.ByteArrayType))
|
||||||
md := newMethodAndPrice(m.getContract, 1000000, smartcontract.ReadStates)
|
md := newMethodAndPrice(m.getContract, 1000000, smartcontract.ReadStates)
|
||||||
m.AddMethod(md, desc)
|
m.AddMethod(md, desc)
|
||||||
|
|
||||||
|
@ -357,11 +357,11 @@ func (m *Management) getMinimumDeploymentFee(ic *interop.Context, args []stackit
|
||||||
|
|
||||||
// GetMinimumDeploymentFee returns the minimum required fee for contract deploy.
|
// GetMinimumDeploymentFee returns the minimum required fee for contract deploy.
|
||||||
func (m *Management) GetMinimumDeploymentFee(dao dao.DAO) int64 {
|
func (m *Management) GetMinimumDeploymentFee(dao dao.DAO) int64 {
|
||||||
return getInt64WithKey(m.ContractID, dao, keyMinimumDeploymentFee, defaultMinimumDeploymentFee)
|
return int64(getUint32WithKey(m.ContractID, dao, keyMinimumDeploymentFee, defaultMinimumDeploymentFee))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Management) setMinimumDeploymentFee(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
func (m *Management) setMinimumDeploymentFee(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
||||||
value := toBigInt(args[0]).Int64()
|
value := toUint32(args[0])
|
||||||
if value < 0 {
|
if value < 0 {
|
||||||
panic(fmt.Errorf("MinimumDeploymentFee cannot be negative"))
|
panic(fmt.Errorf("MinimumDeploymentFee cannot be negative"))
|
||||||
}
|
}
|
||||||
|
@ -372,7 +372,7 @@ func (m *Management) setMinimumDeploymentFee(ic *interop.Context, args []stackit
|
||||||
if !ok {
|
if !ok {
|
||||||
return stackitem.NewBool(false)
|
return stackitem.NewBool(false)
|
||||||
}
|
}
|
||||||
err = setInt64WithKey(m.ContractID, ic.DAO, keyMinimumDeploymentFee, value)
|
err = setUint32WithKey(m.ContractID, ic.DAO, keyMinimumDeploymentFee, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -483,7 +483,7 @@ func (m *Management) PostPersist(ic *interop.Context) error {
|
||||||
|
|
||||||
// Initialize implements Contract interface.
|
// Initialize implements Contract interface.
|
||||||
func (m *Management) Initialize(ic *interop.Context) error {
|
func (m *Management) Initialize(ic *interop.Context) error {
|
||||||
return setInt64WithKey(m.ContractID, ic.DAO, keyMinimumDeploymentFee, defaultMinimumDeploymentFee)
|
return setUint32WithKey(m.ContractID, ic.DAO, keyMinimumDeploymentFee, defaultMinimumDeploymentFee)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PutContractState saves given contract state into given DAO.
|
// PutContractState saves given contract state into given DAO.
|
||||||
|
|
|
@ -108,24 +108,24 @@ func newNEO() *NEO {
|
||||||
n.committeeHash.Store(util.Uint160{})
|
n.committeeHash.Store(util.Uint160{})
|
||||||
|
|
||||||
desc := newDescriptor("unclaimedGas", smartcontract.IntegerType,
|
desc := newDescriptor("unclaimedGas", smartcontract.IntegerType,
|
||||||
manifest.NewParameter("account", smartcontract.Hash160Type),
|
manifest.NewParameter("account", smartcontract.ByteArrayType),
|
||||||
manifest.NewParameter("end", smartcontract.IntegerType))
|
manifest.NewParameter("end", smartcontract.IntegerType))
|
||||||
md := newMethodAndPrice(n.unclaimedGas, 3000000, smartcontract.ReadStates)
|
md := newMethodAndPrice(n.unclaimedGas, 3000000, smartcontract.ReadStates)
|
||||||
n.AddMethod(md, desc)
|
n.AddMethod(md, desc)
|
||||||
|
|
||||||
desc = newDescriptor("registerCandidate", smartcontract.BoolType,
|
desc = newDescriptor("registerCandidate", smartcontract.BoolType,
|
||||||
manifest.NewParameter("pubkey", smartcontract.PublicKeyType))
|
manifest.NewParameter("pubkey", smartcontract.ByteArrayType))
|
||||||
md = newMethodAndPrice(n.registerCandidate, 5000000, smartcontract.WriteStates)
|
md = newMethodAndPrice(n.registerCandidate, 5000000, smartcontract.WriteStates)
|
||||||
n.AddMethod(md, desc)
|
n.AddMethod(md, desc)
|
||||||
|
|
||||||
desc = newDescriptor("unregisterCandidate", smartcontract.BoolType,
|
desc = newDescriptor("unregisterCandidate", smartcontract.BoolType,
|
||||||
manifest.NewParameter("pubkey", smartcontract.PublicKeyType))
|
manifest.NewParameter("pubkey", smartcontract.ByteArrayType))
|
||||||
md = newMethodAndPrice(n.unregisterCandidate, 5000000, smartcontract.WriteStates)
|
md = newMethodAndPrice(n.unregisterCandidate, 5000000, smartcontract.WriteStates)
|
||||||
n.AddMethod(md, desc)
|
n.AddMethod(md, desc)
|
||||||
|
|
||||||
desc = newDescriptor("vote", smartcontract.BoolType,
|
desc = newDescriptor("vote", smartcontract.BoolType,
|
||||||
manifest.NewParameter("account", smartcontract.Hash160Type),
|
manifest.NewParameter("account", smartcontract.ByteArrayType),
|
||||||
manifest.NewParameter("pubkey", smartcontract.PublicKeyType))
|
manifest.NewParameter("pubkey", smartcontract.ByteArrayType))
|
||||||
md = newMethodAndPrice(n.vote, 5000000, smartcontract.WriteStates)
|
md = newMethodAndPrice(n.vote, 5000000, smartcontract.WriteStates)
|
||||||
n.AddMethod(md, desc)
|
n.AddMethod(md, desc)
|
||||||
|
|
||||||
|
@ -246,11 +246,9 @@ func (n *NEO) updateCommittee(ic *interop.Context) error {
|
||||||
return ic.DAO.PutStorageItem(n.ContractID, prefixCommittee, si)
|
return ic.DAO.PutStorageItem(n.ContractID, prefixCommittee, si)
|
||||||
}
|
}
|
||||||
|
|
||||||
committee, cvs, err := n.computeCommitteeMembers(ic.Chain, ic.DAO)
|
_, cvs, err := n.computeCommitteeMembers(ic.Chain, ic.DAO)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if cvs == nil {
|
|
||||||
cvs = toKeysWithVotes(committee)
|
|
||||||
}
|
}
|
||||||
if err := n.updateCache(cvs, ic.Chain); err != nil {
|
if err := n.updateCache(cvs, ic.Chain); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -852,18 +850,28 @@ func (n *NEO) computeCommitteeMembers(bc blockchainer.Blockchainer, d dao.DAO) (
|
||||||
// votersCount / totalSupply must be >= 0.2
|
// votersCount / totalSupply must be >= 0.2
|
||||||
votersCount.Mul(votersCount, big.NewInt(effectiveVoterTurnout))
|
votersCount.Mul(votersCount, big.NewInt(effectiveVoterTurnout))
|
||||||
voterTurnout := votersCount.Div(votersCount, n.getTotalSupply(d))
|
voterTurnout := votersCount.Div(votersCount, n.getTotalSupply(d))
|
||||||
if voterTurnout.Sign() != 1 {
|
|
||||||
pubs := bc.GetStandByCommittee()
|
sbVals := bc.GetStandByCommittee()
|
||||||
return pubs, nil, nil
|
count := len(sbVals)
|
||||||
}
|
|
||||||
cs, err := n.getCandidates(d, false)
|
cs, err := n.getCandidates(d, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
sbVals := bc.GetStandByCommittee()
|
if voterTurnout.Sign() != 1 || len(cs) < count {
|
||||||
count := len(sbVals)
|
kvs := make(keysWithVotes, count)
|
||||||
if len(cs) < count {
|
for i := range kvs {
|
||||||
return sbVals, nil, nil
|
kvs[i].UnmarshaledKey = sbVals[i]
|
||||||
|
kvs[i].Key = string(sbVals[i].Bytes())
|
||||||
|
votes := big.NewInt(0)
|
||||||
|
for j := range cs {
|
||||||
|
if cs[j].Key == kvs[i].Key {
|
||||||
|
votes = cs[j].Votes
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kvs[i].Votes = votes
|
||||||
|
}
|
||||||
|
return sbVals, kvs, nil
|
||||||
}
|
}
|
||||||
pubs := make(keys.PublicKeys, count)
|
pubs := make(keys.PublicKeys, count)
|
||||||
for i := range pubs {
|
for i := range pubs {
|
||||||
|
|
|
@ -59,22 +59,23 @@ func newNEP17Native(name string) *nep17TokenNative {
|
||||||
n.AddMethod(md, desc)
|
n.AddMethod(md, desc)
|
||||||
|
|
||||||
desc = newDescriptor("balanceOf", smartcontract.IntegerType,
|
desc = newDescriptor("balanceOf", smartcontract.IntegerType,
|
||||||
manifest.NewParameter("account", smartcontract.Hash160Type))
|
manifest.NewParameter("account", smartcontract.ByteArrayType))
|
||||||
md = newMethodAndPrice(n.balanceOf, 1000000, smartcontract.ReadStates)
|
md = newMethodAndPrice(n.balanceOf, 1000000, smartcontract.ReadStates)
|
||||||
n.AddMethod(md, desc)
|
n.AddMethod(md, desc)
|
||||||
|
|
||||||
transferParams := []manifest.Parameter{
|
|
||||||
manifest.NewParameter("from", smartcontract.Hash160Type),
|
|
||||||
manifest.NewParameter("to", smartcontract.Hash160Type),
|
|
||||||
manifest.NewParameter("amount", smartcontract.IntegerType),
|
|
||||||
}
|
|
||||||
desc = newDescriptor("transfer", smartcontract.BoolType,
|
desc = newDescriptor("transfer", smartcontract.BoolType,
|
||||||
append(transferParams, manifest.NewParameter("data", smartcontract.AnyType))...,
|
manifest.NewParameter("from", smartcontract.ByteArrayType),
|
||||||
|
manifest.NewParameter("to", smartcontract.ByteArrayType),
|
||||||
|
manifest.NewParameter("amount", smartcontract.IntegerType),
|
||||||
|
manifest.NewParameter("data", smartcontract.AnyType),
|
||||||
)
|
)
|
||||||
md = newMethodAndPrice(n.Transfer, 9000000, smartcontract.WriteStates|smartcontract.AllowCall|smartcontract.AllowNotify)
|
md = newMethodAndPrice(n.Transfer, 9000000, smartcontract.WriteStates|smartcontract.AllowCall|smartcontract.AllowNotify)
|
||||||
n.AddMethod(md, desc)
|
n.AddMethod(md, desc)
|
||||||
|
|
||||||
n.AddEvent("Transfer", transferParams...)
|
n.AddEvent("Transfer",
|
||||||
|
manifest.NewParameter("from", smartcontract.Hash160Type),
|
||||||
|
manifest.NewParameter("to", smartcontract.Hash160Type),
|
||||||
|
manifest.NewParameter("amount", smartcontract.IntegerType))
|
||||||
|
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ func newPolicy() *Policy {
|
||||||
p.AddMethod(md, desc)
|
p.AddMethod(md, desc)
|
||||||
|
|
||||||
desc = newDescriptor("isBlocked", smartcontract.BoolType,
|
desc = newDescriptor("isBlocked", smartcontract.BoolType,
|
||||||
manifest.NewParameter("account", smartcontract.Hash160Type))
|
manifest.NewParameter("account", smartcontract.ByteArrayType))
|
||||||
md = newMethodAndPrice(p.isBlocked, 1000000, smartcontract.ReadStates)
|
md = newMethodAndPrice(p.isBlocked, 1000000, smartcontract.ReadStates)
|
||||||
p.AddMethod(md, desc)
|
p.AddMethod(md, desc)
|
||||||
|
|
||||||
|
@ -144,12 +144,12 @@ func newPolicy() *Policy {
|
||||||
p.AddMethod(md, desc)
|
p.AddMethod(md, desc)
|
||||||
|
|
||||||
desc = newDescriptor("blockAccount", smartcontract.BoolType,
|
desc = newDescriptor("blockAccount", smartcontract.BoolType,
|
||||||
manifest.NewParameter("account", smartcontract.Hash160Type))
|
manifest.NewParameter("account", smartcontract.ByteArrayType))
|
||||||
md = newMethodAndPrice(p.blockAccount, 3000000, smartcontract.WriteStates)
|
md = newMethodAndPrice(p.blockAccount, 3000000, smartcontract.WriteStates)
|
||||||
p.AddMethod(md, desc)
|
p.AddMethod(md, desc)
|
||||||
|
|
||||||
desc = newDescriptor("unblockAccount", smartcontract.BoolType,
|
desc = newDescriptor("unblockAccount", smartcontract.BoolType,
|
||||||
manifest.NewParameter("account", smartcontract.Hash160Type))
|
manifest.NewParameter("account", smartcontract.ByteArrayType))
|
||||||
md = newMethodAndPrice(p.unblockAccount, 3000000, smartcontract.WriteStates)
|
md = newMethodAndPrice(p.unblockAccount, 3000000, smartcontract.WriteStates)
|
||||||
p.AddMethod(md, desc)
|
p.AddMethod(md, desc)
|
||||||
|
|
||||||
|
|
|
@ -539,7 +539,11 @@ func (s *Server) getApplicationLog(reqParams request.Params) (interface{}, *resp
|
||||||
|
|
||||||
trig := trigger.All
|
trig := trigger.All
|
||||||
if len(reqParams) > 1 {
|
if len(reqParams) > 1 {
|
||||||
trig, err = trigger.FromString(reqParams.ValueWithType(1, request.StringT).String())
|
trigString := reqParams.ValueWithType(1, request.StringT)
|
||||||
|
if trigString == nil {
|
||||||
|
return nil, response.ErrInvalidParams
|
||||||
|
}
|
||||||
|
trig, err = trigger.FromString(trigString.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, response.ErrInvalidParams
|
return nil, response.ErrInvalidParams
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,11 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
assert.Equal(t, vm.HaltState, res.Executions[0].VMState)
|
assert.Equal(t, vm.HaltState, res.Executions[0].VMState)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "invalid trigger (not a string)",
|
||||||
|
params: `["` + genesisBlockHash + `", 1]`,
|
||||||
|
fail: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "no params",
|
name: "no params",
|
||||||
params: `[]`,
|
params: `[]`,
|
||||||
|
|
Loading…
Reference in a new issue