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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
142,100 | decred/dcrdata | exchanges/bot.go | Indices | func (bot *ExchangeBot) Indices(token string) FiatIndices {
bot.mtx.RLock()
defer bot.mtx.RUnlock()
indices := make(FiatIndices)
for code, price := range bot.indexMap[token] {
indices[code] = price
}
return indices
} | go | func (bot *ExchangeBot) Indices(token string) FiatIndices {
bot.mtx.RLock()
defer bot.mtx.RUnlock()
indices := make(FiatIndices)
for code, price := range bot.indexMap[token] {
indices[code] = price
}
return indices
} | [
"func",
"(",
"bot",
"*",
"ExchangeBot",
")",
"Indices",
"(",
"token",
"string",
")",
"FiatIndices",
"{",
"bot",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"bot",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"indices",
":=",
"make",
"(",
"Fia... | // Indices is the fiat indices for a given BTC index exchange. | [
"Indices",
"is",
"the",
"fiat",
"indices",
"for",
"a",
"given",
"BTC",
"index",
"exchange",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L625-L633 |
142,101 | decred/dcrdata | exchanges/bot.go | processState | func (bot *ExchangeBot) processState(states map[string]*ExchangeState, volumeAveraged bool) (float64, float64) {
var priceAccumulator, volSum float64
var deletions []string
oldestValid := time.Now().Add(-bot.RequestExpiry)
for token, state := range states {
if bot.Exchanges[token].LastUpdate().Before(oldestValid)... | go | func (bot *ExchangeBot) processState(states map[string]*ExchangeState, volumeAveraged bool) (float64, float64) {
var priceAccumulator, volSum float64
var deletions []string
oldestValid := time.Now().Add(-bot.RequestExpiry)
for token, state := range states {
if bot.Exchanges[token].LastUpdate().Before(oldestValid)... | [
"func",
"(",
"bot",
"*",
"ExchangeBot",
")",
"processState",
"(",
"states",
"map",
"[",
"string",
"]",
"*",
"ExchangeState",
",",
"volumeAveraged",
"bool",
")",
"(",
"float64",
",",
"float64",
")",
"{",
"var",
"priceAccumulator",
",",
"volSum",
"float64",
... | // processState is a helper function to process a slice of ExchangeState into
// a price, and optionally a volume sum, and perform some cleanup along the way.
// If volumeAveraged is false, all exchanges are given equal weight in the avg. | [
"processState",
"is",
"a",
"helper",
"function",
"to",
"process",
"a",
"slice",
"of",
"ExchangeState",
"into",
"a",
"price",
"and",
"optionally",
"a",
"volume",
"sum",
"and",
"perform",
"some",
"cleanup",
"along",
"the",
"way",
".",
"If",
"volumeAveraged",
"... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L655-L678 |
142,102 | decred/dcrdata | exchanges/bot.go | updateExchange | func (bot *ExchangeBot) updateExchange(update *ExchangeUpdate) error {
bot.mtx.Lock()
defer bot.mtx.Unlock()
if update.State.Candlesticks != nil {
for bin := range update.State.Candlesticks {
bot.incrementChart(genCacheID(update.Token, string(bin)))
}
}
if update.State.Depth != nil {
bot.incrementChart(ge... | go | func (bot *ExchangeBot) updateExchange(update *ExchangeUpdate) error {
bot.mtx.Lock()
defer bot.mtx.Unlock()
if update.State.Candlesticks != nil {
for bin := range update.State.Candlesticks {
bot.incrementChart(genCacheID(update.Token, string(bin)))
}
}
if update.State.Depth != nil {
bot.incrementChart(ge... | [
"func",
"(",
"bot",
"*",
"ExchangeBot",
")",
"updateExchange",
"(",
"update",
"*",
"ExchangeUpdate",
")",
"error",
"{",
"bot",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"bot",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"if",
"update",
".",
... | // updateExchange processes an update from a Decred-BTC Exchange. | [
"updateExchange",
"processes",
"an",
"update",
"from",
"a",
"Decred",
"-",
"BTC",
"Exchange",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L681-L694 |
142,103 | decred/dcrdata | exchanges/bot.go | updateIndices | func (bot *ExchangeBot) updateIndices(update *IndexUpdate) error {
bot.mtx.Lock()
defer bot.mtx.Unlock()
bot.indexMap[update.Token] = update.Indices
price, hasCode := update.Indices[bot.config.BtcIndex]
if hasCode {
bot.currentState.FiatIndices[update.Token] = &ExchangeState{
Price: price,
Stamp: time.Now(... | go | func (bot *ExchangeBot) updateIndices(update *IndexUpdate) error {
bot.mtx.Lock()
defer bot.mtx.Unlock()
bot.indexMap[update.Token] = update.Indices
price, hasCode := update.Indices[bot.config.BtcIndex]
if hasCode {
bot.currentState.FiatIndices[update.Token] = &ExchangeState{
Price: price,
Stamp: time.Now(... | [
"func",
"(",
"bot",
"*",
"ExchangeBot",
")",
"updateIndices",
"(",
"update",
"*",
"IndexUpdate",
")",
"error",
"{",
"bot",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"bot",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"bot",
".",
"indexMap",
"... | // updateIndices processes an update from an Bitcoin index source, essentially
// a map pairing currency codes to bitcoin prices. | [
"updateIndices",
"processes",
"an",
"update",
"from",
"an",
"Bitcoin",
"index",
"source",
"essentially",
"a",
"map",
"pairing",
"currency",
"codes",
"to",
"bitcoin",
"prices",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L698-L712 |
142,104 | decred/dcrdata | exchanges/bot.go | nextTick | func (bot *ExchangeBot) nextTick() *time.Timer {
tNow := time.Now()
tOldest := tNow
for _, xc := range bot.Exchanges {
t := xc.LastTry()
if t.Before(tOldest) {
tOldest = t
}
}
tSince := tNow.Sub(tOldest)
tilNext := bot.DataExpiry - tSince
if tilNext < bot.minTick {
tilNext = bot.minTick
}
return tim... | go | func (bot *ExchangeBot) nextTick() *time.Timer {
tNow := time.Now()
tOldest := tNow
for _, xc := range bot.Exchanges {
t := xc.LastTry()
if t.Before(tOldest) {
tOldest = t
}
}
tSince := tNow.Sub(tOldest)
tilNext := bot.DataExpiry - tSince
if tilNext < bot.minTick {
tilNext = bot.minTick
}
return tim... | [
"func",
"(",
"bot",
"*",
"ExchangeBot",
")",
"nextTick",
"(",
")",
"*",
"time",
".",
"Timer",
"{",
"tNow",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"tOldest",
":=",
"tNow",
"\n",
"for",
"_",
",",
"xc",
":=",
"range",
"bot",
".",
"Exchanges",
"{"... | // nextTick checks the exchanges' last update and fail times, and calculates
// when the next Cycle should run. | [
"nextTick",
"checks",
"the",
"exchanges",
"last",
"update",
"and",
"fail",
"times",
"and",
"calculates",
"when",
"the",
"next",
"Cycle",
"should",
"run",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L756-L771 |
142,105 | decred/dcrdata | exchanges/bot.go | Cycle | func (bot *ExchangeBot) Cycle() {
tNow := time.Now()
for _, xc := range bot.Exchanges {
if tNow.Sub(xc.LastTry()) > bot.DataExpiry {
go xc.Refresh()
}
}
} | go | func (bot *ExchangeBot) Cycle() {
tNow := time.Now()
for _, xc := range bot.Exchanges {
if tNow.Sub(xc.LastTry()) > bot.DataExpiry {
go xc.Refresh()
}
}
} | [
"func",
"(",
"bot",
"*",
"ExchangeBot",
")",
"Cycle",
"(",
")",
"{",
"tNow",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"for",
"_",
",",
"xc",
":=",
"range",
"bot",
".",
"Exchanges",
"{",
"if",
"tNow",
".",
"Sub",
"(",
"xc",
".",
"LastTry",
"(",... | // Cycle refreshes all expired exchanges. | [
"Cycle",
"refreshes",
"all",
"expired",
"exchanges",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L774-L781 |
142,106 | decred/dcrdata | exchanges/bot.go | TwoDecimals | func (c *Conversion) TwoDecimals() string {
if c.Value == 0.0 {
return "0.00"
} else if c.Value < 1.0 && c.Value > -1.0 {
return fmt.Sprintf("%3g", c.Value)
}
return fmt.Sprintf("%.2f", c.Value)
} | go | func (c *Conversion) TwoDecimals() string {
if c.Value == 0.0 {
return "0.00"
} else if c.Value < 1.0 && c.Value > -1.0 {
return fmt.Sprintf("%3g", c.Value)
}
return fmt.Sprintf("%.2f", c.Value)
} | [
"func",
"(",
"c",
"*",
"Conversion",
")",
"TwoDecimals",
"(",
")",
"string",
"{",
"if",
"c",
".",
"Value",
"==",
"0.0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"else",
"if",
"c",
".",
"Value",
"<",
"1.0",
"&&",
"c",
".",
"Value",
">",
"-",
"1.0",... | // TwoDecimals is a string representation of the value with two digits after
// the decimal point, but will show more to achieve at least three significant
// digits. | [
"TwoDecimals",
"is",
"a",
"string",
"representation",
"of",
"the",
"value",
"with",
"two",
"digits",
"after",
"the",
"decimal",
"point",
"but",
"will",
"show",
"more",
"to",
"achieve",
"at",
"least",
"three",
"significant",
"digits",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L799-L806 |
142,107 | decred/dcrdata | exchanges/bot.go | Conversion | func (bot *ExchangeBot) Conversion(dcrVal float64) *Conversion {
if bot == nil {
return nil
}
xcState := bot.State()
if xcState != nil {
return &Conversion{
Value: xcState.Price * dcrVal,
Index: xcState.BtcIndex,
}
}
return nil
} | go | func (bot *ExchangeBot) Conversion(dcrVal float64) *Conversion {
if bot == nil {
return nil
}
xcState := bot.State()
if xcState != nil {
return &Conversion{
Value: xcState.Price * dcrVal,
Index: xcState.BtcIndex,
}
}
return nil
} | [
"func",
"(",
"bot",
"*",
"ExchangeBot",
")",
"Conversion",
"(",
"dcrVal",
"float64",
")",
"*",
"Conversion",
"{",
"if",
"bot",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"xcState",
":=",
"bot",
".",
"State",
"(",
")",
"\n",
"if",
"xcState",
... | // Conversion attempts to multiply the supplied float with the default index.
// Nil pointer will be returned if there is no valid exchangeState. | [
"Conversion",
"attempts",
"to",
"multiply",
"the",
"supplied",
"float",
"with",
"the",
"default",
"index",
".",
"Nil",
"pointer",
"will",
"be",
"returned",
"if",
"there",
"is",
"no",
"valid",
"exchangeState",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L810-L822 |
142,108 | decred/dcrdata | exchanges/bot.go | QuickSticks | func (bot *ExchangeBot) QuickSticks(token string, rawBin string) ([]byte, error) {
chartID := genCacheID(token, rawBin)
bin := candlestickKey(rawBin)
data, bestVersion, isGood := bot.fetchFromCache(chartID)
if isGood {
return data, nil
}
// No hit on cache. Re-encode.
bot.mtx.Lock()
defer bot.mtx.Unlock()
... | go | func (bot *ExchangeBot) QuickSticks(token string, rawBin string) ([]byte, error) {
chartID := genCacheID(token, rawBin)
bin := candlestickKey(rawBin)
data, bestVersion, isGood := bot.fetchFromCache(chartID)
if isGood {
return data, nil
}
// No hit on cache. Re-encode.
bot.mtx.Lock()
defer bot.mtx.Unlock()
... | [
"func",
"(",
"bot",
"*",
"ExchangeBot",
")",
"QuickSticks",
"(",
"token",
"string",
",",
"rawBin",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"chartID",
":=",
"genCacheID",
"(",
"token",
",",
"rawBin",
")",
"\n",
"bin",
":=",
"cand... | // QuickSticks returns the up-to-date candlestick data for the specified
// exchange and bin width, pulling from the cache if appropriate. | [
"QuickSticks",
"returns",
"the",
"up",
"-",
"to",
"-",
"date",
"candlestick",
"data",
"for",
"the",
"specified",
"exchange",
"and",
"bin",
"width",
"pulling",
"from",
"the",
"cache",
"if",
"appropriate",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L841-L890 |
142,109 | decred/dcrdata | exchanges/bot.go | QuickDepth | func (bot *ExchangeBot) QuickDepth(token string) ([]byte, error) {
chartID := genCacheID(token, "depth")
data, bestVersion, isGood := bot.fetchFromCache(chartID)
if isGood {
return data, nil
}
// No hit on cache. Re-encode.
bot.mtx.Lock()
defer bot.mtx.Unlock()
state, found := bot.currentState.DcrBtc[token]... | go | func (bot *ExchangeBot) QuickDepth(token string) ([]byte, error) {
chartID := genCacheID(token, "depth")
data, bestVersion, isGood := bot.fetchFromCache(chartID)
if isGood {
return data, nil
}
// No hit on cache. Re-encode.
bot.mtx.Lock()
defer bot.mtx.Unlock()
state, found := bot.currentState.DcrBtc[token]... | [
"func",
"(",
"bot",
"*",
"ExchangeBot",
")",
"QuickDepth",
"(",
"token",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"chartID",
":=",
"genCacheID",
"(",
"token",
",",
"\"",
"\"",
")",
"\n",
"data",
",",
"bestVersion",
",",
"isGood",... | // QuickDepth returns the up-to-date depth chart data for the specified
// exchange, pulling from the cache if appropriate. | [
"QuickDepth",
"returns",
"the",
"up",
"-",
"to",
"-",
"date",
"depth",
"chart",
"data",
"for",
"the",
"specified",
"exchange",
"pulling",
"from",
"the",
"cache",
"if",
"appropriate",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L894-L931 |
142,110 | decred/dcrdata | middleware/apimiddleware.go | writeHTMLBadRequest | func writeHTMLBadRequest(w http.ResponseWriter, str string) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusBadRequest)
io.WriteString(w, str)
} | go | func writeHTMLBadRequest(w http.ResponseWriter, str string) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusBadRequest)
io.WriteString(w, str)
} | [
"func",
"writeHTMLBadRequest",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"str",
"string",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusBadReques... | // writeHTMLBadRequest is used for the Insight API error response for a BAD REQUEST.
// This means the request was malformed in some way or the request HASH,
// ADDRESS, BLOCK was not valid. | [
"writeHTMLBadRequest",
"is",
"used",
"for",
"the",
"Insight",
"API",
"error",
"response",
"for",
"a",
"BAD",
"REQUEST",
".",
"This",
"means",
"the",
"request",
"was",
"malformed",
"in",
"some",
"way",
"or",
"the",
"request",
"HASH",
"ADDRESS",
"BLOCK",
"was"... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L70-L74 |
142,111 | decred/dcrdata | middleware/apimiddleware.go | GetBlockStepCtx | func GetBlockStepCtx(r *http.Request) int {
step, ok := r.Context().Value(ctxBlockStep).(int)
if !ok {
apiLog.Error("block step is not set or is not an int")
return -1
}
return step
} | go | func GetBlockStepCtx(r *http.Request) int {
step, ok := r.Context().Value(ctxBlockStep).(int)
if !ok {
apiLog.Error("block step is not set or is not an int")
return -1
}
return step
} | [
"func",
"GetBlockStepCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"int",
"{",
"step",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxBlockStep",
")",
".",
"(",
"int",
")",
"\n",
"if",
"!",
"ok",
"{",
"apiLog",
".",
... | // GetBlockStepCtx retrieves the ctxBlockStep data from the request context. If
// not set, the return value is -1. | [
"GetBlockStepCtx",
"retrieves",
"the",
"ctxBlockStep",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"-",
"1",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L88-L95 |
142,112 | decred/dcrdata | middleware/apimiddleware.go | GetBlockIndex0Ctx | func GetBlockIndex0Ctx(r *http.Request) int {
idx, ok := r.Context().Value(ctxBlockIndex0).(int)
if !ok {
apiLog.Error("block index0 is not set or is not an int")
return -1
}
return idx
} | go | func GetBlockIndex0Ctx(r *http.Request) int {
idx, ok := r.Context().Value(ctxBlockIndex0).(int)
if !ok {
apiLog.Error("block index0 is not set or is not an int")
return -1
}
return idx
} | [
"func",
"GetBlockIndex0Ctx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"int",
"{",
"idx",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxBlockIndex0",
")",
".",
"(",
"int",
")",
"\n",
"if",
"!",
"ok",
"{",
"apiLog",
".",... | // GetBlockIndex0Ctx retrieves the ctxBlockIndex0 data from the request context.
// If not set, the return value is -1. | [
"GetBlockIndex0Ctx",
"retrieves",
"the",
"ctxBlockIndex0",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"-",
"1",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L99-L106 |
142,113 | decred/dcrdata | middleware/apimiddleware.go | GetTxIOIndexCtx | func GetTxIOIndexCtx(r *http.Request) int {
index, ok := r.Context().Value(ctxTxInOutIndex).(int)
if !ok {
apiLog.Warn("txinoutindex is not set or is not an int")
return -1
}
return index
} | go | func GetTxIOIndexCtx(r *http.Request) int {
index, ok := r.Context().Value(ctxTxInOutIndex).(int)
if !ok {
apiLog.Warn("txinoutindex is not set or is not an int")
return -1
}
return index
} | [
"func",
"GetTxIOIndexCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"int",
"{",
"index",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxTxInOutIndex",
")",
".",
"(",
"int",
")",
"\n",
"if",
"!",
"ok",
"{",
"apiLog",
"."... | // GetTxIOIndexCtx retrieves the ctxTxInOutIndex data from the request context.
// If not set, the return value is -1. | [
"GetTxIOIndexCtx",
"retrieves",
"the",
"ctxTxInOutIndex",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"-",
"1",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L110-L117 |
142,114 | decred/dcrdata | middleware/apimiddleware.go | GetNCtx | func GetNCtx(r *http.Request) int {
N, ok := r.Context().Value(ctxN).(int)
if !ok {
apiLog.Trace("N is not set or is not an int")
return -1
}
return N
} | go | func GetNCtx(r *http.Request) int {
N, ok := r.Context().Value(ctxN).(int)
if !ok {
apiLog.Trace("N is not set or is not an int")
return -1
}
return N
} | [
"func",
"GetNCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"int",
"{",
"N",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxN",
")",
".",
"(",
"int",
")",
"\n",
"if",
"!",
"ok",
"{",
"apiLog",
".",
"Trace",
"(",
"... | // GetNCtx retrieves the ctxN data from the request context. If not set, the
// return value is -1. | [
"GetNCtx",
"retrieves",
"the",
"ctxN",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"-",
"1",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L121-L128 |
142,115 | decred/dcrdata | middleware/apimiddleware.go | GetMCtx | func GetMCtx(r *http.Request) int {
M, ok := r.Context().Value(ctxM).(int)
if !ok {
apiLog.Trace("M is not set or is not an int")
return -1
}
return M
} | go | func GetMCtx(r *http.Request) int {
M, ok := r.Context().Value(ctxM).(int)
if !ok {
apiLog.Trace("M is not set or is not an int")
return -1
}
return M
} | [
"func",
"GetMCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"int",
"{",
"M",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxM",
")",
".",
"(",
"int",
")",
"\n",
"if",
"!",
"ok",
"{",
"apiLog",
".",
"Trace",
"(",
"... | // GetMCtx retrieves the ctxM data from the request context. If not set, the
// return value is -1. | [
"GetMCtx",
"retrieves",
"the",
"ctxM",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"-",
"1",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L132-L139 |
142,116 | decred/dcrdata | middleware/apimiddleware.go | GetTpCtx | func GetTpCtx(r *http.Request) string {
tp, ok := r.Context().Value(ctxTp).(string)
if !ok {
apiLog.Trace("ticket pool interval not set")
return ""
}
return tp
} | go | func GetTpCtx(r *http.Request) string {
tp, ok := r.Context().Value(ctxTp).(string)
if !ok {
apiLog.Trace("ticket pool interval not set")
return ""
}
return tp
} | [
"func",
"GetTpCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"tp",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxTp",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"apiLog",
".",
"Trace",
... | // GetTpCtx retrieves the ctxTp data from the request context.
// If the value is not set, an empty string is returned. | [
"GetTpCtx",
"retrieves",
"the",
"ctxTp",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"the",
"value",
"is",
"not",
"set",
"an",
"empty",
"string",
"is",
"returned",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L143-L150 |
142,117 | decred/dcrdata | middleware/apimiddleware.go | GetProposalTokenCtx | func GetProposalTokenCtx(r *http.Request) string {
tp, ok := r.Context().Value(ctxProposalToken).(string)
if !ok {
apiLog.Trace("proposal token hash not set")
return ""
}
return tp
} | go | func GetProposalTokenCtx(r *http.Request) string {
tp, ok := r.Context().Value(ctxProposalToken).(string)
if !ok {
apiLog.Trace("proposal token hash not set")
return ""
}
return tp
} | [
"func",
"GetProposalTokenCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"tp",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxProposalToken",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"apiLog... | // GetProposalTokenCtx retrieves the ctxProposalToken data from the request context.
// If the value is not set, an empty string is returned. | [
"GetProposalTokenCtx",
"retrieves",
"the",
"ctxProposalToken",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"the",
"value",
"is",
"not",
"set",
"an",
"empty",
"string",
"is",
"returned",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L154-L161 |
142,118 | decred/dcrdata | middleware/apimiddleware.go | GetRawHexTx | func GetRawHexTx(r *http.Request) (string, error) {
rawHexTx, ok := r.Context().Value(ctxRawHexTx).(string)
if !ok {
apiLog.Trace("hex transaction id not set")
return "", fmt.Errorf("hex transaction id not set")
}
msgtx := wire.NewMsgTx()
err := msgtx.Deserialize(hex.NewDecoder(strings.NewReader(rawHexTx)))
... | go | func GetRawHexTx(r *http.Request) (string, error) {
rawHexTx, ok := r.Context().Value(ctxRawHexTx).(string)
if !ok {
apiLog.Trace("hex transaction id not set")
return "", fmt.Errorf("hex transaction id not set")
}
msgtx := wire.NewMsgTx()
err := msgtx.Deserialize(hex.NewDecoder(strings.NewReader(rawHexTx)))
... | [
"func",
"GetRawHexTx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"string",
",",
"error",
")",
"{",
"rawHexTx",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxRawHexTx",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",... | // GetRawHexTx retrieves the ctxRawHexTx data from the request context. If not
// set, the return value is an empty string. | [
"GetRawHexTx",
"retrieves",
"the",
"ctxRawHexTx",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"an",
"empty",
"string",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L165-L178 |
142,119 | decred/dcrdata | middleware/apimiddleware.go | PostBroadcastTxCtx | func PostBroadcastTxCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var req apitypes.InsightRawTx
body, err := ioutil.ReadAll(r.Body)
r.Body.Close()
if err != nil {
writeHTMLBadRequest(w, fmt.Sprintf("Error reading JSON message: %v", err))
retu... | go | func PostBroadcastTxCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var req apitypes.InsightRawTx
body, err := ioutil.ReadAll(r.Body)
r.Body.Close()
if err != nil {
writeHTMLBadRequest(w, fmt.Sprintf("Error reading JSON message: %v", err))
retu... | [
"func",
"PostBroadcastTxCtx",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"var",
"re... | // PostBroadcastTxCtx is middleware that checks for parameters given in POST
// request body of the broadcast transaction endpoint. | [
"PostBroadcastTxCtx",
"is",
"middleware",
"that",
"checks",
"for",
"parameters",
"given",
"in",
"POST",
"request",
"body",
"of",
"the",
"broadcast",
"transaction",
"endpoint",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L182-L208 |
142,120 | decred/dcrdata | middleware/apimiddleware.go | GetTxIDCtx | func GetTxIDCtx(r *http.Request) (*chainhash.Hash, error) {
hashStr, ok := r.Context().Value(ctxTxHash).(string)
if !ok {
apiLog.Trace("txid not set")
return nil, fmt.Errorf("txid not set")
}
hash, err := chainhash.NewHashFromStr(hashStr)
if err != nil {
apiLog.Trace("invalid hash '%s': %v", hashStr, err)
... | go | func GetTxIDCtx(r *http.Request) (*chainhash.Hash, error) {
hashStr, ok := r.Context().Value(ctxTxHash).(string)
if !ok {
apiLog.Trace("txid not set")
return nil, fmt.Errorf("txid not set")
}
hash, err := chainhash.NewHashFromStr(hashStr)
if err != nil {
apiLog.Trace("invalid hash '%s': %v", hashStr, err)
... | [
"func",
"GetTxIDCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"hashStr",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxTxHash",
")",
".",
"(",
"string",
")",... | // GetTxIDCtx retrieves the ctxTxHash data from the request context. If not set,
// the return value is an empty string. | [
"GetTxIDCtx",
"retrieves",
"the",
"ctxTxHash",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"an",
"empty",
"string",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L212-L225 |
142,121 | decred/dcrdata | middleware/apimiddleware.go | GetTxnsCtx | func GetTxnsCtx(r *http.Request) ([]*chainhash.Hash, error) {
hashStrs, ok := r.Context().Value(ctxTxns).([]string)
if !ok || len(hashStrs) == 0 {
apiLog.Trace("ctxTxns not set")
return nil, fmt.Errorf("ctxTxns not set")
}
var hashes []*chainhash.Hash
for _, hashStr := range hashStrs {
hash, err := chainhas... | go | func GetTxnsCtx(r *http.Request) ([]*chainhash.Hash, error) {
hashStrs, ok := r.Context().Value(ctxTxns).([]string)
if !ok || len(hashStrs) == 0 {
apiLog.Trace("ctxTxns not set")
return nil, fmt.Errorf("ctxTxns not set")
}
var hashes []*chainhash.Hash
for _, hashStr := range hashStrs {
hash, err := chainhas... | [
"func",
"GetTxnsCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"[",
"]",
"*",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"hashStrs",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxTxns",
")",
".",
"(",
"["... | // GetTxnsCtx retrieves the ctxTxns data from the request context. If not set,
// the return value is an empty string slice. | [
"GetTxnsCtx",
"retrieves",
"the",
"ctxTxns",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"an",
"empty",
"string",
"slice",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L229-L247 |
142,122 | decred/dcrdata | middleware/apimiddleware.go | PostTxnsCtx | func PostTxnsCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
req := apitypes.Txns{}
body, err := ioutil.ReadAll(r.Body)
r.Body.Close()
if err != nil {
apiLog.Debugf("No/invalid txns: %v", err)
http.Error(w, "error reading JSON message", http.St... | go | func PostTxnsCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
req := apitypes.Txns{}
body, err := ioutil.ReadAll(r.Body)
r.Body.Close()
if err != nil {
apiLog.Debugf("No/invalid txns: %v", err)
http.Error(w, "error reading JSON message", http.St... | [
"func",
"PostTxnsCtx",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"req",
":=",
"a... | // PostTxnsCtx extract transaction IDs from the POST body | [
"PostTxnsCtx",
"extract",
"transaction",
"IDs",
"from",
"the",
"POST",
"body"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L257-L278 |
142,123 | decred/dcrdata | middleware/apimiddleware.go | ValidateTxnsPostCtx | func ValidateTxnsPostCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
contentLengthString := r.Header.Get("Content-Length")
contentLength, err := strconv.Atoi(contentLengthString)
if err != nil {
http.Error(w, "Unable to parse Content-Length", http.S... | go | func ValidateTxnsPostCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
contentLengthString := r.Header.Get("Content-Length")
contentLength, err := strconv.Atoi(contentLengthString)
if err != nil {
http.Error(w, "Unable to parse Content-Length", http.S... | [
"func",
"ValidateTxnsPostCtx",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"contentLen... | // ValidateTxnsPostCtx will confirm Post content length is valid. | [
"ValidateTxnsPostCtx",
"will",
"confirm",
"Post",
"content",
"length",
"is",
"valid",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L281-L297 |
142,124 | decred/dcrdata | middleware/apimiddleware.go | GetBlockHashCtx | func GetBlockHashCtx(r *http.Request) (string, error) {
hash, ok := r.Context().Value(ctxBlockHash).(string)
if !ok {
apiLog.Trace("block hash not set")
return "", fmt.Errorf("block hash not set")
}
if _, err := chainhash.NewHashFromStr(hash); err != nil {
apiLog.Trace("invalid hash '%s': %v", hash, err)
re... | go | func GetBlockHashCtx(r *http.Request) (string, error) {
hash, ok := r.Context().Value(ctxBlockHash).(string)
if !ok {
apiLog.Trace("block hash not set")
return "", fmt.Errorf("block hash not set")
}
if _, err := chainhash.NewHashFromStr(hash); err != nil {
apiLog.Trace("invalid hash '%s': %v", hash, err)
re... | [
"func",
"GetBlockHashCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"string",
",",
"error",
")",
"{",
"hash",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxBlockHash",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!"... | // GetBlockHashCtx retrieves the ctxBlockHash data from the request context. If
// not set, the return value is an empty string. | [
"GetBlockHashCtx",
"retrieves",
"the",
"ctxBlockHash",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"an",
"empty",
"string",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L301-L313 |
142,125 | decred/dcrdata | middleware/apimiddleware.go | GetAddressCtx | func GetAddressCtx(r *http.Request, activeNetParams *chaincfg.Params, maxAddrs int) ([]string, error) {
addressStr, ok := r.Context().Value(CtxAddress).(string)
if !ok || len(addressStr) == 0 {
apiLog.Trace("address not set")
return nil, fmt.Errorf("address not set")
}
addressStrs := strings.Split(addressStr, "... | go | func GetAddressCtx(r *http.Request, activeNetParams *chaincfg.Params, maxAddrs int) ([]string, error) {
addressStr, ok := r.Context().Value(CtxAddress).(string)
if !ok || len(addressStr) == 0 {
apiLog.Trace("address not set")
return nil, fmt.Errorf("address not set")
}
addressStrs := strings.Split(addressStr, "... | [
"func",
"GetAddressCtx",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"activeNetParams",
"*",
"chaincfg",
".",
"Params",
",",
"maxAddrs",
"int",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"addressStr",
",",
"ok",
":=",
"r",
".",
"Context",
... | // GetAddressCtx retrieves the CtxAddress data from the request context. If not
// set, the return value is an empty string. The CtxAddress string data may be a
// comma-separated list of addresses, subject to the provided maximum number of
// addresses allowed. Duplicate addresses are removed, but the limit is enforce... | [
"GetAddressCtx",
"retrieves",
"the",
"CtxAddress",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"an",
"empty",
"string",
".",
"The",
"CtxAddress",
"string",
"data",
"may",
"be",
"a",
"comma",
"-",
"s... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L320-L357 |
142,126 | decred/dcrdata | middleware/apimiddleware.go | GetChartTypeCtx | func GetChartTypeCtx(r *http.Request) string {
chartType, ok := r.Context().Value(ctxChartType).(string)
if !ok {
apiLog.Trace("chart type not set")
return ""
}
return chartType
} | go | func GetChartTypeCtx(r *http.Request) string {
chartType, ok := r.Context().Value(ctxChartType).(string)
if !ok {
apiLog.Trace("chart type not set")
return ""
}
return chartType
} | [
"func",
"GetChartTypeCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"chartType",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxChartType",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"apiLog"... | // GetChartTypeCtx retrieves the ctxChart data from the request context.
// If not set, the return value is an empty string. | [
"GetChartTypeCtx",
"retrieves",
"the",
"ctxChart",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"an",
"empty",
"string",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L361-L368 |
142,127 | decred/dcrdata | middleware/apimiddleware.go | GetChartGroupingCtx | func GetChartGroupingCtx(r *http.Request) string {
chartType, ok := r.Context().Value(ctxChartGrouping).(string)
if !ok {
apiLog.Trace("chart grouping not set")
return ""
}
return chartType
} | go | func GetChartGroupingCtx(r *http.Request) string {
chartType, ok := r.Context().Value(ctxChartGrouping).(string)
if !ok {
apiLog.Trace("chart grouping not set")
return ""
}
return chartType
} | [
"func",
"GetChartGroupingCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"chartType",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxChartGrouping",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
... | // GetChartGroupingCtx retrieves the ctxChart data from the request context.
// If not set, the return value is an empty string. | [
"GetChartGroupingCtx",
"retrieves",
"the",
"ctxChart",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"an",
"empty",
"string",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L372-L379 |
142,128 | decred/dcrdata | middleware/apimiddleware.go | GetBlockDateCtx | func GetBlockDateCtx(r *http.Request) string {
blockDate, _ := r.Context().Value(CtxBlockDate).(string)
return blockDate
} | go | func GetBlockDateCtx(r *http.Request) string {
blockDate, _ := r.Context().Value(CtxBlockDate).(string)
return blockDate
} | [
"func",
"GetBlockDateCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"blockDate",
",",
"_",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"CtxBlockDate",
")",
".",
"(",
"string",
")",
"\n",
"return",
"blockDate",
"\n",
"}"
... | // GetBlockDateCtx retrieves the ctxBlockDate data from the request context. If
// not set, the return value is an empty string. | [
"GetBlockDateCtx",
"retrieves",
"the",
"ctxBlockDate",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"an",
"empty",
"string",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L416-L419 |
142,129 | decred/dcrdata | middleware/apimiddleware.go | GetBlockIndexCtx | func GetBlockIndexCtx(r *http.Request) int {
idx, ok := r.Context().Value(ctxBlockIndex).(int)
if !ok {
apiLog.Warn("block index not set or is not an int")
return -1
}
return idx
} | go | func GetBlockIndexCtx(r *http.Request) int {
idx, ok := r.Context().Value(ctxBlockIndex).(int)
if !ok {
apiLog.Warn("block index not set or is not an int")
return -1
}
return idx
} | [
"func",
"GetBlockIndexCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"int",
"{",
"idx",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxBlockIndex",
")",
".",
"(",
"int",
")",
"\n",
"if",
"!",
"ok",
"{",
"apiLog",
".",
... | // GetBlockIndexCtx retrieves the ctxBlockIndex data from the request context.
// If not set, the return -1. | [
"GetBlockIndexCtx",
"retrieves",
"the",
"ctxBlockIndex",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"-",
"1",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L423-L430 |
142,130 | decred/dcrdata | middleware/apimiddleware.go | apiDocs | func apiDocs(mux *chi.Mux) func(next http.Handler) http.Handler {
var buf bytes.Buffer
json.Indent(&buf, []byte(docgen.JSONRoutesDoc(mux)), "", "\t")
docs := buf.String()
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValu... | go | func apiDocs(mux *chi.Mux) func(next http.Handler) http.Handler {
var buf bytes.Buffer
json.Indent(&buf, []byte(docgen.JSONRoutesDoc(mux)), "", "\t")
docs := buf.String()
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValu... | [
"func",
"apiDocs",
"(",
"mux",
"*",
"chi",
".",
"Mux",
")",
"func",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"json",
".",
"Indent",
"(",
"&",
"buf",
",",
"[",
"]",
"byte",
... | // apiDocs generates a middleware with a "docs" in the context containing a map
// of the routers handlers, etc. | [
"apiDocs",
"generates",
"a",
"middleware",
"with",
"a",
"docs",
"in",
"the",
"context",
"containing",
"a",
"map",
"of",
"the",
"routers",
"handlers",
"etc",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L632-L642 |
142,131 | decred/dcrdata | middleware/apimiddleware.go | GetAgendaIdCtx | func GetAgendaIdCtx(r *http.Request) string {
agendaId, ok := r.Context().Value(ctxAgendaId).(string)
if !ok {
apiLog.Error("agendaId not parsed")
return ""
}
return agendaId
} | go | func GetAgendaIdCtx(r *http.Request) string {
agendaId, ok := r.Context().Value(ctxAgendaId).(string)
if !ok {
apiLog.Error("agendaId not parsed")
return ""
}
return agendaId
} | [
"func",
"GetAgendaIdCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"agendaId",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxAgendaId",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"apiLog",
... | // GetAgendaIdCtx retrieves the ctxAgendaId data from the request context.
// If not set, the return value is an empty string. | [
"GetAgendaIdCtx",
"retrieves",
"the",
"ctxAgendaId",
"data",
"from",
"the",
"request",
"context",
".",
"If",
"not",
"set",
"the",
"return",
"value",
"is",
"an",
"empty",
"string",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L739-L746 |
142,132 | decred/dcrdata | middleware/apimiddleware.go | StatusInfoCtx | func StatusInfoCtx(r *http.Request, source DataSource) context.Context {
idx := int64(-1)
h, err := source.GetHeight()
if h >= 0 && err == nil {
idx = h
}
ctx := context.WithValue(r.Context(), ctxBlockIndex, int(idx)) // Must be int!
q := r.FormValue("q")
return context.WithValue(ctx, ctxGetStatus, q)
} | go | func StatusInfoCtx(r *http.Request, source DataSource) context.Context {
idx := int64(-1)
h, err := source.GetHeight()
if h >= 0 && err == nil {
idx = h
}
ctx := context.WithValue(r.Context(), ctxBlockIndex, int(idx)) // Must be int!
q := r.FormValue("q")
return context.WithValue(ctx, ctxGetStatus, q)
} | [
"func",
"StatusInfoCtx",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"source",
"DataSource",
")",
"context",
".",
"Context",
"{",
"idx",
":=",
"int64",
"(",
"-",
"1",
")",
"\n",
"h",
",",
"err",
":=",
"source",
".",
"GetHeight",
"(",
")",
"\n",
"if... | // StatusInfoCtx embeds the best block index and the POST form data for
// parameter "q" into a request context. | [
"StatusInfoCtx",
"embeds",
"the",
"best",
"block",
"index",
"and",
"the",
"POST",
"form",
"data",
"for",
"parameter",
"q",
"into",
"a",
"request",
"context",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L762-L772 |
142,133 | decred/dcrdata | middleware/apimiddleware.go | GetBlockHeightCtx | func GetBlockHeightCtx(r *http.Request, source DataSource) (int64, error) {
idxI, ok := r.Context().Value(ctxBlockIndex).(int)
idx := int64(idxI)
if !ok || idx < 0 {
hash, err := GetBlockHashCtx(r)
if err != nil {
return 0, err
}
idx, err = source.GetBlockHeight(hash)
if err != nil {
return 0, err
... | go | func GetBlockHeightCtx(r *http.Request, source DataSource) (int64, error) {
idxI, ok := r.Context().Value(ctxBlockIndex).(int)
idx := int64(idxI)
if !ok || idx < 0 {
hash, err := GetBlockHashCtx(r)
if err != nil {
return 0, err
}
idx, err = source.GetBlockHeight(hash)
if err != nil {
return 0, err
... | [
"func",
"GetBlockHeightCtx",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"source",
"DataSource",
")",
"(",
"int64",
",",
"error",
")",
"{",
"idxI",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxBlockIndex",
")",
".",
"(",
"... | // GetBlockHeightCtx returns the block height for the block index or hash
// specified on the URL path. | [
"GetBlockHeightCtx",
"returns",
"the",
"block",
"height",
"for",
"the",
"block",
"index",
"or",
"hash",
"specified",
"on",
"the",
"URL",
"path",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L818-L832 |
142,134 | decred/dcrdata | middleware/apimiddleware.go | RetrieveExchangeTokenCtx | func RetrieveExchangeTokenCtx(r *http.Request) string {
token, ok := r.Context().Value(ctxXcToken).(string)
if !ok {
apiLog.Error("non-string encountered in exchange token context")
return ""
}
return token
} | go | func RetrieveExchangeTokenCtx(r *http.Request) string {
token, ok := r.Context().Value(ctxXcToken).(string)
if !ok {
apiLog.Error("non-string encountered in exchange token context")
return ""
}
return token
} | [
"func",
"RetrieveExchangeTokenCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"token",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxXcToken",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"apiL... | // RetrieveExchangeTokenCtx tries to fetch the exchange token from the request
// context. | [
"RetrieveExchangeTokenCtx",
"tries",
"to",
"fetch",
"the",
"exchange",
"token",
"from",
"the",
"request",
"context",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L856-L863 |
142,135 | decred/dcrdata | middleware/apimiddleware.go | StickWidthContext | func StickWidthContext(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
bin := chi.URLParam(r, "bin")
ctx := context.WithValue(r.Context(), ctxStickWidth, bin)
next.ServeHTTP(w, r.WithContext(ctx))
})
} | go | func StickWidthContext(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
bin := chi.URLParam(r, "bin")
ctx := context.WithValue(r.Context(), ctxStickWidth, bin)
next.ServeHTTP(w, r.WithContext(ctx))
})
} | [
"func",
"StickWidthContext",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"bin",
":="... | // ExchangeTokenContext pulls the bin width from the URL. | [
"ExchangeTokenContext",
"pulls",
"the",
"bin",
"width",
"from",
"the",
"URL",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L866-L872 |
142,136 | decred/dcrdata | middleware/apimiddleware.go | RetrieveStickWidthCtx | func RetrieveStickWidthCtx(r *http.Request) string {
bin, ok := r.Context().Value(ctxStickWidth).(string)
if !ok {
apiLog.Error("non-string encountered in candlestick width context")
return ""
}
return bin
} | go | func RetrieveStickWidthCtx(r *http.Request) string {
bin, ok := r.Context().Value(ctxStickWidth).(string)
if !ok {
apiLog.Error("non-string encountered in candlestick width context")
return ""
}
return bin
} | [
"func",
"RetrieveStickWidthCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"bin",
",",
"ok",
":=",
"r",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxStickWidth",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"apiLog... | // RetrieveStickWidthCtx tries to fetch the candlestick width from the request
// context. | [
"RetrieveStickWidthCtx",
"tries",
"to",
"fetch",
"the",
"candlestick",
"width",
"from",
"the",
"request",
"context",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/middleware/apimiddleware.go#L876-L883 |
142,137 | decred/dcrdata | dcrrates/rateserver/tls.go | openRPCKeyPair | func openRPCKeyPair(cfg *config) (credentials.TransportCredentials, error) {
// Generate a new keypair when the key is missing.
_, e := os.Stat(cfg.KeyPath)
keyExists := !os.IsNotExist(e)
if !keyExists {
cert, err := generateRPCKeyPair(cfg.CertificatePath, cfg.KeyPath, cfg.AltDNSNames, certWriter{})
if err != n... | go | func openRPCKeyPair(cfg *config) (credentials.TransportCredentials, error) {
// Generate a new keypair when the key is missing.
_, e := os.Stat(cfg.KeyPath)
keyExists := !os.IsNotExist(e)
if !keyExists {
cert, err := generateRPCKeyPair(cfg.CertificatePath, cfg.KeyPath, cfg.AltDNSNames, certWriter{})
if err != n... | [
"func",
"openRPCKeyPair",
"(",
"cfg",
"*",
"config",
")",
"(",
"credentials",
".",
"TransportCredentials",
",",
"error",
")",
"{",
"// Generate a new keypair when the key is missing.",
"_",
",",
"e",
":=",
"os",
".",
"Stat",
"(",
"cfg",
".",
"KeyPath",
")",
"\... | // openRPCKeyPair creates or loads the RPC TLS keypair specified by the
// application config. | [
"openRPCKeyPair",
"creates",
"or",
"loads",
"the",
"RPC",
"TLS",
"keypair",
"specified",
"by",
"the",
"application",
"config",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/dcrrates/rateserver/tls.go#L23-L58 |
142,138 | decred/dcrdata | pubsub/psclient/client.go | Subscribe | func (c *Client) Subscribe(event string) (*pstypes.WebSocketMessage, error) {
// Validate the event type.
_, _, ok := pstypes.ValidateSubscription(event)
if !ok {
return nil, fmt.Errorf("invalid subscription %s", event)
}
// Send the subscribe message.
msg := newSubscribeMsg(event)
_ = c.SetWriteDeadline(time... | go | func (c *Client) Subscribe(event string) (*pstypes.WebSocketMessage, error) {
// Validate the event type.
_, _, ok := pstypes.ValidateSubscription(event)
if !ok {
return nil, fmt.Errorf("invalid subscription %s", event)
}
// Send the subscribe message.
msg := newSubscribeMsg(event)
_ = c.SetWriteDeadline(time... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Subscribe",
"(",
"event",
"string",
")",
"(",
"*",
"pstypes",
".",
"WebSocketMessage",
",",
"error",
")",
"{",
"// Validate the event type.",
"_",
",",
"_",
",",
"ok",
":=",
"pstypes",
".",
"ValidateSubscription",
"("... | // Subscribe sends a subscribe type WebSocketMessage for the given event name
// after validating it. The response is returned. | [
"Subscribe",
"sends",
"a",
"subscribe",
"type",
"WebSocketMessage",
"for",
"the",
"given",
"event",
"name",
"after",
"validating",
"it",
".",
"The",
"response",
"is",
"returned",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/pubsub/psclient/client.go#L52-L69 |
142,139 | decred/dcrdata | pubsub/psclient/client.go | ReceiveMsgTimeout | func (c *Client) ReceiveMsgTimeout(timeout time.Duration) (*pstypes.WebSocketMessage, error) {
_ = c.SetReadDeadline(time.Now().Add(timeout))
msg := new(pstypes.WebSocketMessage)
if err := websocket.JSON.Receive(c.Conn, &msg); err != nil {
return nil, err
}
return msg, nil
} | go | func (c *Client) ReceiveMsgTimeout(timeout time.Duration) (*pstypes.WebSocketMessage, error) {
_ = c.SetReadDeadline(time.Now().Add(timeout))
msg := new(pstypes.WebSocketMessage)
if err := websocket.JSON.Receive(c.Conn, &msg); err != nil {
return nil, err
}
return msg, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ReceiveMsgTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"*",
"pstypes",
".",
"WebSocketMessage",
",",
"error",
")",
"{",
"_",
"=",
"c",
".",
"SetReadDeadline",
"(",
"time",
".",
"Now",
"(",
")",
"... | // ReceiveMsgTimeout waits for the specified time Duration for a message,
// returned decoded into a WebSocketMessage. | [
"ReceiveMsgTimeout",
"waits",
"for",
"the",
"specified",
"time",
"Duration",
"for",
"a",
"message",
"returned",
"decoded",
"into",
"a",
"WebSocketMessage",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/pubsub/psclient/client.go#L94-L101 |
142,140 | decred/dcrdata | pubsub/psclient/client.go | ReceiveMsg | func (c *Client) ReceiveMsg() (*pstypes.WebSocketMessage, error) {
return c.ReceiveMsgTimeout(c.ReadTimeout)
} | go | func (c *Client) ReceiveMsg() (*pstypes.WebSocketMessage, error) {
return c.ReceiveMsgTimeout(c.ReadTimeout)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ReceiveMsg",
"(",
")",
"(",
"*",
"pstypes",
".",
"WebSocketMessage",
",",
"error",
")",
"{",
"return",
"c",
".",
"ReceiveMsgTimeout",
"(",
"c",
".",
"ReadTimeout",
")",
"\n",
"}"
] | // ReceiveMsg waits for a message, returned decoded into a WebSocketMessage. The
// Client's configured ReadTimeout is used. | [
"ReceiveMsg",
"waits",
"for",
"a",
"message",
"returned",
"decoded",
"into",
"a",
"WebSocketMessage",
".",
"The",
"Client",
"s",
"configured",
"ReadTimeout",
"is",
"used",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/pubsub/psclient/client.go#L105-L107 |
142,141 | decred/dcrdata | pubsub/psclient/client.go | ReceiveRaw | func (c *Client) ReceiveRaw() (message string, err error) {
_ = c.SetReadDeadline(time.Now().Add(c.ReadTimeout))
err = websocket.Message.Receive(c.Conn, &message)
return
} | go | func (c *Client) ReceiveRaw() (message string, err error) {
_ = c.SetReadDeadline(time.Now().Add(c.ReadTimeout))
err = websocket.Message.Receive(c.Conn, &message)
return
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"ReceiveRaw",
"(",
")",
"(",
"message",
"string",
",",
"err",
"error",
")",
"{",
"_",
"=",
"c",
".",
"SetReadDeadline",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"c",
".",
"ReadTimeout",
")",
")",
... | // ReceiveRaw for a message, returned undecoded as a string. | [
"ReceiveRaw",
"for",
"a",
"message",
"returned",
"undecoded",
"as",
"a",
"string",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/pubsub/psclient/client.go#L110-L114 |
142,142 | decred/dcrdata | pubsub/psclient/client.go | DecodeMsgString | func DecodeMsgString(msg *pstypes.WebSocketMessage) (string, error) {
s, err := DecodeMsg(msg)
if err != nil {
return "", err
}
str, ok := s.(string)
if !ok {
return "", fmt.Errorf("content of Message was not of type string")
}
return str, nil
} | go | func DecodeMsgString(msg *pstypes.WebSocketMessage) (string, error) {
s, err := DecodeMsg(msg)
if err != nil {
return "", err
}
str, ok := s.(string)
if !ok {
return "", fmt.Errorf("content of Message was not of type string")
}
return str, nil
} | [
"func",
"DecodeMsgString",
"(",
"msg",
"*",
"pstypes",
".",
"WebSocketMessage",
")",
"(",
"string",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"DecodeMsg",
"(",
"msg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
... | // DecodeMsgString attempts to decode the Message content of the given
// WebSocketMessage as a string. | [
"DecodeMsgString",
"attempts",
"to",
"decode",
"the",
"Message",
"content",
"of",
"the",
"given",
"WebSocketMessage",
"as",
"a",
"string",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/pubsub/psclient/client.go#L151-L161 |
142,143 | decred/dcrdata | rpcutils/prefetcher.go | Stop | func (p *BlockPrefetchClient) Stop() {
p.Lock()
close(p.retargetChan)
p.Unlock()
} | go | func (p *BlockPrefetchClient) Stop() {
p.Lock()
close(p.retargetChan)
p.Unlock()
} | [
"func",
"(",
"p",
"*",
"BlockPrefetchClient",
")",
"Stop",
"(",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"close",
"(",
"p",
".",
"retargetChan",
")",
"\n",
"p",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // Stop shuts down the fetcher goroutine. The BlockPrefetchClient may not be
// used after this. | [
"Stop",
"shuts",
"down",
"the",
"fetcher",
"goroutine",
".",
"The",
"BlockPrefetchClient",
"may",
"not",
"be",
"used",
"after",
"this",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/prefetcher.go#L77-L81 |
142,144 | decred/dcrdata | rpcutils/prefetcher.go | Hits | func (p *BlockPrefetchClient) Hits() uint64 {
p.Lock()
defer p.Unlock()
return p.hits
} | go | func (p *BlockPrefetchClient) Hits() uint64 {
p.Lock()
defer p.Unlock()
return p.hits
} | [
"func",
"(",
"p",
"*",
"BlockPrefetchClient",
")",
"Hits",
"(",
")",
"uint64",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"return",
"p",
".",
"hits",
"\n",
"}"
] | // Hits safely returns the number of prefetch hits. | [
"Hits",
"safely",
"returns",
"the",
"number",
"of",
"prefetch",
"hits",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/prefetcher.go#L84-L88 |
142,145 | decred/dcrdata | rpcutils/prefetcher.go | Misses | func (p *BlockPrefetchClient) Misses() uint64 {
p.Lock()
defer p.Unlock()
return p.misses
} | go | func (p *BlockPrefetchClient) Misses() uint64 {
p.Lock()
defer p.Unlock()
return p.misses
} | [
"func",
"(",
"p",
"*",
"BlockPrefetchClient",
")",
"Misses",
"(",
")",
"uint64",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"return",
"p",
".",
"misses",
"\n",
"}"
] | // Misses safely returns the number of prefetch misses. | [
"Misses",
"safely",
"returns",
"the",
"number",
"of",
"prefetch",
"misses",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/prefetcher.go#L91-L95 |
142,146 | decred/dcrdata | rpcutils/prefetcher.go | GetBestBlock | func (p *BlockPrefetchClient) GetBestBlock() (*chainhash.Hash, int64, error) {
return p.f.GetBestBlock()
} | go | func (p *BlockPrefetchClient) GetBestBlock() (*chainhash.Hash, int64, error) {
return p.f.GetBestBlock()
} | [
"func",
"(",
"p",
"*",
"BlockPrefetchClient",
")",
"GetBestBlock",
"(",
")",
"(",
"*",
"chainhash",
".",
"Hash",
",",
"int64",
",",
"error",
")",
"{",
"return",
"p",
".",
"f",
".",
"GetBestBlock",
"(",
")",
"\n",
"}"
] | // GetBestBlock is a passthrough to the client. It does not retarget the
// prefetch range since it does not request the actual block, just the hash and
// height of the best block. | [
"GetBestBlock",
"is",
"a",
"passthrough",
"to",
"the",
"client",
".",
"It",
"does",
"not",
"retarget",
"the",
"prefetch",
"range",
"since",
"it",
"does",
"not",
"request",
"the",
"actual",
"block",
"just",
"the",
"hash",
"and",
"height",
"of",
"the",
"best... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/prefetcher.go#L100-L102 |
142,147 | decred/dcrdata | rpcutils/prefetcher.go | GetBlockData | func (p *BlockPrefetchClient) GetBlockData(hash *chainhash.Hash) (*wire.MsgBlock, *dcrjson.GetBlockHeaderVerboseResult, error) {
p.Lock()
retargetAndUnlock := func(nextHash string) {
p.retarget(nextHash)
p.Unlock()
}
// If the block is already fetched, and the current block, return it. Do not
// retarget.
i... | go | func (p *BlockPrefetchClient) GetBlockData(hash *chainhash.Hash) (*wire.MsgBlock, *dcrjson.GetBlockHeaderVerboseResult, error) {
p.Lock()
retargetAndUnlock := func(nextHash string) {
p.retarget(nextHash)
p.Unlock()
}
// If the block is already fetched, and the current block, return it. Do not
// retarget.
i... | [
"func",
"(",
"p",
"*",
"BlockPrefetchClient",
")",
"GetBlockData",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"wire",
".",
"MsgBlock",
",",
"*",
"dcrjson",
".",
"GetBlockHeaderVerboseResult",
",",
"error",
")",
"{",
"p",
".",
"Lock",
"(",... | // GetBlockData attempts to get the specified block and retargets the prefetcher
// with the next block's hash. If the block was not already fetched, it is
// retrieved immediately and stored following retargeting. | [
"GetBlockData",
"attempts",
"to",
"get",
"the",
"specified",
"block",
"and",
"retargets",
"the",
"prefetcher",
"with",
"the",
"next",
"block",
"s",
"hash",
".",
"If",
"the",
"block",
"was",
"not",
"already",
"fetched",
"it",
"is",
"retrieved",
"immediately",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/prefetcher.go#L107-L152 |
142,148 | decred/dcrdata | rpcutils/prefetcher.go | GetBlock | func (p *BlockPrefetchClient) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error) {
msgBlock, _, err := p.GetBlockData(hash)
return msgBlock, err
} | go | func (p *BlockPrefetchClient) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error) {
msgBlock, _, err := p.GetBlockData(hash)
return msgBlock, err
} | [
"func",
"(",
"p",
"*",
"BlockPrefetchClient",
")",
"GetBlock",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"wire",
".",
"MsgBlock",
",",
"error",
")",
"{",
"msgBlock",
",",
"_",
",",
"err",
":=",
"p",
".",
"GetBlockData",
"(",
"hash",
... | // GetBlock retrieves the wire.MsgBlock for the block with the specified hash.
// See GetBlockData for details on how this interacts with the prefetcher. | [
"GetBlock",
"retrieves",
"the",
"wire",
".",
"MsgBlock",
"for",
"the",
"block",
"with",
"the",
"specified",
"hash",
".",
"See",
"GetBlockData",
"for",
"details",
"on",
"how",
"this",
"interacts",
"with",
"the",
"prefetcher",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/prefetcher.go#L156-L159 |
142,149 | decred/dcrdata | rpcutils/prefetcher.go | GetBlockHeaderVerbose | func (p *BlockPrefetchClient) GetBlockHeaderVerbose(hash *chainhash.Hash) (*dcrjson.GetBlockHeaderVerboseResult, error) {
_, headerResult, err := p.GetBlockData(hash)
return headerResult, err
} | go | func (p *BlockPrefetchClient) GetBlockHeaderVerbose(hash *chainhash.Hash) (*dcrjson.GetBlockHeaderVerboseResult, error) {
_, headerResult, err := p.GetBlockData(hash)
return headerResult, err
} | [
"func",
"(",
"p",
"*",
"BlockPrefetchClient",
")",
"GetBlockHeaderVerbose",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"dcrjson",
".",
"GetBlockHeaderVerboseResult",
",",
"error",
")",
"{",
"_",
",",
"headerResult",
",",
"err",
":=",
"p",
"... | // GetBlockHeaderVerbose retrieves the dcrjson.GetBlockHeaderVerboseResult for
// the block with the specified hash. See GetBlockData for details on how this
// interacts with the prefetcher | [
"GetBlockHeaderVerbose",
"retrieves",
"the",
"dcrjson",
".",
"GetBlockHeaderVerboseResult",
"for",
"the",
"block",
"with",
"the",
"specified",
"hash",
".",
"See",
"GetBlockData",
"for",
"details",
"on",
"how",
"this",
"interacts",
"with",
"the",
"prefetcher"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/prefetcher.go#L164-L167 |
142,150 | decred/dcrdata | rpcutils/prefetcher.go | storeNext | func (p *BlockPrefetchClient) storeNext(msgBlock *wire.MsgBlock, headerResult *dcrjson.GetBlockHeaderVerboseResult) {
p.current = p.next
p.next = &blockData{
height: msgBlock.Header.Height,
hash: msgBlock.BlockHash(),
msgBlock: msgBlock,
headerResult: headerResult,
}
} | go | func (p *BlockPrefetchClient) storeNext(msgBlock *wire.MsgBlock, headerResult *dcrjson.GetBlockHeaderVerboseResult) {
p.current = p.next
p.next = &blockData{
height: msgBlock.Header.Height,
hash: msgBlock.BlockHash(),
msgBlock: msgBlock,
headerResult: headerResult,
}
} | [
"func",
"(",
"p",
"*",
"BlockPrefetchClient",
")",
"storeNext",
"(",
"msgBlock",
"*",
"wire",
".",
"MsgBlock",
",",
"headerResult",
"*",
"dcrjson",
".",
"GetBlockHeaderVerboseResult",
")",
"{",
"p",
".",
"current",
"=",
"p",
".",
"next",
"\n",
"p",
".",
... | // storeNext stores the input data as the new "next" block. The existing "next"
// becomes "current". | [
"storeNext",
"stores",
"the",
"input",
"data",
"as",
"the",
"new",
"next",
"block",
".",
"The",
"existing",
"next",
"becomes",
"current",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/prefetcher.go#L192-L200 |
142,151 | decred/dcrdata | rpcutils/prefetcher.go | RetrieveAndStoreNext | func (p *BlockPrefetchClient) RetrieveAndStoreNext(nextHash *chainhash.Hash) {
p.Lock()
defer p.Unlock()
// Fetch the next block, if needed.
if p.haveBlockHash(*nextHash) {
return
}
msgBlock, headerResult, _, err := p.retrieveBlockAndHeaderResult(nextHash)
if err != nil {
if strings.HasPrefix(err.Error(), ... | go | func (p *BlockPrefetchClient) RetrieveAndStoreNext(nextHash *chainhash.Hash) {
p.Lock()
defer p.Unlock()
// Fetch the next block, if needed.
if p.haveBlockHash(*nextHash) {
return
}
msgBlock, headerResult, _, err := p.retrieveBlockAndHeaderResult(nextHash)
if err != nil {
if strings.HasPrefix(err.Error(), ... | [
"func",
"(",
"p",
"*",
"BlockPrefetchClient",
")",
"RetrieveAndStoreNext",
"(",
"nextHash",
"*",
"chainhash",
".",
"Hash",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n\n",
"// Fetch the next block, if needed.",
"if",... | // RetrieveAndStoreNext retrieves the next block specified by the Hash, if it is
// not already the stored next block, and stores the block data. The existing
// "next" becomes "current". | [
"RetrieveAndStoreNext",
"retrieves",
"the",
"next",
"block",
"specified",
"by",
"the",
"Hash",
"if",
"it",
"is",
"not",
"already",
"the",
"stored",
"next",
"block",
"and",
"stores",
"the",
"block",
"data",
".",
"The",
"existing",
"next",
"becomes",
"current",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/prefetcher.go#L220-L240 |
142,152 | decred/dcrdata | rpcutils/prefetcher.go | HaveBlockHeight | func (p *BlockPrefetchClient) HaveBlockHeight(height uint32) bool {
p.Lock()
defer p.Unlock()
return p.haveBlockHeight(height)
} | go | func (p *BlockPrefetchClient) HaveBlockHeight(height uint32) bool {
p.Lock()
defer p.Unlock()
return p.haveBlockHeight(height)
} | [
"func",
"(",
"p",
"*",
"BlockPrefetchClient",
")",
"HaveBlockHeight",
"(",
"height",
"uint32",
")",
"bool",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"return",
"p",
".",
"haveBlockHeight",
"(",
"height",
")",
... | // HaveBlockHeight checks if the current or prefetched next block is for a block
// with the specified height. Use HaveBlockHash to be sure it is the desired
// block. | [
"HaveBlockHeight",
"checks",
"if",
"the",
"current",
"or",
"prefetched",
"next",
"block",
"is",
"for",
"a",
"block",
"with",
"the",
"specified",
"height",
".",
"Use",
"HaveBlockHash",
"to",
"be",
"sure",
"it",
"is",
"the",
"desired",
"block",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/prefetcher.go#L257-L261 |
142,153 | decred/dcrdata | rpcutils/prefetcher.go | HaveBlockHash | func (p *BlockPrefetchClient) HaveBlockHash(hash chainhash.Hash) bool {
p.Lock()
defer p.Unlock()
return p.haveBlockHash(hash)
} | go | func (p *BlockPrefetchClient) HaveBlockHash(hash chainhash.Hash) bool {
p.Lock()
defer p.Unlock()
return p.haveBlockHash(hash)
} | [
"func",
"(",
"p",
"*",
"BlockPrefetchClient",
")",
"HaveBlockHash",
"(",
"hash",
"chainhash",
".",
"Hash",
")",
"bool",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"return",
"p",
".",
"haveBlockHash",
"(",
"has... | // HaveBlockHash checks if the current or prefetched next block is for a block
// with the specified hash. | [
"HaveBlockHash",
"checks",
"if",
"the",
"current",
"or",
"prefetched",
"next",
"block",
"is",
"for",
"a",
"block",
"with",
"the",
"specified",
"hash",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/prefetcher.go#L269-L273 |
142,154 | decred/dcrdata | gov/agendas/tracker.go | NewVoteTracker | func NewVoteTracker(params *chaincfg.Params, node VoteDataSource, counter voteCounter,
activeVersions map[uint32][]chaincfg.ConsensusDeployment) (*VoteTracker, error) {
var latestStakeVersion uint32
var starttime uint64
// Consensus deployments that share a stake version as the key should also
// have matching st... | go | func NewVoteTracker(params *chaincfg.Params, node VoteDataSource, counter voteCounter,
activeVersions map[uint32][]chaincfg.ConsensusDeployment) (*VoteTracker, error) {
var latestStakeVersion uint32
var starttime uint64
// Consensus deployments that share a stake version as the key should also
// have matching st... | [
"func",
"NewVoteTracker",
"(",
"params",
"*",
"chaincfg",
".",
"Params",
",",
"node",
"VoteDataSource",
",",
"counter",
"voteCounter",
",",
"activeVersions",
"map",
"[",
"uint32",
"]",
"[",
"]",
"chaincfg",
".",
"ConsensusDeployment",
")",
"(",
"*",
"VoteTrack... | // NewVoteTracker is a constructor for a VoteTracker. | [
"NewVoteTracker",
"is",
"a",
"constructor",
"for",
"a",
"VoteTracker",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/agendas/tracker.go#L130-L181 |
142,155 | decred/dcrdata | gov/agendas/tracker.go | Refresh | func (tracker *VoteTracker) Refresh() {
voteInfo, err := tracker.refreshRCI()
if err != nil {
log.Errorf("VoteTracker.Refresh -> refreshRCI: %v")
return
}
blocksToAdd, stakeVersion, err := tracker.fetchBlocks(voteInfo)
if err != nil {
log.Errorf("VoteTracker.Refresh -> fetchBlocks: %v")
return
}
stakeInf... | go | func (tracker *VoteTracker) Refresh() {
voteInfo, err := tracker.refreshRCI()
if err != nil {
log.Errorf("VoteTracker.Refresh -> refreshRCI: %v")
return
}
blocksToAdd, stakeVersion, err := tracker.fetchBlocks(voteInfo)
if err != nil {
log.Errorf("VoteTracker.Refresh -> fetchBlocks: %v")
return
}
stakeInf... | [
"func",
"(",
"tracker",
"*",
"VoteTracker",
")",
"Refresh",
"(",
")",
"{",
"voteInfo",
",",
"err",
":=",
"tracker",
".",
"refreshRCI",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
... | // Refresh refreshes node version and vote data. It can be called as a
// goroutine. All VoteTracker updating and mutex locking is handled within
// VoteTracker.update. | [
"Refresh",
"refreshes",
"node",
"version",
"and",
"vote",
"data",
".",
"It",
"can",
"be",
"called",
"as",
"a",
"goroutine",
".",
"All",
"VoteTracker",
"updating",
"and",
"mutex",
"locking",
"is",
"handled",
"within",
"VoteTracker",
".",
"update",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/agendas/tracker.go#L186-L203 |
142,156 | decred/dcrdata | gov/agendas/tracker.go | Version | func (tracker *VoteTracker) Version() uint32 {
tracker.mtx.RLock()
defer tracker.mtx.RUnlock()
return tracker.version
} | go | func (tracker *VoteTracker) Version() uint32 {
tracker.mtx.RLock()
defer tracker.mtx.RUnlock()
return tracker.version
} | [
"func",
"(",
"tracker",
"*",
"VoteTracker",
")",
"Version",
"(",
")",
"uint32",
"{",
"tracker",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"tracker",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"tracker",
".",
"version",
"\n",
"}"
] | // Version returns the current best known vote version.
// Since version could technically be updated without turning off dcrdata,
// the field must be protected. | [
"Version",
"returns",
"the",
"current",
"best",
"known",
"vote",
"version",
".",
"Since",
"version",
"could",
"technically",
"be",
"updated",
"without",
"turning",
"off",
"dcrdata",
"the",
"field",
"must",
"be",
"protected",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/agendas/tracker.go#L208-L212 |
142,157 | decred/dcrdata | gov/agendas/tracker.go | refreshRCI | func (tracker *VoteTracker) refreshRCI() (*dcrjson.GetVoteInfoResult, error) {
oldVersion := tracker.Version()
v := oldVersion
var err error
var voteInfo, vinfo *dcrjson.GetVoteInfoResult
// Retrieves the voteinfo for the last stake version supported.
for {
vinfo, err = tracker.node.GetVoteInfo(v)
if err != ... | go | func (tracker *VoteTracker) refreshRCI() (*dcrjson.GetVoteInfoResult, error) {
oldVersion := tracker.Version()
v := oldVersion
var err error
var voteInfo, vinfo *dcrjson.GetVoteInfoResult
// Retrieves the voteinfo for the last stake version supported.
for {
vinfo, err = tracker.node.GetVoteInfo(v)
if err != ... | [
"func",
"(",
"tracker",
"*",
"VoteTracker",
")",
"refreshRCI",
"(",
")",
"(",
"*",
"dcrjson",
".",
"GetVoteInfoResult",
",",
"error",
")",
"{",
"oldVersion",
":=",
"tracker",
".",
"Version",
"(",
")",
"\n",
"v",
":=",
"oldVersion",
"\n",
"var",
"err",
... | // Grab the getvoteinfo data. Do not update VoteTracker.voteInfo here, as it
// will be updated with other fields under mutex lock in VoteTracker.update. | [
"Grab",
"the",
"getvoteinfo",
"data",
".",
"Do",
"not",
"update",
"VoteTracker",
".",
"voteInfo",
"here",
"as",
"it",
"will",
"be",
"updated",
"with",
"other",
"fields",
"under",
"mutex",
"lock",
"in",
"VoteTracker",
".",
"update",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/agendas/tracker.go#L216-L241 |
142,158 | decred/dcrdata | gov/agendas/tracker.go | fetchBlocks | func (tracker *VoteTracker) fetchBlocks(voteInfo *dcrjson.GetVoteInfoResult) ([]int32, uint32, error) {
blocksToRequest := 1
// If this isn't the next block, request them all again
if voteInfo.CurrentHeight < 0 || voteInfo.CurrentHeight != tracker.ringHeight+1 {
blocksToRequest = int(tracker.params.BlockUpgradeNum... | go | func (tracker *VoteTracker) fetchBlocks(voteInfo *dcrjson.GetVoteInfoResult) ([]int32, uint32, error) {
blocksToRequest := 1
// If this isn't the next block, request them all again
if voteInfo.CurrentHeight < 0 || voteInfo.CurrentHeight != tracker.ringHeight+1 {
blocksToRequest = int(tracker.params.BlockUpgradeNum... | [
"func",
"(",
"tracker",
"*",
"VoteTracker",
")",
"fetchBlocks",
"(",
"voteInfo",
"*",
"dcrjson",
".",
"GetVoteInfoResult",
")",
"(",
"[",
"]",
"int32",
",",
"uint32",
",",
"error",
")",
"{",
"blocksToRequest",
":=",
"1",
"\n",
"// If this isn't the next block,... | // Grab the block versions for up to the last BlockUpgradeNumToCheck blocks.
// If the current block builds upon the last block, only request a single
// block's data. Otherwise, request all BlockUpgradeNumToCheck. | [
"Grab",
"the",
"block",
"versions",
"for",
"up",
"to",
"the",
"last",
"BlockUpgradeNumToCheck",
"blocks",
".",
"If",
"the",
"current",
"block",
"builds",
"upon",
"the",
"last",
"block",
"only",
"request",
"a",
"single",
"block",
"s",
"data",
".",
"Otherwise"... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/agendas/tracker.go#L251-L273 |
142,159 | decred/dcrdata | gov/agendas/tracker.go | refreshSVIs | func (tracker *VoteTracker) refreshSVIs(voteInfo *dcrjson.GetVoteInfoResult) (*dcrjson.GetStakeVersionInfoResult, error) {
blocksInCurrentRCI := rciBlocks(voteInfo)
svis := int32(blocksInCurrentRCI / tracker.params.StakeVersionInterval)
// blocksInCurrentSVI := int32(blocksInCurrentRCI % params.StakeVersionInterval)... | go | func (tracker *VoteTracker) refreshSVIs(voteInfo *dcrjson.GetVoteInfoResult) (*dcrjson.GetStakeVersionInfoResult, error) {
blocksInCurrentRCI := rciBlocks(voteInfo)
svis := int32(blocksInCurrentRCI / tracker.params.StakeVersionInterval)
// blocksInCurrentSVI := int32(blocksInCurrentRCI % params.StakeVersionInterval)... | [
"func",
"(",
"tracker",
"*",
"VoteTracker",
")",
"refreshSVIs",
"(",
"voteInfo",
"*",
"dcrjson",
".",
"GetVoteInfoResult",
")",
"(",
"*",
"dcrjson",
".",
"GetStakeVersionInfoResult",
",",
"error",
")",
"{",
"blocksInCurrentRCI",
":=",
"rciBlocks",
"(",
"voteInfo... | // Get the info for the stake versions in the current rule change interval. | [
"Get",
"the",
"info",
"for",
"the",
"stake",
"versions",
"in",
"the",
"current",
"rule",
"change",
"interval",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/agendas/tracker.go#L276-L288 |
142,160 | decred/dcrdata | gov/agendas/tracker.go | cachedCounts | func (tracker *VoteTracker) cachedCounts(agendaID string) *voteCount {
tracker.mtx.RLock()
defer tracker.mtx.RUnlock()
return tracker.countCache[agendaID]
} | go | func (tracker *VoteTracker) cachedCounts(agendaID string) *voteCount {
tracker.mtx.RLock()
defer tracker.mtx.RUnlock()
return tracker.countCache[agendaID]
} | [
"func",
"(",
"tracker",
"*",
"VoteTracker",
")",
"cachedCounts",
"(",
"agendaID",
"string",
")",
"*",
"voteCount",
"{",
"tracker",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"tracker",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"trac... | // The cached voteCount for the given agenda, or nil if not found. | [
"The",
"cached",
"voteCount",
"for",
"the",
"given",
"agenda",
"or",
"nil",
"if",
"not",
"found",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/agendas/tracker.go#L291-L295 |
142,161 | decred/dcrdata | gov/agendas/tracker.go | cacheVoteCounts | func (tracker *VoteTracker) cacheVoteCounts(agendaID string, counts *voteCount) {
tracker.mtx.Lock()
defer tracker.mtx.Unlock()
tracker.countCache[agendaID] = counts
} | go | func (tracker *VoteTracker) cacheVoteCounts(agendaID string, counts *voteCount) {
tracker.mtx.Lock()
defer tracker.mtx.Unlock()
tracker.countCache[agendaID] = counts
} | [
"func",
"(",
"tracker",
"*",
"VoteTracker",
")",
"cacheVoteCounts",
"(",
"agendaID",
"string",
",",
"counts",
"*",
"voteCount",
")",
"{",
"tracker",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"tracker",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",... | // Cache the voteCount for the given agenda. | [
"Cache",
"the",
"voteCount",
"for",
"the",
"given",
"agenda",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/agendas/tracker.go#L298-L302 |
142,162 | decred/dcrdata | gov/agendas/tracker.go | update | func (tracker *VoteTracker) update(voteInfo *dcrjson.GetVoteInfoResult, blocks []int32,
stakeInfo *dcrjson.GetStakeVersionInfoResult, stakeVersion uint32) {
// Check if voteCounts are needed
for idx := range voteInfo.Agendas {
agenda := &voteInfo.Agendas[idx]
if agenda.Status != statusDefined && agenda.Status !=... | go | func (tracker *VoteTracker) update(voteInfo *dcrjson.GetVoteInfoResult, blocks []int32,
stakeInfo *dcrjson.GetStakeVersionInfoResult, stakeVersion uint32) {
// Check if voteCounts are needed
for idx := range voteInfo.Agendas {
agenda := &voteInfo.Agendas[idx]
if agenda.Status != statusDefined && agenda.Status !=... | [
"func",
"(",
"tracker",
"*",
"VoteTracker",
")",
"update",
"(",
"voteInfo",
"*",
"dcrjson",
".",
"GetVoteInfoResult",
",",
"blocks",
"[",
"]",
"int32",
",",
"stakeInfo",
"*",
"dcrjson",
".",
"GetStakeVersionInfoResult",
",",
"stakeVersion",
"uint32",
")",
"{",... | // Once all resources have been retrieved from dcrd, update VoteTracker fields. | [
"Once",
"all",
"resources",
"have",
"been",
"retrieved",
"from",
"dcrd",
"update",
"VoteTracker",
"fields",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/agendas/tracker.go#L305-L348 |
142,163 | decred/dcrdata | gov/agendas/tracker.go | Summary | func (tracker *VoteTracker) Summary() *VoteSummary {
tracker.mtx.RLock()
defer tracker.mtx.RUnlock()
return tracker.summary
} | go | func (tracker *VoteTracker) Summary() *VoteSummary {
tracker.mtx.RLock()
defer tracker.mtx.RUnlock()
return tracker.summary
} | [
"func",
"(",
"tracker",
"*",
"VoteTracker",
")",
"Summary",
"(",
")",
"*",
"VoteSummary",
"{",
"tracker",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"tracker",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"tracker",
".",
"summary",
"... | // Summary is a getter for the cached VoteSummary. The summary returned will
// never be modified by VoteTracker, so can be used read-only by any number
// of threads. | [
"Summary",
"is",
"a",
"getter",
"for",
"the",
"cached",
"VoteSummary",
".",
"The",
"summary",
"returned",
"will",
"never",
"be",
"modified",
"by",
"VoteTracker",
"so",
"can",
"be",
"used",
"read",
"-",
"only",
"by",
"any",
"number",
"of",
"threads",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/agendas/tracker.go#L469-L473 |
142,164 | decred/dcrdata | dcrrates/rateserver/log.go | initializeLogging | func initializeLogging(logFile, logLevel string) {
log = backendLog.Logger("SRVR")
exchanges.UseLogger(xcLogger)
logDir, _ := filepath.Split(logFile)
err := os.MkdirAll(logDir, 0700)
if err != nil {
log.Errorf("failed to create log directory: %v", err)
os.Exit(1)
}
r, err := rotator.New(logFile, 10*1024, fal... | go | func initializeLogging(logFile, logLevel string) {
log = backendLog.Logger("SRVR")
exchanges.UseLogger(xcLogger)
logDir, _ := filepath.Split(logFile)
err := os.MkdirAll(logDir, 0700)
if err != nil {
log.Errorf("failed to create log directory: %v", err)
os.Exit(1)
}
r, err := rotator.New(logFile, 10*1024, fal... | [
"func",
"initializeLogging",
"(",
"logFile",
",",
"logLevel",
"string",
")",
"{",
"log",
"=",
"backendLog",
".",
"Logger",
"(",
"\"",
"\"",
")",
"\n",
"exchanges",
".",
"UseLogger",
"(",
"xcLogger",
")",
"\n",
"logDir",
",",
"_",
":=",
"filepath",
".",
... | // initializeLogging initializes the logging rotater to write logs to logFile
// and create roll files in the same directory. It must be called before the
// package-global log rotater variables are used. | [
"initializeLogging",
"initializes",
"the",
"logging",
"rotater",
"to",
"write",
"logs",
"to",
"logFile",
"and",
"create",
"roll",
"files",
"in",
"the",
"same",
"directory",
".",
"It",
"must",
"be",
"called",
"before",
"the",
"package",
"-",
"global",
"log",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/dcrrates/rateserver/log.go#L36-L60 |
142,165 | decred/dcrdata | db/dcrpg/chainmonitor.go | NewChainMonitor | func (pgb *ChainDBRPC) NewChainMonitor(ctx context.Context, wg *sync.WaitGroup,
blockChan chan *chainhash.Hash, reorgChan chan *txhelpers.ReorgData) *ChainMonitor {
if pgb == nil {
return nil
}
return &ChainMonitor{
ctx: ctx,
db: pgb,
wg: wg,
blockChan: blockChan,
... | go | func (pgb *ChainDBRPC) NewChainMonitor(ctx context.Context, wg *sync.WaitGroup,
blockChan chan *chainhash.Hash, reorgChan chan *txhelpers.ReorgData) *ChainMonitor {
if pgb == nil {
return nil
}
return &ChainMonitor{
ctx: ctx,
db: pgb,
wg: wg,
blockChan: blockChan,
... | [
"func",
"(",
"pgb",
"*",
"ChainDBRPC",
")",
"NewChainMonitor",
"(",
"ctx",
"context",
".",
"Context",
",",
"wg",
"*",
"sync",
".",
"WaitGroup",
",",
"blockChan",
"chan",
"*",
"chainhash",
".",
"Hash",
",",
"reorgChan",
"chan",
"*",
"txhelpers",
".",
"Reo... | // NewChainMonitor creates a new ChainMonitor. | [
"NewChainMonitor",
"creates",
"a",
"new",
"ChainMonitor",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/chainmonitor.go#L30-L44 |
142,166 | decred/dcrdata | rpcutils/rpcclient.go | ConnectNodeRPC | func ConnectNodeRPC(host, user, pass, cert string, disableTLS, disableReconnect bool,
ntfnHandlers ...*rpcclient.NotificationHandlers) (*rpcclient.Client, semver.Semver, error) {
var dcrdCerts []byte
var err error
var nodeVer semver.Semver
if !disableTLS {
dcrdCerts, err = ioutil.ReadFile(cert)
if err != nil {... | go | func ConnectNodeRPC(host, user, pass, cert string, disableTLS, disableReconnect bool,
ntfnHandlers ...*rpcclient.NotificationHandlers) (*rpcclient.Client, semver.Semver, error) {
var dcrdCerts []byte
var err error
var nodeVer semver.Semver
if !disableTLS {
dcrdCerts, err = ioutil.ReadFile(cert)
if err != nil {... | [
"func",
"ConnectNodeRPC",
"(",
"host",
",",
"user",
",",
"pass",
",",
"cert",
"string",
",",
"disableTLS",
",",
"disableReconnect",
"bool",
",",
"ntfnHandlers",
"...",
"*",
"rpcclient",
".",
"NotificationHandlers",
")",
"(",
"*",
"rpcclient",
".",
"Client",
... | // ConnectNodeRPC attempts to create a new websocket connection to a dcrd node,
// with the given credentials and optional notification handlers. | [
"ConnectNodeRPC",
"attempts",
"to",
"create",
"a",
"new",
"websocket",
"connection",
"to",
"a",
"dcrd",
"node",
"with",
"the",
"given",
"credentials",
"and",
"optional",
"notification",
"handlers",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/rpcclient.go#L44-L105 |
142,167 | decred/dcrdata | rpcutils/rpcclient.go | GetBlockByHash | func GetBlockByHash(blockhash *chainhash.Hash, client BlockFetcher) (*dcrutil.Block, error) {
msgBlock, err := client.GetBlock(blockhash)
if err != nil {
return nil, fmt.Errorf("GetBlock failed (%s): %v", blockhash, err)
}
block := dcrutil.NewBlock(msgBlock)
return block, nil
} | go | func GetBlockByHash(blockhash *chainhash.Hash, client BlockFetcher) (*dcrutil.Block, error) {
msgBlock, err := client.GetBlock(blockhash)
if err != nil {
return nil, fmt.Errorf("GetBlock failed (%s): %v", blockhash, err)
}
block := dcrutil.NewBlock(msgBlock)
return block, nil
} | [
"func",
"GetBlockByHash",
"(",
"blockhash",
"*",
"chainhash",
".",
"Hash",
",",
"client",
"BlockFetcher",
")",
"(",
"*",
"dcrutil",
".",
"Block",
",",
"error",
")",
"{",
"msgBlock",
",",
"err",
":=",
"client",
".",
"GetBlock",
"(",
"blockhash",
")",
"\n"... | // GetBlockByHash gets the block with the given hash from a chain server. | [
"GetBlockByHash",
"gets",
"the",
"block",
"with",
"the",
"given",
"hash",
"from",
"a",
"chain",
"server",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/rpcclient.go#L261-L269 |
142,168 | decred/dcrdata | rpcutils/rpcclient.go | SideChains | func SideChains(client *rpcclient.Client) ([]dcrjson.GetChainTipsResult, error) {
tips, err := client.GetChainTips()
if err != nil {
return nil, err
}
return sideChainTips(tips), nil
} | go | func SideChains(client *rpcclient.Client) ([]dcrjson.GetChainTipsResult, error) {
tips, err := client.GetChainTips()
if err != nil {
return nil, err
}
return sideChainTips(tips), nil
} | [
"func",
"SideChains",
"(",
"client",
"*",
"rpcclient",
".",
"Client",
")",
"(",
"[",
"]",
"dcrjson",
".",
"GetChainTipsResult",
",",
"error",
")",
"{",
"tips",
",",
"err",
":=",
"client",
".",
"GetChainTips",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // SideChains gets a slice of known side chain tips. This corresponds to the
// results of the getchaintips node RPC where the block tip "status" is either
// "valid-headers" or "valid-fork". | [
"SideChains",
"gets",
"a",
"slice",
"of",
"known",
"side",
"chain",
"tips",
".",
"This",
"corresponds",
"to",
"the",
"results",
"of",
"the",
"getchaintips",
"node",
"RPC",
"where",
"the",
"block",
"tip",
"status",
"is",
"either",
"valid",
"-",
"headers",
"... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/rpcclient.go#L274-L281 |
142,169 | decred/dcrdata | rpcutils/rpcclient.go | GetTransactionVerboseByID | func GetTransactionVerboseByID(client *rpcclient.Client, txhash *chainhash.Hash) (*dcrjson.TxRawResult, error) {
txraw, err := client.GetRawTransactionVerbose(txhash)
if err != nil {
log.Errorf("GetRawTransactionVerbose failed for: %v", txhash)
return nil, err
}
return txraw, nil
} | go | func GetTransactionVerboseByID(client *rpcclient.Client, txhash *chainhash.Hash) (*dcrjson.TxRawResult, error) {
txraw, err := client.GetRawTransactionVerbose(txhash)
if err != nil {
log.Errorf("GetRawTransactionVerbose failed for: %v", txhash)
return nil, err
}
return txraw, nil
} | [
"func",
"GetTransactionVerboseByID",
"(",
"client",
"*",
"rpcclient",
".",
"Client",
",",
"txhash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"dcrjson",
".",
"TxRawResult",
",",
"error",
")",
"{",
"txraw",
",",
"err",
":=",
"client",
".",
"GetRawTransa... | // GetTransactionVerboseByID get a transaction by transaction id | [
"GetTransactionVerboseByID",
"get",
"a",
"transaction",
"by",
"transaction",
"id"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/rpcclient.go#L341-L348 |
142,170 | decred/dcrdata | rpcutils/rpcclient.go | SearchRawTransaction | func SearchRawTransaction(client *rpcclient.Client, count int, address string) ([]*dcrjson.SearchRawTransactionsResult, error) {
addr, err := dcrutil.DecodeAddress(address)
if err != nil {
log.Infof("Invalid address %s: %v", address, err)
return nil, err
}
//change the 1000 000 number demo for now
txs, err := ... | go | func SearchRawTransaction(client *rpcclient.Client, count int, address string) ([]*dcrjson.SearchRawTransactionsResult, error) {
addr, err := dcrutil.DecodeAddress(address)
if err != nil {
log.Infof("Invalid address %s: %v", address, err)
return nil, err
}
//change the 1000 000 number demo for now
txs, err := ... | [
"func",
"SearchRawTransaction",
"(",
"client",
"*",
"rpcclient",
".",
"Client",
",",
"count",
"int",
",",
"address",
"string",
")",
"(",
"[",
"]",
"*",
"dcrjson",
".",
"SearchRawTransactionsResult",
",",
"error",
")",
"{",
"addr",
",",
"err",
":=",
"dcruti... | // SearchRawTransaction fetch transactions the belong to an
// address | [
"SearchRawTransaction",
"fetch",
"transactions",
"the",
"belong",
"to",
"an",
"address"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/rpcclient.go#L352-L365 |
142,171 | decred/dcrdata | rpcutils/rpcclient.go | CommonAncestor | func CommonAncestor(client BlockFetcher, hashA, hashB chainhash.Hash) (*chainhash.Hash, []chainhash.Hash, []chainhash.Hash, error) {
if client == nil {
return nil, nil, nil, errors.New("nil RPC client")
}
var length int
var chainA, chainB []chainhash.Hash
for {
if length >= maxAncestorChainLength {
return ... | go | func CommonAncestor(client BlockFetcher, hashA, hashB chainhash.Hash) (*chainhash.Hash, []chainhash.Hash, []chainhash.Hash, error) {
if client == nil {
return nil, nil, nil, errors.New("nil RPC client")
}
var length int
var chainA, chainB []chainhash.Hash
for {
if length >= maxAncestorChainLength {
return ... | [
"func",
"CommonAncestor",
"(",
"client",
"BlockFetcher",
",",
"hashA",
",",
"hashB",
"chainhash",
".",
"Hash",
")",
"(",
"*",
"chainhash",
".",
"Hash",
",",
"[",
"]",
"chainhash",
".",
"Hash",
",",
"[",
"]",
"chainhash",
".",
"Hash",
",",
"error",
")",... | // CommonAncestor attempts to determine the common ancestor block for two chains
// specified by the hash of the chain tip block. The full chains from the tips
// back to but not including the common ancestor are also returned. The first
// element in the chain slices is the lowest block following the common
// ancesto... | [
"CommonAncestor",
"attempts",
"to",
"determine",
"the",
"common",
"ancestor",
"block",
"for",
"two",
"chains",
"specified",
"by",
"the",
"hash",
"of",
"the",
"chain",
"tip",
"block",
".",
"The",
"full",
"chains",
"from",
"the",
"tips",
"back",
"to",
"but",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/rpcclient.go#L376-L446 |
142,172 | decred/dcrdata | rpcutils/rpcclient.go | OrphanedTipLength | func OrphanedTipLength(ctx context.Context, client BlockHashGetter,
tipHeight int64, hashFunc func(int64) (string, error)) (int64, error) {
commonHeight := tipHeight
var dbHash string
var err error
var dcrdHash *chainhash.Hash
for {
// Since there are no limits on the number of blocks scanned, allow
// cancel... | go | func OrphanedTipLength(ctx context.Context, client BlockHashGetter,
tipHeight int64, hashFunc func(int64) (string, error)) (int64, error) {
commonHeight := tipHeight
var dbHash string
var err error
var dcrdHash *chainhash.Hash
for {
// Since there are no limits on the number of blocks scanned, allow
// cancel... | [
"func",
"OrphanedTipLength",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"BlockHashGetter",
",",
"tipHeight",
"int64",
",",
"hashFunc",
"func",
"(",
"int64",
")",
"(",
"string",
",",
"error",
")",
")",
"(",
"int64",
",",
"error",
")",
"{",
"com... | // OrphanedTipLength finds a common ancestor by iterating block heights
// backwards until a common block hash is found. Unlike CommonAncestor, an
// orphaned DB tip whose corresponding block is not known to dcrd will not cause
// an error. The number of blocks that have been orphaned is returned.
// Realistically, thi... | [
"OrphanedTipLength",
"finds",
"a",
"common",
"ancestor",
"by",
"iterating",
"block",
"heights",
"backwards",
"until",
"a",
"common",
"block",
"hash",
"is",
"found",
".",
"Unlike",
"CommonAncestor",
"an",
"orphaned",
"DB",
"tip",
"whose",
"corresponding",
"block",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/rpcclient.go#L458-L497 |
142,173 | decred/dcrdata | rpcutils/rpcclient.go | GetChainWork | func GetChainWork(client BlockFetcher, hash *chainhash.Hash) (string, error) {
header, err := client.GetBlockHeaderVerbose(hash)
if err != nil {
return "", err
}
return header.ChainWork, nil
} | go | func GetChainWork(client BlockFetcher, hash *chainhash.Hash) (string, error) {
header, err := client.GetBlockHeaderVerbose(hash)
if err != nil {
return "", err
}
return header.ChainWork, nil
} | [
"func",
"GetChainWork",
"(",
"client",
"BlockFetcher",
",",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"string",
",",
"error",
")",
"{",
"header",
",",
"err",
":=",
"client",
".",
"GetBlockHeaderVerbose",
"(",
"hash",
")",
"\n",
"if",
"err",
"!=",
... | // GetChainWork fetches the dcrjson.BlockHeaderVerbose and returns only the
// ChainWork field as a string. | [
"GetChainWork",
"fetches",
"the",
"dcrjson",
".",
"BlockHeaderVerbose",
"and",
"returns",
"only",
"the",
"ChainWork",
"field",
"as",
"a",
"string",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/rpcutils/rpcclient.go#L501-L507 |
142,174 | decred/dcrdata | explorer/explorer.go | TicketStatusText | func TicketStatusText(s dbtypes.TicketSpendType, p dbtypes.TicketPoolStatus) string {
switch p {
case dbtypes.PoolStatusLive:
return "In Live Ticket Pool"
case dbtypes.PoolStatusVoted:
return "Voted"
case dbtypes.PoolStatusExpired:
switch s {
case dbtypes.TicketUnspent:
return "Expired, Unrevoked"
case... | go | func TicketStatusText(s dbtypes.TicketSpendType, p dbtypes.TicketPoolStatus) string {
switch p {
case dbtypes.PoolStatusLive:
return "In Live Ticket Pool"
case dbtypes.PoolStatusVoted:
return "Voted"
case dbtypes.PoolStatusExpired:
switch s {
case dbtypes.TicketUnspent:
return "Expired, Unrevoked"
case... | [
"func",
"TicketStatusText",
"(",
"s",
"dbtypes",
".",
"TicketSpendType",
",",
"p",
"dbtypes",
".",
"TicketPoolStatus",
")",
"string",
"{",
"switch",
"p",
"{",
"case",
"dbtypes",
".",
"PoolStatusLive",
":",
"return",
"\"",
"\"",
"\n",
"case",
"dbtypes",
".",
... | // TicketStatusText generates the text to display on the explorer's transaction
// page for the "POOL STATUS" field. | [
"TicketStatusText",
"generates",
"the",
"text",
"to",
"display",
"on",
"the",
"explorer",
"s",
"transaction",
"page",
"for",
"the",
"POOL",
"STATUS",
"field",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorer.go#L159-L186 |
142,175 | decred/dcrdata | explorer/explorer.go | SetDBsSyncing | func (exp *explorerUI) SetDBsSyncing(syncing bool) {
exp.dbsSyncing.Store(syncing)
exp.wsHub.SetDBsSyncing(syncing)
} | go | func (exp *explorerUI) SetDBsSyncing(syncing bool) {
exp.dbsSyncing.Store(syncing)
exp.wsHub.SetDBsSyncing(syncing)
} | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"SetDBsSyncing",
"(",
"syncing",
"bool",
")",
"{",
"exp",
".",
"dbsSyncing",
".",
"Store",
"(",
"syncing",
")",
"\n",
"exp",
".",
"wsHub",
".",
"SetDBsSyncing",
"(",
"syncing",
")",
"\n",
"}"
] | // SetDBsSyncing is a thread-safe way to update dbsSyncing. | [
"SetDBsSyncing",
"is",
"a",
"thread",
"-",
"safe",
"way",
"to",
"update",
"dbsSyncing",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorer.go#L230-L233 |
142,176 | decred/dcrdata | explorer/explorer.go | StopWebsocketHub | func (exp *explorerUI) StopWebsocketHub() {
if exp == nil {
return
}
log.Info("Stopping websocket hub.")
exp.wsHub.Stop()
close(exp.xcDone)
} | go | func (exp *explorerUI) StopWebsocketHub() {
if exp == nil {
return
}
log.Info("Stopping websocket hub.")
exp.wsHub.Stop()
close(exp.xcDone)
} | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"StopWebsocketHub",
"(",
")",
"{",
"if",
"exp",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"exp",
".",
"wsHub",
".",
"Stop",
"(",
")",
"\n",
"close",
... | // StopWebsocketHub stops the websocket hub | [
"StopWebsocketHub",
"stops",
"the",
"websocket",
"hub"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorer.go#L260-L267 |
142,177 | decred/dcrdata | explorer/explorer.go | Height | func (exp *explorerUI) Height() int64 {
exp.pageData.RLock()
defer exp.pageData.RUnlock()
if exp.pageData.BlockInfo.BlockBasic == nil {
// If exp.pageData.BlockInfo.BlockBasic has not yet been set return:
return -1
}
return exp.pageData.BlockInfo.Height
} | go | func (exp *explorerUI) Height() int64 {
exp.pageData.RLock()
defer exp.pageData.RUnlock()
if exp.pageData.BlockInfo.BlockBasic == nil {
// If exp.pageData.BlockInfo.BlockBasic has not yet been set return:
return -1
}
return exp.pageData.BlockInfo.Height
} | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"Height",
"(",
")",
"int64",
"{",
"exp",
".",
"pageData",
".",
"RLock",
"(",
")",
"\n",
"defer",
"exp",
".",
"pageData",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"exp",
".",
"pageData",
".",
"BlockInfo",
"... | // Height returns the height of the current block data. | [
"Height",
"returns",
"the",
"height",
"of",
"the",
"current",
"block",
"data",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorer.go#L375-L385 |
142,178 | decred/dcrdata | explorer/explorer.go | LastBlock | func (exp *explorerUI) LastBlock() (lastBlockHash string, lastBlock int64, lastBlockTime int64) {
exp.pageData.RLock()
defer exp.pageData.RUnlock()
if exp.pageData.BlockInfo.BlockBasic == nil {
// If exp.pageData.BlockInfo.BlockBasic has not yet been set return:
lastBlock, lastBlockTime = -1, -1
return
}
l... | go | func (exp *explorerUI) LastBlock() (lastBlockHash string, lastBlock int64, lastBlockTime int64) {
exp.pageData.RLock()
defer exp.pageData.RUnlock()
if exp.pageData.BlockInfo.BlockBasic == nil {
// If exp.pageData.BlockInfo.BlockBasic has not yet been set return:
lastBlock, lastBlockTime = -1, -1
return
}
l... | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"LastBlock",
"(",
")",
"(",
"lastBlockHash",
"string",
",",
"lastBlock",
"int64",
",",
"lastBlockTime",
"int64",
")",
"{",
"exp",
".",
"pageData",
".",
"RLock",
"(",
")",
"\n",
"defer",
"exp",
".",
"pageData",
... | // LastBlock returns the last block hash, height and time. | [
"LastBlock",
"returns",
"the",
"last",
"block",
"hash",
"height",
"and",
"time",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorer.go#L388-L402 |
142,179 | decred/dcrdata | explorer/explorer.go | MempoolID | func (exp *explorerUI) MempoolID() uint64 {
exp.invsMtx.RLock()
defer exp.invsMtx.RUnlock()
return exp.invs.ID()
} | go | func (exp *explorerUI) MempoolID() uint64 {
exp.invsMtx.RLock()
defer exp.invsMtx.RUnlock()
return exp.invs.ID()
} | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"MempoolID",
"(",
")",
"uint64",
"{",
"exp",
".",
"invsMtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"exp",
".",
"invsMtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"exp",
".",
"invs",
".",
"ID",
"(",
"... | // MempoolID safely fetches the current mempool inventory ID. | [
"MempoolID",
"safely",
"fetches",
"the",
"current",
"mempool",
"inventory",
"ID",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorer.go#L412-L416 |
142,180 | decred/dcrdata | explorer/explorer.go | simulateASR | func (exp *explorerUI) simulateASR(StartingDCRBalance float64, IntegerTicketQty bool,
CurrentStakePercent float64, ActualCoinbase float64, CurrentBlockNum float64,
ActualTicketPrice float64) (ASR float64, ReturnTable string) {
// Calculations are only useful on mainnet. Short circuit calculations if
// on any oth... | go | func (exp *explorerUI) simulateASR(StartingDCRBalance float64, IntegerTicketQty bool,
CurrentStakePercent float64, ActualCoinbase float64, CurrentBlockNum float64,
ActualTicketPrice float64) (ASR float64, ReturnTable string) {
// Calculations are only useful on mainnet. Short circuit calculations if
// on any oth... | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"simulateASR",
"(",
"StartingDCRBalance",
"float64",
",",
"IntegerTicketQty",
"bool",
",",
"CurrentStakePercent",
"float64",
",",
"ActualCoinbase",
"float64",
",",
"CurrentBlockNum",
"float64",
",",
"ActualTicketPrice",
"flo... | // Simulate ticket purchase and re-investment over a full year for a given
// starting amount of DCR and calculation parameters. Generate a TEXT table of
// the simulation results that can optionally be used for future expansion of
// dcrdata functionality. | [
"Simulate",
"ticket",
"purchase",
"and",
"re",
"-",
"investment",
"over",
"a",
"full",
"year",
"for",
"a",
"given",
"starting",
"amount",
"of",
"DCR",
"and",
"calculation",
"parameters",
".",
"Generate",
"a",
"TEXT",
"table",
"of",
"the",
"simulation",
"resu... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorer.go#L629-L736 |
142,181 | decred/dcrdata | explorer/explorer.go | mempoolTime | func (exp *explorerUI) mempoolTime(txid string) types.TimeDef {
exp.invsMtx.RLock()
defer exp.invsMtx.RUnlock()
tx, found := exp.invs.Tx(txid)
if !found {
return types.NewTimeDefFromUNIX(0)
}
return types.NewTimeDefFromUNIX(tx.Time)
} | go | func (exp *explorerUI) mempoolTime(txid string) types.TimeDef {
exp.invsMtx.RLock()
defer exp.invsMtx.RUnlock()
tx, found := exp.invs.Tx(txid)
if !found {
return types.NewTimeDefFromUNIX(0)
}
return types.NewTimeDefFromUNIX(tx.Time)
} | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"mempoolTime",
"(",
"txid",
"string",
")",
"types",
".",
"TimeDef",
"{",
"exp",
".",
"invsMtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"exp",
".",
"invsMtx",
".",
"RUnlock",
"(",
")",
"\n",
"tx",
",",
"fo... | // mempoolTime is the TimeDef that the transaction was received in DCRData, or
// else a zero-valued TimeDef if no transaction is found. | [
"mempoolTime",
"is",
"the",
"TimeDef",
"that",
"the",
"transaction",
"was",
"received",
"in",
"DCRData",
"or",
"else",
"a",
"zero",
"-",
"valued",
"TimeDef",
"if",
"no",
"transaction",
"is",
"found",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorer.go#L795-L803 |
142,182 | decred/dcrdata | semver/semver.go | NewSemver | func NewSemver(major, minor, patch uint32) Semver {
return Semver{major, minor, patch}
} | go | func NewSemver(major, minor, patch uint32) Semver {
return Semver{major, minor, patch}
} | [
"func",
"NewSemver",
"(",
"major",
",",
"minor",
",",
"patch",
"uint32",
")",
"Semver",
"{",
"return",
"Semver",
"{",
"major",
",",
"minor",
",",
"patch",
"}",
"\n",
"}"
] | // NewSemver returns a new Semver with the version major.minor.patch | [
"NewSemver",
"returns",
"a",
"new",
"Semver",
"with",
"the",
"version",
"major",
".",
"minor",
".",
"patch"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/semver/semver.go#L14-L16 |
142,183 | decred/dcrdata | semver/semver.go | Compatible | func Compatible(required, actual Semver) bool {
switch {
case required.major != actual.major:
return false
case required.minor > actual.minor:
return false
case required.minor == actual.minor && required.patch > actual.patch:
return false
default:
return true
}
} | go | func Compatible(required, actual Semver) bool {
switch {
case required.major != actual.major:
return false
case required.minor > actual.minor:
return false
case required.minor == actual.minor && required.patch > actual.patch:
return false
default:
return true
}
} | [
"func",
"Compatible",
"(",
"required",
",",
"actual",
"Semver",
")",
"bool",
"{",
"switch",
"{",
"case",
"required",
".",
"major",
"!=",
"actual",
".",
"major",
":",
"return",
"false",
"\n",
"case",
"required",
".",
"minor",
">",
"actual",
".",
"minor",
... | // Compatible decides if the actual version is compatible with the required one. | [
"Compatible",
"decides",
"if",
"the",
"actual",
"version",
"is",
"compatible",
"with",
"the",
"required",
"one",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/semver/semver.go#L24-L35 |
142,184 | decred/dcrdata | semver/semver.go | AnyCompatible | func AnyCompatible(compatible []Semver, actual Semver) (isApiCompat bool) {
for _, v := range compatible {
if Compatible(v, actual) {
isApiCompat = true
break
}
}
return
} | go | func AnyCompatible(compatible []Semver, actual Semver) (isApiCompat bool) {
for _, v := range compatible {
if Compatible(v, actual) {
isApiCompat = true
break
}
}
return
} | [
"func",
"AnyCompatible",
"(",
"compatible",
"[",
"]",
"Semver",
",",
"actual",
"Semver",
")",
"(",
"isApiCompat",
"bool",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"compatible",
"{",
"if",
"Compatible",
"(",
"v",
",",
"actual",
")",
"{",
"isApiCom... | // AnyCompatible checks if the version is compatible with any versions in a
// slice of versions. | [
"AnyCompatible",
"checks",
"if",
"the",
"version",
"is",
"compatible",
"with",
"any",
"versions",
"in",
"a",
"slice",
"of",
"versions",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/semver/semver.go#L39-L47 |
142,185 | decred/dcrdata | semver/semver.go | Split | func (s *Semver) Split() (uint32, uint32, uint32) {
return s.major, s.minor, s.patch
} | go | func (s *Semver) Split() (uint32, uint32, uint32) {
return s.major, s.minor, s.patch
} | [
"func",
"(",
"s",
"*",
"Semver",
")",
"Split",
"(",
")",
"(",
"uint32",
",",
"uint32",
",",
"uint32",
")",
"{",
"return",
"s",
".",
"major",
",",
"s",
".",
"minor",
",",
"s",
".",
"patch",
"\n",
"}"
] | // Split returns the major, minor and patch version. | [
"Split",
"returns",
"the",
"major",
"minor",
"and",
"patch",
"version",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/semver/semver.go#L54-L56 |
142,186 | decred/dcrdata | gov/politeia/proposals.go | NewProposalsDB | func NewProposalsDB(politeiaURL, dbPath string) (*ProposalDB, error) {
if politeiaURL == "" {
return nil, fmt.Errorf("missing politeia API URL")
}
if dbPath == "" {
return nil, fmt.Errorf("missing db path")
}
_, err := os.Stat(dbPath)
if err != nil && !os.IsNotExist(err) {
return nil, err
}
db, err := ... | go | func NewProposalsDB(politeiaURL, dbPath string) (*ProposalDB, error) {
if politeiaURL == "" {
return nil, fmt.Errorf("missing politeia API URL")
}
if dbPath == "" {
return nil, fmt.Errorf("missing db path")
}
_, err := os.Stat(dbPath)
if err != nil && !os.IsNotExist(err) {
return nil, err
}
db, err := ... | [
"func",
"NewProposalsDB",
"(",
"politeiaURL",
",",
"dbPath",
"string",
")",
"(",
"*",
"ProposalDB",
",",
"error",
")",
"{",
"if",
"politeiaURL",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n... | // NewProposalsDB opens an exiting database or creates a new DB instance with
// the provided file name. Returns an initialized instance of proposals DB, http
// client and the formatted politeia API URL path to be used. It also checks the
// db version, Reindexes the db if need be and sets the required db version. | [
"NewProposalsDB",
"opens",
"an",
"exiting",
"database",
"or",
"creates",
"a",
"new",
"DB",
"instance",
"with",
"the",
"provided",
"file",
"name",
".",
"Returns",
"an",
"initialized",
"instance",
"of",
"proposals",
"DB",
"http",
"client",
"and",
"the",
"formatt... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/politeia/proposals.go#L51-L114 |
142,187 | decred/dcrdata | gov/politeia/proposals.go | Close | func (db *ProposalDB) Close() error {
if db == nil || db.dbP == nil {
return nil
}
return db.dbP.Close()
} | go | func (db *ProposalDB) Close() error {
if db == nil || db.dbP == nil {
return nil
}
return db.dbP.Close()
} | [
"func",
"(",
"db",
"*",
"ProposalDB",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"db",
"==",
"nil",
"||",
"db",
".",
"dbP",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"db",
".",
"dbP",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Close closes the proposal DB instance created passed if it not nil. | [
"Close",
"closes",
"the",
"proposal",
"DB",
"instance",
"created",
"passed",
"if",
"it",
"not",
"nil",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/politeia/proposals.go#L117-L123 |
142,188 | decred/dcrdata | gov/politeia/proposals.go | generateCustomID | func generateCustomID(title string) (string, error) {
if title == "" {
return "", fmt.Errorf("ID not generated: invalid title found")
}
// regex selects only the alphanumeric characters.
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
if err != nil {
return "", err
}
// Replace all punctuation marks with a hyph... | go | func generateCustomID(title string) (string, error) {
if title == "" {
return "", fmt.Errorf("ID not generated: invalid title found")
}
// regex selects only the alphanumeric characters.
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
if err != nil {
return "", err
}
// Replace all punctuation marks with a hyph... | [
"func",
"generateCustomID",
"(",
"title",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"title",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// regex selects only the alp... | // generateCustomID generates a custom ID that is used to reference the proposals
// from the frontend. The ID generated from the title by having all its
// punctuation marks replaced with a hyphen and the string converted to lowercase.
// According to Politeia, a proposal title has a max length of 80 characters thus
/... | [
"generateCustomID",
"generates",
"a",
"custom",
"ID",
"that",
"is",
"used",
"to",
"reference",
"the",
"proposals",
"from",
"the",
"frontend",
".",
"The",
"ID",
"generated",
"from",
"the",
"title",
"by",
"having",
"all",
"its",
"punctuation",
"marks",
"replaced... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/politeia/proposals.go#L130-L142 |
142,189 | decred/dcrdata | gov/politeia/proposals.go | saveProposals | func (db *ProposalDB) saveProposals(URLParams string) (int, error) {
copyURLParams := URLParams
pageSize := int(piapi.ProposalListPageSize)
var publicProposals pitypes.Proposals
// Since Politeia sets page the limit as piapi.ProposalListPageSize, keep
// fetching the proposals till the count of fetched proposals ... | go | func (db *ProposalDB) saveProposals(URLParams string) (int, error) {
copyURLParams := URLParams
pageSize := int(piapi.ProposalListPageSize)
var publicProposals pitypes.Proposals
// Since Politeia sets page the limit as piapi.ProposalListPageSize, keep
// fetching the proposals till the count of fetched proposals ... | [
"func",
"(",
"db",
"*",
"ProposalDB",
")",
"saveProposals",
"(",
"URLParams",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"copyURLParams",
":=",
"URLParams",
"\n",
"pageSize",
":=",
"int",
"(",
"piapi",
".",
"ProposalListPageSize",
")",
"\n",
"var",... | // saveProposals adds the proposals data to the db. | [
"saveProposals",
"adds",
"the",
"proposals",
"data",
"to",
"the",
"db",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/politeia/proposals.go#L145-L211 |
142,190 | decred/dcrdata | gov/politeia/proposals.go | AllProposals | func (db *ProposalDB) AllProposals(offset, rowsCount int,
filterByVoteStatus ...int) (proposals []*pitypes.ProposalInfo,
totalCount int, err error) {
if db == nil || db.dbP == nil {
return nil, 0, errDef
}
db.mtx.RLock()
defer db.mtx.RUnlock()
query := db.dbP.Select()
if len(filterByVoteStatus) > 0 {
// F... | go | func (db *ProposalDB) AllProposals(offset, rowsCount int,
filterByVoteStatus ...int) (proposals []*pitypes.ProposalInfo,
totalCount int, err error) {
if db == nil || db.dbP == nil {
return nil, 0, errDef
}
db.mtx.RLock()
defer db.mtx.RUnlock()
query := db.dbP.Select()
if len(filterByVoteStatus) > 0 {
// F... | [
"func",
"(",
"db",
"*",
"ProposalDB",
")",
"AllProposals",
"(",
"offset",
",",
"rowsCount",
"int",
",",
"filterByVoteStatus",
"...",
"int",
")",
"(",
"proposals",
"[",
"]",
"*",
"pitypes",
".",
"ProposalInfo",
",",
"totalCount",
"int",
",",
"err",
"error",... | // AllProposals fetches all the proposals data saved to the db. | [
"AllProposals",
"fetches",
"all",
"the",
"proposals",
"data",
"saved",
"to",
"the",
"db",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/politeia/proposals.go#L214-L248 |
142,191 | decred/dcrdata | gov/politeia/proposals.go | ProposalByToken | func (db *ProposalDB) ProposalByToken(proposalToken string) (*pitypes.ProposalInfo, error) {
if db == nil || db.dbP == nil {
return nil, errDef
}
db.mtx.RLock()
defer db.mtx.RUnlock()
return db.proposal("TokenVal", proposalToken)
} | go | func (db *ProposalDB) ProposalByToken(proposalToken string) (*pitypes.ProposalInfo, error) {
if db == nil || db.dbP == nil {
return nil, errDef
}
db.mtx.RLock()
defer db.mtx.RUnlock()
return db.proposal("TokenVal", proposalToken)
} | [
"func",
"(",
"db",
"*",
"ProposalDB",
")",
"ProposalByToken",
"(",
"proposalToken",
"string",
")",
"(",
"*",
"pitypes",
".",
"ProposalInfo",
",",
"error",
")",
"{",
"if",
"db",
"==",
"nil",
"||",
"db",
".",
"dbP",
"==",
"nil",
"{",
"return",
"nil",
"... | // ProposalByToken returns the single proposal identified by the provided token. | [
"ProposalByToken",
"returns",
"the",
"single",
"proposal",
"identified",
"by",
"the",
"provided",
"token",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/politeia/proposals.go#L251-L260 |
142,192 | decred/dcrdata | gov/politeia/proposals.go | ProposalByRefID | func (db *ProposalDB) ProposalByRefID(RefID string) (*pitypes.ProposalInfo, error) {
if db == nil || db.dbP == nil {
return nil, errDef
}
db.mtx.RLock()
defer db.mtx.RUnlock()
return db.proposal("RefID", RefID)
} | go | func (db *ProposalDB) ProposalByRefID(RefID string) (*pitypes.ProposalInfo, error) {
if db == nil || db.dbP == nil {
return nil, errDef
}
db.mtx.RLock()
defer db.mtx.RUnlock()
return db.proposal("RefID", RefID)
} | [
"func",
"(",
"db",
"*",
"ProposalDB",
")",
"ProposalByRefID",
"(",
"RefID",
"string",
")",
"(",
"*",
"pitypes",
".",
"ProposalInfo",
",",
"error",
")",
"{",
"if",
"db",
"==",
"nil",
"||",
"db",
".",
"dbP",
"==",
"nil",
"{",
"return",
"nil",
",",
"e... | // ProposalByRefID returns the single proposal identified by the provided refID.
// RefID is generated from the proposal name and used as the descriptive part of
// the URL to proposal details page on the | [
"ProposalByRefID",
"returns",
"the",
"single",
"proposal",
"identified",
"by",
"the",
"provided",
"refID",
".",
"RefID",
"is",
"generated",
"from",
"the",
"proposal",
"name",
"and",
"used",
"as",
"the",
"descriptive",
"part",
"of",
"the",
"URL",
"to",
"proposa... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/politeia/proposals.go#L265-L274 |
142,193 | decred/dcrdata | gov/politeia/proposals.go | proposal | func (db *ProposalDB) proposal(searchBy, searchTerm string) (*pitypes.ProposalInfo, error) {
var pInfo pitypes.ProposalInfo
err := db.dbP.Select(q.Eq(searchBy, searchTerm)).Limit(1).First(&pInfo)
if err != nil {
log.Errorf("Failed to fetch data from Proposals DB: %v", err)
return nil, err
}
return &pInfo, nil... | go | func (db *ProposalDB) proposal(searchBy, searchTerm string) (*pitypes.ProposalInfo, error) {
var pInfo pitypes.ProposalInfo
err := db.dbP.Select(q.Eq(searchBy, searchTerm)).Limit(1).First(&pInfo)
if err != nil {
log.Errorf("Failed to fetch data from Proposals DB: %v", err)
return nil, err
}
return &pInfo, nil... | [
"func",
"(",
"db",
"*",
"ProposalDB",
")",
"proposal",
"(",
"searchBy",
",",
"searchTerm",
"string",
")",
"(",
"*",
"pitypes",
".",
"ProposalInfo",
",",
"error",
")",
"{",
"var",
"pInfo",
"pitypes",
".",
"ProposalInfo",
"\n",
"err",
":=",
"db",
".",
"d... | // proposal runs the query with searchBy and searchTerm parameters provided and
// returns the result. | [
"proposal",
"runs",
"the",
"query",
"with",
"searchBy",
"and",
"searchTerm",
"parameters",
"provided",
"and",
"returns",
"the",
"result",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/politeia/proposals.go#L278-L287 |
142,194 | decred/dcrdata | gov/politeia/proposals.go | LastProposalsSync | func (db *ProposalDB) LastProposalsSync() int64 {
db.mtx.Lock()
defer db.mtx.Unlock()
return db.lastSync
} | go | func (db *ProposalDB) LastProposalsSync() int64 {
db.mtx.Lock()
defer db.mtx.Unlock()
return db.lastSync
} | [
"func",
"(",
"db",
"*",
"ProposalDB",
")",
"LastProposalsSync",
"(",
")",
"int64",
"{",
"db",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"db",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"db",
".",
"lastSync",
"\n",
"}"
] | // LastProposalsSync returns the last time a sync to update the proposals was run
// but not necessarily the last time updates were synced in proposals.db. | [
"LastProposalsSync",
"returns",
"the",
"last",
"time",
"a",
"sync",
"to",
"update",
"the",
"proposals",
"was",
"run",
"but",
"not",
"necessarily",
"the",
"last",
"time",
"updates",
"were",
"synced",
"in",
"proposals",
".",
"db",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/politeia/proposals.go#L291-L296 |
142,195 | decred/dcrdata | gov/politeia/proposals.go | CheckProposalsUpdates | func (db *ProposalDB) CheckProposalsUpdates() error {
if db == nil || db.dbP == nil {
return errDef
}
db.mtx.Lock()
defer func() {
// Update the lastSync before the function exits.
db.lastSync = time.Now().UTC().Unix()
db.mtx.Unlock()
}()
// Retrieve and update all current proposals whose vote statuses... | go | func (db *ProposalDB) CheckProposalsUpdates() error {
if db == nil || db.dbP == nil {
return errDef
}
db.mtx.Lock()
defer func() {
// Update the lastSync before the function exits.
db.lastSync = time.Now().UTC().Unix()
db.mtx.Unlock()
}()
// Retrieve and update all current proposals whose vote statuses... | [
"func",
"(",
"db",
"*",
"ProposalDB",
")",
"CheckProposalsUpdates",
"(",
")",
"error",
"{",
"if",
"db",
"==",
"nil",
"||",
"db",
".",
"dbP",
"==",
"nil",
"{",
"return",
"errDef",
"\n",
"}",
"\n\n",
"db",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"... | // CheckProposalsUpdates updates the proposal changes if they exist and updates
// them to the proposal db. | [
"CheckProposalsUpdates",
"updates",
"the",
"proposal",
"changes",
"if",
"they",
"exist",
"and",
"updates",
"them",
"to",
"the",
"proposal",
"db",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/politeia/proposals.go#L300-L343 |
142,196 | decred/dcrdata | gov/politeia/proposals.go | updateInProgressProposals | func (db *ProposalDB) updateInProgressProposals() (int, error) {
// statuses defines a list of vote statuses whose proposals may need an update.
statuses := []pitypes.VoteStatusType{
pitypes.VoteStatusType(piapi.PropVoteStatusNotAuthorized),
pitypes.VoteStatusType(piapi.PropVoteStatusAuthorized),
pitypes.VoteSt... | go | func (db *ProposalDB) updateInProgressProposals() (int, error) {
// statuses defines a list of vote statuses whose proposals may need an update.
statuses := []pitypes.VoteStatusType{
pitypes.VoteStatusType(piapi.PropVoteStatusNotAuthorized),
pitypes.VoteStatusType(piapi.PropVoteStatusAuthorized),
pitypes.VoteSt... | [
"func",
"(",
"db",
"*",
"ProposalDB",
")",
"updateInProgressProposals",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"// statuses defines a list of vote statuses whose proposals may need an update.",
"statuses",
":=",
"[",
"]",
"pitypes",
".",
"VoteStatusType",
"{",
... | // Proposals whose vote statuses are either NotAuthorized, Authorized or Started
// are considered to be in progress. Data for the in progress proposals is
// fetched from Politeia API. From the newly fetched proposals data, db update
// is only made for the vote statuses without NotAuthorized status out of all
// the ... | [
"Proposals",
"whose",
"vote",
"statuses",
"are",
"either",
"NotAuthorized",
"Authorized",
"or",
"Started",
"are",
"considered",
"to",
"be",
"in",
"progress",
".",
"Data",
"for",
"the",
"in",
"progress",
"proposals",
"is",
"fetched",
"from",
"Politeia",
"API",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/gov/politeia/proposals.go#L355-L414 |
142,197 | decred/dcrdata | db/dcrpg/system.go | parseUnit | func parseUnit(unit string) (multiple float64, baseUnit string, err error) {
// This regular expression is defined so that it will match any input.
re := regexp.MustCompile(`([-\d\.]*)\s*(.*)`)
matches := re.FindStringSubmatch(unit)
// One or more of the matched substrings may be "", but the base unit
// substring... | go | func parseUnit(unit string) (multiple float64, baseUnit string, err error) {
// This regular expression is defined so that it will match any input.
re := regexp.MustCompile(`([-\d\.]*)\s*(.*)`)
matches := re.FindStringSubmatch(unit)
// One or more of the matched substrings may be "", but the base unit
// substring... | [
"func",
"parseUnit",
"(",
"unit",
"string",
")",
"(",
"multiple",
"float64",
",",
"baseUnit",
"string",
",",
"err",
"error",
")",
"{",
"// This regular expression is defined so that it will match any input.",
"re",
":=",
"regexp",
".",
"MustCompile",
"(",
"`([-\\d\\.]... | // parseUnit is used to separate a "unit" from pg_settings such as "8kB" into a
// numeric component and a base unit string. | [
"parseUnit",
"is",
"used",
"to",
"separate",
"a",
"unit",
"from",
"pg_settings",
"such",
"as",
"8kB",
"into",
"a",
"numeric",
"component",
"and",
"a",
"base",
"unit",
"string",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/system.go#L19-L51 |
142,198 | decred/dcrdata | db/dcrpg/system.go | RetrievePGVersion | func RetrievePGVersion(db *sql.DB) (ver string, err error) {
err = db.QueryRow(internal.RetrievePGVersion).Scan(&ver)
return
} | go | func RetrievePGVersion(db *sql.DB) (ver string, err error) {
err = db.QueryRow(internal.RetrievePGVersion).Scan(&ver)
return
} | [
"func",
"RetrievePGVersion",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"ver",
"string",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"internal",
".",
"RetrievePGVersion",
")",
".",
"Scan",
"(",
"&",
"ver",
")",
"\n",
"re... | // RetrievePGVersion retrieves the version of the connected PostgreSQL server. | [
"RetrievePGVersion",
"retrieves",
"the",
"version",
"of",
"the",
"connected",
"PostgreSQL",
"server",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/system.go#L145-L148 |
142,199 | decred/dcrdata | db/dcrpg/system.go | RetrieveSysSettingsPerformance | func RetrieveSysSettingsPerformance(db *sql.DB) (PGSettings, error) {
return retrieveSysSettings(internal.RetrieveSysSettingsPerformance, db)
} | go | func RetrieveSysSettingsPerformance(db *sql.DB) (PGSettings, error) {
return retrieveSysSettings(internal.RetrieveSysSettingsPerformance, db)
} | [
"func",
"RetrieveSysSettingsPerformance",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"PGSettings",
",",
"error",
")",
"{",
"return",
"retrieveSysSettings",
"(",
"internal",
".",
"RetrieveSysSettingsPerformance",
",",
"db",
")",
"\n",
"}"
] | // RetrieveSysSettingsPerformance retrieves performance-related settings. | [
"RetrieveSysSettingsPerformance",
"retrieves",
"performance",
"-",
"related",
"settings",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/system.go#L207-L209 |
Subsets and Splits
SQL Console for google/code_x_glue_ct_code_to_text
This query implements a thoughtful three-tier curation strategy to build a balanced safety dataset, categorizing code by destructive operations, safe I/O operations, and pure computational negatives with subsampling—revealing important patterns about how destructive intent manifests in Python code for model safety research.
SQL Console for google/code_x_glue_ct_code_to_text
This query performs meaningful classification of Python code samples into safety-relevant tiers based on destructive operations, I/O patterns, and pure computation, which could be valuable for building safety classifiers or curating training data, though the output itself is a filtered/ranked dataset rather than revealing novel statistical insights.