native: make *totalSupply accept DAO
There is no need to provide full interop context.
This commit is contained in:
parent
3e39f0f211
commit
f0b62cdaa6
3 changed files with 10 additions and 9 deletions
|
@ -70,7 +70,7 @@ func (g *GAS) Initialize(ic *interop.Context) error {
|
||||||
if err := g.nep5TokenNative.Initialize(ic); err != nil {
|
if err := g.nep5TokenNative.Initialize(ic); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if g.nep5TokenNative.getTotalSupply(ic).Sign() != 0 {
|
if g.nep5TokenNative.getTotalSupply(ic.DAO).Sign() != 0 {
|
||||||
return errors.New("already initialized")
|
return errors.New("already initialized")
|
||||||
}
|
}
|
||||||
h, _, err := getStandbyValidatorsHash(ic)
|
h, _, err := getStandbyValidatorsHash(ic)
|
||||||
|
|
|
@ -121,7 +121,7 @@ func (n *NEO) Initialize(ic *interop.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.nep5TokenNative.getTotalSupply(ic).Sign() != 0 {
|
if n.nep5TokenNative.getTotalSupply(ic.DAO).Sign() != 0 {
|
||||||
return errors.New("already initialized")
|
return errors.New("already initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/runtime"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/runtime"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
@ -104,20 +105,20 @@ func (c *nep5TokenNative) Decimals(_ *interop.Context, _ []stackitem.Item) stack
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *nep5TokenNative) TotalSupply(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
|
func (c *nep5TokenNative) TotalSupply(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
|
||||||
return stackitem.NewBigInteger(c.getTotalSupply(ic))
|
return stackitem.NewBigInteger(c.getTotalSupply(ic.DAO))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *nep5TokenNative) getTotalSupply(ic *interop.Context) *big.Int {
|
func (c *nep5TokenNative) getTotalSupply(d dao.DAO) *big.Int {
|
||||||
si := ic.DAO.GetStorageItem(c.ContractID, totalSupplyKey)
|
si := d.GetStorageItem(c.ContractID, totalSupplyKey)
|
||||||
if si == nil {
|
if si == nil {
|
||||||
return big.NewInt(0)
|
return big.NewInt(0)
|
||||||
}
|
}
|
||||||
return bigint.FromBytes(si.Value)
|
return bigint.FromBytes(si.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *nep5TokenNative) saveTotalSupply(ic *interop.Context, supply *big.Int) error {
|
func (c *nep5TokenNative) saveTotalSupply(d dao.DAO, supply *big.Int) error {
|
||||||
si := &state.StorageItem{Value: bigint.ToBytes(supply)}
|
si := &state.StorageItem{Value: bigint.ToBytes(supply)}
|
||||||
return ic.DAO.PutStorageItem(c.ContractID, totalSupplyKey, si)
|
return d.PutStorageItem(c.ContractID, totalSupplyKey, si)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *nep5TokenNative) Transfer(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
func (c *nep5TokenNative) Transfer(ic *interop.Context, args []stackitem.Item) stackitem.Item {
|
||||||
|
@ -248,9 +249,9 @@ func (c *nep5TokenNative) addTokens(ic *interop.Context, h util.Uint160, amount
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
supply := c.getTotalSupply(ic)
|
supply := c.getTotalSupply(ic.DAO)
|
||||||
supply.Add(supply, amount)
|
supply.Add(supply, amount)
|
||||||
err := c.saveTotalSupply(ic, supply)
|
err := c.saveTotalSupply(ic.DAO, supply)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue