/
multisig_state.go
45 lines (37 loc) · 1.19 KB
/
multisig_state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package multisig
import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/ipfs/go-cid"
)
type State struct {
Signers []address.Address // Signers must be canonical ID-addresses.
NumApprovalsThreshold uint64
NextTxnID TxnID
// Linear unlock
InitialBalance abi.TokenAmount
StartEpoch abi.ChainEpoch
UnlockDuration abi.ChainEpoch
PendingTxns cid.Cid // HAMT[TxnID]Transaction
}
func (st *State) AmountLocked(elapsedEpoch abi.ChainEpoch) abi.TokenAmount {
if elapsedEpoch >= st.UnlockDuration {
return abi.NewTokenAmount(0)
}
if elapsedEpoch <= 0 {
return st.InitialBalance
}
unlockDuration := big.NewInt(int64(st.UnlockDuration))
remainingLockDuration := big.Sub(unlockDuration, big.NewInt(int64(elapsedEpoch)))
// locked = ceil(InitialBalance * remainingLockDuration / UnlockDuration)
numerator := big.Mul(st.InitialBalance, remainingLockDuration)
denominator := unlockDuration
quot := big.Div(numerator, denominator)
rem := big.Mod(numerator, denominator)
locked := quot
if !rem.IsZero() {
locked = big.Add(locked, big.NewInt(1))
}
return locked
}