[#326] morph/balance: Provide interface to "transferX" method's invocations

Implement TransferX method on Balance contract client. Implement TransferX
method on Balance client's wrapper that encapsulates it's TransferX call.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-01-26 13:21:16 +03:00 committed by Alex Vanin
parent f7a9e43165
commit 20ad0ae82a
3 changed files with 110 additions and 0 deletions

View file

@ -28,17 +28,20 @@ var ErrNilClient = errors.New("balance contract client is nil")
type Option func(*cfg)
type cfg struct {
transferXMethod, // transferX method name for invocation
balanceOfMethod, // balanceOf method name for invocation
decimalsMethod string // decimals method name for invocation
}
const (
defaultTransferXMethod = "transferX" // default "transferX" method name
defaultBalanceOfMethod = "balanceOf" // default "balance of" method name
defaultDecimalsMethod = "decimals" // default decimals method name
)
func defaultConfig() *cfg {
return &cfg{
transferXMethod: defaultTransferXMethod,
balanceOfMethod: defaultBalanceOfMethod,
decimalsMethod: defaultDecimalsMethod,
}
@ -100,3 +103,17 @@ func WithDecimalsMethod(n string) Option {
}
}
}
// WithTransferXMethod returns a client constructor option that
// specifies the "transferX" method name.
//
// Ignores empty value.
//
// If option not provided, "transferX" is used.
func WithTransferXMethod(n string) Option {
return func(c *cfg) {
if n != "" {
c.transferXMethod = n
}
}
}