Documentation
¶
Index ¶
- Constants
- Variables
- func EndpointWithParam(path, key, param string) string
- type API
- type APIConfig
- type CensusParticipant
- type CensusParticipants
- type ContractAddresses
- type Error
- type HostLoadResponse
- type LoggingConfig
- type NewCensus
- type ProcessList
- type ProcessResponse
- type SequencerInfo
- type SequencerStatsResponse
- type SetMetadataResponse
- type Vote
- type VoteResponse
- type VoteStatusResponse
- type WorkerAuthDataResponse
- type WorkerInfo
- type WorkerJobResponse
- type WorkersListResponse
Constants ¶
const ( // Health endpoints PingEndpoint = "/ping" // Health check endpoint // Process endpoints ProcessesEndpoint = "/processes" // GET: List processes, POST: Create process ProcessURLParam = "processId" // URL parameter for process ID ProcessEndpoint = "/processes/{" + ProcessURLParam + "}" // GET: Get process info // Vote endpoints VotesEndpoint = "/votes" // POST: Submit a vote // Vote status endpoints VoteStatusVoteIDParam = "voteId" // URL parameter for vote ID VoteStatusEndpoint = VotesEndpoint + "/{" + ProcessURLParam + "}/voteId/{" + VoteStatusVoteIDParam + "}" // GET: Check vote status // Vote address endpoint VoteByAddressAddressParam = "address" // URL parameter for address VoteByAddressEndpoint = VotesEndpoint + "/{" + ProcessURLParam + "}/address/{" + VoteByAddressAddressParam + "}" // GET: Get vote by address // Info endpoint InfoEndpoint = "/info" // GET: Get ballot proof information // Host load endpoint HostLoadEndpoint = "/info/load" // GET: Get host load metrics // Static file serving endpoint StaticFilesEndpoint = "/app*" // GET: Serve static files from the /webapp directory // Census endpoints CensusURLParam = "censusId" // URL parameter for census ID NewCensusEndpoint = "/censuses" // POST: Create a new census AddCensusParticipantsEndpoint = "/censuses/{" + CensusURLParam + "}/participants" // POST: Add participants to census GetCensusParticipantsEndpoint = "/censuses/{" + CensusURLParam + "}/participants" // GET: Get census participants GetCensusRootEndpoint = "/censuses/{" + CensusURLParam + "}/root" // GET: Get census root GetCensusSizeEndpoint = "/censuses/{" + CensusURLParam + "}/size" // GET: Get census size DeleteCensusEndpoint = "/censuses/{" + CensusURLParam + "}" // DELETE: Delete census GetCensusProofEndpoint = "/censuses/{" + CensusURLParam + "}/proof" // GET: Get census proof // Worker URL params and endpoints SequencerUUIDParam = "uuid" // Param for worker UUID WorkerAddressQueryParam = "address" // URL query param for worker address WorkerNameQueryParam = "name" // URL query param for worker name WorkerTokenQueryParam = "token" // URL query param for worker token WorkersEndpoint = "/workers/{" + SequencerUUIDParam + "}" // Base workers endpoint WorkerTokenDataEndpoint = WorkersEndpoint + "/authData" // GET: Message to be signed by workers WorkerJobEndpoint = WorkersEndpoint + "/job" // GET: New job for worker POST: Submit job from worker // Sequencer endpoints SequencerWorkersEndpoint = "/sequencer/workers" // GET: List worker statistics // Metadata endpoints MetadataHashParam = "metadataHash" // URL parameter for metadata hash MetadataSetEndpoint = "/metadata" // POST: Set metadata MetadataGetEndpoint = MetadataSetEndpoint + "/{" + MetadataHashParam + "}" // GET: Get metadata )
Variables ¶
var ( ErrResourceNotFound = Error{Code: 40001, HTTPstatus: http.StatusNotFound, Err: fmt.Errorf("resource not found")} ErrMalformedBody = Error{Code: 40004, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("malformed JSON body")} ErrInvalidSignature = Error{Code: 40005, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("invalid signature")} ErrMalformedProcessID = Error{Code: 40006, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("malformed process ID")} ErrProcessNotFound = Error{Code: 40007, HTTPstatus: http.StatusNotFound, Err: fmt.Errorf("process not found")} ErrInvalidCensusProof = Error{Code: 40008, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("invalid census proof")} ErrInvalidBallotProof = Error{Code: 40009, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("invalid ballot proof")} ErrInvalidCensusID = Error{Code: 40010, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("invalid census ID")} ErrCensusNotFound = Error{Code: 40011, HTTPstatus: http.StatusNotFound, Err: fmt.Errorf("census not found")} ErrKeyLengthExceeded = Error{Code: 40012, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("key length exceeded")} ErrInvalidBallotInputsHash = Error{Code: 40013, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("invalid ballot inputs hash")} ErrMalformedParam = Error{Code: 40015, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("malformed parameter")} ErrMalformedNullifier = Error{Code: 40016, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("malformed nullifier")} ErrMalformedAddress = Error{Code: 40017, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("malformed address")} ErrBallotAlreadySubmitted = Error{Code: 40018, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("ballot already submitted")} ErrBallotAlreadyProcessing = Error{Code: 40019, HTTPstatus: http.StatusConflict, Err: fmt.Errorf("ballot is already processing")} ErrProcessNotAcceptingVotes = Error{Code: 40020, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("process is not accepting votes")} ErrInvalidContractVersion = Error{Code: 40021, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("not supported contract version")} // Worker errors ErrWorkerNotAvailable = Error{Code: 40022, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("worker not available")} ErrMalformedWorkerInfo = Error{Code: 40023, HTTPstatus: http.StatusBadRequest, Err: fmt.Errorf("malformed worker info")} ErrInvalidWorkerAuthtoken = Error{Code: 40024, HTTPstatus: http.StatusForbidden, Err: fmt.Errorf("invalid worker authentication token")} ErrExpiredWorkerAuthtoken = Error{Code: 40025, HTTPstatus: http.StatusForbidden, Err: fmt.Errorf("expired worker authentication token")} ErrWorkerNotFound = Error{Code: 40026, HTTPstatus: http.StatusNotFound, Err: fmt.Errorf("worker not found")} ErrMarshalingServerJSONFailed = Error{Code: 50001, HTTPstatus: http.StatusInternalServerError, Err: fmt.Errorf("marshaling (server-side) JSON failed")} ErrGenericInternalServerError = Error{Code: 50002, HTTPstatus: http.StatusInternalServerError, Err: fmt.Errorf("internal server error")} )
The custom Error type satisfies the error interface. Error() returns a human-readable description of the error.
Error codes in the 40001-49999 range are the user's fault, and they return HTTP Status 400 or 404 (or even 204), whatever is most appropriate.
Error codes 50001-59999 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
var DisabledLogging = false
DisabledLogging is a global flag to disable logging middleware
var LogExcludedPrefixes = []string{ PingEndpoint, WorkersEndpoint, InfoEndpoint, }
LogExcludedPrefixes defines URL prefixes to exclude from request logging
Functions ¶
func EndpointWithParam ¶
EndpointWithParam creates an endpoint URL by replacing the parameter placeholder with the actual value. Used to build fully qualified endpoint URLs.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API type represents the API HTTP server with JWT authentication capabilities.
func New ¶
New creates a new API instance with the given configuration. It also initializes the storage and starts the HTTP server.
func (*API) ProcessIDVersion ¶
ProcessIDVersion returns the expected ProcessID version for the current network and contract address. It can be used to validate ProcessIDs.
type APIConfig ¶
type APIConfig struct { Host string Port int Storage *stg.Storage // Optional: use existing storage instance Network string // Optional: web3 network shortname Web3Config config.DavinciWeb3Config // Worker configuration SequencerWorkersSeed string // Seed for workers authentication over current sequencer WorkersAuthtokenExpiration time.Duration // Expiration time for worker authentication tokens WorkerJobTimeout time.Duration // Worker job timeout WorkerBanRules *workers.WorkerBanRules // Custom ban rules for workers }
APIConfig type represents the configuration for the API HTTP server. It includes the host, port and optionally an existing storage instance.
type CensusParticipant ¶
type CensusParticipant struct { Key types.HexBytes `json:"key"` Weight *types.BigInt `json:"weight,omitempty"` }
CensusParticipant is a participant in a census.
type CensusParticipants ¶
type CensusParticipants struct {
Participants []*CensusParticipant `json:"participants"`
}
CensusParticipants is a list of participants in a census.
type ContractAddresses ¶
type ContractAddresses struct { ProcessRegistry string `json:"process"` OrganizationRegistry string `json:"organization"` StateTransitionZKVerifier string `json:"stateTransitionVerifier"` ResultsZKVerifier string `json:"resultsVerifier"` }
ContractAddresses holds the smart contract addresses needed by the client
type Error ¶
Error is used by handler functions to wrap errors, assigning a unique error code and also specifying which HTTP Status should be used.
func (Error) MarshalJSON ¶
MarshalJSON returns a JSON containing Err.Error() and Code. Field HTTPstatus is ignored.
Example output: {"error":"account not found","code":4003}
func (Error) WithErr ¶
WithErr returns a copy of APIerror with err.Error() appended at the end of e.Err
func (Error) Withf ¶
Withf returns a copy of APIerror with the Sprintf formatted string appended at the end of e.Err
func (Error) Write ¶
func (e Error) Write(w http.ResponseWriter)
Write serializes a JSON msg using APIerror.Message and APIerror.Code and passes that to ctx.Send()
type HostLoadResponse ¶
type HostLoadResponse struct { MemStats any `json:"memStats,omitempty"` HostLoad1 float64 `json:"hostLoad1,omitempty"` HostMemUsedPercent float64 `json:"hostMemUsedPercent,omitempty"` HostDiskUsedPercent map[string]float64 `json:"hostDiskUsedPercent,omitempty"` }
HostLoadResponse is the exact shape we return to the client.
type LoggingConfig ¶
type LoggingConfig struct { MaxBodyLog int ExcludedPrefixes []string // URL path prefixes to exclude from logging }
LoggingConfig holds configuration for the logging middleware
func DefaultLoggingConfig ¶
func DefaultLoggingConfig() LoggingConfig
DefaultLoggingConfig returns a LoggingConfig with sensible defaults
type ProcessList ¶
ProcessList is the response returned by the process list endpoint.
type ProcessResponse ¶
type SequencerInfo ¶
type SequencerInfo struct { CircuitURL string `json:"circuitUrl"` CircuitHash string `json:"circuitHash"` WASMhelperURL string `json:"ballotProofWasmHelperUrl"` WASMhelperHash string `json:"ballotProofWasmHelperHash"` WASMhelperExecJsURL string `json:"ballotProofWasmHelperExecJsUrl"` WASMhelperExecJsHash string `json:"ballotProofWasmHelperExecJsHash"` ProvingKeyURL string `json:"provingKeyUrl"` ProvingKeyHash string `json:"provingKeyHash"` VerificationKeyURL string `json:"verificationKeyUrl"` VerificationKeyHash string `json:"verificationKeyHash"` Contracts ContractAddresses `json:"contracts"` Network map[string]uint32 `json:"network,omitempty"` SequencerAddress types.HexBytes `json:"sequencerAddress"` }
SequencerInfo contains any relevant information about the current sequencer for a client.
type SequencerStatsResponse ¶
type SequencerStatsResponse struct { storage.Stats ActiveProcesses int `json:"activeProcesses"` PendingVotes int `json:"pendingVotes"` }
SequencerStatsResponse is the response returned by the sequencer stats endpoint.
type SetMetadataResponse ¶
SetMetadataResponse is the response returned by the set metadata endpoint.
type Vote ¶
type Vote struct { ProcessID types.HexBytes `json:"processId"` CensusProof types.CensusProof `json:"censusProof"` Ballot *elgamal.Ballot `json:"ballot"` BallotProof *circomgnark.CircomProof `json:"ballotProof"` BallotInputsHash *types.BigInt `json:"ballotInputsHash"` Address types.HexBytes `json:"address"` Signature types.HexBytes `json:"signature"` VoteID types.HexBytes `json:"voteId"` }
Vote is the struct to represent a vote in the system. It will be provided by the user to cast a vote in a process.
type VoteResponse ¶
VoteResponse is the response returned by the vote submission endpoint.
type VoteStatusResponse ¶
type VoteStatusResponse struct {
Status string `json:"status"`
}
VoteStatusResponse is the response returned by the vote status endpoint.
type WorkerAuthDataResponse ¶
type WorkerAuthDataResponse struct { Message string `json:"message"` Signature types.HexBytes `json:"signature"` CreatedAt string `json:"createdAt"` AuthTokenSuffix types.HexBytes `json:"authTokenSuffix"` }
WorkerAuthDataResponse is the response returned by the worker sign message endpoint.
type WorkerInfo ¶
type WorkerInfo struct { Name string `json:"name"` SuccessCount int64 `json:"successCount"` FailedCount int64 `json:"failedCount"` }
WorkerInfo contains information about a worker node.
type WorkerJobResponse ¶
type WorkerJobResponse struct { VoteID types.HexBytes `json:"voteId"` Address string `json:"address"` SuccessCount int64 `json:"successCount"` FailedCount int64 `json:"failedCount"` }
WorkerJobResponse is the response returned by the worker job submission endpoint.
type WorkersListResponse ¶
type WorkersListResponse struct {
Workers []WorkerInfo `json:"workers"`
}
WorkersListResponse is the response returned by the workers list endpoint.