80 lines
2.4 KiB
Go
80 lines
2.4 KiB
Go
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"
|
|
|
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
|
multisig4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
)
|
|
|
|
var Methods = builtin4.MethodsMultisig
|
|
|
|
func Message(version actors.Version, from address.Address) MessageBuilder {
|
|
switch version {
|
|
case actors.Version0:
|
|
return message0{from}
|
|
case actors.Version2:
|
|
return message2{message0{from}}
|
|
case actors.Version3:
|
|
return message3{message0{from}}
|
|
case actors.Version4:
|
|
return message4{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 = multisig4.ProposalHashData
|
|
type ProposeReturn = multisig4.ProposeReturn
|
|
type ProposeParams = multisig4.ProposeParams
|
|
|
|
func txnParams(id uint64, data *ProposalHashData) ([]byte, error) {
|
|
params := multisig4.TxnIDParams{ID: multisig4.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)
|
|
}
|