native: hide native contract methods
Copy public keys when returning them to the outside and hide unused `GetValidators` method.
This commit is contained in:
parent
8c18142e8a
commit
f007cca80b
2 changed files with 16 additions and 7 deletions
|
@ -91,7 +91,7 @@ func (g *GAS) OnPersist(ic *interop.Context) error {
|
|||
absAmount := big.NewInt(int64(tx.SystemFee + tx.NetworkFee))
|
||||
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 {
|
||||
return fmt.Errorf("cannot get block validators: %v", err)
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ func (n *NEO) Initialize(ic *interop.Context) error {
|
|||
|
||||
// OnPersist implements Contract interface.
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
@ -385,8 +385,8 @@ func (n *NEO) getRegisteredValidatorsCall(ic *interop.Context, _ []stackitem.Ite
|
|||
return stackitem.NewArray(arr)
|
||||
}
|
||||
|
||||
// GetValidatorsInternal returns a list of current validators.
|
||||
func (n *NEO) GetValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) {
|
||||
// getValidatorsInternal returns a list of current validators.
|
||||
func (n *NEO) getValidatorsInternal(bc blockchainer.Blockchainer, d dao.DAO) (keys.PublicKeys, error) {
|
||||
if vals := n.validators.Load().(keys.PublicKeys); 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 {
|
||||
result, err := n.GetValidatorsInternal(ic.Chain, ic.DAO)
|
||||
result, err := n.getValidatorsInternal(ic.Chain, ic.DAO)
|
||||
if err != nil {
|
||||
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 {
|
||||
result, err := n.GetNextBlockValidatorsInternal(ic.Chain, ic.DAO)
|
||||
result, err := n.getNextBlockValidatorsInternal(ic.Chain, ic.DAO)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -459,9 +459,18 @@ func (n *NEO) getNextBlockValidators(ic *interop.Context, _ []stackitem.Item) st
|
|||
|
||||
// GetNextBlockValidatorsInternal returns next block validators.
|
||||
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)
|
||||
if si == nil {
|
||||
return n.GetValidatorsInternal(bc, d)
|
||||
return n.getValidatorsInternal(bc, d)
|
||||
}
|
||||
pubs := keys.PublicKeys{}
|
||||
err := pubs.DecodeBytes(si.Value)
|
||||
|
|
Loading…
Reference in a new issue