[#122] Add converter interface in balance and neofs processors
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
b6012977bc
commit
90984ee219
4 changed files with 24 additions and 4 deletions
|
@ -17,7 +17,7 @@ func (bp *Processor) processLock(lock *balanceEvent.Lock) {
|
|||
err := invoke.CashOutCheque(bp.mainnetClient, bp.neofsContract,
|
||||
&invoke.ChequeParams{
|
||||
ID: lock.ID(),
|
||||
Amount: lock.Amount() / 1_0000_0000, // Fixed16 to Fixed8
|
||||
Amount: bp.converter.ToFixed8(lock.Amount()),
|
||||
User: lock.User(),
|
||||
LockAccount: lock.LockAccount(),
|
||||
})
|
||||
|
|
|
@ -16,6 +16,11 @@ type (
|
|||
IsActive() bool
|
||||
}
|
||||
|
||||
// PrecisionConverter converts balance amount values.
|
||||
PrecisionConverter interface {
|
||||
ToFixed8(int64) int64
|
||||
}
|
||||
|
||||
// Processor of events produced by balance contract in morph chain.
|
||||
Processor struct {
|
||||
log *zap.Logger
|
||||
|
@ -24,6 +29,7 @@ type (
|
|||
balanceContract util.Uint160
|
||||
mainnetClient *client.Client
|
||||
activeState ActiveState
|
||||
converter PrecisionConverter
|
||||
}
|
||||
|
||||
// Params of the processor constructor.
|
||||
|
@ -34,6 +40,7 @@ type (
|
|||
BalanceContract util.Uint160
|
||||
MainnetClient *client.Client
|
||||
ActiveState ActiveState
|
||||
Converter PrecisionConverter
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -50,6 +57,8 @@ func New(p *Params) (*Processor, error) {
|
|||
return nil, errors.New("ir/balance: neo:mainnet client is not set")
|
||||
case p.ActiveState == nil:
|
||||
return nil, errors.New("ir/balance: global state is not set")
|
||||
case p.Converter == nil:
|
||||
return nil, errors.New("ir/balance: balance precision converter is not set")
|
||||
}
|
||||
|
||||
p.Log.Debug("balance worker pool", zap.Int("size", p.PoolSize))
|
||||
|
@ -66,6 +75,7 @@ func New(p *Params) (*Processor, error) {
|
|||
balanceContract: p.BalanceContract,
|
||||
mainnetClient: p.MainnetClient,
|
||||
activeState: p.ActiveState,
|
||||
converter: p.Converter,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ func (np *Processor) processDeposit(deposit *neofsEvent.Deposit) {
|
|||
err := invoke.Mint(np.morphClient, np.balanceContract,
|
||||
&invoke.MintBurnParams{
|
||||
ScriptHash: deposit.To().BytesBE(),
|
||||
Amount: deposit.Amount() * 1_0000_0000, // from Fixed8 to Fixed16
|
||||
Amount: np.converter.ToBalancePrecision(deposit.Amount()),
|
||||
Comment: append([]byte(txLogPrefix), deposit.ID()...),
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -69,7 +69,7 @@ func (np *Processor) processWithdraw(withdraw *neofsEvent.Withdraw) {
|
|||
ID: withdraw.ID(),
|
||||
User: withdraw.User(),
|
||||
LockAccount: lock,
|
||||
Amount: withdraw.Amount() * 1_0000_0000, // from Fixed8 to Fixed16
|
||||
Amount: np.converter.ToBalancePrecision(withdraw.Amount()),
|
||||
Until: curEpoch + lockAccountLifetime,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -88,7 +88,7 @@ func (np *Processor) processCheque(cheque *neofsEvent.Cheque) {
|
|||
err := invoke.Burn(np.morphClient, np.balanceContract,
|
||||
&invoke.MintBurnParams{
|
||||
ScriptHash: cheque.LockAccount().BytesBE(),
|
||||
Amount: cheque.Amount() * 1_0000_0000, // from Fixed8 to Fixed16
|
||||
Amount: np.converter.ToBalancePrecision(cheque.Amount()),
|
||||
Comment: append([]byte(txLogPrefix), cheque.ID()...),
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -21,6 +21,11 @@ type (
|
|||
IsActive() bool
|
||||
}
|
||||
|
||||
// PrecisionConverter converts balance amount values.
|
||||
PrecisionConverter interface {
|
||||
ToBalancePrecision(int64) int64
|
||||
}
|
||||
|
||||
// Processor of events produced by neofs contract in main net.
|
||||
Processor struct {
|
||||
log *zap.Logger
|
||||
|
@ -31,6 +36,7 @@ type (
|
|||
morphClient *client.Client
|
||||
epochState EpochState
|
||||
activeState ActiveState
|
||||
converter PrecisionConverter
|
||||
}
|
||||
|
||||
// Params of the processor constructor.
|
||||
|
@ -43,6 +49,7 @@ type (
|
|||
MorphClient *client.Client
|
||||
EpochState EpochState
|
||||
ActiveState ActiveState
|
||||
Converter PrecisionConverter
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -65,6 +72,8 @@ func New(p *Params) (*Processor, error) {
|
|||
return nil, errors.New("ir/neofs: global state is not set")
|
||||
case p.ActiveState == nil:
|
||||
return nil, errors.New("ir/neofs: global state is not set")
|
||||
case p.Converter == nil:
|
||||
return nil, errors.New("ir/neofs: balance precision converter is not set")
|
||||
}
|
||||
|
||||
p.Log.Debug("neofs worker pool", zap.Int("size", p.PoolSize))
|
||||
|
@ -83,6 +92,7 @@ func New(p *Params) (*Processor, error) {
|
|||
morphClient: p.MorphClient,
|
||||
epochState: p.EpochState,
|
||||
activeState: p.ActiveState,
|
||||
converter: p.Converter,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue