mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 19:29:39 +00:00
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,
|
||||
manifest.NewParameter("hash", smartcontract.Hash160Type))
|
||||
manifest.NewParameter("hash", smartcontract.ByteArrayType))
|
||||
md := newMethodAndPrice(m.getContract, 1000000, smartcontract.ReadStates)
|
||||
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.
|
||||
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 {
|
||||
value := toBigInt(args[0]).Int64()
|
||||
value := toUint32(args[0])
|
||||
if value < 0 {
|
||||
panic(fmt.Errorf("MinimumDeploymentFee cannot be negative"))
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ func (m *Management) setMinimumDeploymentFee(ic *interop.Context, args []stackit
|
|||
if !ok {
|
||||
return stackitem.NewBool(false)
|
||||
}
|
||||
err = setInt64WithKey(m.ContractID, ic.DAO, keyMinimumDeploymentFee, value)
|
||||
err = setUint32WithKey(m.ContractID, ic.DAO, keyMinimumDeploymentFee, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ func (m *Management) PostPersist(ic *interop.Context) error {
|
|||
|
||||
// Initialize implements Contract interface.
|
||||
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.
|
||||
|
|
|
@ -108,24 +108,24 @@ func newNEO() *NEO {
|
|||
n.committeeHash.Store(util.Uint160{})
|
||||
|
||||
desc := newDescriptor("unclaimedGas", smartcontract.IntegerType,
|
||||
manifest.NewParameter("account", smartcontract.Hash160Type),
|
||||
manifest.NewParameter("account", smartcontract.ByteArrayType),
|
||||
manifest.NewParameter("end", smartcontract.IntegerType))
|
||||
md := newMethodAndPrice(n.unclaimedGas, 3000000, smartcontract.ReadStates)
|
||||
n.AddMethod(md, desc)
|
||||
|
||||
desc = newDescriptor("registerCandidate", smartcontract.BoolType,
|
||||
manifest.NewParameter("pubkey", smartcontract.PublicKeyType))
|
||||
manifest.NewParameter("pubkey", smartcontract.ByteArrayType))
|
||||
md = newMethodAndPrice(n.registerCandidate, 5000000, smartcontract.WriteStates)
|
||||
n.AddMethod(md, desc)
|
||||
|
||||
desc = newDescriptor("unregisterCandidate", smartcontract.BoolType,
|
||||
manifest.NewParameter("pubkey", smartcontract.PublicKeyType))
|
||||
manifest.NewParameter("pubkey", smartcontract.ByteArrayType))
|
||||
md = newMethodAndPrice(n.unregisterCandidate, 5000000, smartcontract.WriteStates)
|
||||
n.AddMethod(md, desc)
|
||||
|
||||
desc = newDescriptor("vote", smartcontract.BoolType,
|
||||
manifest.NewParameter("account", smartcontract.Hash160Type),
|
||||
manifest.NewParameter("pubkey", smartcontract.PublicKeyType))
|
||||
manifest.NewParameter("account", smartcontract.ByteArrayType),
|
||||
manifest.NewParameter("pubkey", smartcontract.ByteArrayType))
|
||||
md = newMethodAndPrice(n.vote, 5000000, smartcontract.WriteStates)
|
||||
n.AddMethod(md, desc)
|
||||
|
||||
|
@ -246,11 +246,9 @@ func (n *NEO) updateCommittee(ic *interop.Context) error {
|
|||
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 {
|
||||
return err
|
||||
} else if cvs == nil {
|
||||
cvs = toKeysWithVotes(committee)
|
||||
}
|
||||
if err := n.updateCache(cvs, ic.Chain); err != nil {
|
||||
return err
|
||||
|
@ -852,18 +850,28 @@ func (n *NEO) computeCommitteeMembers(bc blockchainer.Blockchainer, d dao.DAO) (
|
|||
// votersCount / totalSupply must be >= 0.2
|
||||
votersCount.Mul(votersCount, big.NewInt(effectiveVoterTurnout))
|
||||
voterTurnout := votersCount.Div(votersCount, n.getTotalSupply(d))
|
||||
if voterTurnout.Sign() != 1 {
|
||||
pubs := bc.GetStandByCommittee()
|
||||
return pubs, nil, nil
|
||||
}
|
||||
|
||||
sbVals := bc.GetStandByCommittee()
|
||||
count := len(sbVals)
|
||||
cs, err := n.getCandidates(d, false)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
sbVals := bc.GetStandByCommittee()
|
||||
count := len(sbVals)
|
||||
if len(cs) < count {
|
||||
return sbVals, nil, nil
|
||||
if voterTurnout.Sign() != 1 || len(cs) < count {
|
||||
kvs := make(keysWithVotes, count)
|
||||
for i := range kvs {
|
||||
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)
|
||||
for i := range pubs {
|
||||
|
|
|
@ -59,22 +59,23 @@ func newNEP17Native(name string) *nep17TokenNative {
|
|||
n.AddMethod(md, desc)
|
||||
|
||||
desc = newDescriptor("balanceOf", smartcontract.IntegerType,
|
||||
manifest.NewParameter("account", smartcontract.Hash160Type))
|
||||
manifest.NewParameter("account", smartcontract.ByteArrayType))
|
||||
md = newMethodAndPrice(n.balanceOf, 1000000, smartcontract.ReadStates)
|
||||
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,
|
||||
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)
|
||||
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
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ func newPolicy() *Policy {
|
|||
p.AddMethod(md, desc)
|
||||
|
||||
desc = newDescriptor("isBlocked", smartcontract.BoolType,
|
||||
manifest.NewParameter("account", smartcontract.Hash160Type))
|
||||
manifest.NewParameter("account", smartcontract.ByteArrayType))
|
||||
md = newMethodAndPrice(p.isBlocked, 1000000, smartcontract.ReadStates)
|
||||
p.AddMethod(md, desc)
|
||||
|
||||
|
@ -144,12 +144,12 @@ func newPolicy() *Policy {
|
|||
p.AddMethod(md, desc)
|
||||
|
||||
desc = newDescriptor("blockAccount", smartcontract.BoolType,
|
||||
manifest.NewParameter("account", smartcontract.Hash160Type))
|
||||
manifest.NewParameter("account", smartcontract.ByteArrayType))
|
||||
md = newMethodAndPrice(p.blockAccount, 3000000, smartcontract.WriteStates)
|
||||
p.AddMethod(md, desc)
|
||||
|
||||
desc = newDescriptor("unblockAccount", smartcontract.BoolType,
|
||||
manifest.NewParameter("account", smartcontract.Hash160Type))
|
||||
manifest.NewParameter("account", smartcontract.ByteArrayType))
|
||||
md = newMethodAndPrice(p.unblockAccount, 3000000, smartcontract.WriteStates)
|
||||
p.AddMethod(md, desc)
|
||||
|
||||
|
|
|
@ -539,7 +539,11 @@ func (s *Server) getApplicationLog(reqParams request.Params) (interface{}, *resp
|
|||
|
||||
trig := trigger.All
|
||||
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 {
|
||||
return nil, response.ErrInvalidParams
|
||||
}
|
||||
|
|
|
@ -121,6 +121,11 @@ var rpcTestCases = map[string][]rpcTestCase{
|
|||
assert.Equal(t, vm.HaltState, res.Executions[0].VMState)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid trigger (not a string)",
|
||||
params: `["` + genesisBlockHash + `", 1]`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
name: "no params",
|
||||
params: `[]`,
|
||||
|
|
Loading…
Reference in a new issue