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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
162,500 | btcsuite/btcd | mining/cpuminer/cpuminer.go | New | func New(cfg *Config) *CPUMiner {
return &CPUMiner{
g: cfg.BlockTemplateGenerator,
cfg: *cfg,
numWorkers: defaultNumWorkers,
updateNumWorkers: make(chan struct{}),
queryHashesPerSec: make(chan float64),
updateHashes: make(chan uint64),
}
} | go | func New(cfg *Config) *CPUMiner {
return &CPUMiner{
g: cfg.BlockTemplateGenerator,
cfg: *cfg,
numWorkers: defaultNumWorkers,
updateNumWorkers: make(chan struct{}),
queryHashesPerSec: make(chan float64),
updateHashes: make(chan uint64),
}
} | [
"func",
"New",
"(",
"cfg",
"*",
"Config",
")",
"*",
"CPUMiner",
"{",
"return",
"&",
"CPUMiner",
"{",
"g",
":",
"cfg",
".",
"BlockTemplateGenerator",
",",
"cfg",
":",
"*",
"cfg",
",",
"numWorkers",
":",
"defaultNumWorkers",
",",
"updateNumWorkers",
":",
"... | // New returns a new instance of a CPU miner for the provided configuration.
// Use Start to begin the mining process. See the documentation for CPUMiner
// type for more details. | [
"New",
"returns",
"a",
"new",
"instance",
"of",
"a",
"CPU",
"miner",
"for",
"the",
"provided",
"configuration",
".",
"Use",
"Start",
"to",
"begin",
"the",
"mining",
"process",
".",
"See",
"the",
"documentation",
"for",
"CPUMiner",
"type",
"for",
"more",
"d... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/mining/cpuminer/cpuminer.go#L633-L642 |
162,501 | btcsuite/btcd | btcjson/help.go | reflectTypeToJSONType | func reflectTypeToJSONType(xT descLookupFunc, rt reflect.Type) string {
kind := rt.Kind()
if isNumeric(kind) {
return xT("json-type-numeric")
}
switch kind {
case reflect.String:
return xT("json-type-string")
case reflect.Bool:
return xT("json-type-bool")
case reflect.Array, reflect.Slice:
return xT("... | go | func reflectTypeToJSONType(xT descLookupFunc, rt reflect.Type) string {
kind := rt.Kind()
if isNumeric(kind) {
return xT("json-type-numeric")
}
switch kind {
case reflect.String:
return xT("json-type-string")
case reflect.Bool:
return xT("json-type-bool")
case reflect.Array, reflect.Slice:
return xT("... | [
"func",
"reflectTypeToJSONType",
"(",
"xT",
"descLookupFunc",
",",
"rt",
"reflect",
".",
"Type",
")",
"string",
"{",
"kind",
":=",
"rt",
".",
"Kind",
"(",
")",
"\n",
"if",
"isNumeric",
"(",
"kind",
")",
"{",
"return",
"xT",
"(",
"\"",
"\"",
")",
"\n"... | // reflectTypeToJSONType returns a string that represents the JSON type
// associated with the provided Go type. | [
"reflectTypeToJSONType",
"returns",
"a",
"string",
"that",
"represents",
"the",
"JSON",
"type",
"associated",
"with",
"the",
"provided",
"Go",
"type",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/help.go#L49-L74 |
162,502 | btcsuite/btcd | btcjson/help.go | reflectTypeToJSONExample | func reflectTypeToJSONExample(xT descLookupFunc, rt reflect.Type, indentLevel int, fieldDescKey string) ([]string, bool) {
// Indirect pointer if needed.
if rt.Kind() == reflect.Ptr {
rt = rt.Elem()
}
kind := rt.Kind()
if isNumeric(kind) {
if kind == reflect.Float32 || kind == reflect.Float64 {
return []str... | go | func reflectTypeToJSONExample(xT descLookupFunc, rt reflect.Type, indentLevel int, fieldDescKey string) ([]string, bool) {
// Indirect pointer if needed.
if rt.Kind() == reflect.Ptr {
rt = rt.Elem()
}
kind := rt.Kind()
if isNumeric(kind) {
if kind == reflect.Float32 || kind == reflect.Float64 {
return []str... | [
"func",
"reflectTypeToJSONExample",
"(",
"xT",
"descLookupFunc",
",",
"rt",
"reflect",
".",
"Type",
",",
"indentLevel",
"int",
",",
"fieldDescKey",
"string",
")",
"(",
"[",
"]",
"string",
",",
"bool",
")",
"{",
"// Indirect pointer if needed.",
"if",
"rt",
"."... | // reflectTypeToJSONExample generates example usage in the format used by the
// help output. It handles arrays, slices and structs recursively. The output
// is returned as a slice of lines so the final help can be nicely aligned via
// a tab writer. A bool is also returned which specifies whether or not the
// typ... | [
"reflectTypeToJSONExample",
"generates",
"example",
"usage",
"in",
"the",
"format",
"used",
"by",
"the",
"help",
"output",
".",
"It",
"handles",
"arrays",
"slices",
"and",
"structs",
"recursively",
".",
"The",
"output",
"is",
"returned",
"as",
"a",
"slice",
"o... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/help.go#L143-L248 |
162,503 | btcsuite/btcd | btcjson/help.go | resultTypeHelp | func resultTypeHelp(xT descLookupFunc, rt reflect.Type, fieldDescKey string) string {
// Generate the JSON example for the result type.
results, isComplex := reflectTypeToJSONExample(xT, rt, 0, fieldDescKey)
// When this is a primitive type, add the associated JSON type and
// result description into the final str... | go | func resultTypeHelp(xT descLookupFunc, rt reflect.Type, fieldDescKey string) string {
// Generate the JSON example for the result type.
results, isComplex := reflectTypeToJSONExample(xT, rt, 0, fieldDescKey)
// When this is a primitive type, add the associated JSON type and
// result description into the final str... | [
"func",
"resultTypeHelp",
"(",
"xT",
"descLookupFunc",
",",
"rt",
"reflect",
".",
"Type",
",",
"fieldDescKey",
"string",
")",
"string",
"{",
"// Generate the JSON example for the result type.",
"results",
",",
"isComplex",
":=",
"reflectTypeToJSONExample",
"(",
"xT",
... | // resultTypeHelp generates and returns formatted help for the provided result
// type. | [
"resultTypeHelp",
"generates",
"and",
"returns",
"formatted",
"help",
"for",
"the",
"provided",
"result",
"type",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/help.go#L252-L279 |
162,504 | btcsuite/btcd | btcjson/help.go | argHelp | func argHelp(xT descLookupFunc, rtp reflect.Type, defaults map[int]reflect.Value, method string) string {
// Return now if the command has no arguments.
rt := rtp.Elem()
numFields := rt.NumField()
if numFields == 0 {
return ""
}
// Generate the help for each argument in the command. Several
// simplifying as... | go | func argHelp(xT descLookupFunc, rtp reflect.Type, defaults map[int]reflect.Value, method string) string {
// Return now if the command has no arguments.
rt := rtp.Elem()
numFields := rt.NumField()
if numFields == 0 {
return ""
}
// Generate the help for each argument in the command. Several
// simplifying as... | [
"func",
"argHelp",
"(",
"xT",
"descLookupFunc",
",",
"rtp",
"reflect",
".",
"Type",
",",
"defaults",
"map",
"[",
"int",
"]",
"reflect",
".",
"Value",
",",
"method",
"string",
")",
"string",
"{",
"// Return now if the command has no arguments.",
"rt",
":=",
"rt... | // argHelp generates and returns formatted help for the provided command. | [
"argHelp",
"generates",
"and",
"returns",
"formatted",
"help",
"for",
"the",
"provided",
"command",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/help.go#L328-L391 |
162,505 | btcsuite/btcd | btcjson/help.go | methodHelp | func methodHelp(xT descLookupFunc, rtp reflect.Type, defaults map[int]reflect.Value, method string, resultTypes []interface{}) string {
// Start off with the method usage and help synopsis.
help := fmt.Sprintf("%s\n\n%s\n", methodUsageText(rtp, defaults, method),
xT(method+"--synopsis"))
// Generate the help for ... | go | func methodHelp(xT descLookupFunc, rtp reflect.Type, defaults map[int]reflect.Value, method string, resultTypes []interface{}) string {
// Start off with the method usage and help synopsis.
help := fmt.Sprintf("%s\n\n%s\n", methodUsageText(rtp, defaults, method),
xT(method+"--synopsis"))
// Generate the help for ... | [
"func",
"methodHelp",
"(",
"xT",
"descLookupFunc",
",",
"rtp",
"reflect",
".",
"Type",
",",
"defaults",
"map",
"[",
"int",
"]",
"reflect",
".",
"Value",
",",
"method",
"string",
",",
"resultTypes",
"[",
"]",
"interface",
"{",
"}",
")",
"string",
"{",
"... | // methodHelp generates and returns the help output for the provided command
// and method info. This is the main work horse for the exported MethodHelp
// function. | [
"methodHelp",
"generates",
"and",
"returns",
"the",
"help",
"output",
"for",
"the",
"provided",
"command",
"and",
"method",
"info",
".",
"This",
"is",
"the",
"main",
"work",
"horse",
"for",
"the",
"exported",
"MethodHelp",
"function",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/help.go#L396-L441 |
162,506 | btcsuite/btcd | btcjson/help.go | isValidResultType | func isValidResultType(kind reflect.Kind) bool {
if isNumeric(kind) {
return true
}
switch kind {
case reflect.String, reflect.Struct, reflect.Array, reflect.Slice,
reflect.Bool, reflect.Map:
return true
}
return false
} | go | func isValidResultType(kind reflect.Kind) bool {
if isNumeric(kind) {
return true
}
switch kind {
case reflect.String, reflect.Struct, reflect.Array, reflect.Slice,
reflect.Bool, reflect.Map:
return true
}
return false
} | [
"func",
"isValidResultType",
"(",
"kind",
"reflect",
".",
"Kind",
")",
"bool",
"{",
"if",
"isNumeric",
"(",
"kind",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"switch",
"kind",
"{",
"case",
"reflect",
".",
"String",
",",
"reflect",
".",
"Struct",
"... | // isValidResultType returns whether the passed reflect kind is one of the
// acceptable types for results. | [
"isValidResultType",
"returns",
"whether",
"the",
"passed",
"reflect",
"kind",
"is",
"one",
"of",
"the",
"acceptable",
"types",
"for",
"results",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/help.go#L445-L458 |
162,507 | btcsuite/btcd | addrmgr/addrmanager.go | updateAddress | func (a *AddrManager) updateAddress(netAddr, srcAddr *wire.NetAddress) {
// Filter out non-routable addresses. Note that non-routable
// also includes invalid and local addresses.
if !IsRoutable(netAddr) {
return
}
addr := NetAddressKey(netAddr)
ka := a.find(netAddr)
if ka != nil {
// TODO: only update addr... | go | func (a *AddrManager) updateAddress(netAddr, srcAddr *wire.NetAddress) {
// Filter out non-routable addresses. Note that non-routable
// also includes invalid and local addresses.
if !IsRoutable(netAddr) {
return
}
addr := NetAddressKey(netAddr)
ka := a.find(netAddr)
if ka != nil {
// TODO: only update addr... | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"updateAddress",
"(",
"netAddr",
",",
"srcAddr",
"*",
"wire",
".",
"NetAddress",
")",
"{",
"// Filter out non-routable addresses. Note that non-routable",
"// also includes invalid and local addresses.",
"if",
"!",
"IsRoutable",
... | // updateAddress is a helper function to either update an address already known
// to the address manager, or to add the address if not already known. | [
"updateAddress",
"is",
"a",
"helper",
"function",
"to",
"either",
"update",
"an",
"address",
"already",
"known",
"to",
"the",
"address",
"manager",
"or",
"to",
"add",
"the",
"address",
"if",
"not",
"already",
"known",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L166-L238 |
162,508 | btcsuite/btcd | addrmgr/addrmanager.go | expireNew | func (a *AddrManager) expireNew(bucket int) {
// First see if there are any entries that are so bad we can just throw
// them away. otherwise we throw away the oldest entry in the cache.
// Bitcoind here chooses four random and just throws the oldest of
// those away, but we keep track of oldest in the initial trav... | go | func (a *AddrManager) expireNew(bucket int) {
// First see if there are any entries that are so bad we can just throw
// them away. otherwise we throw away the oldest entry in the cache.
// Bitcoind here chooses four random and just throws the oldest of
// those away, but we keep track of oldest in the initial trav... | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"expireNew",
"(",
"bucket",
"int",
")",
"{",
"// First see if there are any entries that are so bad we can just throw",
"// them away. otherwise we throw away the oldest entry in the cache.",
"// Bitcoind here chooses four random and just throws... | // expireNew makes space in the new buckets by expiring the really bad entries.
// If no bad entries are available we look at a few and remove the oldest. | [
"expireNew",
"makes",
"space",
"in",
"the",
"new",
"buckets",
"by",
"expiring",
"the",
"really",
"bad",
"entries",
".",
"If",
"no",
"bad",
"entries",
"are",
"available",
"we",
"look",
"at",
"a",
"few",
"and",
"remove",
"the",
"oldest",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L242-L278 |
162,509 | btcsuite/btcd | addrmgr/addrmanager.go | pickTried | func (a *AddrManager) pickTried(bucket int) *list.Element {
var oldest *KnownAddress
var oldestElem *list.Element
for e := a.addrTried[bucket].Front(); e != nil; e = e.Next() {
ka := e.Value.(*KnownAddress)
if oldest == nil || oldest.na.Timestamp.After(ka.na.Timestamp) {
oldestElem = e
oldest = ka
}
}
... | go | func (a *AddrManager) pickTried(bucket int) *list.Element {
var oldest *KnownAddress
var oldestElem *list.Element
for e := a.addrTried[bucket].Front(); e != nil; e = e.Next() {
ka := e.Value.(*KnownAddress)
if oldest == nil || oldest.na.Timestamp.After(ka.na.Timestamp) {
oldestElem = e
oldest = ka
}
}
... | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"pickTried",
"(",
"bucket",
"int",
")",
"*",
"list",
".",
"Element",
"{",
"var",
"oldest",
"*",
"KnownAddress",
"\n",
"var",
"oldestElem",
"*",
"list",
".",
"Element",
"\n",
"for",
"e",
":=",
"a",
".",
"addr... | // pickTried selects an address from the tried bucket to be evicted.
// We just choose the eldest. Bitcoind selects 4 random entries and throws away
// the older of them. | [
"pickTried",
"selects",
"an",
"address",
"from",
"the",
"tried",
"bucket",
"to",
"be",
"evicted",
".",
"We",
"just",
"choose",
"the",
"eldest",
".",
"Bitcoind",
"selects",
"4",
"random",
"entries",
"and",
"throws",
"away",
"the",
"older",
"of",
"them",
"."... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L283-L295 |
162,510 | btcsuite/btcd | addrmgr/addrmanager.go | addressHandler | func (a *AddrManager) addressHandler() {
dumpAddressTicker := time.NewTicker(dumpAddressInterval)
defer dumpAddressTicker.Stop()
out:
for {
select {
case <-dumpAddressTicker.C:
a.savePeers()
case <-a.quit:
break out
}
}
a.savePeers()
a.wg.Done()
log.Trace("Address handler done")
} | go | func (a *AddrManager) addressHandler() {
dumpAddressTicker := time.NewTicker(dumpAddressInterval)
defer dumpAddressTicker.Stop()
out:
for {
select {
case <-dumpAddressTicker.C:
a.savePeers()
case <-a.quit:
break out
}
}
a.savePeers()
a.wg.Done()
log.Trace("Address handler done")
} | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"addressHandler",
"(",
")",
"{",
"dumpAddressTicker",
":=",
"time",
".",
"NewTicker",
"(",
"dumpAddressInterval",
")",
"\n",
"defer",
"dumpAddressTicker",
".",
"Stop",
"(",
")",
"\n",
"out",
":",
"for",
"{",
"sele... | // addressHandler is the main handler for the address manager. It must be run
// as a goroutine. | [
"addressHandler",
"is",
"the",
"main",
"handler",
"for",
"the",
"address",
"manager",
".",
"It",
"must",
"be",
"run",
"as",
"a",
"goroutine",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L341-L357 |
162,511 | btcsuite/btcd | addrmgr/addrmanager.go | savePeers | func (a *AddrManager) savePeers() {
a.mtx.Lock()
defer a.mtx.Unlock()
// First we make a serialisable datastructure so we can encode it to
// json.
sam := new(serializedAddrManager)
sam.Version = a.version
copy(sam.Key[:], a.key[:])
sam.Addresses = make([]*serializedKnownAddress, len(a.addrIndex))
i := 0
fo... | go | func (a *AddrManager) savePeers() {
a.mtx.Lock()
defer a.mtx.Unlock()
// First we make a serialisable datastructure so we can encode it to
// json.
sam := new(serializedAddrManager)
sam.Version = a.version
copy(sam.Key[:], a.key[:])
sam.Addresses = make([]*serializedKnownAddress, len(a.addrIndex))
i := 0
fo... | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"savePeers",
"(",
")",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"// First we make a serialisable datastructure so we can encode it to",
"// json.",
... | // savePeers saves all the known addresses to a file so they can be read back
// in at next run. | [
"savePeers",
"saves",
"all",
"the",
"known",
"addresses",
"to",
"a",
"file",
"so",
"they",
"can",
"be",
"read",
"back",
"in",
"at",
"next",
"run",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L361-L419 |
162,512 | btcsuite/btcd | addrmgr/addrmanager.go | loadPeers | func (a *AddrManager) loadPeers() {
a.mtx.Lock()
defer a.mtx.Unlock()
err := a.deserializePeers(a.peersFile)
if err != nil {
log.Errorf("Failed to parse file %s: %v", a.peersFile, err)
// if it is invalid we nuke the old one unconditionally.
err = os.Remove(a.peersFile)
if err != nil {
log.Warnf("Failed... | go | func (a *AddrManager) loadPeers() {
a.mtx.Lock()
defer a.mtx.Unlock()
err := a.deserializePeers(a.peersFile)
if err != nil {
log.Errorf("Failed to parse file %s: %v", a.peersFile, err)
// if it is invalid we nuke the old one unconditionally.
err = os.Remove(a.peersFile)
if err != nil {
log.Warnf("Failed... | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"loadPeers",
"(",
")",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"err",
":=",
"a",
".",
"deserializePeers",
"(",
"a",
".",
"peersFile",... | // loadPeers loads the known address from the saved file. If empty, missing, or
// malformed file, just don't load anything and start fresh | [
"loadPeers",
"loads",
"the",
"known",
"address",
"from",
"the",
"saved",
"file",
".",
"If",
"empty",
"missing",
"or",
"malformed",
"file",
"just",
"don",
"t",
"load",
"anything",
"and",
"start",
"fresh"
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L423-L440 |
162,513 | btcsuite/btcd | addrmgr/addrmanager.go | Start | func (a *AddrManager) Start() {
// Already started?
if atomic.AddInt32(&a.started, 1) != 1 {
return
}
log.Trace("Starting address manager")
// Load peers we already know about from file.
a.loadPeers()
// Start the address ticker to save addresses periodically.
a.wg.Add(1)
go a.addressHandler()
} | go | func (a *AddrManager) Start() {
// Already started?
if atomic.AddInt32(&a.started, 1) != 1 {
return
}
log.Trace("Starting address manager")
// Load peers we already know about from file.
a.loadPeers()
// Start the address ticker to save addresses periodically.
a.wg.Add(1)
go a.addressHandler()
} | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"Start",
"(",
")",
"{",
"// Already started?",
"if",
"atomic",
".",
"AddInt32",
"(",
"&",
"a",
".",
"started",
",",
"1",
")",
"!=",
"1",
"{",
"return",
"\n",
"}",
"\n\n",
"log",
".",
"Trace",
"(",
"\"",
... | // Start begins the core address handler which manages a pool of known
// addresses, timeouts, and interval based writes. | [
"Start",
"begins",
"the",
"core",
"address",
"handler",
"which",
"manages",
"a",
"pool",
"of",
"known",
"addresses",
"timeouts",
"and",
"interval",
"based",
"writes",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L567-L581 |
162,514 | btcsuite/btcd | addrmgr/addrmanager.go | Stop | func (a *AddrManager) Stop() error {
if atomic.AddInt32(&a.shutdown, 1) != 1 {
log.Warnf("Address manager is already in the process of " +
"shutting down")
return nil
}
log.Infof("Address manager shutting down")
close(a.quit)
a.wg.Wait()
return nil
} | go | func (a *AddrManager) Stop() error {
if atomic.AddInt32(&a.shutdown, 1) != 1 {
log.Warnf("Address manager is already in the process of " +
"shutting down")
return nil
}
log.Infof("Address manager shutting down")
close(a.quit)
a.wg.Wait()
return nil
} | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"Stop",
"(",
")",
"error",
"{",
"if",
"atomic",
".",
"AddInt32",
"(",
"&",
"a",
".",
"shutdown",
",",
"1",
")",
"!=",
"1",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
")",
"\n",
"retu... | // Stop gracefully shuts down the address manager by stopping the main handler. | [
"Stop",
"gracefully",
"shuts",
"down",
"the",
"address",
"manager",
"by",
"stopping",
"the",
"main",
"handler",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L584-L595 |
162,515 | btcsuite/btcd | addrmgr/addrmanager.go | AddAddresses | func (a *AddrManager) AddAddresses(addrs []*wire.NetAddress, srcAddr *wire.NetAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
for _, na := range addrs {
a.updateAddress(na, srcAddr)
}
} | go | func (a *AddrManager) AddAddresses(addrs []*wire.NetAddress, srcAddr *wire.NetAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
for _, na := range addrs {
a.updateAddress(na, srcAddr)
}
} | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"AddAddresses",
"(",
"addrs",
"[",
"]",
"*",
"wire",
".",
"NetAddress",
",",
"srcAddr",
"*",
"wire",
".",
"NetAddress",
")",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
"... | // AddAddresses adds new addresses to the address manager. It enforces a max
// number of addresses and silently ignores duplicate addresses. It is
// safe for concurrent access. | [
"AddAddresses",
"adds",
"new",
"addresses",
"to",
"the",
"address",
"manager",
".",
"It",
"enforces",
"a",
"max",
"number",
"of",
"addresses",
"and",
"silently",
"ignores",
"duplicate",
"addresses",
".",
"It",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L600-L607 |
162,516 | btcsuite/btcd | addrmgr/addrmanager.go | AddAddress | func (a *AddrManager) AddAddress(addr, srcAddr *wire.NetAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
a.updateAddress(addr, srcAddr)
} | go | func (a *AddrManager) AddAddress(addr, srcAddr *wire.NetAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
a.updateAddress(addr, srcAddr)
} | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"AddAddress",
"(",
"addr",
",",
"srcAddr",
"*",
"wire",
".",
"NetAddress",
")",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"a",
".",
"... | // AddAddress adds a new address to the address manager. It enforces a max
// number of addresses and silently ignores duplicate addresses. It is
// safe for concurrent access. | [
"AddAddress",
"adds",
"a",
"new",
"address",
"to",
"the",
"address",
"manager",
".",
"It",
"enforces",
"a",
"max",
"number",
"of",
"addresses",
"and",
"silently",
"ignores",
"duplicate",
"addresses",
".",
"It",
"is",
"safe",
"for",
"concurrent",
"access",
".... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L612-L617 |
162,517 | btcsuite/btcd | addrmgr/addrmanager.go | NumAddresses | func (a *AddrManager) NumAddresses() int {
a.mtx.Lock()
defer a.mtx.Unlock()
return a.numAddresses()
} | go | func (a *AddrManager) NumAddresses() int {
a.mtx.Lock()
defer a.mtx.Unlock()
return a.numAddresses()
} | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"NumAddresses",
"(",
")",
"int",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"a",
".",
"numAddresses",
"(",
")",
"\n",
"}"
] | // NumAddresses returns the number of addresses known to the address manager. | [
"NumAddresses",
"returns",
"the",
"number",
"of",
"addresses",
"known",
"to",
"the",
"address",
"manager",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L647-L652 |
162,518 | btcsuite/btcd | addrmgr/addrmanager.go | NeedMoreAddresses | func (a *AddrManager) NeedMoreAddresses() bool {
a.mtx.Lock()
defer a.mtx.Unlock()
return a.numAddresses() < needAddressThreshold
} | go | func (a *AddrManager) NeedMoreAddresses() bool {
a.mtx.Lock()
defer a.mtx.Unlock()
return a.numAddresses() < needAddressThreshold
} | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"NeedMoreAddresses",
"(",
")",
"bool",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"a",
".",
"numAddresses",
"(",
")",
"<",
"ne... | // NeedMoreAddresses returns whether or not the address manager needs more
// addresses. | [
"NeedMoreAddresses",
"returns",
"whether",
"or",
"not",
"the",
"address",
"manager",
"needs",
"more",
"addresses",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L656-L661 |
162,519 | btcsuite/btcd | addrmgr/addrmanager.go | getAddresses | func (a *AddrManager) getAddresses() []*wire.NetAddress {
a.mtx.Lock()
defer a.mtx.Unlock()
addrIndexLen := len(a.addrIndex)
if addrIndexLen == 0 {
return nil
}
addrs := make([]*wire.NetAddress, 0, addrIndexLen)
for _, v := range a.addrIndex {
addrs = append(addrs, v.na)
}
return addrs
} | go | func (a *AddrManager) getAddresses() []*wire.NetAddress {
a.mtx.Lock()
defer a.mtx.Unlock()
addrIndexLen := len(a.addrIndex)
if addrIndexLen == 0 {
return nil
}
addrs := make([]*wire.NetAddress, 0, addrIndexLen)
for _, v := range a.addrIndex {
addrs = append(addrs, v.na)
}
return addrs
} | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"getAddresses",
"(",
")",
"[",
"]",
"*",
"wire",
".",
"NetAddress",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"addrIndexLen",
":=",
"le... | // getAddresses returns all of the addresses currently found within the
// manager's address cache. | [
"getAddresses",
"returns",
"all",
"of",
"the",
"addresses",
"currently",
"found",
"within",
"the",
"manager",
"s",
"address",
"cache",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L687-L702 |
162,520 | btcsuite/btcd | addrmgr/addrmanager.go | reset | func (a *AddrManager) reset() {
a.addrIndex = make(map[string]*KnownAddress)
// fill key with bytes from a good random source.
io.ReadFull(crand.Reader, a.key[:])
for i := range a.addrNew {
a.addrNew[i] = make(map[string]*KnownAddress)
}
for i := range a.addrTried {
a.addrTried[i] = list.New()
}
} | go | func (a *AddrManager) reset() {
a.addrIndex = make(map[string]*KnownAddress)
// fill key with bytes from a good random source.
io.ReadFull(crand.Reader, a.key[:])
for i := range a.addrNew {
a.addrNew[i] = make(map[string]*KnownAddress)
}
for i := range a.addrTried {
a.addrTried[i] = list.New()
}
} | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"reset",
"(",
")",
"{",
"a",
".",
"addrIndex",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"KnownAddress",
")",
"\n\n",
"// fill key with bytes from a good random source.",
"io",
".",
"ReadFull",
"(",
"crand",... | // reset resets the address manager by reinitialising the random source
// and allocating fresh empty bucket storage. | [
"reset",
"resets",
"the",
"address",
"manager",
"by",
"reinitialising",
"the",
"random",
"source",
"and",
"allocating",
"fresh",
"empty",
"bucket",
"storage",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L706-L718 |
162,521 | btcsuite/btcd | addrmgr/addrmanager.go | ipString | func ipString(na *wire.NetAddress) string {
if IsOnionCatTor(na) {
// We know now that na.IP is long enough.
base32 := base32.StdEncoding.EncodeToString(na.IP[6:])
return strings.ToLower(base32) + ".onion"
}
return na.IP.String()
} | go | func ipString(na *wire.NetAddress) string {
if IsOnionCatTor(na) {
// We know now that na.IP is long enough.
base32 := base32.StdEncoding.EncodeToString(na.IP[6:])
return strings.ToLower(base32) + ".onion"
}
return na.IP.String()
} | [
"func",
"ipString",
"(",
"na",
"*",
"wire",
".",
"NetAddress",
")",
"string",
"{",
"if",
"IsOnionCatTor",
"(",
"na",
")",
"{",
"// We know now that na.IP is long enough.",
"base32",
":=",
"base32",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"na",
".",
"IP... | // ipString returns a string for the ip from the provided NetAddress. If the
// ip is in the range used for Tor addresses then it will be transformed into
// the relevant .onion address. | [
"ipString",
"returns",
"a",
"string",
"for",
"the",
"ip",
"from",
"the",
"provided",
"NetAddress",
".",
"If",
"the",
"ip",
"is",
"in",
"the",
"range",
"used",
"for",
"Tor",
"addresses",
"then",
"it",
"will",
"be",
"transformed",
"into",
"the",
"relevant",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L754-L762 |
162,522 | btcsuite/btcd | addrmgr/addrmanager.go | GetAddress | func (a *AddrManager) GetAddress() *KnownAddress {
// Protect concurrent access.
a.mtx.Lock()
defer a.mtx.Unlock()
if a.numAddresses() == 0 {
return nil
}
// Use a 50% chance for choosing between tried and new table entries.
if a.nTried > 0 && (a.nNew == 0 || a.rand.Intn(2) == 0) {
// Tried entry.
large ... | go | func (a *AddrManager) GetAddress() *KnownAddress {
// Protect concurrent access.
a.mtx.Lock()
defer a.mtx.Unlock()
if a.numAddresses() == 0 {
return nil
}
// Use a 50% chance for choosing between tried and new table entries.
if a.nTried > 0 && (a.nNew == 0 || a.rand.Intn(2) == 0) {
// Tried entry.
large ... | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"GetAddress",
"(",
")",
"*",
"KnownAddress",
"{",
"// Protect concurrent access.",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"a",
".",
"nu... | // GetAddress returns a single address that should be routable. It picks a
// random one from the possible addresses with preference given to ones that
// have not been used recently and should not pick 'close' addresses
// consecutively. | [
"GetAddress",
"returns",
"a",
"single",
"address",
"that",
"should",
"be",
"routable",
".",
"It",
"picks",
"a",
"random",
"one",
"from",
"the",
"possible",
"addresses",
"with",
"preference",
"given",
"to",
"ones",
"that",
"have",
"not",
"been",
"used",
"rece... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L776-L841 |
162,523 | btcsuite/btcd | addrmgr/addrmanager.go | Attempt | func (a *AddrManager) Attempt(addr *wire.NetAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
// find address.
// Surely address will be in tried by now?
ka := a.find(addr)
if ka == nil {
return
}
// set last tried time to now
ka.attempts++
ka.lastattempt = time.Now()
} | go | func (a *AddrManager) Attempt(addr *wire.NetAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
// find address.
// Surely address will be in tried by now?
ka := a.find(addr)
if ka == nil {
return
}
// set last tried time to now
ka.attempts++
ka.lastattempt = time.Now()
} | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"Attempt",
"(",
"addr",
"*",
"wire",
".",
"NetAddress",
")",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"// find address.",
"// Surely addre... | // Attempt increases the given address' attempt counter and updates
// the last attempt time. | [
"Attempt",
"increases",
"the",
"given",
"address",
"attempt",
"counter",
"and",
"updates",
"the",
"last",
"attempt",
"time",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L849-L862 |
162,524 | btcsuite/btcd | addrmgr/addrmanager.go | Connected | func (a *AddrManager) Connected(addr *wire.NetAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
ka := a.find(addr)
if ka == nil {
return
}
// Update the time as long as it has been 20 minutes since last we did
// so.
now := time.Now()
if now.After(ka.na.Timestamp.Add(time.Minute * 20)) {
// ka.na is immutable... | go | func (a *AddrManager) Connected(addr *wire.NetAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
ka := a.find(addr)
if ka == nil {
return
}
// Update the time as long as it has been 20 minutes since last we did
// so.
now := time.Now()
if now.After(ka.na.Timestamp.Add(time.Minute * 20)) {
// ka.na is immutable... | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"Connected",
"(",
"addr",
"*",
"wire",
".",
"NetAddress",
")",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"ka",
":=",
"a",
".",
"find"... | // Connected Marks the given address as currently connected and working at the
// current time. The address must already be known to AddrManager else it will
// be ignored. | [
"Connected",
"Marks",
"the",
"given",
"address",
"as",
"currently",
"connected",
"and",
"working",
"at",
"the",
"current",
"time",
".",
"The",
"address",
"must",
"already",
"be",
"known",
"to",
"AddrManager",
"else",
"it",
"will",
"be",
"ignored",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L867-L885 |
162,525 | btcsuite/btcd | addrmgr/addrmanager.go | Good | func (a *AddrManager) Good(addr *wire.NetAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
ka := a.find(addr)
if ka == nil {
return
}
// ka.Timestamp is not updated here to avoid leaking information
// about currently connected peers.
now := time.Now()
ka.lastsuccess = now
ka.lastattempt = now
ka.attempts = 0... | go | func (a *AddrManager) Good(addr *wire.NetAddress) {
a.mtx.Lock()
defer a.mtx.Unlock()
ka := a.find(addr)
if ka == nil {
return
}
// ka.Timestamp is not updated here to avoid leaking information
// about currently connected peers.
now := time.Now()
ka.lastsuccess = now
ka.lastattempt = now
ka.attempts = 0... | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"Good",
"(",
"addr",
"*",
"wire",
".",
"NetAddress",
")",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"ka",
":=",
"a",
".",
"find",
"... | // Good marks the given address as good. To be called after a successful
// connection and version exchange. If the address is unknown to the address
// manager it will be ignored. | [
"Good",
"marks",
"the",
"given",
"address",
"as",
"good",
".",
"To",
"be",
"called",
"after",
"a",
"successful",
"connection",
"and",
"version",
"exchange",
".",
"If",
"the",
"address",
"is",
"unknown",
"to",
"the",
"address",
"manager",
"it",
"will",
"be"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L890-L974 |
162,526 | btcsuite/btcd | addrmgr/addrmanager.go | SetServices | func (a *AddrManager) SetServices(addr *wire.NetAddress, services wire.ServiceFlag) {
a.mtx.Lock()
defer a.mtx.Unlock()
ka := a.find(addr)
if ka == nil {
return
}
// Update the services if needed.
if ka.na.Services != services {
// ka.na is immutable, so replace it.
naCopy := *ka.na
naCopy.Services = s... | go | func (a *AddrManager) SetServices(addr *wire.NetAddress, services wire.ServiceFlag) {
a.mtx.Lock()
defer a.mtx.Unlock()
ka := a.find(addr)
if ka == nil {
return
}
// Update the services if needed.
if ka.na.Services != services {
// ka.na is immutable, so replace it.
naCopy := *ka.na
naCopy.Services = s... | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"SetServices",
"(",
"addr",
"*",
"wire",
".",
"NetAddress",
",",
"services",
"wire",
".",
"ServiceFlag",
")",
"{",
"a",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"mtx",
".",
"Unlock",
"("... | // SetServices sets the services for the giiven address to the provided value. | [
"SetServices",
"sets",
"the",
"services",
"for",
"the",
"giiven",
"address",
"to",
"the",
"provided",
"value",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L977-L993 |
162,527 | btcsuite/btcd | addrmgr/addrmanager.go | AddLocalAddress | func (a *AddrManager) AddLocalAddress(na *wire.NetAddress, priority AddressPriority) error {
if !IsRoutable(na) {
return fmt.Errorf("address %s is not routable", na.IP)
}
a.lamtx.Lock()
defer a.lamtx.Unlock()
key := NetAddressKey(na)
la, ok := a.localAddresses[key]
if !ok || la.score < priority {
if ok {
... | go | func (a *AddrManager) AddLocalAddress(na *wire.NetAddress, priority AddressPriority) error {
if !IsRoutable(na) {
return fmt.Errorf("address %s is not routable", na.IP)
}
a.lamtx.Lock()
defer a.lamtx.Unlock()
key := NetAddressKey(na)
la, ok := a.localAddresses[key]
if !ok || la.score < priority {
if ok {
... | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"AddLocalAddress",
"(",
"na",
"*",
"wire",
".",
"NetAddress",
",",
"priority",
"AddressPriority",
")",
"error",
"{",
"if",
"!",
"IsRoutable",
"(",
"na",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"... | // AddLocalAddress adds na to the list of known local addresses to advertise
// with the given priority. | [
"AddLocalAddress",
"adds",
"na",
"to",
"the",
"list",
"of",
"known",
"local",
"addresses",
"to",
"advertise",
"with",
"the",
"given",
"priority",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L997-L1018 |
162,528 | btcsuite/btcd | addrmgr/addrmanager.go | getReachabilityFrom | func getReachabilityFrom(localAddr, remoteAddr *wire.NetAddress) int {
const (
Unreachable = 0
Default = iota
Teredo
Ipv6Weak
Ipv4
Ipv6Strong
Private
)
if !IsRoutable(remoteAddr) {
return Unreachable
}
if IsOnionCatTor(remoteAddr) {
if IsOnionCatTor(localAddr) {
return Private
}
if ... | go | func getReachabilityFrom(localAddr, remoteAddr *wire.NetAddress) int {
const (
Unreachable = 0
Default = iota
Teredo
Ipv6Weak
Ipv4
Ipv6Strong
Private
)
if !IsRoutable(remoteAddr) {
return Unreachable
}
if IsOnionCatTor(remoteAddr) {
if IsOnionCatTor(localAddr) {
return Private
}
if ... | [
"func",
"getReachabilityFrom",
"(",
"localAddr",
",",
"remoteAddr",
"*",
"wire",
".",
"NetAddress",
")",
"int",
"{",
"const",
"(",
"Unreachable",
"=",
"0",
"\n",
"Default",
"=",
"iota",
"\n",
"Teredo",
"\n",
"Ipv6Weak",
"\n",
"Ipv4",
"\n",
"Ipv6Strong",
"\... | // getReachabilityFrom returns the relative reachability of the provided local
// address to the provided remote address. | [
"getReachabilityFrom",
"returns",
"the",
"relative",
"reachability",
"of",
"the",
"provided",
"local",
"address",
"to",
"the",
"provided",
"remote",
"address",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L1022-L1097 |
162,529 | btcsuite/btcd | addrmgr/addrmanager.go | GetBestLocalAddress | func (a *AddrManager) GetBestLocalAddress(remoteAddr *wire.NetAddress) *wire.NetAddress {
a.lamtx.Lock()
defer a.lamtx.Unlock()
bestreach := 0
var bestscore AddressPriority
var bestAddress *wire.NetAddress
for _, la := range a.localAddresses {
reach := getReachabilityFrom(la.na, remoteAddr)
if reach > bestre... | go | func (a *AddrManager) GetBestLocalAddress(remoteAddr *wire.NetAddress) *wire.NetAddress {
a.lamtx.Lock()
defer a.lamtx.Unlock()
bestreach := 0
var bestscore AddressPriority
var bestAddress *wire.NetAddress
for _, la := range a.localAddresses {
reach := getReachabilityFrom(la.na, remoteAddr)
if reach > bestre... | [
"func",
"(",
"a",
"*",
"AddrManager",
")",
"GetBestLocalAddress",
"(",
"remoteAddr",
"*",
"wire",
".",
"NetAddress",
")",
"*",
"wire",
".",
"NetAddress",
"{",
"a",
".",
"lamtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"lamtx",
".",
"Unlock",
... | // GetBestLocalAddress returns the most appropriate local address to use
// for the given remote address. | [
"GetBestLocalAddress",
"returns",
"the",
"most",
"appropriate",
"local",
"address",
"to",
"use",
"for",
"the",
"given",
"remote",
"address",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L1101-L1136 |
162,530 | btcsuite/btcd | addrmgr/addrmanager.go | New | func New(dataDir string, lookupFunc func(string) ([]net.IP, error)) *AddrManager {
am := AddrManager{
peersFile: filepath.Join(dataDir, "peers.json"),
lookupFunc: lookupFunc,
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
quit: make(chan struct{}),
localAddresses: make(ma... | go | func New(dataDir string, lookupFunc func(string) ([]net.IP, error)) *AddrManager {
am := AddrManager{
peersFile: filepath.Join(dataDir, "peers.json"),
lookupFunc: lookupFunc,
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
quit: make(chan struct{}),
localAddresses: make(ma... | [
"func",
"New",
"(",
"dataDir",
"string",
",",
"lookupFunc",
"func",
"(",
"string",
")",
"(",
"[",
"]",
"net",
".",
"IP",
",",
"error",
")",
")",
"*",
"AddrManager",
"{",
"am",
":=",
"AddrManager",
"{",
"peersFile",
":",
"filepath",
".",
"Join",
"(",
... | // New returns a new bitcoin address manager.
// Use Start to begin processing asynchronous address updates. | [
"New",
"returns",
"a",
"new",
"bitcoin",
"address",
"manager",
".",
"Use",
"Start",
"to",
"begin",
"processing",
"asynchronous",
"address",
"updates",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/addrmgr/addrmanager.go#L1140-L1151 |
162,531 | btcsuite/btcd | wire/msgcfcheckpt.go | AddCFHeader | func (msg *MsgCFCheckpt) AddCFHeader(header *chainhash.Hash) error {
if len(msg.FilterHeaders) == cap(msg.FilterHeaders) {
str := fmt.Sprintf("FilterHeaders has insufficient capacity for "+
"additional header: len = %d", len(msg.FilterHeaders))
return messageError("MsgCFCheckpt.AddCFHeader", str)
}
msg.Filte... | go | func (msg *MsgCFCheckpt) AddCFHeader(header *chainhash.Hash) error {
if len(msg.FilterHeaders) == cap(msg.FilterHeaders) {
str := fmt.Sprintf("FilterHeaders has insufficient capacity for "+
"additional header: len = %d", len(msg.FilterHeaders))
return messageError("MsgCFCheckpt.AddCFHeader", str)
}
msg.Filte... | [
"func",
"(",
"msg",
"*",
"MsgCFCheckpt",
")",
"AddCFHeader",
"(",
"header",
"*",
"chainhash",
".",
"Hash",
")",
"error",
"{",
"if",
"len",
"(",
"msg",
".",
"FilterHeaders",
")",
"==",
"cap",
"(",
"msg",
".",
"FilterHeaders",
")",
"{",
"str",
":=",
"f... | // AddCFHeader adds a new committed filter header to the message. | [
"AddCFHeader",
"adds",
"a",
"new",
"committed",
"filter",
"header",
"to",
"the",
"message",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/msgcfcheckpt.go#L41-L50 |
162,532 | btcsuite/btcd | wire/msgcfcheckpt.go | NewMsgCFCheckpt | func NewMsgCFCheckpt(filterType FilterType, stopHash *chainhash.Hash,
headersCount int) *MsgCFCheckpt {
return &MsgCFCheckpt{
FilterType: filterType,
StopHash: *stopHash,
FilterHeaders: make([]*chainhash.Hash, 0, headersCount),
}
} | go | func NewMsgCFCheckpt(filterType FilterType, stopHash *chainhash.Hash,
headersCount int) *MsgCFCheckpt {
return &MsgCFCheckpt{
FilterType: filterType,
StopHash: *stopHash,
FilterHeaders: make([]*chainhash.Hash, 0, headersCount),
}
} | [
"func",
"NewMsgCFCheckpt",
"(",
"filterType",
"FilterType",
",",
"stopHash",
"*",
"chainhash",
".",
"Hash",
",",
"headersCount",
"int",
")",
"*",
"MsgCFCheckpt",
"{",
"return",
"&",
"MsgCFCheckpt",
"{",
"FilterType",
":",
"filterType",
",",
"StopHash",
":",
"*... | // NewMsgCFCheckpt returns a new bitcoin cfheaders message that conforms to
// the Message interface. See MsgCFCheckpt for details. | [
"NewMsgCFCheckpt",
"returns",
"a",
"new",
"bitcoin",
"cfheaders",
"message",
"that",
"conforms",
"to",
"the",
"Message",
"interface",
".",
"See",
"MsgCFCheckpt",
"for",
"details",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/msgcfcheckpt.go#L157-L164 |
162,533 | btcsuite/btcd | blockchain/error.go | ruleError | func ruleError(c ErrorCode, desc string) RuleError {
return RuleError{ErrorCode: c, Description: desc}
} | go | func ruleError(c ErrorCode, desc string) RuleError {
return RuleError{ErrorCode: c, Description: desc}
} | [
"func",
"ruleError",
"(",
"c",
"ErrorCode",
",",
"desc",
"string",
")",
"RuleError",
"{",
"return",
"RuleError",
"{",
"ErrorCode",
":",
"c",
",",
"Description",
":",
"desc",
"}",
"\n",
"}"
] | // ruleError creates an RuleError given a set of arguments. | [
"ruleError",
"creates",
"an",
"RuleError",
"given",
"a",
"set",
"of",
"arguments",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/error.go#L296-L298 |
162,534 | btcsuite/btcd | wire/error.go | messageError | func messageError(f string, desc string) *MessageError {
return &MessageError{Func: f, Description: desc}
} | go | func messageError(f string, desc string) *MessageError {
return &MessageError{Func: f, Description: desc}
} | [
"func",
"messageError",
"(",
"f",
"string",
",",
"desc",
"string",
")",
"*",
"MessageError",
"{",
"return",
"&",
"MessageError",
"{",
"Func",
":",
"f",
",",
"Description",
":",
"desc",
"}",
"\n",
"}"
] | // messageError creates an error for the given function and description. | [
"messageError",
"creates",
"an",
"error",
"for",
"the",
"given",
"function",
"and",
"description",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/error.go#L32-L34 |
162,535 | btcsuite/btcd | blockchain/chainview.go | newChainView | func newChainView(tip *blockNode) *chainView {
// The mutex is intentionally not held since this is a constructor.
var c chainView
c.setTip(tip)
return &c
} | go | func newChainView(tip *blockNode) *chainView {
// The mutex is intentionally not held since this is a constructor.
var c chainView
c.setTip(tip)
return &c
} | [
"func",
"newChainView",
"(",
"tip",
"*",
"blockNode",
")",
"*",
"chainView",
"{",
"// The mutex is intentionally not held since this is a constructor.",
"var",
"c",
"chainView",
"\n",
"c",
".",
"setTip",
"(",
"tip",
")",
"\n",
"return",
"&",
"c",
"\n",
"}"
] | // newChainView returns a new chain view for the given tip block node. Passing
// nil as the tip will result in a chain view that is not initialized. The tip
// can be updated at any time via the setTip function. | [
"newChainView",
"returns",
"a",
"new",
"chain",
"view",
"for",
"the",
"given",
"tip",
"block",
"node",
".",
"Passing",
"nil",
"as",
"the",
"tip",
"will",
"result",
"in",
"a",
"chain",
"view",
"that",
"is",
"not",
"initialized",
".",
"The",
"tip",
"can",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chainview.go#L52-L57 |
162,536 | btcsuite/btcd | blockchain/chainview.go | Genesis | func (c *chainView) Genesis() *blockNode {
c.mtx.Lock()
genesis := c.genesis()
c.mtx.Unlock()
return genesis
} | go | func (c *chainView) Genesis() *blockNode {
c.mtx.Lock()
genesis := c.genesis()
c.mtx.Unlock()
return genesis
} | [
"func",
"(",
"c",
"*",
"chainView",
")",
"Genesis",
"(",
")",
"*",
"blockNode",
"{",
"c",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"genesis",
":=",
"c",
".",
"genesis",
"(",
")",
"\n",
"c",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"return",
... | // Genesis returns the genesis block for the chain view.
//
// This function is safe for concurrent access. | [
"Genesis",
"returns",
"the",
"genesis",
"block",
"for",
"the",
"chain",
"view",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chainview.go#L75-L80 |
162,537 | btcsuite/btcd | blockchain/chainview.go | Tip | func (c *chainView) Tip() *blockNode {
c.mtx.Lock()
tip := c.tip()
c.mtx.Unlock()
return tip
} | go | func (c *chainView) Tip() *blockNode {
c.mtx.Lock()
tip := c.tip()
c.mtx.Unlock()
return tip
} | [
"func",
"(",
"c",
"*",
"chainView",
")",
"Tip",
"(",
")",
"*",
"blockNode",
"{",
"c",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"tip",
":=",
"c",
".",
"tip",
"(",
")",
"\n",
"c",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"return",
"tip",
"\... | // Tip returns the current tip block node for the chain view. It will return
// nil if there is no tip.
//
// This function is safe for concurrent access. | [
"Tip",
"returns",
"the",
"current",
"tip",
"block",
"node",
"for",
"the",
"chain",
"view",
".",
"It",
"will",
"return",
"nil",
"if",
"there",
"is",
"no",
"tip",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chainview.go#L99-L104 |
162,538 | btcsuite/btcd | blockchain/chainview.go | SetTip | func (c *chainView) SetTip(node *blockNode) {
c.mtx.Lock()
c.setTip(node)
c.mtx.Unlock()
} | go | func (c *chainView) SetTip(node *blockNode) {
c.mtx.Lock()
c.setTip(node)
c.mtx.Unlock()
} | [
"func",
"(",
"c",
"*",
"chainView",
")",
"SetTip",
"(",
"node",
"*",
"blockNode",
")",
"{",
"c",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"setTip",
"(",
"node",
")",
"\n",
"c",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // SetTip sets the chain view to use the provided block node as the current tip
// and ensures the view is consistent by populating it with the nodes obtained
// by walking backwards all the way to genesis block as necessary. Further
// calls will only perform the minimum work needed, so switching between chain
// tip... | [
"SetTip",
"sets",
"the",
"chain",
"view",
"to",
"use",
"the",
"provided",
"block",
"node",
"as",
"the",
"current",
"tip",
"and",
"ensures",
"the",
"view",
"is",
"consistent",
"by",
"populating",
"it",
"with",
"the",
"nodes",
"obtained",
"by",
"walking",
"b... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chainview.go#L155-L159 |
162,539 | btcsuite/btcd | blockchain/chainview.go | NodeByHeight | func (c *chainView) NodeByHeight(height int32) *blockNode {
c.mtx.Lock()
node := c.nodeByHeight(height)
c.mtx.Unlock()
return node
} | go | func (c *chainView) NodeByHeight(height int32) *blockNode {
c.mtx.Lock()
node := c.nodeByHeight(height)
c.mtx.Unlock()
return node
} | [
"func",
"(",
"c",
"*",
"chainView",
")",
"NodeByHeight",
"(",
"height",
"int32",
")",
"*",
"blockNode",
"{",
"c",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"node",
":=",
"c",
".",
"nodeByHeight",
"(",
"height",
")",
"\n",
"c",
".",
"mtx",
".",
"Un... | // NodeByHeight returns the block node at the specified height. Nil will be
// returned if the height does not exist.
//
// This function is safe for concurrent access. | [
"NodeByHeight",
"returns",
"the",
"block",
"node",
"at",
"the",
"specified",
"height",
".",
"Nil",
"will",
"be",
"returned",
"if",
"the",
"height",
"does",
"not",
"exist",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chainview.go#L200-L205 |
162,540 | btcsuite/btcd | blockchain/chainview.go | Contains | func (c *chainView) Contains(node *blockNode) bool {
c.mtx.Lock()
contains := c.contains(node)
c.mtx.Unlock()
return contains
} | go | func (c *chainView) Contains(node *blockNode) bool {
c.mtx.Lock()
contains := c.contains(node)
c.mtx.Unlock()
return contains
} | [
"func",
"(",
"c",
"*",
"chainView",
")",
"Contains",
"(",
"node",
"*",
"blockNode",
")",
"bool",
"{",
"c",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"contains",
":=",
"c",
".",
"contains",
"(",
"node",
")",
"\n",
"c",
".",
"mtx",
".",
"Unlock",
... | // Contains returns whether or not the chain view contains the passed block
// node.
//
// This function is safe for concurrent access. | [
"Contains",
"returns",
"whether",
"or",
"not",
"the",
"chain",
"view",
"contains",
"the",
"passed",
"block",
"node",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chainview.go#L233-L238 |
162,541 | btcsuite/btcd | blockchain/chainview.go | BlockLocator | func (c *chainView) BlockLocator(node *blockNode) BlockLocator {
c.mtx.Lock()
locator := c.blockLocator(node)
c.mtx.Unlock()
return locator
} | go | func (c *chainView) BlockLocator(node *blockNode) BlockLocator {
c.mtx.Lock()
locator := c.blockLocator(node)
c.mtx.Unlock()
return locator
} | [
"func",
"(",
"c",
"*",
"chainView",
")",
"BlockLocator",
"(",
"node",
"*",
"blockNode",
")",
"BlockLocator",
"{",
"c",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"locator",
":=",
"c",
".",
"blockLocator",
"(",
"node",
")",
"\n",
"c",
".",
"mtx",
".",... | // BlockLocator returns a block locator for the passed block node. The passed
// node can be nil in which case the block locator for the current tip
// associated with the view will be returned.
//
// See the BlockLocator type for details on the algorithm used to create a block
// locator.
//
// This function is safe ... | [
"BlockLocator",
"returns",
"a",
"block",
"locator",
"for",
"the",
"passed",
"block",
"node",
".",
"The",
"passed",
"node",
"can",
"be",
"nil",
"in",
"which",
"case",
"the",
"block",
"locator",
"for",
"the",
"current",
"tip",
"associated",
"with",
"the",
"v... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chainview.go#L418-L423 |
162,542 | btcsuite/btcd | txscript/script.go | isSmallInt | func isSmallInt(op *opcode) bool {
if op.value == OP_0 || (op.value >= OP_1 && op.value <= OP_16) {
return true
}
return false
} | go | func isSmallInt(op *opcode) bool {
if op.value == OP_0 || (op.value >= OP_1 && op.value <= OP_16) {
return true
}
return false
} | [
"func",
"isSmallInt",
"(",
"op",
"*",
"opcode",
")",
"bool",
"{",
"if",
"op",
".",
"value",
"==",
"OP_0",
"||",
"(",
"op",
".",
"value",
">=",
"OP_1",
"&&",
"op",
".",
"value",
"<=",
"OP_16",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",... | // isSmallInt returns whether or not the opcode is considered a small integer,
// which is an OP_0, or OP_1 through OP_16. | [
"isSmallInt",
"returns",
"whether",
"or",
"not",
"the",
"opcode",
"is",
"considered",
"a",
"small",
"integer",
"which",
"is",
"an",
"OP_0",
"or",
"OP_1",
"through",
"OP_16",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L47-L52 |
162,543 | btcsuite/btcd | txscript/script.go | isScriptHash | func isScriptHash(pops []parsedOpcode) bool {
return len(pops) == 3 &&
pops[0].opcode.value == OP_HASH160 &&
pops[1].opcode.value == OP_DATA_20 &&
pops[2].opcode.value == OP_EQUAL
} | go | func isScriptHash(pops []parsedOpcode) bool {
return len(pops) == 3 &&
pops[0].opcode.value == OP_HASH160 &&
pops[1].opcode.value == OP_DATA_20 &&
pops[2].opcode.value == OP_EQUAL
} | [
"func",
"isScriptHash",
"(",
"pops",
"[",
"]",
"parsedOpcode",
")",
"bool",
"{",
"return",
"len",
"(",
"pops",
")",
"==",
"3",
"&&",
"pops",
"[",
"0",
"]",
".",
"opcode",
".",
"value",
"==",
"OP_HASH160",
"&&",
"pops",
"[",
"1",
"]",
".",
"opcode",... | // isScriptHash returns true if the script passed is a pay-to-script-hash
// transaction, false otherwise. | [
"isScriptHash",
"returns",
"true",
"if",
"the",
"script",
"passed",
"is",
"a",
"pay",
"-",
"to",
"-",
"script",
"-",
"hash",
"transaction",
"false",
"otherwise",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L56-L61 |
162,544 | btcsuite/btcd | txscript/script.go | isWitnessScriptHash | func isWitnessScriptHash(pops []parsedOpcode) bool {
return len(pops) == 2 &&
pops[0].opcode.value == OP_0 &&
pops[1].opcode.value == OP_DATA_32
} | go | func isWitnessScriptHash(pops []parsedOpcode) bool {
return len(pops) == 2 &&
pops[0].opcode.value == OP_0 &&
pops[1].opcode.value == OP_DATA_32
} | [
"func",
"isWitnessScriptHash",
"(",
"pops",
"[",
"]",
"parsedOpcode",
")",
"bool",
"{",
"return",
"len",
"(",
"pops",
")",
"==",
"2",
"&&",
"pops",
"[",
"0",
"]",
".",
"opcode",
".",
"value",
"==",
"OP_0",
"&&",
"pops",
"[",
"1",
"]",
".",
"opcode"... | // isWitnessScriptHash returns true if the passed script is a
// pay-to-witness-script-hash transaction, false otherwise. | [
"isWitnessScriptHash",
"returns",
"true",
"if",
"the",
"passed",
"script",
"is",
"a",
"pay",
"-",
"to",
"-",
"witness",
"-",
"script",
"-",
"hash",
"transaction",
"false",
"otherwise",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L75-L79 |
162,545 | btcsuite/btcd | txscript/script.go | isWitnessPubKeyHash | func isWitnessPubKeyHash(pops []parsedOpcode) bool {
return len(pops) == 2 &&
pops[0].opcode.value == OP_0 &&
pops[1].opcode.value == OP_DATA_20
} | go | func isWitnessPubKeyHash(pops []parsedOpcode) bool {
return len(pops) == 2 &&
pops[0].opcode.value == OP_0 &&
pops[1].opcode.value == OP_DATA_20
} | [
"func",
"isWitnessPubKeyHash",
"(",
"pops",
"[",
"]",
"parsedOpcode",
")",
"bool",
"{",
"return",
"len",
"(",
"pops",
")",
"==",
"2",
"&&",
"pops",
"[",
"0",
"]",
".",
"opcode",
".",
"value",
"==",
"OP_0",
"&&",
"pops",
"[",
"1",
"]",
".",
"opcode"... | // isWitnessPubKeyHash returns true if the passed script is a
// pay-to-witness-pubkey-hash, and false otherwise. | [
"isWitnessPubKeyHash",
"returns",
"true",
"if",
"the",
"passed",
"script",
"is",
"a",
"pay",
"-",
"to",
"-",
"witness",
"-",
"pubkey",
"-",
"hash",
"and",
"false",
"otherwise",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L103-L107 |
162,546 | btcsuite/btcd | txscript/script.go | ExtractWitnessProgramInfo | func ExtractWitnessProgramInfo(script []byte) (int, []byte, error) {
pops, err := parseScript(script)
if err != nil {
return 0, nil, err
}
// If at this point, the scripts doesn't resemble a witness program,
// then we'll exit early as there isn't a valid version or program to
// extract.
if !isWitnessProgram... | go | func ExtractWitnessProgramInfo(script []byte) (int, []byte, error) {
pops, err := parseScript(script)
if err != nil {
return 0, nil, err
}
// If at this point, the scripts doesn't resemble a witness program,
// then we'll exit early as there isn't a valid version or program to
// extract.
if !isWitnessProgram... | [
"func",
"ExtractWitnessProgramInfo",
"(",
"script",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"pops",
",",
"err",
":=",
"parseScript",
"(",
"script",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
"... | // ExtractWitnessProgramInfo attempts to extract the witness program version,
// as well as the witness program itself from the passed script. | [
"ExtractWitnessProgramInfo",
"attempts",
"to",
"extract",
"the",
"witness",
"program",
"version",
"as",
"well",
"as",
"the",
"witness",
"program",
"itself",
"from",
"the",
"passed",
"script",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L145-L163 |
162,547 | btcsuite/btcd | txscript/script.go | isPushOnly | func isPushOnly(pops []parsedOpcode) bool {
// NOTE: This function does NOT verify opcodes directly since it is
// internal and is only called with parsed opcodes for scripts that did
// not have any parse errors. Thus, consensus is properly maintained.
for _, pop := range pops {
// All opcodes up to OP_16 are ... | go | func isPushOnly(pops []parsedOpcode) bool {
// NOTE: This function does NOT verify opcodes directly since it is
// internal and is only called with parsed opcodes for scripts that did
// not have any parse errors. Thus, consensus is properly maintained.
for _, pop := range pops {
// All opcodes up to OP_16 are ... | [
"func",
"isPushOnly",
"(",
"pops",
"[",
"]",
"parsedOpcode",
")",
"bool",
"{",
"// NOTE: This function does NOT verify opcodes directly since it is",
"// internal and is only called with parsed opcodes for scripts that did",
"// not have any parse errors. Thus, consensus is properly maintai... | // isPushOnly returns true if the script only pushes data, false otherwise. | [
"isPushOnly",
"returns",
"true",
"if",
"the",
"script",
"only",
"pushes",
"data",
"false",
"otherwise",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L166-L181 |
162,548 | btcsuite/btcd | txscript/script.go | IsPushOnlyScript | func IsPushOnlyScript(script []byte) bool {
pops, err := parseScript(script)
if err != nil {
return false
}
return isPushOnly(pops)
} | go | func IsPushOnlyScript(script []byte) bool {
pops, err := parseScript(script)
if err != nil {
return false
}
return isPushOnly(pops)
} | [
"func",
"IsPushOnlyScript",
"(",
"script",
"[",
"]",
"byte",
")",
"bool",
"{",
"pops",
",",
"err",
":=",
"parseScript",
"(",
"script",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"isPushOnly",
"(",
"pops",
... | // IsPushOnlyScript returns whether or not the passed script only pushes data.
//
// False will be returned when the script does not parse. | [
"IsPushOnlyScript",
"returns",
"whether",
"or",
"not",
"the",
"passed",
"script",
"only",
"pushes",
"data",
".",
"False",
"will",
"be",
"returned",
"when",
"the",
"script",
"does",
"not",
"parse",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L186-L192 |
162,549 | btcsuite/btcd | txscript/script.go | parseScriptTemplate | func parseScriptTemplate(script []byte, opcodes *[256]opcode) ([]parsedOpcode, error) {
retScript := make([]parsedOpcode, 0, len(script))
for i := 0; i < len(script); {
instr := script[i]
op := &opcodes[instr]
pop := parsedOpcode{opcode: op}
// Parse data out of instruction.
switch {
// No additional dat... | go | func parseScriptTemplate(script []byte, opcodes *[256]opcode) ([]parsedOpcode, error) {
retScript := make([]parsedOpcode, 0, len(script))
for i := 0; i < len(script); {
instr := script[i]
op := &opcodes[instr]
pop := parsedOpcode{opcode: op}
// Parse data out of instruction.
switch {
// No additional dat... | [
"func",
"parseScriptTemplate",
"(",
"script",
"[",
"]",
"byte",
",",
"opcodes",
"*",
"[",
"256",
"]",
"opcode",
")",
"(",
"[",
"]",
"parsedOpcode",
",",
"error",
")",
"{",
"retScript",
":=",
"make",
"(",
"[",
"]",
"parsedOpcode",
",",
"0",
",",
"len"... | // parseScriptTemplate is the same as parseScript but allows the passing of the
// template list for testing purposes. When there are parse errors, it returns
// the list of parsed opcodes up to the point of failure along with the error. | [
"parseScriptTemplate",
"is",
"the",
"same",
"as",
"parseScript",
"but",
"allows",
"the",
"passing",
"of",
"the",
"template",
"list",
"for",
"testing",
"purposes",
".",
"When",
"there",
"are",
"parse",
"errors",
"it",
"returns",
"the",
"list",
"of",
"parsed",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L197-L279 |
162,550 | btcsuite/btcd | txscript/script.go | unparseScript | func unparseScript(pops []parsedOpcode) ([]byte, error) {
script := make([]byte, 0, len(pops))
for _, pop := range pops {
b, err := pop.bytes()
if err != nil {
return nil, err
}
script = append(script, b...)
}
return script, nil
} | go | func unparseScript(pops []parsedOpcode) ([]byte, error) {
script := make([]byte, 0, len(pops))
for _, pop := range pops {
b, err := pop.bytes()
if err != nil {
return nil, err
}
script = append(script, b...)
}
return script, nil
} | [
"func",
"unparseScript",
"(",
"pops",
"[",
"]",
"parsedOpcode",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"script",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"len",
"(",
"pops",
")",
")",
"\n",
"for",
"_",
",",
"pop",
":=",
... | // unparseScript reversed the action of parseScript and returns the
// parsedOpcodes as a list of bytes | [
"unparseScript",
"reversed",
"the",
"action",
"of",
"parseScript",
"and",
"returns",
"the",
"parsedOpcodes",
"as",
"a",
"list",
"of",
"bytes"
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L289-L299 |
162,551 | btcsuite/btcd | txscript/script.go | removeOpcode | func removeOpcode(pkscript []parsedOpcode, opcode byte) []parsedOpcode {
retScript := make([]parsedOpcode, 0, len(pkscript))
for _, pop := range pkscript {
if pop.opcode.value != opcode {
retScript = append(retScript, pop)
}
}
return retScript
} | go | func removeOpcode(pkscript []parsedOpcode, opcode byte) []parsedOpcode {
retScript := make([]parsedOpcode, 0, len(pkscript))
for _, pop := range pkscript {
if pop.opcode.value != opcode {
retScript = append(retScript, pop)
}
}
return retScript
} | [
"func",
"removeOpcode",
"(",
"pkscript",
"[",
"]",
"parsedOpcode",
",",
"opcode",
"byte",
")",
"[",
"]",
"parsedOpcode",
"{",
"retScript",
":=",
"make",
"(",
"[",
"]",
"parsedOpcode",
",",
"0",
",",
"len",
"(",
"pkscript",
")",
")",
"\n",
"for",
"_",
... | // removeOpcode will remove any opcode matching ``opcode'' from the opcode
// stream in pkscript | [
"removeOpcode",
"will",
"remove",
"any",
"opcode",
"matching",
"opcode",
"from",
"the",
"opcode",
"stream",
"in",
"pkscript"
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L324-L332 |
162,552 | btcsuite/btcd | txscript/script.go | canonicalPush | func canonicalPush(pop parsedOpcode) bool {
opcode := pop.opcode.value
data := pop.data
dataLen := len(pop.data)
if opcode > OP_16 {
return true
}
if opcode < OP_PUSHDATA1 && opcode > OP_0 && (dataLen == 1 && data[0] <= 16) {
return false
}
if opcode == OP_PUSHDATA1 && dataLen < OP_PUSHDATA1 {
return fal... | go | func canonicalPush(pop parsedOpcode) bool {
opcode := pop.opcode.value
data := pop.data
dataLen := len(pop.data)
if opcode > OP_16 {
return true
}
if opcode < OP_PUSHDATA1 && opcode > OP_0 && (dataLen == 1 && data[0] <= 16) {
return false
}
if opcode == OP_PUSHDATA1 && dataLen < OP_PUSHDATA1 {
return fal... | [
"func",
"canonicalPush",
"(",
"pop",
"parsedOpcode",
")",
"bool",
"{",
"opcode",
":=",
"pop",
".",
"opcode",
".",
"value",
"\n",
"data",
":=",
"pop",
".",
"data",
"\n",
"dataLen",
":=",
"len",
"(",
"pop",
".",
"data",
")",
"\n",
"if",
"opcode",
">",
... | // canonicalPush returns true if the object is either not a push instruction
// or the push instruction contained wherein is matches the canonical form
// or using the smallest instruction to do the job. False otherwise. | [
"canonicalPush",
"returns",
"true",
"if",
"the",
"object",
"is",
"either",
"not",
"a",
"push",
"instruction",
"or",
"the",
"push",
"instruction",
"contained",
"wherein",
"is",
"matches",
"the",
"canonical",
"form",
"or",
"using",
"the",
"smallest",
"instruction"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L337-L358 |
162,553 | btcsuite/btcd | txscript/script.go | removeOpcodeByData | func removeOpcodeByData(pkscript []parsedOpcode, data []byte) []parsedOpcode {
retScript := make([]parsedOpcode, 0, len(pkscript))
for _, pop := range pkscript {
if !canonicalPush(pop) || !bytes.Contains(pop.data, data) {
retScript = append(retScript, pop)
}
}
return retScript
} | go | func removeOpcodeByData(pkscript []parsedOpcode, data []byte) []parsedOpcode {
retScript := make([]parsedOpcode, 0, len(pkscript))
for _, pop := range pkscript {
if !canonicalPush(pop) || !bytes.Contains(pop.data, data) {
retScript = append(retScript, pop)
}
}
return retScript
} | [
"func",
"removeOpcodeByData",
"(",
"pkscript",
"[",
"]",
"parsedOpcode",
",",
"data",
"[",
"]",
"byte",
")",
"[",
"]",
"parsedOpcode",
"{",
"retScript",
":=",
"make",
"(",
"[",
"]",
"parsedOpcode",
",",
"0",
",",
"len",
"(",
"pkscript",
")",
")",
"\n",... | // removeOpcodeByData will return the script minus any opcodes that would push
// the passed data to the stack. | [
"removeOpcodeByData",
"will",
"return",
"the",
"script",
"minus",
"any",
"opcodes",
"that",
"would",
"push",
"the",
"passed",
"data",
"to",
"the",
"stack",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L362-L371 |
162,554 | btcsuite/btcd | txscript/script.go | CalcWitnessSigHash | func CalcWitnessSigHash(script []byte, sigHashes *TxSigHashes, hType SigHashType,
tx *wire.MsgTx, idx int, amt int64) ([]byte, error) {
parsedScript, err := parseScript(script)
if err != nil {
return nil, fmt.Errorf("cannot parse output script: %v", err)
}
return calcWitnessSignatureHash(parsedScript, sigHashe... | go | func CalcWitnessSigHash(script []byte, sigHashes *TxSigHashes, hType SigHashType,
tx *wire.MsgTx, idx int, amt int64) ([]byte, error) {
parsedScript, err := parseScript(script)
if err != nil {
return nil, fmt.Errorf("cannot parse output script: %v", err)
}
return calcWitnessSignatureHash(parsedScript, sigHashe... | [
"func",
"CalcWitnessSigHash",
"(",
"script",
"[",
"]",
"byte",
",",
"sigHashes",
"*",
"TxSigHashes",
",",
"hType",
"SigHashType",
",",
"tx",
"*",
"wire",
".",
"MsgTx",
",",
"idx",
"int",
",",
"amt",
"int64",
")",
"(",
"[",
"]",
"byte",
",",
"error",
... | // CalcWitnessSigHash computes the sighash digest for the specified input of
// the target transaction observing the desired sig hash type. | [
"CalcWitnessSigHash",
"computes",
"the",
"sighash",
"digest",
"for",
"the",
"specified",
"input",
"of",
"the",
"target",
"transaction",
"observing",
"the",
"desired",
"sig",
"hash",
"type",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L545-L555 |
162,555 | btcsuite/btcd | txscript/script.go | shallowCopyTx | func shallowCopyTx(tx *wire.MsgTx) wire.MsgTx {
// As an additional memory optimization, use contiguous backing arrays
// for the copied inputs and outputs and point the final slice of
// pointers into the contiguous arrays. This avoids a lot of small
// allocations.
txCopy := wire.MsgTx{
Version: tx.Version,
... | go | func shallowCopyTx(tx *wire.MsgTx) wire.MsgTx {
// As an additional memory optimization, use contiguous backing arrays
// for the copied inputs and outputs and point the final slice of
// pointers into the contiguous arrays. This avoids a lot of small
// allocations.
txCopy := wire.MsgTx{
Version: tx.Version,
... | [
"func",
"shallowCopyTx",
"(",
"tx",
"*",
"wire",
".",
"MsgTx",
")",
"wire",
".",
"MsgTx",
"{",
"// As an additional memory optimization, use contiguous backing arrays",
"// for the copied inputs and outputs and point the final slice of",
"// pointers into the contiguous arrays. This a... | // shallowCopyTx creates a shallow copy of the transaction for use when
// calculating the signature hash. It is used over the Copy method on the
// transaction itself since that is a deep copy and therefore does more work and
// allocates much more space than needed. | [
"shallowCopyTx",
"creates",
"a",
"shallow",
"copy",
"of",
"the",
"transaction",
"for",
"use",
"when",
"calculating",
"the",
"signature",
"hash",
".",
"It",
"is",
"used",
"over",
"the",
"Copy",
"method",
"on",
"the",
"transaction",
"itself",
"since",
"that",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L561-L583 |
162,556 | btcsuite/btcd | txscript/script.go | CalcSignatureHash | func CalcSignatureHash(script []byte, hashType SigHashType, tx *wire.MsgTx, idx int) ([]byte, error) {
parsedScript, err := parseScript(script)
if err != nil {
return nil, fmt.Errorf("cannot parse output script: %v", err)
}
return calcSignatureHash(parsedScript, hashType, tx, idx), nil
} | go | func CalcSignatureHash(script []byte, hashType SigHashType, tx *wire.MsgTx, idx int) ([]byte, error) {
parsedScript, err := parseScript(script)
if err != nil {
return nil, fmt.Errorf("cannot parse output script: %v", err)
}
return calcSignatureHash(parsedScript, hashType, tx, idx), nil
} | [
"func",
"CalcSignatureHash",
"(",
"script",
"[",
"]",
"byte",
",",
"hashType",
"SigHashType",
",",
"tx",
"*",
"wire",
".",
"MsgTx",
",",
"idx",
"int",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"parsedScript",
",",
"err",
":=",
"parseScript",
... | // CalcSignatureHash will, given a script and hash type for the current script
// engine instance, calculate the signature hash to be used for signing and
// verification. | [
"CalcSignatureHash",
"will",
"given",
"a",
"script",
"and",
"hash",
"type",
"for",
"the",
"current",
"script",
"engine",
"instance",
"calculate",
"the",
"signature",
"hash",
"to",
"be",
"used",
"for",
"signing",
"and",
"verification",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L588-L594 |
162,557 | btcsuite/btcd | txscript/script.go | calcSignatureHash | func calcSignatureHash(script []parsedOpcode, hashType SigHashType, tx *wire.MsgTx, idx int) []byte {
// The SigHashSingle signature type signs only the corresponding input
// and output (the output with the same index number as the input).
//
// Since transactions can have more inputs than outputs, this means it
... | go | func calcSignatureHash(script []parsedOpcode, hashType SigHashType, tx *wire.MsgTx, idx int) []byte {
// The SigHashSingle signature type signs only the corresponding input
// and output (the output with the same index number as the input).
//
// Since transactions can have more inputs than outputs, this means it
... | [
"func",
"calcSignatureHash",
"(",
"script",
"[",
"]",
"parsedOpcode",
",",
"hashType",
"SigHashType",
",",
"tx",
"*",
"wire",
".",
"MsgTx",
",",
"idx",
"int",
")",
"[",
"]",
"byte",
"{",
"// The SigHashSingle signature type signs only the corresponding input",
"// a... | // calcSignatureHash will, given a script and hash type for the current script
// engine instance, calculate the signature hash to be used for signing and
// verification. | [
"calcSignatureHash",
"will",
"given",
"a",
"script",
"and",
"hash",
"type",
"for",
"the",
"current",
"script",
"engine",
"instance",
"calculate",
"the",
"signature",
"hash",
"to",
"be",
"used",
"for",
"signing",
"and",
"verification",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L599-L689 |
162,558 | btcsuite/btcd | txscript/script.go | getSigOpCount | func getSigOpCount(pops []parsedOpcode, precise bool) int {
nSigs := 0
for i, pop := range pops {
switch pop.opcode.value {
case OP_CHECKSIG:
fallthrough
case OP_CHECKSIGVERIFY:
nSigs++
case OP_CHECKMULTISIG:
fallthrough
case OP_CHECKMULTISIGVERIFY:
// If we are being precise then look for famil... | go | func getSigOpCount(pops []parsedOpcode, precise bool) int {
nSigs := 0
for i, pop := range pops {
switch pop.opcode.value {
case OP_CHECKSIG:
fallthrough
case OP_CHECKSIGVERIFY:
nSigs++
case OP_CHECKMULTISIG:
fallthrough
case OP_CHECKMULTISIGVERIFY:
// If we are being precise then look for famil... | [
"func",
"getSigOpCount",
"(",
"pops",
"[",
"]",
"parsedOpcode",
",",
"precise",
"bool",
")",
"int",
"{",
"nSigs",
":=",
"0",
"\n",
"for",
"i",
",",
"pop",
":=",
"range",
"pops",
"{",
"switch",
"pop",
".",
"opcode",
".",
"value",
"{",
"case",
"OP_CHEC... | // getSigOpCount is the implementation function for counting the number of
// signature operations in the script provided by pops. If precise mode is
// requested then we attempt to count the number of operations for a multisig
// op. Otherwise we use the maximum. | [
"getSigOpCount",
"is",
"the",
"implementation",
"function",
"for",
"counting",
"the",
"number",
"of",
"signature",
"operations",
"in",
"the",
"script",
"provided",
"by",
"pops",
".",
"If",
"precise",
"mode",
"is",
"requested",
"then",
"we",
"attempt",
"to",
"c... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L705-L733 |
162,559 | btcsuite/btcd | txscript/script.go | GetSigOpCount | func GetSigOpCount(script []byte) int {
// Don't check error since parseScript returns the parsed-up-to-error
// list of pops.
pops, _ := parseScript(script)
return getSigOpCount(pops, false)
} | go | func GetSigOpCount(script []byte) int {
// Don't check error since parseScript returns the parsed-up-to-error
// list of pops.
pops, _ := parseScript(script)
return getSigOpCount(pops, false)
} | [
"func",
"GetSigOpCount",
"(",
"script",
"[",
"]",
"byte",
")",
"int",
"{",
"// Don't check error since parseScript returns the parsed-up-to-error",
"// list of pops.",
"pops",
",",
"_",
":=",
"parseScript",
"(",
"script",
")",
"\n",
"return",
"getSigOpCount",
"(",
"po... | // GetSigOpCount provides a quick count of the number of signature operations
// in a script. a CHECKSIG operations counts for 1, and a CHECK_MULTISIG for 20.
// If the script fails to parse, then the count up to the point of failure is
// returned. | [
"GetSigOpCount",
"provides",
"a",
"quick",
"count",
"of",
"the",
"number",
"of",
"signature",
"operations",
"in",
"a",
"script",
".",
"a",
"CHECKSIG",
"operations",
"counts",
"for",
"1",
"and",
"a",
"CHECK_MULTISIG",
"for",
"20",
".",
"If",
"the",
"script",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L739-L744 |
162,560 | btcsuite/btcd | txscript/script.go | GetPreciseSigOpCount | func GetPreciseSigOpCount(scriptSig, scriptPubKey []byte, bip16 bool) int {
// Don't check error since parseScript returns the parsed-up-to-error
// list of pops.
pops, _ := parseScript(scriptPubKey)
// Treat non P2SH transactions as normal.
if !(bip16 && isScriptHash(pops)) {
return getSigOpCount(pops, true)
... | go | func GetPreciseSigOpCount(scriptSig, scriptPubKey []byte, bip16 bool) int {
// Don't check error since parseScript returns the parsed-up-to-error
// list of pops.
pops, _ := parseScript(scriptPubKey)
// Treat non P2SH transactions as normal.
if !(bip16 && isScriptHash(pops)) {
return getSigOpCount(pops, true)
... | [
"func",
"GetPreciseSigOpCount",
"(",
"scriptSig",
",",
"scriptPubKey",
"[",
"]",
"byte",
",",
"bip16",
"bool",
")",
"int",
"{",
"// Don't check error since parseScript returns the parsed-up-to-error",
"// list of pops.",
"pops",
",",
"_",
":=",
"parseScript",
"(",
"scri... | // GetPreciseSigOpCount returns the number of signature operations in
// scriptPubKey. If bip16 is true then scriptSig may be searched for the
// Pay-To-Script-Hash script in order to find the precise number of signature
// operations in the transaction. If the script fails to parse, then the count
// up to the point... | [
"GetPreciseSigOpCount",
"returns",
"the",
"number",
"of",
"signature",
"operations",
"in",
"scriptPubKey",
".",
"If",
"bip16",
"is",
"true",
"then",
"scriptSig",
"may",
"be",
"searched",
"for",
"the",
"Pay",
"-",
"To",
"-",
"Script",
"-",
"Hash",
"script",
"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L751-L789 |
162,561 | btcsuite/btcd | txscript/script.go | GetWitnessSigOpCount | func GetWitnessSigOpCount(sigScript, pkScript []byte, witness wire.TxWitness) int {
// If this is a regular witness program, then we can proceed directly
// to counting its signature operations without any further processing.
if IsWitnessProgram(pkScript) {
return getWitnessSigOps(pkScript, witness)
}
// Next, ... | go | func GetWitnessSigOpCount(sigScript, pkScript []byte, witness wire.TxWitness) int {
// If this is a regular witness program, then we can proceed directly
// to counting its signature operations without any further processing.
if IsWitnessProgram(pkScript) {
return getWitnessSigOps(pkScript, witness)
}
// Next, ... | [
"func",
"GetWitnessSigOpCount",
"(",
"sigScript",
",",
"pkScript",
"[",
"]",
"byte",
",",
"witness",
"wire",
".",
"TxWitness",
")",
"int",
"{",
"// If this is a regular witness program, then we can proceed directly",
"// to counting its signature operations without any further pr... | // GetWitnessSigOpCount returns the number of signature operations generated by
// spending the passed pkScript with the specified witness, or sigScript.
// Unlike GetPreciseSigOpCount, this function is able to accurately count the
// number of signature operations generated by spending witness programs, and
// nested ... | [
"GetWitnessSigOpCount",
"returns",
"the",
"number",
"of",
"signature",
"operations",
"generated",
"by",
"spending",
"the",
"passed",
"pkScript",
"with",
"the",
"specified",
"witness",
"or",
"sigScript",
".",
"Unlike",
"GetPreciseSigOpCount",
"this",
"function",
"is",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L797-L817 |
162,562 | btcsuite/btcd | txscript/script.go | getWitnessSigOps | func getWitnessSigOps(pkScript []byte, witness wire.TxWitness) int {
// Attempt to extract the witness program version.
witnessVersion, witnessProgram, err := ExtractWitnessProgramInfo(
pkScript,
)
if err != nil {
return 0
}
switch witnessVersion {
case 0:
switch {
case len(witnessProgram) == payToWitne... | go | func getWitnessSigOps(pkScript []byte, witness wire.TxWitness) int {
// Attempt to extract the witness program version.
witnessVersion, witnessProgram, err := ExtractWitnessProgramInfo(
pkScript,
)
if err != nil {
return 0
}
switch witnessVersion {
case 0:
switch {
case len(witnessProgram) == payToWitne... | [
"func",
"getWitnessSigOps",
"(",
"pkScript",
"[",
"]",
"byte",
",",
"witness",
"wire",
".",
"TxWitness",
")",
"int",
"{",
"// Attempt to extract the witness program version.",
"witnessVersion",
",",
"witnessProgram",
",",
"err",
":=",
"ExtractWitnessProgramInfo",
"(",
... | // getWitnessSigOps returns the number of signature operations generated by
// spending the passed witness program wit the passed witness. The exact
// signature counting heuristic is modified by the version of the passed
// witness program. If the version of the witness program is unable to be
// extracted, then 0 is ... | [
"getWitnessSigOps",
"returns",
"the",
"number",
"of",
"signature",
"operations",
"generated",
"by",
"spending",
"the",
"passed",
"witness",
"program",
"wit",
"the",
"passed",
"witness",
".",
"The",
"exact",
"signature",
"counting",
"heuristic",
"is",
"modified",
"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L824-L848 |
162,563 | btcsuite/btcd | txscript/script.go | IsUnspendable | func IsUnspendable(pkScript []byte) bool {
pops, err := parseScript(pkScript)
if err != nil {
return true
}
return len(pops) > 0 && pops[0].opcode.value == OP_RETURN
} | go | func IsUnspendable(pkScript []byte) bool {
pops, err := parseScript(pkScript)
if err != nil {
return true
}
return len(pops) > 0 && pops[0].opcode.value == OP_RETURN
} | [
"func",
"IsUnspendable",
"(",
"pkScript",
"[",
"]",
"byte",
")",
"bool",
"{",
"pops",
",",
"err",
":=",
"parseScript",
"(",
"pkScript",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"len",
"(",
"pops",
")",
... | // IsUnspendable returns whether the passed public key script is unspendable, or
// guaranteed to fail at execution. This allows inputs to be pruned instantly
// when entering the UTXO set. | [
"IsUnspendable",
"returns",
"whether",
"the",
"passed",
"public",
"key",
"script",
"is",
"unspendable",
"or",
"guaranteed",
"to",
"fail",
"at",
"execution",
".",
"This",
"allows",
"inputs",
"to",
"be",
"pruned",
"instantly",
"when",
"entering",
"the",
"UTXO",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/script.go#L853-L860 |
162,564 | btcsuite/btcd | btcec/gensecp256k1.go | SerializedBytePoints | func (curve *KoblitzCurve) SerializedBytePoints() []byte {
doublingPoints := curve.getDoublingPoints()
// Segregate the bits into byte-sized windows
serialized := make([]byte, curve.byteSize*256*3*10*4)
offset := 0
for byteNum := 0; byteNum < curve.byteSize; byteNum++ {
// Grab the 8 bits that make up this byte... | go | func (curve *KoblitzCurve) SerializedBytePoints() []byte {
doublingPoints := curve.getDoublingPoints()
// Segregate the bits into byte-sized windows
serialized := make([]byte, curve.byteSize*256*3*10*4)
offset := 0
for byteNum := 0; byteNum < curve.byteSize; byteNum++ {
// Grab the 8 bits that make up this byte... | [
"func",
"(",
"curve",
"*",
"KoblitzCurve",
")",
"SerializedBytePoints",
"(",
")",
"[",
"]",
"byte",
"{",
"doublingPoints",
":=",
"curve",
".",
"getDoublingPoints",
"(",
")",
"\n\n",
"// Segregate the bits into byte-sized windows",
"serialized",
":=",
"make",
"(",
... | // SerializedBytePoints returns a serialized byte slice which contains all of
// the possible points per 8-bit window. This is used to when generating
// secp256k1.go. | [
"SerializedBytePoints",
"returns",
"a",
"serialized",
"byte",
"slice",
"which",
"contains",
"all",
"of",
"the",
"possible",
"points",
"per",
"8",
"-",
"bit",
"window",
".",
"This",
"is",
"used",
"to",
"when",
"generating",
"secp256k1",
".",
"go",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcec/gensecp256k1.go#L43-L79 |
162,565 | btcsuite/btcd | btcec/gensecp256k1.go | sqrt | func sqrt(n *big.Int) *big.Int {
// Initial guess = 2^(log_2(n)/2)
guess := big.NewInt(2)
guess.Exp(guess, big.NewInt(int64(n.BitLen()/2)), nil)
// Now refine using Newton's method.
big2 := big.NewInt(2)
prevGuess := big.NewInt(0)
for {
prevGuess.Set(guess)
guess.Add(guess, new(big.Int).Div(n, guess))
gue... | go | func sqrt(n *big.Int) *big.Int {
// Initial guess = 2^(log_2(n)/2)
guess := big.NewInt(2)
guess.Exp(guess, big.NewInt(int64(n.BitLen()/2)), nil)
// Now refine using Newton's method.
big2 := big.NewInt(2)
prevGuess := big.NewInt(0)
for {
prevGuess.Set(guess)
guess.Add(guess, new(big.Int).Div(n, guess))
gue... | [
"func",
"sqrt",
"(",
"n",
"*",
"big",
".",
"Int",
")",
"*",
"big",
".",
"Int",
"{",
"// Initial guess = 2^(log_2(n)/2)",
"guess",
":=",
"big",
".",
"NewInt",
"(",
"2",
")",
"\n",
"guess",
".",
"Exp",
"(",
"guess",
",",
"big",
".",
"NewInt",
"(",
"i... | // sqrt returns the square root of the provided big integer using Newton's
// method. It's only compiled and used during generation of pre-computed
// values, so speed is not a huge concern. | [
"sqrt",
"returns",
"the",
"square",
"root",
"of",
"the",
"provided",
"big",
"integer",
"using",
"Newton",
"s",
"method",
".",
"It",
"s",
"only",
"compiled",
"and",
"used",
"during",
"generation",
"of",
"pre",
"-",
"computed",
"values",
"so",
"speed",
"is",... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcec/gensecp256k1.go#L84-L101 |
162,566 | btcsuite/btcd | database/ffldb/blockio.go | deserializeBlockLoc | func deserializeBlockLoc(serializedLoc []byte) blockLocation {
// The serialized block location format is:
//
// [0:4] Block file (4 bytes)
// [4:8] File offset (4 bytes)
// [8:12] Block length (4 bytes)
return blockLocation{
blockFileNum: byteOrder.Uint32(serializedLoc[0:4]),
fileOffset: byteOrder.Uin... | go | func deserializeBlockLoc(serializedLoc []byte) blockLocation {
// The serialized block location format is:
//
// [0:4] Block file (4 bytes)
// [4:8] File offset (4 bytes)
// [8:12] Block length (4 bytes)
return blockLocation{
blockFileNum: byteOrder.Uint32(serializedLoc[0:4]),
fileOffset: byteOrder.Uin... | [
"func",
"deserializeBlockLoc",
"(",
"serializedLoc",
"[",
"]",
"byte",
")",
"blockLocation",
"{",
"// The serialized block location format is:",
"//",
"// [0:4] Block file (4 bytes)",
"// [4:8] File offset (4 bytes)",
"// [8:12] Block length (4 bytes)",
"return",
"blockLocation"... | // deserializeBlockLoc deserializes the passed serialized block location
// information. This is data stored into the block index metadata for each
// block. The serialized data passed to this function MUST be at least
// blockLocSize bytes or it will panic. The error check is avoided here because
// this informatio... | [
"deserializeBlockLoc",
"deserializes",
"the",
"passed",
"serialized",
"block",
"location",
"information",
".",
"This",
"is",
"data",
"stored",
"into",
"the",
"block",
"index",
"metadata",
"for",
"each",
"block",
".",
"The",
"serialized",
"data",
"passed",
"to",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/ffldb/blockio.go#L192-L203 |
162,567 | btcsuite/btcd | database/ffldb/blockio.go | serializeBlockLoc | func serializeBlockLoc(loc blockLocation) []byte {
// The serialized block location format is:
//
// [0:4] Block file (4 bytes)
// [4:8] File offset (4 bytes)
// [8:12] Block length (4 bytes)
var serializedData [12]byte
byteOrder.PutUint32(serializedData[0:4], loc.blockFileNum)
byteOrder.PutUint32(serializ... | go | func serializeBlockLoc(loc blockLocation) []byte {
// The serialized block location format is:
//
// [0:4] Block file (4 bytes)
// [4:8] File offset (4 bytes)
// [8:12] Block length (4 bytes)
var serializedData [12]byte
byteOrder.PutUint32(serializedData[0:4], loc.blockFileNum)
byteOrder.PutUint32(serializ... | [
"func",
"serializeBlockLoc",
"(",
"loc",
"blockLocation",
")",
"[",
"]",
"byte",
"{",
"// The serialized block location format is:",
"//",
"// [0:4] Block file (4 bytes)",
"// [4:8] File offset (4 bytes)",
"// [8:12] Block length (4 bytes)",
"var",
"serializedData",
"[",
"12... | // serializeBlockLoc returns the serialization of the passed block location.
// This is data to be stored into the block index metadata for each block. | [
"serializeBlockLoc",
"returns",
"the",
"serialization",
"of",
"the",
"passed",
"block",
"location",
".",
"This",
"is",
"data",
"to",
"be",
"stored",
"into",
"the",
"block",
"index",
"metadata",
"for",
"each",
"block",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/ffldb/blockio.go#L207-L218 |
162,568 | btcsuite/btcd | database/ffldb/blockio.go | blockFilePath | func blockFilePath(dbPath string, fileNum uint32) string {
fileName := fmt.Sprintf(blockFilenameTemplate, fileNum)
return filepath.Join(dbPath, fileName)
} | go | func blockFilePath(dbPath string, fileNum uint32) string {
fileName := fmt.Sprintf(blockFilenameTemplate, fileNum)
return filepath.Join(dbPath, fileName)
} | [
"func",
"blockFilePath",
"(",
"dbPath",
"string",
",",
"fileNum",
"uint32",
")",
"string",
"{",
"fileName",
":=",
"fmt",
".",
"Sprintf",
"(",
"blockFilenameTemplate",
",",
"fileNum",
")",
"\n",
"return",
"filepath",
".",
"Join",
"(",
"dbPath",
",",
"fileName... | // blockFilePath return the file path for the provided block file number. | [
"blockFilePath",
"return",
"the",
"file",
"path",
"for",
"the",
"provided",
"block",
"file",
"number",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/ffldb/blockio.go#L221-L224 |
162,569 | btcsuite/btcd | database/ffldb/blockio.go | deleteFile | func (s *blockStore) deleteFile(fileNum uint32) error {
filePath := blockFilePath(s.basePath, fileNum)
if err := os.Remove(filePath); err != nil {
return makeDbErr(database.ErrDriverSpecific, err.Error(), err)
}
return nil
} | go | func (s *blockStore) deleteFile(fileNum uint32) error {
filePath := blockFilePath(s.basePath, fileNum)
if err := os.Remove(filePath); err != nil {
return makeDbErr(database.ErrDriverSpecific, err.Error(), err)
}
return nil
} | [
"func",
"(",
"s",
"*",
"blockStore",
")",
"deleteFile",
"(",
"fileNum",
"uint32",
")",
"error",
"{",
"filePath",
":=",
"blockFilePath",
"(",
"s",
".",
"basePath",
",",
"fileNum",
")",
"\n",
"if",
"err",
":=",
"os",
".",
"Remove",
"(",
"filePath",
")",
... | // deleteFile removes the block file for the passed flat file number. The file
// must already be closed and it is the responsibility of the caller to do any
// other state cleanup necessary. | [
"deleteFile",
"removes",
"the",
"block",
"file",
"for",
"the",
"passed",
"flat",
"file",
"number",
".",
"The",
"file",
"must",
"already",
"be",
"closed",
"and",
"it",
"is",
"the",
"responsibility",
"of",
"the",
"caller",
"to",
"do",
"any",
"other",
"state"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/ffldb/blockio.go#L301-L308 |
162,570 | btcsuite/btcd | database/ffldb/blockio.go | syncBlocks | func (s *blockStore) syncBlocks() error {
wc := s.writeCursor
wc.RLock()
defer wc.RUnlock()
// Nothing to do if there is no current file associated with the write
// cursor.
wc.curFile.RLock()
defer wc.curFile.RUnlock()
if wc.curFile.file == nil {
return nil
}
// Sync the file to disk.
if err := wc.curFi... | go | func (s *blockStore) syncBlocks() error {
wc := s.writeCursor
wc.RLock()
defer wc.RUnlock()
// Nothing to do if there is no current file associated with the write
// cursor.
wc.curFile.RLock()
defer wc.curFile.RUnlock()
if wc.curFile.file == nil {
return nil
}
// Sync the file to disk.
if err := wc.curFi... | [
"func",
"(",
"s",
"*",
"blockStore",
")",
"syncBlocks",
"(",
")",
"error",
"{",
"wc",
":=",
"s",
".",
"writeCursor",
"\n",
"wc",
".",
"RLock",
"(",
")",
"\n",
"defer",
"wc",
".",
"RUnlock",
"(",
")",
"\n\n",
"// Nothing to do if there is no current file as... | // syncBlocks performs a file system sync on the flat file associated with the
// store's current write cursor. It is safe to call even when there is not a
// current write file in which case it will have no effect.
//
// This is used when flushing cached metadata updates to disk to ensure all the
// block data is ful... | [
"syncBlocks",
"performs",
"a",
"file",
"system",
"sync",
"on",
"the",
"flat",
"file",
"associated",
"with",
"the",
"store",
"s",
"current",
"write",
"cursor",
".",
"It",
"is",
"safe",
"to",
"call",
"even",
"when",
"there",
"is",
"not",
"a",
"current",
"w... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/ffldb/blockio.go#L597-L618 |
162,571 | btcsuite/btcd | database/ffldb/blockio.go | scanBlockFiles | func scanBlockFiles(dbPath string) (int, uint32) {
lastFile := -1
fileLen := uint32(0)
for i := 0; ; i++ {
filePath := blockFilePath(dbPath, uint32(i))
st, err := os.Stat(filePath)
if err != nil {
break
}
lastFile = i
fileLen = uint32(st.Size())
}
log.Tracef("Scan found latest block file #%d with ... | go | func scanBlockFiles(dbPath string) (int, uint32) {
lastFile := -1
fileLen := uint32(0)
for i := 0; ; i++ {
filePath := blockFilePath(dbPath, uint32(i))
st, err := os.Stat(filePath)
if err != nil {
break
}
lastFile = i
fileLen = uint32(st.Size())
}
log.Tracef("Scan found latest block file #%d with ... | [
"func",
"scanBlockFiles",
"(",
"dbPath",
"string",
")",
"(",
"int",
",",
"uint32",
")",
"{",
"lastFile",
":=",
"-",
"1",
"\n",
"fileLen",
":=",
"uint32",
"(",
"0",
")",
"\n",
"for",
"i",
":=",
"0",
";",
";",
"i",
"++",
"{",
"filePath",
":=",
"blo... | // scanBlockFiles searches the database directory for all flat block files to
// find the end of the most recent file. This position is considered the
// current write cursor which is also stored in the metadata. Thus, it is used
// to detect unexpected shutdowns in the middle of writes so the block files
// can be r... | [
"scanBlockFiles",
"searches",
"the",
"database",
"directory",
"for",
"all",
"flat",
"block",
"files",
"to",
"find",
"the",
"end",
"of",
"the",
"most",
"recent",
"file",
".",
"This",
"position",
"is",
"considered",
"the",
"current",
"write",
"cursor",
"which",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/ffldb/blockio.go#L720-L737 |
162,572 | btcsuite/btcd | database/ffldb/blockio.go | newBlockStore | func newBlockStore(basePath string, network wire.BitcoinNet) *blockStore {
// Look for the end of the latest block to file to determine what the
// write cursor position is from the viewpoing of the block files on
// disk.
fileNum, fileOff := scanBlockFiles(basePath)
if fileNum == -1 {
fileNum = 0
fileOff = 0
... | go | func newBlockStore(basePath string, network wire.BitcoinNet) *blockStore {
// Look for the end of the latest block to file to determine what the
// write cursor position is from the viewpoing of the block files on
// disk.
fileNum, fileOff := scanBlockFiles(basePath)
if fileNum == -1 {
fileNum = 0
fileOff = 0
... | [
"func",
"newBlockStore",
"(",
"basePath",
"string",
",",
"network",
"wire",
".",
"BitcoinNet",
")",
"*",
"blockStore",
"{",
"// Look for the end of the latest block to file to determine what the",
"// write cursor position is from the viewpoing of the block files on",
"// disk.",
"... | // newBlockStore returns a new block store with the current block file number
// and offset set and all fields initialized. | [
"newBlockStore",
"returns",
"a",
"new",
"block",
"store",
"with",
"the",
"current",
"block",
"file",
"number",
"and",
"offset",
"set",
"and",
"all",
"fields",
"initialized",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/database/ffldb/blockio.go#L741-L769 |
162,573 | btcsuite/btcd | blockchain/chain.go | newBestState | func newBestState(node *blockNode, blockSize, blockWeight, numTxns,
totalTxns uint64, medianTime time.Time) *BestState {
return &BestState{
Hash: node.hash,
Height: node.height,
Bits: node.bits,
BlockSize: blockSize,
BlockWeight: blockWeight,
NumTxns: numTxns,
TotalTxns: tota... | go | func newBestState(node *blockNode, blockSize, blockWeight, numTxns,
totalTxns uint64, medianTime time.Time) *BestState {
return &BestState{
Hash: node.hash,
Height: node.height,
Bits: node.bits,
BlockSize: blockSize,
BlockWeight: blockWeight,
NumTxns: numTxns,
TotalTxns: tota... | [
"func",
"newBestState",
"(",
"node",
"*",
"blockNode",
",",
"blockSize",
",",
"blockWeight",
",",
"numTxns",
",",
"totalTxns",
"uint64",
",",
"medianTime",
"time",
".",
"Time",
")",
"*",
"BestState",
"{",
"return",
"&",
"BestState",
"{",
"Hash",
":",
"node... | // newBestState returns a new best stats instance for the given parameters. | [
"newBestState",
"returns",
"a",
"new",
"best",
"stats",
"instance",
"for",
"the",
"given",
"parameters",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L73-L86 |
162,574 | btcsuite/btcd | blockchain/chain.go | HaveBlock | func (b *BlockChain) HaveBlock(hash *chainhash.Hash) (bool, error) {
exists, err := b.blockExists(hash)
if err != nil {
return false, err
}
return exists || b.IsKnownOrphan(hash), nil
} | go | func (b *BlockChain) HaveBlock(hash *chainhash.Hash) (bool, error) {
exists, err := b.blockExists(hash)
if err != nil {
return false, err
}
return exists || b.IsKnownOrphan(hash), nil
} | [
"func",
"(",
"b",
"*",
"BlockChain",
")",
"HaveBlock",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"bool",
",",
"error",
")",
"{",
"exists",
",",
"err",
":=",
"b",
".",
"blockExists",
"(",
"hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{... | // HaveBlock returns whether or not the chain instance has the block represented
// by the passed hash. This includes checking the various places a block can
// be like part of the main chain, on a side chain, or in the orphan pool.
//
// This function is safe for concurrent access. | [
"HaveBlock",
"returns",
"whether",
"or",
"not",
"the",
"chain",
"instance",
"has",
"the",
"block",
"represented",
"by",
"the",
"passed",
"hash",
".",
"This",
"includes",
"checking",
"the",
"various",
"places",
"a",
"block",
"can",
"be",
"like",
"part",
"of",... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L194-L200 |
162,575 | btcsuite/btcd | blockchain/chain.go | GetOrphanRoot | func (b *BlockChain) GetOrphanRoot(hash *chainhash.Hash) *chainhash.Hash {
// Protect concurrent access. Using a read lock only so multiple
// readers can query without blocking each other.
b.orphanLock.RLock()
defer b.orphanLock.RUnlock()
// Keep looping while the parent of each orphaned block is
// known and ... | go | func (b *BlockChain) GetOrphanRoot(hash *chainhash.Hash) *chainhash.Hash {
// Protect concurrent access. Using a read lock only so multiple
// readers can query without blocking each other.
b.orphanLock.RLock()
defer b.orphanLock.RUnlock()
// Keep looping while the parent of each orphaned block is
// known and ... | [
"func",
"(",
"b",
"*",
"BlockChain",
")",
"GetOrphanRoot",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"*",
"chainhash",
".",
"Hash",
"{",
"// Protect concurrent access. Using a read lock only so multiple",
"// readers can query without blocking each other.",
"b",
"... | // GetOrphanRoot returns the head of the chain for the provided hash from the
// map of orphan blocks.
//
// This function is safe for concurrent access. | [
"GetOrphanRoot",
"returns",
"the",
"head",
"of",
"the",
"chain",
"for",
"the",
"provided",
"hash",
"from",
"the",
"map",
"of",
"orphan",
"blocks",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L226-L246 |
162,576 | btcsuite/btcd | blockchain/chain.go | removeOrphanBlock | func (b *BlockChain) removeOrphanBlock(orphan *orphanBlock) {
// Protect concurrent access.
b.orphanLock.Lock()
defer b.orphanLock.Unlock()
// Remove the orphan block from the orphan pool.
orphanHash := orphan.block.Hash()
delete(b.orphans, *orphanHash)
// Remove the reference from the previous orphan index to... | go | func (b *BlockChain) removeOrphanBlock(orphan *orphanBlock) {
// Protect concurrent access.
b.orphanLock.Lock()
defer b.orphanLock.Unlock()
// Remove the orphan block from the orphan pool.
orphanHash := orphan.block.Hash()
delete(b.orphans, *orphanHash)
// Remove the reference from the previous orphan index to... | [
"func",
"(",
"b",
"*",
"BlockChain",
")",
"removeOrphanBlock",
"(",
"orphan",
"*",
"orphanBlock",
")",
"{",
"// Protect concurrent access.",
"b",
".",
"orphanLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"b",
".",
"orphanLock",
".",
"Unlock",
"(",
")",
"\n\... | // removeOrphanBlock removes the passed orphan block from the orphan pool and
// previous orphan index. | [
"removeOrphanBlock",
"removes",
"the",
"passed",
"orphan",
"block",
"from",
"the",
"orphan",
"pool",
"and",
"previous",
"orphan",
"index",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L250-L281 |
162,577 | btcsuite/btcd | blockchain/chain.go | CalcSequenceLock | func (b *BlockChain) CalcSequenceLock(tx *btcutil.Tx, utxoView *UtxoViewpoint, mempool bool) (*SequenceLock, error) {
b.chainLock.Lock()
defer b.chainLock.Unlock()
return b.calcSequenceLock(b.bestChain.Tip(), tx, utxoView, mempool)
} | go | func (b *BlockChain) CalcSequenceLock(tx *btcutil.Tx, utxoView *UtxoViewpoint, mempool bool) (*SequenceLock, error) {
b.chainLock.Lock()
defer b.chainLock.Unlock()
return b.calcSequenceLock(b.bestChain.Tip(), tx, utxoView, mempool)
} | [
"func",
"(",
"b",
"*",
"BlockChain",
")",
"CalcSequenceLock",
"(",
"tx",
"*",
"btcutil",
".",
"Tx",
",",
"utxoView",
"*",
"UtxoViewpoint",
",",
"mempool",
"bool",
")",
"(",
"*",
"SequenceLock",
",",
"error",
")",
"{",
"b",
".",
"chainLock",
".",
"Lock"... | // CalcSequenceLock computes a relative lock-time SequenceLock for the passed
// transaction using the passed UtxoViewpoint to obtain the past median time
// for blocks in which the referenced inputs of the transactions were included
// within. The generated SequenceLock lock can be used in conjunction with a
// block ... | [
"CalcSequenceLock",
"computes",
"a",
"relative",
"lock",
"-",
"time",
"SequenceLock",
"for",
"the",
"passed",
"transaction",
"using",
"the",
"passed",
"UtxoViewpoint",
"to",
"obtain",
"the",
"past",
"median",
"time",
"for",
"blocks",
"in",
"which",
"the",
"refer... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L351-L356 |
162,578 | btcsuite/btcd | blockchain/chain.go | countSpentOutputs | func countSpentOutputs(block *btcutil.Block) int {
// Exclude the coinbase transaction since it can't spend anything.
var numSpent int
for _, tx := range block.Transactions()[1:] {
numSpent += len(tx.MsgTx().TxIn)
}
return numSpent
} | go | func countSpentOutputs(block *btcutil.Block) int {
// Exclude the coinbase transaction since it can't spend anything.
var numSpent int
for _, tx := range block.Transactions()[1:] {
numSpent += len(tx.MsgTx().TxIn)
}
return numSpent
} | [
"func",
"countSpentOutputs",
"(",
"block",
"*",
"btcutil",
".",
"Block",
")",
"int",
"{",
"// Exclude the coinbase transaction since it can't spend anything.",
"var",
"numSpent",
"int",
"\n",
"for",
"_",
",",
"tx",
":=",
"range",
"block",
".",
"Transactions",
"(",
... | // countSpentOutputs returns the number of utxos the passed block spends. | [
"countSpentOutputs",
"returns",
"the",
"number",
"of",
"utxos",
"the",
"passed",
"block",
"spends",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L802-L809 |
162,579 | btcsuite/btcd | blockchain/chain.go | BestSnapshot | func (b *BlockChain) BestSnapshot() *BestState {
b.stateLock.RLock()
snapshot := b.stateSnapshot
b.stateLock.RUnlock()
return snapshot
} | go | func (b *BlockChain) BestSnapshot() *BestState {
b.stateLock.RLock()
snapshot := b.stateSnapshot
b.stateLock.RUnlock()
return snapshot
} | [
"func",
"(",
"b",
"*",
"BlockChain",
")",
"BestSnapshot",
"(",
")",
"*",
"BestState",
"{",
"b",
".",
"stateLock",
".",
"RLock",
"(",
")",
"\n",
"snapshot",
":=",
"b",
".",
"stateSnapshot",
"\n",
"b",
".",
"stateLock",
".",
"RUnlock",
"(",
")",
"\n",
... | // BestSnapshot returns information about the current best chain block and
// related state as of the current point in time. The returned instance must be
// treated as immutable since it is shared by all callers.
//
// This function is safe for concurrent access. | [
"BestSnapshot",
"returns",
"information",
"about",
"the",
"current",
"best",
"chain",
"block",
"and",
"related",
"state",
"as",
"of",
"the",
"current",
"point",
"in",
"time",
".",
"The",
"returned",
"instance",
"must",
"be",
"treated",
"as",
"immutable",
"sinc... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L1261-L1266 |
162,580 | btcsuite/btcd | blockchain/chain.go | HeaderByHash | func (b *BlockChain) HeaderByHash(hash *chainhash.Hash) (wire.BlockHeader, error) {
node := b.index.LookupNode(hash)
if node == nil {
err := fmt.Errorf("block %s is not known", hash)
return wire.BlockHeader{}, err
}
return node.Header(), nil
} | go | func (b *BlockChain) HeaderByHash(hash *chainhash.Hash) (wire.BlockHeader, error) {
node := b.index.LookupNode(hash)
if node == nil {
err := fmt.Errorf("block %s is not known", hash)
return wire.BlockHeader{}, err
}
return node.Header(), nil
} | [
"func",
"(",
"b",
"*",
"BlockChain",
")",
"HeaderByHash",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"wire",
".",
"BlockHeader",
",",
"error",
")",
"{",
"node",
":=",
"b",
".",
"index",
".",
"LookupNode",
"(",
"hash",
")",
"\n",
"if",
"n... | // HeaderByHash returns the block header identified by the given hash or an
// error if it doesn't exist. Note that this will return headers from both the
// main and side chains. | [
"HeaderByHash",
"returns",
"the",
"block",
"header",
"identified",
"by",
"the",
"given",
"hash",
"or",
"an",
"error",
"if",
"it",
"doesn",
"t",
"exist",
".",
"Note",
"that",
"this",
"will",
"return",
"headers",
"from",
"both",
"the",
"main",
"and",
"side",... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L1271-L1279 |
162,581 | btcsuite/btcd | blockchain/chain.go | MainChainHasBlock | func (b *BlockChain) MainChainHasBlock(hash *chainhash.Hash) bool {
node := b.index.LookupNode(hash)
return node != nil && b.bestChain.Contains(node)
} | go | func (b *BlockChain) MainChainHasBlock(hash *chainhash.Hash) bool {
node := b.index.LookupNode(hash)
return node != nil && b.bestChain.Contains(node)
} | [
"func",
"(",
"b",
"*",
"BlockChain",
")",
"MainChainHasBlock",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"bool",
"{",
"node",
":=",
"b",
".",
"index",
".",
"LookupNode",
"(",
"hash",
")",
"\n",
"return",
"node",
"!=",
"nil",
"&&",
"b",
".",
... | // MainChainHasBlock returns whether or not the block with the given hash is in
// the main chain.
//
// This function is safe for concurrent access. | [
"MainChainHasBlock",
"returns",
"whether",
"or",
"not",
"the",
"block",
"with",
"the",
"given",
"hash",
"is",
"in",
"the",
"main",
"chain",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L1285-L1288 |
162,582 | btcsuite/btcd | blockchain/chain.go | BlockHeightByHash | func (b *BlockChain) BlockHeightByHash(hash *chainhash.Hash) (int32, error) {
node := b.index.LookupNode(hash)
if node == nil || !b.bestChain.Contains(node) {
str := fmt.Sprintf("block %s is not in the main chain", hash)
return 0, errNotInMainChain(str)
}
return node.height, nil
} | go | func (b *BlockChain) BlockHeightByHash(hash *chainhash.Hash) (int32, error) {
node := b.index.LookupNode(hash)
if node == nil || !b.bestChain.Contains(node) {
str := fmt.Sprintf("block %s is not in the main chain", hash)
return 0, errNotInMainChain(str)
}
return node.height, nil
} | [
"func",
"(",
"b",
"*",
"BlockChain",
")",
"BlockHeightByHash",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"int32",
",",
"error",
")",
"{",
"node",
":=",
"b",
".",
"index",
".",
"LookupNode",
"(",
"hash",
")",
"\n",
"if",
"node",
"==",
"n... | // BlockHeightByHash returns the height of the block with the given hash in the
// main chain.
//
// This function is safe for concurrent access. | [
"BlockHeightByHash",
"returns",
"the",
"height",
"of",
"the",
"block",
"with",
"the",
"given",
"hash",
"in",
"the",
"main",
"chain",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L1321-L1329 |
162,583 | btcsuite/btcd | blockchain/chain.go | BlockHashByHeight | func (b *BlockChain) BlockHashByHeight(blockHeight int32) (*chainhash.Hash, error) {
node := b.bestChain.NodeByHeight(blockHeight)
if node == nil {
str := fmt.Sprintf("no block at height %d exists", blockHeight)
return nil, errNotInMainChain(str)
}
return &node.hash, nil
} | go | func (b *BlockChain) BlockHashByHeight(blockHeight int32) (*chainhash.Hash, error) {
node := b.bestChain.NodeByHeight(blockHeight)
if node == nil {
str := fmt.Sprintf("no block at height %d exists", blockHeight)
return nil, errNotInMainChain(str)
}
return &node.hash, nil
} | [
"func",
"(",
"b",
"*",
"BlockChain",
")",
"BlockHashByHeight",
"(",
"blockHeight",
"int32",
")",
"(",
"*",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"node",
":=",
"b",
".",
"bestChain",
".",
"NodeByHeight",
"(",
"blockHeight",
")",
"\n",
"if",
... | // BlockHashByHeight returns the hash of the block at the given height in the
// main chain.
//
// This function is safe for concurrent access. | [
"BlockHashByHeight",
"returns",
"the",
"hash",
"of",
"the",
"block",
"at",
"the",
"given",
"height",
"in",
"the",
"main",
"chain",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
"access",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L1335-L1344 |
162,584 | btcsuite/btcd | blockchain/chain.go | HeightRange | func (b *BlockChain) HeightRange(startHeight, endHeight int32) ([]chainhash.Hash, error) {
// Ensure requested heights are sane.
if startHeight < 0 {
return nil, fmt.Errorf("start height of fetch range must not "+
"be less than zero - got %d", startHeight)
}
if endHeight < startHeight {
return nil, fmt.Error... | go | func (b *BlockChain) HeightRange(startHeight, endHeight int32) ([]chainhash.Hash, error) {
// Ensure requested heights are sane.
if startHeight < 0 {
return nil, fmt.Errorf("start height of fetch range must not "+
"be less than zero - got %d", startHeight)
}
if endHeight < startHeight {
return nil, fmt.Error... | [
"func",
"(",
"b",
"*",
"BlockChain",
")",
"HeightRange",
"(",
"startHeight",
",",
"endHeight",
"int32",
")",
"(",
"[",
"]",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"// Ensure requested heights are sane.",
"if",
"startHeight",
"<",
"0",
"{",
"return... | // HeightRange returns a range of block hashes for the given start and end
// heights. It is inclusive of the start height and exclusive of the end
// height. The end height will be limited to the current main chain height.
//
// This function is safe for concurrent access. | [
"HeightRange",
"returns",
"a",
"range",
"of",
"block",
"hashes",
"for",
"the",
"given",
"start",
"and",
"end",
"heights",
".",
"It",
"is",
"inclusive",
"of",
"the",
"start",
"height",
"and",
"exclusive",
"of",
"the",
"end",
"height",
".",
"The",
"end",
"... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L1351-L1392 |
162,585 | btcsuite/btcd | blockchain/chain.go | HeightToHashRange | func (b *BlockChain) HeightToHashRange(startHeight int32,
endHash *chainhash.Hash, maxResults int) ([]chainhash.Hash, error) {
endNode := b.index.LookupNode(endHash)
if endNode == nil {
return nil, fmt.Errorf("no known block header with hash %v", endHash)
}
if !b.index.NodeStatus(endNode).KnownValid() {
retur... | go | func (b *BlockChain) HeightToHashRange(startHeight int32,
endHash *chainhash.Hash, maxResults int) ([]chainhash.Hash, error) {
endNode := b.index.LookupNode(endHash)
if endNode == nil {
return nil, fmt.Errorf("no known block header with hash %v", endHash)
}
if !b.index.NodeStatus(endNode).KnownValid() {
retur... | [
"func",
"(",
"b",
"*",
"BlockChain",
")",
"HeightToHashRange",
"(",
"startHeight",
"int32",
",",
"endHash",
"*",
"chainhash",
".",
"Hash",
",",
"maxResults",
"int",
")",
"(",
"[",
"]",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"endNode",
":=",
... | // HeightToHashRange returns a range of block hashes for the given start height
// and end hash, inclusive on both ends. The hashes are for all blocks that are
// ancestors of endHash with height greater than or equal to startHeight. The
// end hash must belong to a block that is known to be valid.
//
// This functio... | [
"HeightToHashRange",
"returns",
"a",
"range",
"of",
"block",
"hashes",
"for",
"the",
"given",
"start",
"height",
"and",
"end",
"hash",
"inclusive",
"on",
"both",
"ends",
".",
"The",
"hashes",
"are",
"for",
"all",
"blocks",
"that",
"are",
"ancestors",
"of",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L1400-L1434 |
162,586 | btcsuite/btcd | blockchain/chain.go | IntervalBlockHashes | func (b *BlockChain) IntervalBlockHashes(endHash *chainhash.Hash, interval int,
) ([]chainhash.Hash, error) {
endNode := b.index.LookupNode(endHash)
if endNode == nil {
return nil, fmt.Errorf("no known block header with hash %v", endHash)
}
if !b.index.NodeStatus(endNode).KnownValid() {
return nil, fmt.Errorf(... | go | func (b *BlockChain) IntervalBlockHashes(endHash *chainhash.Hash, interval int,
) ([]chainhash.Hash, error) {
endNode := b.index.LookupNode(endHash)
if endNode == nil {
return nil, fmt.Errorf("no known block header with hash %v", endHash)
}
if !b.index.NodeStatus(endNode).KnownValid() {
return nil, fmt.Errorf(... | [
"func",
"(",
"b",
"*",
"BlockChain",
")",
"IntervalBlockHashes",
"(",
"endHash",
"*",
"chainhash",
".",
"Hash",
",",
"interval",
"int",
",",
")",
"(",
"[",
"]",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"endNode",
":=",
"b",
".",
"index",
"."... | // IntervalBlockHashes returns hashes for all blocks that are ancestors of
// endHash where the block height is a positive multiple of interval.
//
// This function is safe for concurrent access. | [
"IntervalBlockHashes",
"returns",
"hashes",
"for",
"all",
"blocks",
"that",
"are",
"ancestors",
"of",
"endHash",
"where",
"the",
"block",
"height",
"is",
"a",
"positive",
"multiple",
"of",
"interval",
".",
"This",
"function",
"is",
"safe",
"for",
"concurrent",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L1440-L1473 |
162,587 | btcsuite/btcd | blockchain/chain.go | New | func New(config *Config) (*BlockChain, error) {
// Enforce required config fields.
if config.DB == nil {
return nil, AssertError("blockchain.New database is nil")
}
if config.ChainParams == nil {
return nil, AssertError("blockchain.New chain parameters nil")
}
if config.TimeSource == nil {
return nil, Asser... | go | func New(config *Config) (*BlockChain, error) {
// Enforce required config fields.
if config.DB == nil {
return nil, AssertError("blockchain.New database is nil")
}
if config.ChainParams == nil {
return nil, AssertError("blockchain.New chain parameters nil")
}
if config.TimeSource == nil {
return nil, Asser... | [
"func",
"New",
"(",
"config",
"*",
"Config",
")",
"(",
"*",
"BlockChain",
",",
"error",
")",
"{",
"// Enforce required config fields.",
"if",
"config",
".",
"DB",
"==",
"nil",
"{",
"return",
"nil",
",",
"AssertError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"... | // New returns a BlockChain instance using the provided configuration details. | [
"New",
"returns",
"a",
"BlockChain",
"instance",
"using",
"the",
"provided",
"configuration",
"details",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/blockchain/chain.go#L1717-L1803 |
162,588 | btcsuite/btcd | btcjson/btcwalletextcmds.go | NewImportAddressCmd | func NewImportAddressCmd(address string, account string, rescan *bool) *ImportAddressCmd {
return &ImportAddressCmd{
Address: address,
Account: account,
Rescan: rescan,
}
} | go | func NewImportAddressCmd(address string, account string, rescan *bool) *ImportAddressCmd {
return &ImportAddressCmd{
Address: address,
Account: account,
Rescan: rescan,
}
} | [
"func",
"NewImportAddressCmd",
"(",
"address",
"string",
",",
"account",
"string",
",",
"rescan",
"*",
"bool",
")",
"*",
"ImportAddressCmd",
"{",
"return",
"&",
"ImportAddressCmd",
"{",
"Address",
":",
"address",
",",
"Account",
":",
"account",
",",
"Rescan",
... | // NewImportAddressCmd returns a new instance which can be used to issue an
// importaddress JSON-RPC command. | [
"NewImportAddressCmd",
"returns",
"a",
"new",
"instance",
"which",
"can",
"be",
"used",
"to",
"issue",
"an",
"importaddress",
"JSON",
"-",
"RPC",
"command",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/btcwalletextcmds.go#L45-L51 |
162,589 | btcsuite/btcd | btcjson/btcwalletextcmds.go | NewImportPubKeyCmd | func NewImportPubKeyCmd(pubKey string, rescan *bool) *ImportPubKeyCmd {
return &ImportPubKeyCmd{
PubKey: pubKey,
Rescan: rescan,
}
} | go | func NewImportPubKeyCmd(pubKey string, rescan *bool) *ImportPubKeyCmd {
return &ImportPubKeyCmd{
PubKey: pubKey,
Rescan: rescan,
}
} | [
"func",
"NewImportPubKeyCmd",
"(",
"pubKey",
"string",
",",
"rescan",
"*",
"bool",
")",
"*",
"ImportPubKeyCmd",
"{",
"return",
"&",
"ImportPubKeyCmd",
"{",
"PubKey",
":",
"pubKey",
",",
"Rescan",
":",
"rescan",
",",
"}",
"\n",
"}"
] | // NewImportPubKeyCmd returns a new instance which can be used to issue an
// importpubkey JSON-RPC command. | [
"NewImportPubKeyCmd",
"returns",
"a",
"new",
"instance",
"which",
"can",
"be",
"used",
"to",
"issue",
"an",
"importpubkey",
"JSON",
"-",
"RPC",
"command",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/btcwalletextcmds.go#L61-L66 |
162,590 | btcsuite/btcd | btcjson/btcwalletextcmds.go | NewRenameAccountCmd | func NewRenameAccountCmd(oldAccount, newAccount string) *RenameAccountCmd {
return &RenameAccountCmd{
OldAccount: oldAccount,
NewAccount: newAccount,
}
} | go | func NewRenameAccountCmd(oldAccount, newAccount string) *RenameAccountCmd {
return &RenameAccountCmd{
OldAccount: oldAccount,
NewAccount: newAccount,
}
} | [
"func",
"NewRenameAccountCmd",
"(",
"oldAccount",
",",
"newAccount",
"string",
")",
"*",
"RenameAccountCmd",
"{",
"return",
"&",
"RenameAccountCmd",
"{",
"OldAccount",
":",
"oldAccount",
",",
"NewAccount",
":",
"newAccount",
",",
"}",
"\n",
"}"
] | // NewRenameAccountCmd returns a new instance which can be used to issue a
// renameaccount JSON-RPC command. | [
"NewRenameAccountCmd",
"returns",
"a",
"new",
"instance",
"which",
"can",
"be",
"used",
"to",
"issue",
"a",
"renameaccount",
"JSON",
"-",
"RPC",
"command",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/btcjson/btcwalletextcmds.go#L89-L94 |
162,591 | btcsuite/btcd | wire/msgcfilter.go | NewMsgCFilter | func NewMsgCFilter(filterType FilterType, blockHash *chainhash.Hash,
data []byte) *MsgCFilter {
return &MsgCFilter{
FilterType: filterType,
BlockHash: *blockHash,
Data: data,
}
} | go | func NewMsgCFilter(filterType FilterType, blockHash *chainhash.Hash,
data []byte) *MsgCFilter {
return &MsgCFilter{
FilterType: filterType,
BlockHash: *blockHash,
Data: data,
}
} | [
"func",
"NewMsgCFilter",
"(",
"filterType",
"FilterType",
",",
"blockHash",
"*",
"chainhash",
".",
"Hash",
",",
"data",
"[",
"]",
"byte",
")",
"*",
"MsgCFilter",
"{",
"return",
"&",
"MsgCFilter",
"{",
"FilterType",
":",
"filterType",
",",
"BlockHash",
":",
... | // NewMsgCFilter returns a new bitcoin cfilter message that conforms to the
// Message interface. See MsgCFilter for details. | [
"NewMsgCFilter",
"returns",
"a",
"new",
"bitcoin",
"cfilter",
"message",
"that",
"conforms",
"to",
"the",
"Message",
"interface",
".",
"See",
"MsgCFilter",
"for",
"details",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/msgcfilter.go#L112-L119 |
162,592 | btcsuite/btcd | peer/log.go | formatLockTime | func formatLockTime(lockTime uint32) string {
// The lock time field of a transaction is either a block height at
// which the transaction is finalized or a timestamp depending on if the
// value is before the lockTimeThreshold. When it is under the
// threshold it is a block height.
if lockTime < txscript.LockTi... | go | func formatLockTime(lockTime uint32) string {
// The lock time field of a transaction is either a block height at
// which the transaction is finalized or a timestamp depending on if the
// value is before the lockTimeThreshold. When it is under the
// threshold it is a block height.
if lockTime < txscript.LockTi... | [
"func",
"formatLockTime",
"(",
"lockTime",
"uint32",
")",
"string",
"{",
"// The lock time field of a transaction is either a block height at",
"// which the transaction is finalized or a timestamp depending on if the",
"// value is before the lockTimeThreshold. When it is under the",
"// thr... | // formatLockTime returns a transaction lock time as a human-readable string. | [
"formatLockTime",
"returns",
"a",
"transaction",
"lock",
"time",
"as",
"a",
"human",
"-",
"readable",
"string",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/log.go#L68-L78 |
162,593 | btcsuite/btcd | peer/log.go | invSummary | func invSummary(invList []*wire.InvVect) string {
// No inventory.
invLen := len(invList)
if invLen == 0 {
return "empty"
}
// One inventory item.
if invLen == 1 {
iv := invList[0]
switch iv.Type {
case wire.InvTypeError:
return fmt.Sprintf("error %s", iv.Hash)
case wire.InvTypeWitnessBlock:
retu... | go | func invSummary(invList []*wire.InvVect) string {
// No inventory.
invLen := len(invList)
if invLen == 0 {
return "empty"
}
// One inventory item.
if invLen == 1 {
iv := invList[0]
switch iv.Type {
case wire.InvTypeError:
return fmt.Sprintf("error %s", iv.Hash)
case wire.InvTypeWitnessBlock:
retu... | [
"func",
"invSummary",
"(",
"invList",
"[",
"]",
"*",
"wire",
".",
"InvVect",
")",
"string",
"{",
"// No inventory.",
"invLen",
":=",
"len",
"(",
"invList",
")",
"\n",
"if",
"invLen",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// One inve... | // invSummary returns an inventory message as a human-readable string. | [
"invSummary",
"returns",
"an",
"inventory",
"message",
"as",
"a",
"human",
"-",
"readable",
"string",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/log.go#L81-L109 |
162,594 | btcsuite/btcd | peer/log.go | locatorSummary | func locatorSummary(locator []*chainhash.Hash, stopHash *chainhash.Hash) string {
if len(locator) > 0 {
return fmt.Sprintf("locator %s, stop %s", locator[0], stopHash)
}
return fmt.Sprintf("no locator, stop %s", stopHash)
} | go | func locatorSummary(locator []*chainhash.Hash, stopHash *chainhash.Hash) string {
if len(locator) > 0 {
return fmt.Sprintf("locator %s, stop %s", locator[0], stopHash)
}
return fmt.Sprintf("no locator, stop %s", stopHash)
} | [
"func",
"locatorSummary",
"(",
"locator",
"[",
"]",
"*",
"chainhash",
".",
"Hash",
",",
"stopHash",
"*",
"chainhash",
".",
"Hash",
")",
"string",
"{",
"if",
"len",
"(",
"locator",
")",
">",
"0",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
... | // locatorSummary returns a block locator as a human-readable string. | [
"locatorSummary",
"returns",
"a",
"block",
"locator",
"as",
"a",
"human",
"-",
"readable",
"string",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/log.go#L112-L119 |
162,595 | btcsuite/btcd | peer/log.go | sanitizeString | func sanitizeString(str string, maxLength uint) string {
const safeChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY" +
"Z01234567890 .,;_/:?@"
// Strip any characters not in the safeChars string removed.
str = strings.Map(func(r rune) rune {
if strings.ContainsRune(safeChars, r) {
return r
}
... | go | func sanitizeString(str string, maxLength uint) string {
const safeChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY" +
"Z01234567890 .,;_/:?@"
// Strip any characters not in the safeChars string removed.
str = strings.Map(func(r rune) rune {
if strings.ContainsRune(safeChars, r) {
return r
}
... | [
"func",
"sanitizeString",
"(",
"str",
"string",
",",
"maxLength",
"uint",
")",
"string",
"{",
"const",
"safeChars",
"=",
"\"",
"\"",
"+",
"\"",
"\"",
"\n\n",
"// Strip any characters not in the safeChars string removed.",
"str",
"=",
"strings",
".",
"Map",
"(",
... | // sanitizeString strips any characters which are even remotely dangerous, such
// as html control characters, from the passed string. It also limits it to
// the passed maximum size, which can be 0 for unlimited. When the string is
// limited, it will also add "..." to the string to indicate it was truncated. | [
"sanitizeString",
"strips",
"any",
"characters",
"which",
"are",
"even",
"remotely",
"dangerous",
"such",
"as",
"html",
"control",
"characters",
"from",
"the",
"passed",
"string",
".",
"It",
"also",
"limits",
"it",
"to",
"the",
"passed",
"maximum",
"size",
"wh... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/log.go#L125-L143 |
162,596 | btcsuite/btcd | peer/log.go | messageSummary | func messageSummary(msg wire.Message) string {
switch msg := msg.(type) {
case *wire.MsgVersion:
return fmt.Sprintf("agent %s, pver %d, block %d",
msg.UserAgent, msg.ProtocolVersion, msg.LastBlock)
case *wire.MsgVerAck:
// No summary.
case *wire.MsgGetAddr:
// No summary.
case *wire.MsgAddr:
return f... | go | func messageSummary(msg wire.Message) string {
switch msg := msg.(type) {
case *wire.MsgVersion:
return fmt.Sprintf("agent %s, pver %d, block %d",
msg.UserAgent, msg.ProtocolVersion, msg.LastBlock)
case *wire.MsgVerAck:
// No summary.
case *wire.MsgGetAddr:
// No summary.
case *wire.MsgAddr:
return f... | [
"func",
"messageSummary",
"(",
"msg",
"wire",
".",
"Message",
")",
"string",
"{",
"switch",
"msg",
":=",
"msg",
".",
"(",
"type",
")",
"{",
"case",
"*",
"wire",
".",
"MsgVersion",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"msg",
"... | // messageSummary returns a human-readable string which summarizes a message.
// Not all messages have or need a summary. This is used for debug logging. | [
"messageSummary",
"returns",
"a",
"human",
"-",
"readable",
"string",
"which",
"summarizes",
"a",
"message",
".",
"Not",
"all",
"messages",
"have",
"or",
"need",
"a",
"summary",
".",
"This",
"is",
"used",
"for",
"debug",
"logging",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/peer/log.go#L147-L227 |
162,597 | btcsuite/btcd | txscript/sigcache.go | NewSigCache | func NewSigCache(maxEntries uint) *SigCache {
return &SigCache{
validSigs: make(map[chainhash.Hash]sigCacheEntry, maxEntries),
maxEntries: maxEntries,
}
} | go | func NewSigCache(maxEntries uint) *SigCache {
return &SigCache{
validSigs: make(map[chainhash.Hash]sigCacheEntry, maxEntries),
maxEntries: maxEntries,
}
} | [
"func",
"NewSigCache",
"(",
"maxEntries",
"uint",
")",
"*",
"SigCache",
"{",
"return",
"&",
"SigCache",
"{",
"validSigs",
":",
"make",
"(",
"map",
"[",
"chainhash",
".",
"Hash",
"]",
"sigCacheEntry",
",",
"maxEntries",
")",
",",
"maxEntries",
":",
"maxEntr... | // NewSigCache creates and initializes a new instance of SigCache. Its sole
// parameter 'maxEntries' represents the maximum number of entries allowed to
// exist in the SigCache at any particular moment. Random entries are evicted
// to make room for new entries that would cause the number of entries in the
// cache t... | [
"NewSigCache",
"creates",
"and",
"initializes",
"a",
"new",
"instance",
"of",
"SigCache",
".",
"Its",
"sole",
"parameter",
"maxEntries",
"represents",
"the",
"maximum",
"number",
"of",
"entries",
"allowed",
"to",
"exist",
"in",
"the",
"SigCache",
"at",
"any",
... | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/txscript/sigcache.go#L46-L51 |
162,598 | btcsuite/btcd | wire/common.go | Borrow | func (l binaryFreeList) Borrow() []byte {
var buf []byte
select {
case buf = <-l:
default:
buf = make([]byte, 8)
}
return buf[:8]
} | go | func (l binaryFreeList) Borrow() []byte {
var buf []byte
select {
case buf = <-l:
default:
buf = make([]byte, 8)
}
return buf[:8]
} | [
"func",
"(",
"l",
"binaryFreeList",
")",
"Borrow",
"(",
")",
"[",
"]",
"byte",
"{",
"var",
"buf",
"[",
"]",
"byte",
"\n",
"select",
"{",
"case",
"buf",
"=",
"<-",
"l",
":",
"default",
":",
"buf",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"8",
... | // Borrow returns a byte slice from the free list with a length of 8. A new
// buffer is allocated if there are not any available on the free list. | [
"Borrow",
"returns",
"a",
"byte",
"slice",
"from",
"the",
"free",
"list",
"with",
"a",
"length",
"of",
"8",
".",
"A",
"new",
"buffer",
"is",
"allocated",
"if",
"there",
"are",
"not",
"any",
"available",
"on",
"the",
"free",
"list",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/common.go#L52-L60 |
162,599 | btcsuite/btcd | wire/common.go | Uint8 | func (l binaryFreeList) Uint8(r io.Reader) (uint8, error) {
buf := l.Borrow()[:1]
if _, err := io.ReadFull(r, buf); err != nil {
l.Return(buf)
return 0, err
}
rv := buf[0]
l.Return(buf)
return rv, nil
} | go | func (l binaryFreeList) Uint8(r io.Reader) (uint8, error) {
buf := l.Borrow()[:1]
if _, err := io.ReadFull(r, buf); err != nil {
l.Return(buf)
return 0, err
}
rv := buf[0]
l.Return(buf)
return rv, nil
} | [
"func",
"(",
"l",
"binaryFreeList",
")",
"Uint8",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"uint8",
",",
"error",
")",
"{",
"buf",
":=",
"l",
".",
"Borrow",
"(",
")",
"[",
":",
"1",
"]",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull... | // Uint8 reads a single byte from the provided reader using a buffer from the
// free list and returns it as a uint8. | [
"Uint8",
"reads",
"a",
"single",
"byte",
"from",
"the",
"provided",
"reader",
"using",
"a",
"buffer",
"from",
"the",
"free",
"list",
"and",
"returns",
"it",
"as",
"a",
"uint8",
"."
] | 96897255fd17525dd12426345d279533780bc4e1 | https://github.com/btcsuite/btcd/blob/96897255fd17525dd12426345d279533780bc4e1/wire/common.go#L74-L83 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.