2021-04-26 14:48:20 +00:00
|
|
|
package multisig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/minio/blake2b-simd"
|
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/cbor"
|
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
|
|
|
|
msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
2021-05-06 05:44:11 +00:00
|
|
|
msig{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin/multisig"
|
2021-04-26 14:48:20 +00:00
|
|
|
{{range .versions}}
|
|
|
|
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
{{range .versions}}
|
|
|
|
builtin.RegisterActorState(builtin{{.}}.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
|
|
|
return load{{.}}(store, root)
|
|
|
|
})
|
2022-04-04 11:23:13 +00:00
|
|
|
|
|
|
|
if c, ok := actors.GetActorCodeID(actors.Version{{.}}, "multisig"); ok {
|
|
|
|
builtin.RegisterActorState(c, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
|
|
|
return load{{.}}(store, root)
|
|
|
|
})
|
|
|
|
}
|
2021-04-26 14:48:20 +00:00
|
|
|
{{end}}}
|
|
|
|
|
|
|
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
2022-04-04 11:23:13 +00:00
|
|
|
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
|
|
|
|
if name != "multisig" {
|
|
|
|
return nil, xerrors.Errorf("actor code is not multisig: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch av {
|
|
|
|
{{range .versions}}
|
|
|
|
case actors.Version{{.}}:
|
|
|
|
return load{{.}}(store, act.Head)
|
|
|
|
{{end}}
|
|
|
|
default:
|
|
|
|
return nil, xerrors.Errorf("unknown actor version: %d", av)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
switch act.Code {
|
|
|
|
{{range .versions}}
|
|
|
|
case builtin{{.}}.MultisigActorCodeID:
|
|
|
|
return load{{.}}(store, act.Head)
|
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
|
|
|
}
|
|
|
|
|
2021-05-15 01:11:23 +00:00
|
|
|
func MakeState(store adt.Store, av actors.Version, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) {
|
|
|
|
switch av {
|
|
|
|
{{range .versions}}
|
|
|
|
case actors.Version{{.}}:
|
|
|
|
return make{{.}}(store, signers, threshold, startEpoch, unlockDuration, initialBalance)
|
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
return nil, xerrors.Errorf("unknown actor version %d", av)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetActorCodeID(av actors.Version) (cid.Cid, error) {
|
2022-04-04 11:23:13 +00:00
|
|
|
if c, ok := actors.GetActorCodeID(av, "multisig"); ok {
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
2021-05-15 01:11:23 +00:00
|
|
|
switch av {
|
|
|
|
{{range .versions}}
|
|
|
|
case actors.Version{{.}}:
|
|
|
|
return builtin{{.}}.MultisigActorCodeID, nil
|
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cid.Undef, xerrors.Errorf("unknown actor version %d", av)
|
|
|
|
}
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
type State interface {
|
|
|
|
cbor.Marshaler
|
|
|
|
|
|
|
|
LockedBalance(epoch abi.ChainEpoch) (abi.TokenAmount, error)
|
|
|
|
StartEpoch() (abi.ChainEpoch, error)
|
|
|
|
UnlockDuration() (abi.ChainEpoch, error)
|
|
|
|
InitialBalance() (abi.TokenAmount, error)
|
|
|
|
Threshold() (uint64, error)
|
|
|
|
Signers() ([]address.Address, error)
|
|
|
|
|
|
|
|
ForEachPendingTxn(func(id int64, txn Transaction) error) error
|
|
|
|
PendingTxnChanged(State) (bool, error)
|
|
|
|
|
|
|
|
transactions() (adt.Map, error)
|
|
|
|
decodeTransaction(val *cbg.Deferred) (Transaction, error)
|
2021-05-15 01:11:23 +00:00
|
|
|
GetState() interface{}
|
2021-04-26 14:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Transaction = msig0.Transaction
|
|
|
|
|
|
|
|
var Methods = builtin{{.latestVersion}}.MethodsMultisig
|
|
|
|
|
|
|
|
func Message(version actors.Version, from address.Address) MessageBuilder {
|
|
|
|
switch version {
|
|
|
|
{{range .versions}}
|
|
|
|
case actors.Version{{.}}:
|
|
|
|
return message{{.}}{{"{"}}{{if (ge . 2)}}message0{from}{{else}}from{{end}}}
|
|
|
|
{{end}} 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 = msig{{.latestVersion}}.ProposalHashData
|
|
|
|
type ProposeReturn = msig{{.latestVersion}}.ProposeReturn
|
|
|
|
type ProposeParams = msig{{.latestVersion}}.ProposeParams
|
2021-06-18 20:52:03 +00:00
|
|
|
type ApproveReturn = msig{{.latestVersion}}.ApproveReturn
|
2021-04-26 14:48:20 +00:00
|
|
|
|
|
|
|
func txnParams(id uint64, data *ProposalHashData) ([]byte, error) {
|
2021-05-06 05:44:11 +00:00
|
|
|
params := msig{{.latestVersion}}.TxnIDParams{ID: msig{{.latestVersion}}.TxnID(id)}
|
2021-04-26 14:48:20 +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)
|
|
|
|
}
|