package multisig import ( "fmt" "github.com/minio/blake2b-simd" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" multisig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" ) func Message(version actors.Version, from address.Address) MessageBuilder { switch version { case actors.Version0: return message0{from} case actors.Version2: return message2{message0{from}} 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 type ProposalHashData = multisig2.ProposalHashData func txnParams(id uint64, data *ProposalHashData) ([]byte, error) { params := multisig2.TxnIDParams{ID: multisig2.TxnID(id)} 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) }