Merge pull request #1735 from nspcc-dev/transfers-read-state

interop: allow transfer calls to read states
This commit is contained in:
Roman Khimov 2021-02-12 14:46:43 +03:00 committed by GitHub
commit 94672d4d83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 4 deletions

View file

@ -260,7 +260,11 @@ func testContractCall(t *testing.T, hash util.Uint160, md interop.MethodAndPrice
require.Equal(t, md.MD.Name, method) require.Equal(t, md.MD.Name, method)
fs := callflag.CallFlag(int32(v.Estack().Pop().BigInt().Int64())) fs := callflag.CallFlag(int32(v.Estack().Pop().BigInt().Int64()))
require.Equal(t, md.RequiredFlags, fs) extended := md.RequiredFlags // In some (all?) cases it's desirable to have Read permissions where Write is also allowed.
if md.RequiredFlags&callflag.WriteStates != 0 {
extended |= callflag.ReadStates
}
require.True(t, fs == md.RequiredFlags || fs == extended)
args := v.Estack().Pop().Array() args := v.Estack().Pop().Array()
require.Equal(t, len(md.MD.Parameters), len(args)) require.Equal(t, len(md.MD.Parameters), len(args))

View file

@ -31,5 +31,5 @@ func BalanceOf(addr interop.Hash160) int {
// Transfer represents `transfer` method of GAS native contract. // Transfer represents `transfer` method of GAS native contract.
func Transfer(from, to interop.Hash160, amount int, data interface{}) bool { func Transfer(from, to interop.Hash160, amount int, data interface{}) bool {
return contract.Call(interop.Hash160(Hash), "transfer", return contract.Call(interop.Hash160(Hash), "transfer",
contract.WriteStates|contract.AllowCall|contract.AllowNotify, from, to, amount, data).(bool) contract.All, from, to, amount, data).(bool)
} }

View file

@ -65,7 +65,7 @@ func TokensOf(addr interop.Hash160) iterator.Iterator {
// Transfer represents `transfer` method of NameService native contract. // Transfer represents `transfer` method of NameService native contract.
func Transfer(to interop.Hash160, tokenID string) bool { func Transfer(to interop.Hash160, tokenID string) bool {
return contract.Call(interop.Hash160(Hash), "transfer", return contract.Call(interop.Hash160(Hash), "transfer",
contract.WriteStates|contract.AllowNotify, to, tokenID).(bool) contract.ReadStates|contract.WriteStates|contract.AllowNotify, to, tokenID).(bool)
} }
// AddRoot represents `addRoot` method of NameService native contract. // AddRoot represents `addRoot` method of NameService native contract.

View file

@ -31,7 +31,7 @@ func BalanceOf(addr interop.Hash160) int {
// Transfer represents `transfer` method of NEO native contract. // Transfer represents `transfer` method of NEO native contract.
func Transfer(from, to interop.Hash160, amount int, data interface{}) bool { func Transfer(from, to interop.Hash160, amount int, data interface{}) bool {
return contract.Call(interop.Hash160(Hash), "transfer", return contract.Call(interop.Hash160(Hash), "transfer",
contract.WriteStates|contract.AllowCall|contract.AllowNotify, from, to, amount, data).(bool) contract.All, from, to, amount, data).(bool)
} }
// GetCommittee represents `getCommittee` method of NEO native contract. // GetCommittee represents `getCommittee` method of NEO native contract.