rpc: move all top*FromStack
client functions to a separate file
Some of them are shared between multiple RPC client APIs, so let's keep them in a separate place for better maintainability.
This commit is contained in:
parent
30e7d9a8b0
commit
347f7ed576
4 changed files with 77 additions and 70 deletions
|
@ -3,14 +3,12 @@ package client
|
|||
// Various non-policy things from native contracts.
|
||||
|
||||
import (
|
||||
"crypto/elliptic"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
)
|
||||
|
||||
// GetOraclePrice invokes `getPrice` method on a native Oracle contract.
|
||||
|
@ -65,28 +63,3 @@ func (c *Client) GetDesignatedByRole(role noderoles.Role, index uint32) (keys.Pu
|
|||
}
|
||||
return topPublicKeysFromStack(result.Stack)
|
||||
}
|
||||
|
||||
// topPublicKeysFromStack returns the top array of public keys from stack.
|
||||
func topPublicKeysFromStack(st []stackitem.Item) (keys.PublicKeys, error) {
|
||||
index := len(st) - 1 // top stack element is last in the array
|
||||
var (
|
||||
pks keys.PublicKeys
|
||||
err error
|
||||
)
|
||||
items, ok := st[index].Value().([]stackitem.Item)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid stack item type: %s", st[index].Type())
|
||||
}
|
||||
pks = make(keys.PublicKeys, len(items))
|
||||
for i, item := range items {
|
||||
val, ok := item.Value().([]byte)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid array element #%d: %s", i, item.Type())
|
||||
}
|
||||
pks[i], err = keys.NewPublicKeyFromBytes(val, elliptic.P256())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return pks, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue