2020-09-30 19:30:02 +00:00
|
|
|
package multisig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
|
|
|
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
|
|
|
init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init"
|
|
|
|
multisig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig"
|
|
|
|
|
|
|
|
"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 message2 struct{ message0 }
|
|
|
|
|
|
|
|
func (m message2) 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 := &multisig2.ConstructorParams{
|
|
|
|
Signers: signers,
|
|
|
|
NumApprovalsThreshold: threshold,
|
|
|
|
UnlockDuration: unlockDuration,
|
|
|
|
StartEpoch: unlockStart,
|
|
|
|
}
|
|
|
|
|
|
|
|
enc, actErr := actors.SerializeParams(msigParams)
|
|
|
|
if actErr != nil {
|
|
|
|
return nil, actErr
|
|
|
|
}
|
|
|
|
|
2022-04-21 12:09:58 +00:00
|
|
|
actorCodeID := builtin2.MultisigActorCodeID
|
|
|
|
|
2020-09-30 19:30:02 +00:00
|
|
|
// new actors are created by invoking 'exec' on the init actor with the constructor params
|
|
|
|
execParams := &init2.ExecParams{
|
2022-04-21 12:09:58 +00:00
|
|
|
CodeCID: actorCodeID,
|
2020-09-30 19:30:02 +00:00
|
|
|
ConstructorParams: enc,
|
|
|
|
}
|
|
|
|
|
|
|
|
enc, actErr = actors.SerializeParams(execParams)
|
|
|
|
if actErr != nil {
|
|
|
|
return nil, actErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return &types.Message{
|
|
|
|
To: init_.Address,
|
|
|
|
From: m.from,
|
|
|
|
Method: builtin2.MethodsInit.Exec,
|
|
|
|
Params: enc,
|
|
|
|
Value: initialAmount,
|
|
|
|
}, nil
|
|
|
|
}
|