multisig

package
v0.0.0-...-9fd3d13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

README

Multisig Accounts

The x/accounts/defaults/multisig module provides the implementation for multisig accounts within the x/accounts module.

State

The multisig account keeps its members as a map of addresses and weights (<[]byte, uint64>), a config struct, a map of proposals and a map of votes.

type Account struct {
	Members  collections.Map[[]byte, uint64]
	Sequence collections.Sequence
	Config   collections.Item[v1.Config]

	addrCodec     address.Codec
	headerService header.Service
	eventService  event.Service

	Proposals collections.Map[uint64, v1.Proposal]
	Votes     collections.Map[collections.Pair[uint64, []byte], int32] // key: proposalID + voter address
}
Config

The config contains the basic rules defining how the multisig will work. All of these fields can be modified afterwards by calling MsgUpdateConfig.

message Config {
  int64 threshold = 1;

  int64 quorum = 2;

  // voting_period is the duration in seconds for the voting period.
  int64 voting_period = 3;

  // revote defines if members can change their vote.
  bool revote = 4;

  // early_execution defines if the multisig can be executed before the voting period ends.
  bool early_execution = 5;
}
Proposal

The proposal contains the title, summary, messages and the status of the proposal. The messages are stored as google.protobuf.Any to allow for any type of message to be stored.

message Proposal {
  string   title                        = 1;
  string   summary                      = 2;
  repeated google.protobuf.Any messages = 3;

  // if true, the proposal will execute as soon as the quorum is reached (last voter will execute).
  bool execute = 4;

  // voting_period_end will be set by the account when the proposal is created.
  int64 voting_period_end = 5;

  ProposalStatus status = 6;
}
Members

Members are stored as a map of addresses and weights. The weight is used to determine the voting power of the member.

Methods

MsgInit

The MsgInit message initializes a multisig account with the given members and config.

message MsgInit {
  repeated Member members = 1;
  Config          Config  = 2;
}
MsgUpdateConfig

The MsgUpdateConfig message updates the config of the multisig account. Only the members that are changing are required, and if their weight is 0, they are removed. If the config is nil, then it will not be updated.

message MsgUpdateConfig {
  // only the members that are changing are required, if their weight is 0, they are removed.
  repeated Member update_members = 1;

  // not all fields from Config can be changed
  Config Config = 2;
}
MsgCreateProposal

Only a member can create a proposal. The proposal will be stored in the account and the members will be able to vote on it.

If a voting period is not set, the proposal will be created using the voting period from the config. If the proposal has a voting period, it will be used instead.

message MsgCreateProposal {
  Proposal proposal = 1;
}
MsgVote

The MsgVote message allows a member to vote on a proposal. The vote can be either Yes, No or Abstain.

message MsgVote {
  uint64 proposal_id = 1;
  VoteOption   vote        = 2;
}

// VoteOption enumerates the valid vote options for a given proposal.
enum VoteOption {
  // VOTE_OPTION_UNSPECIFIED defines a no-op vote option.
  VOTE_OPTION_UNSPECIFIED = 0;
  // VOTE_OPTION_YES defines the yes proposal vote option.
  VOTE_OPTION_YES = 1;
  // VOTE_OPTION_ABSTAIN defines the abstain proposal vote option.
  VOTE_OPTION_ABSTAIN = 2;
  // VOTE_OPTION_NO defines the no proposal vote option.
  VOTE_OPTION_NO = 3;
}
MsgExecuteProposal

The MsgExecuteProposal message allows a member to execute a proposal. The proposal must have reached the quorum and the voting period must have ended.

message MsgExecuteProposal {
  uint64 proposal_id = 1;
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MembersPrefix   = collections.NewPrefix(0)
	SequencePrefix  = collections.NewPrefix(1)
	ConfigPrefix    = collections.NewPrefix(2)
	ProposalsPrefix = collections.NewPrefix(3)
	VotesPrefix     = collections.NewPrefix(4)
)
View Source
var MULTISIG_ACCOUNT = "multisig-account"

Functions

This section is empty.

Types

type Account

type Account struct {
	Members  collections.Map[[]byte, uint64]
	Sequence collections.Sequence
	Config   collections.Item[v1.Config]

	Proposals collections.Map[uint64, v1.Proposal]
	Votes     collections.Map[collections.Pair[uint64, []byte], int32] // key: proposalID + voter address
	// contains filtered or unexported fields
}

func NewAccount

func NewAccount(deps accountstd.Dependencies) (*Account, error)

NewAccount returns a new multisig account creator function.

func (Account) CreateProposal

func (a Account) CreateProposal(ctx context.Context, msg *v1.MsgCreateProposal) (*v1.MsgCreateProposalResponse, error)

CreateProposal creates a new proposal. If the proposal contains a voting period it will be used, otherwise the default voting period will be used.

func (Account) ExecuteProposal

ExecuteProposal tallies the votes for a proposal and executes it if it passes. If early execution is enabled, it will ignore the voting period and tally the votes without deleting them if the proposal has not passed.

func (*Account) Init

func (a *Account) Init(ctx context.Context, msg *v1.MsgInit) (*v1.MsgInitResponse, error)

Init initializes the multisig account with the given configuration and members.

func (Account) QueryConfig

func (a Account) QueryConfig(ctx context.Context, _ *v1.QueryConfig) (*v1.QueryConfigResponse, error)

QueryConfig returns the current multisig configuration.

func (Account) QueryProposal

func (a Account) QueryProposal(ctx context.Context, q *v1.QueryProposal) (*v1.QueryProposalResponse, error)

QueryProposal returns a proposal for a given ID, if the proposal hasn't been pruned yet.

func (Account) QuerySequence

func (a Account) QuerySequence(ctx context.Context, _ *v1.QuerySequence) (*v1.QuerySequenceResponse, error)

QuerySequence returns the current sequence number, used for proposal IDs.

func (*Account) RegisterExecuteHandlers

func (a *Account) RegisterExecuteHandlers(builder *accountstd.ExecuteBuilder)

RegisterExecuteHandlers implements implementation.Account.

func (*Account) RegisterInitHandler

func (a *Account) RegisterInitHandler(builder *accountstd.InitBuilder)

RegisterInitHandler implements implementation.Account.

func (*Account) RegisterQueryHandlers

func (a *Account) RegisterQueryHandlers(builder *accountstd.QueryBuilder)

RegisterQueryHandlers implements implementation.Account.

func (Account) UpdateConfig

func (a Account) UpdateConfig(ctx context.Context, msg *v1.MsgUpdateConfig) (*v1.MsgUpdateConfigResponse, error)

UpdateConfig updates the configuration of the multisig account.

func (Account) Vote

func (a Account) Vote(ctx context.Context, msg *v1.MsgVote) (*v1.MsgVoteResponse, error)

Vote casts a vote on a proposal. The sender must be a member of the multisig and the proposal must be in the voting period.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL