2020-09-15 21:44:03 +00:00
|
|
|
package multisig
|
|
|
|
|
|
|
|
import (
|
2021-04-26 14:48:20 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-11-16 22:32:59 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2021-04-26 14:48:20 +00:00
|
|
|
"github.com/minio/blake2b-simd"
|
2020-11-04 01:25:53 +00:00
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
2020-09-15 21:44:03 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-09-21 20:13:38 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-15 21:44:03 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-11-08 05:53:13 +00:00
|
|
|
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
|
|
|
builtintypes "github.com/filecoin-project/go-state-types/builtin"
|
2023-09-21 15:37:02 +00:00
|
|
|
msig12 "github.com/filecoin-project/go-state-types/builtin/v12/multisig"
|
2022-11-08 05:53:13 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/cbor"
|
2022-12-13 23:02:34 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/manifest"
|
2021-04-26 14:48:20 +00:00
|
|
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
2020-09-28 20:13:18 +00:00
|
|
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
2021-01-16 07:00:14 +00:00
|
|
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
2021-04-23 12:29:46 +00:00
|
|
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
2021-05-06 05:44:11 +00:00
|
|
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
2021-09-15 15:22:25 +00:00
|
|
|
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
2021-11-04 15:59:29 +00:00
|
|
|
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
2020-09-15 21:44:03 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
2022-04-04 11:25:03 +00:00
|
|
|
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
|
2022-12-13 23:02:34 +00:00
|
|
|
if name != manifest.MultisigKey {
|
2022-04-04 11:30:42 +00:00
|
|
|
return nil, xerrors.Errorf("actor code is not multisig: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version8:
|
2022-04-04 11:30:42 +00:00
|
|
|
return load8(store, act.Head)
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version9:
|
|
|
|
return load9(store, act.Head)
|
|
|
|
|
2022-11-08 04:55:56 +00:00
|
|
|
case actorstypes.Version10:
|
|
|
|
return load10(store, act.Head)
|
|
|
|
|
2023-03-29 16:05:42 +00:00
|
|
|
case actorstypes.Version11:
|
|
|
|
return load11(store, act.Head)
|
|
|
|
|
2023-09-21 15:37:02 +00:00
|
|
|
case actorstypes.Version12:
|
|
|
|
return load12(store, act.Head)
|
|
|
|
|
2022-04-04 11:30:42 +00:00
|
|
|
}
|
2022-04-04 11:25:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 21:44:03 +00:00
|
|
|
switch act.Code {
|
2021-04-26 14:48:20 +00:00
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
case builtin0.MultisigActorCodeID:
|
2020-09-24 00:40:29 +00:00
|
|
|
return load0(store, act.Head)
|
2021-04-26 14:48:20 +00:00
|
|
|
|
2020-09-28 20:13:18 +00:00
|
|
|
case builtin2.MultisigActorCodeID:
|
|
|
|
return load2(store, act.Head)
|
2021-04-26 14:48:20 +00:00
|
|
|
|
2021-01-18 23:04:32 +00:00
|
|
|
case builtin3.MultisigActorCodeID:
|
|
|
|
return load3(store, act.Head)
|
2021-04-26 14:48:20 +00:00
|
|
|
|
2021-04-23 12:29:46 +00:00
|
|
|
case builtin4.MultisigActorCodeID:
|
|
|
|
return load4(store, act.Head)
|
2021-04-26 14:48:20 +00:00
|
|
|
|
2021-05-06 05:44:11 +00:00
|
|
|
case builtin5.MultisigActorCodeID:
|
|
|
|
return load5(store, act.Head)
|
|
|
|
|
2021-09-15 15:22:25 +00:00
|
|
|
case builtin6.MultisigActorCodeID:
|
|
|
|
return load6(store, act.Head)
|
|
|
|
|
2021-11-04 15:59:29 +00:00
|
|
|
case builtin7.MultisigActorCodeID:
|
|
|
|
return load7(store, act.Head)
|
|
|
|
|
2020-09-15 21:44:03 +00:00
|
|
|
}
|
2022-04-20 21:34:28 +00:00
|
|
|
|
2020-09-15 21:44:03 +00:00
|
|
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
|
|
|
}
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
func MakeState(store adt.Store, av actorstypes.Version, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) {
|
2021-05-15 01:11:23 +00:00
|
|
|
switch av {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2021-05-15 01:11:23 +00:00
|
|
|
return make0(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2021-05-15 01:11:23 +00:00
|
|
|
return make2(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2021-05-15 01:11:23 +00:00
|
|
|
return make3(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2021-05-15 01:11:23 +00:00
|
|
|
return make4(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2021-05-27 10:27:47 +00:00
|
|
|
return make5(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2021-09-15 15:22:25 +00:00
|
|
|
return make6(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2021-11-04 15:59:29 +00:00
|
|
|
return make7(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version8:
|
2022-03-01 03:57:40 +00:00
|
|
|
return make8(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version9:
|
|
|
|
return make9(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
|
2022-11-08 04:55:56 +00:00
|
|
|
case actorstypes.Version10:
|
|
|
|
return make10(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
|
2023-03-29 16:05:42 +00:00
|
|
|
case actorstypes.Version11:
|
|
|
|
return make11(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
|
2023-09-21 15:37:02 +00:00
|
|
|
case actorstypes.Version12:
|
|
|
|
return make12(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
|
2022-04-04 11:30:42 +00:00
|
|
|
}
|
2021-05-15 01:11:23 +00:00
|
|
|
return nil, xerrors.Errorf("unknown actor version %d", av)
|
|
|
|
}
|
|
|
|
|
2020-09-15 21:44:03 +00:00
|
|
|
type State interface {
|
|
|
|
cbor.Marshaler
|
|
|
|
|
2022-11-16 22:32:59 +00:00
|
|
|
Code() cid.Cid
|
|
|
|
ActorKey() string
|
|
|
|
ActorVersion() actorstypes.Version
|
|
|
|
|
2020-09-15 21:44:03 +00:00
|
|
|
LockedBalance(epoch abi.ChainEpoch) (abi.TokenAmount, error)
|
2020-09-23 05:19:43 +00:00
|
|
|
StartEpoch() (abi.ChainEpoch, error)
|
|
|
|
UnlockDuration() (abi.ChainEpoch, error)
|
|
|
|
InitialBalance() (abi.TokenAmount, error)
|
|
|
|
Threshold() (uint64, error)
|
|
|
|
Signers() ([]address.Address, error)
|
2020-09-21 20:13:38 +00:00
|
|
|
|
|
|
|
ForEachPendingTxn(func(id int64, txn Transaction) error) error
|
2020-11-04 01:25:53 +00:00
|
|
|
PendingTxnChanged(State) (bool, error)
|
|
|
|
|
|
|
|
transactions() (adt.Map, error)
|
|
|
|
decodeTransaction(val *cbg.Deferred) (Transaction, error)
|
2021-05-15 01:11:23 +00:00
|
|
|
GetState() interface{}
|
2020-09-15 21:44:03 +00:00
|
|
|
}
|
2020-09-21 20:13:38 +00:00
|
|
|
|
2023-09-21 15:37:02 +00:00
|
|
|
type Transaction = msig12.Transaction
|
2021-04-26 14:48:20 +00:00
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
var Methods = builtintypes.MethodsMultisig
|
2021-04-26 14:48:20 +00:00
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
func Message(version actorstypes.Version, from address.Address) MessageBuilder {
|
2021-04-26 14:48:20 +00:00
|
|
|
switch version {
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version0:
|
2021-04-26 14:48:20 +00:00
|
|
|
return message0{from}
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version2:
|
2021-04-26 14:48:20 +00:00
|
|
|
return message2{message0{from}}
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version3:
|
2021-04-26 14:48:20 +00:00
|
|
|
return message3{message0{from}}
|
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version4:
|
2021-04-26 14:48:20 +00:00
|
|
|
return message4{message0{from}}
|
2021-05-06 05:44:11 +00:00
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version5:
|
2021-05-06 05:44:11 +00:00
|
|
|
return message5{message0{from}}
|
2021-09-15 15:22:25 +00:00
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version6:
|
2021-09-15 15:22:25 +00:00
|
|
|
return message6{message0{from}}
|
2021-11-04 15:59:29 +00:00
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version7:
|
2021-11-04 15:59:29 +00:00
|
|
|
return message7{message0{from}}
|
2022-03-01 03:57:40 +00:00
|
|
|
|
2022-09-06 15:49:29 +00:00
|
|
|
case actorstypes.Version8:
|
2022-03-01 03:57:40 +00:00
|
|
|
return message8{message0{from}}
|
2022-09-06 15:49:29 +00:00
|
|
|
|
|
|
|
case actorstypes.Version9:
|
|
|
|
return message9{message0{from}}
|
2022-11-08 04:55:56 +00:00
|
|
|
|
|
|
|
case actorstypes.Version10:
|
|
|
|
return message10{message0{from}}
|
2023-03-29 16:05:42 +00:00
|
|
|
|
|
|
|
case actorstypes.Version11:
|
|
|
|
return message11{message0{from}}
|
2023-09-21 15:37:02 +00:00
|
|
|
|
|
|
|
case actorstypes.Version12:
|
|
|
|
return message12{message0{from}}
|
2021-04-26 14:48:20 +00:00
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("unsupported actors version: %d", version))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type MessageBuilder interface {
|
|
|
|
// Create a new multisig with the specified parameters.
|
|
|
|
Create(signers []address.Address, threshold uint64,
|
|
|
|
vestingStart, vestingDuration abi.ChainEpoch,
|
|
|
|
initialAmount abi.TokenAmount) (*types.Message, error)
|
|
|
|
|
|
|
|
// Propose a transaction to the given multisig.
|
|
|
|
Propose(msig, target address.Address, amt abi.TokenAmount,
|
|
|
|
method abi.MethodNum, params []byte) (*types.Message, error)
|
|
|
|
|
|
|
|
// Approve a multisig transaction. The "hash" is optional.
|
|
|
|
Approve(msig address.Address, txID uint64, hash *ProposalHashData) (*types.Message, error)
|
|
|
|
|
|
|
|
// Cancel a multisig transaction. The "hash" is optional.
|
|
|
|
Cancel(msig address.Address, txID uint64, hash *ProposalHashData) (*types.Message, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// this type is the same between v0 and v2
|
2023-09-21 15:37:02 +00:00
|
|
|
type ProposalHashData = msig12.ProposalHashData
|
|
|
|
type ProposeReturn = msig12.ProposeReturn
|
|
|
|
type ProposeParams = msig12.ProposeParams
|
|
|
|
type ApproveReturn = msig12.ApproveReturn
|
2021-04-26 14:48:20 +00:00
|
|
|
|
|
|
|
func txnParams(id uint64, data *ProposalHashData) ([]byte, error) {
|
2023-09-21 15:37:02 +00:00
|
|
|
params := msig12.TxnIDParams{ID: msig12.TxnID(id)}
|
2021-04-26 14:48:20 +00:00
|
|
|
if data != nil {
|
|
|
|
if data.Requester.Protocol() != address.ID {
|
|
|
|
return nil, xerrors.Errorf("proposer address must be an ID address, was %s", data.Requester)
|
|
|
|
}
|
|
|
|
if data.Value.Sign() == -1 {
|
|
|
|
return nil, xerrors.Errorf("proposal value must be non-negative, was %s", data.Value)
|
|
|
|
}
|
|
|
|
if data.To == address.Undef {
|
|
|
|
return nil, xerrors.Errorf("proposed destination address must be set")
|
|
|
|
}
|
|
|
|
pser, err := data.Serialize()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
hash := blake2b.Sum256(pser)
|
|
|
|
params.ProposalHash = hash[:]
|
|
|
|
}
|
|
|
|
|
|
|
|
return actors.SerializeParams(¶ms)
|
|
|
|
}
|
2022-11-16 22:32:59 +00:00
|
|
|
|
|
|
|
func AllCodes() []cid.Cid {
|
|
|
|
return []cid.Cid{
|
|
|
|
(&state0{}).Code(),
|
|
|
|
(&state2{}).Code(),
|
|
|
|
(&state3{}).Code(),
|
|
|
|
(&state4{}).Code(),
|
|
|
|
(&state5{}).Code(),
|
|
|
|
(&state6{}).Code(),
|
|
|
|
(&state7{}).Code(),
|
|
|
|
(&state8{}).Code(),
|
|
|
|
(&state9{}).Code(),
|
2022-11-22 18:03:02 +00:00
|
|
|
(&state10{}).Code(),
|
2023-03-29 16:05:42 +00:00
|
|
|
(&state11{}).Code(),
|
2023-09-21 15:37:02 +00:00
|
|
|
(&state12{}).Code(),
|
2022-11-16 22:32:59 +00:00
|
|
|
}
|
|
|
|
}
|