Documentation ¶
Index ¶
- Constants
- Variables
- func GetFaucetPackageFromDefaultService(account string, chainID string) (*models.FaucetPackage, error)
- func GetFaucetPackageFromRemoteService(faucetURL, token string) (*models.FaucetPackage, error)
- func UnmarshalFaucetPackage(data []byte) (*models.FaucetPackage, error)
- type CensusProof
- type HTTPclient
- func (c *HTTPclient) Account(address string) (*api.Account, error)
- func (c *HTTPclient) AccountBootstrap(faucetPkg *models.FaucetPackage, metadata *api.AccountMetadata, sik []byte) (types.HexBytes, error)
- func (c *HTTPclient) AccountSetMetadata(metadata *api.AccountMetadata) (types.HexBytes, error)
- func (c *HTTPclient) AccountSetValidator(pubKey []byte, name string) (types.HexBytes, error)
- func (c *HTTPclient) BearerToken() *uuid.UUID
- func (c *HTTPclient) CensusAddParticipants(censusID types.HexBytes, participants *api.CensusParticipants) error
- func (c *HTTPclient) CensusGenProof(censusID, voterKey types.HexBytes) (*CensusProof, error)
- func (c *HTTPclient) CensusPublish(censusID types.HexBytes) (types.HexBytes, string, error)
- func (c *HTTPclient) CensusSize(censusID types.HexBytes) (uint64, error)
- func (c *HTTPclient) ChainID() string
- func (c *HTTPclient) ChainInfo() (*api.ChainInfo, error)
- func (c *HTTPclient) Clone(accountPrivateKey string) *HTTPclient
- func (c *HTTPclient) CountAccounts() (uint64, error)
- func (c *HTTPclient) CountTokenTransfers(accountID common.Address) (uint64, error)
- func (c *HTTPclient) DateToHeight(date time.Time) (uint32, error)
- func (c *HTTPclient) DelSIK() (types.HexBytes, error)
- func (c *HTTPclient) Election(electionID types.HexBytes) (*api.Election, error)
- func (c *HTTPclient) ElectionFilterPaginated(organizationID types.HexBytes, electionID types.HexBytes, ...) (*[]api.ElectionSummary, error)
- func (c *HTTPclient) ElectionKeys(electionID types.HexBytes) (*api.ElectionKeys, error)
- func (c *HTTPclient) ElectionPrice(election *api.ElectionDescription) (uint64, error)
- func (c *HTTPclient) ElectionResults(electionID types.HexBytes) (*api.ElectionResults, error)
- func (c *HTTPclient) ElectionVoteCount(electionID types.HexBytes) (uint32, error)
- func (c *HTTPclient) EncryptionKeys(electionID types.HexBytes) ([]api.Key, error)
- func (c *HTTPclient) GenSIKProof() (*CensusProof, error)
- func (c *HTTPclient) ListAccounts(page int) ([]indexertypes.Account, error)
- func (c *HTTPclient) ListTokenTransfers(account common.Address, page int) (indexertypes.TokenTransfersAccount, error)
- func (c *HTTPclient) MyAddress() common.Address
- func (c *HTTPclient) NewCensus(censusType string) (types.HexBytes, error)
- func (c *HTTPclient) NewElection(description *api.ElectionDescription) (types.HexBytes, error)
- func (c *HTTPclient) NewElectionRaw(process *models.Process) (types.HexBytes, error)
- func (c *HTTPclient) NextElectionID(organizationID types.HexBytes, censusOrigin int32, ...) (string, error)
- func (c *HTTPclient) OrganizationsBySearchTermPaginated(organizationID types.HexBytes, page int) ([]types.HexBytes, error)
- func (c *HTTPclient) RegisterSIKForVote(electionId types.HexBytes, proof *CensusProof, secret []byte) (types.HexBytes, error)
- func (c *HTTPclient) Request(method string, jsonBody any, urlPath ...string) ([]byte, int, error)
- func (c *HTTPclient) SetAccount(accountPrivateKey string) error
- func (c *HTTPclient) SetAuthToken(token *uuid.UUID)
- func (c *HTTPclient) SetElectionStatus(electionID types.HexBytes, status string) (types.HexBytes, error)
- func (c *HTTPclient) SetHostAddr(addr *url.URL) error
- func (c *HTTPclient) SetRetries(n int)
- func (c *HTTPclient) SetSIK(secret []byte) (types.HexBytes, error)
- func (c *HTTPclient) SignAndSendTx(stx *models.SignedTx) (types.HexBytes, []byte, error)
- func (c *HTTPclient) TransactionByHash(txHash types.HexBytes) (*models.Tx, error)
- func (c *HTTPclient) TransactionCost(txType models.TxType) (uint64, error)
- func (c *HTTPclient) TransactionCount() (uint64, error)
- func (c *HTTPclient) TransactionReference(txHash types.HexBytes) (*api.TransactionReference, error)
- func (c *HTTPclient) TransactionSetCensus(electionID types.HexBytes, census api.ElectionCensus) (types.HexBytes, error)
- func (c *HTTPclient) TransactionsCost() (map[string]uint64, error)
- func (c *HTTPclient) Transfer(to common.Address, amount uint64) (types.HexBytes, error)
- func (c *HTTPclient) TransferWithNonce(to common.Address, amount uint64, nonce uint32) (types.HexBytes, error)
- func (c *HTTPclient) ValidSIK() (bool, error)
- func (c *HTTPclient) ValidSIKRoots() (SIKRoots, error)
- func (c *HTTPclient) Verify(electionID, voteID types.HexBytes) (bool, error)
- func (cl *HTTPclient) Vote(v *VoteData) (types.HexBytes, error)
- func (c *HTTPclient) WaitUntilElectionCreated(ctx context.Context, electionID types.HexBytes) (*api.Election, error)
- func (c *HTTPclient) WaitUntilElectionKeys(ctx context.Context, electionID types.HexBytes) (*api.ElectionKeys, error)
- func (c *HTTPclient) WaitUntilElectionResults(ctx context.Context, electionID types.HexBytes) (*api.ElectionResults, error)
- func (c *HTTPclient) WaitUntilElectionStarts(ctx context.Context, electionID types.HexBytes) (*api.Election, error)
- func (c *HTTPclient) WaitUntilElectionStatus(ctx context.Context, electionID types.HexBytes, status string) (*api.Election, error)
- func (c *HTTPclient) WaitUntilHeight(ctx context.Context, height uint32) error
- func (c *HTTPclient) WaitUntilNBlocks(ctx context.Context, n uint32) error
- func (c *HTTPclient) WaitUntilNextBlock() error
- func (c *HTTPclient) WaitUntilTxIsMined(ctx context.Context, txHash types.HexBytes) (*api.TransactionReference, error)
- type SIKRoots
- type VoteData
Constants ¶
const ( // HTTPGET is the method string used for calling Request() HTTPGET = http.MethodGet // HTTPPOST is the method string used for calling Request() HTTPPOST = http.MethodPost // HTTPDELETE is the method string used for calling HTTPDELETE = http.MethodDelete // DefaultRetries this enables Request() to handle the situation where the server replies // "mempool is full", it will wait for next block and retry sending the tx DefaultRetries = 3 )
const ( DefaultBlockInterval = 8 * time.Second WaitTimeout = 3 * DefaultBlockInterval PollInterval = DefaultBlockInterval / 2 )
Variables ¶
var DefaultFaucetURLs = map[string]string{
"dev": "https://api-dev.faucet.vocdoni.net/v2/open/claim/",
"develop": "https://api-dev.faucet.vocdoni.net/v2/open/claim/",
"stg": "https://api-stg.faucet.vocdoni.net/v2/open/claim",
"stage": "https://api-stg.faucet.vocdoni.net/v2/open/claim",
"lts": "https://api-faucet.vocdoni.io/v2/open/claim/",
"prod": "https://api-faucet.vocdoni.io/v2/open/claim/",
}
DefaultFaucetURLs is a map of default faucet URLs for each network.
var ( // ErrAccountNotConfigured is returned when the client has not been configured with an account. ErrAccountNotConfigured = fmt.Errorf("account not configured") )
var ( // ErrTransactionDoesNotExist is returned when the transaction does not exist ErrTransactionDoesNotExist = fmt.Errorf("transaction does not exist") )
Functions ¶
func GetFaucetPackageFromDefaultService ¶ added in v1.10.1
func GetFaucetPackageFromDefaultService(account string, chainID string) (*models.FaucetPackage, error)
GetFaucetPackageFromDefaultService returns a faucet package. Needs the destination wallet address and the chainID.
func GetFaucetPackageFromRemoteService ¶
func GetFaucetPackageFromRemoteService(faucetURL, token string) (*models.FaucetPackage, error)
GetFaucetPackageFromRemoteService returns a faucet package from a remote HTTP faucet service. This service usually requires a valid bearer token. faucetURL usually includes the destination wallet address that will receive the funds.
func UnmarshalFaucetPackage ¶
func UnmarshalFaucetPackage(data []byte) (*models.FaucetPackage, error)
UnmarshalFaucetPackage unmarshals a faucet package into a FaucetPackage struct.
Types ¶
type CensusProof ¶
type CensusProof struct { // Root contains census tree root Root types.HexBytes // Proof contains encoded and packed siblings as a census proof Proof types.HexBytes // LeafValue contains the associated value on the census tree LeafValue types.HexBytes // LeafWeight contains the decoded LeafValue as big.Int that represents // the associated weight for the voter. LeafWeight *big.Int // KeyType defines the type of the census tree key KeyType models.ProofArbo_KeyType // Siblings contains the decoded siblings keys Siblings []string }
CensusProof represents proof for a voter in a census
type HTTPclient ¶
type HTTPclient struct {
// contains filtered or unexported fields
}
HTTPclient is the Vocdoni API HTTP client.
func NewHTTPclient ¶
NewHTTPclient creates a new HTTP(s) API Vocdoni client.
func (*HTTPclient) Account ¶
func (c *HTTPclient) Account(address string) (*api.Account, error)
Account returns the information about a Vocdoni account. If address is empty, it returns the information about the account associated with the client.
func (*HTTPclient) AccountBootstrap ¶
func (c *HTTPclient) AccountBootstrap(faucetPkg *models.FaucetPackage, metadata *api.AccountMetadata, sik []byte) (types.HexBytes, error)
AccountBootstrap initializes the account in the Vocdoni blockchain. A faucet package is required in order to pay for the costs of the transaction if the blockchain requires it. Returns the transaction hash.
func (*HTTPclient) AccountSetMetadata ¶
func (c *HTTPclient) AccountSetMetadata(metadata *api.AccountMetadata) (types.HexBytes, error)
AccountSetMetadata updates the metadata associated with the account associated with the client.
func (*HTTPclient) AccountSetValidator ¶ added in v1.10.0
AccountSetValidator upgrades to validator status the account associated with the public key provided. If the public key is nil, the public key associated with the account client is used. Returns the transaction hash.
func (*HTTPclient) BearerToken ¶ added in v1.10.0
func (c *HTTPclient) BearerToken() *uuid.UUID
BearerToken returns the current bearer authentication token.
func (*HTTPclient) CensusAddParticipants ¶
func (c *HTTPclient) CensusAddParticipants(censusID types.HexBytes, participants *api.CensusParticipants) error
CensusAddParticipants adds one or several participants to an existing census. The Key can be either the public key or address of the voter.
func (*HTTPclient) CensusGenProof ¶
func (c *HTTPclient) CensusGenProof(censusID, voterKey types.HexBytes) (*CensusProof, error)
CensusGenProof generates a proof for a voter in a census. The voterKey is the public key or address of the voter.
func (*HTTPclient) CensusPublish ¶
CensusPublish publishes a census to the distributed data storage and returns its root hash and storage URI.
func (*HTTPclient) CensusSize ¶
func (c *HTTPclient) CensusSize(censusID types.HexBytes) (uint64, error)
CensusSize returns the number of participants in a census.
func (*HTTPclient) ChainID ¶
func (c *HTTPclient) ChainID() string
ChainID returns the chain identifier name in which the API backend is connected.
func (*HTTPclient) ChainInfo ¶
func (c *HTTPclient) ChainInfo() (*api.ChainInfo, error)
ChainInfo returns some information about the chain, such as block height.
func (*HTTPclient) Clone ¶
func (c *HTTPclient) Clone(accountPrivateKey string) *HTTPclient
Clone returns a copy of the HTTPclient with the accountPrivateKey set as the account key. Panics if the accountPrivateKey is not valid.
func (*HTTPclient) CountAccounts ¶ added in v1.10.0
func (c *HTTPclient) CountAccounts() (uint64, error)
CountAccounts returns the total count of exiting accounts
func (*HTTPclient) CountTokenTransfers ¶ added in v1.10.0
func (c *HTTPclient) CountTokenTransfers(accountID common.Address) (uint64, error)
CountTokenTransfers returns the total count of transfers sent and received for an account
func (*HTTPclient) DateToHeight ¶
func (c *HTTPclient) DateToHeight(date time.Time) (uint32, error)
func (*HTTPclient) DelSIK ¶ added in v1.9.0
func (c *HTTPclient) DelSIK() (types.HexBytes, error)
DelSIK function allows to delete the Secret Identity Key for the current HTTPClient account if it already has a valid one.
func (*HTTPclient) ElectionFilterPaginated ¶
func (c *HTTPclient) ElectionFilterPaginated(organizationID types.HexBytes, electionID types.HexBytes, status models.ProcessStatus, withResults bool, page int) (*[]api.ElectionSummary, error)
ElectionFilterPaginated returns a list of elections filtered by the given parameters. POST /elections/filter/page/<page> Returns a list of elections filtered by the given parameters.
func (*HTTPclient) ElectionKeys ¶ added in v1.8.0
func (c *HTTPclient) ElectionKeys(electionID types.HexBytes) (*api.ElectionKeys, error)
ElectionKeys fetches the encryption keys for an election. Note that only elections that are SecretUntilTheEnd will return keys
func (*HTTPclient) ElectionPrice ¶ added in v1.8.0
func (c *HTTPclient) ElectionPrice(election *api.ElectionDescription) (uint64, error)
ElectionPrice returns the price of an election.
func (*HTTPclient) ElectionResults ¶
func (c *HTTPclient) ElectionResults(electionID types.HexBytes) (*api.ElectionResults, error)
ElectionResults returns the election results given its ID.
func (*HTTPclient) ElectionVoteCount ¶
func (c *HTTPclient) ElectionVoteCount(electionID types.HexBytes) (uint32, error)
ElectionVoteCount returns the number of registered votes for a given election.
func (*HTTPclient) EncryptionKeys ¶ added in v1.8.0
func (*HTTPclient) GenSIKProof ¶ added in v1.9.0
func (c *HTTPclient) GenSIKProof() (*CensusProof, error)
GenSIKProof generates a proof for the voter address in the sik merkle tree.
func (*HTTPclient) ListAccounts ¶ added in v1.10.0
func (c *HTTPclient) ListAccounts(page int) ([]indexertypes.Account, error)
ListAccounts return the account list information (address, balance and nonce)
func (*HTTPclient) ListTokenTransfers ¶ added in v1.10.0
func (c *HTTPclient) ListTokenTransfers(account common.Address, page int) (indexertypes.TokenTransfersAccount, error)
ListTokenTransfers returns the list of sent and received token transfers associated with an account
func (*HTTPclient) MyAddress ¶
func (c *HTTPclient) MyAddress() common.Address
MyAddress returns the address of the account used for signing transactions.
func (*HTTPclient) NewCensus ¶
func (c *HTTPclient) NewCensus(censusType string) (types.HexBytes, error)
NewCensus creates a new census and returns its ID. The censusType can be weighted (api.CensusTypeWeighted), zkweighted (api.CensusTypeZKWeighted) or csp (api.CensusTypeCSP).
func (*HTTPclient) NewElection ¶
func (c *HTTPclient) NewElection(description *api.ElectionDescription) (types.HexBytes, error)
NewElection creates a new election given the election details and returns the ElectionID
func (*HTTPclient) NewElectionRaw ¶
NewElectionRaw creates a new election given the protobuf Process message and returns the ElectionID
func (*HTTPclient) NextElectionID ¶ added in v1.10.1
func (c *HTTPclient) NextElectionID(organizationID types.HexBytes, censusOrigin int32, envelopeType *models.EnvelopeType) (string, error)
NextElectionID gets the next election ID for an organization. POST /elections/id
func (*HTTPclient) OrganizationsBySearchTermPaginated ¶
func (c *HTTPclient) OrganizationsBySearchTermPaginated( organizationID types.HexBytes, page int) ([]types.HexBytes, error)
OrganizationsBySearchTermPaginated returns a paginated list of organizations that match the given search term.
func (*HTTPclient) RegisterSIKForVote ¶ added in v1.9.0
func (c *HTTPclient) RegisterSIKForVote(electionId types.HexBytes, proof *CensusProof, secret []byte) (types.HexBytes, error)
RegisterSIKForVote function performs the free RegisterSIKTx to the vochain helping to non registered accounts to vote in an ongoing election, but only if the account is in the election census. The function returns the hash of the sent transaction, and requires the election ID. The census proof and the secret are optional. If no proof is provided, it will be generated.
func (*HTTPclient) Request ¶
Request performs a `method` type raw request to the endpoint specified in urlPath parameter. Method is either GET or POST. If POST, a JSON struct should be attached. Returns the response, the status code and an error.
func (*HTTPclient) SetAccount ¶
func (c *HTTPclient) SetAccount(accountPrivateKey string) error
SetAccount sets the Vocdoni account used for signing transactions and assign a new ZkAddress based on the provided private key account.
func (*HTTPclient) SetAuthToken ¶
func (c *HTTPclient) SetAuthToken(token *uuid.UUID)
SetAuthToken configures the bearer authentication token.
func (*HTTPclient) SetElectionStatus ¶
func (c *HTTPclient) SetElectionStatus(electionID types.HexBytes, status string) (types.HexBytes, error)
SetElectionStatus configures the status of an election. The status can be one of the following: "READY", "ENDED", "CANCELED", "PAUSED". Not all transition status are valid. Returns the transaction hash.
func (*HTTPclient) SetHostAddr ¶
func (c *HTTPclient) SetHostAddr(addr *url.URL) error
SetHostAddr configures the host address of the API server.
func (*HTTPclient) SetRetries ¶ added in v1.9.0
func (c *HTTPclient) SetRetries(n int)
func (*HTTPclient) SetSIK ¶ added in v1.9.0
func (c *HTTPclient) SetSIK(secret []byte) (types.HexBytes, error)
SetSIK function allows to update the Secret Identity Key for the current HTTPClient account. To do that, the function requires a secret user input.
func (*HTTPclient) SignAndSendTx ¶
func (*HTTPclient) TransactionByHash ¶
TransactionByHash returns the full transaction given its hash. For querying if a transaction is included in a block, it is recommended to use TransactionReference which is much faster.
func (*HTTPclient) TransactionCost ¶
func (c *HTTPclient) TransactionCost(txType models.TxType) (uint64, error)
TransactionCost returns the current cost for the given transaction type
func (*HTTPclient) TransactionCount ¶ added in v1.8.0
func (c *HTTPclient) TransactionCount() (uint64, error)
TransactionCount returns the count of transactions
func (*HTTPclient) TransactionReference ¶
func (c *HTTPclient) TransactionReference(txHash types.HexBytes) (*api.TransactionReference, error)
TransactionReference returns the reference of a transaction given its hash.
func (*HTTPclient) TransactionSetCensus ¶ added in v1.9.0
func (c *HTTPclient) TransactionSetCensus(electionID types.HexBytes, census api.ElectionCensus) (types.HexBytes, error)
func (*HTTPclient) TransactionsCost ¶
func (c *HTTPclient) TransactionsCost() (map[string]uint64, error)
TransactionsCost returns a map with the current cost for all transactions
func (*HTTPclient) Transfer ¶
Transfer sends tokens from the account associated with the client to the given address. The nonce is automatically calculated from the account information. Returns the transaction hash.
func (*HTTPclient) TransferWithNonce ¶ added in v1.10.0
func (c *HTTPclient) TransferWithNonce(to common.Address, amount uint64, nonce uint32) (types.HexBytes, error)
TransferWithNonce sends tokens from the account associated with the client to the given address. Returns the transaction hash.
func (*HTTPclient) ValidSIK ¶ added in v1.9.0
func (c *HTTPclient) ValidSIK() (bool, error)
ValidSIK checks if the current client account has a valid SIK registered in the vochain
func (*HTTPclient) ValidSIKRoots ¶ added in v1.9.0
func (c *HTTPclient) ValidSIKRoots() (SIKRoots, error)
ValidSIKRoots returns the currently valid roots of SIK merkle tree from the API.
func (*HTTPclient) Verify ¶
func (c *HTTPclient) Verify(electionID, voteID types.HexBytes) (bool, error)
Verify verifies a vote. The voteID is the nullifier of the vote.
func (*HTTPclient) Vote ¶
func (cl *HTTPclient) Vote(v *VoteData) (types.HexBytes, error)
Vote sends a vote to the Vochain. The vote is a VoteData struct, which contains the electionID, the choices and the proof. if VoterAccount is set, it's used to sign the vote, else it defaults to signing with the account set in HTTPclient. The return value is the voteID (nullifier).
func (*HTTPclient) WaitUntilElectionCreated ¶
func (*HTTPclient) WaitUntilElectionKeys ¶ added in v1.8.0
func (c *HTTPclient) WaitUntilElectionKeys(ctx context.Context, electionID types.HexBytes) ( *api.ElectionKeys, error)
WaitUntilElectionKeys waits until the election has published its encryption keys, and returns them.
func (*HTTPclient) WaitUntilElectionResults ¶ added in v1.8.0
func (c *HTTPclient) WaitUntilElectionResults(ctx context.Context, electionID types.HexBytes) (*api.ElectionResults, error)
WaitUntilElectionResults waits until the given election has published final results.
func (*HTTPclient) WaitUntilElectionStarts ¶
func (c *HTTPclient) WaitUntilElectionStarts(ctx context.Context, electionID types.HexBytes) (*api.Election, error)
WaitUntilElectionStarts waits until the given election starts.
func (*HTTPclient) WaitUntilElectionStatus ¶
func (c *HTTPclient) WaitUntilElectionStatus(ctx context.Context, electionID types.HexBytes, status string) (*api.Election, error)
WaitUntilElectionStatus waits until the given election has the given status.
func (*HTTPclient) WaitUntilHeight ¶
func (c *HTTPclient) WaitUntilHeight(ctx context.Context, height uint32) error
WaitUntilHeight waits until the given height is reached and returns nil.
If ctx.Done() is reached, returns ctx.Err() instead.
func (*HTTPclient) WaitUntilNBlocks ¶
func (c *HTTPclient) WaitUntilNBlocks(ctx context.Context, n uint32) error
WaitUntilNBlocks waits until N blocks are produced, and returns nil.
If ctx.Done() is reached, returns ctx.Err() instead.
func (*HTTPclient) WaitUntilNextBlock ¶
func (c *HTTPclient) WaitUntilNextBlock() error
WaitUntilNextBlock waits until next block, and returns nil
It uses a context.WithTimeout(24s) before giving up and returning ctx.Err()
func (*HTTPclient) WaitUntilTxIsMined ¶
func (c *HTTPclient) WaitUntilTxIsMined(ctx context.Context, txHash types.HexBytes) (*api.TransactionReference, error)
WaitUntilTxIsMined waits until the given transaction is mined (included in a block)
type VoteData ¶
type VoteData struct { Choices []int Election *api.Election VoteWeight *big.Int ProofMkTree *CensusProof ProofSIKTree *CensusProof ProofCSP types.HexBytes Keys []api.Key // if VoterAccount is set, it will be used to sign the vote // instead of the keys found in HTTPclient.account VoterAccount *ethereum.SignKeys }
VoteData contains the data needed to create a vote.
Choices is a list of choices, where each position represents a question. ElectionID is the ID of the election. VoteWeight is the desired weight for voting. It can be less than or equal to the weight registered in the census. If is defined as nil, it will be equal to the registered one. ProofMkTree is the proof of the vote for an off chain tree, weighted election. ProofCSP is the proof of the vote for a CSP election.
KeyType is the type of the key used when the census was created. It can be either models.ProofArbo_ADDRESS (default) or models.ProofArbo_PUBKEY (deprecated).