id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
141,600
decred/dcrdata
db/dcrpg/tables.go
CheckColumnDataType
func CheckColumnDataType(db *sql.DB, table, column string) (dataType string, err error) { err = db.QueryRow(`SELECT data_type FROM information_schema.columns WHERE table_name=$1 AND column_name=$2`, table, column).Scan(&dataType) return }
go
func CheckColumnDataType(db *sql.DB, table, column string) (dataType string, err error) { err = db.QueryRow(`SELECT data_type FROM information_schema.columns WHERE table_name=$1 AND column_name=$2`, table, column).Scan(&dataType) return }
[ "func", "CheckColumnDataType", "(", "db", "*", "sql", ".", "DB", ",", "table", ",", "column", "string", ")", "(", "dataType", "string", ",", "err", "error", ")", "{", "err", "=", "db", ".", "QueryRow", "(", "`SELECT data_type\n\t\tFROM information_schema.colum...
// CheckColumnDataType gets the data type of specified table column .
[ "CheckColumnDataType", "gets", "the", "data", "type", "of", "specified", "table", "column", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/tables.go#L224-L230
141,601
decred/dcrdata
db/dcrpg/tables.go
DeleteDuplicates
func (pgb *ChainDB) DeleteDuplicates(barLoad chan *dbtypes.ProgressBarLoad) error { allDuplicates := []dropDuplicatesInfo{ // Remove duplicate vins {TableName: "vins", DropDupsFunc: pgb.DeleteDuplicateVins}, // Remove duplicate vouts {TableName: "vouts", DropDupsFunc: pgb.DeleteDuplicateVouts}, // Remove d...
go
func (pgb *ChainDB) DeleteDuplicates(barLoad chan *dbtypes.ProgressBarLoad) error { allDuplicates := []dropDuplicatesInfo{ // Remove duplicate vins {TableName: "vins", DropDupsFunc: pgb.DeleteDuplicateVins}, // Remove duplicate vouts {TableName: "vouts", DropDupsFunc: pgb.DeleteDuplicateVouts}, // Remove d...
[ "func", "(", "pgb", "*", "ChainDB", ")", "DeleteDuplicates", "(", "barLoad", "chan", "*", "dbtypes", ".", "ProgressBarLoad", ")", "error", "{", "allDuplicates", ":=", "[", "]", "dropDuplicatesInfo", "{", "// Remove duplicate vins", "{", "TableName", ":", "\"", ...
// DeleteDuplicates attempts to delete "duplicate" rows in tables where unique // indexes are to be created.
[ "DeleteDuplicates", "attempts", "to", "delete", "duplicate", "rows", "in", "tables", "where", "unique", "indexes", "are", "to", "be", "created", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/tables.go#L234-L276
141,602
decred/dcrdata
api/apirouter.go
stackedMux
func stackedMux(useRealIP bool) *chi.Mux { mux := chi.NewRouter() if useRealIP { mux.Use(middleware.RealIP) } mux.Use(middleware.Logger) mux.Use(middleware.Recoverer) corsMW := cors.Default() mux.Use(corsMW.Handler) return mux }
go
func stackedMux(useRealIP bool) *chi.Mux { mux := chi.NewRouter() if useRealIP { mux.Use(middleware.RealIP) } mux.Use(middleware.Logger) mux.Use(middleware.Recoverer) corsMW := cors.Default() mux.Use(corsMW.Handler) return mux }
[ "func", "stackedMux", "(", "useRealIP", "bool", ")", "*", "chi", ".", "Mux", "{", "mux", ":=", "chi", ".", "NewRouter", "(", ")", "\n", "if", "useRealIP", "{", "mux", ".", "Use", "(", "middleware", ".", "RealIP", ")", "\n", "}", "\n", "mux", ".", ...
// Stacks some middleware common to both file and api router.
[ "Stacks", "some", "middleware", "common", "to", "both", "file", "and", "api", "router", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/apirouter.go#L289-L299
141,603
decred/dcrdata
api/apiroutes.go
NewContext
func NewContext(cfg *AppContextConfig) *appContext { conns, _ := cfg.Client.GetConnectionCount() nodeHeight, _ := cfg.Client.GetBlockCount() // auxDataSource is an interface that could have a value of pointer type. if cfg.DBSource == nil || reflect.ValueOf(cfg.DBSource).IsNil() { log.Errorf("NewContext: a DataSo...
go
func NewContext(cfg *AppContextConfig) *appContext { conns, _ := cfg.Client.GetConnectionCount() nodeHeight, _ := cfg.Client.GetBlockCount() // auxDataSource is an interface that could have a value of pointer type. if cfg.DBSource == nil || reflect.ValueOf(cfg.DBSource).IsNil() { log.Errorf("NewContext: a DataSo...
[ "func", "NewContext", "(", "cfg", "*", "AppContextConfig", ")", "*", "appContext", "{", "conns", ",", "_", ":=", "cfg", ".", "Client", ".", "GetConnectionCount", "(", ")", "\n", "nodeHeight", ",", "_", ":=", "cfg", ".", "Client", ".", "GetBlockCount", "(...
// NewContext constructs a new appContext from the RPC client, primary and // auxiliary data sources, and JSON indentation string.
[ "NewContext", "constructs", "a", "new", "appContext", "from", "the", "RPC", "client", "primary", "and", "auxiliary", "data", "sources", "and", "JSON", "indentation", "string", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/apiroutes.go#L150-L172
141,604
decred/dcrdata
api/apiroutes.go
StatusNtfnHandler
func (c *appContext) StatusNtfnHandler(ctx context.Context, wg *sync.WaitGroup) { defer wg.Done() out: for { keepon: select { case height, ok := <-notify.NtfnChans.UpdateStatusNodeHeight: if !ok { log.Warnf("Block connected channel closed.") break out } nodeConnections, err := c.nodeClient.GetC...
go
func (c *appContext) StatusNtfnHandler(ctx context.Context, wg *sync.WaitGroup) { defer wg.Done() out: for { keepon: select { case height, ok := <-notify.NtfnChans.UpdateStatusNodeHeight: if !ok { log.Warnf("Block connected channel closed.") break out } nodeConnections, err := c.nodeClient.GetC...
[ "func", "(", "c", "*", "appContext", ")", "StatusNtfnHandler", "(", "ctx", "context", ".", "Context", ",", "wg", "*", "sync", ".", "WaitGroup", ")", "{", "defer", "wg", ".", "Done", "(", ")", "\n", "out", ":", "for", "{", "keepon", ":", "select", "...
// StatusNtfnHandler keeps the appContext's Status up-to-date with changes in // node and DB status.
[ "StatusNtfnHandler", "keeps", "the", "appContext", "s", "Status", "up", "-", "to", "-", "date", "with", "changes", "in", "node", "and", "DB", "status", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/apiroutes.go#L176-L238
141,605
decred/dcrdata
api/apiroutes.go
root
func (c *appContext) root(w http.ResponseWriter, _ *http.Request) { fmt.Fprint(w, "dcrdata api running") }
go
func (c *appContext) root(w http.ResponseWriter, _ *http.Request) { fmt.Fprint(w, "dcrdata api running") }
[ "func", "(", "c", "*", "appContext", ")", "root", "(", "w", "http", ".", "ResponseWriter", ",", "_", "*", "http", ".", "Request", ")", "{", "fmt", ".", "Fprint", "(", "w", ",", "\"", "\"", ")", "\n", "}" ]
// root is a http.Handler intended for the API root path. This essentially // provides a heartbeat, and no information about the application status.
[ "root", "is", "a", "http", ".", "Handler", "intended", "for", "the", "API", "root", "path", ".", "This", "essentially", "provides", "a", "heartbeat", "and", "no", "information", "about", "the", "application", "status", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/apiroutes.go#L242-L244
141,606
decred/dcrdata
api/apiroutes.go
writeJSONBytes
func writeJSONBytes(w http.ResponseWriter, data []byte) { w.Header().Set("Content-Type", "application/json; charset=utf-8") _, err := w.Write(data) if err != nil { apiLog.Warnf("ResponseWriter.Write error: %v", err) } }
go
func writeJSONBytes(w http.ResponseWriter, data []byte) { w.Header().Set("Content-Type", "application/json; charset=utf-8") _, err := w.Write(data) if err != nil { apiLog.Warnf("ResponseWriter.Write error: %v", err) } }
[ "func", "writeJSONBytes", "(", "w", "http", ".", "ResponseWriter", ",", "data", "[", "]", "byte", ")", "{", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "_", ",", "err", ":=", "w", ".", "Write", "(", ...
// writeJSONBytes prepares the headers for pre-encoded JSON and writes the JSON // bytes.
[ "writeJSONBytes", "prepares", "the", "headers", "for", "pre", "-", "encoded", "JSON", "and", "writes", "the", "JSON", "bytes", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/apiroutes.go#L263-L269
141,607
decred/dcrdata
api/apiroutes.go
writeCSV
func writeCSV(w http.ResponseWriter, rows [][]string, filename string, useCRLF bool) { w.Header().Set("Content-Disposition", fmt.Sprintf("attachment;filename=%s", filename)) w.Header().Set("Content-Type", "text/csv") // To set the Content-Length response header, it is necessary to write the // CSV data into a bu...
go
func writeCSV(w http.ResponseWriter, rows [][]string, filename string, useCRLF bool) { w.Header().Set("Content-Disposition", fmt.Sprintf("attachment;filename=%s", filename)) w.Header().Set("Content-Type", "text/csv") // To set the Content-Length response header, it is necessary to write the // CSV data into a bu...
[ "func", "writeCSV", "(", "w", "http", ".", "ResponseWriter", ",", "rows", "[", "]", "[", "]", "string", ",", "filename", "string", ",", "useCRLF", "bool", ")", "{", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "fmt", ".", "Spri...
// Measures length, sets common headers, formats, and sends CSV data.
[ "Measures", "length", "sets", "common", "headers", "formats", "and", "sends", "CSV", "data", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/apiroutes.go#L272-L308
141,608
decred/dcrdata
api/apiroutes.go
setTrimmedTxSpends
func (c *appContext) setTrimmedTxSpends(tx *apitypes.TrimmedTx) error { return c.setOutputSpends(tx.TxID, tx.Vout) }
go
func (c *appContext) setTrimmedTxSpends(tx *apitypes.TrimmedTx) error { return c.setOutputSpends(tx.TxID, tx.Vout) }
[ "func", "(", "c", "*", "appContext", ")", "setTrimmedTxSpends", "(", "tx", "*", "apitypes", ".", "TrimmedTx", ")", "error", "{", "return", "c", ".", "setOutputSpends", "(", "tx", ".", "TxID", ",", "tx", ".", "Vout", ")", "\n", "}" ]
// setTrimmedTxSpends is like setTxSpends except that it operates on a TrimmedTx // instead of a Tx.
[ "setTrimmedTxSpends", "is", "like", "setTxSpends", "except", "that", "it", "operates", "on", "a", "TrimmedTx", "instead", "of", "a", "Tx", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/apiroutes.go#L603-L605
141,609
decred/dcrdata
api/apiroutes.go
getBlockStakeInfoExtendedByHash
func (c *appContext) getBlockStakeInfoExtendedByHash(w http.ResponseWriter, r *http.Request) { hash, err := c.getBlockHashCtx(r) if err != nil { http.Error(w, http.StatusText(422), 422) return } stakeinfo := c.BlockData.GetStakeInfoExtendedByHash(hash) if stakeinfo == nil { apiLog.Errorf("Unable to get bloc...
go
func (c *appContext) getBlockStakeInfoExtendedByHash(w http.ResponseWriter, r *http.Request) { hash, err := c.getBlockHashCtx(r) if err != nil { http.Error(w, http.StatusText(422), 422) return } stakeinfo := c.BlockData.GetStakeInfoExtendedByHash(hash) if stakeinfo == nil { apiLog.Errorf("Unable to get bloc...
[ "func", "(", "c", "*", "appContext", ")", "getBlockStakeInfoExtendedByHash", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "hash", ",", "err", ":=", "c", ".", "getBlockHashCtx", "(", "r", ")", "\n", "if", "er...
// getBlockStakeInfoExtendedByHash retrieves the apitype.StakeInfoExtended // for the given blockhash
[ "getBlockStakeInfoExtendedByHash", "retrieves", "the", "apitype", ".", "StakeInfoExtended", "for", "the", "given", "blockhash" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/apiroutes.go#L894-L909
141,610
decred/dcrdata
api/apiroutes.go
getBlockStakeInfoExtendedByHeight
func (c *appContext) getBlockStakeInfoExtendedByHeight(w http.ResponseWriter, r *http.Request) { idx, err := c.getBlockHeightCtx(r) if err != nil { http.Error(w, http.StatusText(422), 422) return } stakeinfo := c.BlockData.GetStakeInfoExtendedByHeight(int(idx)) if stakeinfo == nil { apiLog.Errorf("Unable to ...
go
func (c *appContext) getBlockStakeInfoExtendedByHeight(w http.ResponseWriter, r *http.Request) { idx, err := c.getBlockHeightCtx(r) if err != nil { http.Error(w, http.StatusText(422), 422) return } stakeinfo := c.BlockData.GetStakeInfoExtendedByHeight(int(idx)) if stakeinfo == nil { apiLog.Errorf("Unable to ...
[ "func", "(", "c", "*", "appContext", ")", "getBlockStakeInfoExtendedByHeight", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "idx", ",", "err", ":=", "c", ".", "getBlockHeightCtx", "(", "r", ")", "\n", "if", ...
// getBlockStakeInfoExtendedByHeight retrieves the apitype.StakeInfoExtended // for the given blockheight on mainchain
[ "getBlockStakeInfoExtendedByHeight", "retrieves", "the", "apitype", ".", "StakeInfoExtended", "for", "the", "given", "blockheight", "on", "mainchain" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/apiroutes.go#L913-L927
141,611
decred/dcrdata
api/apiroutes.go
getPowerlessTickets
func (c *appContext) getPowerlessTickets(w http.ResponseWriter, r *http.Request) { tickets, err := c.AuxDataSource.PowerlessTickets() if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } writeJSON(w, tickets, c.getIndentQuery(r)) }
go
func (c *appContext) getPowerlessTickets(w http.ResponseWriter, r *http.Request) { tickets, err := c.AuxDataSource.PowerlessTickets() if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } writeJSON(w, tickets, c.getIndentQuery(r)) }
[ "func", "(", "c", "*", "appContext", ")", "getPowerlessTickets", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "tickets", ",", "err", ":=", "c", ".", "AuxDataSource", ".", "PowerlessTickets", "(", ")", "\n", ...
// Encodes apitypes.PowerlessTickets, which is missed or expired tickets sorted // by revocation status.
[ "Encodes", "apitypes", ".", "PowerlessTickets", "which", "is", "missed", "or", "expired", "tickets", "sorted", "by", "revocation", "status", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/apiroutes.go#L942-L949
141,612
decred/dcrdata
api/apiroutes.go
getAgendasData
func (c *appContext) getAgendasData(w http.ResponseWriter, _ *http.Request) { agendas, err := c.AgendaDB.AllAgendas() if err != nil { apiLog.Errorf("agendadb AllAgendas error: %v", err) http.Error(w, "agendadb.AllAgendas failed.", http.StatusServiceUnavailable) return } voteMilestones, err := c.AuxDataSource...
go
func (c *appContext) getAgendasData(w http.ResponseWriter, _ *http.Request) { agendas, err := c.AgendaDB.AllAgendas() if err != nil { apiLog.Errorf("agendadb AllAgendas error: %v", err) http.Error(w, "agendadb.AllAgendas failed.", http.StatusServiceUnavailable) return } voteMilestones, err := c.AuxDataSource...
[ "func", "(", "c", "*", "appContext", ")", "getAgendasData", "(", "w", "http", ".", "ResponseWriter", ",", "_", "*", "http", ".", "Request", ")", "{", "agendas", ",", "err", ":=", "c", ".", "AgendaDB", ".", "AllAgendas", "(", ")", "\n", "if", "err", ...
// getAgendasData returns high level agendas details that includes Name, // Description, Vote Version, VotingDone height, Activated, HardForked, // StartTime and ExpireTime.
[ "getAgendasData", "returns", "high", "level", "agendas", "details", "that", "includes", "Name", "Description", "Vote", "Version", "VotingDone", "height", "Activated", "HardForked", "StartTime", "and", "ExpireTime", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/apiroutes.go#L1757-L1787
141,613
decred/dcrdata
db/dbtypes/types.go
IsTimeout
func IsTimeout(msg string) bool { // Contains is used instead of HasPrefix since error messages are often // supplemented with additional information. return strings.Contains(msg, TimeoutPrefix) || strings.Contains(msg, CtxDeadlineExceeded) }
go
func IsTimeout(msg string) bool { // Contains is used instead of HasPrefix since error messages are often // supplemented with additional information. return strings.Contains(msg, TimeoutPrefix) || strings.Contains(msg, CtxDeadlineExceeded) }
[ "func", "IsTimeout", "(", "msg", "string", ")", "bool", "{", "// Contains is used instead of HasPrefix since error messages are often", "// supplemented with additional information.", "return", "strings", ".", "Contains", "(", "msg", ",", "TimeoutPrefix", ")", "||", "strings"...
// IsTimeout checks if the message is prefixed with the expected DB timeout // message prefix.
[ "IsTimeout", "checks", "if", "the", "message", "is", "prefixed", "with", "the", "expected", "DB", "timeout", "message", "prefix", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L32-L37
141,614
decred/dcrdata
db/dbtypes/types.go
Value
func (t TimeDef) Value() (driver.Value, error) { return t.T.UTC(), nil }
go
func (t TimeDef) Value() (driver.Value, error) { return t.T.UTC(), nil }
[ "func", "(", "t", "TimeDef", ")", "Value", "(", ")", "(", "driver", ".", "Value", ",", "error", ")", "{", "return", "t", ".", "T", ".", "UTC", "(", ")", ",", "nil", "\n", "}" ]
// Value implements the sql.Valuer interface. It ensures that the Time Values // are for the UTC time zone. Times will only survive a round trip to and from // the DB tables if they are stored from a time.Time with Location set to UTC.
[ "Value", "implements", "the", "sql", ".", "Valuer", "interface", ".", "It", "ensures", "that", "the", "Time", "Values", "are", "for", "the", "UTC", "time", "zone", ".", "Times", "will", "only", "survive", "a", "round", "trip", "to", "and", "from", "the",...
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L130-L132
141,615
decred/dcrdata
db/dbtypes/types.go
Value
func (t TimeDefLocal) Value() (driver.Value, error) { return t.T.Local(), nil }
go
func (t TimeDefLocal) Value() (driver.Value, error) { return t.T.Local(), nil }
[ "func", "(", "t", "TimeDefLocal", ")", "Value", "(", ")", "(", "driver", ".", "Value", ",", "error", ")", "{", "return", "t", ".", "T", ".", "Local", "(", ")", ",", "nil", "\n", "}" ]
// Value implements the sql.Valuer interface. It ensures that the Time Values // are for the Local time zone. It is unlikely to be desirable to store values // this way. Only storing a time.Time in UTC allows round trip fidelity.
[ "Value", "implements", "the", "sql", ".", "Valuer", "interface", ".", "It", "ensures", "that", "the", "Time", "Values", "are", "for", "the", "Local", "time", "zone", ".", "It", "is", "unlikely", "to", "be", "desirable", "to", "store", "values", "this", "...
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L143-L145
141,616
decred/dcrdata
db/dbtypes/types.go
UnmarshalJSON
func (a *AgendaStatusType) UnmarshalJSON(b []byte) error { var str string if err := json.Unmarshal(b, &str); err != nil { return err } *a = AgendaStatusFromStr(str) return nil }
go
func (a *AgendaStatusType) UnmarshalJSON(b []byte) error { var str string if err := json.Unmarshal(b, &str); err != nil { return err } *a = AgendaStatusFromStr(str) return nil }
[ "func", "(", "a", "*", "AgendaStatusType", ")", "UnmarshalJSON", "(", "b", "[", "]", "byte", ")", "error", "{", "var", "str", "string", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "b", ",", "&", "str", ")", ";", "err", "!=", "nil", "{...
// UnmarshalJSON is the default unmarshaller for AgendaStatusType.
[ "UnmarshalJSON", "is", "the", "default", "unmarshaller", "for", "AgendaStatusType", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L232-L239
141,617
decred/dcrdata
db/dbtypes/types.go
AgendaStatusFromStr
func AgendaStatusFromStr(status string) AgendaStatusType { switch strings.ToLower(status) { case "defined", "upcoming": return InitialAgendaStatus case "started", "in progress": return StartedAgendaStatus case "failed": return FailedAgendaStatus case "lockedin", "locked in": return LockedInAgendaStatus ca...
go
func AgendaStatusFromStr(status string) AgendaStatusType { switch strings.ToLower(status) { case "defined", "upcoming": return InitialAgendaStatus case "started", "in progress": return StartedAgendaStatus case "failed": return FailedAgendaStatus case "lockedin", "locked in": return LockedInAgendaStatus ca...
[ "func", "AgendaStatusFromStr", "(", "status", "string", ")", "AgendaStatusType", "{", "switch", "strings", ".", "ToLower", "(", "status", ")", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "return", "InitialAgendaStatus", "\n", "case", "\"", "\"", ",", "\...
// AgendaStatusFromStr creates an agenda status from a string. If "UnknownStatus" // is returned then an invalid status string has been passed.
[ "AgendaStatusFromStr", "creates", "an", "agenda", "status", "from", "a", "string", ".", "If", "UnknownStatus", "is", "returned", "then", "an", "invalid", "status", "string", "has", "been", "passed", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L243-L258
141,618
decred/dcrdata
db/dbtypes/types.go
IsMerged
func (a AddrTxnViewType) IsMerged() (bool, error) { switch a { case AddrTxnAll, AddrTxnCredit, AddrTxnDebit: return false, nil case AddrMergedTxn, AddrMergedTxnCredit, AddrMergedTxnDebit: return true, nil default: return false, fmt.Errorf("unrecognized address transaction view: %v", a) } }
go
func (a AddrTxnViewType) IsMerged() (bool, error) { switch a { case AddrTxnAll, AddrTxnCredit, AddrTxnDebit: return false, nil case AddrMergedTxn, AddrMergedTxnCredit, AddrMergedTxnDebit: return true, nil default: return false, fmt.Errorf("unrecognized address transaction view: %v", a) } }
[ "func", "(", "a", "AddrTxnViewType", ")", "IsMerged", "(", ")", "(", "bool", ",", "error", ")", "{", "switch", "a", "{", "case", "AddrTxnAll", ",", "AddrTxnCredit", ",", "AddrTxnDebit", ":", "return", "false", ",", "nil", "\n", "case", "AddrMergedTxn", "...
// IsMerged indicates if the address transactions view type is a merged view. If // the type is invalid, a non-nil error is returned.
[ "IsMerged", "indicates", "if", "the", "address", "transactions", "view", "type", "is", "a", "merged", "view", ".", "If", "the", "type", "is", "invalid", "a", "non", "-", "nil", "error", "is", "returned", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L291-L300
141,619
decred/dcrdata
db/dbtypes/types.go
AddrTxnViewTypeFromStr
func AddrTxnViewTypeFromStr(txnType string) AddrTxnViewType { txnType = strings.ToLower(txnType) switch txnType { case "all": return AddrTxnAll case "credit", "credits": return AddrTxnCredit case "debit", "debits": return AddrTxnDebit case "merged_debit", "merged debit": return AddrMergedTxnDebit case "m...
go
func AddrTxnViewTypeFromStr(txnType string) AddrTxnViewType { txnType = strings.ToLower(txnType) switch txnType { case "all": return AddrTxnAll case "credit", "credits": return AddrTxnCredit case "debit", "debits": return AddrTxnDebit case "merged_debit", "merged debit": return AddrMergedTxnDebit case "m...
[ "func", "AddrTxnViewTypeFromStr", "(", "txnType", "string", ")", "AddrTxnViewType", "{", "txnType", "=", "strings", ".", "ToLower", "(", "txnType", ")", "\n", "switch", "txnType", "{", "case", "\"", "\"", ":", "return", "AddrTxnAll", "\n", "case", "\"", "\""...
// AddrTxnViewTypeFromStr attempts to decode a string into an AddrTxnViewType.
[ "AddrTxnViewTypeFromStr", "attempts", "to", "decode", "a", "string", "into", "an", "AddrTxnViewType", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L303-L321
141,620
decred/dcrdata
db/dbtypes/types.go
TimeGroupingFromStr
func TimeGroupingFromStr(groupings string) TimeBasedGrouping { switch strings.ToLower(groupings) { case "all": return AllGrouping case "yr", "year", "years": return YearGrouping case "mo", "month", "months": return MonthGrouping case "wk", "week", "weeks": return WeekGrouping case "day", "days": return ...
go
func TimeGroupingFromStr(groupings string) TimeBasedGrouping { switch strings.ToLower(groupings) { case "all": return AllGrouping case "yr", "year", "years": return YearGrouping case "mo", "month", "months": return MonthGrouping case "wk", "week", "weeks": return WeekGrouping case "day", "days": return ...
[ "func", "TimeGroupingFromStr", "(", "groupings", "string", ")", "TimeBasedGrouping", "{", "switch", "strings", ".", "ToLower", "(", "groupings", ")", "{", "case", "\"", "\"", ":", "return", "AllGrouping", "\n", "case", "\"", "\"", ",", "\"", "\"", ",", "\"...
// TimeGroupingFromStr converts groupings string to its respective TimeBasedGrouping value.
[ "TimeGroupingFromStr", "converts", "groupings", "string", "to", "its", "respective", "TimeBasedGrouping", "value", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L411-L426
141,621
decred/dcrdata
db/dbtypes/types.go
ChoiceIndexFromStr
func ChoiceIndexFromStr(choice string) (VoteChoice, error) { switch choice { case "abstain": return Abstain, nil case "yes": return Yes, nil case "no": return No, nil default: return VoteChoiceUnknown, fmt.Errorf(`Vote Choice "%s" is unknown`, choice) } }
go
func ChoiceIndexFromStr(choice string) (VoteChoice, error) { switch choice { case "abstain": return Abstain, nil case "yes": return Yes, nil case "no": return No, nil default: return VoteChoiceUnknown, fmt.Errorf(`Vote Choice "%s" is unknown`, choice) } }
[ "func", "ChoiceIndexFromStr", "(", "choice", "string", ")", "(", "VoteChoice", ",", "error", ")", "{", "switch", "choice", "{", "case", "\"", "\"", ":", "return", "Abstain", ",", "nil", "\n", "case", "\"", "\"", ":", "return", "Yes", ",", "nil", "\n", ...
// ChoiceIndexFromStr converts the vote choice string to a vote choice index.
[ "ChoiceIndexFromStr", "converts", "the", "vote", "choice", "string", "to", "a", "vote", "choice", "index", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L488-L499
141,622
decred/dcrdata
db/dbtypes/types.go
Value
func (p VinTxPropertyARRAY) Value() (driver.Value, error) { j, err := json.Marshal(p) return j, err }
go
func (p VinTxPropertyARRAY) Value() (driver.Value, error) { j, err := json.Marshal(p) return j, err }
[ "func", "(", "p", "VinTxPropertyARRAY", ")", "Value", "(", ")", "(", "driver", ".", "Value", ",", "error", ")", "{", "j", ",", "err", ":=", "json", ".", "Marshal", "(", "p", ")", "\n", "return", "j", ",", "err", "\n", "}" ]
// Value satisfies driver.Valuer
[ "Value", "satisfies", "driver", ".", "Valuer" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L585-L588
141,623
decred/dcrdata
db/dbtypes/types.go
Scan
func (p *VinTxPropertyARRAY) Scan(src interface{}) error { source, ok := src.([]byte) if !ok { return fmt.Errorf("scan type assertion .([]byte) failed") } var i interface{} err := json.Unmarshal(source, &i) if err != nil { return err } // Set this JSONB is, ok := i.([]interface{}) if !ok { return fmt....
go
func (p *VinTxPropertyARRAY) Scan(src interface{}) error { source, ok := src.([]byte) if !ok { return fmt.Errorf("scan type assertion .([]byte) failed") } var i interface{} err := json.Unmarshal(source, &i) if err != nil { return err } // Set this JSONB is, ok := i.([]interface{}) if !ok { return fmt....
[ "func", "(", "p", "*", "VinTxPropertyARRAY", ")", "Scan", "(", "src", "interface", "{", "}", ")", "error", "{", "source", ",", "ok", ":=", "src", ".", "(", "[", "]", "byte", ")", "\n", "if", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", ...
// Scan satisfies sql.Scanner
[ "Scan", "satisfies", "sql", ".", "Scanner" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L591-L624
141,624
decred/dcrdata
db/dbtypes/types.go
String
func (s DeletionSummary) String() string { summary := fmt.Sprintf("%9d Blocks purged\n", s.Blocks) summary += fmt.Sprintf("%9d Vins purged\n", s.Vins) summary += fmt.Sprintf("%9d Vouts purged\n", s.Vouts) summary += fmt.Sprintf("%9d Addresses purged\n", s.Addresses) summary += fmt.Sprintf("%9d Transactions purged\...
go
func (s DeletionSummary) String() string { summary := fmt.Sprintf("%9d Blocks purged\n", s.Blocks) summary += fmt.Sprintf("%9d Vins purged\n", s.Vins) summary += fmt.Sprintf("%9d Vouts purged\n", s.Vouts) summary += fmt.Sprintf("%9d Addresses purged\n", s.Addresses) summary += fmt.Sprintf("%9d Transactions purged\...
[ "func", "(", "s", "DeletionSummary", ")", "String", "(", ")", "string", "{", "summary", ":=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "s", ".", "Blocks", ")", "\n", "summary", "+=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", ...
// String makes a pretty summary of the totals.
[ "String", "makes", "a", "pretty", "summary", "of", "the", "totals", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L634-L644
141,625
decred/dcrdata
db/dbtypes/types.go
Reduce
func (ds DeletionSummarySlice) Reduce() DeletionSummary { var s DeletionSummary for i := range ds { s.Blocks += ds[i].Blocks s.Vins += ds[i].Vins s.Vouts += ds[i].Vouts s.Addresses += ds[i].Addresses s.Transactions += ds[i].Transactions s.Tickets += ds[i].Tickets s.Votes += ds[i].Votes s.Misses += ds[...
go
func (ds DeletionSummarySlice) Reduce() DeletionSummary { var s DeletionSummary for i := range ds { s.Blocks += ds[i].Blocks s.Vins += ds[i].Vins s.Vouts += ds[i].Vouts s.Addresses += ds[i].Addresses s.Transactions += ds[i].Transactions s.Tickets += ds[i].Tickets s.Votes += ds[i].Votes s.Misses += ds[...
[ "func", "(", "ds", "DeletionSummarySlice", ")", "Reduce", "(", ")", "DeletionSummary", "{", "var", "s", "DeletionSummary", "\n", "for", "i", ":=", "range", "ds", "{", "s", ".", "Blocks", "+=", "ds", "[", "i", "]", ".", "Blocks", "\n", "s", ".", "Vins...
// Reduce returns a single DeletionSummary with the corresponding fields summed.
[ "Reduce", "returns", "a", "single", "DeletionSummary", "with", "the", "corresponding", "fields", "summed", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L650-L663
141,626
decred/dcrdata
db/dbtypes/types.go
ReduceAddressHistory
func ReduceAddressHistory(addrHist []*AddressRow) (*AddressInfo, float64, float64) { if len(addrHist) == 0 { return nil, 0, 0 } var received, sent, fromStake, toStake int64 var transactions, creditTxns, debitTxns []*AddressTx for _, addrOut := range addrHist { if !addrOut.ValidMainChain { continue } co...
go
func ReduceAddressHistory(addrHist []*AddressRow) (*AddressInfo, float64, float64) { if len(addrHist) == 0 { return nil, 0, 0 } var received, sent, fromStake, toStake int64 var transactions, creditTxns, debitTxns []*AddressTx for _, addrOut := range addrHist { if !addrOut.ValidMainChain { continue } co...
[ "func", "ReduceAddressHistory", "(", "addrHist", "[", "]", "*", "AddressRow", ")", "(", "*", "AddressInfo", ",", "float64", ",", "float64", ")", "{", "if", "len", "(", "addrHist", ")", "==", "0", "{", "return", "nil", ",", "0", ",", "0", "\n", "}", ...
// ReduceAddressHistory generates a template AddressInfo from a slice of // AddressRow. All fields except NumUnconfirmed and Transactions are set // completely. Transactions is partially set, with each transaction having only // the TxID and ReceivedTotal set. The rest of the data should be filled in by // other means,...
[ "ReduceAddressHistory", "generates", "a", "template", "AddressInfo", "from", "a", "slice", "of", "AddressRow", ".", "All", "fields", "except", "NumUnconfirmed", "and", "Transactions", "are", "set", "completely", ".", "Transactions", "is", "partially", "set", "with",...
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L1567-L1631
141,627
decred/dcrdata
stakedb/chainmonitor.go
ReorgHandler
func (p *ChainMonitor) ReorgHandler() { defer p.wg.Done() out: for { //keepon: select { case reorgData, ok := <-p.reorgChan: p.mtx.Lock() if !ok { p.mtx.Unlock() log.Warnf("Reorg channel closed.") break out } newHeight, oldHeight := reorgData.NewChainHeight, reorgData.OldChainHeight ...
go
func (p *ChainMonitor) ReorgHandler() { defer p.wg.Done() out: for { //keepon: select { case reorgData, ok := <-p.reorgChan: p.mtx.Lock() if !ok { p.mtx.Unlock() log.Warnf("Reorg channel closed.") break out } newHeight, oldHeight := reorgData.NewChainHeight, reorgData.OldChainHeight ...
[ "func", "(", "p", "*", "ChainMonitor", ")", "ReorgHandler", "(", ")", "{", "defer", "p", ".", "wg", ".", "Done", "(", ")", "\n", "out", ":", "for", "{", "//keepon:", "select", "{", "case", "reorgData", ",", "ok", ":=", "<-", "p", ".", "reorgChan", ...
// ReorgHandler receives notification of a chain reorganization and initiates a // corresponding reorganization of the stakedb.StakeDatabase.
[ "ReorgHandler", "receives", "notification", "of", "a", "chain", "reorganization", "and", "initiates", "a", "corresponding", "reorganization", "of", "the", "stakedb", ".", "StakeDatabase", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/chainmonitor.go#L155-L200
141,628
decred/dcrdata
api/types/apicache.go
NewAPICache
func NewAPICache(capacity uint32) *APICache { apic := &APICache{ capacity: capacity, blockCache: make(blockCache), MainchainBlocks: make(map[int64]chainhash.Hash, capacity), expireQueue: NewBlockPriorityQueue(capacity), } go WatchPriorityQueue(apic.expireQueue) return apic }
go
func NewAPICache(capacity uint32) *APICache { apic := &APICache{ capacity: capacity, blockCache: make(blockCache), MainchainBlocks: make(map[int64]chainhash.Hash, capacity), expireQueue: NewBlockPriorityQueue(capacity), } go WatchPriorityQueue(apic.expireQueue) return apic }
[ "func", "NewAPICache", "(", "capacity", "uint32", ")", "*", "APICache", "{", "apic", ":=", "&", "APICache", "{", "capacity", ":", "capacity", ",", "blockCache", ":", "make", "(", "blockCache", ")", ",", "MainchainBlocks", ":", "make", "(", "map", "[", "i...
// NewAPICache creates an APICache with the specified capacity.
[ "NewAPICache", "creates", "an", "APICache", "with", "the", "specified", "capacity", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L66-L77
141,629
decred/dcrdata
api/types/apicache.go
Utilization
func (apic *APICache) Utilization() float64 { apic.mtx.RLock() defer apic.mtx.RUnlock() return 100.0 * float64(len(apic.blockCache)) / float64(apic.capacity) }
go
func (apic *APICache) Utilization() float64 { apic.mtx.RLock() defer apic.mtx.RUnlock() return 100.0 * float64(len(apic.blockCache)) / float64(apic.capacity) }
[ "func", "(", "apic", "*", "APICache", ")", "Utilization", "(", ")", "float64", "{", "apic", ".", "mtx", ".", "RLock", "(", ")", "\n", "defer", "apic", ".", "mtx", ".", "RUnlock", "(", ")", "\n", "return", "100.0", "*", "float64", "(", "len", "(", ...
// Utilization returns the percent utilization of the cache
[ "Utilization", "returns", "the", "percent", "utilization", "of", "the", "cache" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L103-L107
141,630
decred/dcrdata
api/types/apicache.go
StoreStakeInfo
func (apic *APICache) StoreStakeInfo(stakeInfo *StakeInfoExtended) error { if !apic.IsEnabled() { fmt.Printf("API cache is disabled") return nil } height := stakeInfo.Feeinfo.Height hash, err := chainhash.NewHashFromStr(stakeInfo.Hash) if err != nil { panic("that's not a real hash") } apic.mtx.Lock() de...
go
func (apic *APICache) StoreStakeInfo(stakeInfo *StakeInfoExtended) error { if !apic.IsEnabled() { fmt.Printf("API cache is disabled") return nil } height := stakeInfo.Feeinfo.Height hash, err := chainhash.NewHashFromStr(stakeInfo.Hash) if err != nil { panic("that's not a real hash") } apic.mtx.Lock() de...
[ "func", "(", "apic", "*", "APICache", ")", "StoreStakeInfo", "(", "stakeInfo", "*", "StakeInfoExtended", ")", "error", "{", "if", "!", "apic", ".", "IsEnabled", "(", ")", "{", "fmt", ".", "Printf", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "...
// StoreStakeInfo caches the input StakeInfoExtended, if the priority queue // indicates that the block should be added.
[ "StoreStakeInfo", "caches", "the", "input", "StakeInfoExtended", "if", "the", "priority", "queue", "indicates", "that", "the", "block", "should", "be", "added", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L176-L221
141,631
decred/dcrdata
api/types/apicache.go
removeCachedBlock
func (apic *APICache) removeCachedBlock(cachedBlock *CachedBlock) { if cachedBlock == nil { return } // remove the block from the expiration queue apic.expireQueue.RemoveBlock(cachedBlock) // remove from block cache if hash, err := chainhash.NewHashFromStr(cachedBlock.hash); err != nil { delete(apic.blockCach...
go
func (apic *APICache) removeCachedBlock(cachedBlock *CachedBlock) { if cachedBlock == nil { return } // remove the block from the expiration queue apic.expireQueue.RemoveBlock(cachedBlock) // remove from block cache if hash, err := chainhash.NewHashFromStr(cachedBlock.hash); err != nil { delete(apic.blockCach...
[ "func", "(", "apic", "*", "APICache", ")", "removeCachedBlock", "(", "cachedBlock", "*", "CachedBlock", ")", "{", "if", "cachedBlock", "==", "nil", "{", "return", "\n", "}", "\n", "// remove the block from the expiration queue", "apic", ".", "expireQueue", ".", ...
// removeCachedBlock is the non-thread-safe version of RemoveCachedBlock.
[ "removeCachedBlock", "is", "the", "non", "-", "thread", "-", "safe", "version", "of", "RemoveCachedBlock", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L224-L235
141,632
decred/dcrdata
api/types/apicache.go
RemoveCachedBlock
func (apic *APICache) RemoveCachedBlock(cachedBlock *CachedBlock) { apic.mtx.Lock() defer apic.mtx.Unlock() apic.removeCachedBlock(cachedBlock) }
go
func (apic *APICache) RemoveCachedBlock(cachedBlock *CachedBlock) { apic.mtx.Lock() defer apic.mtx.Unlock() apic.removeCachedBlock(cachedBlock) }
[ "func", "(", "apic", "*", "APICache", ")", "RemoveCachedBlock", "(", "cachedBlock", "*", "CachedBlock", ")", "{", "apic", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "apic", ".", "mtx", ".", "Unlock", "(", ")", "\n", "apic", ".", "removeCachedBlo...
// RemoveCachedBlock removes the input CachedBlock the cache. If the block is // not in cache, this is essentially a silent no-op.
[ "RemoveCachedBlock", "removes", "the", "input", "CachedBlock", "the", "cache", ".", "If", "the", "block", "is", "not", "in", "cache", "this", "is", "essentially", "a", "silent", "no", "-", "op", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L239-L243
141,633
decred/dcrdata
api/types/apicache.go
RemoveCachedBlockByHeight
func (apic *APICache) RemoveCachedBlockByHeight(height int64) { apic.mtx.Lock() defer apic.mtx.Unlock() hash, ok := apic.MainchainBlocks[height] if !ok { return } cb := apic.getCachedBlockByHash(hash) apic.removeCachedBlock(cb) }
go
func (apic *APICache) RemoveCachedBlockByHeight(height int64) { apic.mtx.Lock() defer apic.mtx.Unlock() hash, ok := apic.MainchainBlocks[height] if !ok { return } cb := apic.getCachedBlockByHash(hash) apic.removeCachedBlock(cb) }
[ "func", "(", "apic", "*", "APICache", ")", "RemoveCachedBlockByHeight", "(", "height", "int64", ")", "{", "apic", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "apic", ".", "mtx", ".", "Unlock", "(", ")", "\n\n", "hash", ",", "ok", ":=", "apic", ...
// RemoveCachedBlockByHeight attempts to remove a CachedBlock with the given // height.
[ "RemoveCachedBlockByHeight", "attempts", "to", "remove", "a", "CachedBlock", "with", "the", "given", "height", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L247-L258
141,634
decred/dcrdata
api/types/apicache.go
blockHash
func (apic *APICache) blockHash(height int64) (chainhash.Hash, bool) { apic.mtx.RLock() defer apic.mtx.RUnlock() hash, ok := apic.MainchainBlocks[height] return hash, ok }
go
func (apic *APICache) blockHash(height int64) (chainhash.Hash, bool) { apic.mtx.RLock() defer apic.mtx.RUnlock() hash, ok := apic.MainchainBlocks[height] return hash, ok }
[ "func", "(", "apic", "*", "APICache", ")", "blockHash", "(", "height", "int64", ")", "(", "chainhash", ".", "Hash", ",", "bool", ")", "{", "apic", ".", "mtx", ".", "RLock", "(", ")", "\n", "defer", "apic", ".", "mtx", ".", "RUnlock", "(", ")", "\...
// blockHash attempts to get the block hash for the main chain block at the // given height. The boolean indicates a cache miss.
[ "blockHash", "attempts", "to", "get", "the", "block", "hash", "for", "the", "main", "chain", "block", "at", "the", "given", "height", ".", "The", "boolean", "indicates", "a", "cache", "miss", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L262-L267
141,635
decred/dcrdata
api/types/apicache.go
GetBlockSize
func (apic *APICache) GetBlockSize(height int64) int32 { if !apic.IsEnabled() { return -1 } cachedBlock := apic.GetCachedBlockByHeight(height) if cachedBlock != nil && cachedBlock.summary != nil { return int32(cachedBlock.summary.Size) } return -1 }
go
func (apic *APICache) GetBlockSize(height int64) int32 { if !apic.IsEnabled() { return -1 } cachedBlock := apic.GetCachedBlockByHeight(height) if cachedBlock != nil && cachedBlock.summary != nil { return int32(cachedBlock.summary.Size) } return -1 }
[ "func", "(", "apic", "*", "APICache", ")", "GetBlockSize", "(", "height", "int64", ")", "int32", "{", "if", "!", "apic", ".", "IsEnabled", "(", ")", "{", "return", "-", "1", "\n", "}", "\n", "cachedBlock", ":=", "apic", ".", "GetCachedBlockByHeight", "...
// GetBlockSize attempts to retrieve the block size for the input height. The // return is -1 if no block with that height is cached.
[ "GetBlockSize", "attempts", "to", "retrieve", "the", "block", "size", "for", "the", "input", "height", ".", "The", "return", "is", "-", "1", "if", "no", "block", "with", "that", "height", "is", "cached", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L284-L293
141,636
decred/dcrdata
api/types/apicache.go
GetBlockSummary
func (apic *APICache) GetBlockSummary(height int64) *BlockDataBasic { if !apic.IsEnabled() { return nil } cachedBlock := apic.GetCachedBlockByHeight(height) if cachedBlock != nil { return cachedBlock.summary } return nil }
go
func (apic *APICache) GetBlockSummary(height int64) *BlockDataBasic { if !apic.IsEnabled() { return nil } cachedBlock := apic.GetCachedBlockByHeight(height) if cachedBlock != nil { return cachedBlock.summary } return nil }
[ "func", "(", "apic", "*", "APICache", ")", "GetBlockSummary", "(", "height", "int64", ")", "*", "BlockDataBasic", "{", "if", "!", "apic", ".", "IsEnabled", "(", ")", "{", "return", "nil", "\n", "}", "\n", "cachedBlock", ":=", "apic", ".", "GetCachedBlock...
// GetBlockSummary attempts to retrieve the block summary for the input height. // The return is nil if no block with that height is cached.
[ "GetBlockSummary", "attempts", "to", "retrieve", "the", "block", "summary", "for", "the", "input", "height", ".", "The", "return", "is", "nil", "if", "no", "block", "with", "that", "height", "is", "cached", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L297-L306
141,637
decred/dcrdata
api/types/apicache.go
GetStakeInfo
func (apic *APICache) GetStakeInfo(height int64) *StakeInfoExtended { if !apic.IsEnabled() { return nil } cachedBlock := apic.GetCachedBlockByHeight(height) if cachedBlock != nil { return cachedBlock.stakeInfo } return nil }
go
func (apic *APICache) GetStakeInfo(height int64) *StakeInfoExtended { if !apic.IsEnabled() { return nil } cachedBlock := apic.GetCachedBlockByHeight(height) if cachedBlock != nil { return cachedBlock.stakeInfo } return nil }
[ "func", "(", "apic", "*", "APICache", ")", "GetStakeInfo", "(", "height", "int64", ")", "*", "StakeInfoExtended", "{", "if", "!", "apic", ".", "IsEnabled", "(", ")", "{", "return", "nil", "\n", "}", "\n", "cachedBlock", ":=", "apic", ".", "GetCachedBlock...
// GetStakeInfo attempts to retrieve the stake info for block at the the input // height. The return is nil if no block with that height is cached.
[ "GetStakeInfo", "attempts", "to", "retrieve", "the", "stake", "info", "for", "block", "at", "the", "the", "input", "height", ".", "The", "return", "is", "nil", "if", "no", "block", "with", "that", "height", "is", "cached", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L310-L319
141,638
decred/dcrdata
api/types/apicache.go
GetStakeInfoByHash
func (apic *APICache) GetStakeInfoByHash(hash string) *StakeInfoExtended { if !apic.IsEnabled() { return nil } cachedBlock := apic.GetCachedBlockByHashStr(hash) if cachedBlock != nil { return cachedBlock.stakeInfo } return nil }
go
func (apic *APICache) GetStakeInfoByHash(hash string) *StakeInfoExtended { if !apic.IsEnabled() { return nil } cachedBlock := apic.GetCachedBlockByHashStr(hash) if cachedBlock != nil { return cachedBlock.stakeInfo } return nil }
[ "func", "(", "apic", "*", "APICache", ")", "GetStakeInfoByHash", "(", "hash", "string", ")", "*", "StakeInfoExtended", "{", "if", "!", "apic", ".", "IsEnabled", "(", ")", "{", "return", "nil", "\n", "}", "\n", "cachedBlock", ":=", "apic", ".", "GetCached...
// GetStakeInfoByHash attempts to retrieve the stake info for block with the // input hash. The return is nil if no block with that hash is cached.
[ "GetStakeInfoByHash", "attempts", "to", "retrieve", "the", "stake", "info", "for", "block", "with", "the", "input", "hash", ".", "The", "return", "is", "nil", "if", "no", "block", "with", "that", "hash", "is", "cached", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L323-L332
141,639
decred/dcrdata
api/types/apicache.go
GetCachedBlockByHeight
func (apic *APICache) GetCachedBlockByHeight(height int64) *CachedBlock { apic.mtx.Lock() defer apic.mtx.Unlock() hash, ok := apic.MainchainBlocks[height] if !ok { return nil } return apic.getCachedBlockByHash(hash) }
go
func (apic *APICache) GetCachedBlockByHeight(height int64) *CachedBlock { apic.mtx.Lock() defer apic.mtx.Unlock() hash, ok := apic.MainchainBlocks[height] if !ok { return nil } return apic.getCachedBlockByHash(hash) }
[ "func", "(", "apic", "*", "APICache", ")", "GetCachedBlockByHeight", "(", "height", "int64", ")", "*", "CachedBlock", "{", "apic", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "apic", ".", "mtx", ".", "Unlock", "(", ")", "\n", "hash", ",", "ok",...
// GetCachedBlockByHeight attempts to fetch a CachedBlock with the given height. // The return is nil if no block with that height is cached.
[ "GetCachedBlockByHeight", "attempts", "to", "fetch", "a", "CachedBlock", "with", "the", "given", "height", ".", "The", "return", "is", "nil", "if", "no", "block", "with", "that", "height", "is", "cached", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L336-L344
141,640
decred/dcrdata
api/types/apicache.go
GetBlockSummaryByHash
func (apic *APICache) GetBlockSummaryByHash(hash string) *BlockDataBasic { if !apic.IsEnabled() { return nil } cachedBlock := apic.GetCachedBlockByHashStr(hash) if cachedBlock != nil { return cachedBlock.summary } return nil }
go
func (apic *APICache) GetBlockSummaryByHash(hash string) *BlockDataBasic { if !apic.IsEnabled() { return nil } cachedBlock := apic.GetCachedBlockByHashStr(hash) if cachedBlock != nil { return cachedBlock.summary } return nil }
[ "func", "(", "apic", "*", "APICache", ")", "GetBlockSummaryByHash", "(", "hash", "string", ")", "*", "BlockDataBasic", "{", "if", "!", "apic", ".", "IsEnabled", "(", ")", "{", "return", "nil", "\n", "}", "\n", "cachedBlock", ":=", "apic", ".", "GetCached...
// GetBlockSummaryByHash attempts to retrieve the block summary for the given // block hash. The return is nil if no block with that hash is cached.
[ "GetBlockSummaryByHash", "attempts", "to", "retrieve", "the", "block", "summary", "for", "the", "given", "block", "hash", ".", "The", "return", "is", "nil", "if", "no", "block", "with", "that", "hash", "is", "cached", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L348-L357
141,641
decred/dcrdata
api/types/apicache.go
GetCachedBlockByHashStr
func (apic *APICache) GetCachedBlockByHashStr(hashStr string) *CachedBlock { // Validate the hash string, and get a *chainhash.Hash hash, err := chainhash.NewHashFromStr(hashStr) if err != nil { fmt.Printf("that's not a real hash!") return nil } apic.mtx.Lock() defer apic.mtx.Unlock() return apic.getCachedB...
go
func (apic *APICache) GetCachedBlockByHashStr(hashStr string) *CachedBlock { // Validate the hash string, and get a *chainhash.Hash hash, err := chainhash.NewHashFromStr(hashStr) if err != nil { fmt.Printf("that's not a real hash!") return nil } apic.mtx.Lock() defer apic.mtx.Unlock() return apic.getCachedB...
[ "func", "(", "apic", "*", "APICache", ")", "GetCachedBlockByHashStr", "(", "hashStr", "string", ")", "*", "CachedBlock", "{", "// Validate the hash string, and get a *chainhash.Hash", "hash", ",", "err", ":=", "chainhash", ".", "NewHashFromStr", "(", "hashStr", ")", ...
// GetCachedBlockByHashStr attempts to fetch a CachedBlock with the given hash. // The return is nil if no block with that hash is cached.
[ "GetCachedBlockByHashStr", "attempts", "to", "fetch", "a", "CachedBlock", "with", "the", "given", "hash", ".", "The", "return", "is", "nil", "if", "no", "block", "with", "that", "hash", "is", "cached", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L361-L372
141,642
decred/dcrdata
api/types/apicache.go
GetCachedBlockByHash
func (apic *APICache) GetCachedBlockByHash(hash chainhash.Hash) *CachedBlock { // validate the chainhash.Hash if _, err := chainhash.NewHashFromStr(hash.String()); err != nil { fmt.Printf("that's not a real hash!") return nil } apic.mtx.Lock() defer apic.mtx.Unlock() return apic.getCachedBlockByHash(hash) }
go
func (apic *APICache) GetCachedBlockByHash(hash chainhash.Hash) *CachedBlock { // validate the chainhash.Hash if _, err := chainhash.NewHashFromStr(hash.String()); err != nil { fmt.Printf("that's not a real hash!") return nil } apic.mtx.Lock() defer apic.mtx.Unlock() return apic.getCachedBlockByHash(hash) }
[ "func", "(", "apic", "*", "APICache", ")", "GetCachedBlockByHash", "(", "hash", "chainhash", ".", "Hash", ")", "*", "CachedBlock", "{", "// validate the chainhash.Hash", "if", "_", ",", "err", ":=", "chainhash", ".", "NewHashFromStr", "(", "hash", ".", "String...
// GetCachedBlockByHash attempts to fetch a CachedBlock with the given hash. The // return is nil if no block with that hash is cached.
[ "GetCachedBlockByHash", "attempts", "to", "fetch", "a", "CachedBlock", "with", "the", "given", "hash", ".", "The", "return", "is", "nil", "if", "no", "block", "with", "that", "hash", "is", "cached", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L376-L386
141,643
decred/dcrdata
api/types/apicache.go
getCachedBlockByHash
func (apic *APICache) getCachedBlockByHash(hash chainhash.Hash) *CachedBlock { cachedBlock, ok := apic.blockCache[hash] if ok { cachedBlock.Access() apic.expireQueue.setNeedsReheap(true) apic.expireQueue.setAccessTime(time.Now()) apic.hits++ return cachedBlock } apic.misses++ return nil }
go
func (apic *APICache) getCachedBlockByHash(hash chainhash.Hash) *CachedBlock { cachedBlock, ok := apic.blockCache[hash] if ok { cachedBlock.Access() apic.expireQueue.setNeedsReheap(true) apic.expireQueue.setAccessTime(time.Now()) apic.hits++ return cachedBlock } apic.misses++ return nil }
[ "func", "(", "apic", "*", "APICache", ")", "getCachedBlockByHash", "(", "hash", "chainhash", ".", "Hash", ")", "*", "CachedBlock", "{", "cachedBlock", ",", "ok", ":=", "apic", ".", "blockCache", "[", "hash", "]", "\n", "if", "ok", "{", "cachedBlock", "."...
// getCachedBlockByHash retrieves the block with the given hash, or nil if it is // not found. Successful retrieval will update the cached block's access time, // and increment the block's access count. This function is not thread-safe. See // GetCachedBlockByHash and GetCachedBlockByHashStr for thread safety and hash ...
[ "getCachedBlockByHash", "retrieves", "the", "block", "with", "the", "given", "hash", "or", "nil", "if", "it", "is", "not", "found", ".", "Successful", "retrieval", "will", "update", "the", "cached", "block", "s", "access", "time", "and", "increment", "the", ...
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L393-L404
141,644
decred/dcrdata
api/types/apicache.go
IsEnabled
func (apic *APICache) IsEnabled() bool { enabled, ok := apic.isEnabled.Load().(bool) return ok && enabled }
go
func (apic *APICache) IsEnabled() bool { enabled, ok := apic.isEnabled.Load().(bool) return ok && enabled }
[ "func", "(", "apic", "*", "APICache", ")", "IsEnabled", "(", ")", "bool", "{", "enabled", ",", "ok", ":=", "apic", ".", "isEnabled", ".", "Load", "(", ")", ".", "(", "bool", ")", "\n", "return", "ok", "&&", "enabled", "\n", "}" ]
// IsEnabled checks if the cache is enabled.
[ "IsEnabled", "checks", "if", "the", "cache", "is", "enabled", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L417-L420
141,645
decred/dcrdata
api/types/apicache.go
newCachedBlock
func newCachedBlock(summary *BlockDataBasic, stakeInfo *StakeInfoExtended) *CachedBlock { if summary == nil && stakeInfo == nil { return nil } height, hash, mismatch := checkBlockHeightHash(&cachedBlockData{ blockSummary: summary, stakeInfo: stakeInfo, }) if mismatch { return nil } return &CachedBlo...
go
func newCachedBlock(summary *BlockDataBasic, stakeInfo *StakeInfoExtended) *CachedBlock { if summary == nil && stakeInfo == nil { return nil } height, hash, mismatch := checkBlockHeightHash(&cachedBlockData{ blockSummary: summary, stakeInfo: stakeInfo, }) if mismatch { return nil } return &CachedBlo...
[ "func", "newCachedBlock", "(", "summary", "*", "BlockDataBasic", ",", "stakeInfo", "*", "StakeInfoExtended", ")", "*", "CachedBlock", "{", "if", "summary", "==", "nil", "&&", "stakeInfo", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "height", ",", ...
// newCachedBlock wraps the given BlockDataBasic in a CachedBlock with no // accesses and an invalid heap index. Use Access to set the access counter and // time. The priority queue will set the heapIdx.
[ "newCachedBlock", "wraps", "the", "given", "BlockDataBasic", "in", "a", "CachedBlock", "with", "no", "accesses", "and", "an", "invalid", "heap", "index", ".", "Use", "Access", "to", "set", "the", "access", "counter", "and", "time", ".", "The", "priority", "q...
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L430-L450
141,646
decred/dcrdata
api/types/apicache.go
Access
func (b *CachedBlock) Access() *BlockDataBasic { b.accesses++ b.accessTime = time.Now().UnixNano() return b.summary }
go
func (b *CachedBlock) Access() *BlockDataBasic { b.accesses++ b.accessTime = time.Now().UnixNano() return b.summary }
[ "func", "(", "b", "*", "CachedBlock", ")", "Access", "(", ")", "*", "BlockDataBasic", "{", "b", ".", "accesses", "++", "\n", "b", ".", "accessTime", "=", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", "\n", "return", "b", ".", "summary", ...
// Access increments the access count and sets the accessTime to now. The // BlockDataBasic stored in the CachedBlock is returned.
[ "Access", "increments", "the", "access", "count", "and", "sets", "the", "accessTime", "to", "now", ".", "The", "BlockDataBasic", "stored", "in", "the", "CachedBlock", "is", "returned", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L454-L458
141,647
decred/dcrdata
api/types/apicache.go
LessByAccessCountThenHeight
func LessByAccessCountThenHeight(bi, bj *CachedBlock) bool { if bi.accesses == bj.accesses { return LessByHeight(bi, bj) } return LessByAccessCount(bi, bj) }
go
func LessByAccessCountThenHeight(bi, bj *CachedBlock) bool { if bi.accesses == bj.accesses { return LessByHeight(bi, bj) } return LessByAccessCount(bi, bj) }
[ "func", "LessByAccessCountThenHeight", "(", "bi", ",", "bj", "*", "CachedBlock", ")", "bool", "{", "if", "bi", ".", "accesses", "==", "bj", ".", "accesses", "{", "return", "LessByHeight", "(", "bi", ",", "bj", ")", "\n", "}", "\n", "return", "LessByAcces...
// LessByAccessCountThenHeight compares access count with LessByAccessCount if // the blocks have different accessTime values, otherwise it compares height // with LessByHeight.
[ "LessByAccessCountThenHeight", "compares", "access", "count", "with", "LessByAccessCount", "if", "the", "blocks", "have", "different", "accessTime", "values", "otherwise", "it", "compares", "height", "with", "LessByHeight", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L550-L555
141,648
decred/dcrdata
api/types/apicache.go
MakeLessByAccessTimeThenCount
func MakeLessByAccessTimeThenCount(millisecondsBinned int64) func(bi, bj *CachedBlock) bool { millisecondThreshold := time.Duration(millisecondsBinned) * time.Millisecond return func(bi, bj *CachedBlock) bool { // higher priority is more recent (larger) access time epochDiff := (bi.accessTime - bj.accessTime) / i...
go
func MakeLessByAccessTimeThenCount(millisecondsBinned int64) func(bi, bj *CachedBlock) bool { millisecondThreshold := time.Duration(millisecondsBinned) * time.Millisecond return func(bi, bj *CachedBlock) bool { // higher priority is more recent (larger) access time epochDiff := (bi.accessTime - bj.accessTime) / i...
[ "func", "MakeLessByAccessTimeThenCount", "(", "millisecondsBinned", "int64", ")", "func", "(", "bi", ",", "bj", "*", "CachedBlock", ")", "bool", "{", "millisecondThreshold", ":=", "time", ".", "Duration", "(", "millisecondsBinned", ")", "*", "time", ".", "Millis...
// MakeLessByAccessTimeThenCount will create a CachedBlock comparison function // given the specified time resolution in milliseconds. Two access times less than // the given time apart are considered the same time, and access count is used // to break the tie.
[ "MakeLessByAccessTimeThenCount", "will", "create", "a", "CachedBlock", "comparison", "function", "given", "the", "specified", "time", "resolution", "in", "milliseconds", ".", "Two", "access", "times", "less", "than", "the", "given", "time", "apart", "are", "consider...
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L561-L572
141,649
decred/dcrdata
api/types/apicache.go
UpdateBlock
func (pq *BlockPriorityQueue) UpdateBlock(b *CachedBlock, summary *BlockDataBasic, stakeInfo *StakeInfoExtended) { if b != nil { heightAdded, hash, mismatch := checkBlockHeightHash(&cachedBlockData{ blockSummary: summary, stakeInfo: stakeInfo, }) if mismatch { fmt.Println("Cannot UpdateBlock!") re...
go
func (pq *BlockPriorityQueue) UpdateBlock(b *CachedBlock, summary *BlockDataBasic, stakeInfo *StakeInfoExtended) { if b != nil { heightAdded, hash, mismatch := checkBlockHeightHash(&cachedBlockData{ blockSummary: summary, stakeInfo: stakeInfo, }) if mismatch { fmt.Println("Cannot UpdateBlock!") re...
[ "func", "(", "pq", "*", "BlockPriorityQueue", ")", "UpdateBlock", "(", "b", "*", "CachedBlock", ",", "summary", "*", "BlockDataBasic", ",", "stakeInfo", "*", "StakeInfoExtended", ")", "{", "if", "b", "!=", "nil", "{", "heightAdded", ",", "hash", ",", "mism...
// UpdateBlock will update the specified CachedBlock, which must be in the // queue. This function is NOT thread-safe.
[ "UpdateBlock", "will", "update", "the", "specified", "CachedBlock", "which", "must", "be", "in", "the", "queue", ".", "This", "function", "is", "NOT", "thread", "-", "safe", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L723-L745
141,650
decred/dcrdata
api/types/apicache.go
RemoveBlock
func (pq *BlockPriorityQueue) RemoveBlock(b *CachedBlock) { pq.mtx.Lock() defer pq.mtx.Unlock() if b != nil && b.heapIdx > 0 && b.heapIdx < pq.Len() { // only remove the block it it is really in the queue if pq.bh[b.heapIdx].hash == b.hash { pq.RemoveIndex(b.heapIdx) return } fmt.Printf("Tried to remo...
go
func (pq *BlockPriorityQueue) RemoveBlock(b *CachedBlock) { pq.mtx.Lock() defer pq.mtx.Unlock() if b != nil && b.heapIdx > 0 && b.heapIdx < pq.Len() { // only remove the block it it is really in the queue if pq.bh[b.heapIdx].hash == b.hash { pq.RemoveIndex(b.heapIdx) return } fmt.Printf("Tried to remo...
[ "func", "(", "pq", "*", "BlockPriorityQueue", ")", "RemoveBlock", "(", "b", "*", "CachedBlock", ")", "{", "pq", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "pq", ".", "mtx", ".", "Unlock", "(", ")", "\n\n", "if", "b", "!=", "nil", "&&", "b"...
// RemoveBlock removes the specified CachedBlock from the queue. Remember to // remove it from the actual block cache!
[ "RemoveBlock", "removes", "the", "specified", "CachedBlock", "from", "the", "queue", ".", "Remember", "to", "remove", "it", "from", "the", "actual", "block", "cache!" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L812-L825
141,651
decred/dcrdata
api/types/apicache.go
RemoveIndex
func (pq *BlockPriorityQueue) RemoveIndex(idx int) { removedHeight := pq.bh[idx].height heap.Remove(pq, idx) pq.RescanMinMaxForRemove(removedHeight) }
go
func (pq *BlockPriorityQueue) RemoveIndex(idx int) { removedHeight := pq.bh[idx].height heap.Remove(pq, idx) pq.RescanMinMaxForRemove(removedHeight) }
[ "func", "(", "pq", "*", "BlockPriorityQueue", ")", "RemoveIndex", "(", "idx", "int", ")", "{", "removedHeight", ":=", "pq", ".", "bh", "[", "idx", "]", ".", "height", "\n", "heap", ".", "Remove", "(", "pq", ",", "idx", ")", "\n", "pq", ".", "Rescan...
// RemoveIndex removes the CachedBlock at the specified position in the heap. // This function is NOT thread-safe.
[ "RemoveIndex", "removes", "the", "CachedBlock", "at", "the", "specified", "position", "in", "the", "heap", ".", "This", "function", "is", "NOT", "thread", "-", "safe", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L829-L833
141,652
decred/dcrdata
mempool/collector.go
NewMempoolDataCollector
func NewMempoolDataCollector(dcrdChainSvr *rpcclient.Client, params *chaincfg.Params) *MempoolDataCollector { return &MempoolDataCollector{ dcrdChainSvr: dcrdChainSvr, activeChain: params, } }
go
func NewMempoolDataCollector(dcrdChainSvr *rpcclient.Client, params *chaincfg.Params) *MempoolDataCollector { return &MempoolDataCollector{ dcrdChainSvr: dcrdChainSvr, activeChain: params, } }
[ "func", "NewMempoolDataCollector", "(", "dcrdChainSvr", "*", "rpcclient", ".", "Client", ",", "params", "*", "chaincfg", ".", "Params", ")", "*", "MempoolDataCollector", "{", "return", "&", "MempoolDataCollector", "{", "dcrdChainSvr", ":", "dcrdChainSvr", ",", "ac...
// NewMempoolDataCollector creates a new MempoolDataCollector.
[ "NewMempoolDataCollector", "creates", "a", "new", "MempoolDataCollector", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/mempool/collector.go#L37-L42
141,653
decred/dcrdata
config.go
normalizeNetworkAddress
func normalizeNetworkAddress(a, defaultHost, defaultPort string) (string, error) { if strings.Contains(a, "://") { return a, fmt.Errorf("Address %s contains a protocol identifier, which is not allowed", a) } if a == "" { return defaultHost + ":" + defaultPort, nil } host, port, err := net.SplitHostPort(a) if ...
go
func normalizeNetworkAddress(a, defaultHost, defaultPort string) (string, error) { if strings.Contains(a, "://") { return a, fmt.Errorf("Address %s contains a protocol identifier, which is not allowed", a) } if a == "" { return defaultHost + ":" + defaultPort, nil } host, port, err := net.SplitHostPort(a) if ...
[ "func", "normalizeNetworkAddress", "(", "a", ",", "defaultHost", ",", "defaultPort", "string", ")", "(", "string", ",", "error", ")", "{", "if", "strings", ".", "Contains", "(", "a", ",", "\"", "\"", ")", "{", "return", "a", ",", "fmt", ".", "Errorf", ...
// normalizeNetworkAddress checks for a valid local network address format and // adds default host and port if not present. Invalidates addresses that include // a protocol identifier.
[ "normalizeNetworkAddress", "checks", "for", "a", "valid", "local", "network", "address", "format", "and", "adds", "default", "host", "and", "port", "if", "not", "present", ".", "Invalidates", "addresses", "that", "include", "a", "protocol", "identifier", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/config.go#L263-L289
141,654
decred/dcrdata
config.go
validLogLevel
func validLogLevel(logLevel string) bool { _, ok := slog.LevelFromString(logLevel) return ok }
go
func validLogLevel(logLevel string) bool { _, ok := slog.LevelFromString(logLevel) return ok }
[ "func", "validLogLevel", "(", "logLevel", "string", ")", "bool", "{", "_", ",", "ok", ":=", "slog", ".", "LevelFromString", "(", "logLevel", ")", "\n", "return", "ok", "\n", "}" ]
// validLogLevel returns whether or not logLevel is a valid debug log level.
[ "validLogLevel", "returns", "whether", "or", "not", "logLevel", "is", "a", "valid", "debug", "log", "level", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/config.go#L292-L295
141,655
decred/dcrdata
config.go
netName
func netName(chainParams *netparams.Params) string { // The following switch is to ensure this code is not built for testnet2, as // TestNet2 was removed entirely for dcrd 1.3.0. Compile check! switch chainParams.Net { case wire.TestNet3, wire.MainNet, wire.SimNet: default: log.Warnf("Unknown network: %s", chain...
go
func netName(chainParams *netparams.Params) string { // The following switch is to ensure this code is not built for testnet2, as // TestNet2 was removed entirely for dcrd 1.3.0. Compile check! switch chainParams.Net { case wire.TestNet3, wire.MainNet, wire.SimNet: default: log.Warnf("Unknown network: %s", chain...
[ "func", "netName", "(", "chainParams", "*", "netparams", ".", "Params", ")", "string", "{", "// The following switch is to ensure this code is not built for testnet2, as", "// TestNet2 was removed entirely for dcrd 1.3.0. Compile check!", "switch", "chainParams", ".", "Net", "{", ...
// netName returns the name used when referring to a decred network. TestNet3 // correctly returns "testnet3", but not TestNet2. This function may be removed // after testnet2 is ancient history.
[ "netName", "returns", "the", "name", "used", "when", "referring", "to", "a", "decred", "network", ".", "TestNet3", "correctly", "returns", "testnet3", "but", "not", "TestNet2", ".", "This", "function", "may", "be", "removed", "after", "testnet2", "is", "ancien...
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/config.go#L663-L672
141,656
decred/dcrdata
db/dbtypes/conversion.go
MsgBlockToDBBlock
func MsgBlockToDBBlock(msgBlock *wire.MsgBlock, chainParams *chaincfg.Params, chainWork string) *Block { // Create the dbtypes.Block structure blockHeader := msgBlock.Header // convert each transaction hash to a hex string txHashes := msgBlock.TxHashes() txHashStrs := make([]string, 0, len(txHashes)) for i := ra...
go
func MsgBlockToDBBlock(msgBlock *wire.MsgBlock, chainParams *chaincfg.Params, chainWork string) *Block { // Create the dbtypes.Block structure blockHeader := msgBlock.Header // convert each transaction hash to a hex string txHashes := msgBlock.TxHashes() txHashStrs := make([]string, 0, len(txHashes)) for i := ra...
[ "func", "MsgBlockToDBBlock", "(", "msgBlock", "*", "wire", ".", "MsgBlock", ",", "chainParams", "*", "chaincfg", ".", "Params", ",", "chainWork", "string", ")", "*", "Block", "{", "// Create the dbtypes.Block structure", "blockHeader", ":=", "msgBlock", ".", "Head...
// MsgBlockToDBBlock creates a dbtypes.Block from a wire.MsgBlock
[ "MsgBlockToDBBlock", "creates", "a", "dbtypes", ".", "Block", "from", "a", "wire", ".", "MsgBlock" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/conversion.go#L13-L56
141,657
decred/dcrdata
db/dbtypes/conversion.go
TimeBasedGroupingToInterval
func TimeBasedGroupingToInterval(grouping TimeBasedGrouping) (float64, error) { var hr = 3600.0 // days per month value is obtained by 365/12 var daysPerMonth = 30.416666666666668 switch grouping { case AllGrouping: return 1, nil case DayGrouping: return hr * 24, nil case WeekGrouping: return hr * 24 * 7...
go
func TimeBasedGroupingToInterval(grouping TimeBasedGrouping) (float64, error) { var hr = 3600.0 // days per month value is obtained by 365/12 var daysPerMonth = 30.416666666666668 switch grouping { case AllGrouping: return 1, nil case DayGrouping: return hr * 24, nil case WeekGrouping: return hr * 24 * 7...
[ "func", "TimeBasedGroupingToInterval", "(", "grouping", "TimeBasedGrouping", ")", "(", "float64", ",", "error", ")", "{", "var", "hr", "=", "3600.0", "\n", "// days per month value is obtained by 365/12", "var", "daysPerMonth", "=", "30.416666666666668", "\n", "switch",...
// TimeBasedGroupingToInterval converts the TimeBasedGrouping value to an actual // time value in seconds based on the gregorian calendar except AllGrouping that // returns 1 while the unknownGrouping returns -1 and an error.
[ "TimeBasedGroupingToInterval", "converts", "the", "TimeBasedGrouping", "value", "to", "an", "actual", "time", "value", "in", "seconds", "based", "on", "the", "gregorian", "calendar", "except", "AllGrouping", "that", "returns", "1", "while", "the", "unknownGrouping", ...
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/conversion.go#L61-L84
141,658
decred/dcrdata
db/dbtypes/conversion.go
CalculateWindowIndex
func CalculateWindowIndex(height, stakeDiffWindowSize int64) int64 { // A window being a group of blocks whose count is defined by // chainParams.StakeDiffWindowSize, the first window starts from block 1 to // block 144 instead of block 0 to block 143. To obtain the accurate window // index value, we should add 1 t...
go
func CalculateWindowIndex(height, stakeDiffWindowSize int64) int64 { // A window being a group of blocks whose count is defined by // chainParams.StakeDiffWindowSize, the first window starts from block 1 to // block 144 instead of block 0 to block 143. To obtain the accurate window // index value, we should add 1 t...
[ "func", "CalculateWindowIndex", "(", "height", ",", "stakeDiffWindowSize", "int64", ")", "int64", "{", "// A window being a group of blocks whose count is defined by", "// chainParams.StakeDiffWindowSize, the first window starts from block 1 to", "// block 144 instead of block 0 to block 143...
// CalculateWindowIndex calculates the window index from the quotient of a block // height and the chainParams.StakeDiffWindowSize.
[ "CalculateWindowIndex", "calculates", "the", "window", "index", "from", "the", "quotient", "of", "a", "block", "height", "and", "the", "chainParams", ".", "StakeDiffWindowSize", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/conversion.go#L95-L109
141,659
decred/dcrdata
api/insight/socket.io.go
NewSocketServer
func NewSocketServer(newTxChan chan *NewTx, params *chaincfg.Params) (*SocketServer, error) { server, err := socketio.NewServer(nil) if err != nil { apiLog.Errorf("Could not create socket.io server: %v", err) return nil, err } // Each address subscription uses its own room, which has the same name as // the a...
go
func NewSocketServer(newTxChan chan *NewTx, params *chaincfg.Params) (*SocketServer, error) { server, err := socketio.NewServer(nil) if err != nil { apiLog.Errorf("Could not create socket.io server: %v", err) return nil, err } // Each address subscription uses its own room, which has the same name as // the a...
[ "func", "NewSocketServer", "(", "newTxChan", "chan", "*", "NewTx", ",", "params", "*", "chaincfg", ".", "Params", ")", "(", "*", "SocketServer", ",", "error", ")", "{", "server", ",", "err", ":=", "socketio", ".", "NewServer", "(", "nil", ")", "\n", "i...
// NewSocketServer constructs a new SocketServer, registering handlers for the // "connection", "disconnection", and "subscribe" events.
[ "NewSocketServer", "constructs", "a", "new", "SocketServer", "registering", "handlers", "for", "the", "connection", "disconnection", "and", "subscribe", "events", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/insight/socket.io.go#L70-L138
141,660
decred/dcrdata
api/insight/socket.io.go
Store
func (soc *SocketServer) Store(blockData *blockdata.BlockData, msgBlock *wire.MsgBlock) error { apiLog.Debugf("Sending new websocket block %s", blockData.Header.Hash) soc.BroadcastTo("inv", "block", blockData.Header.Hash) // Since the coinbase transaction is generated by the miner, it will never // hit mempool. It...
go
func (soc *SocketServer) Store(blockData *blockdata.BlockData, msgBlock *wire.MsgBlock) error { apiLog.Debugf("Sending new websocket block %s", blockData.Header.Hash) soc.BroadcastTo("inv", "block", blockData.Header.Hash) // Since the coinbase transaction is generated by the miner, it will never // hit mempool. It...
[ "func", "(", "soc", "*", "SocketServer", ")", "Store", "(", "blockData", "*", "blockdata", ".", "BlockData", ",", "msgBlock", "*", "wire", ".", "MsgBlock", ")", "error", "{", "apiLog", ".", "Debugf", "(", "\"", "\"", ",", "blockData", ".", "Header", "....
// Store broadcasts the lastest block hash to the the inv room
[ "Store", "broadcasts", "the", "lastest", "block", "hash", "to", "the", "the", "inv", "room" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/insight/socket.io.go#L141-L175
141,661
decred/dcrdata
explorer/explorerroutes.go
netName
func netName(chainParams *chaincfg.Params) string { if chainParams == nil { return "invalid" } if strings.HasPrefix(strings.ToLower(chainParams.Name), "testnet") { return "Testnet" } return strings.Title(chainParams.Name) }
go
func netName(chainParams *chaincfg.Params) string { if chainParams == nil { return "invalid" } if strings.HasPrefix(strings.ToLower(chainParams.Name), "testnet") { return "Testnet" } return strings.Title(chainParams.Name) }
[ "func", "netName", "(", "chainParams", "*", "chaincfg", ".", "Params", ")", "string", "{", "if", "chainParams", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "strings", ".", "ToLower", "(", "chainParams"...
// netName returns the name used when referring to a decred network.
[ "netName", "returns", "the", "name", "used", "when", "referring", "to", "a", "decred", "network", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorerroutes.go#L109-L117
141,662
decred/dcrdata
explorer/explorerroutes.go
StatusPage
func (exp *explorerUI) StatusPage(w http.ResponseWriter, code, message, additionalInfo string, sType expStatus) { str, err := exp.templates.execTemplateToString("status", struct { *CommonPageData StatusType expStatus Code string Message string AdditionalInfo string }{ CommonPageData: ...
go
func (exp *explorerUI) StatusPage(w http.ResponseWriter, code, message, additionalInfo string, sType expStatus) { str, err := exp.templates.execTemplateToString("status", struct { *CommonPageData StatusType expStatus Code string Message string AdditionalInfo string }{ CommonPageData: ...
[ "func", "(", "exp", "*", "explorerUI", ")", "StatusPage", "(", "w", "http", ".", "ResponseWriter", ",", "code", ",", "message", ",", "additionalInfo", "string", ",", "sType", "expStatus", ")", "{", "str", ",", "err", ":=", "exp", ".", "templates", ".", ...
// StatusPage provides a page for displaying status messages and exception // handling without redirecting. Be sure to return after calling StatusPage if // this completes the processing of the calling http handler.
[ "StatusPage", "provides", "a", "page", "for", "displaying", "status", "messages", "and", "exception", "handling", "without", "redirecting", ".", "Be", "sure", "to", "return", "after", "calling", "StatusPage", "if", "this", "completes", "the", "processing", "of", ...
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorerroutes.go#L1541-L1583
141,663
decred/dcrdata
explorer/explorerroutes.go
NotFound
func (exp *explorerUI) NotFound(w http.ResponseWriter, r *http.Request) { exp.StatusPage(w, "Page not found.", "Cannot find page: "+r.URL.Path, "", ExpStatusNotFound) }
go
func (exp *explorerUI) NotFound(w http.ResponseWriter, r *http.Request) { exp.StatusPage(w, "Page not found.", "Cannot find page: "+r.URL.Path, "", ExpStatusNotFound) }
[ "func", "(", "exp", "*", "explorerUI", ")", "NotFound", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "exp", ".", "StatusPage", "(", "w", ",", "\"", "\"", ",", "\"", "\"", "+", "r", ".", "URL", ".", "...
// NotFound wraps StatusPage to display a 404 page.
[ "NotFound", "wraps", "StatusPage", "to", "display", "a", "404", "page", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorerroutes.go#L1586-L1588
141,664
decred/dcrdata
explorer/explorerroutes.go
HandleApiRequestsOnSync
func (exp *explorerUI) HandleApiRequestsOnSync(w http.ResponseWriter, r *http.Request) { var complete int dataFetched := SyncStatus() syncStatus := "in progress" if len(dataFetched) == complete { syncStatus = "complete" } for _, v := range dataFetched { if v.PercentComplete == 100 { complete++ } } st...
go
func (exp *explorerUI) HandleApiRequestsOnSync(w http.ResponseWriter, r *http.Request) { var complete int dataFetched := SyncStatus() syncStatus := "in progress" if len(dataFetched) == complete { syncStatus = "complete" } for _, v := range dataFetched { if v.PercentComplete == 100 { complete++ } } st...
[ "func", "(", "exp", "*", "explorerUI", ")", "HandleApiRequestsOnSync", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "var", "complete", "int", "\n", "dataFetched", ":=", "SyncStatus", "(", ")", "\n\n", "syncStatu...
// HandleApiRequestsOnSync handles all API request when the sync status pages is // running.
[ "HandleApiRequestsOnSync", "handles", "all", "API", "request", "when", "the", "sync", "status", "pages", "is", "running", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorerroutes.go#L1866-L1903
141,665
decred/dcrdata
explorer/explorerroutes.go
commonData
func (exp *explorerUI) commonData(r *http.Request) *CommonPageData { tip, err := exp.blockData.GetTip() if err != nil { log.Errorf("Failed to get the chain tip from the database.: %v", err) return nil } darkMode, err := r.Cookie(darkModeCoookie) if err != nil && err != http.ErrNoCookie { log.Errorf("Cookie d...
go
func (exp *explorerUI) commonData(r *http.Request) *CommonPageData { tip, err := exp.blockData.GetTip() if err != nil { log.Errorf("Failed to get the chain tip from the database.: %v", err) return nil } darkMode, err := r.Cookie(darkModeCoookie) if err != nil && err != http.ErrNoCookie { log.Errorf("Cookie d...
[ "func", "(", "exp", "*", "explorerUI", ")", "commonData", "(", "r", "*", "http", ".", "Request", ")", "*", "CommonPageData", "{", "tip", ",", "err", ":=", "exp", ".", "blockData", ".", "GetTip", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log",...
// commonData grabs the common page data that is available to every page. // This is particularly useful for extras.tmpl, parts of which // are used on every page
[ "commonData", "grabs", "the", "common", "page", "data", "that", "is", "available", "to", "every", "page", ".", "This", "is", "particularly", "useful", "for", "extras", ".", "tmpl", "parts", "of", "which", "are", "used", "on", "every", "page" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorerroutes.go#L2015-L2038
141,666
decred/dcrdata
explorer/explorermiddleware.go
SyncStatusPageIntercept
func (exp *explorerUI) SyncStatusPageIntercept(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if exp.ShowingSyncStatusPage() { exp.StatusPage(w, "Database Update Running. Please Wait.", "Blockchain sync is running. Please wait.", "", ExpStatusSyncing) ...
go
func (exp *explorerUI) SyncStatusPageIntercept(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if exp.ShowingSyncStatusPage() { exp.StatusPage(w, "Database Update Running. Please Wait.", "Blockchain sync is running. Please wait.", "", ExpStatusSyncing) ...
[ "func", "(", "exp", "*", "explorerUI", ")", "SyncStatusPageIntercept", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http...
// SyncStatusPageIntercept serves only the syncing status page until it is // deactivated when ShowingSyncStatusPage is set to false. This page is served // for all the possible routes supported until the background syncing is done.
[ "SyncStatusPageIntercept", "serves", "only", "the", "syncing", "status", "page", "until", "it", "is", "deactivated", "when", "ShowingSyncStatusPage", "is", "set", "to", "false", ".", "This", "page", "is", "served", "for", "all", "the", "possible", "routes", "sup...
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L88-L98
141,667
decred/dcrdata
explorer/explorermiddleware.go
SyncStatusAPIIntercept
func (exp *explorerUI) SyncStatusAPIIntercept(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if exp.ShowingSyncStatusPage() { exp.HandleApiRequestsOnSync(w, r) return } // Otherwise, proceed to the next http handler. next.ServeHTTP(w, r) }) }
go
func (exp *explorerUI) SyncStatusAPIIntercept(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if exp.ShowingSyncStatusPage() { exp.HandleApiRequestsOnSync(w, r) return } // Otherwise, proceed to the next http handler. next.ServeHTTP(w, r) }) }
[ "func", "(", "exp", "*", "explorerUI", ")", "SyncStatusAPIIntercept", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http"...
// SyncStatusAPIIntercept returns a json response back instead of a web page // when display sync status is active for the api endpoints supported.
[ "SyncStatusAPIIntercept", "returns", "a", "json", "response", "back", "instead", "of", "a", "web", "page", "when", "display", "sync", "status", "is", "active", "for", "the", "api", "endpoints", "supported", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L102-L111
141,668
decred/dcrdata
explorer/explorermiddleware.go
SyncStatusFileIntercept
func (exp *explorerUI) SyncStatusFileIntercept(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if exp.ShowingSyncStatusPage() { http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable) return } // Otherwise, procee...
go
func (exp *explorerUI) SyncStatusFileIntercept(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if exp.ShowingSyncStatusPage() { http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable) return } // Otherwise, procee...
[ "func", "(", "exp", "*", "explorerUI", ")", "SyncStatusFileIntercept", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http...
// SyncStatusFileIntercept triggers an HTTP error if a file is requested for // download before the DB is synced.
[ "SyncStatusFileIntercept", "triggers", "an", "HTTP", "error", "if", "a", "file", "is", "requested", "for", "download", "before", "the", "DB", "is", "synced", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L115-L124
141,669
decred/dcrdata
explorer/explorermiddleware.go
TransactionHashCtx
func TransactionHashCtx(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { txid := chi.URLParam(r, "txid") ctx := context.WithValue(r.Context(), ctxTxHash, txid) next.ServeHTTP(w, r.WithContext(ctx)) }) }
go
func TransactionHashCtx(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { txid := chi.URLParam(r, "txid") ctx := context.WithValue(r.Context(), ctxTxHash, txid) next.ServeHTTP(w, r.WithContext(ctx)) }) }
[ "func", "TransactionHashCtx", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "txid", ":...
// TransactionHashCtx embeds "txid" into the request context
[ "TransactionHashCtx", "embeds", "txid", "into", "the", "request", "context" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L164-L170
141,670
decred/dcrdata
explorer/explorermiddleware.go
TransactionIoIndexCtx
func TransactionIoIndexCtx(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { inout := chi.URLParam(r, "inout") inoutid := chi.URLParam(r, "inoutid") ctx := context.WithValue(r.Context(), ctxTxInOut, inout) ctx = context.WithValue(ctx, ctxTxInOutId, inoutid...
go
func TransactionIoIndexCtx(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { inout := chi.URLParam(r, "inout") inoutid := chi.URLParam(r, "inoutid") ctx := context.WithValue(r.Context(), ctxTxInOut, inout) ctx = context.WithValue(ctx, ctxTxInOutId, inoutid...
[ "func", "TransactionIoIndexCtx", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "inout", ...
// TransactionIoIndexCtx embeds "inout" and "inoutid" into the request context
[ "TransactionIoIndexCtx", "embeds", "inout", "and", "inoutid", "into", "the", "request", "context" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L173-L181
141,671
decred/dcrdata
explorer/explorermiddleware.go
ProposalPathCtx
func ProposalPathCtx(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { proposalRefID := chi.URLParam(r, "proposalrefid") ctx := context.WithValue(r.Context(), ctxProposalRefID, proposalRefID) next.ServeHTTP(w, r.WithContext(ctx)) }) }
go
func ProposalPathCtx(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { proposalRefID := chi.URLParam(r, "proposalrefid") ctx := context.WithValue(r.Context(), ctxProposalRefID, proposalRefID) next.ServeHTTP(w, r.WithContext(ctx)) }) }
[ "func", "ProposalPathCtx", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "proposalRefID"...
// ProposalPathCtx embeds "proposalrefID" into the request context
[ "ProposalPathCtx", "embeds", "proposalrefID", "into", "the", "request", "context" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L202-L208
141,672
decred/dcrdata
explorer/explorermiddleware.go
MenuFormParser
func MenuFormParser(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.FormValue(darkModeFormKey) != "" { cookie, err := r.Cookie(darkModeCoookie) if err != nil && err != http.ErrNoCookie { log.Errorf("Cookie dcrdataDarkBG retrieval error: %v", err...
go
func MenuFormParser(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.FormValue(darkModeFormKey) != "" { cookie, err := r.Cookie(darkModeCoookie) if err != nil && err != http.ErrNoCookie { log.Errorf("Cookie dcrdataDarkBG retrieval error: %v", err...
[ "func", "MenuFormParser", "(", "next", "http", ".", "Handler", ")", "http", ".", "Handler", "{", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "if", "r", "...
// MenuFormParser parses a form submission from the navigation menu.
[ "MenuFormParser", "parses", "a", "form", "submission", "from", "the", "navigation", "menu", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L211-L239
141,673
decred/dcrdata
notification/ntfnhandlers.go
RegisterNodeNtfnHandlers
func RegisterNodeNtfnHandlers(dcrdClient *rpcclient.Client) *ContextualError { // Set the node client for use by signalReorg to determine the common // ancestor of two chains. nodeClient = dcrdClient // Register for block connection and chain reorg notifications. var err error if err = dcrdClient.NotifyBlocks();...
go
func RegisterNodeNtfnHandlers(dcrdClient *rpcclient.Client) *ContextualError { // Set the node client for use by signalReorg to determine the common // ancestor of two chains. nodeClient = dcrdClient // Register for block connection and chain reorg notifications. var err error if err = dcrdClient.NotifyBlocks();...
[ "func", "RegisterNodeNtfnHandlers", "(", "dcrdClient", "*", "rpcclient", ".", "Client", ")", "*", "ContextualError", "{", "// Set the node client for use by signalReorg to determine the common", "// ancestor of two chains.", "nodeClient", "=", "dcrdClient", "\n\n", "// Register f...
// RegisterNodeNtfnHandlers registers with dcrd to receive new block, // transaction and winning ticket notifications.
[ "RegisterNodeNtfnHandlers", "registers", "with", "dcrd", "to", "receive", "new", "block", "transaction", "and", "winning", "ticket", "notifications", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/notification/ntfnhandlers.go#L27-L63
141,674
decred/dcrdata
notification/ntfnhandlers.go
SetSynchronousHandlers
func (q *collectionQueue) SetSynchronousHandlers(syncHandlers []func(hash *chainhash.Hash) error) { q.syncHandlers = syncHandlers }
go
func (q *collectionQueue) SetSynchronousHandlers(syncHandlers []func(hash *chainhash.Hash) error) { q.syncHandlers = syncHandlers }
[ "func", "(", "q", "*", "collectionQueue", ")", "SetSynchronousHandlers", "(", "syncHandlers", "[", "]", "func", "(", "hash", "*", "chainhash", ".", "Hash", ")", "error", ")", "{", "q", ".", "syncHandlers", "=", "syncHandlers", "\n", "}" ]
// SetSynchronousHandlers sets the slice of synchronous new block handler // functions, which are called in the order they occur in the slice.
[ "SetSynchronousHandlers", "sets", "the", "slice", "of", "synchronous", "new", "block", "handler", "functions", "which", "are", "called", "in", "the", "order", "they", "occur", "in", "the", "slice", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/notification/ntfnhandlers.go#L92-L94
141,675
decred/dcrdata
notification/ntfnhandlers.go
processBlock
func (q *collectionQueue) processBlock(bh *blockHashHeight) { hash := bh.hash height := bh.height // Ensure that the received block (bh.hash, bh.height) connects to the // previously connected block (q.prevHash, q.prevHeight). if bh.prevHash != q.prevHash { log.Infof("Received block at %d (%v) does not connect ...
go
func (q *collectionQueue) processBlock(bh *blockHashHeight) { hash := bh.hash height := bh.height // Ensure that the received block (bh.hash, bh.height) connects to the // previously connected block (q.prevHash, q.prevHeight). if bh.prevHash != q.prevHash { log.Infof("Received block at %d (%v) does not connect ...
[ "func", "(", "q", "*", "collectionQueue", ")", "processBlock", "(", "bh", "*", "blockHashHeight", ")", "{", "hash", ":=", "bh", ".", "hash", "\n", "height", ":=", "bh", ".", "height", "\n\n", "// Ensure that the received block (bh.hash, bh.height) connects to the", ...
// processBlock calls each synchronous new block handler with the given // blockHashHeight, and then signals to the monitors that a new block was mined.
[ "processBlock", "calls", "each", "synchronous", "new", "block", "handler", "with", "the", "given", "blockHashHeight", "and", "then", "signals", "to", "the", "monitors", "that", "a", "new", "block", "was", "mined", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/notification/ntfnhandlers.go#L119-L158
141,676
decred/dcrdata
notification/ntfnhandlers.go
signalReorg
func signalReorg(d ReorgData) { if nodeClient == nil { log.Errorf("The daemon RPC client for signalReorg is not configured!") return } // Determine the common ancestor of the two chains, and get the full // list of blocks in each chain back to but not including the common // ancestor. ancestor, newChain, old...
go
func signalReorg(d ReorgData) { if nodeClient == nil { log.Errorf("The daemon RPC client for signalReorg is not configured!") return } // Determine the common ancestor of the two chains, and get the full // list of blocks in each chain back to but not including the common // ancestor. ancestor, newChain, old...
[ "func", "signalReorg", "(", "d", "ReorgData", ")", "{", "if", "nodeClient", "==", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "// Determine the common ancestor of the two chains, and get the full", "// list of blocks in...
// signalReorg takes the basic reorganization data from dcrd, determines the two // chains and their common ancestor, and signals the reorg to each packages' // reorganization handler. Lastly, the collectionQueue's best block data is // updated so that it will successfully accept new blocks building on the new // chain...
[ "signalReorg", "takes", "the", "basic", "reorganization", "data", "from", "dcrd", "determines", "the", "two", "chains", "and", "their", "common", "ancestor", "and", "signals", "the", "reorg", "to", "each", "packages", "reorganization", "handler", ".", "Lastly", ...
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/notification/ntfnhandlers.go#L174-L247
141,677
decred/dcrdata
notification/ntfnhandlers.go
superQueue
func superQueue() { for e := range anyQueue { // Do not allow new blocks to process while running reorg. Only allow // them to be processed after this reorg completes. switch et := e.(type) { case *blockHashHeight: // Process the new block. log.Infof("superQueue: Processing new block %v (height %d).", et...
go
func superQueue() { for e := range anyQueue { // Do not allow new blocks to process while running reorg. Only allow // them to be processed after this reorg completes. switch et := e.(type) { case *blockHashHeight: // Process the new block. log.Infof("superQueue: Processing new block %v (height %d).", et...
[ "func", "superQueue", "(", ")", "{", "for", "e", ":=", "range", "anyQueue", "{", "// Do not allow new blocks to process while running reorg. Only allow", "// them to be processed after this reorg completes.", "switch", "et", ":=", "e", ".", "(", "type", ")", "{", "case", ...
// superQueue manages the event notification queue, keeping the events in the // same order they were received by the rpcclient.NotificationHandlers, and // sending them to the appropriate handlers. This should be run as a goroutine.
[ "superQueue", "manages", "the", "event", "notification", "queue", "keeping", "the", "events", "in", "the", "same", "order", "they", "were", "received", "by", "the", "rpcclient", ".", "NotificationHandlers", "and", "sending", "them", "to", "the", "appropriate", "...
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/notification/ntfnhandlers.go#L257-L276
141,678
decred/dcrdata
exchanges/exchanges.go
Tokens
func Tokens() []string { tokens := make([]string, 0, len(BtcIndices)+len(DcrExchanges)) var token string for token = range BtcIndices { tokens = append(tokens, token) } for token = range DcrExchanges { tokens = append(tokens, token) } return tokens }
go
func Tokens() []string { tokens := make([]string, 0, len(BtcIndices)+len(DcrExchanges)) var token string for token = range BtcIndices { tokens = append(tokens, token) } for token = range DcrExchanges { tokens = append(tokens, token) } return tokens }
[ "func", "Tokens", "(", ")", "[", "]", "string", "{", "tokens", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "BtcIndices", ")", "+", "len", "(", "DcrExchanges", ")", ")", "\n", "var", "token", "string", "\n", "for", "token", "...
// Tokens is a new slice of available exchange tokens.
[ "Tokens", "is", "a", "new", "slice", "of", "available", "exchange", "tokens", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L169-L179
141,679
decred/dcrdata
exchanges/exchanges.go
IsFresh
func (depth *DepthData) IsFresh() bool { return time.Duration(time.Now().Unix()-depth.Time)* time.Second < depthDataExpiration }
go
func (depth *DepthData) IsFresh() bool { return time.Duration(time.Now().Unix()-depth.Time)* time.Second < depthDataExpiration }
[ "func", "(", "depth", "*", "DepthData", ")", "IsFresh", "(", ")", "bool", "{", "return", "time", ".", "Duration", "(", "time", ".", "Now", "(", ")", ".", "Unix", "(", ")", "-", "depth", ".", "Time", ")", "*", "time", ".", "Second", "<", "depthDat...
// IsFresh will be true if the data is older than depthDataExpiration.
[ "IsFresh", "will", "be", "true", "if", "the", "data", "is", "older", "than", "depthDataExpiration", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L200-L203
141,680
decred/dcrdata
exchanges/exchanges.go
time
func (sticks Candlesticks) time() time.Time { if len(sticks) > 0 { return sticks[len(sticks)-1].Start } return time.Time{} }
go
func (sticks Candlesticks) time() time.Time { if len(sticks) > 0 { return sticks[len(sticks)-1].Start } return time.Time{} }
[ "func", "(", "sticks", "Candlesticks", ")", "time", "(", ")", "time", ".", "Time", "{", "if", "len", "(", "sticks", ")", ">", "0", "{", "return", "sticks", "[", "len", "(", "sticks", ")", "-", "1", "]", ".", "Start", "\n", "}", "\n", "return", ...
// returns the start time of the last Candlestick, else the zero time,
[ "returns", "the", "start", "time", "of", "the", "last", "Candlestick", "else", "the", "zero", "time" ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L219-L224
141,681
decred/dcrdata
exchanges/exchanges.go
needsUpdate
func (sticks Candlesticks) needsUpdate(bin candlestickKey) bool { if len(sticks) == 0 { return true } lastStick := sticks[len(sticks)-1] return time.Now().After(lastStick.Start.Add(bin.duration() * 2)) }
go
func (sticks Candlesticks) needsUpdate(bin candlestickKey) bool { if len(sticks) == 0 { return true } lastStick := sticks[len(sticks)-1] return time.Now().After(lastStick.Start.Add(bin.duration() * 2)) }
[ "func", "(", "sticks", "Candlesticks", ")", "needsUpdate", "(", "bin", "candlestickKey", ")", "bool", "{", "if", "len", "(", "sticks", ")", "==", "0", "{", "return", "true", "\n", "}", "\n", "lastStick", ":=", "sticks", "[", "len", "(", "sticks", ")", ...
// Checks whether the candlestick data for the given bin size is up-to-date.
[ "Checks", "whether", "the", "candlestick", "data", "for", "the", "given", "bin", "size", "is", "up", "-", "to", "-", "date", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L227-L233
141,682
decred/dcrdata
exchanges/exchanges.go
stealSticks
func (state *ExchangeState) stealSticks(top *ExchangeState) { if len(top.Candlesticks) == 0 { return } if state.Candlesticks == nil { state.Candlesticks = make(map[candlestickKey]Candlesticks) } for bin := range top.Candlesticks { _, have := state.Candlesticks[bin] if !have { state.Candlesticks[bin] = t...
go
func (state *ExchangeState) stealSticks(top *ExchangeState) { if len(top.Candlesticks) == 0 { return } if state.Candlesticks == nil { state.Candlesticks = make(map[candlestickKey]Candlesticks) } for bin := range top.Candlesticks { _, have := state.Candlesticks[bin] if !have { state.Candlesticks[bin] = t...
[ "func", "(", "state", "*", "ExchangeState", ")", "stealSticks", "(", "top", "*", "ExchangeState", ")", "{", "if", "len", "(", "top", ".", "Candlesticks", ")", "==", "0", "{", "return", "\n", "}", "\n", "if", "state", ".", "Candlesticks", "==", "nil", ...
// Grab any candlesticks from the top that are not in the receiver. Candlesticks // are historical data, so never need to be discarded.
[ "Grab", "any", "candlesticks", "from", "the", "top", "that", "are", "not", "in", "the", "receiver", ".", "Candlesticks", "are", "historical", "data", "so", "never", "need", "to", "be", "discarded", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L268-L281
141,683
decred/dcrdata
exchanges/exchanges.go
exchangeStateFromProto
func exchangeStateFromProto(proto *dcrrates.ExchangeRateUpdate) *ExchangeState { state := &ExchangeState{ Price: proto.GetPrice(), BaseVolume: proto.GetBaseVolume(), Volume: proto.GetVolume(), Change: proto.GetChange(), Stamp: proto.GetStamp(), } updateDepth := proto.GetDepth() if updat...
go
func exchangeStateFromProto(proto *dcrrates.ExchangeRateUpdate) *ExchangeState { state := &ExchangeState{ Price: proto.GetPrice(), BaseVolume: proto.GetBaseVolume(), Volume: proto.GetVolume(), Change: proto.GetChange(), Stamp: proto.GetStamp(), } updateDepth := proto.GetDepth() if updat...
[ "func", "exchangeStateFromProto", "(", "proto", "*", "dcrrates", ".", "ExchangeRateUpdate", ")", "*", "ExchangeState", "{", "state", ":=", "&", "ExchangeState", "{", "Price", ":", "proto", ".", "GetPrice", "(", ")", ",", "BaseVolume", ":", "proto", ".", "Get...
// Parse an ExchangeState from a protocol buffer message.
[ "Parse", "an", "ExchangeState", "from", "a", "protocol", "buffer", "message", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L284-L334
141,684
decred/dcrdata
exchanges/exchanges.go
StickList
func (state *ExchangeState) StickList() string { sticks := make([]string, 0, len(state.Candlesticks)) for bin := range state.Candlesticks { sticks = append(sticks, string(bin)) } return strings.Join(sticks, ";") }
go
func (state *ExchangeState) StickList() string { sticks := make([]string, 0, len(state.Candlesticks)) for bin := range state.Candlesticks { sticks = append(sticks, string(bin)) } return strings.Join(sticks, ";") }
[ "func", "(", "state", "*", "ExchangeState", ")", "StickList", "(", ")", "string", "{", "sticks", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "state", ".", "Candlesticks", ")", ")", "\n", "for", "bin", ":=", "range", "state", "...
// StickList is a semicolon-delimited list of available binSize.
[ "StickList", "is", "a", "semicolon", "-", "delimited", "list", "of", "available", "binSize", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L347-L353
141,685
decred/dcrdata
exchanges/exchanges.go
LastUpdate
func (xc *CommonExchange) LastUpdate() time.Time { xc.mtx.RLock() defer xc.mtx.RUnlock() return xc.lastUpdate }
go
func (xc *CommonExchange) LastUpdate() time.Time { xc.mtx.RLock() defer xc.mtx.RUnlock() return xc.lastUpdate }
[ "func", "(", "xc", "*", "CommonExchange", ")", "LastUpdate", "(", ")", "time", ".", "Time", "{", "xc", ".", "mtx", ".", "RLock", "(", ")", "\n", "defer", "xc", ".", "mtx", ".", "RUnlock", "(", ")", "\n", "return", "xc", ".", "lastUpdate", "\n", "...
// LastUpdate gets a time.Time of the last successful exchange update.
[ "LastUpdate", "gets", "a", "time", ".", "Time", "of", "the", "last", "successful", "exchange", "update", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L403-L407
141,686
decred/dcrdata
exchanges/exchanges.go
Hurry
func (xc *CommonExchange) Hurry(d time.Duration) { xc.mtx.Lock() defer xc.mtx.Unlock() xc.lastRequest = xc.lastRequest.Add(-d) }
go
func (xc *CommonExchange) Hurry(d time.Duration) { xc.mtx.Lock() defer xc.mtx.Unlock() xc.lastRequest = xc.lastRequest.Add(-d) }
[ "func", "(", "xc", "*", "CommonExchange", ")", "Hurry", "(", "d", "time", ".", "Duration", ")", "{", "xc", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "xc", ".", "mtx", ".", "Unlock", "(", ")", "\n", "xc", ".", "lastRequest", "=", "xc", "...
// Hurry can be used to subtract some amount of time from the lastUpate // and lastFail, and can be used to de-sync the exchange updates.
[ "Hurry", "can", "be", "used", "to", "subtract", "some", "amount", "of", "time", "from", "the", "lastUpate", "and", "lastFail", "and", "can", "be", "used", "to", "de", "-", "sync", "the", "exchange", "updates", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L411-L415
141,687
decred/dcrdata
exchanges/exchanges.go
LastFail
func (xc *CommonExchange) LastFail() time.Time { xc.mtx.RLock() defer xc.mtx.RUnlock() return xc.lastFail }
go
func (xc *CommonExchange) LastFail() time.Time { xc.mtx.RLock() defer xc.mtx.RUnlock() return xc.lastFail }
[ "func", "(", "xc", "*", "CommonExchange", ")", "LastFail", "(", ")", "time", ".", "Time", "{", "xc", ".", "mtx", ".", "RLock", "(", ")", "\n", "defer", "xc", ".", "mtx", ".", "RUnlock", "(", ")", "\n", "return", "xc", ".", "lastFail", "\n", "}" ]
// LastFail gets the last time.Time of a failed exchange update.
[ "LastFail", "gets", "the", "last", "time", ".", "Time", "of", "a", "failed", "exchange", "update", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L418-L422
141,688
decred/dcrdata
exchanges/exchanges.go
IsFailed
func (xc *CommonExchange) IsFailed() bool { xc.mtx.RLock() defer xc.mtx.RUnlock() return xc.lastFail.After(xc.lastUpdate) }
go
func (xc *CommonExchange) IsFailed() bool { xc.mtx.RLock() defer xc.mtx.RUnlock() return xc.lastFail.After(xc.lastUpdate) }
[ "func", "(", "xc", "*", "CommonExchange", ")", "IsFailed", "(", ")", "bool", "{", "xc", ".", "mtx", ".", "RLock", "(", ")", "\n", "defer", "xc", ".", "mtx", ".", "RUnlock", "(", ")", "\n", "return", "xc", ".", "lastFail", ".", "After", "(", "xc",...
// IsFailed will be true if xc.lastFail > xc.lastUpdate.
[ "IsFailed", "will", "be", "true", "if", "xc", ".", "lastFail", ">", "xc", ".", "lastUpdate", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L425-L429
141,689
decred/dcrdata
exchanges/exchanges.go
LogRequest
func (xc *CommonExchange) LogRequest() { xc.mtx.Lock() defer xc.mtx.Unlock() xc.lastRequest = time.Now() }
go
func (xc *CommonExchange) LogRequest() { xc.mtx.Lock() defer xc.mtx.Unlock() xc.lastRequest = time.Now() }
[ "func", "(", "xc", "*", "CommonExchange", ")", "LogRequest", "(", ")", "{", "xc", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "xc", ".", "mtx", ".", "Unlock", "(", ")", "\n", "xc", ".", "lastRequest", "=", "time", ".", "Now", "(", ")", "\...
// LogRequest sets the lastRequest time.Time.
[ "LogRequest", "sets", "the", "lastRequest", "time", ".", "Time", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L432-L436
141,690
decred/dcrdata
exchanges/exchanges.go
LastTry
func (xc *CommonExchange) LastTry() time.Time { xc.mtx.RLock() defer xc.mtx.RUnlock() return xc.lastRequest }
go
func (xc *CommonExchange) LastTry() time.Time { xc.mtx.RLock() defer xc.mtx.RUnlock() return xc.lastRequest }
[ "func", "(", "xc", "*", "CommonExchange", ")", "LastTry", "(", ")", "time", ".", "Time", "{", "xc", ".", "mtx", ".", "RLock", "(", ")", "\n", "defer", "xc", ".", "mtx", ".", "RUnlock", "(", ")", "\n", "return", "xc", ".", "lastRequest", "\n", "}"...
// LastTry is the more recent of lastFail and LastUpdate.
[ "LastTry", "is", "the", "more", "recent", "of", "lastFail", "and", "LastUpdate", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L439-L443
141,691
decred/dcrdata
exchanges/exchanges.go
setLastFail
func (xc *CommonExchange) setLastFail(t time.Time) { xc.mtx.Lock() defer xc.mtx.Unlock() xc.lastFail = t }
go
func (xc *CommonExchange) setLastFail(t time.Time) { xc.mtx.Lock() defer xc.mtx.Unlock() xc.lastFail = t }
[ "func", "(", "xc", "*", "CommonExchange", ")", "setLastFail", "(", "t", "time", ".", "Time", ")", "{", "xc", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "xc", ".", "mtx", ".", "Unlock", "(", ")", "\n", "xc", ".", "lastFail", "=", "t", "\n...
// setLastFail sets the last failure time.
[ "setLastFail", "sets", "the", "last", "failure", "time", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L451-L455
141,692
decred/dcrdata
exchanges/exchanges.go
fail
func (xc *CommonExchange) fail(msg string, err error) { log.Errorf("%s: %s: %v", xc.token, msg, err) xc.setLastFail(time.Now()) }
go
func (xc *CommonExchange) fail(msg string, err error) { log.Errorf("%s: %s: %v", xc.token, msg, err) xc.setLastFail(time.Now()) }
[ "func", "(", "xc", "*", "CommonExchange", ")", "fail", "(", "msg", "string", ",", "err", "error", ")", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "xc", ".", "token", ",", "msg", ",", "err", ")", "\n", "xc", ".", "setLastFail", "(", "time", ...
// Log the error along with the token and an additional passed identifier.
[ "Log", "the", "error", "along", "with", "the", "token", "and", "an", "additional", "passed", "identifier", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L458-L461
141,693
decred/dcrdata
exchanges/exchanges.go
UpdateIndices
func (xc *CommonExchange) UpdateIndices(indices FiatIndices) { xc.mtx.Lock() defer xc.mtx.Unlock() xc.lastUpdate = time.Now() xc.channels.index <- &IndexUpdate{ Token: xc.token, Indices: indices, } }
go
func (xc *CommonExchange) UpdateIndices(indices FiatIndices) { xc.mtx.Lock() defer xc.mtx.Unlock() xc.lastUpdate = time.Now() xc.channels.index <- &IndexUpdate{ Token: xc.token, Indices: indices, } }
[ "func", "(", "xc", "*", "CommonExchange", ")", "UpdateIndices", "(", "indices", "FiatIndices", ")", "{", "xc", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "xc", ".", "mtx", ".", "Unlock", "(", ")", "\n", "xc", ".", "lastUpdate", "=", "time", ...
// UpdateIndices sends a bitcoin index update to the ExchangeBot.
[ "UpdateIndices", "sends", "a", "bitcoin", "index", "update", "to", "the", "ExchangeBot", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L490-L498
141,694
decred/dcrdata
exchanges/exchanges.go
fetch
func (xc *CommonExchange) fetch(request *http.Request, response interface{}) (err error) { resp, err := xc.client.Do(request) if err != nil { return fmt.Errorf(fmt.Sprintf("Request failed: %v", err)) } defer resp.Body.Close() err = json.NewDecoder(resp.Body).Decode(response) if err != nil { return fmt.Errorf(...
go
func (xc *CommonExchange) fetch(request *http.Request, response interface{}) (err error) { resp, err := xc.client.Do(request) if err != nil { return fmt.Errorf(fmt.Sprintf("Request failed: %v", err)) } defer resp.Body.Close() err = json.NewDecoder(resp.Body).Decode(response) if err != nil { return fmt.Errorf(...
[ "func", "(", "xc", "*", "CommonExchange", ")", "fetch", "(", "request", "*", "http", ".", "Request", ",", "response", "interface", "{", "}", ")", "(", "err", "error", ")", "{", "resp", ",", "err", ":=", "xc", ".", "client", ".", "Do", "(", "request...
// Send the exchange request and decode the response.
[ "Send", "the", "exchange", "request", "and", "decode", "the", "response", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L501-L512
141,695
decred/dcrdata
exchanges/exchanges.go
state
func (xc *CommonExchange) state() *ExchangeState { xc.mtx.RLock() defer xc.mtx.RUnlock() return xc.currentState }
go
func (xc *CommonExchange) state() *ExchangeState { xc.mtx.RLock() defer xc.mtx.RUnlock() return xc.currentState }
[ "func", "(", "xc", "*", "CommonExchange", ")", "state", "(", ")", "*", "ExchangeState", "{", "xc", ".", "mtx", ".", "RLock", "(", ")", "\n", "defer", "xc", ".", "mtx", ".", "RUnlock", "(", ")", "\n", "return", "xc", ".", "currentState", "\n", "}" ]
// A thread-safe getter for the last known ExchangeState.
[ "A", "thread", "-", "safe", "getter", "for", "the", "last", "known", "ExchangeState", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L515-L519
141,696
decred/dcrdata
exchanges/exchanges.go
connectWebsocket
func (xc *CommonExchange) connectWebsocket(processor WebsocketProcessor, cfg *socketConfig) error { ws, err := newSocketConnection(cfg) if err != nil { return err } xc.wsMtx.Lock() if xc.ws != nil { select { case <-xc.ws.Done(): default: xc.ws.Close() } } xc.wsProcessor = processor xc.ws = ws xc....
go
func (xc *CommonExchange) connectWebsocket(processor WebsocketProcessor, cfg *socketConfig) error { ws, err := newSocketConnection(cfg) if err != nil { return err } xc.wsMtx.Lock() if xc.ws != nil { select { case <-xc.ws.Done(): default: xc.ws.Close() } } xc.wsProcessor = processor xc.ws = ws xc....
[ "func", "(", "xc", "*", "CommonExchange", ")", "connectWebsocket", "(", "processor", "WebsocketProcessor", ",", "cfg", "*", "socketConfig", ")", "error", "{", "ws", ",", "err", ":=", "newSocketConnection", "(", "cfg", ")", "\n", "if", "err", "!=", "nil", "...
// Creates a websocket connection and starts a listen loop. Closes any existing // connections for this exchange.
[ "Creates", "a", "websocket", "connection", "and", "starts", "a", "listen", "loop", ".", "Closes", "any", "existing", "connections", "for", "this", "exchange", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L534-L554
141,697
decred/dcrdata
exchanges/exchanges.go
startWebsocket
func (xc *CommonExchange) startWebsocket() { ws, processor := xc.websocket() go func() { for { message, err := ws.Read() if err != nil { xc.setWsFail(err) return } processor(message) } }() }
go
func (xc *CommonExchange) startWebsocket() { ws, processor := xc.websocket() go func() { for { message, err := ws.Read() if err != nil { xc.setWsFail(err) return } processor(message) } }() }
[ "func", "(", "xc", "*", "CommonExchange", ")", "startWebsocket", "(", ")", "{", "ws", ",", "processor", ":=", "xc", ".", "websocket", "(", ")", "\n", "go", "func", "(", ")", "{", "for", "{", "message", ",", "err", ":=", "ws", ".", "Read", "(", ")...
// The listen loop for a websocket connection.
[ "The", "listen", "loop", "for", "a", "websocket", "connection", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L557-L569
141,698
decred/dcrdata
exchanges/exchanges.go
wsListening
func (xc *CommonExchange) wsListening() bool { ws, _ := xc.websocket() if ws == nil { return false } select { case <-ws.Done(): return false default: return true } }
go
func (xc *CommonExchange) wsListening() bool { ws, _ := xc.websocket() if ws == nil { return false } select { case <-ws.Done(): return false default: return true } }
[ "func", "(", "xc", "*", "CommonExchange", ")", "wsListening", "(", ")", "bool", "{", "ws", ",", "_", ":=", "xc", ".", "websocket", "(", ")", "\n", "if", "ws", "==", "nil", "{", "return", "false", "\n", "}", "\n", "select", "{", "case", "<-", "ws"...
// Checks whether the websocketFeed Done channel is closed.
[ "Checks", "whether", "the", "websocketFeed", "Done", "channel", "is", "closed", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L577-L588
141,699
decred/dcrdata
exchanges/exchanges.go
setWsFail
func (xc *CommonExchange) setWsFail(err error) { xc.wsMtx.Lock() defer xc.wsMtx.Unlock() log.Errorf("%s websocket error: %v", xc.token, err) xc.wsSync.err = err xc.wsSync.errCount++ xc.wsSync.fail = time.Now() }
go
func (xc *CommonExchange) setWsFail(err error) { xc.wsMtx.Lock() defer xc.wsMtx.Unlock() log.Errorf("%s websocket error: %v", xc.token, err) xc.wsSync.err = err xc.wsSync.errCount++ xc.wsSync.fail = time.Now() }
[ "func", "(", "xc", "*", "CommonExchange", ")", "setWsFail", "(", "err", "error", ")", "{", "xc", ".", "wsMtx", ".", "Lock", "(", ")", "\n", "defer", "xc", ".", "wsMtx", ".", "Unlock", "(", ")", "\n", "log", ".", "Errorf", "(", "\"", "\"", ",", ...
// Log the error and time, and increment the error counter.
[ "Log", "the", "error", "and", "time", "and", "increment", "the", "error", "counter", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L591-L598