api

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: AGPL-3.0 Imports: 48 Imported by: 6

Documentation

Index

Constants

View Source
const (
	AccountHandler                     = "accounts"
	AccountFetchMetadataTimeoutSeconds = 5
)
View Source
const (
	CensusHandler = "censuses"

	CensusTypeWeighted   = "weighted"
	CensusTypeZKWeighted = "zkweighted"
	CensusTypeCSP        = "csp"
	CensusTypeUnknown    = "unknown"

	MaxCensusAddBatchSize = 8192
)
View Source
const (
	ElectionHandler     = "elections"
	MaxOffchainFileSize = 1024 * 1024 * 1 // 1MB
)
View Source
const (
	ChainHandler = "chain"
)
View Source
const MaxPageSize = 10

MaxPageSize defines the maximum number of results returned by the paginated endpoints

View Source
const (
	SIKHandler = "sik"
)
View Source
const VoteHandler = "votes"
View Source
const (
	WalletHandler = "wallet"
)

Variables

View Source
var (
	ErrMissingModulesForHandler = fmt.Errorf("missing modules attached for enabling handler")
	ErrHandlerUnknown           = fmt.Errorf("handler unknown")
	ErrHTTPRouterIsNil          = fmt.Errorf("httprouter is nil")
	ErrBaseRouteInvalid         = fmt.Errorf("base route must start with /")
)
View Source
var (
	ErrAddressMalformed                 = apirest.APIerror{Code: 4000, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("address malformed")}
	ErrDstAddressMalformed              = apirest.APIerror{Code: 4001, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("destination address malformed")}
	ErrDstAccountUnknown                = apirest.APIerror{Code: 4002, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("destination account is unknown")}
	ErrAccountNotFound                  = apirest.APIerror{Code: 4003, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("account not found")}
	ErrAccountAlreadyExists             = apirest.APIerror{Code: 4004, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("account already exists")}
	ErrOrgNotFound                      = apirest.APIerror{Code: 4006, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("organization not found")}
	ErrTransactionNotFound              = apirest.APIerror{Code: 4007, HTTPstatus: apirest.HTTPstatusNoContent, Err: fmt.Errorf("transaction not found")}
	ErrBlockNotFound                    = apirest.APIerror{Code: 4008, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("block not found")}
	ErrMetadataProvidedButNoURI         = apirest.APIerror{Code: 4009, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("metadata provided but no metadata URI found in transaction")}
	ErrMetadataURINotMatchContent       = apirest.APIerror{Code: 4010, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("metadata URI does not match metadata content")}
	ErrMarshalingJSONFailed             = apirest.APIerror{Code: 4011, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("marshaling JSON failed")}
	ErrFileSizeTooBig                   = apirest.APIerror{Code: 4012, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("file size exceeds the maximum allowed")}
	ErrCantParseOrgID                   = apirest.APIerror{Code: 4013, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("cannot parse organizationID")}
	ErrCantParseAccountID               = apirest.APIerror{Code: 4014, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("cannot parse accountID")}
	ErrCantParseBearerToken             = apirest.APIerror{Code: 4015, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("cannot parse bearer token")}
	ErrCantParseDataAsJSON              = apirest.APIerror{Code: 4016, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("cannot parse data as JSON")}
	ErrCantParseElectionID              = apirest.APIerror{Code: 4017, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("cannot parse electionID")}
	ErrCantParseMetadataAsJSON          = apirest.APIerror{Code: 4018, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("cannot parse metadata (invalid format)")}
	ErrCantParsePageNumber              = apirest.APIerror{Code: 4019, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("cannot parse page number")}
	ErrCantParsePayloadAsJSON           = apirest.APIerror{Code: 4020, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("cannot parse payload as JSON")}
	ErrCantParseVoteID                  = apirest.APIerror{Code: 4021, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("cannot parse voteID")}
	ErrCantExtractMetadataURI           = apirest.APIerror{Code: 4022, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("cannot extract metadata URI")}
	ErrVoteIDMalformed                  = apirest.APIerror{Code: 4023, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("voteID is malformed")}
	ErrVoteNotFound                     = apirest.APIerror{Code: 4024, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("vote not found")}
	ErrCensusIDLengthInvalid            = apirest.APIerror{Code: 4025, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("censusID length is wrong")}
	ErrCensusRootIsNil                  = apirest.APIerror{Code: 4026, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("census root is nil")}
	ErrCensusTypeUnknown                = apirest.APIerror{Code: 4027, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("census type is unknown")}
	ErrCensusTypeMismatch               = apirest.APIerror{Code: 4028, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("census type mismatch")}
	ErrCensusIndexedFlagMismatch        = apirest.APIerror{Code: 4029, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("census indexed flag mismatch")}
	ErrCensusRootHashMismatch           = apirest.APIerror{Code: 4030, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("census root hash mismatch after importing dump")}
	ErrParamStatusMissing               = apirest.APIerror{Code: 4031, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("parameter (status) missing or invalid")}
	ErrParamParticipantsMissing         = apirest.APIerror{Code: 4032, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("parameter (participants) missing")}
	ErrParamParticipantsTooBig          = apirest.APIerror{Code: 4033, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("parameter (participants) exceeds max length per call")}
	ErrParamDumpOrRootMissing           = apirest.APIerror{Code: 4034, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("parameter (dump or root) missing")}
	ErrParamKeyOrProofMissing           = apirest.APIerror{Code: 4035, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("parameter (key or proof) missing")}
	ErrParamRootInvalid                 = apirest.APIerror{Code: 4036, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("parameter (root) invalid")}
	ErrParamNetworkInvalid              = apirest.APIerror{Code: 4037, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("invalid network")}
	ErrParamToInvalid                   = apirest.APIerror{Code: 4038, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("invalid address")}
	ErrParticipantKeyMissing            = apirest.APIerror{Code: 4039, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("missing participant key")}
	ErrIndexedCensusCantUseWeight       = apirest.APIerror{Code: 4040, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("indexed census cannot use weight")}
	ErrWalletNotFound                   = apirest.APIerror{Code: 4041, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("wallet not found")}
	ErrWalletPrivKeyAlreadyExists       = apirest.APIerror{Code: 4042, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("wallet private key already exists")}
	ErrElectionEndDateInThePast         = apirest.APIerror{Code: 4043, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("election end date cannot be in the past")}
	ErrElectionEndDateBeforeStart       = apirest.APIerror{Code: 4044, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("election end date must be after start date")}
	ErrElectionNotFound                 = apirest.APIerror{Code: 4045, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("election not found")}
	ErrCensusNotFound                   = apirest.APIerror{Code: 4046, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("census not found")}
	ErrNoElectionKeys                   = apirest.APIerror{Code: 4047, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("no election keys available")}
	ErrMissingParameter                 = apirest.APIerror{Code: 4048, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("one or more parameters are missing")}
	ErrKeyNotFoundInCensus              = apirest.APIerror{Code: 4049, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("key not found in census")}
	ErrInvalidStatus                    = apirest.APIerror{Code: 4050, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("invalid status")}
	ErrInvalidCensusKeyLength           = apirest.APIerror{Code: 4051, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("invalid census key length")}
	ErrUnmarshalingServerProto          = apirest.APIerror{Code: 4052, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error unmarshaling protobuf data")}
	ErrMarshalingServerProto            = apirest.APIerror{Code: 4053, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error marshaling protobuf data")}
	ErrSIKNotFound                      = apirest.APIerror{Code: 4054, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("SIK not found")}
	ErrVochainEmptyReply                = apirest.APIerror{Code: 5000, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("vochain returned an empty reply")}
	ErrVochainSendTxFailed              = apirest.APIerror{Code: 5001, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("vochain SendTx failed")}
	ErrVochainGetTxFailed               = apirest.APIerror{Code: 5002, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("vochain GetTx failed")}
	ErrVochainReturnedErrorCode         = apirest.APIerror{Code: 5003, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("vochain replied with error code")}
	ErrVochainReturnedInvalidElectionID = apirest.APIerror{Code: 5004, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("vochain returned an invalid electionID after executing tx")}
	ErrVochainReturnedWrongMetadataCID  = apirest.APIerror{Code: 5005, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("vochain returned an unexpected metadata CID after executing tx")}
	ErrMarshalingServerJSONFailed       = apirest.APIerror{Code: 5006, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("marshaling (server-side) JSON failed")}
	ErrCantFetchElectionList            = apirest.APIerror{Code: 5007, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot fetch election list")}
	ErrCantFetchElection                = apirest.APIerror{Code: 5008, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot fetch election")}
	ErrCantFetchElectionResults         = apirest.APIerror{Code: 5009, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot fetch election results")} // unused as of 2023-06-28
	ErrCantFetchTokenTransfers          = apirest.APIerror{Code: 5010, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot fetch token transfers")}
	ErrCantFetchEnvelopeHeight          = apirest.APIerror{Code: 5011, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot fetch envelope height")}
	ErrCantFetchEnvelope                = apirest.APIerror{Code: 5012, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot fetch vote envelope")}
	ErrCantCheckTxType                  = apirest.APIerror{Code: 5013, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot check transaction type")}
	ErrCantABIEncodeResults             = apirest.APIerror{Code: 5014, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot abi.encode results")}
	ErrCantComputeKeyHash               = apirest.APIerror{Code: 5015, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot compute key hash")}
	ErrCantAddKeyAndValueToTree         = apirest.APIerror{Code: 5016, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot add key and value to tree")}
	ErrCantAddKeyToTree                 = apirest.APIerror{Code: 5017, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot add key to tree")}
	ErrCantGenerateFaucetPkg            = apirest.APIerror{Code: 5018, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot generate faucet package")}
	ErrCantEstimateBlockHeight          = apirest.APIerror{Code: 5019, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot estimate startDate block height")}
	ErrCantMarshalMetadata              = apirest.APIerror{Code: 5020, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot marshal metadata")}
	ErrCantPublishMetadata              = apirest.APIerror{Code: 5021, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot publish metadata file")}
	ErrTxTypeMismatch                   = apirest.APIerror{Code: 5022, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("transaction type mismatch")}
	ErrElectionIsNil                    = apirest.APIerror{Code: 5023, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("election is nil")}
	ErrElectionResultsNotYetAvailable   = apirest.APIerror{Code: 5024, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("election results are not yet available")}
	ErrElectionResultsIsNil             = apirest.APIerror{Code: 5025, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("election results is nil")}
	ErrElectionResultsMismatch          = apirest.APIerror{Code: 5026, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("election results don't match reported ones")}
	ErrCantGetCircomSiblings            = apirest.APIerror{Code: 5027, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot get circom siblings")}
	ErrCensusProofVerificationFailed    = apirest.APIerror{Code: 5028, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("census proof verification failed")}
	ErrCantCountVotes                   = apirest.APIerror{Code: 5029, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("cannot count votes")}
	ErrVochainOverloaded                = apirest.APIerror{Code: 5030, HTTPstatus: apirest.HTTPstatusServiceUnavailable, Err: fmt.Errorf("vochain overloaded")}
	ErrGettingSIK                       = apirest.APIerror{Code: 5031, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error getting SIK")}
)

APIerror satisfies the error interface. Error() returns a human-readable description of the error.

Error codes in the 4001-4999 range are the user's fault, and they return HTTP Status 400 or 404 (or even 204), whatever is most appropriate.

Error codes 5001-5999 are the server's fault and they return HTTP Status 500 or 503, or something else if appropriate.

The initial list of errors were more or less grouped by topic, but the list grows with time in a random fashion. NEVER change any of the current error codes, only append new errors after the current last 4XXX or 5XXX If you notice there's a gap (say, error code 4010, 4011 and 4013 exist, 4012 is missing) DON'T fill in the gap, that code was used in the past for some error (not anymore) and shouldn't be reused. There's no correlation between Code and HTTP Status, for example the fact that Code 4045 returns HTTP Status 404 Not Found is just a coincidence

Do note that HTTPstatus 204 No Content implies the response body will be empty, so the Code and Message will actually be discarded, never sent to the client

Functions

func CensusTypeToOrigin added in v1.4.0

func CensusTypeToOrigin(ctype CensusTypeDescription) (models.CensusOrigin, []byte, error)

Types

type API added in v1.4.0

type API struct {
	PrivateCalls uint64
	PublicCalls  uint64
	BaseRoute    string
	Endpoint     *apirest.API
	// contains filtered or unexported fields
}

API is the URL based REST API supporting bearer authentication.

func NewAPI added in v1.4.0

func NewAPI(router *httprouter.HTTProuter, baseRoute, dataDir, dbType string) (*API, error)

NewAPI creates a new instance of the API. Attach must be called next.

func (*API) Attach added in v1.4.0

func (a *API) Attach(vocdoniAPP *vochain.BaseApplication, vocdoniInfo *vochaininfo.VochainInfo,
	indexer *indexer.Indexer, data data.Storage, censusdb *censusdb.CensusDB)

Attach takes a list of modules which are used by the handlers in order to interact with the system. Attach must be called before EnableHandlers.

func (*API) EnableHandlers added in v1.4.0

func (a *API) EnableHandlers(handlers ...string) error

EnableHandlers enables the list of handlers. Attach must be called before.

func (*API) RouterHandler added in v1.4.0

func (a *API) RouterHandler() *apirest.API

RouterHandler returns the API router handler which can be used to register new custom endpoints.

type Account added in v1.4.0

type Account struct {
	Address       types.HexBytes   `json:"address" `
	Nonce         uint32           `json:"nonce"`
	Balance       uint64           `json:"balance"`
	ElectionIndex uint32           `json:"electionIndex"`
	InfoURL       string           `json:"infoURL,omitempty"`
	Token         *uuid.UUID       `json:"token,omitempty" swaggerignore:"true"`
	Metadata      *AccountMetadata `json:"metadata,omitempty"`
	SIK           types.HexBytes   `json:"sik"`
}

type AccountMedia added in v1.4.0

type AccountMedia struct {
	Avatar string `json:"avatar,omitempty"`
	Header string `json:"header,omitempty"`
}

AccountMedia stores the avatar, header, and logo for an entity metadata

type AccountMetadata added in v1.4.0

type AccountMetadata struct {
	Version     string         `json:"version,omitempty"`
	Languages   []string       `json:"languages,omitempty"`
	Name        LanguageString `json:"name,omitempty"`
	Description LanguageString `json:"description,omitempty"`
	NewsFeed    LanguageString `json:"newsFeed,omitempty"`
	Media       *AccountMedia  `json:"media,omitempty"`
	Meta        any            `json:"meta,omitempty"`
	Actions     any            `json:"actions,omitempty"`
}

AccountMetadata is the metadata for an organization

type AccountSet added in v1.4.0

type AccountSet struct {
	TxPayload   []byte         `json:"txPayload,omitempty" swaggerignore:"true"`
	Metadata    []byte         `json:"metadata,omitempty" swaggerignore:"true"`
	TxHash      types.HexBytes `json:"txHash" `
	MetadataURL string         `json:"metadataURL" swaggertype:"string"`
}

type Block added in v1.8.0

type Block struct {
	tmtypes.Block `json:",inline"`
	Hash          types.HexBytes `json:"hash" `
}

type BlockTransactionsInfo added in v1.8.0

type BlockTransactionsInfo struct {
	BlockNumber       uint64                `json:"blockNumber"`
	TransactionsCount uint32                `json:"transactionCount"`
	Transactions      []TransactionMetadata `json:"transactions"`
}

type Census added in v1.4.0

type Census struct {
	CensusID types.HexBytes `json:"censusID,omitempty"`
	Type     string         `json:"type,omitempty"`
	Weight   *types.BigInt  `json:"weight,omitempty"`
	Size     uint64         `json:"size,omitempty"`
	Valid    bool           `json:"valid,omitempty"`
	URI      string         `json:"uri,omitempty"`
	// proof stuff
	CensusRoot     types.HexBytes `json:"censusRoot,omitempty"`
	CensusProof    types.HexBytes `json:"censusProof,omitempty"`
	Key            types.HexBytes `json:"key,omitempty"`
	Value          types.HexBytes `json:"value,omitempty"`
	CensusSiblings []string       `json:"censusSiblings,omitempty"`
}

type CensusParticipant added in v1.4.0

type CensusParticipant struct {
	Key    types.HexBytes `json:"key" `
	Weight *types.BigInt  `json:"weight"`
}

type CensusParticipants added in v1.4.0

type CensusParticipants struct {
	Participants []CensusParticipant `json:"participants"`
}

type CensusTypeDescription added in v1.4.0

type CensusTypeDescription struct {
	Type      string         `json:"type"`
	Size      uint64         `json:"size"`
	URL       string         `json:"url,omitempty"`
	PublicKey types.HexBytes `json:"publicKey,omitempty" `
	RootHash  types.HexBytes `json:"rootHash,omitempty" `
}

type ChainInfo added in v1.4.0

type ChainInfo struct {
	ID                      string    `json:"chainId" example:"azeno"`
	BlockTime               [5]uint64 `json:"blockTime" example:"12000,11580,11000,11100,11100"`
	ElectionCount           uint64    `json:"electionCount" example:"120"`
	OrganizationCount       uint64    `json:"organizationCount" example:"20"`
	GenesisTime             time.Time `json:"genesisTime"  format:"date-time" example:"2022-11-17T18:00:57.379551614Z"`
	Height                  uint32    `json:"height" example:"5467"`
	Syncing                 bool      `json:"syncing" example:"true"`
	Timestamp               int64     `json:"blockTimestamp" swaggertype:"string" format:"date-time" example:"2022-11-17T18:00:57.379551614Z"`
	TransactionCount        uint64    `json:"transactionCount" example:"554"`
	ValidatorCount          uint32    `json:"validatorCount" example:"5"`
	VoteCount               uint64    `json:"voteCount" example:"432"`
	CircuitConfigurationTag string    `json:"cicuitConfigurationTag" example:"dev"`
	MaxCensusSize           uint64    `json:"maxCensusSize" example:"50000"`
	NetworkCapacity         uint64    `json:"networkCapacity" example:"2000"`
}

type ChoiceMetadata added in v1.4.0

type ChoiceMetadata struct {
	Title LanguageString `json:"title"`
	Value uint32         `json:"value"`
}

ChoiceMetadata contains metadata for one choice of a question

type Election added in v1.4.0

type Election struct {
	ElectionSummary
	Census       *ElectionCensus   `json:"census,omitempty"`
	MetadataURL  string            `json:"metadataURL"`
	CreationTime time.Time         `json:"creationTime"`
	VoteMode     VoteMode          `json:"voteMode,omitempty"`
	ElectionMode ElectionMode      `json:"electionMode,omitempty"`
	TallyMode    TallyMode         `json:"tallyMode,omitempty"`
	Metadata     *ElectionMetadata `json:"metadata,omitempty"`
}

type ElectionCensus added in v1.4.0

type ElectionCensus struct {
	CensusOrigin           string         `json:"censusOrigin"`
	CensusRoot             types.HexBytes `json:"censusRoot" `
	PostRegisterCensusRoot types.HexBytes `json:"postRegisterCensusRoot" `
	CensusURL              string         `json:"censusURL"`
	MaxCensusSize          uint64         `json:"maxCensusSize"`
}

type ElectionCreate added in v1.4.0

type ElectionCreate struct {
	TxPayload   []byte         `json:"txPayload,omitempty"`
	Metadata    []byte         `json:"metadata,omitempty"`
	TxHash      types.HexBytes `json:"txHash" `
	ElectionID  types.HexBytes `json:"electionID" `
	MetadataURL string         `json:"metadataURL"`
}

type ElectionDescription added in v1.4.0

type ElectionDescription struct {
	Title        LanguageString        `json:"title"`
	Description  LanguageString        `json:"description"`
	Header       string                `json:"header"`
	StreamURI    string                `json:"streamUri"`
	StartDate    time.Time             `json:"startDate,omitempty"`
	EndDate      time.Time             `json:"endDate"`
	VoteType     VoteType              `json:"voteType"`
	ElectionType ElectionType          `json:"electionType"`
	Questions    []Question            `json:"questions"`
	Census       CensusTypeDescription `json:"census"`
	TempSIKs     bool                  `json:"tempSIKs"`
}

type ElectionFilter added in v1.7.0

type ElectionFilter struct {
	OrganizationID types.HexBytes `json:"organizationId,omitempty" `
	ElectionID     types.HexBytes `json:"electionId,omitempty" `
	WithResults    *bool          `json:"withResults,omitempty"`
	Status         string         `json:"status,omitempty"`
}

type ElectionKeys added in v1.4.0

type ElectionKeys struct {
	PublicKeys  []Key `json:"publicKeys,omitempty" swaggertype:"string"`
	PrivateKeys []Key `json:"privateKeys,omitempty" swaggertype:"string"`
}

type ElectionMetadata added in v1.4.0

type ElectionMetadata struct {
	Title       LanguageString         `json:"title"`
	Version     string                 `json:"version"`
	Description LanguageString         `json:"description"`
	Media       ProcessMedia           `json:"media,omitempty"`
	Meta        any                    `json:"meta,omitempty"`
	Questions   []Question             `json:"questions,omitempty"`
	Results     ElectionResultsDetails `json:"results,omitempty"`
}

ElectionMetadata contains the process metadata fields as stored on ipfs

type ElectionMode added in v1.4.0

type ElectionMode struct {
	*models.ProcessMode
}

func (ElectionMode) MarshalJSON added in v1.4.0

func (e ElectionMode) MarshalJSON() ([]byte, error)

type ElectionResults added in v1.4.0

type ElectionResults struct {
	// ABIEncoded is the abi encoded election results
	ABIEncoded string `json:"abiEncoded" swaggerignore:"true"`
	// CensusRoot is the root of the census tree
	CensusRoot types.HexBytes `json:"censusRoot" `
	// ElectionID is the ID of the election
	ElectionID types.HexBytes `json:"electionId" `
	// OrganizationID is the ID of the organization that created the election
	OrganizationID types.HexBytes `json:"organizationId" `
	// Results is the list of votes
	Results [][]*types.BigInt `json:"results"`
	// SourceContractAddress is the address of the smart contract containing the census
	SourceContractAddress types.HexBytes `json:"sourceContractAddress,omitempty" `
}

ElectionResults is the struct used to wrap the results of an election

type ElectionResultsDetails added in v1.4.0

type ElectionResultsDetails struct {
	Aggregation string `json:"aggregation"`
	Display     string `json:"display"`
}

ElectionResultsDetails describes how a process results should be displayed and aggregated

type ElectionSummary added in v1.4.0

type ElectionSummary struct {
	ElectionID     types.HexBytes    `json:"electionId" `
	OrganizationID types.HexBytes    `json:"organizationId" `
	Status         string            `json:"status"`
	StartDate      time.Time         `json:"startDate"`
	EndDate        time.Time         `json:"endDate"`
	VoteCount      uint64            `json:"voteCount"`
	FinalResults   bool              `json:"finalResults"`
	Results        [][]*types.BigInt `json:"result,omitempty"`
	ManuallyEnded  bool              `json:"manuallyEnded"`
	FromArchive    bool              `json:"fromArchive"`
	ChainID        string            `json:"chainId"`
}

type ElectionType added in v1.4.0

type ElectionType struct {
	Autostart         bool `json:"autostart"`
	Interruptible     bool `json:"interruptible"`
	DynamicCensus     bool `json:"dynamicCensus"`
	SecretUntilTheEnd bool `json:"secretUntilTheEnd"`
	Anonymous         bool `json:"anonymous"`
}

type File added in v1.4.0

type File struct {
	Payload []byte `json:"payload,omitempty" swaggerignore:"true"`
	CID     string `json:"cid,omitempty"`
}

type GenericTransactionWithInfo added in v1.8.0

type GenericTransactionWithInfo struct {
	TxContent json.RawMessage          `json:"tx"`
	TxInfo    indexertypes.Transaction `json:"txInfo"`
	Signature types.HexBytes           `json:"signature"`
}

type Key

type Key struct {
	Index int            `json:"index"`
	Key   types.HexBytes `json:"key" `
}

type LanguageString added in v1.4.0

type LanguageString map[string]string

LanguageString is a wrapper for multi-language strings, specified in metadata.

example {"default": "hello", "en": "hello", "es": "hola"}

type NextElectionID added in v1.10.1

type NextElectionID struct {
	OrganizationID types.HexBytes `json:"organizationId"`
	CensusOrigin   int32          `json:"censusOrigin"`
	EnvelopeType   struct {
		Serial         bool `json:"serial"`
		Anonymous      bool `json:"anonymous"`
		EncryptedVotes bool `json:"encryptedVotes"`
		UniqueValues   bool `json:"uniqueValues"`
		CostFromWeight bool `json:"costFromWeight"`
	} `json:"envelopeType"`
}

type Organization added in v1.4.0

type Organization struct {
	OrganizationID types.HexBytes      `json:"organizationID,omitempty" `
	Elections      []*ElectionSummary  `json:"elections,omitempty"`
	Organizations  []*OrganizationList `json:"organizations,omitempty"`
	Count          *uint64             `json:"count,omitempty" example:"1"`
}

type OrganizationList added in v1.4.0

type OrganizationList struct {
	OrganizationID types.HexBytes `json:"organizationID"  example:"0x370372b92514d81a0e3efb8eba9d036ae0877653"`
	ElectionCount  uint64         `json:"electionCount" example:"1"`
}

type ProcessMedia added in v1.4.0

type ProcessMedia struct {
	Header    string `json:"header,omitempty"`
	StreamURI string `json:"streamUri,omitempty"`
}

ProcessMedia holds the process metadata's header and streamURI

type Question added in v1.4.0

type Question struct {
	Choices     []ChoiceMetadata `json:"choices"`
	Description LanguageString   `json:"description"`
	Title       LanguageString   `json:"title"`
}

Question contains metadata for one single question of a process

type TallyMode added in v1.4.0

type TallyMode struct {
	*models.ProcessVoteOptions
}

func (TallyMode) MarshalJSON added in v1.4.0

func (t TallyMode) MarshalJSON() ([]byte, error)

type Transaction added in v1.4.0

type Transaction struct {
	Payload   []byte            `json:"payload,omitempty" extensions:"x-omitempty" swaggerignore:"true"`
	Hash      types.HexBytes    `json:"hash,omitempty" extensions:"x-omitempty" `
	Response  []byte            `json:"response,omitempty" extensions:"x-omitempty" swaggertype:"string" format:"base64"`
	Code      *uint32           `json:"code,omitempty" extensions:"x-omitempty"`
	Costs     map[string]uint64 `json:"costs,omitempty" extensions:"x-omitempty" swaggerignore:"true"`
	Address   types.HexBytes    `json:"address,omitempty" extensions:"x-omitempty" swaggerignore:"true" `
	ProcessID types.HexBytes    `json:"processId,omitempty" extensions:"x-omitempty" swaggerignore:"true" `
}

type TransactionMetadata added in v1.8.0

type TransactionMetadata struct {
	Type   string         `json:"transactionType"`
	Number uint32         `json:"transactionNumber"`
	Index  int32          `json:"transactionIndex"`
	Hash   types.HexBytes `json:"transactionHash" `
}

type TransactionReference added in v1.4.0

type TransactionReference struct {
	Height uint32 `json:"blockHeight"`
	Index  uint32 `json:"transactionIndex"`
}

type Validator added in v1.4.0

type Validator struct {
	Power            uint64         `json:"power"`
	PubKey           types.HexBytes `json:"pubKey"`
	AccountAddress   types.HexBytes `json:"address"`
	Name             string         `json:"name"`
	ValidatorAddress types.HexBytes `json:"validatorAddress"`
	JoinHeight       uint64         `json:"joinHeight"`
	Votes            uint64         `json:"votes"`
	Proposals        uint64         `json:"proposals"`
	Score            uint32         `json:"score"`
}

type ValidatorList added in v1.4.0

type ValidatorList struct {
	Validators []Validator `json:"validators"`
}

type Vote added in v1.4.0

type Vote struct {
	TxPayload []byte         `json:"txPayload,omitempty"  extensions:"x-omitempty" swaggerignore:"true"`
	TxHash    types.HexBytes `json:"txHash,omitempty"  extensions:"x-omitempty" `
	VoteID    types.HexBytes `json:"voteID,omitempty"  extensions:"x-omitempty" `
	// Sent only for encrypted elections (no results until the end)
	EncryptionKeyIndexes []uint32 `json:"encryptionKeys,omitempty" extensions:"x-omitempty"`
	// For encrypted elections this will be codified
	VotePackage      json.RawMessage `json:"package,omitempty" extensions:"x-omitempty"`
	VoteWeight       string          `json:"weight,omitempty" extensions:"x-omitempty"`
	VoteNumber       *uint32         `json:"number,omitempty" extensions:"x-omitempty"`
	ElectionID       types.HexBytes  `json:"electionID,omitempty" extensions:"x-omitempty" `
	VoterID          types.HexBytes  `json:"voterID,omitempty" extensions:"x-omitempty" `
	BlockHeight      uint32          `json:"blockHeight,omitempty" extensions:"x-omitempty"`
	TransactionIndex *int32          `json:"transactionIndex,omitempty" extensions:"x-omitempty"`
	OverwriteCount   *uint32         `json:"overwriteCount,omitempty" extensions:"x-omitempty"`
	// Date when the vote was emitted
	Date *time.Time `json:"date,omitempty" extensions:"x-omitempty"`
}

type VoteMode added in v1.4.0

type VoteMode struct {
	*models.EnvelopeType
}

func (VoteMode) MarshalJSON added in v1.4.0

func (v VoteMode) MarshalJSON() ([]byte, error)

type VoteType added in v1.4.0

type VoteType struct {
	UniqueChoices     bool `json:"uniqueChoices"`
	MaxVoteOverwrites int  `json:"maxVoteOverwrites"`
	CostFromWeight    bool `json:"costFromWeight"`
	CostExponent      int  `json:"costExponent"`
	MaxCount          int  `json:"maxCount"`
	MaxValue          int  `json:"maxValue"`
}

Directories

Path Synopsis
docs

Jump to

Keyboard shortcuts

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