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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
19,600 | decred/dcrdata | db/dbtypes/types.go | UnmarshalJSON | func (a *AgendaStatusType) UnmarshalJSON(b []byte) error {
var str string
if err := json.Unmarshal(b, &str); err != nil {
return err
}
*a = AgendaStatusFromStr(str)
return nil
} | go | func (a *AgendaStatusType) UnmarshalJSON(b []byte) error {
var str string
if err := json.Unmarshal(b, &str); err != nil {
return err
}
*a = AgendaStatusFromStr(str)
return nil
} | [
"func",
"(",
"a",
"*",
"AgendaStatusType",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"str",
"string",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"str",
")",
";",
"err",
"!=",
"nil",
"{... | // UnmarshalJSON is the default unmarshaller for AgendaStatusType. | [
"UnmarshalJSON",
"is",
"the",
"default",
"unmarshaller",
"for",
"AgendaStatusType",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L232-L239 |
19,601 | decred/dcrdata | db/dbtypes/types.go | AgendaStatusFromStr | func AgendaStatusFromStr(status string) AgendaStatusType {
switch strings.ToLower(status) {
case "defined", "upcoming":
return InitialAgendaStatus
case "started", "in progress":
return StartedAgendaStatus
case "failed":
return FailedAgendaStatus
case "lockedin", "locked in":
return LockedInAgendaStatus
ca... | go | func AgendaStatusFromStr(status string) AgendaStatusType {
switch strings.ToLower(status) {
case "defined", "upcoming":
return InitialAgendaStatus
case "started", "in progress":
return StartedAgendaStatus
case "failed":
return FailedAgendaStatus
case "lockedin", "locked in":
return LockedInAgendaStatus
ca... | [
"func",
"AgendaStatusFromStr",
"(",
"status",
"string",
")",
"AgendaStatusType",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"status",
")",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"InitialAgendaStatus",
"\n",
"case",
"\"",
"\"",
",",
"\... | // AgendaStatusFromStr creates an agenda status from a string. If "UnknownStatus"
// is returned then an invalid status string has been passed. | [
"AgendaStatusFromStr",
"creates",
"an",
"agenda",
"status",
"from",
"a",
"string",
".",
"If",
"UnknownStatus",
"is",
"returned",
"then",
"an",
"invalid",
"status",
"string",
"has",
"been",
"passed",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L243-L258 |
19,602 | decred/dcrdata | db/dbtypes/types.go | IsMerged | func (a AddrTxnViewType) IsMerged() (bool, error) {
switch a {
case AddrTxnAll, AddrTxnCredit, AddrTxnDebit:
return false, nil
case AddrMergedTxn, AddrMergedTxnCredit, AddrMergedTxnDebit:
return true, nil
default:
return false, fmt.Errorf("unrecognized address transaction view: %v", a)
}
} | go | func (a AddrTxnViewType) IsMerged() (bool, error) {
switch a {
case AddrTxnAll, AddrTxnCredit, AddrTxnDebit:
return false, nil
case AddrMergedTxn, AddrMergedTxnCredit, AddrMergedTxnDebit:
return true, nil
default:
return false, fmt.Errorf("unrecognized address transaction view: %v", a)
}
} | [
"func",
"(",
"a",
"AddrTxnViewType",
")",
"IsMerged",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"switch",
"a",
"{",
"case",
"AddrTxnAll",
",",
"AddrTxnCredit",
",",
"AddrTxnDebit",
":",
"return",
"false",
",",
"nil",
"\n",
"case",
"AddrMergedTxn",
"... | // IsMerged indicates if the address transactions view type is a merged view. If
// the type is invalid, a non-nil error is returned. | [
"IsMerged",
"indicates",
"if",
"the",
"address",
"transactions",
"view",
"type",
"is",
"a",
"merged",
"view",
".",
"If",
"the",
"type",
"is",
"invalid",
"a",
"non",
"-",
"nil",
"error",
"is",
"returned",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L291-L300 |
19,603 | decred/dcrdata | db/dbtypes/types.go | AddrTxnViewTypeFromStr | func AddrTxnViewTypeFromStr(txnType string) AddrTxnViewType {
txnType = strings.ToLower(txnType)
switch txnType {
case "all":
return AddrTxnAll
case "credit", "credits":
return AddrTxnCredit
case "debit", "debits":
return AddrTxnDebit
case "merged_debit", "merged debit":
return AddrMergedTxnDebit
case "m... | go | func AddrTxnViewTypeFromStr(txnType string) AddrTxnViewType {
txnType = strings.ToLower(txnType)
switch txnType {
case "all":
return AddrTxnAll
case "credit", "credits":
return AddrTxnCredit
case "debit", "debits":
return AddrTxnDebit
case "merged_debit", "merged debit":
return AddrMergedTxnDebit
case "m... | [
"func",
"AddrTxnViewTypeFromStr",
"(",
"txnType",
"string",
")",
"AddrTxnViewType",
"{",
"txnType",
"=",
"strings",
".",
"ToLower",
"(",
"txnType",
")",
"\n",
"switch",
"txnType",
"{",
"case",
"\"",
"\"",
":",
"return",
"AddrTxnAll",
"\n",
"case",
"\"",
"\""... | // AddrTxnViewTypeFromStr attempts to decode a string into an AddrTxnViewType. | [
"AddrTxnViewTypeFromStr",
"attempts",
"to",
"decode",
"a",
"string",
"into",
"an",
"AddrTxnViewType",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L303-L321 |
19,604 | decred/dcrdata | db/dbtypes/types.go | TimeGroupingFromStr | func TimeGroupingFromStr(groupings string) TimeBasedGrouping {
switch strings.ToLower(groupings) {
case "all":
return AllGrouping
case "yr", "year", "years":
return YearGrouping
case "mo", "month", "months":
return MonthGrouping
case "wk", "week", "weeks":
return WeekGrouping
case "day", "days":
return ... | go | func TimeGroupingFromStr(groupings string) TimeBasedGrouping {
switch strings.ToLower(groupings) {
case "all":
return AllGrouping
case "yr", "year", "years":
return YearGrouping
case "mo", "month", "months":
return MonthGrouping
case "wk", "week", "weeks":
return WeekGrouping
case "day", "days":
return ... | [
"func",
"TimeGroupingFromStr",
"(",
"groupings",
"string",
")",
"TimeBasedGrouping",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"groupings",
")",
"{",
"case",
"\"",
"\"",
":",
"return",
"AllGrouping",
"\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"... | // TimeGroupingFromStr converts groupings string to its respective TimeBasedGrouping value. | [
"TimeGroupingFromStr",
"converts",
"groupings",
"string",
"to",
"its",
"respective",
"TimeBasedGrouping",
"value",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L411-L426 |
19,605 | decred/dcrdata | db/dbtypes/types.go | ChoiceIndexFromStr | func ChoiceIndexFromStr(choice string) (VoteChoice, error) {
switch choice {
case "abstain":
return Abstain, nil
case "yes":
return Yes, nil
case "no":
return No, nil
default:
return VoteChoiceUnknown, fmt.Errorf(`Vote Choice "%s" is unknown`, choice)
}
} | go | func ChoiceIndexFromStr(choice string) (VoteChoice, error) {
switch choice {
case "abstain":
return Abstain, nil
case "yes":
return Yes, nil
case "no":
return No, nil
default:
return VoteChoiceUnknown, fmt.Errorf(`Vote Choice "%s" is unknown`, choice)
}
} | [
"func",
"ChoiceIndexFromStr",
"(",
"choice",
"string",
")",
"(",
"VoteChoice",
",",
"error",
")",
"{",
"switch",
"choice",
"{",
"case",
"\"",
"\"",
":",
"return",
"Abstain",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"Yes",
",",
"nil",
"\n",
... | // ChoiceIndexFromStr converts the vote choice string to a vote choice index. | [
"ChoiceIndexFromStr",
"converts",
"the",
"vote",
"choice",
"string",
"to",
"a",
"vote",
"choice",
"index",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L488-L499 |
19,606 | decred/dcrdata | db/dbtypes/types.go | Value | func (p VinTxPropertyARRAY) Value() (driver.Value, error) {
j, err := json.Marshal(p)
return j, err
} | go | func (p VinTxPropertyARRAY) Value() (driver.Value, error) {
j, err := json.Marshal(p)
return j, err
} | [
"func",
"(",
"p",
"VinTxPropertyARRAY",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"j",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"p",
")",
"\n",
"return",
"j",
",",
"err",
"\n",
"}"
] | // Value satisfies driver.Valuer | [
"Value",
"satisfies",
"driver",
".",
"Valuer"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L585-L588 |
19,607 | decred/dcrdata | db/dbtypes/types.go | Scan | func (p *VinTxPropertyARRAY) Scan(src interface{}) error {
source, ok := src.([]byte)
if !ok {
return fmt.Errorf("scan type assertion .([]byte) failed")
}
var i interface{}
err := json.Unmarshal(source, &i)
if err != nil {
return err
}
// Set this JSONB
is, ok := i.([]interface{})
if !ok {
return fmt.... | go | func (p *VinTxPropertyARRAY) Scan(src interface{}) error {
source, ok := src.([]byte)
if !ok {
return fmt.Errorf("scan type assertion .([]byte) failed")
}
var i interface{}
err := json.Unmarshal(source, &i)
if err != nil {
return err
}
// Set this JSONB
is, ok := i.([]interface{})
if !ok {
return fmt.... | [
"func",
"(",
"p",
"*",
"VinTxPropertyARRAY",
")",
"Scan",
"(",
"src",
"interface",
"{",
"}",
")",
"error",
"{",
"source",
",",
"ok",
":=",
"src",
".",
"(",
"[",
"]",
"byte",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
... | // Scan satisfies sql.Scanner | [
"Scan",
"satisfies",
"sql",
".",
"Scanner"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L591-L624 |
19,608 | decred/dcrdata | db/dbtypes/types.go | String | func (s DeletionSummary) String() string {
summary := fmt.Sprintf("%9d Blocks purged\n", s.Blocks)
summary += fmt.Sprintf("%9d Vins purged\n", s.Vins)
summary += fmt.Sprintf("%9d Vouts purged\n", s.Vouts)
summary += fmt.Sprintf("%9d Addresses purged\n", s.Addresses)
summary += fmt.Sprintf("%9d Transactions purged\... | go | func (s DeletionSummary) String() string {
summary := fmt.Sprintf("%9d Blocks purged\n", s.Blocks)
summary += fmt.Sprintf("%9d Vins purged\n", s.Vins)
summary += fmt.Sprintf("%9d Vouts purged\n", s.Vouts)
summary += fmt.Sprintf("%9d Addresses purged\n", s.Addresses)
summary += fmt.Sprintf("%9d Transactions purged\... | [
"func",
"(",
"s",
"DeletionSummary",
")",
"String",
"(",
")",
"string",
"{",
"summary",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"s",
".",
"Blocks",
")",
"\n",
"summary",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
... | // String makes a pretty summary of the totals. | [
"String",
"makes",
"a",
"pretty",
"summary",
"of",
"the",
"totals",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L634-L644 |
19,609 | decred/dcrdata | db/dbtypes/types.go | Reduce | func (ds DeletionSummarySlice) Reduce() DeletionSummary {
var s DeletionSummary
for i := range ds {
s.Blocks += ds[i].Blocks
s.Vins += ds[i].Vins
s.Vouts += ds[i].Vouts
s.Addresses += ds[i].Addresses
s.Transactions += ds[i].Transactions
s.Tickets += ds[i].Tickets
s.Votes += ds[i].Votes
s.Misses += ds[... | go | func (ds DeletionSummarySlice) Reduce() DeletionSummary {
var s DeletionSummary
for i := range ds {
s.Blocks += ds[i].Blocks
s.Vins += ds[i].Vins
s.Vouts += ds[i].Vouts
s.Addresses += ds[i].Addresses
s.Transactions += ds[i].Transactions
s.Tickets += ds[i].Tickets
s.Votes += ds[i].Votes
s.Misses += ds[... | [
"func",
"(",
"ds",
"DeletionSummarySlice",
")",
"Reduce",
"(",
")",
"DeletionSummary",
"{",
"var",
"s",
"DeletionSummary",
"\n",
"for",
"i",
":=",
"range",
"ds",
"{",
"s",
".",
"Blocks",
"+=",
"ds",
"[",
"i",
"]",
".",
"Blocks",
"\n",
"s",
".",
"Vins... | // Reduce returns a single DeletionSummary with the corresponding fields summed. | [
"Reduce",
"returns",
"a",
"single",
"DeletionSummary",
"with",
"the",
"corresponding",
"fields",
"summed",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L650-L663 |
19,610 | decred/dcrdata | db/dbtypes/types.go | ReduceAddressHistory | func ReduceAddressHistory(addrHist []*AddressRow) (*AddressInfo, float64, float64) {
if len(addrHist) == 0 {
return nil, 0, 0
}
var received, sent, fromStake, toStake int64
var transactions, creditTxns, debitTxns []*AddressTx
for _, addrOut := range addrHist {
if !addrOut.ValidMainChain {
continue
}
co... | go | func ReduceAddressHistory(addrHist []*AddressRow) (*AddressInfo, float64, float64) {
if len(addrHist) == 0 {
return nil, 0, 0
}
var received, sent, fromStake, toStake int64
var transactions, creditTxns, debitTxns []*AddressTx
for _, addrOut := range addrHist {
if !addrOut.ValidMainChain {
continue
}
co... | [
"func",
"ReduceAddressHistory",
"(",
"addrHist",
"[",
"]",
"*",
"AddressRow",
")",
"(",
"*",
"AddressInfo",
",",
"float64",
",",
"float64",
")",
"{",
"if",
"len",
"(",
"addrHist",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"0",
",",
"0",
"\n",
"}",
... | // ReduceAddressHistory generates a template AddressInfo from a slice of
// AddressRow. All fields except NumUnconfirmed and Transactions are set
// completely. Transactions is partially set, with each transaction having only
// the TxID and ReceivedTotal set. The rest of the data should be filled in by
// other means,... | [
"ReduceAddressHistory",
"generates",
"a",
"template",
"AddressInfo",
"from",
"a",
"slice",
"of",
"AddressRow",
".",
"All",
"fields",
"except",
"NumUnconfirmed",
"and",
"Transactions",
"are",
"set",
"completely",
".",
"Transactions",
"is",
"partially",
"set",
"with",... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/types.go#L1567-L1631 |
19,611 | decred/dcrdata | stakedb/chainmonitor.go | ReorgHandler | func (p *ChainMonitor) ReorgHandler() {
defer p.wg.Done()
out:
for {
//keepon:
select {
case reorgData, ok := <-p.reorgChan:
p.mtx.Lock()
if !ok {
p.mtx.Unlock()
log.Warnf("Reorg channel closed.")
break out
}
newHeight, oldHeight := reorgData.NewChainHeight, reorgData.OldChainHeight
... | go | func (p *ChainMonitor) ReorgHandler() {
defer p.wg.Done()
out:
for {
//keepon:
select {
case reorgData, ok := <-p.reorgChan:
p.mtx.Lock()
if !ok {
p.mtx.Unlock()
log.Warnf("Reorg channel closed.")
break out
}
newHeight, oldHeight := reorgData.NewChainHeight, reorgData.OldChainHeight
... | [
"func",
"(",
"p",
"*",
"ChainMonitor",
")",
"ReorgHandler",
"(",
")",
"{",
"defer",
"p",
".",
"wg",
".",
"Done",
"(",
")",
"\n",
"out",
":",
"for",
"{",
"//keepon:",
"select",
"{",
"case",
"reorgData",
",",
"ok",
":=",
"<-",
"p",
".",
"reorgChan",
... | // ReorgHandler receives notification of a chain reorganization and initiates a
// corresponding reorganization of the stakedb.StakeDatabase. | [
"ReorgHandler",
"receives",
"notification",
"of",
"a",
"chain",
"reorganization",
"and",
"initiates",
"a",
"corresponding",
"reorganization",
"of",
"the",
"stakedb",
".",
"StakeDatabase",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/stakedb/chainmonitor.go#L155-L200 |
19,612 | decred/dcrdata | api/types/apicache.go | NewAPICache | func NewAPICache(capacity uint32) *APICache {
apic := &APICache{
capacity: capacity,
blockCache: make(blockCache),
MainchainBlocks: make(map[int64]chainhash.Hash, capacity),
expireQueue: NewBlockPriorityQueue(capacity),
}
go WatchPriorityQueue(apic.expireQueue)
return apic
} | go | func NewAPICache(capacity uint32) *APICache {
apic := &APICache{
capacity: capacity,
blockCache: make(blockCache),
MainchainBlocks: make(map[int64]chainhash.Hash, capacity),
expireQueue: NewBlockPriorityQueue(capacity),
}
go WatchPriorityQueue(apic.expireQueue)
return apic
} | [
"func",
"NewAPICache",
"(",
"capacity",
"uint32",
")",
"*",
"APICache",
"{",
"apic",
":=",
"&",
"APICache",
"{",
"capacity",
":",
"capacity",
",",
"blockCache",
":",
"make",
"(",
"blockCache",
")",
",",
"MainchainBlocks",
":",
"make",
"(",
"map",
"[",
"i... | // NewAPICache creates an APICache with the specified capacity. | [
"NewAPICache",
"creates",
"an",
"APICache",
"with",
"the",
"specified",
"capacity",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L66-L77 |
19,613 | decred/dcrdata | api/types/apicache.go | Utilization | func (apic *APICache) Utilization() float64 {
apic.mtx.RLock()
defer apic.mtx.RUnlock()
return 100.0 * float64(len(apic.blockCache)) / float64(apic.capacity)
} | go | func (apic *APICache) Utilization() float64 {
apic.mtx.RLock()
defer apic.mtx.RUnlock()
return 100.0 * float64(len(apic.blockCache)) / float64(apic.capacity)
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"Utilization",
"(",
")",
"float64",
"{",
"apic",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"apic",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"100.0",
"*",
"float64",
"(",
"len",
"(",
... | // Utilization returns the percent utilization of the cache | [
"Utilization",
"returns",
"the",
"percent",
"utilization",
"of",
"the",
"cache"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L103-L107 |
19,614 | decred/dcrdata | api/types/apicache.go | StoreStakeInfo | func (apic *APICache) StoreStakeInfo(stakeInfo *StakeInfoExtended) error {
if !apic.IsEnabled() {
fmt.Printf("API cache is disabled")
return nil
}
height := stakeInfo.Feeinfo.Height
hash, err := chainhash.NewHashFromStr(stakeInfo.Hash)
if err != nil {
panic("that's not a real hash")
}
apic.mtx.Lock()
de... | go | func (apic *APICache) StoreStakeInfo(stakeInfo *StakeInfoExtended) error {
if !apic.IsEnabled() {
fmt.Printf("API cache is disabled")
return nil
}
height := stakeInfo.Feeinfo.Height
hash, err := chainhash.NewHashFromStr(stakeInfo.Hash)
if err != nil {
panic("that's not a real hash")
}
apic.mtx.Lock()
de... | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"StoreStakeInfo",
"(",
"stakeInfo",
"*",
"StakeInfoExtended",
")",
"error",
"{",
"if",
"!",
"apic",
".",
"IsEnabled",
"(",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"... | // StoreStakeInfo caches the input StakeInfoExtended, if the priority queue
// indicates that the block should be added. | [
"StoreStakeInfo",
"caches",
"the",
"input",
"StakeInfoExtended",
"if",
"the",
"priority",
"queue",
"indicates",
"that",
"the",
"block",
"should",
"be",
"added",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L176-L221 |
19,615 | decred/dcrdata | api/types/apicache.go | removeCachedBlock | func (apic *APICache) removeCachedBlock(cachedBlock *CachedBlock) {
if cachedBlock == nil {
return
}
// remove the block from the expiration queue
apic.expireQueue.RemoveBlock(cachedBlock)
// remove from block cache
if hash, err := chainhash.NewHashFromStr(cachedBlock.hash); err != nil {
delete(apic.blockCach... | go | func (apic *APICache) removeCachedBlock(cachedBlock *CachedBlock) {
if cachedBlock == nil {
return
}
// remove the block from the expiration queue
apic.expireQueue.RemoveBlock(cachedBlock)
// remove from block cache
if hash, err := chainhash.NewHashFromStr(cachedBlock.hash); err != nil {
delete(apic.blockCach... | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"removeCachedBlock",
"(",
"cachedBlock",
"*",
"CachedBlock",
")",
"{",
"if",
"cachedBlock",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"// remove the block from the expiration queue",
"apic",
".",
"expireQueue",
".",
... | // removeCachedBlock is the non-thread-safe version of RemoveCachedBlock. | [
"removeCachedBlock",
"is",
"the",
"non",
"-",
"thread",
"-",
"safe",
"version",
"of",
"RemoveCachedBlock",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L224-L235 |
19,616 | decred/dcrdata | api/types/apicache.go | RemoveCachedBlock | func (apic *APICache) RemoveCachedBlock(cachedBlock *CachedBlock) {
apic.mtx.Lock()
defer apic.mtx.Unlock()
apic.removeCachedBlock(cachedBlock)
} | go | func (apic *APICache) RemoveCachedBlock(cachedBlock *CachedBlock) {
apic.mtx.Lock()
defer apic.mtx.Unlock()
apic.removeCachedBlock(cachedBlock)
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"RemoveCachedBlock",
"(",
"cachedBlock",
"*",
"CachedBlock",
")",
"{",
"apic",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"apic",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"apic",
".",
"removeCachedBlo... | // RemoveCachedBlock removes the input CachedBlock the cache. If the block is
// not in cache, this is essentially a silent no-op. | [
"RemoveCachedBlock",
"removes",
"the",
"input",
"CachedBlock",
"the",
"cache",
".",
"If",
"the",
"block",
"is",
"not",
"in",
"cache",
"this",
"is",
"essentially",
"a",
"silent",
"no",
"-",
"op",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L239-L243 |
19,617 | decred/dcrdata | api/types/apicache.go | RemoveCachedBlockByHeight | func (apic *APICache) RemoveCachedBlockByHeight(height int64) {
apic.mtx.Lock()
defer apic.mtx.Unlock()
hash, ok := apic.MainchainBlocks[height]
if !ok {
return
}
cb := apic.getCachedBlockByHash(hash)
apic.removeCachedBlock(cb)
} | go | func (apic *APICache) RemoveCachedBlockByHeight(height int64) {
apic.mtx.Lock()
defer apic.mtx.Unlock()
hash, ok := apic.MainchainBlocks[height]
if !ok {
return
}
cb := apic.getCachedBlockByHash(hash)
apic.removeCachedBlock(cb)
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"RemoveCachedBlockByHeight",
"(",
"height",
"int64",
")",
"{",
"apic",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"apic",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"hash",
",",
"ok",
":=",
"apic",
... | // RemoveCachedBlockByHeight attempts to remove a CachedBlock with the given
// height. | [
"RemoveCachedBlockByHeight",
"attempts",
"to",
"remove",
"a",
"CachedBlock",
"with",
"the",
"given",
"height",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L247-L258 |
19,618 | decred/dcrdata | api/types/apicache.go | blockHash | func (apic *APICache) blockHash(height int64) (chainhash.Hash, bool) {
apic.mtx.RLock()
defer apic.mtx.RUnlock()
hash, ok := apic.MainchainBlocks[height]
return hash, ok
} | go | func (apic *APICache) blockHash(height int64) (chainhash.Hash, bool) {
apic.mtx.RLock()
defer apic.mtx.RUnlock()
hash, ok := apic.MainchainBlocks[height]
return hash, ok
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"blockHash",
"(",
"height",
"int64",
")",
"(",
"chainhash",
".",
"Hash",
",",
"bool",
")",
"{",
"apic",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"apic",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\... | // blockHash attempts to get the block hash for the main chain block at the
// given height. The boolean indicates a cache miss. | [
"blockHash",
"attempts",
"to",
"get",
"the",
"block",
"hash",
"for",
"the",
"main",
"chain",
"block",
"at",
"the",
"given",
"height",
".",
"The",
"boolean",
"indicates",
"a",
"cache",
"miss",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L262-L267 |
19,619 | decred/dcrdata | api/types/apicache.go | GetBlockSize | func (apic *APICache) GetBlockSize(height int64) int32 {
if !apic.IsEnabled() {
return -1
}
cachedBlock := apic.GetCachedBlockByHeight(height)
if cachedBlock != nil && cachedBlock.summary != nil {
return int32(cachedBlock.summary.Size)
}
return -1
} | go | func (apic *APICache) GetBlockSize(height int64) int32 {
if !apic.IsEnabled() {
return -1
}
cachedBlock := apic.GetCachedBlockByHeight(height)
if cachedBlock != nil && cachedBlock.summary != nil {
return int32(cachedBlock.summary.Size)
}
return -1
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"GetBlockSize",
"(",
"height",
"int64",
")",
"int32",
"{",
"if",
"!",
"apic",
".",
"IsEnabled",
"(",
")",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"cachedBlock",
":=",
"apic",
".",
"GetCachedBlockByHeight",
"... | // GetBlockSize attempts to retrieve the block size for the input height. The
// return is -1 if no block with that height is cached. | [
"GetBlockSize",
"attempts",
"to",
"retrieve",
"the",
"block",
"size",
"for",
"the",
"input",
"height",
".",
"The",
"return",
"is",
"-",
"1",
"if",
"no",
"block",
"with",
"that",
"height",
"is",
"cached",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L284-L293 |
19,620 | decred/dcrdata | api/types/apicache.go | GetBlockSummary | func (apic *APICache) GetBlockSummary(height int64) *BlockDataBasic {
if !apic.IsEnabled() {
return nil
}
cachedBlock := apic.GetCachedBlockByHeight(height)
if cachedBlock != nil {
return cachedBlock.summary
}
return nil
} | go | func (apic *APICache) GetBlockSummary(height int64) *BlockDataBasic {
if !apic.IsEnabled() {
return nil
}
cachedBlock := apic.GetCachedBlockByHeight(height)
if cachedBlock != nil {
return cachedBlock.summary
}
return nil
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"GetBlockSummary",
"(",
"height",
"int64",
")",
"*",
"BlockDataBasic",
"{",
"if",
"!",
"apic",
".",
"IsEnabled",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"cachedBlock",
":=",
"apic",
".",
"GetCachedBlock... | // GetBlockSummary attempts to retrieve the block summary for the input height.
// The return is nil if no block with that height is cached. | [
"GetBlockSummary",
"attempts",
"to",
"retrieve",
"the",
"block",
"summary",
"for",
"the",
"input",
"height",
".",
"The",
"return",
"is",
"nil",
"if",
"no",
"block",
"with",
"that",
"height",
"is",
"cached",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L297-L306 |
19,621 | decred/dcrdata | api/types/apicache.go | GetStakeInfo | func (apic *APICache) GetStakeInfo(height int64) *StakeInfoExtended {
if !apic.IsEnabled() {
return nil
}
cachedBlock := apic.GetCachedBlockByHeight(height)
if cachedBlock != nil {
return cachedBlock.stakeInfo
}
return nil
} | go | func (apic *APICache) GetStakeInfo(height int64) *StakeInfoExtended {
if !apic.IsEnabled() {
return nil
}
cachedBlock := apic.GetCachedBlockByHeight(height)
if cachedBlock != nil {
return cachedBlock.stakeInfo
}
return nil
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"GetStakeInfo",
"(",
"height",
"int64",
")",
"*",
"StakeInfoExtended",
"{",
"if",
"!",
"apic",
".",
"IsEnabled",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"cachedBlock",
":=",
"apic",
".",
"GetCachedBlock... | // GetStakeInfo attempts to retrieve the stake info for block at the the input
// height. The return is nil if no block with that height is cached. | [
"GetStakeInfo",
"attempts",
"to",
"retrieve",
"the",
"stake",
"info",
"for",
"block",
"at",
"the",
"the",
"input",
"height",
".",
"The",
"return",
"is",
"nil",
"if",
"no",
"block",
"with",
"that",
"height",
"is",
"cached",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L310-L319 |
19,622 | decred/dcrdata | api/types/apicache.go | GetStakeInfoByHash | func (apic *APICache) GetStakeInfoByHash(hash string) *StakeInfoExtended {
if !apic.IsEnabled() {
return nil
}
cachedBlock := apic.GetCachedBlockByHashStr(hash)
if cachedBlock != nil {
return cachedBlock.stakeInfo
}
return nil
} | go | func (apic *APICache) GetStakeInfoByHash(hash string) *StakeInfoExtended {
if !apic.IsEnabled() {
return nil
}
cachedBlock := apic.GetCachedBlockByHashStr(hash)
if cachedBlock != nil {
return cachedBlock.stakeInfo
}
return nil
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"GetStakeInfoByHash",
"(",
"hash",
"string",
")",
"*",
"StakeInfoExtended",
"{",
"if",
"!",
"apic",
".",
"IsEnabled",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"cachedBlock",
":=",
"apic",
".",
"GetCached... | // GetStakeInfoByHash attempts to retrieve the stake info for block with the
// input hash. The return is nil if no block with that hash is cached. | [
"GetStakeInfoByHash",
"attempts",
"to",
"retrieve",
"the",
"stake",
"info",
"for",
"block",
"with",
"the",
"input",
"hash",
".",
"The",
"return",
"is",
"nil",
"if",
"no",
"block",
"with",
"that",
"hash",
"is",
"cached",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L323-L332 |
19,623 | decred/dcrdata | api/types/apicache.go | GetCachedBlockByHeight | func (apic *APICache) GetCachedBlockByHeight(height int64) *CachedBlock {
apic.mtx.Lock()
defer apic.mtx.Unlock()
hash, ok := apic.MainchainBlocks[height]
if !ok {
return nil
}
return apic.getCachedBlockByHash(hash)
} | go | func (apic *APICache) GetCachedBlockByHeight(height int64) *CachedBlock {
apic.mtx.Lock()
defer apic.mtx.Unlock()
hash, ok := apic.MainchainBlocks[height]
if !ok {
return nil
}
return apic.getCachedBlockByHash(hash)
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"GetCachedBlockByHeight",
"(",
"height",
"int64",
")",
"*",
"CachedBlock",
"{",
"apic",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"apic",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"hash",
",",
"ok",... | // GetCachedBlockByHeight attempts to fetch a CachedBlock with the given height.
// The return is nil if no block with that height is cached. | [
"GetCachedBlockByHeight",
"attempts",
"to",
"fetch",
"a",
"CachedBlock",
"with",
"the",
"given",
"height",
".",
"The",
"return",
"is",
"nil",
"if",
"no",
"block",
"with",
"that",
"height",
"is",
"cached",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L336-L344 |
19,624 | decred/dcrdata | api/types/apicache.go | GetBlockSummaryByHash | func (apic *APICache) GetBlockSummaryByHash(hash string) *BlockDataBasic {
if !apic.IsEnabled() {
return nil
}
cachedBlock := apic.GetCachedBlockByHashStr(hash)
if cachedBlock != nil {
return cachedBlock.summary
}
return nil
} | go | func (apic *APICache) GetBlockSummaryByHash(hash string) *BlockDataBasic {
if !apic.IsEnabled() {
return nil
}
cachedBlock := apic.GetCachedBlockByHashStr(hash)
if cachedBlock != nil {
return cachedBlock.summary
}
return nil
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"GetBlockSummaryByHash",
"(",
"hash",
"string",
")",
"*",
"BlockDataBasic",
"{",
"if",
"!",
"apic",
".",
"IsEnabled",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"cachedBlock",
":=",
"apic",
".",
"GetCached... | // GetBlockSummaryByHash attempts to retrieve the block summary for the given
// block hash. The return is nil if no block with that hash is cached. | [
"GetBlockSummaryByHash",
"attempts",
"to",
"retrieve",
"the",
"block",
"summary",
"for",
"the",
"given",
"block",
"hash",
".",
"The",
"return",
"is",
"nil",
"if",
"no",
"block",
"with",
"that",
"hash",
"is",
"cached",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L348-L357 |
19,625 | decred/dcrdata | api/types/apicache.go | GetCachedBlockByHashStr | func (apic *APICache) GetCachedBlockByHashStr(hashStr string) *CachedBlock {
// Validate the hash string, and get a *chainhash.Hash
hash, err := chainhash.NewHashFromStr(hashStr)
if err != nil {
fmt.Printf("that's not a real hash!")
return nil
}
apic.mtx.Lock()
defer apic.mtx.Unlock()
return apic.getCachedB... | go | func (apic *APICache) GetCachedBlockByHashStr(hashStr string) *CachedBlock {
// Validate the hash string, and get a *chainhash.Hash
hash, err := chainhash.NewHashFromStr(hashStr)
if err != nil {
fmt.Printf("that's not a real hash!")
return nil
}
apic.mtx.Lock()
defer apic.mtx.Unlock()
return apic.getCachedB... | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"GetCachedBlockByHashStr",
"(",
"hashStr",
"string",
")",
"*",
"CachedBlock",
"{",
"// Validate the hash string, and get a *chainhash.Hash",
"hash",
",",
"err",
":=",
"chainhash",
".",
"NewHashFromStr",
"(",
"hashStr",
")",
... | // GetCachedBlockByHashStr attempts to fetch a CachedBlock with the given hash.
// The return is nil if no block with that hash is cached. | [
"GetCachedBlockByHashStr",
"attempts",
"to",
"fetch",
"a",
"CachedBlock",
"with",
"the",
"given",
"hash",
".",
"The",
"return",
"is",
"nil",
"if",
"no",
"block",
"with",
"that",
"hash",
"is",
"cached",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L361-L372 |
19,626 | decred/dcrdata | api/types/apicache.go | GetCachedBlockByHash | func (apic *APICache) GetCachedBlockByHash(hash chainhash.Hash) *CachedBlock {
// validate the chainhash.Hash
if _, err := chainhash.NewHashFromStr(hash.String()); err != nil {
fmt.Printf("that's not a real hash!")
return nil
}
apic.mtx.Lock()
defer apic.mtx.Unlock()
return apic.getCachedBlockByHash(hash)
} | go | func (apic *APICache) GetCachedBlockByHash(hash chainhash.Hash) *CachedBlock {
// validate the chainhash.Hash
if _, err := chainhash.NewHashFromStr(hash.String()); err != nil {
fmt.Printf("that's not a real hash!")
return nil
}
apic.mtx.Lock()
defer apic.mtx.Unlock()
return apic.getCachedBlockByHash(hash)
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"GetCachedBlockByHash",
"(",
"hash",
"chainhash",
".",
"Hash",
")",
"*",
"CachedBlock",
"{",
"// validate the chainhash.Hash",
"if",
"_",
",",
"err",
":=",
"chainhash",
".",
"NewHashFromStr",
"(",
"hash",
".",
"String... | // GetCachedBlockByHash attempts to fetch a CachedBlock with the given hash. The
// return is nil if no block with that hash is cached. | [
"GetCachedBlockByHash",
"attempts",
"to",
"fetch",
"a",
"CachedBlock",
"with",
"the",
"given",
"hash",
".",
"The",
"return",
"is",
"nil",
"if",
"no",
"block",
"with",
"that",
"hash",
"is",
"cached",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L376-L386 |
19,627 | decred/dcrdata | api/types/apicache.go | getCachedBlockByHash | func (apic *APICache) getCachedBlockByHash(hash chainhash.Hash) *CachedBlock {
cachedBlock, ok := apic.blockCache[hash]
if ok {
cachedBlock.Access()
apic.expireQueue.setNeedsReheap(true)
apic.expireQueue.setAccessTime(time.Now())
apic.hits++
return cachedBlock
}
apic.misses++
return nil
} | go | func (apic *APICache) getCachedBlockByHash(hash chainhash.Hash) *CachedBlock {
cachedBlock, ok := apic.blockCache[hash]
if ok {
cachedBlock.Access()
apic.expireQueue.setNeedsReheap(true)
apic.expireQueue.setAccessTime(time.Now())
apic.hits++
return cachedBlock
}
apic.misses++
return nil
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"getCachedBlockByHash",
"(",
"hash",
"chainhash",
".",
"Hash",
")",
"*",
"CachedBlock",
"{",
"cachedBlock",
",",
"ok",
":=",
"apic",
".",
"blockCache",
"[",
"hash",
"]",
"\n",
"if",
"ok",
"{",
"cachedBlock",
"."... | // getCachedBlockByHash retrieves the block with the given hash, or nil if it is
// not found. Successful retrieval will update the cached block's access time,
// and increment the block's access count. This function is not thread-safe. See
// GetCachedBlockByHash and GetCachedBlockByHashStr for thread safety and hash
... | [
"getCachedBlockByHash",
"retrieves",
"the",
"block",
"with",
"the",
"given",
"hash",
"or",
"nil",
"if",
"it",
"is",
"not",
"found",
".",
"Successful",
"retrieval",
"will",
"update",
"the",
"cached",
"block",
"s",
"access",
"time",
"and",
"increment",
"the",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L393-L404 |
19,628 | decred/dcrdata | api/types/apicache.go | IsEnabled | func (apic *APICache) IsEnabled() bool {
enabled, ok := apic.isEnabled.Load().(bool)
return ok && enabled
} | go | func (apic *APICache) IsEnabled() bool {
enabled, ok := apic.isEnabled.Load().(bool)
return ok && enabled
} | [
"func",
"(",
"apic",
"*",
"APICache",
")",
"IsEnabled",
"(",
")",
"bool",
"{",
"enabled",
",",
"ok",
":=",
"apic",
".",
"isEnabled",
".",
"Load",
"(",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"ok",
"&&",
"enabled",
"\n",
"}"
] | // IsEnabled checks if the cache is enabled. | [
"IsEnabled",
"checks",
"if",
"the",
"cache",
"is",
"enabled",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L417-L420 |
19,629 | decred/dcrdata | api/types/apicache.go | newCachedBlock | func newCachedBlock(summary *BlockDataBasic, stakeInfo *StakeInfoExtended) *CachedBlock {
if summary == nil && stakeInfo == nil {
return nil
}
height, hash, mismatch := checkBlockHeightHash(&cachedBlockData{
blockSummary: summary,
stakeInfo: stakeInfo,
})
if mismatch {
return nil
}
return &CachedBlo... | go | func newCachedBlock(summary *BlockDataBasic, stakeInfo *StakeInfoExtended) *CachedBlock {
if summary == nil && stakeInfo == nil {
return nil
}
height, hash, mismatch := checkBlockHeightHash(&cachedBlockData{
blockSummary: summary,
stakeInfo: stakeInfo,
})
if mismatch {
return nil
}
return &CachedBlo... | [
"func",
"newCachedBlock",
"(",
"summary",
"*",
"BlockDataBasic",
",",
"stakeInfo",
"*",
"StakeInfoExtended",
")",
"*",
"CachedBlock",
"{",
"if",
"summary",
"==",
"nil",
"&&",
"stakeInfo",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"height",
",",
... | // newCachedBlock wraps the given BlockDataBasic in a CachedBlock with no
// accesses and an invalid heap index. Use Access to set the access counter and
// time. The priority queue will set the heapIdx. | [
"newCachedBlock",
"wraps",
"the",
"given",
"BlockDataBasic",
"in",
"a",
"CachedBlock",
"with",
"no",
"accesses",
"and",
"an",
"invalid",
"heap",
"index",
".",
"Use",
"Access",
"to",
"set",
"the",
"access",
"counter",
"and",
"time",
".",
"The",
"priority",
"q... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L430-L450 |
19,630 | decred/dcrdata | api/types/apicache.go | Access | func (b *CachedBlock) Access() *BlockDataBasic {
b.accesses++
b.accessTime = time.Now().UnixNano()
return b.summary
} | go | func (b *CachedBlock) Access() *BlockDataBasic {
b.accesses++
b.accessTime = time.Now().UnixNano()
return b.summary
} | [
"func",
"(",
"b",
"*",
"CachedBlock",
")",
"Access",
"(",
")",
"*",
"BlockDataBasic",
"{",
"b",
".",
"accesses",
"++",
"\n",
"b",
".",
"accessTime",
"=",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
"\n",
"return",
"b",
".",
"summary",
... | // Access increments the access count and sets the accessTime to now. The
// BlockDataBasic stored in the CachedBlock is returned. | [
"Access",
"increments",
"the",
"access",
"count",
"and",
"sets",
"the",
"accessTime",
"to",
"now",
".",
"The",
"BlockDataBasic",
"stored",
"in",
"the",
"CachedBlock",
"is",
"returned",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L454-L458 |
19,631 | decred/dcrdata | api/types/apicache.go | LessByAccessCountThenHeight | func LessByAccessCountThenHeight(bi, bj *CachedBlock) bool {
if bi.accesses == bj.accesses {
return LessByHeight(bi, bj)
}
return LessByAccessCount(bi, bj)
} | go | func LessByAccessCountThenHeight(bi, bj *CachedBlock) bool {
if bi.accesses == bj.accesses {
return LessByHeight(bi, bj)
}
return LessByAccessCount(bi, bj)
} | [
"func",
"LessByAccessCountThenHeight",
"(",
"bi",
",",
"bj",
"*",
"CachedBlock",
")",
"bool",
"{",
"if",
"bi",
".",
"accesses",
"==",
"bj",
".",
"accesses",
"{",
"return",
"LessByHeight",
"(",
"bi",
",",
"bj",
")",
"\n",
"}",
"\n",
"return",
"LessByAcces... | // LessByAccessCountThenHeight compares access count with LessByAccessCount if
// the blocks have different accessTime values, otherwise it compares height
// with LessByHeight. | [
"LessByAccessCountThenHeight",
"compares",
"access",
"count",
"with",
"LessByAccessCount",
"if",
"the",
"blocks",
"have",
"different",
"accessTime",
"values",
"otherwise",
"it",
"compares",
"height",
"with",
"LessByHeight",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L550-L555 |
19,632 | decred/dcrdata | api/types/apicache.go | MakeLessByAccessTimeThenCount | func MakeLessByAccessTimeThenCount(millisecondsBinned int64) func(bi, bj *CachedBlock) bool {
millisecondThreshold := time.Duration(millisecondsBinned) * time.Millisecond
return func(bi, bj *CachedBlock) bool {
// higher priority is more recent (larger) access time
epochDiff := (bi.accessTime - bj.accessTime) / i... | go | func MakeLessByAccessTimeThenCount(millisecondsBinned int64) func(bi, bj *CachedBlock) bool {
millisecondThreshold := time.Duration(millisecondsBinned) * time.Millisecond
return func(bi, bj *CachedBlock) bool {
// higher priority is more recent (larger) access time
epochDiff := (bi.accessTime - bj.accessTime) / i... | [
"func",
"MakeLessByAccessTimeThenCount",
"(",
"millisecondsBinned",
"int64",
")",
"func",
"(",
"bi",
",",
"bj",
"*",
"CachedBlock",
")",
"bool",
"{",
"millisecondThreshold",
":=",
"time",
".",
"Duration",
"(",
"millisecondsBinned",
")",
"*",
"time",
".",
"Millis... | // MakeLessByAccessTimeThenCount will create a CachedBlock comparison function
// given the specified time resolution in milliseconds. Two access times less than
// the given time apart are considered the same time, and access count is used
// to break the tie. | [
"MakeLessByAccessTimeThenCount",
"will",
"create",
"a",
"CachedBlock",
"comparison",
"function",
"given",
"the",
"specified",
"time",
"resolution",
"in",
"milliseconds",
".",
"Two",
"access",
"times",
"less",
"than",
"the",
"given",
"time",
"apart",
"are",
"consider... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L561-L572 |
19,633 | decred/dcrdata | api/types/apicache.go | UpdateBlock | func (pq *BlockPriorityQueue) UpdateBlock(b *CachedBlock, summary *BlockDataBasic, stakeInfo *StakeInfoExtended) {
if b != nil {
heightAdded, hash, mismatch := checkBlockHeightHash(&cachedBlockData{
blockSummary: summary,
stakeInfo: stakeInfo,
})
if mismatch {
fmt.Println("Cannot UpdateBlock!")
re... | go | func (pq *BlockPriorityQueue) UpdateBlock(b *CachedBlock, summary *BlockDataBasic, stakeInfo *StakeInfoExtended) {
if b != nil {
heightAdded, hash, mismatch := checkBlockHeightHash(&cachedBlockData{
blockSummary: summary,
stakeInfo: stakeInfo,
})
if mismatch {
fmt.Println("Cannot UpdateBlock!")
re... | [
"func",
"(",
"pq",
"*",
"BlockPriorityQueue",
")",
"UpdateBlock",
"(",
"b",
"*",
"CachedBlock",
",",
"summary",
"*",
"BlockDataBasic",
",",
"stakeInfo",
"*",
"StakeInfoExtended",
")",
"{",
"if",
"b",
"!=",
"nil",
"{",
"heightAdded",
",",
"hash",
",",
"mism... | // UpdateBlock will update the specified CachedBlock, which must be in the
// queue. This function is NOT thread-safe. | [
"UpdateBlock",
"will",
"update",
"the",
"specified",
"CachedBlock",
"which",
"must",
"be",
"in",
"the",
"queue",
".",
"This",
"function",
"is",
"NOT",
"thread",
"-",
"safe",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L723-L745 |
19,634 | decred/dcrdata | api/types/apicache.go | RemoveBlock | func (pq *BlockPriorityQueue) RemoveBlock(b *CachedBlock) {
pq.mtx.Lock()
defer pq.mtx.Unlock()
if b != nil && b.heapIdx > 0 && b.heapIdx < pq.Len() {
// only remove the block it it is really in the queue
if pq.bh[b.heapIdx].hash == b.hash {
pq.RemoveIndex(b.heapIdx)
return
}
fmt.Printf("Tried to remo... | go | func (pq *BlockPriorityQueue) RemoveBlock(b *CachedBlock) {
pq.mtx.Lock()
defer pq.mtx.Unlock()
if b != nil && b.heapIdx > 0 && b.heapIdx < pq.Len() {
// only remove the block it it is really in the queue
if pq.bh[b.heapIdx].hash == b.hash {
pq.RemoveIndex(b.heapIdx)
return
}
fmt.Printf("Tried to remo... | [
"func",
"(",
"pq",
"*",
"BlockPriorityQueue",
")",
"RemoveBlock",
"(",
"b",
"*",
"CachedBlock",
")",
"{",
"pq",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pq",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"b",
"!=",
"nil",
"&&",
"b"... | // RemoveBlock removes the specified CachedBlock from the queue. Remember to
// remove it from the actual block cache! | [
"RemoveBlock",
"removes",
"the",
"specified",
"CachedBlock",
"from",
"the",
"queue",
".",
"Remember",
"to",
"remove",
"it",
"from",
"the",
"actual",
"block",
"cache!"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L812-L825 |
19,635 | decred/dcrdata | api/types/apicache.go | RemoveIndex | func (pq *BlockPriorityQueue) RemoveIndex(idx int) {
removedHeight := pq.bh[idx].height
heap.Remove(pq, idx)
pq.RescanMinMaxForRemove(removedHeight)
} | go | func (pq *BlockPriorityQueue) RemoveIndex(idx int) {
removedHeight := pq.bh[idx].height
heap.Remove(pq, idx)
pq.RescanMinMaxForRemove(removedHeight)
} | [
"func",
"(",
"pq",
"*",
"BlockPriorityQueue",
")",
"RemoveIndex",
"(",
"idx",
"int",
")",
"{",
"removedHeight",
":=",
"pq",
".",
"bh",
"[",
"idx",
"]",
".",
"height",
"\n",
"heap",
".",
"Remove",
"(",
"pq",
",",
"idx",
")",
"\n",
"pq",
".",
"Rescan... | // RemoveIndex removes the CachedBlock at the specified position in the heap.
// This function is NOT thread-safe. | [
"RemoveIndex",
"removes",
"the",
"CachedBlock",
"at",
"the",
"specified",
"position",
"in",
"the",
"heap",
".",
"This",
"function",
"is",
"NOT",
"thread",
"-",
"safe",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/types/apicache.go#L829-L833 |
19,636 | decred/dcrdata | mempool/collector.go | NewMempoolDataCollector | func NewMempoolDataCollector(dcrdChainSvr *rpcclient.Client, params *chaincfg.Params) *MempoolDataCollector {
return &MempoolDataCollector{
dcrdChainSvr: dcrdChainSvr,
activeChain: params,
}
} | go | func NewMempoolDataCollector(dcrdChainSvr *rpcclient.Client, params *chaincfg.Params) *MempoolDataCollector {
return &MempoolDataCollector{
dcrdChainSvr: dcrdChainSvr,
activeChain: params,
}
} | [
"func",
"NewMempoolDataCollector",
"(",
"dcrdChainSvr",
"*",
"rpcclient",
".",
"Client",
",",
"params",
"*",
"chaincfg",
".",
"Params",
")",
"*",
"MempoolDataCollector",
"{",
"return",
"&",
"MempoolDataCollector",
"{",
"dcrdChainSvr",
":",
"dcrdChainSvr",
",",
"ac... | // NewMempoolDataCollector creates a new MempoolDataCollector. | [
"NewMempoolDataCollector",
"creates",
"a",
"new",
"MempoolDataCollector",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/mempool/collector.go#L37-L42 |
19,637 | decred/dcrdata | config.go | normalizeNetworkAddress | func normalizeNetworkAddress(a, defaultHost, defaultPort string) (string, error) {
if strings.Contains(a, "://") {
return a, fmt.Errorf("Address %s contains a protocol identifier, which is not allowed", a)
}
if a == "" {
return defaultHost + ":" + defaultPort, nil
}
host, port, err := net.SplitHostPort(a)
if ... | go | func normalizeNetworkAddress(a, defaultHost, defaultPort string) (string, error) {
if strings.Contains(a, "://") {
return a, fmt.Errorf("Address %s contains a protocol identifier, which is not allowed", a)
}
if a == "" {
return defaultHost + ":" + defaultPort, nil
}
host, port, err := net.SplitHostPort(a)
if ... | [
"func",
"normalizeNetworkAddress",
"(",
"a",
",",
"defaultHost",
",",
"defaultPort",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"strings",
".",
"Contains",
"(",
"a",
",",
"\"",
"\"",
")",
"{",
"return",
"a",
",",
"fmt",
".",
"Errorf",
... | // normalizeNetworkAddress checks for a valid local network address format and
// adds default host and port if not present. Invalidates addresses that include
// a protocol identifier. | [
"normalizeNetworkAddress",
"checks",
"for",
"a",
"valid",
"local",
"network",
"address",
"format",
"and",
"adds",
"default",
"host",
"and",
"port",
"if",
"not",
"present",
".",
"Invalidates",
"addresses",
"that",
"include",
"a",
"protocol",
"identifier",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/config.go#L263-L289 |
19,638 | decred/dcrdata | config.go | validLogLevel | func validLogLevel(logLevel string) bool {
_, ok := slog.LevelFromString(logLevel)
return ok
} | go | func validLogLevel(logLevel string) bool {
_, ok := slog.LevelFromString(logLevel)
return ok
} | [
"func",
"validLogLevel",
"(",
"logLevel",
"string",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"slog",
".",
"LevelFromString",
"(",
"logLevel",
")",
"\n",
"return",
"ok",
"\n",
"}"
] | // validLogLevel returns whether or not logLevel is a valid debug log level. | [
"validLogLevel",
"returns",
"whether",
"or",
"not",
"logLevel",
"is",
"a",
"valid",
"debug",
"log",
"level",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/config.go#L292-L295 |
19,639 | decred/dcrdata | config.go | netName | func netName(chainParams *netparams.Params) string {
// The following switch is to ensure this code is not built for testnet2, as
// TestNet2 was removed entirely for dcrd 1.3.0. Compile check!
switch chainParams.Net {
case wire.TestNet3, wire.MainNet, wire.SimNet:
default:
log.Warnf("Unknown network: %s", chain... | go | func netName(chainParams *netparams.Params) string {
// The following switch is to ensure this code is not built for testnet2, as
// TestNet2 was removed entirely for dcrd 1.3.0. Compile check!
switch chainParams.Net {
case wire.TestNet3, wire.MainNet, wire.SimNet:
default:
log.Warnf("Unknown network: %s", chain... | [
"func",
"netName",
"(",
"chainParams",
"*",
"netparams",
".",
"Params",
")",
"string",
"{",
"// The following switch is to ensure this code is not built for testnet2, as",
"// TestNet2 was removed entirely for dcrd 1.3.0. Compile check!",
"switch",
"chainParams",
".",
"Net",
"{",
... | // netName returns the name used when referring to a decred network. TestNet3
// correctly returns "testnet3", but not TestNet2. This function may be removed
// after testnet2 is ancient history. | [
"netName",
"returns",
"the",
"name",
"used",
"when",
"referring",
"to",
"a",
"decred",
"network",
".",
"TestNet3",
"correctly",
"returns",
"testnet3",
"but",
"not",
"TestNet2",
".",
"This",
"function",
"may",
"be",
"removed",
"after",
"testnet2",
"is",
"ancien... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/config.go#L663-L672 |
19,640 | decred/dcrdata | db/dbtypes/conversion.go | MsgBlockToDBBlock | func MsgBlockToDBBlock(msgBlock *wire.MsgBlock, chainParams *chaincfg.Params, chainWork string) *Block {
// Create the dbtypes.Block structure
blockHeader := msgBlock.Header
// convert each transaction hash to a hex string
txHashes := msgBlock.TxHashes()
txHashStrs := make([]string, 0, len(txHashes))
for i := ra... | go | func MsgBlockToDBBlock(msgBlock *wire.MsgBlock, chainParams *chaincfg.Params, chainWork string) *Block {
// Create the dbtypes.Block structure
blockHeader := msgBlock.Header
// convert each transaction hash to a hex string
txHashes := msgBlock.TxHashes()
txHashStrs := make([]string, 0, len(txHashes))
for i := ra... | [
"func",
"MsgBlockToDBBlock",
"(",
"msgBlock",
"*",
"wire",
".",
"MsgBlock",
",",
"chainParams",
"*",
"chaincfg",
".",
"Params",
",",
"chainWork",
"string",
")",
"*",
"Block",
"{",
"// Create the dbtypes.Block structure",
"blockHeader",
":=",
"msgBlock",
".",
"Head... | // MsgBlockToDBBlock creates a dbtypes.Block from a wire.MsgBlock | [
"MsgBlockToDBBlock",
"creates",
"a",
"dbtypes",
".",
"Block",
"from",
"a",
"wire",
".",
"MsgBlock"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/conversion.go#L13-L56 |
19,641 | decred/dcrdata | db/dbtypes/conversion.go | TimeBasedGroupingToInterval | func TimeBasedGroupingToInterval(grouping TimeBasedGrouping) (float64, error) {
var hr = 3600.0
// days per month value is obtained by 365/12
var daysPerMonth = 30.416666666666668
switch grouping {
case AllGrouping:
return 1, nil
case DayGrouping:
return hr * 24, nil
case WeekGrouping:
return hr * 24 * 7... | go | func TimeBasedGroupingToInterval(grouping TimeBasedGrouping) (float64, error) {
var hr = 3600.0
// days per month value is obtained by 365/12
var daysPerMonth = 30.416666666666668
switch grouping {
case AllGrouping:
return 1, nil
case DayGrouping:
return hr * 24, nil
case WeekGrouping:
return hr * 24 * 7... | [
"func",
"TimeBasedGroupingToInterval",
"(",
"grouping",
"TimeBasedGrouping",
")",
"(",
"float64",
",",
"error",
")",
"{",
"var",
"hr",
"=",
"3600.0",
"\n",
"// days per month value is obtained by 365/12",
"var",
"daysPerMonth",
"=",
"30.416666666666668",
"\n",
"switch",... | // TimeBasedGroupingToInterval converts the TimeBasedGrouping value to an actual
// time value in seconds based on the gregorian calendar except AllGrouping that
// returns 1 while the unknownGrouping returns -1 and an error. | [
"TimeBasedGroupingToInterval",
"converts",
"the",
"TimeBasedGrouping",
"value",
"to",
"an",
"actual",
"time",
"value",
"in",
"seconds",
"based",
"on",
"the",
"gregorian",
"calendar",
"except",
"AllGrouping",
"that",
"returns",
"1",
"while",
"the",
"unknownGrouping",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/conversion.go#L61-L84 |
19,642 | decred/dcrdata | db/dbtypes/conversion.go | CalculateWindowIndex | func CalculateWindowIndex(height, stakeDiffWindowSize int64) int64 {
// A window being a group of blocks whose count is defined by
// chainParams.StakeDiffWindowSize, the first window starts from block 1 to
// block 144 instead of block 0 to block 143. To obtain the accurate window
// index value, we should add 1 t... | go | func CalculateWindowIndex(height, stakeDiffWindowSize int64) int64 {
// A window being a group of blocks whose count is defined by
// chainParams.StakeDiffWindowSize, the first window starts from block 1 to
// block 144 instead of block 0 to block 143. To obtain the accurate window
// index value, we should add 1 t... | [
"func",
"CalculateWindowIndex",
"(",
"height",
",",
"stakeDiffWindowSize",
"int64",
")",
"int64",
"{",
"// A window being a group of blocks whose count is defined by",
"// chainParams.StakeDiffWindowSize, the first window starts from block 1 to",
"// block 144 instead of block 0 to block 143... | // CalculateWindowIndex calculates the window index from the quotient of a block
// height and the chainParams.StakeDiffWindowSize. | [
"CalculateWindowIndex",
"calculates",
"the",
"window",
"index",
"from",
"the",
"quotient",
"of",
"a",
"block",
"height",
"and",
"the",
"chainParams",
".",
"StakeDiffWindowSize",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dbtypes/conversion.go#L95-L109 |
19,643 | decred/dcrdata | api/insight/socket.io.go | NewSocketServer | func NewSocketServer(newTxChan chan *NewTx, params *chaincfg.Params) (*SocketServer, error) {
server, err := socketio.NewServer(nil)
if err != nil {
apiLog.Errorf("Could not create socket.io server: %v", err)
return nil, err
}
// Each address subscription uses its own room, which has the same name as
// the a... | go | func NewSocketServer(newTxChan chan *NewTx, params *chaincfg.Params) (*SocketServer, error) {
server, err := socketio.NewServer(nil)
if err != nil {
apiLog.Errorf("Could not create socket.io server: %v", err)
return nil, err
}
// Each address subscription uses its own room, which has the same name as
// the a... | [
"func",
"NewSocketServer",
"(",
"newTxChan",
"chan",
"*",
"NewTx",
",",
"params",
"*",
"chaincfg",
".",
"Params",
")",
"(",
"*",
"SocketServer",
",",
"error",
")",
"{",
"server",
",",
"err",
":=",
"socketio",
".",
"NewServer",
"(",
"nil",
")",
"\n",
"i... | // NewSocketServer constructs a new SocketServer, registering handlers for the
// "connection", "disconnection", and "subscribe" events. | [
"NewSocketServer",
"constructs",
"a",
"new",
"SocketServer",
"registering",
"handlers",
"for",
"the",
"connection",
"disconnection",
"and",
"subscribe",
"events",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/insight/socket.io.go#L70-L138 |
19,644 | decred/dcrdata | api/insight/socket.io.go | Store | func (soc *SocketServer) Store(blockData *blockdata.BlockData, msgBlock *wire.MsgBlock) error {
apiLog.Debugf("Sending new websocket block %s", blockData.Header.Hash)
soc.BroadcastTo("inv", "block", blockData.Header.Hash)
// Since the coinbase transaction is generated by the miner, it will never
// hit mempool. It... | go | func (soc *SocketServer) Store(blockData *blockdata.BlockData, msgBlock *wire.MsgBlock) error {
apiLog.Debugf("Sending new websocket block %s", blockData.Header.Hash)
soc.BroadcastTo("inv", "block", blockData.Header.Hash)
// Since the coinbase transaction is generated by the miner, it will never
// hit mempool. It... | [
"func",
"(",
"soc",
"*",
"SocketServer",
")",
"Store",
"(",
"blockData",
"*",
"blockdata",
".",
"BlockData",
",",
"msgBlock",
"*",
"wire",
".",
"MsgBlock",
")",
"error",
"{",
"apiLog",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"blockData",
".",
"Header",
".... | // Store broadcasts the lastest block hash to the the inv room | [
"Store",
"broadcasts",
"the",
"lastest",
"block",
"hash",
"to",
"the",
"the",
"inv",
"room"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/api/insight/socket.io.go#L141-L175 |
19,645 | decred/dcrdata | explorer/explorerroutes.go | netName | func netName(chainParams *chaincfg.Params) string {
if chainParams == nil {
return "invalid"
}
if strings.HasPrefix(strings.ToLower(chainParams.Name), "testnet") {
return "Testnet"
}
return strings.Title(chainParams.Name)
} | go | func netName(chainParams *chaincfg.Params) string {
if chainParams == nil {
return "invalid"
}
if strings.HasPrefix(strings.ToLower(chainParams.Name), "testnet") {
return "Testnet"
}
return strings.Title(chainParams.Name)
} | [
"func",
"netName",
"(",
"chainParams",
"*",
"chaincfg",
".",
"Params",
")",
"string",
"{",
"if",
"chainParams",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"strings",
".",
"ToLower",
"(",
"chainParams"... | // netName returns the name used when referring to a decred network. | [
"netName",
"returns",
"the",
"name",
"used",
"when",
"referring",
"to",
"a",
"decred",
"network",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorerroutes.go#L109-L117 |
19,646 | decred/dcrdata | explorer/explorerroutes.go | StatusPage | func (exp *explorerUI) StatusPage(w http.ResponseWriter, code, message, additionalInfo string, sType expStatus) {
str, err := exp.templates.execTemplateToString("status", struct {
*CommonPageData
StatusType expStatus
Code string
Message string
AdditionalInfo string
}{
CommonPageData: ... | go | func (exp *explorerUI) StatusPage(w http.ResponseWriter, code, message, additionalInfo string, sType expStatus) {
str, err := exp.templates.execTemplateToString("status", struct {
*CommonPageData
StatusType expStatus
Code string
Message string
AdditionalInfo string
}{
CommonPageData: ... | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"StatusPage",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"code",
",",
"message",
",",
"additionalInfo",
"string",
",",
"sType",
"expStatus",
")",
"{",
"str",
",",
"err",
":=",
"exp",
".",
"templates",
".",
... | // StatusPage provides a page for displaying status messages and exception
// handling without redirecting. Be sure to return after calling StatusPage if
// this completes the processing of the calling http handler. | [
"StatusPage",
"provides",
"a",
"page",
"for",
"displaying",
"status",
"messages",
"and",
"exception",
"handling",
"without",
"redirecting",
".",
"Be",
"sure",
"to",
"return",
"after",
"calling",
"StatusPage",
"if",
"this",
"completes",
"the",
"processing",
"of",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorerroutes.go#L1541-L1583 |
19,647 | decred/dcrdata | explorer/explorerroutes.go | NotFound | func (exp *explorerUI) NotFound(w http.ResponseWriter, r *http.Request) {
exp.StatusPage(w, "Page not found.", "Cannot find page: "+r.URL.Path, "", ExpStatusNotFound)
} | go | func (exp *explorerUI) NotFound(w http.ResponseWriter, r *http.Request) {
exp.StatusPage(w, "Page not found.", "Cannot find page: "+r.URL.Path, "", ExpStatusNotFound)
} | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"NotFound",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"exp",
".",
"StatusPage",
"(",
"w",
",",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"r",
".",
"URL",
".",
"... | // NotFound wraps StatusPage to display a 404 page. | [
"NotFound",
"wraps",
"StatusPage",
"to",
"display",
"a",
"404",
"page",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorerroutes.go#L1586-L1588 |
19,648 | decred/dcrdata | explorer/explorerroutes.go | HandleApiRequestsOnSync | func (exp *explorerUI) HandleApiRequestsOnSync(w http.ResponseWriter, r *http.Request) {
var complete int
dataFetched := SyncStatus()
syncStatus := "in progress"
if len(dataFetched) == complete {
syncStatus = "complete"
}
for _, v := range dataFetched {
if v.PercentComplete == 100 {
complete++
}
}
st... | go | func (exp *explorerUI) HandleApiRequestsOnSync(w http.ResponseWriter, r *http.Request) {
var complete int
dataFetched := SyncStatus()
syncStatus := "in progress"
if len(dataFetched) == complete {
syncStatus = "complete"
}
for _, v := range dataFetched {
if v.PercentComplete == 100 {
complete++
}
}
st... | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"HandleApiRequestsOnSync",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"var",
"complete",
"int",
"\n",
"dataFetched",
":=",
"SyncStatus",
"(",
")",
"\n\n",
"syncStatu... | // HandleApiRequestsOnSync handles all API request when the sync status pages is
// running. | [
"HandleApiRequestsOnSync",
"handles",
"all",
"API",
"request",
"when",
"the",
"sync",
"status",
"pages",
"is",
"running",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorerroutes.go#L1866-L1903 |
19,649 | decred/dcrdata | explorer/explorerroutes.go | commonData | func (exp *explorerUI) commonData(r *http.Request) *CommonPageData {
tip, err := exp.blockData.GetTip()
if err != nil {
log.Errorf("Failed to get the chain tip from the database.: %v", err)
return nil
}
darkMode, err := r.Cookie(darkModeCoookie)
if err != nil && err != http.ErrNoCookie {
log.Errorf("Cookie d... | go | func (exp *explorerUI) commonData(r *http.Request) *CommonPageData {
tip, err := exp.blockData.GetTip()
if err != nil {
log.Errorf("Failed to get the chain tip from the database.: %v", err)
return nil
}
darkMode, err := r.Cookie(darkModeCoookie)
if err != nil && err != http.ErrNoCookie {
log.Errorf("Cookie d... | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"commonData",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"*",
"CommonPageData",
"{",
"tip",
",",
"err",
":=",
"exp",
".",
"blockData",
".",
"GetTip",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",... | // commonData grabs the common page data that is available to every page.
// This is particularly useful for extras.tmpl, parts of which
// are used on every page | [
"commonData",
"grabs",
"the",
"common",
"page",
"data",
"that",
"is",
"available",
"to",
"every",
"page",
".",
"This",
"is",
"particularly",
"useful",
"for",
"extras",
".",
"tmpl",
"parts",
"of",
"which",
"are",
"used",
"on",
"every",
"page"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorerroutes.go#L2015-L2038 |
19,650 | decred/dcrdata | explorer/explorermiddleware.go | SyncStatusPageIntercept | func (exp *explorerUI) SyncStatusPageIntercept(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if exp.ShowingSyncStatusPage() {
exp.StatusPage(w, "Database Update Running. Please Wait.",
"Blockchain sync is running. Please wait.", "", ExpStatusSyncing)
... | go | func (exp *explorerUI) SyncStatusPageIntercept(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if exp.ShowingSyncStatusPage() {
exp.StatusPage(w, "Database Update Running. Please Wait.",
"Blockchain sync is running. Please wait.", "", ExpStatusSyncing)
... | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"SyncStatusPageIntercept",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http... | // SyncStatusPageIntercept serves only the syncing status page until it is
// deactivated when ShowingSyncStatusPage is set to false. This page is served
// for all the possible routes supported until the background syncing is done. | [
"SyncStatusPageIntercept",
"serves",
"only",
"the",
"syncing",
"status",
"page",
"until",
"it",
"is",
"deactivated",
"when",
"ShowingSyncStatusPage",
"is",
"set",
"to",
"false",
".",
"This",
"page",
"is",
"served",
"for",
"all",
"the",
"possible",
"routes",
"sup... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L88-L98 |
19,651 | decred/dcrdata | explorer/explorermiddleware.go | SyncStatusAPIIntercept | func (exp *explorerUI) SyncStatusAPIIntercept(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if exp.ShowingSyncStatusPage() {
exp.HandleApiRequestsOnSync(w, r)
return
}
// Otherwise, proceed to the next http handler.
next.ServeHTTP(w, r)
})
} | go | func (exp *explorerUI) SyncStatusAPIIntercept(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if exp.ShowingSyncStatusPage() {
exp.HandleApiRequestsOnSync(w, r)
return
}
// Otherwise, proceed to the next http handler.
next.ServeHTTP(w, r)
})
} | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"SyncStatusAPIIntercept",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http"... | // SyncStatusAPIIntercept returns a json response back instead of a web page
// when display sync status is active for the api endpoints supported. | [
"SyncStatusAPIIntercept",
"returns",
"a",
"json",
"response",
"back",
"instead",
"of",
"a",
"web",
"page",
"when",
"display",
"sync",
"status",
"is",
"active",
"for",
"the",
"api",
"endpoints",
"supported",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L102-L111 |
19,652 | decred/dcrdata | explorer/explorermiddleware.go | SyncStatusFileIntercept | func (exp *explorerUI) SyncStatusFileIntercept(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if exp.ShowingSyncStatusPage() {
http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable)
return
}
// Otherwise, procee... | go | func (exp *explorerUI) SyncStatusFileIntercept(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if exp.ShowingSyncStatusPage() {
http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable)
return
}
// Otherwise, procee... | [
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"SyncStatusFileIntercept",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http... | // SyncStatusFileIntercept triggers an HTTP error if a file is requested for
// download before the DB is synced. | [
"SyncStatusFileIntercept",
"triggers",
"an",
"HTTP",
"error",
"if",
"a",
"file",
"is",
"requested",
"for",
"download",
"before",
"the",
"DB",
"is",
"synced",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L115-L124 |
19,653 | decred/dcrdata | explorer/explorermiddleware.go | TransactionHashCtx | func TransactionHashCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
txid := chi.URLParam(r, "txid")
ctx := context.WithValue(r.Context(), ctxTxHash, txid)
next.ServeHTTP(w, r.WithContext(ctx))
})
} | go | func TransactionHashCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
txid := chi.URLParam(r, "txid")
ctx := context.WithValue(r.Context(), ctxTxHash, txid)
next.ServeHTTP(w, r.WithContext(ctx))
})
} | [
"func",
"TransactionHashCtx",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"txid",
":... | // TransactionHashCtx embeds "txid" into the request context | [
"TransactionHashCtx",
"embeds",
"txid",
"into",
"the",
"request",
"context"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L164-L170 |
19,654 | decred/dcrdata | explorer/explorermiddleware.go | TransactionIoIndexCtx | func TransactionIoIndexCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
inout := chi.URLParam(r, "inout")
inoutid := chi.URLParam(r, "inoutid")
ctx := context.WithValue(r.Context(), ctxTxInOut, inout)
ctx = context.WithValue(ctx, ctxTxInOutId, inoutid... | go | func TransactionIoIndexCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
inout := chi.URLParam(r, "inout")
inoutid := chi.URLParam(r, "inoutid")
ctx := context.WithValue(r.Context(), ctxTxInOut, inout)
ctx = context.WithValue(ctx, ctxTxInOutId, inoutid... | [
"func",
"TransactionIoIndexCtx",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"inout",
... | // TransactionIoIndexCtx embeds "inout" and "inoutid" into the request context | [
"TransactionIoIndexCtx",
"embeds",
"inout",
"and",
"inoutid",
"into",
"the",
"request",
"context"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L173-L181 |
19,655 | decred/dcrdata | explorer/explorermiddleware.go | ProposalPathCtx | func ProposalPathCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
proposalRefID := chi.URLParam(r, "proposalrefid")
ctx := context.WithValue(r.Context(), ctxProposalRefID, proposalRefID)
next.ServeHTTP(w, r.WithContext(ctx))
})
} | go | func ProposalPathCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
proposalRefID := chi.URLParam(r, "proposalrefid")
ctx := context.WithValue(r.Context(), ctxProposalRefID, proposalRefID)
next.ServeHTTP(w, r.WithContext(ctx))
})
} | [
"func",
"ProposalPathCtx",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"proposalRefID"... | // ProposalPathCtx embeds "proposalrefID" into the request context | [
"ProposalPathCtx",
"embeds",
"proposalrefID",
"into",
"the",
"request",
"context"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L202-L208 |
19,656 | decred/dcrdata | explorer/explorermiddleware.go | MenuFormParser | func MenuFormParser(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.FormValue(darkModeFormKey) != "" {
cookie, err := r.Cookie(darkModeCoookie)
if err != nil && err != http.ErrNoCookie {
log.Errorf("Cookie dcrdataDarkBG retrieval error: %v", err... | go | func MenuFormParser(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.FormValue(darkModeFormKey) != "" {
cookie, err := r.Cookie(darkModeCoookie)
if err != nil && err != http.ErrNoCookie {
log.Errorf("Cookie dcrdataDarkBG retrieval error: %v", err... | [
"func",
"MenuFormParser",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"r",
"... | // MenuFormParser parses a form submission from the navigation menu. | [
"MenuFormParser",
"parses",
"a",
"form",
"submission",
"from",
"the",
"navigation",
"menu",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/explorermiddleware.go#L211-L239 |
19,657 | decred/dcrdata | notification/ntfnhandlers.go | RegisterNodeNtfnHandlers | func RegisterNodeNtfnHandlers(dcrdClient *rpcclient.Client) *ContextualError {
// Set the node client for use by signalReorg to determine the common
// ancestor of two chains.
nodeClient = dcrdClient
// Register for block connection and chain reorg notifications.
var err error
if err = dcrdClient.NotifyBlocks();... | go | func RegisterNodeNtfnHandlers(dcrdClient *rpcclient.Client) *ContextualError {
// Set the node client for use by signalReorg to determine the common
// ancestor of two chains.
nodeClient = dcrdClient
// Register for block connection and chain reorg notifications.
var err error
if err = dcrdClient.NotifyBlocks();... | [
"func",
"RegisterNodeNtfnHandlers",
"(",
"dcrdClient",
"*",
"rpcclient",
".",
"Client",
")",
"*",
"ContextualError",
"{",
"// Set the node client for use by signalReorg to determine the common",
"// ancestor of two chains.",
"nodeClient",
"=",
"dcrdClient",
"\n\n",
"// Register f... | // RegisterNodeNtfnHandlers registers with dcrd to receive new block,
// transaction and winning ticket notifications. | [
"RegisterNodeNtfnHandlers",
"registers",
"with",
"dcrd",
"to",
"receive",
"new",
"block",
"transaction",
"and",
"winning",
"ticket",
"notifications",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/notification/ntfnhandlers.go#L27-L63 |
19,658 | decred/dcrdata | notification/ntfnhandlers.go | SetSynchronousHandlers | func (q *collectionQueue) SetSynchronousHandlers(syncHandlers []func(hash *chainhash.Hash) error) {
q.syncHandlers = syncHandlers
} | go | func (q *collectionQueue) SetSynchronousHandlers(syncHandlers []func(hash *chainhash.Hash) error) {
q.syncHandlers = syncHandlers
} | [
"func",
"(",
"q",
"*",
"collectionQueue",
")",
"SetSynchronousHandlers",
"(",
"syncHandlers",
"[",
"]",
"func",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"error",
")",
"{",
"q",
".",
"syncHandlers",
"=",
"syncHandlers",
"\n",
"}"
] | // SetSynchronousHandlers sets the slice of synchronous new block handler
// functions, which are called in the order they occur in the slice. | [
"SetSynchronousHandlers",
"sets",
"the",
"slice",
"of",
"synchronous",
"new",
"block",
"handler",
"functions",
"which",
"are",
"called",
"in",
"the",
"order",
"they",
"occur",
"in",
"the",
"slice",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/notification/ntfnhandlers.go#L92-L94 |
19,659 | decred/dcrdata | notification/ntfnhandlers.go | processBlock | func (q *collectionQueue) processBlock(bh *blockHashHeight) {
hash := bh.hash
height := bh.height
// Ensure that the received block (bh.hash, bh.height) connects to the
// previously connected block (q.prevHash, q.prevHeight).
if bh.prevHash != q.prevHash {
log.Infof("Received block at %d (%v) does not connect ... | go | func (q *collectionQueue) processBlock(bh *blockHashHeight) {
hash := bh.hash
height := bh.height
// Ensure that the received block (bh.hash, bh.height) connects to the
// previously connected block (q.prevHash, q.prevHeight).
if bh.prevHash != q.prevHash {
log.Infof("Received block at %d (%v) does not connect ... | [
"func",
"(",
"q",
"*",
"collectionQueue",
")",
"processBlock",
"(",
"bh",
"*",
"blockHashHeight",
")",
"{",
"hash",
":=",
"bh",
".",
"hash",
"\n",
"height",
":=",
"bh",
".",
"height",
"\n\n",
"// Ensure that the received block (bh.hash, bh.height) connects to the",
... | // processBlock calls each synchronous new block handler with the given
// blockHashHeight, and then signals to the monitors that a new block was mined. | [
"processBlock",
"calls",
"each",
"synchronous",
"new",
"block",
"handler",
"with",
"the",
"given",
"blockHashHeight",
"and",
"then",
"signals",
"to",
"the",
"monitors",
"that",
"a",
"new",
"block",
"was",
"mined",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/notification/ntfnhandlers.go#L119-L158 |
19,660 | decred/dcrdata | notification/ntfnhandlers.go | signalReorg | func signalReorg(d ReorgData) {
if nodeClient == nil {
log.Errorf("The daemon RPC client for signalReorg is not configured!")
return
}
// Determine the common ancestor of the two chains, and get the full
// list of blocks in each chain back to but not including the common
// ancestor.
ancestor, newChain, old... | go | func signalReorg(d ReorgData) {
if nodeClient == nil {
log.Errorf("The daemon RPC client for signalReorg is not configured!")
return
}
// Determine the common ancestor of the two chains, and get the full
// list of blocks in each chain back to but not including the common
// ancestor.
ancestor, newChain, old... | [
"func",
"signalReorg",
"(",
"d",
"ReorgData",
")",
"{",
"if",
"nodeClient",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Determine the common ancestor of the two chains, and get the full",
"// list of blocks in... | // signalReorg takes the basic reorganization data from dcrd, determines the two
// chains and their common ancestor, and signals the reorg to each packages'
// reorganization handler. Lastly, the collectionQueue's best block data is
// updated so that it will successfully accept new blocks building on the new
// chain... | [
"signalReorg",
"takes",
"the",
"basic",
"reorganization",
"data",
"from",
"dcrd",
"determines",
"the",
"two",
"chains",
"and",
"their",
"common",
"ancestor",
"and",
"signals",
"the",
"reorg",
"to",
"each",
"packages",
"reorganization",
"handler",
".",
"Lastly",
... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/notification/ntfnhandlers.go#L174-L247 |
19,661 | decred/dcrdata | notification/ntfnhandlers.go | superQueue | func superQueue() {
for e := range anyQueue {
// Do not allow new blocks to process while running reorg. Only allow
// them to be processed after this reorg completes.
switch et := e.(type) {
case *blockHashHeight:
// Process the new block.
log.Infof("superQueue: Processing new block %v (height %d).", et... | go | func superQueue() {
for e := range anyQueue {
// Do not allow new blocks to process while running reorg. Only allow
// them to be processed after this reorg completes.
switch et := e.(type) {
case *blockHashHeight:
// Process the new block.
log.Infof("superQueue: Processing new block %v (height %d).", et... | [
"func",
"superQueue",
"(",
")",
"{",
"for",
"e",
":=",
"range",
"anyQueue",
"{",
"// Do not allow new blocks to process while running reorg. Only allow",
"// them to be processed after this reorg completes.",
"switch",
"et",
":=",
"e",
".",
"(",
"type",
")",
"{",
"case",
... | // superQueue manages the event notification queue, keeping the events in the
// same order they were received by the rpcclient.NotificationHandlers, and
// sending them to the appropriate handlers. This should be run as a goroutine. | [
"superQueue",
"manages",
"the",
"event",
"notification",
"queue",
"keeping",
"the",
"events",
"in",
"the",
"same",
"order",
"they",
"were",
"received",
"by",
"the",
"rpcclient",
".",
"NotificationHandlers",
"and",
"sending",
"them",
"to",
"the",
"appropriate",
"... | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/notification/ntfnhandlers.go#L257-L276 |
19,662 | decred/dcrdata | exchanges/exchanges.go | Tokens | func Tokens() []string {
tokens := make([]string, 0, len(BtcIndices)+len(DcrExchanges))
var token string
for token = range BtcIndices {
tokens = append(tokens, token)
}
for token = range DcrExchanges {
tokens = append(tokens, token)
}
return tokens
} | go | func Tokens() []string {
tokens := make([]string, 0, len(BtcIndices)+len(DcrExchanges))
var token string
for token = range BtcIndices {
tokens = append(tokens, token)
}
for token = range DcrExchanges {
tokens = append(tokens, token)
}
return tokens
} | [
"func",
"Tokens",
"(",
")",
"[",
"]",
"string",
"{",
"tokens",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"BtcIndices",
")",
"+",
"len",
"(",
"DcrExchanges",
")",
")",
"\n",
"var",
"token",
"string",
"\n",
"for",
"token",
"... | // Tokens is a new slice of available exchange tokens. | [
"Tokens",
"is",
"a",
"new",
"slice",
"of",
"available",
"exchange",
"tokens",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L169-L179 |
19,663 | decred/dcrdata | exchanges/exchanges.go | IsFresh | func (depth *DepthData) IsFresh() bool {
return time.Duration(time.Now().Unix()-depth.Time)*
time.Second < depthDataExpiration
} | go | func (depth *DepthData) IsFresh() bool {
return time.Duration(time.Now().Unix()-depth.Time)*
time.Second < depthDataExpiration
} | [
"func",
"(",
"depth",
"*",
"DepthData",
")",
"IsFresh",
"(",
")",
"bool",
"{",
"return",
"time",
".",
"Duration",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
"-",
"depth",
".",
"Time",
")",
"*",
"time",
".",
"Second",
"<",
"depthDat... | // IsFresh will be true if the data is older than depthDataExpiration. | [
"IsFresh",
"will",
"be",
"true",
"if",
"the",
"data",
"is",
"older",
"than",
"depthDataExpiration",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L200-L203 |
19,664 | decred/dcrdata | exchanges/exchanges.go | time | func (sticks Candlesticks) time() time.Time {
if len(sticks) > 0 {
return sticks[len(sticks)-1].Start
}
return time.Time{}
} | go | func (sticks Candlesticks) time() time.Time {
if len(sticks) > 0 {
return sticks[len(sticks)-1].Start
}
return time.Time{}
} | [
"func",
"(",
"sticks",
"Candlesticks",
")",
"time",
"(",
")",
"time",
".",
"Time",
"{",
"if",
"len",
"(",
"sticks",
")",
">",
"0",
"{",
"return",
"sticks",
"[",
"len",
"(",
"sticks",
")",
"-",
"1",
"]",
".",
"Start",
"\n",
"}",
"\n",
"return",
... | // returns the start time of the last Candlestick, else the zero time, | [
"returns",
"the",
"start",
"time",
"of",
"the",
"last",
"Candlestick",
"else",
"the",
"zero",
"time"
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L219-L224 |
19,665 | decred/dcrdata | exchanges/exchanges.go | needsUpdate | func (sticks Candlesticks) needsUpdate(bin candlestickKey) bool {
if len(sticks) == 0 {
return true
}
lastStick := sticks[len(sticks)-1]
return time.Now().After(lastStick.Start.Add(bin.duration() * 2))
} | go | func (sticks Candlesticks) needsUpdate(bin candlestickKey) bool {
if len(sticks) == 0 {
return true
}
lastStick := sticks[len(sticks)-1]
return time.Now().After(lastStick.Start.Add(bin.duration() * 2))
} | [
"func",
"(",
"sticks",
"Candlesticks",
")",
"needsUpdate",
"(",
"bin",
"candlestickKey",
")",
"bool",
"{",
"if",
"len",
"(",
"sticks",
")",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"lastStick",
":=",
"sticks",
"[",
"len",
"(",
"sticks",
")",
... | // Checks whether the candlestick data for the given bin size is up-to-date. | [
"Checks",
"whether",
"the",
"candlestick",
"data",
"for",
"the",
"given",
"bin",
"size",
"is",
"up",
"-",
"to",
"-",
"date",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L227-L233 |
19,666 | decred/dcrdata | exchanges/exchanges.go | stealSticks | func (state *ExchangeState) stealSticks(top *ExchangeState) {
if len(top.Candlesticks) == 0 {
return
}
if state.Candlesticks == nil {
state.Candlesticks = make(map[candlestickKey]Candlesticks)
}
for bin := range top.Candlesticks {
_, have := state.Candlesticks[bin]
if !have {
state.Candlesticks[bin] = t... | go | func (state *ExchangeState) stealSticks(top *ExchangeState) {
if len(top.Candlesticks) == 0 {
return
}
if state.Candlesticks == nil {
state.Candlesticks = make(map[candlestickKey]Candlesticks)
}
for bin := range top.Candlesticks {
_, have := state.Candlesticks[bin]
if !have {
state.Candlesticks[bin] = t... | [
"func",
"(",
"state",
"*",
"ExchangeState",
")",
"stealSticks",
"(",
"top",
"*",
"ExchangeState",
")",
"{",
"if",
"len",
"(",
"top",
".",
"Candlesticks",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"if",
"state",
".",
"Candlesticks",
"==",
"nil",
... | // Grab any candlesticks from the top that are not in the receiver. Candlesticks
// are historical data, so never need to be discarded. | [
"Grab",
"any",
"candlesticks",
"from",
"the",
"top",
"that",
"are",
"not",
"in",
"the",
"receiver",
".",
"Candlesticks",
"are",
"historical",
"data",
"so",
"never",
"need",
"to",
"be",
"discarded",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L268-L281 |
19,667 | decred/dcrdata | exchanges/exchanges.go | exchangeStateFromProto | func exchangeStateFromProto(proto *dcrrates.ExchangeRateUpdate) *ExchangeState {
state := &ExchangeState{
Price: proto.GetPrice(),
BaseVolume: proto.GetBaseVolume(),
Volume: proto.GetVolume(),
Change: proto.GetChange(),
Stamp: proto.GetStamp(),
}
updateDepth := proto.GetDepth()
if updat... | go | func exchangeStateFromProto(proto *dcrrates.ExchangeRateUpdate) *ExchangeState {
state := &ExchangeState{
Price: proto.GetPrice(),
BaseVolume: proto.GetBaseVolume(),
Volume: proto.GetVolume(),
Change: proto.GetChange(),
Stamp: proto.GetStamp(),
}
updateDepth := proto.GetDepth()
if updat... | [
"func",
"exchangeStateFromProto",
"(",
"proto",
"*",
"dcrrates",
".",
"ExchangeRateUpdate",
")",
"*",
"ExchangeState",
"{",
"state",
":=",
"&",
"ExchangeState",
"{",
"Price",
":",
"proto",
".",
"GetPrice",
"(",
")",
",",
"BaseVolume",
":",
"proto",
".",
"Get... | // Parse an ExchangeState from a protocol buffer message. | [
"Parse",
"an",
"ExchangeState",
"from",
"a",
"protocol",
"buffer",
"message",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L284-L334 |
19,668 | decred/dcrdata | exchanges/exchanges.go | StickList | func (state *ExchangeState) StickList() string {
sticks := make([]string, 0, len(state.Candlesticks))
for bin := range state.Candlesticks {
sticks = append(sticks, string(bin))
}
return strings.Join(sticks, ";")
} | go | func (state *ExchangeState) StickList() string {
sticks := make([]string, 0, len(state.Candlesticks))
for bin := range state.Candlesticks {
sticks = append(sticks, string(bin))
}
return strings.Join(sticks, ";")
} | [
"func",
"(",
"state",
"*",
"ExchangeState",
")",
"StickList",
"(",
")",
"string",
"{",
"sticks",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"state",
".",
"Candlesticks",
")",
")",
"\n",
"for",
"bin",
":=",
"range",
"state",
"... | // StickList is a semicolon-delimited list of available binSize. | [
"StickList",
"is",
"a",
"semicolon",
"-",
"delimited",
"list",
"of",
"available",
"binSize",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L347-L353 |
19,669 | decred/dcrdata | exchanges/exchanges.go | LastUpdate | func (xc *CommonExchange) LastUpdate() time.Time {
xc.mtx.RLock()
defer xc.mtx.RUnlock()
return xc.lastUpdate
} | go | func (xc *CommonExchange) LastUpdate() time.Time {
xc.mtx.RLock()
defer xc.mtx.RUnlock()
return xc.lastUpdate
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"LastUpdate",
"(",
")",
"time",
".",
"Time",
"{",
"xc",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"xc",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"xc",
".",
"lastUpdate",
"\n",
"... | // LastUpdate gets a time.Time of the last successful exchange update. | [
"LastUpdate",
"gets",
"a",
"time",
".",
"Time",
"of",
"the",
"last",
"successful",
"exchange",
"update",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L403-L407 |
19,670 | decred/dcrdata | exchanges/exchanges.go | Hurry | func (xc *CommonExchange) Hurry(d time.Duration) {
xc.mtx.Lock()
defer xc.mtx.Unlock()
xc.lastRequest = xc.lastRequest.Add(-d)
} | go | func (xc *CommonExchange) Hurry(d time.Duration) {
xc.mtx.Lock()
defer xc.mtx.Unlock()
xc.lastRequest = xc.lastRequest.Add(-d)
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"Hurry",
"(",
"d",
"time",
".",
"Duration",
")",
"{",
"xc",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"xc",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"xc",
".",
"lastRequest",
"=",
"xc",
"... | // Hurry can be used to subtract some amount of time from the lastUpate
// and lastFail, and can be used to de-sync the exchange updates. | [
"Hurry",
"can",
"be",
"used",
"to",
"subtract",
"some",
"amount",
"of",
"time",
"from",
"the",
"lastUpate",
"and",
"lastFail",
"and",
"can",
"be",
"used",
"to",
"de",
"-",
"sync",
"the",
"exchange",
"updates",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L411-L415 |
19,671 | decred/dcrdata | exchanges/exchanges.go | LastFail | func (xc *CommonExchange) LastFail() time.Time {
xc.mtx.RLock()
defer xc.mtx.RUnlock()
return xc.lastFail
} | go | func (xc *CommonExchange) LastFail() time.Time {
xc.mtx.RLock()
defer xc.mtx.RUnlock()
return xc.lastFail
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"LastFail",
"(",
")",
"time",
".",
"Time",
"{",
"xc",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"xc",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"xc",
".",
"lastFail",
"\n",
"}"
] | // LastFail gets the last time.Time of a failed exchange update. | [
"LastFail",
"gets",
"the",
"last",
"time",
".",
"Time",
"of",
"a",
"failed",
"exchange",
"update",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L418-L422 |
19,672 | decred/dcrdata | exchanges/exchanges.go | IsFailed | func (xc *CommonExchange) IsFailed() bool {
xc.mtx.RLock()
defer xc.mtx.RUnlock()
return xc.lastFail.After(xc.lastUpdate)
} | go | func (xc *CommonExchange) IsFailed() bool {
xc.mtx.RLock()
defer xc.mtx.RUnlock()
return xc.lastFail.After(xc.lastUpdate)
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"IsFailed",
"(",
")",
"bool",
"{",
"xc",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"xc",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"xc",
".",
"lastFail",
".",
"After",
"(",
"xc",... | // IsFailed will be true if xc.lastFail > xc.lastUpdate. | [
"IsFailed",
"will",
"be",
"true",
"if",
"xc",
".",
"lastFail",
">",
"xc",
".",
"lastUpdate",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L425-L429 |
19,673 | decred/dcrdata | exchanges/exchanges.go | LogRequest | func (xc *CommonExchange) LogRequest() {
xc.mtx.Lock()
defer xc.mtx.Unlock()
xc.lastRequest = time.Now()
} | go | func (xc *CommonExchange) LogRequest() {
xc.mtx.Lock()
defer xc.mtx.Unlock()
xc.lastRequest = time.Now()
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"LogRequest",
"(",
")",
"{",
"xc",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"xc",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"xc",
".",
"lastRequest",
"=",
"time",
".",
"Now",
"(",
")",
"\... | // LogRequest sets the lastRequest time.Time. | [
"LogRequest",
"sets",
"the",
"lastRequest",
"time",
".",
"Time",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L432-L436 |
19,674 | decred/dcrdata | exchanges/exchanges.go | LastTry | func (xc *CommonExchange) LastTry() time.Time {
xc.mtx.RLock()
defer xc.mtx.RUnlock()
return xc.lastRequest
} | go | func (xc *CommonExchange) LastTry() time.Time {
xc.mtx.RLock()
defer xc.mtx.RUnlock()
return xc.lastRequest
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"LastTry",
"(",
")",
"time",
".",
"Time",
"{",
"xc",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"xc",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"xc",
".",
"lastRequest",
"\n",
"}"... | // LastTry is the more recent of lastFail and LastUpdate. | [
"LastTry",
"is",
"the",
"more",
"recent",
"of",
"lastFail",
"and",
"LastUpdate",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L439-L443 |
19,675 | decred/dcrdata | exchanges/exchanges.go | setLastFail | func (xc *CommonExchange) setLastFail(t time.Time) {
xc.mtx.Lock()
defer xc.mtx.Unlock()
xc.lastFail = t
} | go | func (xc *CommonExchange) setLastFail(t time.Time) {
xc.mtx.Lock()
defer xc.mtx.Unlock()
xc.lastFail = t
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"setLastFail",
"(",
"t",
"time",
".",
"Time",
")",
"{",
"xc",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"xc",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"xc",
".",
"lastFail",
"=",
"t",
"\n... | // setLastFail sets the last failure time. | [
"setLastFail",
"sets",
"the",
"last",
"failure",
"time",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L451-L455 |
19,676 | decred/dcrdata | exchanges/exchanges.go | fail | func (xc *CommonExchange) fail(msg string, err error) {
log.Errorf("%s: %s: %v", xc.token, msg, err)
xc.setLastFail(time.Now())
} | go | func (xc *CommonExchange) fail(msg string, err error) {
log.Errorf("%s: %s: %v", xc.token, msg, err)
xc.setLastFail(time.Now())
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"fail",
"(",
"msg",
"string",
",",
"err",
"error",
")",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"xc",
".",
"token",
",",
"msg",
",",
"err",
")",
"\n",
"xc",
".",
"setLastFail",
"(",
"time",
... | // Log the error along with the token and an additional passed identifier. | [
"Log",
"the",
"error",
"along",
"with",
"the",
"token",
"and",
"an",
"additional",
"passed",
"identifier",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L458-L461 |
19,677 | decred/dcrdata | exchanges/exchanges.go | UpdateIndices | func (xc *CommonExchange) UpdateIndices(indices FiatIndices) {
xc.mtx.Lock()
defer xc.mtx.Unlock()
xc.lastUpdate = time.Now()
xc.channels.index <- &IndexUpdate{
Token: xc.token,
Indices: indices,
}
} | go | func (xc *CommonExchange) UpdateIndices(indices FiatIndices) {
xc.mtx.Lock()
defer xc.mtx.Unlock()
xc.lastUpdate = time.Now()
xc.channels.index <- &IndexUpdate{
Token: xc.token,
Indices: indices,
}
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"UpdateIndices",
"(",
"indices",
"FiatIndices",
")",
"{",
"xc",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"xc",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"xc",
".",
"lastUpdate",
"=",
"time",
... | // UpdateIndices sends a bitcoin index update to the ExchangeBot. | [
"UpdateIndices",
"sends",
"a",
"bitcoin",
"index",
"update",
"to",
"the",
"ExchangeBot",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L490-L498 |
19,678 | decred/dcrdata | exchanges/exchanges.go | fetch | func (xc *CommonExchange) fetch(request *http.Request, response interface{}) (err error) {
resp, err := xc.client.Do(request)
if err != nil {
return fmt.Errorf(fmt.Sprintf("Request failed: %v", err))
}
defer resp.Body.Close()
err = json.NewDecoder(resp.Body).Decode(response)
if err != nil {
return fmt.Errorf(... | go | func (xc *CommonExchange) fetch(request *http.Request, response interface{}) (err error) {
resp, err := xc.client.Do(request)
if err != nil {
return fmt.Errorf(fmt.Sprintf("Request failed: %v", err))
}
defer resp.Body.Close()
err = json.NewDecoder(resp.Body).Decode(response)
if err != nil {
return fmt.Errorf(... | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"fetch",
"(",
"request",
"*",
"http",
".",
"Request",
",",
"response",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"xc",
".",
"client",
".",
"Do",
"(",
"request... | // Send the exchange request and decode the response. | [
"Send",
"the",
"exchange",
"request",
"and",
"decode",
"the",
"response",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L501-L512 |
19,679 | decred/dcrdata | exchanges/exchanges.go | state | func (xc *CommonExchange) state() *ExchangeState {
xc.mtx.RLock()
defer xc.mtx.RUnlock()
return xc.currentState
} | go | func (xc *CommonExchange) state() *ExchangeState {
xc.mtx.RLock()
defer xc.mtx.RUnlock()
return xc.currentState
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"state",
"(",
")",
"*",
"ExchangeState",
"{",
"xc",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"xc",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"xc",
".",
"currentState",
"\n",
"}"
] | // A thread-safe getter for the last known ExchangeState. | [
"A",
"thread",
"-",
"safe",
"getter",
"for",
"the",
"last",
"known",
"ExchangeState",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L515-L519 |
19,680 | decred/dcrdata | exchanges/exchanges.go | connectWebsocket | func (xc *CommonExchange) connectWebsocket(processor WebsocketProcessor, cfg *socketConfig) error {
ws, err := newSocketConnection(cfg)
if err != nil {
return err
}
xc.wsMtx.Lock()
if xc.ws != nil {
select {
case <-xc.ws.Done():
default:
xc.ws.Close()
}
}
xc.wsProcessor = processor
xc.ws = ws
xc.... | go | func (xc *CommonExchange) connectWebsocket(processor WebsocketProcessor, cfg *socketConfig) error {
ws, err := newSocketConnection(cfg)
if err != nil {
return err
}
xc.wsMtx.Lock()
if xc.ws != nil {
select {
case <-xc.ws.Done():
default:
xc.ws.Close()
}
}
xc.wsProcessor = processor
xc.ws = ws
xc.... | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"connectWebsocket",
"(",
"processor",
"WebsocketProcessor",
",",
"cfg",
"*",
"socketConfig",
")",
"error",
"{",
"ws",
",",
"err",
":=",
"newSocketConnection",
"(",
"cfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"... | // Creates a websocket connection and starts a listen loop. Closes any existing
// connections for this exchange. | [
"Creates",
"a",
"websocket",
"connection",
"and",
"starts",
"a",
"listen",
"loop",
".",
"Closes",
"any",
"existing",
"connections",
"for",
"this",
"exchange",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L534-L554 |
19,681 | decred/dcrdata | exchanges/exchanges.go | startWebsocket | func (xc *CommonExchange) startWebsocket() {
ws, processor := xc.websocket()
go func() {
for {
message, err := ws.Read()
if err != nil {
xc.setWsFail(err)
return
}
processor(message)
}
}()
} | go | func (xc *CommonExchange) startWebsocket() {
ws, processor := xc.websocket()
go func() {
for {
message, err := ws.Read()
if err != nil {
xc.setWsFail(err)
return
}
processor(message)
}
}()
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"startWebsocket",
"(",
")",
"{",
"ws",
",",
"processor",
":=",
"xc",
".",
"websocket",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"message",
",",
"err",
":=",
"ws",
".",
"Read",
"(",
")... | // The listen loop for a websocket connection. | [
"The",
"listen",
"loop",
"for",
"a",
"websocket",
"connection",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L557-L569 |
19,682 | decred/dcrdata | exchanges/exchanges.go | wsListening | func (xc *CommonExchange) wsListening() bool {
ws, _ := xc.websocket()
if ws == nil {
return false
}
select {
case <-ws.Done():
return false
default:
return true
}
} | go | func (xc *CommonExchange) wsListening() bool {
ws, _ := xc.websocket()
if ws == nil {
return false
}
select {
case <-ws.Done():
return false
default:
return true
}
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"wsListening",
"(",
")",
"bool",
"{",
"ws",
",",
"_",
":=",
"xc",
".",
"websocket",
"(",
")",
"\n",
"if",
"ws",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"select",
"{",
"case",
"<-",
"ws"... | // Checks whether the websocketFeed Done channel is closed. | [
"Checks",
"whether",
"the",
"websocketFeed",
"Done",
"channel",
"is",
"closed",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L577-L588 |
19,683 | decred/dcrdata | exchanges/exchanges.go | setWsFail | func (xc *CommonExchange) setWsFail(err error) {
xc.wsMtx.Lock()
defer xc.wsMtx.Unlock()
log.Errorf("%s websocket error: %v", xc.token, err)
xc.wsSync.err = err
xc.wsSync.errCount++
xc.wsSync.fail = time.Now()
} | go | func (xc *CommonExchange) setWsFail(err error) {
xc.wsMtx.Lock()
defer xc.wsMtx.Unlock()
log.Errorf("%s websocket error: %v", xc.token, err)
xc.wsSync.err = err
xc.wsSync.errCount++
xc.wsSync.fail = time.Now()
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"setWsFail",
"(",
"err",
"error",
")",
"{",
"xc",
".",
"wsMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"xc",
".",
"wsMtx",
".",
"Unlock",
"(",
")",
"\n",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
... | // Log the error and time, and increment the error counter. | [
"Log",
"the",
"error",
"and",
"time",
"and",
"increment",
"the",
"error",
"counter",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L591-L598 |
19,684 | decred/dcrdata | exchanges/exchanges.go | wsFailed | func (xc *CommonExchange) wsFailed() bool {
xc.wsMtx.RLock()
defer xc.wsMtx.RUnlock()
return xc.wsSync.fail.After(xc.wsSync.update)
} | go | func (xc *CommonExchange) wsFailed() bool {
xc.wsMtx.RLock()
defer xc.wsMtx.RUnlock()
return xc.wsSync.fail.After(xc.wsSync.update)
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"wsFailed",
"(",
")",
"bool",
"{",
"xc",
".",
"wsMtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"xc",
".",
"wsMtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"xc",
".",
"wsSync",
".",
"fail",
".",
"Aft... | // Checks whether the websocket is in a failed state. | [
"Checks",
"whether",
"the",
"websocket",
"is",
"in",
"a",
"failed",
"state",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L601-L605 |
19,685 | decred/dcrdata | exchanges/exchanges.go | wsErrorCount | func (xc *CommonExchange) wsErrorCount() int {
xc.wsMtx.RLock()
defer xc.wsMtx.RUnlock()
return xc.wsSync.errCount
} | go | func (xc *CommonExchange) wsErrorCount() int {
xc.wsMtx.RLock()
defer xc.wsMtx.RUnlock()
return xc.wsSync.errCount
} | [
"func",
"(",
"xc",
"*",
"CommonExchange",
")",
"wsErrorCount",
"(",
")",
"int",
"{",
"xc",
".",
"wsMtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"xc",
".",
"wsMtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"xc",
".",
"wsSync",
".",
"errCount",
"\n"... | // The count of errors logged since the last success-triggered reset. | [
"The",
"count",
"of",
"errors",
"logged",
"since",
"the",
"last",
"success",
"-",
"triggered",
"reset",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L608-L612 |
19,686 | decred/dcrdata | exchanges/exchanges.go | newCommonExchange | func newCommonExchange(token string, client *http.Client,
reqs requests, channels *BotChannels) *CommonExchange {
var tZero time.Time
return &CommonExchange{
token: token,
client: client,
channels: channels,
currentState: new(ExchangeState),
lastUpdate: tZero,
lastFail: tZero,
la... | go | func newCommonExchange(token string, client *http.Client,
reqs requests, channels *BotChannels) *CommonExchange {
var tZero time.Time
return &CommonExchange{
token: token,
client: client,
channels: channels,
currentState: new(ExchangeState),
lastUpdate: tZero,
lastFail: tZero,
la... | [
"func",
"newCommonExchange",
"(",
"token",
"string",
",",
"client",
"*",
"http",
".",
"Client",
",",
"reqs",
"requests",
",",
"channels",
"*",
"BotChannels",
")",
"*",
"CommonExchange",
"{",
"var",
"tZero",
"time",
".",
"Time",
"\n",
"return",
"&",
"Common... | // Used to initialize the embedding exchanges. | [
"Used",
"to",
"initialize",
"the",
"embedding",
"exchanges",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L615-L628 |
19,687 | decred/dcrdata | exchanges/exchanges.go | NewCoinbase | func NewCoinbase(client *http.Client, channels *BotChannels) (coinbase Exchange, err error) {
reqs := newRequests()
reqs.price, err = http.NewRequest(http.MethodGet, CoinbaseURLs.Price, nil)
if err != nil {
return
}
coinbase = &CoinbaseExchange{
CommonExchange: newCommonExchange(Coinbase, client, reqs, channel... | go | func NewCoinbase(client *http.Client, channels *BotChannels) (coinbase Exchange, err error) {
reqs := newRequests()
reqs.price, err = http.NewRequest(http.MethodGet, CoinbaseURLs.Price, nil)
if err != nil {
return
}
coinbase = &CoinbaseExchange{
CommonExchange: newCommonExchange(Coinbase, client, reqs, channel... | [
"func",
"NewCoinbase",
"(",
"client",
"*",
"http",
".",
"Client",
",",
"channels",
"*",
"BotChannels",
")",
"(",
"coinbase",
"Exchange",
",",
"err",
"error",
")",
"{",
"reqs",
":=",
"newRequests",
"(",
")",
"\n",
"reqs",
".",
"price",
",",
"err",
"=",
... | // NewCoinbase constructs a CoinbaseExchange. | [
"NewCoinbase",
"constructs",
"a",
"CoinbaseExchange",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L636-L646 |
19,688 | decred/dcrdata | exchanges/exchanges.go | Refresh | func (coinbase *CoinbaseExchange) Refresh() {
coinbase.LogRequest()
response := new(CoinbaseResponse)
err := coinbase.fetch(coinbase.requests.price, response)
if err != nil {
coinbase.fail("Fetch", err)
return
}
indices := make(FiatIndices)
for code, floatStr := range response.Data.Rates {
price, err := s... | go | func (coinbase *CoinbaseExchange) Refresh() {
coinbase.LogRequest()
response := new(CoinbaseResponse)
err := coinbase.fetch(coinbase.requests.price, response)
if err != nil {
coinbase.fail("Fetch", err)
return
}
indices := make(FiatIndices)
for code, floatStr := range response.Data.Rates {
price, err := s... | [
"func",
"(",
"coinbase",
"*",
"CoinbaseExchange",
")",
"Refresh",
"(",
")",
"{",
"coinbase",
".",
"LogRequest",
"(",
")",
"\n",
"response",
":=",
"new",
"(",
"CoinbaseResponse",
")",
"\n",
"err",
":=",
"coinbase",
".",
"fetch",
"(",
"coinbase",
".",
"req... | // Refresh retrieves and parses API data from Coinbase. | [
"Refresh",
"retrieves",
"and",
"parses",
"API",
"data",
"from",
"Coinbase",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L660-L679 |
19,689 | decred/dcrdata | exchanges/exchanges.go | NewCoindesk | func NewCoindesk(client *http.Client, channels *BotChannels) (coindesk Exchange, err error) {
reqs := newRequests()
reqs.price, err = http.NewRequest(http.MethodGet, CoindeskURLs.Price, nil)
if err != nil {
return
}
coindesk = &CoindeskExchange{
CommonExchange: newCommonExchange(Coindesk, client, reqs, channel... | go | func NewCoindesk(client *http.Client, channels *BotChannels) (coindesk Exchange, err error) {
reqs := newRequests()
reqs.price, err = http.NewRequest(http.MethodGet, CoindeskURLs.Price, nil)
if err != nil {
return
}
coindesk = &CoindeskExchange{
CommonExchange: newCommonExchange(Coindesk, client, reqs, channel... | [
"func",
"NewCoindesk",
"(",
"client",
"*",
"http",
".",
"Client",
",",
"channels",
"*",
"BotChannels",
")",
"(",
"coindesk",
"Exchange",
",",
"err",
"error",
")",
"{",
"reqs",
":=",
"newRequests",
"(",
")",
"\n",
"reqs",
".",
"price",
",",
"err",
"=",
... | // NewCoindesk constructs a CoindeskExchange. | [
"NewCoindesk",
"constructs",
"a",
"CoindeskExchange",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L688-L698 |
19,690 | decred/dcrdata | exchanges/exchanges.go | Refresh | func (coindesk *CoindeskExchange) Refresh() {
coindesk.LogRequest()
response := new(CoindeskResponse)
err := coindesk.fetch(coindesk.requests.price, response)
if err != nil {
coindesk.fail("Fetch", err)
return
}
indices := make(FiatIndices)
for code, bpi := range response.Bpi {
indices[code] = bpi.RateFlo... | go | func (coindesk *CoindeskExchange) Refresh() {
coindesk.LogRequest()
response := new(CoindeskResponse)
err := coindesk.fetch(coindesk.requests.price, response)
if err != nil {
coindesk.fail("Fetch", err)
return
}
indices := make(FiatIndices)
for code, bpi := range response.Bpi {
indices[code] = bpi.RateFlo... | [
"func",
"(",
"coindesk",
"*",
"CoindeskExchange",
")",
"Refresh",
"(",
")",
"{",
"coindesk",
".",
"LogRequest",
"(",
")",
"\n",
"response",
":=",
"new",
"(",
"CoindeskResponse",
")",
"\n",
"err",
":=",
"coindesk",
".",
"fetch",
"(",
"coindesk",
".",
"req... | // Refresh retrieves and parses API data from Coindesk. | [
"Refresh",
"retrieves",
"and",
"parses",
"API",
"data",
"from",
"Coindesk",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L725-L739 |
19,691 | decred/dcrdata | exchanges/exchanges.go | NewBinance | func NewBinance(client *http.Client, channels *BotChannels) (binance Exchange, err error) {
reqs := newRequests()
reqs.price, err = http.NewRequest(http.MethodGet, BinanceURLs.Price, nil)
if err != nil {
return
}
reqs.depth, err = http.NewRequest(http.MethodGet, BinanceURLs.Depth, nil)
if err != nil {
return... | go | func NewBinance(client *http.Client, channels *BotChannels) (binance Exchange, err error) {
reqs := newRequests()
reqs.price, err = http.NewRequest(http.MethodGet, BinanceURLs.Price, nil)
if err != nil {
return
}
reqs.depth, err = http.NewRequest(http.MethodGet, BinanceURLs.Depth, nil)
if err != nil {
return... | [
"func",
"NewBinance",
"(",
"client",
"*",
"http",
".",
"Client",
",",
"channels",
"*",
"BotChannels",
")",
"(",
"binance",
"Exchange",
",",
"err",
"error",
")",
"{",
"reqs",
":=",
"newRequests",
"(",
")",
"\n",
"reqs",
".",
"price",
",",
"err",
"=",
... | // NewBinance constructs a BinanceExchange. | [
"NewBinance",
"constructs",
"a",
"BinanceExchange",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L747-L769 |
19,692 | decred/dcrdata | exchanges/exchanges.go | Refresh | func (binance *BinanceExchange) Refresh() {
binance.LogRequest()
priceResponse := new(BinancePriceResponse)
err := binance.fetch(binance.requests.price, priceResponse)
if err != nil {
binance.fail("Fetch price", err)
return
}
price, err := strconv.ParseFloat(priceResponse.LastPrice, 64)
if err != nil {
bin... | go | func (binance *BinanceExchange) Refresh() {
binance.LogRequest()
priceResponse := new(BinancePriceResponse)
err := binance.fetch(binance.requests.price, priceResponse)
if err != nil {
binance.fail("Fetch price", err)
return
}
price, err := strconv.ParseFloat(priceResponse.LastPrice, 64)
if err != nil {
bin... | [
"func",
"(",
"binance",
"*",
"BinanceExchange",
")",
"Refresh",
"(",
")",
"{",
"binance",
".",
"LogRequest",
"(",
")",
"\n",
"priceResponse",
":=",
"new",
"(",
"BinancePriceResponse",
")",
"\n",
"err",
":=",
"binance",
".",
"fetch",
"(",
"binance",
".",
... | // Refresh retrieves and parses API data from Binance. | [
"Refresh",
"retrieves",
"and",
"parses",
"API",
"data",
"from",
"Binance",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L936-L1005 |
19,693 | decred/dcrdata | exchanges/exchanges.go | NewBittrex | func NewBittrex(client *http.Client, channels *BotChannels) (bittrex Exchange, err error) {
reqs := newRequests()
reqs.price, err = http.NewRequest(http.MethodGet, BittrexURLs.Price, nil)
if err != nil {
return
}
reqs.depth, err = http.NewRequest(http.MethodGet, BittrexURLs.Depth, nil)
if err != nil {
return... | go | func NewBittrex(client *http.Client, channels *BotChannels) (bittrex Exchange, err error) {
reqs := newRequests()
reqs.price, err = http.NewRequest(http.MethodGet, BittrexURLs.Price, nil)
if err != nil {
return
}
reqs.depth, err = http.NewRequest(http.MethodGet, BittrexURLs.Depth, nil)
if err != nil {
return... | [
"func",
"NewBittrex",
"(",
"client",
"*",
"http",
".",
"Client",
",",
"channels",
"*",
"BotChannels",
")",
"(",
"bittrex",
"Exchange",
",",
"err",
"error",
")",
"{",
"reqs",
":=",
"newRequests",
"(",
")",
"\n",
"reqs",
".",
"price",
",",
"err",
"=",
... | // NewBittrex constructs a BittrexExchange. | [
"NewBittrex",
"constructs",
"a",
"BittrexExchange",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L1014-L1038 |
19,694 | decred/dcrdata | exchanges/exchanges.go | makePts | func (pts BittrexDepthArray) makePts() []DepthPoint {
depth := make([]DepthPoint, 0, len(pts))
for _, pt := range pts {
depth = append(depth, DepthPoint{
Quantity: pt.Quantity,
Price: pt.Rate,
})
}
return depth
} | go | func (pts BittrexDepthArray) makePts() []DepthPoint {
depth := make([]DepthPoint, 0, len(pts))
for _, pt := range pts {
depth = append(depth, DepthPoint{
Quantity: pt.Quantity,
Price: pt.Rate,
})
}
return depth
} | [
"func",
"(",
"pts",
"BittrexDepthArray",
")",
"makePts",
"(",
")",
"[",
"]",
"DepthPoint",
"{",
"depth",
":=",
"make",
"(",
"[",
"]",
"DepthPoint",
",",
"0",
",",
"len",
"(",
"pts",
")",
")",
"\n",
"for",
"_",
",",
"pt",
":=",
"range",
"pts",
"{"... | // Translate the bittrex list to DepthPoints. | [
"Translate",
"the",
"bittrex",
"list",
"to",
"DepthPoints",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L1080-L1089 |
19,695 | decred/dcrdata | exchanges/exchanges.go | translate | func (r *BittrexDepthResponse) translate() *DepthData {
if r == nil {
return nil
}
if !r.Success {
log.Errorf("Bittrex depth result error: %s", r.Message)
return nil
}
depth := new(DepthData)
depth.Time = time.Now().Unix()
depth.Asks = r.Result.Sell.makePts()
depth.Bids = r.Result.Buy.makePts()
return de... | go | func (r *BittrexDepthResponse) translate() *DepthData {
if r == nil {
return nil
}
if !r.Success {
log.Errorf("Bittrex depth result error: %s", r.Message)
return nil
}
depth := new(DepthData)
depth.Time = time.Now().Unix()
depth.Asks = r.Result.Sell.makePts()
depth.Bids = r.Result.Buy.makePts()
return de... | [
"func",
"(",
"r",
"*",
"BittrexDepthResponse",
")",
"translate",
"(",
")",
"*",
"DepthData",
"{",
"if",
"r",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"r",
".",
"Success",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",... | // Translate the Bittrex response to DepthData. | [
"Translate",
"the",
"Bittrex",
"response",
"to",
"DepthData",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L1099-L1112 |
19,696 | decred/dcrdata | exchanges/exchanges.go | Refresh | func (bittrex *BittrexExchange) Refresh() {
bittrex.LogRequest()
priceResponse := new(BittrexPriceResponse)
err := bittrex.fetch(bittrex.requests.price, priceResponse)
if err != nil {
bittrex.fail("Fetch", err)
return
}
if !priceResponse.Success {
bittrex.fail("Unsuccessful resquest", err)
return
}
if l... | go | func (bittrex *BittrexExchange) Refresh() {
bittrex.LogRequest()
priceResponse := new(BittrexPriceResponse)
err := bittrex.fetch(bittrex.requests.price, priceResponse)
if err != nil {
bittrex.fail("Fetch", err)
return
}
if !priceResponse.Success {
bittrex.fail("Unsuccessful resquest", err)
return
}
if l... | [
"func",
"(",
"bittrex",
"*",
"BittrexExchange",
")",
"Refresh",
"(",
")",
"{",
"bittrex",
".",
"LogRequest",
"(",
")",
"\n",
"priceResponse",
":=",
"new",
"(",
"BittrexPriceResponse",
")",
"\n",
"err",
":=",
"bittrex",
".",
"fetch",
"(",
"bittrex",
".",
... | // Refresh retrieves and parses API data from Bittrex.
// Bittrex provides timestamps in a string format that is not quite RFC 3339. | [
"Refresh",
"retrieves",
"and",
"parses",
"API",
"data",
"from",
"Bittrex",
".",
"Bittrex",
"provides",
"timestamps",
"in",
"a",
"string",
"format",
"that",
"is",
"not",
"quite",
"RFC",
"3339",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L1159-L1221 |
19,697 | decred/dcrdata | exchanges/exchanges.go | NewDragonEx | func NewDragonEx(client *http.Client, channels *BotChannels) (dragonex Exchange, err error) {
reqs := newRequests()
reqs.price, err = http.NewRequest(http.MethodGet, DragonExURLs.Price, nil)
if err != nil {
return
}
// Dragonex has separate endpoints for buy and sell, so the requests are
// stored as fields of... | go | func NewDragonEx(client *http.Client, channels *BotChannels) (dragonex Exchange, err error) {
reqs := newRequests()
reqs.price, err = http.NewRequest(http.MethodGet, DragonExURLs.Price, nil)
if err != nil {
return
}
// Dragonex has separate endpoints for buy and sell, so the requests are
// stored as fields of... | [
"func",
"NewDragonEx",
"(",
"client",
"*",
"http",
".",
"Client",
",",
"channels",
"*",
"BotChannels",
")",
"(",
"dragonex",
"Exchange",
",",
"err",
"error",
")",
"{",
"reqs",
":=",
"newRequests",
"(",
")",
"\n",
"reqs",
".",
"price",
",",
"err",
"=",
... | // NewDragonEx constructs a DragonExchange. | [
"NewDragonEx",
"constructs",
"a",
"DragonExchange",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L1232-L1266 |
19,698 | decred/dcrdata | exchanges/exchanges.go | NewHuobi | func NewHuobi(client *http.Client, channels *BotChannels) (huobi Exchange, err error) {
reqs := newRequests()
reqs.price, err = http.NewRequest(http.MethodGet, HuobiURLs.Price, nil)
if err != nil {
return
}
reqs.price.Header.Add("Content-Type", "application/x-www-form-urlencoded")
reqs.depth, err = http.NewReq... | go | func NewHuobi(client *http.Client, channels *BotChannels) (huobi Exchange, err error) {
reqs := newRequests()
reqs.price, err = http.NewRequest(http.MethodGet, HuobiURLs.Price, nil)
if err != nil {
return
}
reqs.price.Header.Add("Content-Type", "application/x-www-form-urlencoded")
reqs.depth, err = http.NewReq... | [
"func",
"NewHuobi",
"(",
"client",
"*",
"http",
".",
"Client",
",",
"channels",
"*",
"BotChannels",
")",
"(",
"huobi",
"Exchange",
",",
"err",
"error",
")",
"{",
"reqs",
":=",
"newRequests",
"(",
")",
"\n",
"reqs",
".",
"price",
",",
"err",
"=",
"htt... | // NewHuobi constructs a HuobiExchange. | [
"NewHuobi",
"constructs",
"a",
"HuobiExchange",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L1589-L1615 |
19,699 | decred/dcrdata | exchanges/exchanges.go | Refresh | func (huobi *HuobiExchange) Refresh() {
huobi.LogRequest()
priceResponse := new(HuobiPriceResponse)
err := huobi.fetch(huobi.requests.price, priceResponse)
if err != nil {
huobi.fail("Fetch", err)
return
}
if priceResponse.Status != huobi.Ok {
huobi.fail("Status not ok", fmt.Errorf("Expected status %s. Rece... | go | func (huobi *HuobiExchange) Refresh() {
huobi.LogRequest()
priceResponse := new(HuobiPriceResponse)
err := huobi.fetch(huobi.requests.price, priceResponse)
if err != nil {
huobi.fail("Fetch", err)
return
}
if priceResponse.Status != huobi.Ok {
huobi.fail("Status not ok", fmt.Errorf("Expected status %s. Rece... | [
"func",
"(",
"huobi",
"*",
"HuobiExchange",
")",
"Refresh",
"(",
")",
"{",
"huobi",
".",
"LogRequest",
"(",
")",
"\n",
"priceResponse",
":=",
"new",
"(",
"HuobiPriceResponse",
")",
"\n",
"err",
":=",
"huobi",
".",
"fetch",
"(",
"huobi",
".",
"requests",
... | // Refresh retrieves and parses API data from Huobi. | [
"Refresh",
"retrieves",
"and",
"parses",
"API",
"data",
"from",
"Huobi",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/exchanges.go#L1713-L1777 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.