Documentation ¶
Index ¶
- Variables
- func CalculateStrategyHolders(ctx context.Context, qdb *queries.Queries, ...) (map[common.Address]*big.Int, *big.Int, uint64, error)
- func CreateAndPublishCensus(db *censusdb.CensusDB, storage storagelayer.Storage, opts CensusOptions) (types.HexBytes, string, []byte, error)
- func Init(db *db.DB, conf Census3APIConf) (*census3API, error)
- func InnerCensusID(blockNumber, strategyID uint64, anonymous bool) uint64
- func TimeToCreateCensus(size uint64) uint64
- type APIInfo
- type CacheKey
- type Census3APIConf
- type CensusOptions
- type CensusQueueResponse
- type CreateCensusRequest
- type CreateStrategyRequest
- type CreateTokenRequest
- type GetCensusResponse
- type GetCensusesResponse
- type GetHoldersAtLastBlockResponse
- type GetStrategiesResponse
- type GetStrategyEstimationResponse
- type GetStrategyHoldersResponse
- type GetStrategyResponse
- type GetStrategyToken
- type GetTokenHolderResponse
- type GetTokenResponse
- type GetTokenStatusResponse
- type GetTokensItemResponse
- type GetTokensResponse
- type ImportStrategyQueueResponse
- type Pagination
- type QueueResponse
- type StrategyEstimation
- type StrategyToken
- type SupportedChain
- type TokenHoldersAtBlock
- type TokenHoldersResponse
- type TokenTypesResponse
Constants ¶
This section is empty.
Variables ¶
var ( ErrMalformedToken = apirest.APIerror{ Code: 4000, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("malformed token information"), } ErrMalformedCensusID = apirest.APIerror{ Code: 4001, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("malformed census ID, it must be a integer"), } ErrMalformedStrategyID = apirest.APIerror{ Code: 4002, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("malformed strategy ID, it must be an integer"), } ErrNotFoundToken = apirest.APIerror{ Code: 4003, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("no token found"), } ErrNotFoundTokenHolders = apirest.APIerror{ Code: 4004, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("no token holders found"), } ErrNotFoundStrategy = apirest.APIerror{ Code: 4005, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("no strategy found with the ID provided"), } ErrNotFoundCensus = apirest.APIerror{ Code: 4006, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("census not found"), } ErrNoTokens = apirest.APIerror{ Code: 4007, HTTPstatus: apirest.HTTPstatusNoContent, Err: fmt.Errorf("no tokens found"), } ErrNoStrategies = apirest.APIerror{ Code: 4008, HTTPstatus: apirest.HTTPstatusNoContent, Err: fmt.Errorf("no strategy found"), } ErrTokenAlreadyExists = apirest.APIerror{ Code: 4009, HTTPstatus: http.StatusConflict, Err: fmt.Errorf("token already created"), } ErrNoStrategyTokens = apirest.APIerror{ Code: 4010, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("no tokens found for the strategy provided"), } ErrMalformedCensusQueueID = apirest.APIerror{ Code: 4011, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("malformed queue ID"), } ErrCensusAlreadyExists = apirest.APIerror{ Code: 4012, HTTPstatus: http.StatusConflict, Err: fmt.Errorf("census already exists"), } ErrChainIDNotSupported = apirest.APIerror{ Code: 4013, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("chain ID provided not supported"), } ErrMalformedStrategy = apirest.APIerror{ Code: 4014, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("malformed strategy provided"), } ErrInvalidStrategyPredicate = apirest.APIerror{ Code: 4015, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("the predicate provided is not valid"), } ErrNoEnoughtStrategyTokens = apirest.APIerror{ Code: 4016, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("the predicate includes tokens that are not included in the request"), } ErrNoStrategyHolders = apirest.APIerror{ Code: 4017, HTTPstatus: apirest.HTTPstatusNoContent, Err: fmt.Errorf("strategy has not registered holders"), } ErrMalformedChainID = apirest.APIerror{ Code: 4018, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("malformed chain ID"), } ErrNoIPFSUri = apirest.APIerror{ Code: 4019, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("no IPFS uri provided"), } ErrMalformedStrategyQueueID = apirest.APIerror{ Code: 4020, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("malformed queue ID"), } ErrMalformedHolder = apirest.APIerror{ Code: 4021, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("malformed holder information"), } ErrMalformedPagination = apirest.APIerror{ Code: 4022, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("malformed pagination params"), } ErrNoTokenHolderFound = apirest.APIerror{ Code: 4023, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("token holder not found for the token provided"), } ErrCantCreateToken = apirest.APIerror{ Code: 5000, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("the token cannot be created"), } ErrCantCreateCensus = apirest.APIerror{ Code: 5001, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error creating the census tree on the census database"), } ErrCantAddHoldersToCensus = apirest.APIerror{ Code: 5002, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error adding the holders to the created census"), } ErrPruningCensus = apirest.APIerror{ Code: 5003, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error pruning the current census tree"), } ErrCantGetToken = apirest.APIerror{ Code: 5004, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error getting token information"), } ErrCantGetTokens = apirest.APIerror{ Code: 5005, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error getting tokens information"), } ErrCantGetTokenHolders = apirest.APIerror{ Code: 5006, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error getting token holders"), } ErrCantGetStrategy = apirest.APIerror{ Code: 5007, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error getting strategy information"), } ErrCantGetStrategies = apirest.APIerror{ Code: 5008, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error getting strategies information"), } ErrCantGetCensus = apirest.APIerror{ Code: 5009, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error getting census information"), } ErrEncodeToken = apirest.APIerror{ Code: 5010, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding token"), } ErrEncodeTokens = apirest.APIerror{ Code: 5011, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding tokens"), } ErrEncodeTokenTypes = apirest.APIerror{ Code: 5012, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding supported tokens types"), } ErrEncodeTokenHolders = apirest.APIerror{ Code: 5013, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding token holders"), } ErrEncodeStrategyHolders = apirest.APIerror{ Code: 5014, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding strategy holders"), } ErrEncodeStrategy = apirest.APIerror{ Code: 5015, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding strategy"), } ErrEncodeStrategies = apirest.APIerror{ Code: 5016, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding strategies"), } ErrEncodeCensus = apirest.APIerror{ Code: 5017, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding census"), } ErrEncodeCensuses = apirest.APIerror{ Code: 5018, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding censuses"), } ErrInitializingWeb3 = apirest.APIerror{ Code: 5019, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error initialising web3 client"), } ErrCantGetTokenCount = apirest.APIerror{ Code: 5020, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error getting number of token holders"), } ErrCantGetLastBlockNumber = apirest.APIerror{ Code: 5021, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error getting last block number from web3 endpoint"), } ErrEncodeQueueItem = apirest.APIerror{ Code: 5022, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding queue item"), } ErrEncodeAPIInfo = apirest.APIerror{ Code: 5023, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding API info"), } ErrEncodeValidPredicate = apirest.APIerror{ Code: 5024, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding validated strategy predicate"), } ErrCantCreateStrategy = apirest.APIerror{ Code: 5025, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error creating strategy"), } ErrEvalStrategyPredicate = apirest.APIerror{ Code: 5026, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error evaluating strategy predicate"), } ErrEncodeStrategyPredicateOperators = apirest.APIerror{ Code: 5027, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error encoding supported strategy predicate operators"), } ErrCantImportStrategy = apirest.APIerror{ Code: 5028, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error importing strategy"), } ErrCantDeleteToken = apirest.APIerror{ Code: 5029, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error deleting token"), } ErrCantGetStrategyHolders = apirest.APIerror{ Code: 5030, HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error getting strategy holders"), } )
Functions ¶
func CalculateStrategyHolders ¶ added in v0.1.3
func CalculateStrategyHolders(ctx context.Context, qdb *queries.Queries, providers map[uint64]providers.HolderProvider, id uint64, predicate string, ) (map[common.Address]*big.Int, *big.Int, uint64, error)
CalculateStrategyHolders function returns the holders of a strategy and the total weight of the census. It also returns the total block number of the census, which is the sum of the strategy block number or the last block number of every token chain id. To calculate the census holders, it uses the supplied predicate to filter the token holders using a lexer and evaluator. The evaluator uses the strategy operators to evaluate the predicate which uses the database queries to get the token holders and their balances, and combines them.
func CreateAndPublishCensus ¶ added in v0.1.3
func CreateAndPublishCensus( db *censusdb.CensusDB, storage storagelayer.Storage, opts CensusOptions, ) (types.HexBytes, string, []byte, error)
CreateAndPublishCensus function creates a new census tree based on the options provided and publishes it to IPFS. It needs to persist it temporaly into a internal trees database. It returns the root of the tree, the IPFS URI and the tree dump.
func InnerCensusID ¶ added in v0.1.3
InnerCensusID generates a unique identifier by concatenating the BlockNumber, StrategyID, and a numerical representation of the Anonymous flag from a CreateCensusRequest struct. The BlockNumber and StrategyID are concatenated as they are, and the Anonymous flag is represented as 1 for true and 0 for false. This concatenated string is then converted to a uint64 to create a unique identifier.
func TimeToCreateCensus ¶ added in v0.1.3
TimeToCreateCensus function returns the estimated time to create a census based on the number of holders. It uses a linear regression to estimate the time to create a census based on the number of holders. The regression was calculated using the census3 data (11/24/2023).
Types ¶
type APIInfo ¶ added in v0.1.3
type APIInfo struct {
SupportedChains []SupportedChain `json:"supportedChains"`
}
type CacheKey ¶ added in v0.1.3
type CacheKey [16]byte
func EncCacheKey ¶ added in v0.1.3
EncCacheKey encodes the key to a string to be used as a map key, it uses md5 to ensure the key is always the same length
type Census3APIConf ¶
type Census3APIConf struct { Hostname string Port int DataDir string GroupKey string Web3Providers web3.NetworkEndpoints HolderProviders map[uint64]providers.HolderProvider AdminToken string }
type CensusOptions ¶ added in v0.1.3
CensusOptions envolves the required parameters to create and publish a census merkle tree
type CensusQueueResponse ¶ added in v0.1.2
type CensusQueueResponse struct { Done bool `json:"done"` Error error `json:"error"` Census *GetCensusResponse `json:"census"` }
type CreateCensusRequest ¶ added in v0.1.2
type CreateStrategyRequest ¶ added in v0.1.3
type CreateStrategyRequest struct { Alias string `json:"alias"` Predicate string `json:"predicate"` Tokens map[string]*StrategyToken `json:"tokens"` }
type CreateTokenRequest ¶
type GetCensusResponse ¶
type GetCensusesResponse ¶
type GetCensusesResponse struct {
Censuses []*GetCensusResponse `json:"censuses"`
}
type GetHoldersAtLastBlockResponse ¶ added in v0.1.3
type GetHoldersAtLastBlockResponse struct { Done bool `json:"done"` Error error `json:"error"` HoldersAtBlock *TokenHoldersAtBlock `json:"holdersAtBlock"` }
type GetStrategiesResponse ¶
type GetStrategiesResponse struct { Strategies []*GetStrategyResponse `json:"strategies"` Pagination *Pagination `json:"pagination"` }
type GetStrategyEstimationResponse ¶ added in v0.1.3
type GetStrategyEstimationResponse struct { Done bool `json:"done"` Error error `json:"error"` Estimation *StrategyEstimation `json:"estimation"` }
type GetStrategyHoldersResponse ¶ added in v0.1.3
type GetStrategyHoldersResponse struct { Holders map[string]string `json:"holders"` Pagination *Pagination `json:"pagination"` }
type GetStrategyResponse ¶
type GetStrategyToken ¶
type GetTokenHolderResponse ¶ added in v0.1.3
type GetTokenHolderResponse struct {
Balance string `json:"balance"`
}
type GetTokenResponse ¶
type GetTokenResponse struct { ID string `json:"ID"` Type string `json:"type"` Decimals uint64 `json:"decimals"` StartBlock uint64 `json:"startBlock"` Symbol string `json:"symbol"` TotalSupply string `json:"totalSupply"` Name string `json:"name"` Status *GetTokenStatusResponse `json:"status"` Size uint64 `json:"size"` DefaultStrategy uint64 `json:"defaultStrategy,omitempty"` Tags string `json:"tags,omitempty"` ChainID uint64 `json:"chainID"` ChainAddress string `json:"chainAddress"` ExternalID string `json:"externalID,omitempty"` IconURI string `json:"iconURI,omitempty"` }
type GetTokenStatusResponse ¶
type GetTokensItemResponse ¶ added in v0.1.3
type GetTokensItemResponse struct { ID string `json:"ID"` Type string `json:"type"` Decimals uint64 `json:"decimals"` StartBlock uint64 `json:"startBlock"` Symbol string `json:"symbol"` TotalSupply string `json:"totalSupply"` Name string `json:"name"` Synced bool `json:"synced"` DefaultStrategy uint64 `json:"defaultStrategy,omitempty"` Tags string `json:"tags,omitempty"` ChainID uint64 `json:"chainID"` ChainAddress string `json:"chainAddress"` ExternalID string `json:"externalID,omitempty"` IconURI string `json:"iconURI,omitempty"` }
type GetTokensResponse ¶
type GetTokensResponse struct { Tokens []GetTokensItemResponse `json:"tokens"` Pagination *Pagination `json:"pagination"` }
type ImportStrategyQueueResponse ¶ added in v0.1.3
type ImportStrategyQueueResponse struct { Done bool `json:"done"` Error error `json:"error"` Strategy *GetStrategyResponse `json:"strategy"` }
type Pagination ¶ added in v0.1.3
type QueueResponse ¶ added in v0.1.3
type QueueResponse struct {
QueueID string `json:"queueID"`
}
type StrategyEstimation ¶ added in v0.1.3
type StrategyToken ¶ added in v0.1.3
type SupportedChain ¶ added in v0.1.3
type TokenHoldersAtBlock ¶ added in v0.1.3
type TokenHoldersResponse ¶
type TokenTypesResponse ¶
type TokenTypesResponse struct {
SupportedTypes []string `json:"supportedTypes"`
}