[#625] client/balance: remove intermediate wrapper

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-01-31 12:24:25 +03:00 committed by Alex Vanin
parent c7a8c762e0
commit 6f50fefbea
17 changed files with 239 additions and 524 deletions

View file

@ -2,7 +2,7 @@ package main
import (
accountingGRPC "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
accountingTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/accounting/grpc"
accountingService "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
accounting "github.com/nspcc-dev/neofs-node/pkg/services/accounting/morph"
@ -13,7 +13,7 @@ func initAccountingService(c *cfg) {
initMorphComponents(c)
}
balanceMorphWrapper, err := wrapper.NewFromMorph(c.cfgMorph.client, c.cfgAccounting.scriptHash, 0)
balanceMorphWrapper, err := balance.NewFromMorph(c.cfgMorph.client, c.cfgAccounting.scriptHash, 0)
fatalOnErr(err)
server := accountingTransportGRPC.New(

View file

@ -30,7 +30,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/metrics"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
balanceWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
balanceClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
cntWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
neofsWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper"
neofsidWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper"
@ -76,7 +76,7 @@ type (
precision precision.Fixed8Converter
auditClient *auditWrapper.ClientWrapper
healthStatus atomic.Value
balanceClient *balanceWrapper.Wrapper
balanceClient *balanceClient.Client
netmapClient *nmWrapper.Wrapper
persistate *state.PersistentStorage
@ -493,7 +493,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
return nil, err
}
server.balanceClient, err = balanceWrapper.NewFromMorph(server.morphClient, server.contracts.balance, fee, balanceWrapper.TryNotary(), balanceWrapper.AsAlphabet())
server.balanceClient, err = balanceClient.NewFromMorph(server.morphClient, server.contracts.balance, fee, balanceClient.TryNotary(), balanceClient.AsAlphabet())
if err != nil {
return nil, err
}

View file

@ -2,7 +2,7 @@ package neofs
import (
"github.com/nspcc-dev/neo-go/pkg/util"
balancewrp "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
neofsEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/neofs"
"go.uber.org/zap"
)
@ -20,7 +20,7 @@ func (np *Processor) processDeposit(deposit *neofsEvent.Deposit) {
return
}
prm := balancewrp.MintPrm{}
prm := balance.MintPrm{}
prm.SetTo(deposit.To())
prm.SetAmount(np.converter.ToBalancePrecision(deposit.Amount()))
@ -95,7 +95,7 @@ func (np *Processor) processWithdraw(withdraw *neofsEvent.Withdraw) {
curEpoch := np.epochState.EpochCounter()
prm := balancewrp.LockPrm{}
prm := balance.LockPrm{}
prm.SetID(withdraw.ID())
prm.SetUser(withdraw.User())
@ -117,7 +117,7 @@ func (np *Processor) processCheque(cheque *neofsEvent.Cheque) {
return
}
prm := balancewrp.BurnPrm{}
prm := balance.BurnPrm{}
prm.SetTo(cheque.LockAccount())
prm.SetAmount(np.converter.ToBalancePrecision(cheque.Amount()))

View file

@ -9,7 +9,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
balanceWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper"
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
@ -39,7 +39,7 @@ type (
log *zap.Logger
pool *ants.Pool
neofsContract util.Uint160
balanceClient *balanceWrapper.Wrapper
balanceClient *balance.Client
netmapClient *nmWrapper.Wrapper
morphClient *client.Client
epochState EpochState
@ -60,7 +60,7 @@ type (
PoolSize int
NeoFSContract util.Uint160
NeoFSIDClient *neofsid.ClientWrapper
BalanceClient *balanceWrapper.Wrapper
BalanceClient *balance.Client
NetmapClient *nmWrapper.Wrapper
MorphClient *client.Client
EpochState EpochState

View file

@ -15,7 +15,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/basic"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/common"
auditClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
balanceClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
balanceClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
containerClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
auditAPI "github.com/nspcc-dev/neofs-sdk-go/audit"
@ -46,7 +46,7 @@ type settlementDeps struct {
clientCache *ClientCache
balanceClient *balanceClient.Wrapper
balanceClient *balanceClient.Client
}
type auditSettlementDeps struct {

View file

@ -4,39 +4,22 @@ import (
"fmt"
"math/big"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-sdk-go/owner"
)
// GetBalanceOfArgs groups the arguments
// of "balance of" test invoke call.
type GetBalanceOfArgs struct {
wallet []byte // wallet script hash
}
// BalanceOf receives the amount of funds in the client's account
// through the Balance contract call, and returns it.
func (c *Client) BalanceOf(id *owner.ID) (*big.Int, error) {
h, err := address.StringToUint160(id.String())
if err != nil {
return nil, err
}
// GetBalanceOfValues groups the stack parameters
// returned by "balance of" test invoke.
type GetBalanceOfValues struct {
amount *big.Int // wallet funds amount
}
// SetWallet sets the wallet script hash
// in a binary format.
func (g *GetBalanceOfArgs) SetWallet(v []byte) {
g.wallet = v
}
// Amount returns the amount of funds.
func (g *GetBalanceOfValues) Amount() *big.Int {
return g.amount
}
// BalanceOf performs the test invoke of "balance of"
// method of NeoFS Balance contract.
func (c *Client) BalanceOf(args GetBalanceOfArgs) (*GetBalanceOfValues, error) {
invokePrm := client.TestInvokePrm{}
invokePrm.SetMethod(balanceOfMethod)
invokePrm.SetArgs(args.wallet)
invokePrm.SetArgs(h.BytesBE())
prms, err := c.client.TestInvoke(invokePrm)
if err != nil {
@ -49,8 +32,5 @@ func (c *Client) BalanceOf(args GetBalanceOfArgs) (*GetBalanceOfValues, error) {
if err != nil {
return nil, fmt.Errorf("could not get integer stack item from stack item (%s): %w", balanceOfMethod, err)
}
return &GetBalanceOfValues{
amount: amount,
}, nil
return amount, nil
}

View file

@ -0,0 +1,40 @@
package balance
import (
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
// BurnPrm groups parameters of Burn operation.
type BurnPrm struct {
to util.Uint160
amount int64
id []byte
client.InvokePrmOptional
}
// SetTo sets receiver.
func (b *BurnPrm) SetTo(to util.Uint160) {
b.to = to
}
// SetAmount sets amount.
func (b *BurnPrm) SetAmount(amount int64) {
b.amount = amount
}
// SetID sets ID
func (b *BurnPrm) SetID(id []byte) {
b.id = id
}
// Burn destroys funds from the account.
func (c *Client) Burn(p BurnPrm) error {
prm := client.InvokePrm{}
prm.SetMethod(burnMethod)
prm.SetArgs(p.to.BytesBE(), p.amount, p.id)
prm.InvokePrmOptional = p.InvokePrmOptional
return c.client.Invoke(prm)
}

View file

@ -1,6 +1,10 @@
package balance
import (
"fmt"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
@ -25,7 +29,49 @@ const (
decimalsMethod = "decimals"
)
// New creates, initializes and returns the Client instance.
func New(c *client.StaticClient) *Client {
return &Client{client: c}
// NewFromMorph returns the wrapper instance from the raw morph client.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*Client, error) {
o := defaultOpts()
for i := range opts {
opts[i](o)
}
staticClient, err := client.NewStatic(cli, contract, fee, ([]client.StaticClientOption)(*o)...)
if err != nil {
return nil, fmt.Errorf("could not create static client of Balance contract: %w", err)
}
return &Client{
client: staticClient,
}, nil
}
// Option allows to set an optional
// parameter of Wrapper.
type Option func(*opts)
type opts []client.StaticClientOption
func defaultOpts() *opts {
return new(opts)
}
// TryNotary returns option to enable
// notary invocation tries.
func TryNotary() Option {
return func(o *opts) {
*o = append(*o, client.TryNotary())
}
}
// AsAlphabet returns option to sign main TX
// of notary requests with client's private
// key.
//
// Considered to be used by IR nodes only.
func AsAlphabet() Option {
return func(o *opts) {
*o = append(*o, client.AsAlphabet())
}
}

View file

@ -6,42 +6,22 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
// DecimalsArgs groups the arguments
// of decimals test invoke call.
type DecimalsArgs struct {
}
// DecimalsValues groups the stack parameters
// returned by decimals test invoke.
type DecimalsValues struct {
decimals int64 // decimals value
}
// Decimals returns the decimals value.
func (d *DecimalsValues) Decimals() int64 {
return d.decimals
}
// Decimals performs the test invoke of decimals
// method of NeoFS Balance contract.
func (c *Client) Decimals(args DecimalsArgs) (*DecimalsValues, error) {
// Decimals decimal precision of currency transactions
// through the Balance contract call, and returns it.
func (c *Client) Decimals() (uint32, error) {
invokePrm := client.TestInvokePrm{}
invokePrm.SetMethod(decimalsMethod)
prms, err := c.client.TestInvoke(invokePrm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", decimalsMethod, err)
return 0, fmt.Errorf("could not perform test invocation (%s): %w", decimalsMethod, err)
} else if ln := len(prms); ln != 1 {
return nil, fmt.Errorf("unexpected stack item count (%s): %d", decimalsMethod, ln)
return 0, fmt.Errorf("unexpected stack item count (%s): %d", decimalsMethod, ln)
}
decimals, err := client.IntFromStackItem(prms[0])
if err != nil {
return nil, fmt.Errorf("could not get integer stack item from stack item (%s): %w", decimalsMethod, err)
return 0, fmt.Errorf("could not get integer stack item from stack item (%s): %w", decimalsMethod, err)
}
return &DecimalsValues{
decimals: decimals,
}, nil
return uint32(decimals), nil
}

View file

@ -0,0 +1,52 @@
package balance
import (
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
// LockPrm groups parameters of Lock operation.
type LockPrm struct {
id []byte
user util.Uint160
lock util.Uint160
amount int64
dueEpoch int64
client.InvokePrmOptional
}
// SetID sets ID.
func (l *LockPrm) SetID(id []byte) {
l.id = id
}
// SetUser set user.
func (l *LockPrm) SetUser(user util.Uint160) {
l.user = user
}
// SetLock sets lock.
func (l *LockPrm) SetLock(lock util.Uint160) {
l.lock = lock
}
// SetAmount sets amount.
func (l *LockPrm) SetAmount(amount int64) {
l.amount = amount
}
// SetDueEpoch sets end of the lock.
func (l *LockPrm) SetDueEpoch(dueEpoch int64) {
l.dueEpoch = dueEpoch
}
// Lock locks fund on the user account.
func (c *Client) Lock(p LockPrm) error {
prm := client.InvokePrm{}
prm.SetMethod(lockMethod)
prm.SetArgs(p.id, p.user.BytesBE(), p.lock.BytesBE(), p.amount, p.dueEpoch)
prm.InvokePrmOptional = p.InvokePrmOptional
return c.client.Invoke(prm)
}

View file

@ -0,0 +1,40 @@
package balance
import (
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
// MintPrm groups parameters of Mint operation.
type MintPrm struct {
to util.Uint160
amount int64
id []byte
client.InvokePrmOptional
}
// SetTo sets receiver of the transfer.
func (m *MintPrm) SetTo(to util.Uint160) {
m.to = to
}
// SetAmount sets amount of the transfer.
func (m *MintPrm) SetAmount(amount int64) {
m.amount = amount
}
// SetID sets ID.
func (m *MintPrm) SetID(id []byte) {
m.id = id
}
// Mint sends funds to the account.
func (c *Client) Mint(p MintPrm) error {
prm := client.InvokePrm{}
prm.SetMethod(mintMethod)
prm.SetArgs(p.to.BytesBE(), p.amount, p.id)
prm.InvokePrmOptional = p.InvokePrmOptional
return c.client.Invoke(prm)
}

View file

@ -3,177 +3,45 @@ package balance
import (
"fmt"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-sdk-go/owner"
)
// TransferXArgs groups the arguments
// of "transferX" invocation call.
type TransferXArgs struct {
amount int64 // amount in GASe-12
// TransferPrm groups parameters of TransferX method.
type TransferPrm struct {
Amount int64
sender []byte // sender's wallet script hash
From, To *owner.ID
recipient []byte // recipient's wallet script hash
details []byte // transfer details
Details []byte
client.InvokePrmOptional
}
// SetAmount sets amount of funds to transfer
// in GASe-12.
func (t *TransferXArgs) SetAmount(v int64) {
t.amount = v
}
// TransferX transfers p.Amount of GASe-12 from p.From to p.To
// with details p.Details through direct smart contract call.
//
// If TryNotary is provided, calls notary contract.
func (c *Client) TransferX(p TransferPrm) error {
from, err := address.StringToUint160(p.From.String())
if err != nil {
return err
}
// SetSender sets wallet script hash
// of the sender of funds in a binary format.
func (t *TransferXArgs) SetSender(v []byte) {
t.sender = v
}
to, err := address.StringToUint160(p.To.String())
if err != nil {
return err
}
// SetRecipient sets wallet script hash
// of the recipient of funds in a binary format.
func (t *TransferXArgs) SetRecipient(v []byte) {
t.recipient = v
}
// SetDetails sets details of the money transaction
// in a binary format.
func (t *TransferXArgs) SetDetails(v []byte) {
t.details = v
}
// TransferX directly invokes the call of "transferX" method
// of NeoFS Balance contract.
func (c *Client) TransferX(args TransferXArgs) error {
prm := client.InvokePrm{}
prm.SetMethod(transferXMethod)
prm.SetArgs(args.sender, args.recipient, args.amount, args.details)
prm.InvokePrmOptional = args.InvokePrmOptional
prm.SetArgs(from.BytesBE(), to.BytesBE(), p.Amount, p.Details)
prm.InvokePrmOptional = p.InvokePrmOptional
err := c.client.Invoke(prm)
err = c.client.Invoke(prm)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", transferXMethod, err)
}
return nil
}
// MintPrm groups parameters of Mint operation.
type MintPrm struct {
to []byte
amount int64
id []byte
client.InvokePrmOptional
}
// SetTo sets receiver of the transfer.
func (m *MintPrm) SetTo(to []byte) {
m.to = to
}
// SetAmount sets amount of the transfer.
func (m *MintPrm) SetAmount(amount int64) {
m.amount = amount
}
// SetID sets ID.
func (m *MintPrm) SetID(id []byte) {
m.id = id
}
// Mint invokes `mint` method of the balance contract.
func (c *Client) Mint(args MintPrm) error {
prm := client.InvokePrm{}
prm.SetMethod(mintMethod)
prm.SetArgs(args.to, args.amount, args.id)
prm.InvokePrmOptional = args.InvokePrmOptional
return c.client.Invoke(prm)
}
// BurnPrm groups parameters of Burn operation.
type BurnPrm struct {
to []byte
amount int64
id []byte
client.InvokePrmOptional
}
// SetTo sets receiver.
func (b *BurnPrm) SetTo(to []byte) {
b.to = to
}
// SetAmount sets amount.
func (b *BurnPrm) SetAmount(amount int64) {
b.amount = amount
}
// SetID sets ID.
func (b *BurnPrm) SetID(id []byte) {
b.id = id
}
// Burn invokes `burn` method of the balance contract.
func (c *Client) Burn(args BurnPrm) error {
prm := client.InvokePrm{}
prm.SetMethod(burnMethod)
prm.SetArgs(args.to, args.amount, args.id)
prm.InvokePrmOptional = args.InvokePrmOptional
return c.client.Invoke(prm)
}
// LockPrm groups parameters of Lock operation.
type LockPrm struct {
id []byte
user []byte
lock []byte
amount int64
dueEpoch int64
client.InvokePrmOptional
}
// SetID sets ID.
func (l *LockPrm) SetID(id []byte) {
l.id = id
}
// SetUser set user.
func (l *LockPrm) SetUser(user []byte) {
l.user = user
}
// SetLock sets lock.
func (l *LockPrm) SetLock(lock []byte) {
l.lock = lock
}
// SetAmount sets amount.
func (l *LockPrm) SetAmount(amount int64) {
l.amount = amount
}
// SetDueEpoch sets end of the lock.
func (l *LockPrm) SetDueEpoch(dueEpoch int64) {
l.dueEpoch = dueEpoch
}
// Lock invokes `lock` method of the balance contract.
func (c *Client) Lock(args LockPrm) error {
prm := client.InvokePrm{}
prm.SetMethod(lockMethod)
prm.SetArgs(args.id, args.user, args.lock, args.amount, args.dueEpoch)
prm.InvokePrmOptional = args.InvokePrmOptional
return c.client.Invoke(prm)
}

View file

@ -1,28 +0,0 @@
package wrapper
import (
"math/big"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
"github.com/nspcc-dev/neofs-sdk-go/owner"
)
// BalanceOf receives the amount of funds in the client's account
// through the Balance contract call, and returns it.
func (w *Wrapper) BalanceOf(id *owner.ID) (*big.Int, error) {
h, err := address.StringToUint160(id.String())
if err != nil {
return nil, err
}
args := balance.GetBalanceOfArgs{}
args.SetWallet(h.BytesBE())
result, err := w.client.BalanceOf(args)
if err != nil {
return nil, err
}
return result.Amount(), nil
}

View file

@ -1,22 +0,0 @@
package wrapper
import (
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
)
// Decimals decimal precision of currency transactions
// through the Balance contract call, and returns it.
func (w *Wrapper) Decimals() (uint32, error) {
// prepare invocation arguments
args := balance.DecimalsArgs{}
// invoke smart contract call
values, err := w.client.Decimals(args)
if err != nil {
return 0, fmt.Errorf("could not invoke smart contract: %w", err)
}
return uint32(values.Decimals()), nil
}

View file

@ -1,167 +0,0 @@
package wrapper
import (
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
"github.com/nspcc-dev/neofs-sdk-go/owner"
)
// TransferPrm groups parameters of TransferX method.
type TransferPrm struct {
Amount int64
From, To *owner.ID
Details []byte
client.InvokePrmOptional
}
// TransferX transfers p.Amount of GASe-12 from p.From to p.To
// with details p.Details through direct smart contract call.
//
// If TryNotary is provided, calls notary contract.
func (w *Wrapper) TransferX(p TransferPrm) error {
from, err := address.StringToUint160(p.From.String())
if err != nil {
return err
}
to, err := address.StringToUint160(p.To.String())
if err != nil {
return err
}
// prepare invocation arguments
args := balance.TransferXArgs{}
args.SetSender(from.BytesBE())
args.SetRecipient(to.BytesBE())
args.SetAmount(p.Amount)
args.SetDetails(p.Details)
args.InvokePrmOptional = p.InvokePrmOptional
return w.client.TransferX(args)
}
// MintPrm groups parameters of Mint operation.
type MintPrm struct {
to util.Uint160
amount int64
id []byte
client.InvokePrmOptional
}
// SetTo sets receiver of the transfer.
func (m *MintPrm) SetTo(to util.Uint160) {
m.to = to
}
// SetAmount sets amount of the transfer.
func (m *MintPrm) SetAmount(amount int64) {
m.amount = amount
}
// SetID sets ID.
func (m *MintPrm) SetID(id []byte) {
m.id = id
}
// Mint sends funds to the account.
func (w *Wrapper) Mint(prm MintPrm) error {
args := balance.MintPrm{}
args.SetTo(prm.to.BytesBE())
args.SetAmount(prm.amount)
args.SetID(prm.id)
args.InvokePrmOptional = prm.InvokePrmOptional
return w.client.Mint(args)
}
// BurnPrm groups parameters of Burn operation.
type BurnPrm struct {
to util.Uint160
amount int64
id []byte
client.InvokePrmOptional
}
// SetTo sets receiver.
func (b *BurnPrm) SetTo(to util.Uint160) {
b.to = to
}
// SetAmount sets amount.
func (b *BurnPrm) SetAmount(amount int64) {
b.amount = amount
}
// SetID sets ID
func (b *BurnPrm) SetID(id []byte) {
b.id = id
}
// Burn destroys funds from the account.
func (w *Wrapper) Burn(prm BurnPrm) error {
args := balance.BurnPrm{}
args.SetTo(prm.to.BytesBE())
args.SetAmount(prm.amount)
args.SetID(prm.id)
args.InvokePrmOptional = prm.InvokePrmOptional
return w.client.Burn(args)
}
// LockPrm groups parameters of Lock operation.
type LockPrm struct {
id []byte
user util.Uint160
lock util.Uint160
amount int64
dueEpoch int64
client.InvokePrmOptional
}
// SetID sets ID.
func (l *LockPrm) SetID(id []byte) {
l.id = id
}
// SetUser set user.
func (l *LockPrm) SetUser(user util.Uint160) {
l.user = user
}
// SetLock sets lock.
func (l *LockPrm) SetLock(lock util.Uint160) {
l.lock = lock
}
// SetAmount sets amount.
func (l *LockPrm) SetAmount(amount int64) {
l.amount = amount
}
// SetDueEpoch sets end of the lock.
func (l *LockPrm) SetDueEpoch(dueEpoch int64) {
l.dueEpoch = dueEpoch
}
// Lock locks fund on the user account.
func (w *Wrapper) Lock(prm LockPrm) error {
args := balance.LockPrm{}
args.SetID(prm.id)
args.SetUser(prm.user.BytesBE())
args.SetLock(prm.lock.BytesBE())
args.SetAmount(prm.amount)
args.SetDueEpoch(prm.dueEpoch)
args.InvokePrmOptional = prm.InvokePrmOptional
return w.client.Lock(args)
}

View file

@ -1,74 +0,0 @@
package wrapper
import (
"fmt"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/internal"
)
// Wrapper is a wrapper over balance contract
// client which implements:
// * tool for obtaining the amount of funds in the client's account;
// * tool for obtaining decimal precision of currency transactions.
//
// Working wrapper must be created via constructor New.
// Using the Wrapper that has been created with new(Wrapper)
// expression (or just declaring a Wrapper variable) is unsafe
// and can lead to panic.
type Wrapper struct {
internal.StaticClient
client *balance.Client
}
// Option allows to set an optional
// parameter of Wrapper.
type Option func(*opts)
type opts []client.StaticClientOption
func defaultOpts() *opts {
return new(opts)
}
// TryNotary returns option to enable
// notary invocation tries.
func TryNotary() Option {
return func(o *opts) {
*o = append(*o, client.TryNotary())
}
}
// AsAlphabet returns option to sign main TX
// of notary requests with client's private
// key.
//
// Considered to be used by IR nodes only.
func AsAlphabet() Option {
return func(o *opts) {
*o = append(*o, client.AsAlphabet())
}
}
// NewFromMorph returns the wrapper instance from the raw morph client.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*Wrapper, error) {
o := defaultOpts()
for i := range opts {
opts[i](o)
}
staticClient, err := client.NewStatic(cli, contract, fee, ([]client.StaticClientOption)(*o)...)
if err != nil {
return nil, fmt.Errorf("could not create static client of Balance contract: %w", err)
}
return &Wrapper{
StaticClient: staticClient,
client: balance.New(staticClient),
}, nil
}

View file

@ -4,16 +4,16 @@ import (
"context"
"github.com/nspcc-dev/neofs-api-go/v2/accounting"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
accountingSvc "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
"github.com/nspcc-dev/neofs-sdk-go/owner"
)
type morphExecutor struct {
client *wrapper.Wrapper
client *balance.Client
}
func NewExecutor(client *wrapper.Wrapper) accountingSvc.ServiceExecutor {
func NewExecutor(client *balance.Client) accountingSvc.ServiceExecutor {
return &morphExecutor{
client: client,
}