2022-09-06 15:49:29 +00:00
|
|
|
package multisig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
2022-11-08 05:53:13 +00:00
|
|
|
builtintypes "github.com/filecoin-project/go-state-types/builtin"
|
2023-03-29 16:05:42 +00:00
|
|
|
init11 "github.com/filecoin-project/go-state-types/builtin/v11/init"
|
2022-09-07 23:30:55 +00:00
|
|
|
multisig9 "github.com/filecoin-project/go-state-types/builtin/v9/multisig"
|
2022-12-13 23:02:34 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/manifest"
|
2022-09-06 15:49:29 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type message9 struct{ message0 }
|
|
|
|
|
|
|
|
func (m message9) Create(
|
|
|
|
signers []address.Address, threshold uint64,
|
|
|
|
unlockStart, unlockDuration abi.ChainEpoch,
|
|
|
|
initialAmount abi.TokenAmount,
|
|
|
|
) (*types.Message, error) {
|
|
|
|
|
|
|
|
lenAddrs := uint64(len(signers))
|
|
|
|
|
|
|
|
if lenAddrs < threshold {
|
|
|
|
return nil, xerrors.Errorf("cannot require signing of more addresses than provided for multisig")
|
|
|
|
}
|
|
|
|
|
|
|
|
if threshold == 0 {
|
|
|
|
threshold = lenAddrs
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.from == address.Undef {
|
|
|
|
return nil, xerrors.Errorf("must provide source address")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up constructor parameters for multisig
|
|
|
|
msigParams := &multisig9.ConstructorParams{
|
|
|
|
Signers: signers,
|
|
|
|
NumApprovalsThreshold: threshold,
|
|
|
|
UnlockDuration: unlockDuration,
|
|
|
|
StartEpoch: unlockStart,
|
|
|
|
}
|
|
|
|
|
|
|
|
enc, actErr := actors.SerializeParams(msigParams)
|
|
|
|
if actErr != nil {
|
|
|
|
return nil, actErr
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:02:34 +00:00
|
|
|
code, ok := actors.GetActorCodeID(actorstypes.Version9, manifest.MultisigKey)
|
2022-09-06 15:49:29 +00:00
|
|
|
if !ok {
|
|
|
|
return nil, xerrors.Errorf("failed to get multisig code ID")
|
|
|
|
}
|
|
|
|
|
|
|
|
// new actors are created by invoking 'exec' on the init actor with the constructor params
|
2023-03-29 16:05:42 +00:00
|
|
|
execParams := &init11.ExecParams{
|
2022-09-06 15:49:29 +00:00
|
|
|
CodeCID: code,
|
|
|
|
ConstructorParams: enc,
|
|
|
|
}
|
|
|
|
|
|
|
|
enc, actErr = actors.SerializeParams(execParams)
|
|
|
|
if actErr != nil {
|
|
|
|
return nil, actErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.Message{
|
|
|
|
To: init_.Address,
|
|
|
|
From: m.from,
|
2022-09-10 14:34:47 +00:00
|
|
|
Method: builtintypes.MethodsInit.Exec,
|
2022-09-06 15:49:29 +00:00
|
|
|
Params: enc,
|
|
|
|
Value: initialAmount,
|
|
|
|
}, nil
|
|
|
|
}
|