native: hide native contract methods

Copy public keys when returning them to the outside and hide unused
`GetValidators` method.
This commit is contained in:
Evgenii Stratonikov 2020-06-29 10:48:35 +03:00
parent 8c18142e8a
commit f007cca80b
2 changed files with 16 additions and 7 deletions

View file

@ -91,7 +91,7 @@ func (g *GAS) OnPersist(ic *interop.Context) error {
absAmount := big.NewInt(int64(tx.SystemFee + tx.NetworkFee)) absAmount := big.NewInt(int64(tx.SystemFee + tx.NetworkFee))
g.burn(ic, tx.Sender, absAmount) g.burn(ic, tx.Sender, absAmount)
} }
validators, err := g.NEO.GetNextBlockValidatorsInternal(ic.Chain, ic.DAO) validators, err := g.NEO.getNextBlockValidatorsInternal(ic.Chain, ic.DAO)
if err != nil { if err != nil {
return fmt.Errorf("cannot get block validators: %v", err) return fmt.Errorf("cannot get block validators: %v", err)
} }

View file

@ -142,7 +142,7 @@ func (n *NEO) Initialize(ic *interop.Context) error {
// OnPersist implements Contract interface. // OnPersist implements Contract interface.
func (n *NEO) OnPersist(ic *interop.Context) error { func (n *NEO) OnPersist(ic *interop.Context) error {
pubs, err := n.GetValidatorsInternal(ic.Chain, ic.DAO) pubs, err := n.getValidatorsInternal(ic.Chain, ic.DAO)
if err != nil { if err != nil {
return err return err
} }
@ -385,8 +385,8 @@ func (n *NEO) getRegisteredValidatorsCall(ic *interop.Context, _ []stackitem.Ite
return stackitem.NewArray(arr) return stackitem.NewArray(arr)
} }
// GetValidatorsInternal returns a list of current validators. // getValidatorsInternal returns a list of current validators.
func (n *NEO) GetValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) { func (n *NEO) getValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) {
if vals := n.validators.Load().(keys.PublicKeys); vals != nil { if vals := n.validators.Load().(keys.PublicKeys); vals != nil {
return vals, nil return vals, nil
} }
@ -442,7 +442,7 @@ func (n *NEO) GetValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (ke
} }
func (n *NEO) getValidators(ic *interop.Context, _ []stackitem.Item) stackitem.Item { func (n *NEO) getValidators(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
result, err := n.GetValidatorsInternal(ic.Chain, ic.DAO) result, err := n.getValidatorsInternal(ic.Chain, ic.DAO)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -450,7 +450,7 @@ func (n *NEO) getValidators(ic *interop.Context, _ []stackitem.Item) stackitem.I
} }
func (n *NEO) getNextBlockValidators(ic *interop.Context, _ []stackitem.Item) stackitem.Item { func (n *NEO) getNextBlockValidators(ic *interop.Context, _ []stackitem.Item) stackitem.Item {
result, err := n.GetNextBlockValidatorsInternal(ic.Chain, ic.DAO) result, err := n.getNextBlockValidatorsInternal(ic.Chain, ic.DAO)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -459,9 +459,18 @@ func (n *NEO) getNextBlockValidators(ic *interop.Context, _ []stackitem.Item) st
// GetNextBlockValidatorsInternal returns next block validators. // GetNextBlockValidatorsInternal returns next block validators.
func (n *NEO) GetNextBlockValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) { func (n *NEO) GetNextBlockValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) {
pubs, err := n.getNextBlockValidatorsInternal(bc, d)
if err != nil {
return nil, err
}
return pubs.Copy(), nil
}
// getNextBlockValidatorsInternal returns next block validators.
func (n *NEO) getNextBlockValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) {
si := d.GetStorageItem(n.ContractID, nextValidatorsKey) si := d.GetStorageItem(n.ContractID, nextValidatorsKey)
if si == nil { if si == nil {
return n.GetValidatorsInternal(bc, d) return n.getValidatorsInternal(bc, d)
} }
pubs := keys.PublicKeys{} pubs := keys.PublicKeys{}
err := pubs.DecodeBytes(si.Value) err := pubs.DecodeBytes(si.Value)