diff --git a/cmd/neofs-node/accounting.go b/cmd/neofs-node/accounting.go index ec2289fc..21cac4e4 100644 --- a/cmd/neofs-node/accounting.go +++ b/cmd/neofs-node/accounting.go @@ -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( diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index dc2bbf48..d7cdc82d 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -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 } diff --git a/pkg/innerring/processors/neofs/process_assets.go b/pkg/innerring/processors/neofs/process_assets.go index 099961ff..f3b01392 100644 --- a/pkg/innerring/processors/neofs/process_assets.go +++ b/pkg/innerring/processors/neofs/process_assets.go @@ -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())) diff --git a/pkg/innerring/processors/neofs/processor.go b/pkg/innerring/processors/neofs/processor.go index d382d926..1491256b 100644 --- a/pkg/innerring/processors/neofs/processor.go +++ b/pkg/innerring/processors/neofs/processor.go @@ -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 diff --git a/pkg/innerring/settlement.go b/pkg/innerring/settlement.go index 3c9cf94c..e63cae93 100644 --- a/pkg/innerring/settlement.go +++ b/pkg/innerring/settlement.go @@ -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 { diff --git a/pkg/morph/client/balance/balanceOf.go b/pkg/morph/client/balance/balanceOf.go index f554bf75..c3aec323 100644 --- a/pkg/morph/client/balance/balanceOf.go +++ b/pkg/morph/client/balance/balanceOf.go @@ -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 } diff --git a/pkg/morph/client/balance/burn.go b/pkg/morph/client/balance/burn.go new file mode 100644 index 00000000..b86807c6 --- /dev/null +++ b/pkg/morph/client/balance/burn.go @@ -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) +} diff --git a/pkg/morph/client/balance/client.go b/pkg/morph/client/balance/client.go index 2cede646..3c363f9c 100644 --- a/pkg/morph/client/balance/client.go +++ b/pkg/morph/client/balance/client.go @@ -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()) + } } diff --git a/pkg/morph/client/balance/decimals.go b/pkg/morph/client/balance/decimals.go index a09fae2a..19110e3a 100644 --- a/pkg/morph/client/balance/decimals.go +++ b/pkg/morph/client/balance/decimals.go @@ -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 } diff --git a/pkg/morph/client/balance/lock.go b/pkg/morph/client/balance/lock.go new file mode 100644 index 00000000..34042c10 --- /dev/null +++ b/pkg/morph/client/balance/lock.go @@ -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) +} diff --git a/pkg/morph/client/balance/mint.go b/pkg/morph/client/balance/mint.go new file mode 100644 index 00000000..c7a89b50 --- /dev/null +++ b/pkg/morph/client/balance/mint.go @@ -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) +} diff --git a/pkg/morph/client/balance/transfer.go b/pkg/morph/client/balance/transfer.go index f5e0ba77..8c9330c4 100644 --- a/pkg/morph/client/balance/transfer.go +++ b/pkg/morph/client/balance/transfer.go @@ -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) -} diff --git a/pkg/morph/client/balance/wrapper/balanceOf.go b/pkg/morph/client/balance/wrapper/balanceOf.go deleted file mode 100644 index 69943346..00000000 --- a/pkg/morph/client/balance/wrapper/balanceOf.go +++ /dev/null @@ -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 -} diff --git a/pkg/morph/client/balance/wrapper/decimals.go b/pkg/morph/client/balance/wrapper/decimals.go deleted file mode 100644 index 2cb8cb6c..00000000 --- a/pkg/morph/client/balance/wrapper/decimals.go +++ /dev/null @@ -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 -} diff --git a/pkg/morph/client/balance/wrapper/transfer.go b/pkg/morph/client/balance/wrapper/transfer.go deleted file mode 100644 index 35541f89..00000000 --- a/pkg/morph/client/balance/wrapper/transfer.go +++ /dev/null @@ -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) -} diff --git a/pkg/morph/client/balance/wrapper/wrapper.go b/pkg/morph/client/balance/wrapper/wrapper.go deleted file mode 100644 index 1fc8990f..00000000 --- a/pkg/morph/client/balance/wrapper/wrapper.go +++ /dev/null @@ -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 -} diff --git a/pkg/services/accounting/morph/executor.go b/pkg/services/accounting/morph/executor.go index bd6dc2e7..3660a29e 100644 --- a/pkg/services/accounting/morph/executor.go +++ b/pkg/services/accounting/morph/executor.go @@ -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, }