2021-02-01 16:17:16 +00:00
|
|
|
package basic
|
|
|
|
|
|
|
|
import (
|
2021-02-02 13:45:13 +00:00
|
|
|
"math/big"
|
2021-02-01 16:17:16 +00:00
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/common"
|
2022-01-31 13:34:01 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
|
2022-09-28 07:41:01 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2022-05-17 13:59:46 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/user"
|
2021-02-01 16:17:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
EstimationFetcher interface {
|
2022-01-31 13:34:01 +00:00
|
|
|
Estimations(uint64) ([]*container.Estimations, error)
|
2021-02-01 16:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RateFetcher interface {
|
2021-02-02 11:12:41 +00:00
|
|
|
BasicRate() (uint64, error)
|
2021-02-01 16:17:16 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 12:03:55 +00:00
|
|
|
// BalanceFetcher uses NEP-17 compatible balance contract.
|
2021-02-02 13:45:13 +00:00
|
|
|
BalanceFetcher interface {
|
2022-05-31 17:00:41 +00:00
|
|
|
Balance(id user.ID) (*big.Int, error)
|
2021-02-02 13:45:13 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 16:17:16 +00:00
|
|
|
IncomeSettlementContext struct {
|
|
|
|
mu sync.Mutex // lock to prevent collection and distribution in the same time
|
|
|
|
|
2022-09-28 07:41:01 +00:00
|
|
|
log *logger.Logger
|
2021-02-01 16:17:16 +00:00
|
|
|
epoch uint64
|
|
|
|
|
|
|
|
rate RateFetcher
|
|
|
|
estimations EstimationFetcher
|
2021-02-02 13:45:13 +00:00
|
|
|
balances BalanceFetcher
|
2021-02-01 16:17:16 +00:00
|
|
|
container common.ContainerStorage
|
|
|
|
placement common.PlacementCalculator
|
|
|
|
exchange common.Exchanger
|
2021-02-02 17:23:01 +00:00
|
|
|
accounts common.AccountStorage
|
2021-02-01 16:17:16 +00:00
|
|
|
|
2022-05-17 13:59:46 +00:00
|
|
|
bankOwner user.ID
|
2021-02-02 17:23:01 +00:00
|
|
|
|
|
|
|
// this table is not thread safe, make sure you use it with mu.Lock()
|
|
|
|
distributeTable *NodeSizeTable
|
2021-02-01 16:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IncomeSettlementContextPrms struct {
|
2022-09-28 07:41:01 +00:00
|
|
|
Log *logger.Logger
|
2021-02-01 16:17:16 +00:00
|
|
|
Epoch uint64
|
|
|
|
Rate RateFetcher
|
|
|
|
Estimations EstimationFetcher
|
2021-02-02 13:45:13 +00:00
|
|
|
Balances BalanceFetcher
|
2021-02-01 16:17:16 +00:00
|
|
|
Container common.ContainerStorage
|
|
|
|
Placement common.PlacementCalculator
|
|
|
|
Exchange common.Exchanger
|
2021-02-02 17:23:01 +00:00
|
|
|
Accounts common.AccountStorage
|
2021-02-01 16:17:16 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-05-17 13:59:46 +00:00
|
|
|
func NewIncomeSettlementContext(p *IncomeSettlementContextPrms) *IncomeSettlementContext {
|
|
|
|
res := &IncomeSettlementContext{
|
2021-02-02 17:23:01 +00:00
|
|
|
log: p.Log,
|
|
|
|
epoch: p.Epoch,
|
|
|
|
rate: p.Rate,
|
|
|
|
estimations: p.Estimations,
|
|
|
|
balances: p.Balances,
|
|
|
|
container: p.Container,
|
|
|
|
placement: p.Placement,
|
|
|
|
exchange: p.Exchange,
|
|
|
|
accounts: p.Accounts,
|
|
|
|
distributeTable: NewNodeSizeTable(),
|
2022-05-17 13:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res.bankOwner.SetScriptHash(util.Uint160{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})
|
|
|
|
|
|
|
|
return res
|
2021-02-01 16:17:16 +00:00
|
|
|
}
|