[#486] innerring: Use fee provider interface in invoke package

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-04-29 16:39:09 +03:00 committed by Alex Vanin
parent 1f3bb33db8
commit 91a1896b8b
7 changed files with 135 additions and 24 deletions

View file

@ -22,10 +22,14 @@ func AlphabetEmit(cli *client.Client, con util.Uint160) error {
}
// AlphabetVote invokes vote method on alphabet contract.
func AlphabetVote(cli *client.Client, con util.Uint160, epoch uint64, keys keys.PublicKeys) error {
func AlphabetVote(cli *client.Client, con util.Uint160, fee SideFeeProvider, epoch uint64, keys keys.PublicKeys) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), voteMethod, int64(epoch), keys)
}
return cli.NotaryInvoke(con, voteMethod, int64(epoch), keys)
}

View file

@ -32,11 +32,19 @@ const (
)
// Mint assets in contract.
func Mint(cli *client.Client, con util.Uint160, p *MintBurnParams) error {
func Mint(cli *client.Client, con util.Uint160, fee SideFeeProvider, p *MintBurnParams) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), mintMethod,
p.ScriptHash,
p.Amount,
p.Comment,
)
}
return cli.NotaryInvoke(con, mintMethod,
p.ScriptHash,
p.Amount,
@ -45,11 +53,19 @@ func Mint(cli *client.Client, con util.Uint160, p *MintBurnParams) error {
}
// Burn minted assets.
func Burn(cli *client.Client, con util.Uint160, p *MintBurnParams) error {
func Burn(cli *client.Client, con util.Uint160, fee SideFeeProvider, p *MintBurnParams) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), burnMethod,
p.ScriptHash,
p.Amount,
p.Comment,
)
}
return cli.NotaryInvoke(con, burnMethod,
p.ScriptHash,
p.Amount,
@ -58,11 +74,21 @@ func Burn(cli *client.Client, con util.Uint160, p *MintBurnParams) error {
}
// LockAsset invokes Lock method.
func LockAsset(cli *client.Client, con util.Uint160, p *LockParams) error {
func LockAsset(cli *client.Client, con util.Uint160, fee SideFeeProvider, p *LockParams) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), lockMethod,
p.ID,
p.User.BytesBE(),
p.LockAccount.BytesBE(),
p.Amount,
int64(p.Until),
)
}
return cli.NotaryInvoke(con, lockMethod,
p.ID,
p.User.BytesBE(),

View file

@ -5,10 +5,25 @@ import (
"crypto/ecdsa"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
type (
// SideFeeProvider is an interface that used by invoker package method to
// get extra fee for all non notary smart contract invocations in side chain.
SideFeeProvider interface {
SideChainFee() fixedn.Fixed8
}
// MainFeeProvider is an interface that used by invoker package method to
// get extra fee for all non notary smart contract invocations in main chain.
MainFeeProvider interface {
MainChainFee() fixedn.Fixed8
}
)
// InnerRingIndex returns index of the `key` in the inner ring list from sidechain
// along with total size of inner ring list. If key is not in the inner ring list,
// then returns `-1` as index.

View file

@ -14,7 +14,7 @@ type (
Signature []byte
}
// ContainerParams for container put invocation.
// RemoveContainerParams for container delete invocation.
RemoveContainerParams struct {
ContainerID []byte
Signature []byte
@ -27,11 +27,19 @@ const (
)
// RegisterContainer invokes Put method.
func RegisterContainer(cli *client.Client, con util.Uint160, p *ContainerParams) error {
func RegisterContainer(cli *client.Client, con util.Uint160, fee SideFeeProvider, p *ContainerParams) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), putContainerMethod,
p.Container,
p.Signature,
p.Key.Bytes(),
)
}
return cli.NotaryInvoke(con, putContainerMethod,
p.Container,
p.Signature,
@ -39,12 +47,19 @@ func RegisterContainer(cli *client.Client, con util.Uint160, p *ContainerParams)
)
}
// RegisterContainer invokes Delete method.
func RemoveContainer(cli *client.Client, con util.Uint160, p *RemoveContainerParams) error {
// RemoveContainer invokes Delete method.
func RemoveContainer(cli *client.Client, con util.Uint160, fee SideFeeProvider, p *RemoveContainerParams) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), deleteContainerMethod,
p.ContainerID,
p.Signature,
)
}
return cli.NotaryInvoke(con, deleteContainerMethod,
p.ContainerID,
p.Signature,

View file

@ -19,8 +19,8 @@ import (
)
// NewContainerClient creates wrapper to access data from container contract.
func NewContainerClient(cli *client.Client, contract util.Uint160) (*wrapContainer.Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, extraFee)
func NewContainerClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*wrapContainer.Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
if err != nil {
return nil, fmt.Errorf("can't create container static client: %w", err)
}
@ -34,8 +34,8 @@ func NewContainerClient(cli *client.Client, contract util.Uint160) (*wrapContain
}
// NewNetmapClient creates wrapper to access data from netmap contract.
func NewNetmapClient(cli *client.Client, contract util.Uint160) (*wrapNetmap.Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, extraFee)
func NewNetmapClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*wrapNetmap.Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
if err != nil {
return nil, fmt.Errorf("can't create netmap static client: %w", err)
}
@ -49,8 +49,8 @@ func NewNetmapClient(cli *client.Client, contract util.Uint160) (*wrapNetmap.Wra
}
// NewAuditClient creates wrapper to work with Audit contract.
func NewAuditClient(cli *client.Client, contract util.Uint160) (*auditWrapper.ClientWrapper, error) {
staticClient, err := client.NewStatic(cli, contract, extraFee)
func NewAuditClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*auditWrapper.ClientWrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
if err != nil {
return nil, err
}
@ -59,8 +59,8 @@ func NewAuditClient(cli *client.Client, contract util.Uint160) (*auditWrapper.Cl
}
// NewBalanceClient creates wrapper to work with Balance contract.
func NewBalanceClient(cli *client.Client, contract util.Uint160) (*balanceWrapper.Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, extraFee)
func NewBalanceClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*balanceWrapper.Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
if err != nil {
return nil, errors.Wrap(err, "could not create static client of Balance contract")
}
@ -74,8 +74,8 @@ func NewBalanceClient(cli *client.Client, contract util.Uint160) (*balanceWrappe
}
// NewReputationClient creates wrapper to work with reputation contract.
func NewReputationClient(cli *client.Client, contract util.Uint160) (*reputationWrapper.ClientWrapper, error) {
staticClient, err := client.NewStatic(cli, contract, 0)
func NewReputationClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*reputationWrapper.ClientWrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
if err != nil {
return nil, errors.Wrap(err, "could not create static client of reputation contract")
}

View file

@ -31,11 +31,20 @@ const (
)
// CashOutCheque invokes Cheque method.
func CashOutCheque(cli *client.Client, con util.Uint160, p *ChequeParams) error {
func CashOutCheque(cli *client.Client, con util.Uint160, fee MainFeeProvider, p *ChequeParams) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.MainChainFee(), chequeMethod,
p.ID,
p.User.BytesBE(),
p.Amount,
p.LockAccount.BytesBE(),
)
}
return cli.NotaryInvoke(con, chequeMethod,
p.ID,
p.User.BytesBE(),
@ -45,10 +54,14 @@ func CashOutCheque(cli *client.Client, con util.Uint160, p *ChequeParams) error
}
// AlphabetUpdate invokes alphabetUpdate method.
func AlphabetUpdate(cli *client.Client, con util.Uint160, id []byte, list keys.PublicKeys) error {
func AlphabetUpdate(cli *client.Client, con util.Uint160, fee MainFeeProvider, id []byte, list keys.PublicKeys) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.MainChainFee(), alphabetUpdateMethod, id, list)
}
return cli.NotaryInvoke(con, alphabetUpdateMethod, id, list)
}

View file

@ -28,6 +28,7 @@ const (
approvePeerMethod = "addPeer"
updatePeerStateMethod = "updateState"
setConfigMethod = "setConfig"
setInnerRingMethod = "updateInnerRing"
getNetmapSnapshotMethod = "netmap"
)
@ -51,29 +52,44 @@ func Epoch(cli *client.Client, con util.Uint160) (int64, error) {
}
// SetNewEpoch invokes newEpoch method.
func SetNewEpoch(cli *client.Client, con util.Uint160, epoch uint64) error {
func SetNewEpoch(cli *client.Client, con util.Uint160, fee SideFeeProvider, epoch uint64) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), setNewEpochMethod, int64(epoch))
}
return cli.NotaryInvoke(con, setNewEpochMethod, int64(epoch))
}
// ApprovePeer invokes addPeer method.
func ApprovePeer(cli *client.Client, con util.Uint160, peer []byte) error {
func ApprovePeer(cli *client.Client, con util.Uint160, fee SideFeeProvider, peer []byte) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), approvePeerMethod, peer)
}
return cli.NotaryInvoke(con, approvePeerMethod, peer)
}
// UpdatePeerState invokes addPeer method.
func UpdatePeerState(cli *client.Client, con util.Uint160, args *UpdatePeerArgs) error {
func UpdatePeerState(cli *client.Client, con util.Uint160, fee SideFeeProvider, args *UpdatePeerArgs) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), updatePeerStateMethod,
int64(args.Status.ToV2()),
args.Key.Bytes(),
)
}
return cli.NotaryInvoke(con, updatePeerStateMethod,
int64(args.Status.ToV2()),
args.Key.Bytes(),
@ -81,11 +97,19 @@ func UpdatePeerState(cli *client.Client, con util.Uint160, args *UpdatePeerArgs)
}
// SetConfig invokes setConfig method.
func SetConfig(cli *client.Client, con util.Uint160, args *SetConfigArgs) error {
func SetConfig(cli *client.Client, con util.Uint160, fee SideFeeProvider, args *SetConfigArgs) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), setConfigMethod,
args.ID,
args.Key,
args.Value,
)
}
return cli.NotaryInvoke(con, setConfigMethod,
args.ID,
args.Key,
@ -93,6 +117,20 @@ func SetConfig(cli *client.Client, con util.Uint160, args *SetConfigArgs) error
)
}
// SetInnerRing invokes update inner ring method. This should be used only
// without notary support.
func SetInnerRing(cli *client.Client, con util.Uint160, fee SideFeeProvider, list keys.PublicKeys) error {
if cli == nil {
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), setInnerRingMethod, list)
}
return cli.NotaryInvoke(con, setInnerRingMethod, list)
}
// NetmapSnapshot returns current netmap node infos.
// Consider using pkg/morph/client/netmap for this.
func NetmapSnapshot(cli *client.Client, con util.Uint160) (*netmap.Netmap, error) {