forked from TrueCloudLab/frostfs-node
[#365] settlement/basic: Implement asset distribution
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
4433448645
commit
8e741a277d
5 changed files with 155 additions and 11 deletions
44
pkg/innerring/processors/settlement/basic/util.go
Normal file
44
pkg/innerring/processors/settlement/basic/util.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package basic
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// NodeSizeTable is not thread safe, make sure it is accessed with external
|
||||
// locks or in single routine.
|
||||
type NodeSizeTable struct {
|
||||
prices map[string]uint64
|
||||
total uint64
|
||||
}
|
||||
|
||||
func (t *NodeSizeTable) Put(id []byte, avg uint64) {
|
||||
t.prices[string(id)] += avg
|
||||
t.total += avg
|
||||
}
|
||||
|
||||
func (t *NodeSizeTable) Total() *big.Int {
|
||||
return new(big.Int).SetUint64(t.total)
|
||||
}
|
||||
|
||||
func (t *NodeSizeTable) Iterate(f func([]byte, *big.Int)) {
|
||||
for k, v := range t.prices {
|
||||
n := new(big.Int).SetUint64(v)
|
||||
f([]byte(k), n)
|
||||
}
|
||||
}
|
||||
|
||||
func NewNodeSizeTable() *NodeSizeTable {
|
||||
return &NodeSizeTable{
|
||||
prices: make(map[string]uint64),
|
||||
}
|
||||
}
|
||||
|
||||
type nodeInfoWrapper []byte
|
||||
|
||||
func (nodeInfoWrapper) Price() *big.Int {
|
||||
panic("should not be used")
|
||||
}
|
||||
|
||||
func (n nodeInfoWrapper) PublicKey() []byte {
|
||||
return n
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue