2020-09-30 19:30:02 +00:00
|
|
|
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"
|
|
|
|
|
2021-01-18 23:10:03 +00:00
|
|
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
|
|
|
multisig3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/multisig"
|
2020-09-30 19:30:02 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
2021-01-18 23:10:03 +00:00
|
|
|
var Methods = builtin3.MethodsMultisig
|
2020-10-08 20:32:54 +00:00
|
|
|
|
2020-09-30 19:30:02 +00:00
|
|
|
func Message(version actors.Version, from address.Address) MessageBuilder {
|
|
|
|
switch version {
|
|
|
|
case actors.Version0:
|
|
|
|
return message0{from}
|
|
|
|
case actors.Version2:
|
|
|
|
return message2{message0{from}}
|
2021-01-16 07:00:14 +00:00
|
|
|
case actors.Version3:
|
|
|
|
return message3{message0{from}}
|
2020-09-30 19:30:02 +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
|
2021-01-18 23:10:03 +00:00
|
|
|
type ProposalHashData = multisig3.ProposalHashData
|
|
|
|
type ProposeReturn = multisig3.ProposeReturn
|
2020-12-17 15:45:32 +00:00
|
|
|
type ProposeParams = multisig3.ProposeParams
|
2020-09-30 19:30:02 +00:00
|
|
|
|
|
|
|
func txnParams(id uint64, data *ProposalHashData) ([]byte, error) {
|
2021-01-18 23:10:03 +00:00
|
|
|
params := multisig3.TxnIDParams{ID: multisig3.TxnID(id)}
|
2020-09-30 19:30:02 +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)
|
|
|
|
}
|