mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 03:38:35 +00:00
core: fix bug with native contracts methods initialisation
`NewNEO()` and `NewGAS()` methods are trying to initialise both `onPersist` and `incBalance` methods of NEO and GAS AFTER nep5TokenNative is set to the VALUE of created nep5 token. In this situation an attemmpt to call the corresponding native contracts methods (e.g. transfer native GAS) leads to contract invocation failure, as far as `nep5TokenNative.incBalance` method is nil. Fixed this by initializing both `onPersist` and `incBalance` methods before getting the value of nep5 contract.
This commit is contained in:
parent
4ebac5a069
commit
c7a040ff81
2 changed files with 8 additions and 7 deletions
|
@ -28,21 +28,22 @@ const initialGAS = 30000000
|
||||||
|
|
||||||
// NewGAS returns GAS native contract.
|
// NewGAS returns GAS native contract.
|
||||||
func NewGAS() *GAS {
|
func NewGAS() *GAS {
|
||||||
|
g := &GAS{}
|
||||||
nep5 := newNEP5Native(gasSyscallName)
|
nep5 := newNEP5Native(gasSyscallName)
|
||||||
nep5.name = "GAS"
|
nep5.name = "GAS"
|
||||||
nep5.symbol = "gas"
|
nep5.symbol = "gas"
|
||||||
nep5.decimals = 8
|
nep5.decimals = 8
|
||||||
nep5.factor = GASFactor
|
nep5.factor = GASFactor
|
||||||
|
nep5.onPersist = chainOnPersist(g.onPersist, g.OnPersist)
|
||||||
|
nep5.incBalance = g.increaseBalance
|
||||||
|
|
||||||
g := &GAS{nep5TokenNative: *nep5}
|
g.nep5TokenNative = *nep5
|
||||||
|
|
||||||
desc := newDescriptor("getSysFeeAmount", smartcontract.IntegerType,
|
desc := newDescriptor("getSysFeeAmount", smartcontract.IntegerType,
|
||||||
manifest.NewParameter("index", smartcontract.IntegerType))
|
manifest.NewParameter("index", smartcontract.IntegerType))
|
||||||
md := newMethodAndPrice(g.getSysFeeAmount, 1, smartcontract.NoneFlag)
|
md := newMethodAndPrice(g.getSysFeeAmount, 1, smartcontract.NoneFlag)
|
||||||
g.AddMethod(md, desc, true)
|
g.AddMethod(md, desc, true)
|
||||||
|
|
||||||
g.onPersist = chainOnPersist(g.onPersist, g.OnPersist)
|
|
||||||
g.incBalance = g.increaseBalance
|
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,13 +60,16 @@ func makeValidatorKey(key *keys.PublicKey) []byte {
|
||||||
|
|
||||||
// NewNEO returns NEO native contract.
|
// NewNEO returns NEO native contract.
|
||||||
func NewNEO() *NEO {
|
func NewNEO() *NEO {
|
||||||
|
n := &NEO{}
|
||||||
nep5 := newNEP5Native(neoSyscallName)
|
nep5 := newNEP5Native(neoSyscallName)
|
||||||
nep5.name = "NEO"
|
nep5.name = "NEO"
|
||||||
nep5.symbol = "neo"
|
nep5.symbol = "neo"
|
||||||
nep5.decimals = 0
|
nep5.decimals = 0
|
||||||
nep5.factor = 1
|
nep5.factor = 1
|
||||||
|
nep5.onPersist = chainOnPersist(n.onPersist, n.OnPersist)
|
||||||
|
nep5.incBalance = n.increaseBalance
|
||||||
|
|
||||||
n := &NEO{nep5TokenNative: *nep5}
|
n.nep5TokenNative = *nep5
|
||||||
|
|
||||||
desc := newDescriptor("unclaimedGas", smartcontract.IntegerType,
|
desc := newDescriptor("unclaimedGas", smartcontract.IntegerType,
|
||||||
manifest.NewParameter("account", smartcontract.Hash160Type),
|
manifest.NewParameter("account", smartcontract.Hash160Type),
|
||||||
|
@ -97,9 +100,6 @@ func NewNEO() *NEO {
|
||||||
md = newMethodAndPrice(n.getNextBlockValidators, 1, smartcontract.NoneFlag)
|
md = newMethodAndPrice(n.getNextBlockValidators, 1, smartcontract.NoneFlag)
|
||||||
n.AddMethod(md, desc, true)
|
n.AddMethod(md, desc, true)
|
||||||
|
|
||||||
n.onPersist = chainOnPersist(n.onPersist, n.OnPersist)
|
|
||||||
n.incBalance = n.increaseBalance
|
|
||||||
|
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue