id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
141,900 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
UpdateTicketPoolData
|
func UpdateTicketPoolData(interval dbtypes.TimeBasedGrouping, timeGraph *dbtypes.PoolTicketsData,
priceGraph *dbtypes.PoolTicketsData, donutcharts *dbtypes.PoolTicketsData, height int64) {
ticketPoolGraphsCache.Lock()
defer ticketPoolGraphsCache.Unlock()
ticketPoolGraphsCache.Height[interval] = height
ticketPoolGraphsCache.TimeGraphCache[interval] = timeGraph
ticketPoolGraphsCache.PriceGraphCache[interval] = priceGraph
ticketPoolGraphsCache.DonutGraphCache[interval] = donutcharts
}
|
go
|
func UpdateTicketPoolData(interval dbtypes.TimeBasedGrouping, timeGraph *dbtypes.PoolTicketsData,
priceGraph *dbtypes.PoolTicketsData, donutcharts *dbtypes.PoolTicketsData, height int64) {
ticketPoolGraphsCache.Lock()
defer ticketPoolGraphsCache.Unlock()
ticketPoolGraphsCache.Height[interval] = height
ticketPoolGraphsCache.TimeGraphCache[interval] = timeGraph
ticketPoolGraphsCache.PriceGraphCache[interval] = priceGraph
ticketPoolGraphsCache.DonutGraphCache[interval] = donutcharts
}
|
[
"func",
"UpdateTicketPoolData",
"(",
"interval",
"dbtypes",
".",
"TimeBasedGrouping",
",",
"timeGraph",
"*",
"dbtypes",
".",
"PoolTicketsData",
",",
"priceGraph",
"*",
"dbtypes",
".",
"PoolTicketsData",
",",
"donutcharts",
"*",
"dbtypes",
".",
"PoolTicketsData",
",",
"height",
"int64",
")",
"{",
"ticketPoolGraphsCache",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ticketPoolGraphsCache",
".",
"Unlock",
"(",
")",
"\n\n",
"ticketPoolGraphsCache",
".",
"Height",
"[",
"interval",
"]",
"=",
"height",
"\n",
"ticketPoolGraphsCache",
".",
"TimeGraphCache",
"[",
"interval",
"]",
"=",
"timeGraph",
"\n",
"ticketPoolGraphsCache",
".",
"PriceGraphCache",
"[",
"interval",
"]",
"=",
"priceGraph",
"\n",
"ticketPoolGraphsCache",
".",
"DonutGraphCache",
"[",
"interval",
"]",
"=",
"donutcharts",
"\n",
"}"
] |
// UpdateTicketPoolData updates the ticket pool cache with the latest data fetched.
// This is a thread-safe way to update ticket pool cache data. TryLock helps avoid
// stacking calls to update the cache.
|
[
"UpdateTicketPoolData",
"updates",
"the",
"ticket",
"pool",
"cache",
"with",
"the",
"latest",
"data",
"fetched",
".",
"This",
"is",
"a",
"thread",
"-",
"safe",
"way",
"to",
"update",
"ticket",
"pool",
"cache",
"data",
".",
"TryLock",
"helps",
"avoid",
"stacking",
"calls",
"to",
"update",
"the",
"cache",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L101-L110
|
141,901 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
newUtxoStore
|
func newUtxoStore(prealloc int) utxoStore {
return utxoStore{
c: make(map[string]map[uint32]*dbtypes.UTXOData, prealloc),
}
}
|
go
|
func newUtxoStore(prealloc int) utxoStore {
return utxoStore{
c: make(map[string]map[uint32]*dbtypes.UTXOData, prealloc),
}
}
|
[
"func",
"newUtxoStore",
"(",
"prealloc",
"int",
")",
"utxoStore",
"{",
"return",
"utxoStore",
"{",
"c",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"uint32",
"]",
"*",
"dbtypes",
".",
"UTXOData",
",",
"prealloc",
")",
",",
"}",
"\n",
"}"
] |
// newUtxoStore constructs a new utxoStore.
|
[
"newUtxoStore",
"constructs",
"a",
"new",
"utxoStore",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L119-L123
|
141,902 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
Get
|
func (u *utxoStore) Get(txHash string, txIndex uint32) (*dbtypes.UTXOData, bool) {
u.Lock()
defer u.Unlock()
utxoData, ok := u.c[txHash][txIndex]
if ok {
u.c[txHash][txIndex] = nil
delete(u.c[txHash], txIndex)
if len(u.c[txHash]) == 0 {
delete(u.c, txHash)
}
}
return utxoData, ok
}
|
go
|
func (u *utxoStore) Get(txHash string, txIndex uint32) (*dbtypes.UTXOData, bool) {
u.Lock()
defer u.Unlock()
utxoData, ok := u.c[txHash][txIndex]
if ok {
u.c[txHash][txIndex] = nil
delete(u.c[txHash], txIndex)
if len(u.c[txHash]) == 0 {
delete(u.c, txHash)
}
}
return utxoData, ok
}
|
[
"func",
"(",
"u",
"*",
"utxoStore",
")",
"Get",
"(",
"txHash",
"string",
",",
"txIndex",
"uint32",
")",
"(",
"*",
"dbtypes",
".",
"UTXOData",
",",
"bool",
")",
"{",
"u",
".",
"Lock",
"(",
")",
"\n",
"defer",
"u",
".",
"Unlock",
"(",
")",
"\n",
"utxoData",
",",
"ok",
":=",
"u",
".",
"c",
"[",
"txHash",
"]",
"[",
"txIndex",
"]",
"\n",
"if",
"ok",
"{",
"u",
".",
"c",
"[",
"txHash",
"]",
"[",
"txIndex",
"]",
"=",
"nil",
"\n",
"delete",
"(",
"u",
".",
"c",
"[",
"txHash",
"]",
",",
"txIndex",
")",
"\n",
"if",
"len",
"(",
"u",
".",
"c",
"[",
"txHash",
"]",
")",
"==",
"0",
"{",
"delete",
"(",
"u",
".",
"c",
",",
"txHash",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"utxoData",
",",
"ok",
"\n",
"}"
] |
// Get attempts to locate UTXOData for the specified outpoint. If the data is
// not in the cache, a nil pointer and false are returned. If the data is
// located, the data and true are returned, and the data is evicted from cache.
|
[
"Get",
"attempts",
"to",
"locate",
"UTXOData",
"for",
"the",
"specified",
"outpoint",
".",
"If",
"the",
"data",
"is",
"not",
"in",
"the",
"cache",
"a",
"nil",
"pointer",
"and",
"false",
"are",
"returned",
".",
"If",
"the",
"data",
"is",
"located",
"the",
"data",
"and",
"true",
"are",
"returned",
"and",
"the",
"data",
"is",
"evicted",
"from",
"cache",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L128-L140
|
141,903 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
Set
|
func (u *utxoStore) Set(txHash string, txIndex uint32, addrs []string, val int64) {
u.Lock()
defer u.Unlock()
u.set(txHash, txIndex, addrs, val)
}
|
go
|
func (u *utxoStore) Set(txHash string, txIndex uint32, addrs []string, val int64) {
u.Lock()
defer u.Unlock()
u.set(txHash, txIndex, addrs, val)
}
|
[
"func",
"(",
"u",
"*",
"utxoStore",
")",
"Set",
"(",
"txHash",
"string",
",",
"txIndex",
"uint32",
",",
"addrs",
"[",
"]",
"string",
",",
"val",
"int64",
")",
"{",
"u",
".",
"Lock",
"(",
")",
"\n",
"defer",
"u",
".",
"Unlock",
"(",
")",
"\n",
"u",
".",
"set",
"(",
"txHash",
",",
"txIndex",
",",
"addrs",
",",
"val",
")",
"\n",
"}"
] |
// Set stores the addresses and amount in a UTXOData entry in the cache for the
// given outpoint.
|
[
"Set",
"stores",
"the",
"addresses",
"and",
"amount",
"in",
"a",
"UTXOData",
"entry",
"in",
"the",
"cache",
"for",
"the",
"given",
"outpoint",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L161-L165
|
141,904 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
Reinit
|
func (u *utxoStore) Reinit(utxos []dbtypes.UTXO) {
u.Lock()
defer u.Unlock()
// Pre-allocate the transaction hash map assuming the number of unique
// transaction hashes in input is roughly 2/3 of the number of UTXOs.
prealloc := 2 * len(utxos) / 3
u.c = make(map[string]map[uint32]*dbtypes.UTXOData, prealloc)
for i := range utxos {
u.set(utxos[i].TxHash, utxos[i].TxIndex, utxos[i].Addresses, utxos[i].Value)
}
}
|
go
|
func (u *utxoStore) Reinit(utxos []dbtypes.UTXO) {
u.Lock()
defer u.Unlock()
// Pre-allocate the transaction hash map assuming the number of unique
// transaction hashes in input is roughly 2/3 of the number of UTXOs.
prealloc := 2 * len(utxos) / 3
u.c = make(map[string]map[uint32]*dbtypes.UTXOData, prealloc)
for i := range utxos {
u.set(utxos[i].TxHash, utxos[i].TxIndex, utxos[i].Addresses, utxos[i].Value)
}
}
|
[
"func",
"(",
"u",
"*",
"utxoStore",
")",
"Reinit",
"(",
"utxos",
"[",
"]",
"dbtypes",
".",
"UTXO",
")",
"{",
"u",
".",
"Lock",
"(",
")",
"\n",
"defer",
"u",
".",
"Unlock",
"(",
")",
"\n",
"// Pre-allocate the transaction hash map assuming the number of unique",
"// transaction hashes in input is roughly 2/3 of the number of UTXOs.",
"prealloc",
":=",
"2",
"*",
"len",
"(",
"utxos",
")",
"/",
"3",
"\n",
"u",
".",
"c",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"uint32",
"]",
"*",
"dbtypes",
".",
"UTXOData",
",",
"prealloc",
")",
"\n",
"for",
"i",
":=",
"range",
"utxos",
"{",
"u",
".",
"set",
"(",
"utxos",
"[",
"i",
"]",
".",
"TxHash",
",",
"utxos",
"[",
"i",
"]",
".",
"TxIndex",
",",
"utxos",
"[",
"i",
"]",
".",
"Addresses",
",",
"utxos",
"[",
"i",
"]",
".",
"Value",
")",
"\n",
"}",
"\n",
"}"
] |
// Reinit re-initializes the utxoStore with the given UTXOs.
|
[
"Reinit",
"re",
"-",
"initializes",
"the",
"utxoStore",
"with",
"the",
"given",
"UTXOs",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L168-L178
|
141,905 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
Size
|
func (u *utxoStore) Size() (sz int) {
u.Lock()
defer u.Unlock()
for _, m := range u.c {
sz += len(m)
}
return
}
|
go
|
func (u *utxoStore) Size() (sz int) {
u.Lock()
defer u.Unlock()
for _, m := range u.c {
sz += len(m)
}
return
}
|
[
"func",
"(",
"u",
"*",
"utxoStore",
")",
"Size",
"(",
")",
"(",
"sz",
"int",
")",
"{",
"u",
".",
"Lock",
"(",
")",
"\n",
"defer",
"u",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"u",
".",
"c",
"{",
"sz",
"+=",
"len",
"(",
"m",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Size returns the size of the utxo cache in number of UTXOs.
|
[
"Size",
"returns",
"the",
"size",
"of",
"the",
"utxo",
"cache",
"in",
"number",
"of",
"UTXOs",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L181-L188
|
141,906 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
NewChainDBRPC
|
func NewChainDBRPC(chaindb *ChainDB, cl *rpcclient.Client) (*ChainDBRPC, error) {
return &ChainDBRPC{chaindb, cl}, nil
}
|
go
|
func NewChainDBRPC(chaindb *ChainDB, cl *rpcclient.Client) (*ChainDBRPC, error) {
return &ChainDBRPC{chaindb, cl}, nil
}
|
[
"func",
"NewChainDBRPC",
"(",
"chaindb",
"*",
"ChainDB",
",",
"cl",
"*",
"rpcclient",
".",
"Client",
")",
"(",
"*",
"ChainDBRPC",
",",
"error",
")",
"{",
"return",
"&",
"ChainDBRPC",
"{",
"chaindb",
",",
"cl",
"}",
",",
"nil",
"\n",
"}"
] |
// NewChainDBRPC contains ChainDB and RPC client parameters. By default,
// duplicate row checks on insertion are enabled. also enables rpc client
|
[
"NewChainDBRPC",
"contains",
"ChainDB",
"and",
"RPC",
"client",
"parameters",
".",
"By",
"default",
"duplicate",
"row",
"checks",
"on",
"insertion",
"are",
"enabled",
".",
"also",
"enables",
"rpc",
"client"
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L288-L290
|
141,907 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
MissingSideChainBlocks
|
func (pgb *ChainDBRPC) MissingSideChainBlocks() ([]dbtypes.SideChain, int, error) {
// First get the side chain tips (head blocks).
tips, err := rpcutils.SideChains(pgb.Client)
if err != nil {
return nil, 0, fmt.Errorf("unable to get chain tips from node: %v", err)
}
nSideChains := len(tips)
// Build a list of all the blocks in each side chain that are not
// already in the database.
blocksToStore := make([]dbtypes.SideChain, nSideChains)
var nSideChainBlocks int
for it := range tips {
sideHeight := tips[it].Height
log.Tracef("Getting full side chain with tip %s at %d.", tips[it].Hash, sideHeight)
sideChain, err := rpcutils.SideChainFull(pgb.Client, tips[it].Hash)
if err != nil {
return nil, 0, fmt.Errorf("unable to get side chain blocks for chain tip %s: %v",
tips[it].Hash, err)
}
// Starting height is the lowest block in the side chain.
sideHeight -= int64(len(sideChain)) - 1
// For each block in the side chain, check if it already stored.
for is := range sideChain {
// Check for the block hash in the DB.
sideHeightDB, err := pgb.BlockHeight(sideChain[is])
if err == sql.ErrNoRows {
// This block is NOT already in the DB.
blocksToStore[it].Hashes = append(blocksToStore[it].Hashes, sideChain[is])
blocksToStore[it].Heights = append(blocksToStore[it].Heights, sideHeight)
nSideChainBlocks++
} else if err == nil {
// This block is already in the DB.
log.Tracef("Found block %s in postgres at height %d.",
sideChain[is], sideHeightDB)
if sideHeight != sideHeightDB {
log.Errorf("Side chain block height %d, expected %d.",
sideHeightDB, sideHeight)
}
} else /* err != nil && err != sql.ErrNoRows */ {
// Unexpected error
log.Errorf("Failed to retrieve block %s: %v", sideChain[is], err)
}
// Next block
sideHeight++
}
}
return blocksToStore, nSideChainBlocks, nil
}
|
go
|
func (pgb *ChainDBRPC) MissingSideChainBlocks() ([]dbtypes.SideChain, int, error) {
// First get the side chain tips (head blocks).
tips, err := rpcutils.SideChains(pgb.Client)
if err != nil {
return nil, 0, fmt.Errorf("unable to get chain tips from node: %v", err)
}
nSideChains := len(tips)
// Build a list of all the blocks in each side chain that are not
// already in the database.
blocksToStore := make([]dbtypes.SideChain, nSideChains)
var nSideChainBlocks int
for it := range tips {
sideHeight := tips[it].Height
log.Tracef("Getting full side chain with tip %s at %d.", tips[it].Hash, sideHeight)
sideChain, err := rpcutils.SideChainFull(pgb.Client, tips[it].Hash)
if err != nil {
return nil, 0, fmt.Errorf("unable to get side chain blocks for chain tip %s: %v",
tips[it].Hash, err)
}
// Starting height is the lowest block in the side chain.
sideHeight -= int64(len(sideChain)) - 1
// For each block in the side chain, check if it already stored.
for is := range sideChain {
// Check for the block hash in the DB.
sideHeightDB, err := pgb.BlockHeight(sideChain[is])
if err == sql.ErrNoRows {
// This block is NOT already in the DB.
blocksToStore[it].Hashes = append(blocksToStore[it].Hashes, sideChain[is])
blocksToStore[it].Heights = append(blocksToStore[it].Heights, sideHeight)
nSideChainBlocks++
} else if err == nil {
// This block is already in the DB.
log.Tracef("Found block %s in postgres at height %d.",
sideChain[is], sideHeightDB)
if sideHeight != sideHeightDB {
log.Errorf("Side chain block height %d, expected %d.",
sideHeightDB, sideHeight)
}
} else /* err != nil && err != sql.ErrNoRows */ {
// Unexpected error
log.Errorf("Failed to retrieve block %s: %v", sideChain[is], err)
}
// Next block
sideHeight++
}
}
return blocksToStore, nSideChainBlocks, nil
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDBRPC",
")",
"MissingSideChainBlocks",
"(",
")",
"(",
"[",
"]",
"dbtypes",
".",
"SideChain",
",",
"int",
",",
"error",
")",
"{",
"// First get the side chain tips (head blocks).",
"tips",
",",
"err",
":=",
"rpcutils",
".",
"SideChains",
"(",
"pgb",
".",
"Client",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"nSideChains",
":=",
"len",
"(",
"tips",
")",
"\n\n",
"// Build a list of all the blocks in each side chain that are not",
"// already in the database.",
"blocksToStore",
":=",
"make",
"(",
"[",
"]",
"dbtypes",
".",
"SideChain",
",",
"nSideChains",
")",
"\n",
"var",
"nSideChainBlocks",
"int",
"\n",
"for",
"it",
":=",
"range",
"tips",
"{",
"sideHeight",
":=",
"tips",
"[",
"it",
"]",
".",
"Height",
"\n",
"log",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"tips",
"[",
"it",
"]",
".",
"Hash",
",",
"sideHeight",
")",
"\n\n",
"sideChain",
",",
"err",
":=",
"rpcutils",
".",
"SideChainFull",
"(",
"pgb",
".",
"Client",
",",
"tips",
"[",
"it",
"]",
".",
"Hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tips",
"[",
"it",
"]",
".",
"Hash",
",",
"err",
")",
"\n",
"}",
"\n",
"// Starting height is the lowest block in the side chain.",
"sideHeight",
"-=",
"int64",
"(",
"len",
"(",
"sideChain",
")",
")",
"-",
"1",
"\n\n",
"// For each block in the side chain, check if it already stored.",
"for",
"is",
":=",
"range",
"sideChain",
"{",
"// Check for the block hash in the DB.",
"sideHeightDB",
",",
"err",
":=",
"pgb",
".",
"BlockHeight",
"(",
"sideChain",
"[",
"is",
"]",
")",
"\n",
"if",
"err",
"==",
"sql",
".",
"ErrNoRows",
"{",
"// This block is NOT already in the DB.",
"blocksToStore",
"[",
"it",
"]",
".",
"Hashes",
"=",
"append",
"(",
"blocksToStore",
"[",
"it",
"]",
".",
"Hashes",
",",
"sideChain",
"[",
"is",
"]",
")",
"\n",
"blocksToStore",
"[",
"it",
"]",
".",
"Heights",
"=",
"append",
"(",
"blocksToStore",
"[",
"it",
"]",
".",
"Heights",
",",
"sideHeight",
")",
"\n",
"nSideChainBlocks",
"++",
"\n",
"}",
"else",
"if",
"err",
"==",
"nil",
"{",
"// This block is already in the DB.",
"log",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"sideChain",
"[",
"is",
"]",
",",
"sideHeightDB",
")",
"\n",
"if",
"sideHeight",
"!=",
"sideHeightDB",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sideHeightDB",
",",
"sideHeight",
")",
"\n",
"}",
"\n",
"}",
"else",
"/* err != nil && err != sql.ErrNoRows */",
"{",
"// Unexpected error",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sideChain",
"[",
"is",
"]",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Next block",
"sideHeight",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"blocksToStore",
",",
"nSideChainBlocks",
",",
"nil",
"\n",
"}"
] |
// MissingSideChainBlocks identifies side chain blocks that are missing from the
// DB. Side chains known to dcrd are listed via the getchaintips RPC. Each block
// presence in the postgres DB is checked, and any missing block is returned in
// a SideChain along with a count of the total number of missing blocks.
|
[
"MissingSideChainBlocks",
"identifies",
"side",
"chain",
"blocks",
"that",
"are",
"missing",
"from",
"the",
"DB",
".",
"Side",
"chains",
"known",
"to",
"dcrd",
"are",
"listed",
"via",
"the",
"getchaintips",
"RPC",
".",
"Each",
"block",
"presence",
"in",
"the",
"postgres",
"DB",
"is",
"checked",
"and",
"any",
"missing",
"block",
"is",
"returned",
"in",
"a",
"SideChain",
"along",
"with",
"a",
"count",
"of",
"the",
"total",
"number",
"of",
"missing",
"blocks",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L337-L389
|
141,908 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
TxnDbID
|
func (t *TicketTxnIDGetter) TxnDbID(txid string, expire bool) (uint64, error) {
if t == nil {
panic("You're using an uninitialized TicketTxnIDGetter")
}
t.mtx.RLock()
dbID, ok := t.idCache[txid]
t.mtx.RUnlock()
if ok {
if expire {
t.mtx.Lock()
delete(t.idCache, txid)
t.mtx.Unlock()
}
return dbID, nil
}
// Cache miss. Get the row id by hash from the tickets table.
log.Tracef("Cache miss for %s.", txid)
return RetrieveTicketIDByHashNoCancel(t.db, txid)
}
|
go
|
func (t *TicketTxnIDGetter) TxnDbID(txid string, expire bool) (uint64, error) {
if t == nil {
panic("You're using an uninitialized TicketTxnIDGetter")
}
t.mtx.RLock()
dbID, ok := t.idCache[txid]
t.mtx.RUnlock()
if ok {
if expire {
t.mtx.Lock()
delete(t.idCache, txid)
t.mtx.Unlock()
}
return dbID, nil
}
// Cache miss. Get the row id by hash from the tickets table.
log.Tracef("Cache miss for %s.", txid)
return RetrieveTicketIDByHashNoCancel(t.db, txid)
}
|
[
"func",
"(",
"t",
"*",
"TicketTxnIDGetter",
")",
"TxnDbID",
"(",
"txid",
"string",
",",
"expire",
"bool",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"if",
"t",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"t",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"dbID",
",",
"ok",
":=",
"t",
".",
"idCache",
"[",
"txid",
"]",
"\n",
"t",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"ok",
"{",
"if",
"expire",
"{",
"t",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"t",
".",
"idCache",
",",
"txid",
")",
"\n",
"t",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"return",
"dbID",
",",
"nil",
"\n",
"}",
"\n",
"// Cache miss. Get the row id by hash from the tickets table.",
"log",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"txid",
")",
"\n",
"return",
"RetrieveTicketIDByHashNoCancel",
"(",
"t",
".",
"db",
",",
"txid",
")",
"\n",
"}"
] |
// TxnDbID fetches DB row ID for the ticket specified by the input transaction
// hash. A cache is checked first. In the event of a cache hit, the DB ID is
// returned and deleted from the internal cache. In the event of a cache miss,
// the database is queried. If the database query fails, the error is non-nil.
|
[
"TxnDbID",
"fetches",
"DB",
"row",
"ID",
"for",
"the",
"ticket",
"specified",
"by",
"the",
"input",
"transaction",
"hash",
".",
"A",
"cache",
"is",
"checked",
"first",
".",
"In",
"the",
"event",
"of",
"a",
"cache",
"hit",
"the",
"DB",
"ID",
"is",
"returned",
"and",
"deleted",
"from",
"the",
"internal",
"cache",
".",
"In",
"the",
"event",
"of",
"a",
"cache",
"miss",
"the",
"database",
"is",
"queried",
".",
"If",
"the",
"database",
"query",
"fails",
"the",
"error",
"is",
"non",
"-",
"nil",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L402-L420
|
141,909 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
NewTicketTxnIDGetter
|
func NewTicketTxnIDGetter(db *sql.DB) *TicketTxnIDGetter {
return &TicketTxnIDGetter{
db: db,
idCache: make(map[string]uint64),
}
}
|
go
|
func NewTicketTxnIDGetter(db *sql.DB) *TicketTxnIDGetter {
return &TicketTxnIDGetter{
db: db,
idCache: make(map[string]uint64),
}
}
|
[
"func",
"NewTicketTxnIDGetter",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"*",
"TicketTxnIDGetter",
"{",
"return",
"&",
"TicketTxnIDGetter",
"{",
"db",
":",
"db",
",",
"idCache",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"uint64",
")",
",",
"}",
"\n",
"}"
] |
// NewTicketTxnIDGetter constructs a new TicketTxnIDGetter with an empty cache.
|
[
"NewTicketTxnIDGetter",
"constructs",
"a",
"new",
"TicketTxnIDGetter",
"with",
"an",
"empty",
"cache",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L445-L450
|
141,910 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
NewChainDB
|
func NewChainDB(dbi *DBInfo, params *chaincfg.Params, stakeDB *stakedb.StakeDatabase,
devPrefetch, hidePGConfig bool, addrCacheCap int, mp rpcutils.MempoolAddressChecker,
parser ProposalsFetcher, bg BlockGetter) (*ChainDB, error) {
ctx := context.Background()
chainDB, err := NewChainDBWithCancel(ctx, dbi, params, stakeDB,
devPrefetch, hidePGConfig, addrCacheCap, mp, parser, bg)
if err != nil {
return nil, err
}
return chainDB, nil
}
|
go
|
func NewChainDB(dbi *DBInfo, params *chaincfg.Params, stakeDB *stakedb.StakeDatabase,
devPrefetch, hidePGConfig bool, addrCacheCap int, mp rpcutils.MempoolAddressChecker,
parser ProposalsFetcher, bg BlockGetter) (*ChainDB, error) {
ctx := context.Background()
chainDB, err := NewChainDBWithCancel(ctx, dbi, params, stakeDB,
devPrefetch, hidePGConfig, addrCacheCap, mp, parser, bg)
if err != nil {
return nil, err
}
return chainDB, nil
}
|
[
"func",
"NewChainDB",
"(",
"dbi",
"*",
"DBInfo",
",",
"params",
"*",
"chaincfg",
".",
"Params",
",",
"stakeDB",
"*",
"stakedb",
".",
"StakeDatabase",
",",
"devPrefetch",
",",
"hidePGConfig",
"bool",
",",
"addrCacheCap",
"int",
",",
"mp",
"rpcutils",
".",
"MempoolAddressChecker",
",",
"parser",
"ProposalsFetcher",
",",
"bg",
"BlockGetter",
")",
"(",
"*",
"ChainDB",
",",
"error",
")",
"{",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n",
"chainDB",
",",
"err",
":=",
"NewChainDBWithCancel",
"(",
"ctx",
",",
"dbi",
",",
"params",
",",
"stakeDB",
",",
"devPrefetch",
",",
"hidePGConfig",
",",
"addrCacheCap",
",",
"mp",
",",
"parser",
",",
"bg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"chainDB",
",",
"nil",
"\n",
"}"
] |
// NewChainDB constructs a ChainDB for the given connection and Decred network
// parameters. By default, duplicate row checks on insertion are enabled. See
// NewChainDBWithCancel to enable context cancellation of running queries.
// proposalsUpdateChan is used to manage politeia update notifications trigger
// between the notifier and the handler method. A non-nil BlockGetter is only
// needed if database upgrades are required.
|
[
"NewChainDB",
"constructs",
"a",
"ChainDB",
"for",
"the",
"given",
"connection",
"and",
"Decred",
"network",
"parameters",
".",
"By",
"default",
"duplicate",
"row",
"checks",
"on",
"insertion",
"are",
"enabled",
".",
"See",
"NewChainDBWithCancel",
"to",
"enable",
"context",
"cancellation",
"of",
"running",
"queries",
".",
"proposalsUpdateChan",
"is",
"used",
"to",
"manage",
"politeia",
"update",
"notifications",
"trigger",
"between",
"the",
"notifier",
"and",
"the",
"handler",
"method",
".",
"A",
"non",
"-",
"nil",
"BlockGetter",
"is",
"only",
"needed",
"if",
"database",
"upgrades",
"are",
"required",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L464-L475
|
141,911 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
InitUtxoCache
|
func (pgb *ChainDB) InitUtxoCache(utxos []dbtypes.UTXO) {
pgb.utxoCache.Reinit(utxos)
}
|
go
|
func (pgb *ChainDB) InitUtxoCache(utxos []dbtypes.UTXO) {
pgb.utxoCache.Reinit(utxos)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"InitUtxoCache",
"(",
"utxos",
"[",
"]",
"dbtypes",
".",
"UTXO",
")",
"{",
"pgb",
".",
"utxoCache",
".",
"Reinit",
"(",
"utxos",
")",
"\n",
"}"
] |
// InitUtxoCache resets the UTXO cache with the given slice of UTXO data.
|
[
"InitUtxoCache",
"resets",
"the",
"UTXO",
"cache",
"with",
"the",
"given",
"slice",
"of",
"UTXO",
"data",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L790-L792
|
141,912 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
SideChainBlocks
|
func (pgb *ChainDB) SideChainBlocks() ([]*dbtypes.BlockStatus, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
scb, err := RetrieveSideChainBlocks(ctx, pgb.db)
return scb, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) SideChainBlocks() ([]*dbtypes.BlockStatus, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
scb, err := RetrieveSideChainBlocks(ctx, pgb.db)
return scb, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"SideChainBlocks",
"(",
")",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"BlockStatus",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"scb",
",",
"err",
":=",
"RetrieveSideChainBlocks",
"(",
"ctx",
",",
"pgb",
".",
"db",
")",
"\n",
"return",
"scb",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// SideChainBlocks retrieves all known side chain blocks.
|
[
"SideChainBlocks",
"retrieves",
"all",
"known",
"side",
"chain",
"blocks",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L874-L879
|
141,913 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
DisapprovedBlocks
|
func (pgb *ChainDB) DisapprovedBlocks() ([]*dbtypes.BlockStatus, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
disb, err := RetrieveDisapprovedBlocks(ctx, pgb.db)
return disb, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) DisapprovedBlocks() ([]*dbtypes.BlockStatus, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
disb, err := RetrieveDisapprovedBlocks(ctx, pgb.db)
return disb, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"DisapprovedBlocks",
"(",
")",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"BlockStatus",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"disb",
",",
"err",
":=",
"RetrieveDisapprovedBlocks",
"(",
"ctx",
",",
"pgb",
".",
"db",
")",
"\n",
"return",
"disb",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// DisapprovedBlocks retrieves all blocks disapproved by stakeholder votes.
|
[
"DisapprovedBlocks",
"retrieves",
"all",
"blocks",
"disapproved",
"by",
"stakeholder",
"votes",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L890-L895
|
141,914 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
BlockStatus
|
func (pgb *ChainDB) BlockStatus(hash string) (dbtypes.BlockStatus, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
bs, err := RetrieveBlockStatus(ctx, pgb.db, hash)
return bs, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) BlockStatus(hash string) (dbtypes.BlockStatus, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
bs, err := RetrieveBlockStatus(ctx, pgb.db, hash)
return bs, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"BlockStatus",
"(",
"hash",
"string",
")",
"(",
"dbtypes",
".",
"BlockStatus",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"bs",
",",
"err",
":=",
"RetrieveBlockStatus",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"hash",
")",
"\n",
"return",
"bs",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// BlockStatus retrieves the block chain status of the specified block.
|
[
"BlockStatus",
"retrieves",
"the",
"block",
"chain",
"status",
"of",
"the",
"specified",
"block",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L898-L903
|
141,915 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
blockFlags
|
func (pgb *ChainDB) blockFlags(ctx context.Context, hash string) (bool, bool, error) {
iv, im, err := RetrieveBlockFlags(ctx, pgb.db, hash)
return iv, im, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) blockFlags(ctx context.Context, hash string) (bool, bool, error) {
iv, im, err := RetrieveBlockFlags(ctx, pgb.db, hash)
return iv, im, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"blockFlags",
"(",
"ctx",
"context",
".",
"Context",
",",
"hash",
"string",
")",
"(",
"bool",
",",
"bool",
",",
"error",
")",
"{",
"iv",
",",
"im",
",",
"err",
":=",
"RetrieveBlockFlags",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"hash",
")",
"\n",
"return",
"iv",
",",
"im",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// blockFlags retrieves the block's isValid and isMainchain flags.
|
[
"blockFlags",
"retrieves",
"the",
"block",
"s",
"isValid",
"and",
"isMainchain",
"flags",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L906-L909
|
141,916 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
BlockFlags
|
func (pgb *ChainDB) BlockFlags(hash string) (bool, bool, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
return pgb.blockFlags(ctx, hash)
}
|
go
|
func (pgb *ChainDB) BlockFlags(hash string) (bool, bool, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
return pgb.blockFlags(ctx, hash)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"BlockFlags",
"(",
"hash",
"string",
")",
"(",
"bool",
",",
"bool",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"return",
"pgb",
".",
"blockFlags",
"(",
"ctx",
",",
"hash",
")",
"\n",
"}"
] |
// BlockFlags retrieves the block's isValid and isMainchain flags.
|
[
"BlockFlags",
"retrieves",
"the",
"block",
"s",
"isValid",
"and",
"isMainchain",
"flags",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L912-L916
|
141,917 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
BlockFlagsNoCancel
|
func (pgb *ChainDB) BlockFlagsNoCancel(hash string) (bool, bool, error) {
return pgb.blockFlags(context.Background(), hash)
}
|
go
|
func (pgb *ChainDB) BlockFlagsNoCancel(hash string) (bool, bool, error) {
return pgb.blockFlags(context.Background(), hash)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"BlockFlagsNoCancel",
"(",
"hash",
"string",
")",
"(",
"bool",
",",
"bool",
",",
"error",
")",
"{",
"return",
"pgb",
".",
"blockFlags",
"(",
"context",
".",
"Background",
"(",
")",
",",
"hash",
")",
"\n",
"}"
] |
// BlockFlagsNoCancel retrieves the block's isValid and isMainchain flags.
|
[
"BlockFlagsNoCancel",
"retrieves",
"the",
"block",
"s",
"isValid",
"and",
"isMainchain",
"flags",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L919-L921
|
141,918 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
blockChainDbID
|
func (pgb *ChainDB) blockChainDbID(ctx context.Context, hash string) (dbID uint64, err error) {
err = pgb.db.QueryRowContext(ctx, internal.SelectBlockChainRowIDByHash, hash).Scan(&dbID)
err = pgb.replaceCancelError(err)
return
}
|
go
|
func (pgb *ChainDB) blockChainDbID(ctx context.Context, hash string) (dbID uint64, err error) {
err = pgb.db.QueryRowContext(ctx, internal.SelectBlockChainRowIDByHash, hash).Scan(&dbID)
err = pgb.replaceCancelError(err)
return
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"blockChainDbID",
"(",
"ctx",
"context",
".",
"Context",
",",
"hash",
"string",
")",
"(",
"dbID",
"uint64",
",",
"err",
"error",
")",
"{",
"err",
"=",
"pgb",
".",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectBlockChainRowIDByHash",
",",
"hash",
")",
".",
"Scan",
"(",
"&",
"dbID",
")",
"\n",
"err",
"=",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"return",
"\n",
"}"
] |
// blockChainDbID gets the row ID of the given block hash in the block_chain
// table. The cancellation context is used without timeout.
|
[
"blockChainDbID",
"gets",
"the",
"row",
"ID",
"of",
"the",
"given",
"block",
"hash",
"in",
"the",
"block_chain",
"table",
".",
"The",
"cancellation",
"context",
"is",
"used",
"without",
"timeout",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L925-L929
|
141,919 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
BlockChainDbID
|
func (pgb *ChainDB) BlockChainDbID(hash string) (dbID uint64, err error) {
return pgb.blockChainDbID(pgb.ctx, hash)
}
|
go
|
func (pgb *ChainDB) BlockChainDbID(hash string) (dbID uint64, err error) {
return pgb.blockChainDbID(pgb.ctx, hash)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"BlockChainDbID",
"(",
"hash",
"string",
")",
"(",
"dbID",
"uint64",
",",
"err",
"error",
")",
"{",
"return",
"pgb",
".",
"blockChainDbID",
"(",
"pgb",
".",
"ctx",
",",
"hash",
")",
"\n",
"}"
] |
// BlockChainDbID gets the row ID of the given block hash in the block_chain
// table. The cancellation context is used without timeout.
|
[
"BlockChainDbID",
"gets",
"the",
"row",
"ID",
"of",
"the",
"given",
"block",
"hash",
"in",
"the",
"block_chain",
"table",
".",
"The",
"cancellation",
"context",
"is",
"used",
"without",
"timeout",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L933-L935
|
141,920 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
BlockChainDbIDNoCancel
|
func (pgb *ChainDB) BlockChainDbIDNoCancel(hash string) (dbID uint64, err error) {
return pgb.blockChainDbID(context.Background(), hash)
}
|
go
|
func (pgb *ChainDB) BlockChainDbIDNoCancel(hash string) (dbID uint64, err error) {
return pgb.blockChainDbID(context.Background(), hash)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"BlockChainDbIDNoCancel",
"(",
"hash",
"string",
")",
"(",
"dbID",
"uint64",
",",
"err",
"error",
")",
"{",
"return",
"pgb",
".",
"blockChainDbID",
"(",
"context",
".",
"Background",
"(",
")",
",",
"hash",
")",
"\n",
"}"
] |
// BlockChainDbIDNoCancel gets the row ID of the given block hash in the
// block_chain table. The cancellation context is used without timeout.
|
[
"BlockChainDbIDNoCancel",
"gets",
"the",
"row",
"ID",
"of",
"the",
"given",
"block",
"hash",
"in",
"the",
"block_chain",
"table",
".",
"The",
"cancellation",
"context",
"is",
"used",
"without",
"timeout",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L939-L941
|
141,921 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
TransactionBlocks
|
func (pgb *ChainDB) TransactionBlocks(txHash string) ([]*dbtypes.BlockStatus, []uint32, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
hashes, heights, inds, valids, mainchains, err := RetrieveTxnsBlocks(ctx, pgb.db, txHash)
if err != nil {
return nil, nil, pgb.replaceCancelError(err)
}
blocks := make([]*dbtypes.BlockStatus, len(hashes))
for i := range hashes {
blocks[i] = &dbtypes.BlockStatus{
IsValid: valids[i],
IsMainchain: mainchains[i],
Height: heights[i],
Hash: hashes[i],
// Next and previous hash not set
}
}
return blocks, inds, nil
}
|
go
|
func (pgb *ChainDB) TransactionBlocks(txHash string) ([]*dbtypes.BlockStatus, []uint32, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
hashes, heights, inds, valids, mainchains, err := RetrieveTxnsBlocks(ctx, pgb.db, txHash)
if err != nil {
return nil, nil, pgb.replaceCancelError(err)
}
blocks := make([]*dbtypes.BlockStatus, len(hashes))
for i := range hashes {
blocks[i] = &dbtypes.BlockStatus{
IsValid: valids[i],
IsMainchain: mainchains[i],
Height: heights[i],
Hash: hashes[i],
// Next and previous hash not set
}
}
return blocks, inds, nil
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"TransactionBlocks",
"(",
"txHash",
"string",
")",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"BlockStatus",
",",
"[",
"]",
"uint32",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"hashes",
",",
"heights",
",",
"inds",
",",
"valids",
",",
"mainchains",
",",
"err",
":=",
"RetrieveTxnsBlocks",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"txHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"blocks",
":=",
"make",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"BlockStatus",
",",
"len",
"(",
"hashes",
")",
")",
"\n\n",
"for",
"i",
":=",
"range",
"hashes",
"{",
"blocks",
"[",
"i",
"]",
"=",
"&",
"dbtypes",
".",
"BlockStatus",
"{",
"IsValid",
":",
"valids",
"[",
"i",
"]",
",",
"IsMainchain",
":",
"mainchains",
"[",
"i",
"]",
",",
"Height",
":",
"heights",
"[",
"i",
"]",
",",
"Hash",
":",
"hashes",
"[",
"i",
"]",
",",
"// Next and previous hash not set",
"}",
"\n",
"}",
"\n\n",
"return",
"blocks",
",",
"inds",
",",
"nil",
"\n",
"}"
] |
// TransactionBlocks retrieves the blocks in which the specified transaction
// appears, along with the index of the transaction in each of the blocks. The
// next and previous block hashes are NOT SET in each BlockStatus.
|
[
"TransactionBlocks",
"retrieves",
"the",
"blocks",
"in",
"which",
"the",
"specified",
"transaction",
"appears",
"along",
"with",
"the",
"index",
"of",
"the",
"transaction",
"in",
"each",
"of",
"the",
"blocks",
".",
"The",
"next",
"and",
"previous",
"block",
"hashes",
"are",
"NOT",
"SET",
"in",
"each",
"BlockStatus",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L968-L989
|
141,922 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
HeightDB
|
func (pgb *ChainDB) HeightDB() (int64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
bestHeight, _, _, err := RetrieveBestBlockHeight(ctx, pgb.db)
height := int64(bestHeight)
if err == sql.ErrNoRows {
height = -1
}
// DO NOT change this to return -1 if err == sql.ErrNoRows.
return height, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) HeightDB() (int64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
bestHeight, _, _, err := RetrieveBestBlockHeight(ctx, pgb.db)
height := int64(bestHeight)
if err == sql.ErrNoRows {
height = -1
}
// DO NOT change this to return -1 if err == sql.ErrNoRows.
return height, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"HeightDB",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"bestHeight",
",",
"_",
",",
"_",
",",
"err",
":=",
"RetrieveBestBlockHeight",
"(",
"ctx",
",",
"pgb",
".",
"db",
")",
"\n",
"height",
":=",
"int64",
"(",
"bestHeight",
")",
"\n",
"if",
"err",
"==",
"sql",
".",
"ErrNoRows",
"{",
"height",
"=",
"-",
"1",
"\n",
"}",
"\n",
"// DO NOT change this to return -1 if err == sql.ErrNoRows.",
"return",
"height",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// HeightDB queries the DB for the best block height. When the tables are empty,
// the returned height will be -1.
|
[
"HeightDB",
"queries",
"the",
"DB",
"for",
"the",
"best",
"block",
"height",
".",
"When",
"the",
"tables",
"are",
"empty",
"the",
"returned",
"height",
"will",
"be",
"-",
"1",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L993-L1003
|
141,923 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
HashDB
|
func (pgb *ChainDB) HashDB() (string, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, bestHash, _, err := RetrieveBestBlockHeight(ctx, pgb.db)
return bestHash, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) HashDB() (string, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, bestHash, _, err := RetrieveBestBlockHeight(ctx, pgb.db)
return bestHash, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"HashDB",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"_",
",",
"bestHash",
",",
"_",
",",
"err",
":=",
"RetrieveBestBlockHeight",
"(",
"ctx",
",",
"pgb",
".",
"db",
")",
"\n",
"return",
"bestHash",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// HashDB queries the DB for the best block's hash.
|
[
"HashDB",
"queries",
"the",
"DB",
"for",
"the",
"best",
"block",
"s",
"hash",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1006-L1011
|
141,924 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
HeightHashDB
|
func (pgb *ChainDB) HeightHashDB() (uint64, string, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
height, hash, _, err := RetrieveBestBlockHeight(ctx, pgb.db)
return height, hash, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) HeightHashDB() (uint64, string, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
height, hash, _, err := RetrieveBestBlockHeight(ctx, pgb.db)
return height, hash, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"HeightHashDB",
"(",
")",
"(",
"uint64",
",",
"string",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"height",
",",
"hash",
",",
"_",
",",
"err",
":=",
"RetrieveBestBlockHeight",
"(",
"ctx",
",",
"pgb",
".",
"db",
")",
"\n",
"return",
"height",
",",
"hash",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// HeightHashDB queries the DB for the best block's height and hash.
|
[
"HeightHashDB",
"queries",
"the",
"DB",
"for",
"the",
"best",
"block",
"s",
"height",
"and",
"hash",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1014-L1019
|
141,925 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
Height
|
func (block *BestBlock) Height() int64 {
block.mtx.RLock()
defer block.mtx.RUnlock()
return block.height
}
|
go
|
func (block *BestBlock) Height() int64 {
block.mtx.RLock()
defer block.mtx.RUnlock()
return block.height
}
|
[
"func",
"(",
"block",
"*",
"BestBlock",
")",
"Height",
"(",
")",
"int64",
"{",
"block",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"block",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"block",
".",
"height",
"\n",
"}"
] |
// Height uses the last stored height.
|
[
"Height",
"uses",
"the",
"last",
"stored",
"height",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1027-L1031
|
141,926 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
HashStr
|
func (block *BestBlock) HashStr() string {
block.mtx.RLock()
defer block.mtx.RUnlock()
return block.hash
}
|
go
|
func (block *BestBlock) HashStr() string {
block.mtx.RLock()
defer block.mtx.RUnlock()
return block.hash
}
|
[
"func",
"(",
"block",
"*",
"BestBlock",
")",
"HashStr",
"(",
")",
"string",
"{",
"block",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"block",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"block",
".",
"hash",
"\n",
"}"
] |
// HashStr uses the last stored block hash.
|
[
"HashStr",
"uses",
"the",
"last",
"stored",
"block",
"hash",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1040-L1044
|
141,927 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
Hash
|
func (block *BestBlock) Hash() *chainhash.Hash {
// Caller should check hash instead of error
hash, _ := chainhash.NewHashFromStr(block.HashStr())
return hash
}
|
go
|
func (block *BestBlock) Hash() *chainhash.Hash {
// Caller should check hash instead of error
hash, _ := chainhash.NewHashFromStr(block.HashStr())
return hash
}
|
[
"func",
"(",
"block",
"*",
"BestBlock",
")",
"Hash",
"(",
")",
"*",
"chainhash",
".",
"Hash",
"{",
"// Caller should check hash instead of error",
"hash",
",",
"_",
":=",
"chainhash",
".",
"NewHashFromStr",
"(",
"block",
".",
"HashStr",
"(",
")",
")",
"\n",
"return",
"hash",
"\n",
"}"
] |
// Hash uses the last stored block hash.
|
[
"Hash",
"uses",
"the",
"last",
"stored",
"block",
"hash",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1047-L1051
|
141,928 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
BlockHeight
|
func (pgb *ChainDB) BlockHeight(hash string) (int64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
height, err := RetrieveBlockHeight(ctx, pgb.db, hash)
return height, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) BlockHeight(hash string) (int64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
height, err := RetrieveBlockHeight(ctx, pgb.db, hash)
return height, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"BlockHeight",
"(",
"hash",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"height",
",",
"err",
":=",
"RetrieveBlockHeight",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"hash",
")",
"\n",
"return",
"height",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// BlockHeight queries the DB for the height of the specified hash.
|
[
"BlockHeight",
"queries",
"the",
"DB",
"for",
"the",
"height",
"of",
"the",
"specified",
"hash",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1077-L1082
|
141,929 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
BlockHash
|
func (pgb *ChainDB) BlockHash(height int64) (string, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
hash, err := RetrieveBlockHash(ctx, pgb.db, height)
return hash, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) BlockHash(height int64) (string, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
hash, err := RetrieveBlockHash(ctx, pgb.db, height)
return hash, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"BlockHash",
"(",
"height",
"int64",
")",
"(",
"string",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"hash",
",",
"err",
":=",
"RetrieveBlockHash",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"height",
")",
"\n",
"return",
"hash",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// BlockHash queries the DB for the hash of the mainchain block at the given
// height.
|
[
"BlockHash",
"queries",
"the",
"DB",
"for",
"the",
"hash",
"of",
"the",
"mainchain",
"block",
"at",
"the",
"given",
"height",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1086-L1091
|
141,930 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
BlockTimeByHeight
|
func (pgb *ChainDB) BlockTimeByHeight(height int64) (int64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
time, err := RetrieveBlockTimeByHeight(ctx, pgb.db, height)
return time.UNIX(), pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) BlockTimeByHeight(height int64) (int64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
time, err := RetrieveBlockTimeByHeight(ctx, pgb.db, height)
return time.UNIX(), pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"BlockTimeByHeight",
"(",
"height",
"int64",
")",
"(",
"int64",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"time",
",",
"err",
":=",
"RetrieveBlockTimeByHeight",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"height",
")",
"\n",
"return",
"time",
".",
"UNIX",
"(",
")",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// BlockTimeByHeight queries the DB for the time of the mainchain block at the
// given height.
|
[
"BlockTimeByHeight",
"queries",
"the",
"DB",
"for",
"the",
"time",
"of",
"the",
"mainchain",
"block",
"at",
"the",
"given",
"height",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1095-L1100
|
141,931 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
VotesInBlock
|
func (pgb *ChainDB) VotesInBlock(hash string) (int16, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
voters, err := RetrieveBlockVoteCount(ctx, pgb.db, hash)
if err != nil {
err = pgb.replaceCancelError(err)
log.Errorf("Unable to get block voter count for hash %s: %v", hash, err)
return -1, err
}
return voters, nil
}
|
go
|
func (pgb *ChainDB) VotesInBlock(hash string) (int16, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
voters, err := RetrieveBlockVoteCount(ctx, pgb.db, hash)
if err != nil {
err = pgb.replaceCancelError(err)
log.Errorf("Unable to get block voter count for hash %s: %v", hash, err)
return -1, err
}
return voters, nil
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"VotesInBlock",
"(",
"hash",
"string",
")",
"(",
"int16",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"voters",
",",
"err",
":=",
"RetrieveBlockVoteCount",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"hash",
",",
"err",
")",
"\n",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n",
"return",
"voters",
",",
"nil",
"\n",
"}"
] |
// VotesInBlock returns the number of votes mined in the block with the
// specified hash.
|
[
"VotesInBlock",
"returns",
"the",
"number",
"of",
"votes",
"mined",
"in",
"the",
"block",
"with",
"the",
"specified",
"hash",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1104-L1114
|
141,932 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
proposalsUpdateHandler
|
func (pgb *ChainDB) proposalsUpdateHandler() {
// Do not initiate the async update if invalid piparser instance was found.
if pgb.piparser == nil {
log.Debug("invalid piparser instance was found: async update stopped")
return
}
go func() {
for range pgb.piparser.UpdateSignal() {
count, err := pgb.PiProposalsHistory()
if err != nil {
log.Error("pgb.PiProposalsHistory failed : %v", err)
} else {
log.Infof("%d politeia's proposal commits were processed", count)
}
}
}()
}
|
go
|
func (pgb *ChainDB) proposalsUpdateHandler() {
// Do not initiate the async update if invalid piparser instance was found.
if pgb.piparser == nil {
log.Debug("invalid piparser instance was found: async update stopped")
return
}
go func() {
for range pgb.piparser.UpdateSignal() {
count, err := pgb.PiProposalsHistory()
if err != nil {
log.Error("pgb.PiProposalsHistory failed : %v", err)
} else {
log.Infof("%d politeia's proposal commits were processed", count)
}
}
}()
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"proposalsUpdateHandler",
"(",
")",
"{",
"// Do not initiate the async update if invalid piparser instance was found.",
"if",
"pgb",
".",
"piparser",
"==",
"nil",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
"range",
"pgb",
".",
"piparser",
".",
"UpdateSignal",
"(",
")",
"{",
"count",
",",
"err",
":=",
"pgb",
".",
"PiProposalsHistory",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"count",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"}"
] |
// proposalsUpdateHandler runs in the background asynchronous to retrieve the
// politeia proposal updates that the piparser tool signaled.
|
[
"proposalsUpdateHandler",
"runs",
"in",
"the",
"background",
"asynchronous",
"to",
"retrieve",
"the",
"politeia",
"proposal",
"updates",
"that",
"the",
"piparser",
"tool",
"signaled",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1118-L1135
|
141,933 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
LastPiParserSync
|
func (pgb *ChainDB) LastPiParserSync() time.Time {
pgb.proposalsSync.mtx.RLock()
defer pgb.proposalsSync.mtx.RUnlock()
return pgb.proposalsSync.syncTime
}
|
go
|
func (pgb *ChainDB) LastPiParserSync() time.Time {
pgb.proposalsSync.mtx.RLock()
defer pgb.proposalsSync.mtx.RUnlock()
return pgb.proposalsSync.syncTime
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"LastPiParserSync",
"(",
")",
"time",
".",
"Time",
"{",
"pgb",
".",
"proposalsSync",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"pgb",
".",
"proposalsSync",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"pgb",
".",
"proposalsSync",
".",
"syncTime",
"\n",
"}"
] |
// LastPiParserSync returns last time value when the piparser run sync on proposals
// and proposal_votes table.
|
[
"LastPiParserSync",
"returns",
"last",
"time",
"value",
"when",
"the",
"piparser",
"run",
"sync",
"on",
"proposals",
"and",
"proposal_votes",
"table",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1139-L1143
|
141,934 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
PiProposalsHistory
|
func (pgb *ChainDB) PiProposalsHistory() (int64, error) {
if pgb.piparser == nil {
return -1, fmt.Errorf("invalid piparser instance was found")
}
pgb.proposalsSync.mtx.Lock()
// set the sync time
pgb.proposalsSync.syncTime = time.Now().UTC()
pgb.proposalsSync.mtx.Unlock()
var isChecked bool
var proposalsData []*pitypes.History
lastUpdate, err := retrieveLastCommitTime(pgb.db)
switch {
case err == sql.ErrNoRows:
// No records exists yet fetch all the history.
proposalsData, err = pgb.piparser.ProposalsHistory()
case err != nil:
return -1, fmt.Errorf("retrieveLastCommitTime failed :%v", err)
default:
// Fetch the updates since the last insert only.
proposalsData, err = pgb.piparser.ProposalsHistorySince(lastUpdate)
isChecked = true
}
if err != nil {
return -1, fmt.Errorf("politeia proposals fetch failed: %v", err)
}
var commitsCount int64
for _, entry := range proposalsData {
if entry.CommitSHA == "" {
// If missing commit sha ignore the entry.
continue
}
// Multiple tokens votes data can be packed in a single Politeia's commit.
for _, val := range entry.Patch {
if val.Token == "" {
// If missing token ignore it.
continue
}
id, err := InsertProposal(pgb.db, val.Token, entry.Author,
entry.CommitSHA, entry.Date, isChecked)
if err != nil {
return -1, fmt.Errorf("InsertProposal failed: %v", err)
}
for _, vote := range val.VotesInfo {
_, err = InsertProposalVote(pgb.db, id, vote.Ticket,
string(vote.VoteBit), isChecked)
if err != nil {
return -1, fmt.Errorf("InsertProposalVote failed: %v", err)
}
}
}
commitsCount++
}
return commitsCount, err
}
|
go
|
func (pgb *ChainDB) PiProposalsHistory() (int64, error) {
if pgb.piparser == nil {
return -1, fmt.Errorf("invalid piparser instance was found")
}
pgb.proposalsSync.mtx.Lock()
// set the sync time
pgb.proposalsSync.syncTime = time.Now().UTC()
pgb.proposalsSync.mtx.Unlock()
var isChecked bool
var proposalsData []*pitypes.History
lastUpdate, err := retrieveLastCommitTime(pgb.db)
switch {
case err == sql.ErrNoRows:
// No records exists yet fetch all the history.
proposalsData, err = pgb.piparser.ProposalsHistory()
case err != nil:
return -1, fmt.Errorf("retrieveLastCommitTime failed :%v", err)
default:
// Fetch the updates since the last insert only.
proposalsData, err = pgb.piparser.ProposalsHistorySince(lastUpdate)
isChecked = true
}
if err != nil {
return -1, fmt.Errorf("politeia proposals fetch failed: %v", err)
}
var commitsCount int64
for _, entry := range proposalsData {
if entry.CommitSHA == "" {
// If missing commit sha ignore the entry.
continue
}
// Multiple tokens votes data can be packed in a single Politeia's commit.
for _, val := range entry.Patch {
if val.Token == "" {
// If missing token ignore it.
continue
}
id, err := InsertProposal(pgb.db, val.Token, entry.Author,
entry.CommitSHA, entry.Date, isChecked)
if err != nil {
return -1, fmt.Errorf("InsertProposal failed: %v", err)
}
for _, vote := range val.VotesInfo {
_, err = InsertProposalVote(pgb.db, id, vote.Ticket,
string(vote.VoteBit), isChecked)
if err != nil {
return -1, fmt.Errorf("InsertProposalVote failed: %v", err)
}
}
}
commitsCount++
}
return commitsCount, err
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"PiProposalsHistory",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"pgb",
".",
"piparser",
"==",
"nil",
"{",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"pgb",
".",
"proposalsSync",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n\n",
"// set the sync time",
"pgb",
".",
"proposalsSync",
".",
"syncTime",
"=",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
"\n\n",
"pgb",
".",
"proposalsSync",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"var",
"isChecked",
"bool",
"\n",
"var",
"proposalsData",
"[",
"]",
"*",
"pitypes",
".",
"History",
"\n\n",
"lastUpdate",
",",
"err",
":=",
"retrieveLastCommitTime",
"(",
"pgb",
".",
"db",
")",
"\n",
"switch",
"{",
"case",
"err",
"==",
"sql",
".",
"ErrNoRows",
":",
"// No records exists yet fetch all the history.",
"proposalsData",
",",
"err",
"=",
"pgb",
".",
"piparser",
".",
"ProposalsHistory",
"(",
")",
"\n\n",
"case",
"err",
"!=",
"nil",
":",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n\n",
"default",
":",
"// Fetch the updates since the last insert only.",
"proposalsData",
",",
"err",
"=",
"pgb",
".",
"piparser",
".",
"ProposalsHistorySince",
"(",
"lastUpdate",
")",
"\n",
"isChecked",
"=",
"true",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"commitsCount",
"int64",
"\n\n",
"for",
"_",
",",
"entry",
":=",
"range",
"proposalsData",
"{",
"if",
"entry",
".",
"CommitSHA",
"==",
"\"",
"\"",
"{",
"// If missing commit sha ignore the entry.",
"continue",
"\n",
"}",
"\n\n",
"// Multiple tokens votes data can be packed in a single Politeia's commit.",
"for",
"_",
",",
"val",
":=",
"range",
"entry",
".",
"Patch",
"{",
"if",
"val",
".",
"Token",
"==",
"\"",
"\"",
"{",
"// If missing token ignore it.",
"continue",
"\n",
"}",
"\n\n",
"id",
",",
"err",
":=",
"InsertProposal",
"(",
"pgb",
".",
"db",
",",
"val",
".",
"Token",
",",
"entry",
".",
"Author",
",",
"entry",
".",
"CommitSHA",
",",
"entry",
".",
"Date",
",",
"isChecked",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"vote",
":=",
"range",
"val",
".",
"VotesInfo",
"{",
"_",
",",
"err",
"=",
"InsertProposalVote",
"(",
"pgb",
".",
"db",
",",
"id",
",",
"vote",
".",
"Ticket",
",",
"string",
"(",
"vote",
".",
"VoteBit",
")",
",",
"isChecked",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"commitsCount",
"++",
"\n",
"}",
"\n\n",
"return",
"commitsCount",
",",
"err",
"\n",
"}"
] |
// PiProposalsHistory queries the politeia's proposal updates via the parser tool
// and pushes them to the proposals and proposal_votes tables.
|
[
"PiProposalsHistory",
"queries",
"the",
"politeia",
"s",
"proposal",
"updates",
"via",
"the",
"parser",
"tool",
"and",
"pushes",
"them",
"to",
"the",
"proposals",
"and",
"proposal_votes",
"tables",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1147-L1214
|
141,935 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
ProposalVotes
|
func (pgb *ChainDB) ProposalVotes(proposalToken string) (*dbtypes.ProposalChartsData, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
chartsData, err := retrieveProposalVotesData(ctx, pgb.db, proposalToken)
return chartsData, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) ProposalVotes(proposalToken string) (*dbtypes.ProposalChartsData, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
chartsData, err := retrieveProposalVotesData(ctx, pgb.db, proposalToken)
return chartsData, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"ProposalVotes",
"(",
"proposalToken",
"string",
")",
"(",
"*",
"dbtypes",
".",
"ProposalChartsData",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"chartsData",
",",
"err",
":=",
"retrieveProposalVotesData",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"proposalToken",
")",
"\n",
"return",
"chartsData",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// ProposalVotes retrieves all the votes data associated with the provided token.
|
[
"ProposalVotes",
"retrieves",
"all",
"the",
"votes",
"data",
"associated",
"with",
"the",
"provided",
"token",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1217-L1222
|
141,936 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
SpendingTransactions
|
func (pgb *ChainDB) SpendingTransactions(fundingTxID string) ([]string, []uint32, []uint32, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, spendingTxns, vinInds, voutInds, err := RetrieveSpendingTxsByFundingTx(ctx, pgb.db, fundingTxID)
return spendingTxns, vinInds, voutInds, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) SpendingTransactions(fundingTxID string) ([]string, []uint32, []uint32, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, spendingTxns, vinInds, voutInds, err := RetrieveSpendingTxsByFundingTx(ctx, pgb.db, fundingTxID)
return spendingTxns, vinInds, voutInds, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"SpendingTransactions",
"(",
"fundingTxID",
"string",
")",
"(",
"[",
"]",
"string",
",",
"[",
"]",
"uint32",
",",
"[",
"]",
"uint32",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"_",
",",
"spendingTxns",
",",
"vinInds",
",",
"voutInds",
",",
"err",
":=",
"RetrieveSpendingTxsByFundingTx",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"fundingTxID",
")",
"\n",
"return",
"spendingTxns",
",",
"vinInds",
",",
"voutInds",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// SpendingTransactions retrieves all transactions spending outpoints from the
// specified funding transaction. The spending transaction hashes, the spending
// tx input indexes, and the corresponding funding tx output indexes, and an
// error value are returned.
|
[
"SpendingTransactions",
"retrieves",
"all",
"transactions",
"spending",
"outpoints",
"from",
"the",
"specified",
"funding",
"transaction",
".",
"The",
"spending",
"transaction",
"hashes",
"the",
"spending",
"tx",
"input",
"indexes",
"and",
"the",
"corresponding",
"funding",
"tx",
"output",
"indexes",
"and",
"an",
"error",
"value",
"are",
"returned",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1228-L1233
|
141,937 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
SpendingTransaction
|
func (pgb *ChainDB) SpendingTransaction(fundingTxID string,
fundingTxVout uint32) (string, uint32, int8, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, spendingTx, vinInd, tree, err := RetrieveSpendingTxByTxOut(ctx, pgb.db, fundingTxID, fundingTxVout)
return spendingTx, vinInd, tree, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) SpendingTransaction(fundingTxID string,
fundingTxVout uint32) (string, uint32, int8, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, spendingTx, vinInd, tree, err := RetrieveSpendingTxByTxOut(ctx, pgb.db, fundingTxID, fundingTxVout)
return spendingTx, vinInd, tree, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"SpendingTransaction",
"(",
"fundingTxID",
"string",
",",
"fundingTxVout",
"uint32",
")",
"(",
"string",
",",
"uint32",
",",
"int8",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"_",
",",
"spendingTx",
",",
"vinInd",
",",
"tree",
",",
"err",
":=",
"RetrieveSpendingTxByTxOut",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"fundingTxID",
",",
"fundingTxVout",
")",
"\n",
"return",
"spendingTx",
",",
"vinInd",
",",
"tree",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// SpendingTransaction returns the transaction that spends the specified
// transaction outpoint, if it is spent. The spending transaction hash, input
// index, tx tree, and an error value are returned.
|
[
"SpendingTransaction",
"returns",
"the",
"transaction",
"that",
"spends",
"the",
"specified",
"transaction",
"outpoint",
"if",
"it",
"is",
"spent",
".",
"The",
"spending",
"transaction",
"hash",
"input",
"index",
"tx",
"tree",
"and",
"an",
"error",
"value",
"are",
"returned",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1238-L1244
|
141,938 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
BlockTransactions
|
func (pgb *ChainDB) BlockTransactions(blockHash string) ([]string, []uint32, []int8, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, blockTransactions, blockInds, trees, _, err := RetrieveTxsByBlockHash(ctx, pgb.db, blockHash)
return blockTransactions, blockInds, trees, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) BlockTransactions(blockHash string) ([]string, []uint32, []int8, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, blockTransactions, blockInds, trees, _, err := RetrieveTxsByBlockHash(ctx, pgb.db, blockHash)
return blockTransactions, blockInds, trees, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"BlockTransactions",
"(",
"blockHash",
"string",
")",
"(",
"[",
"]",
"string",
",",
"[",
"]",
"uint32",
",",
"[",
"]",
"int8",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"_",
",",
"blockTransactions",
",",
"blockInds",
",",
"trees",
",",
"_",
",",
"err",
":=",
"RetrieveTxsByBlockHash",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"blockHash",
")",
"\n",
"return",
"blockTransactions",
",",
"blockInds",
",",
"trees",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// BlockTransactions retrieves all transactions in the specified block, their
// indexes in the block, their tree, and an error value.
|
[
"BlockTransactions",
"retrieves",
"all",
"transactions",
"in",
"the",
"specified",
"block",
"their",
"indexes",
"in",
"the",
"block",
"their",
"tree",
"and",
"an",
"error",
"value",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1248-L1253
|
141,939 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
Transaction
|
func (pgb *ChainDB) Transaction(txHash string) ([]*dbtypes.Tx, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, dbTxs, err := RetrieveDbTxsByHash(ctx, pgb.db, txHash)
return dbTxs, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) Transaction(txHash string) ([]*dbtypes.Tx, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, dbTxs, err := RetrieveDbTxsByHash(ctx, pgb.db, txHash)
return dbTxs, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"Transaction",
"(",
"txHash",
"string",
")",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"Tx",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"_",
",",
"dbTxs",
",",
"err",
":=",
"RetrieveDbTxsByHash",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"txHash",
")",
"\n",
"return",
"dbTxs",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// Transaction retrieves all rows from the transactions table for the given
// transaction hash.
|
[
"Transaction",
"retrieves",
"all",
"rows",
"from",
"the",
"transactions",
"table",
"for",
"the",
"given",
"transaction",
"hash",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1257-L1262
|
141,940 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
BlockMissedVotes
|
func (pgb *ChainDB) BlockMissedVotes(blockHash string) ([]string, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
mv, err := RetrieveMissedVotesInBlock(ctx, pgb.db, blockHash)
return mv, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) BlockMissedVotes(blockHash string) ([]string, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
mv, err := RetrieveMissedVotesInBlock(ctx, pgb.db, blockHash)
return mv, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"BlockMissedVotes",
"(",
"blockHash",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"mv",
",",
"err",
":=",
"RetrieveMissedVotesInBlock",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"blockHash",
")",
"\n",
"return",
"mv",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// BlockMissedVotes retrieves the ticket IDs for all missed votes in the
// specified block, and an error value.
|
[
"BlockMissedVotes",
"retrieves",
"the",
"ticket",
"IDs",
"for",
"all",
"missed",
"votes",
"in",
"the",
"specified",
"block",
"and",
"an",
"error",
"value",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1266-L1271
|
141,941 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
PoolStatusForTicket
|
func (pgb *ChainDB) PoolStatusForTicket(txid string) (dbtypes.TicketSpendType, dbtypes.TicketPoolStatus, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, spendType, poolStatus, err := RetrieveTicketStatusByHash(ctx, pgb.db, txid)
return spendType, poolStatus, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) PoolStatusForTicket(txid string) (dbtypes.TicketSpendType, dbtypes.TicketPoolStatus, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, spendType, poolStatus, err := RetrieveTicketStatusByHash(ctx, pgb.db, txid)
return spendType, poolStatus, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"PoolStatusForTicket",
"(",
"txid",
"string",
")",
"(",
"dbtypes",
".",
"TicketSpendType",
",",
"dbtypes",
".",
"TicketPoolStatus",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"_",
",",
"spendType",
",",
"poolStatus",
",",
"err",
":=",
"RetrieveTicketStatusByHash",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"txid",
")",
"\n",
"return",
"spendType",
",",
"poolStatus",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// PoolStatusForTicket retrieves the specified ticket's spend status and ticket
// pool status, and an error value.
|
[
"PoolStatusForTicket",
"retrieves",
"the",
"specified",
"ticket",
"s",
"spend",
"status",
"and",
"ticket",
"pool",
"status",
"and",
"an",
"error",
"value",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1296-L1301
|
141,942 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
VoutValue
|
func (pgb *ChainDB) VoutValue(txID string, vout uint32) (uint64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
voutValue, err := RetrieveVoutValue(ctx, pgb.db, txID, vout)
if err != nil {
return 0, pgb.replaceCancelError(err)
}
return voutValue, nil
}
|
go
|
func (pgb *ChainDB) VoutValue(txID string, vout uint32) (uint64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
voutValue, err := RetrieveVoutValue(ctx, pgb.db, txID, vout)
if err != nil {
return 0, pgb.replaceCancelError(err)
}
return voutValue, nil
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"VoutValue",
"(",
"txID",
"string",
",",
"vout",
"uint32",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"voutValue",
",",
"err",
":=",
"RetrieveVoutValue",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"txID",
",",
"vout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"voutValue",
",",
"nil",
"\n",
"}"
] |
// VoutValue retrieves the value of the specified transaction outpoint in atoms.
|
[
"VoutValue",
"retrieves",
"the",
"value",
"of",
"the",
"specified",
"transaction",
"outpoint",
"in",
"atoms",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1304-L1312
|
141,943 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
VoutValues
|
func (pgb *ChainDB) VoutValues(txID string) ([]uint64, []uint32, []int8, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
voutValues, txInds, txTrees, err := RetrieveVoutValues(ctx, pgb.db, txID)
if err != nil {
return nil, nil, nil, pgb.replaceCancelError(err)
}
return voutValues, txInds, txTrees, nil
}
|
go
|
func (pgb *ChainDB) VoutValues(txID string) ([]uint64, []uint32, []int8, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
voutValues, txInds, txTrees, err := RetrieveVoutValues(ctx, pgb.db, txID)
if err != nil {
return nil, nil, nil, pgb.replaceCancelError(err)
}
return voutValues, txInds, txTrees, nil
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"VoutValues",
"(",
"txID",
"string",
")",
"(",
"[",
"]",
"uint64",
",",
"[",
"]",
"uint32",
",",
"[",
"]",
"int8",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"voutValues",
",",
"txInds",
",",
"txTrees",
",",
"err",
":=",
"RetrieveVoutValues",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"txID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"voutValues",
",",
"txInds",
",",
"txTrees",
",",
"nil",
"\n",
"}"
] |
// VoutValues retrieves the values of each outpoint of the specified
// transaction. The corresponding indexes in the block and tx trees of the
// outpoints, and an error value are also returned.
|
[
"VoutValues",
"retrieves",
"the",
"values",
"of",
"each",
"outpoint",
"of",
"the",
"specified",
"transaction",
".",
"The",
"corresponding",
"indexes",
"in",
"the",
"block",
"and",
"tx",
"trees",
"of",
"the",
"outpoints",
"and",
"an",
"error",
"value",
"are",
"also",
"returned",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1317-L1325
|
141,944 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
TransactionBlock
|
func (pgb *ChainDB) TransactionBlock(txID string) (string, uint32, int8, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, blockHash, blockInd, tree, err := RetrieveTxByHash(ctx, pgb.db, txID)
return blockHash, blockInd, tree, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) TransactionBlock(txID string) (string, uint32, int8, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, blockHash, blockInd, tree, err := RetrieveTxByHash(ctx, pgb.db, txID)
return blockHash, blockInd, tree, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"TransactionBlock",
"(",
"txID",
"string",
")",
"(",
"string",
",",
"uint32",
",",
"int8",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"_",
",",
"blockHash",
",",
"blockInd",
",",
"tree",
",",
"err",
":=",
"RetrieveTxByHash",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"txID",
")",
"\n",
"return",
"blockHash",
",",
"blockInd",
",",
"tree",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// TransactionBlock retrieves the hash of the block containing the specified
// transaction. The index of the transaction within the block, the transaction
// index, and an error value are also returned.
|
[
"TransactionBlock",
"retrieves",
"the",
"hash",
"of",
"the",
"block",
"containing",
"the",
"specified",
"transaction",
".",
"The",
"index",
"of",
"the",
"transaction",
"within",
"the",
"block",
"the",
"transaction",
"index",
"and",
"an",
"error",
"value",
"are",
"also",
"returned",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1330-L1335
|
141,945 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
AgendaVotes
|
func (pgb *ChainDB) AgendaVotes(agendaID string, chartType int) (*dbtypes.AgendaVoteChoices, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
chainInfo := pgb.ChainInfo()
agendaInfo := chainInfo.AgendaMileStones[agendaID]
// check if starttime is in the future exit.
if time.Now().Before(agendaInfo.StartTime) {
return nil, nil
}
avc, err := retrieveAgendaVoteChoices(ctx, pgb.db, agendaID, chartType,
agendaInfo.VotingStarted, agendaInfo.VotingDone)
return avc, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) AgendaVotes(agendaID string, chartType int) (*dbtypes.AgendaVoteChoices, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
chainInfo := pgb.ChainInfo()
agendaInfo := chainInfo.AgendaMileStones[agendaID]
// check if starttime is in the future exit.
if time.Now().Before(agendaInfo.StartTime) {
return nil, nil
}
avc, err := retrieveAgendaVoteChoices(ctx, pgb.db, agendaID, chartType,
agendaInfo.VotingStarted, agendaInfo.VotingDone)
return avc, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"AgendaVotes",
"(",
"agendaID",
"string",
",",
"chartType",
"int",
")",
"(",
"*",
"dbtypes",
".",
"AgendaVoteChoices",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"chainInfo",
":=",
"pgb",
".",
"ChainInfo",
"(",
")",
"\n",
"agendaInfo",
":=",
"chainInfo",
".",
"AgendaMileStones",
"[",
"agendaID",
"]",
"\n\n",
"// check if starttime is in the future exit.",
"if",
"time",
".",
"Now",
"(",
")",
".",
"Before",
"(",
"agendaInfo",
".",
"StartTime",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"avc",
",",
"err",
":=",
"retrieveAgendaVoteChoices",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"agendaID",
",",
"chartType",
",",
"agendaInfo",
".",
"VotingStarted",
",",
"agendaInfo",
".",
"VotingDone",
")",
"\n",
"return",
"avc",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// AgendaVotes fetches the data used to plot a graph of votes cast per day per
// choice for the provided agenda.
|
[
"AgendaVotes",
"fetches",
"the",
"data",
"used",
"to",
"plot",
"a",
"graph",
"of",
"votes",
"cast",
"per",
"day",
"per",
"choice",
"for",
"the",
"provided",
"agenda",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1339-L1354
|
141,946 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
AgendasVotesSummary
|
func (pgb *ChainDB) AgendasVotesSummary(agendaID string) (summary *dbtypes.AgendaSummary, err error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
chainInfo := pgb.ChainInfo()
agendaInfo := chainInfo.AgendaMileStones[agendaID]
// Check if starttime is in the future and exit if true.
if time.Now().Before(agendaInfo.StartTime) {
return
}
summary = &dbtypes.AgendaSummary{
VotingStarted: agendaInfo.VotingStarted,
LockedIn: agendaInfo.VotingDone,
}
summary.Yes, summary.Abstain, summary.No, err = retrieveTotalAgendaVotesCount(ctx,
pgb.db, agendaID, agendaInfo.VotingStarted, agendaInfo.VotingDone)
return
}
|
go
|
func (pgb *ChainDB) AgendasVotesSummary(agendaID string) (summary *dbtypes.AgendaSummary, err error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
chainInfo := pgb.ChainInfo()
agendaInfo := chainInfo.AgendaMileStones[agendaID]
// Check if starttime is in the future and exit if true.
if time.Now().Before(agendaInfo.StartTime) {
return
}
summary = &dbtypes.AgendaSummary{
VotingStarted: agendaInfo.VotingStarted,
LockedIn: agendaInfo.VotingDone,
}
summary.Yes, summary.Abstain, summary.No, err = retrieveTotalAgendaVotesCount(ctx,
pgb.db, agendaID, agendaInfo.VotingStarted, agendaInfo.VotingDone)
return
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"AgendasVotesSummary",
"(",
"agendaID",
"string",
")",
"(",
"summary",
"*",
"dbtypes",
".",
"AgendaSummary",
",",
"err",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"chainInfo",
":=",
"pgb",
".",
"ChainInfo",
"(",
")",
"\n",
"agendaInfo",
":=",
"chainInfo",
".",
"AgendaMileStones",
"[",
"agendaID",
"]",
"\n\n",
"// Check if starttime is in the future and exit if true.",
"if",
"time",
".",
"Now",
"(",
")",
".",
"Before",
"(",
"agendaInfo",
".",
"StartTime",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"summary",
"=",
"&",
"dbtypes",
".",
"AgendaSummary",
"{",
"VotingStarted",
":",
"agendaInfo",
".",
"VotingStarted",
",",
"LockedIn",
":",
"agendaInfo",
".",
"VotingDone",
",",
"}",
"\n\n",
"summary",
".",
"Yes",
",",
"summary",
".",
"Abstain",
",",
"summary",
".",
"No",
",",
"err",
"=",
"retrieveTotalAgendaVotesCount",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"agendaID",
",",
"agendaInfo",
".",
"VotingStarted",
",",
"agendaInfo",
".",
"VotingDone",
")",
"\n",
"return",
"\n",
"}"
] |
// AgendasVotesSummary fetches the total vote choices count for the provided agenda.
|
[
"AgendasVotesSummary",
"fetches",
"the",
"total",
"vote",
"choices",
"count",
"for",
"the",
"provided",
"agenda",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1357-L1377
|
141,947 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
AgendaVoteCounts
|
func (pgb *ChainDB) AgendaVoteCounts(agendaID string) (yes, abstain, no uint32, err error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
chainInfo := pgb.ChainInfo()
agendaInfo := chainInfo.AgendaMileStones[agendaID]
// Check if starttime is in the future and exit if true.
if time.Now().Before(agendaInfo.StartTime) {
return
}
return retrieveTotalAgendaVotesCount(ctx, pgb.db, agendaID,
agendaInfo.VotingStarted, agendaInfo.VotingDone)
}
|
go
|
func (pgb *ChainDB) AgendaVoteCounts(agendaID string) (yes, abstain, no uint32, err error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
chainInfo := pgb.ChainInfo()
agendaInfo := chainInfo.AgendaMileStones[agendaID]
// Check if starttime is in the future and exit if true.
if time.Now().Before(agendaInfo.StartTime) {
return
}
return retrieveTotalAgendaVotesCount(ctx, pgb.db, agendaID,
agendaInfo.VotingStarted, agendaInfo.VotingDone)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"AgendaVoteCounts",
"(",
"agendaID",
"string",
")",
"(",
"yes",
",",
"abstain",
",",
"no",
"uint32",
",",
"err",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"chainInfo",
":=",
"pgb",
".",
"ChainInfo",
"(",
")",
"\n",
"agendaInfo",
":=",
"chainInfo",
".",
"AgendaMileStones",
"[",
"agendaID",
"]",
"\n\n",
"// Check if starttime is in the future and exit if true.",
"if",
"time",
".",
"Now",
"(",
")",
".",
"Before",
"(",
"agendaInfo",
".",
"StartTime",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"return",
"retrieveTotalAgendaVotesCount",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"agendaID",
",",
"agendaInfo",
".",
"VotingStarted",
",",
"agendaInfo",
".",
"VotingDone",
")",
"\n",
"}"
] |
// AgendaVoteCounts returns the vote counts for the agenda as builtin types.
|
[
"AgendaVoteCounts",
"returns",
"the",
"vote",
"counts",
"for",
"the",
"agenda",
"as",
"builtin",
"types",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1380-L1394
|
141,948 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
AllAgendas
|
func (pgb *ChainDB) AllAgendas() (map[string]dbtypes.MileStone, error) {
return retrieveAllAgendas(pgb.db)
}
|
go
|
func (pgb *ChainDB) AllAgendas() (map[string]dbtypes.MileStone, error) {
return retrieveAllAgendas(pgb.db)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"AllAgendas",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"dbtypes",
".",
"MileStone",
",",
"error",
")",
"{",
"return",
"retrieveAllAgendas",
"(",
"pgb",
".",
"db",
")",
"\n",
"}"
] |
// AllAgendas returns all the agendas stored currently.
|
[
"AllAgendas",
"returns",
"all",
"the",
"agendas",
"stored",
"currently",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1397-L1399
|
141,949 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
NumAddressIntervals
|
func (pgb *ChainDB) NumAddressIntervals(addr string, grouping dbtypes.TimeBasedGrouping) (int64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
return retrieveAddressTxsCount(ctx, pgb.db, addr, grouping.String())
}
|
go
|
func (pgb *ChainDB) NumAddressIntervals(addr string, grouping dbtypes.TimeBasedGrouping) (int64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
return retrieveAddressTxsCount(ctx, pgb.db, addr, grouping.String())
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"NumAddressIntervals",
"(",
"addr",
"string",
",",
"grouping",
"dbtypes",
".",
"TimeBasedGrouping",
")",
"(",
"int64",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"return",
"retrieveAddressTxsCount",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"addr",
",",
"grouping",
".",
"String",
"(",
")",
")",
"\n",
"}"
] |
// NumAddressIntervals gets the number of unique time intervals for the
// specified grouping where there are entries in the addresses table for the
// given address.
|
[
"NumAddressIntervals",
"gets",
"the",
"number",
"of",
"unique",
"time",
"intervals",
"for",
"the",
"specified",
"grouping",
"where",
"there",
"are",
"entries",
"in",
"the",
"addresses",
"table",
"for",
"the",
"given",
"address",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1404-L1408
|
141,950 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
AddressMetrics
|
func (pgb *ChainDB) AddressMetrics(addr string) (*dbtypes.AddressMetrics, error) {
// For each time grouping/interval size, get the number if intervals with
// data for the address.
var metrics dbtypes.AddressMetrics
for _, s := range dbtypes.TimeIntervals {
numIntervals, err := pgb.NumAddressIntervals(addr, s)
if err != nil {
return nil, fmt.Errorf("retrieveAddressAllTxsCount failed: error: %v", err)
}
switch s {
case dbtypes.YearGrouping:
metrics.YearTxsCount = numIntervals
case dbtypes.MonthGrouping:
metrics.MonthTxsCount = numIntervals
case dbtypes.WeekGrouping:
metrics.WeekTxsCount = numIntervals
case dbtypes.DayGrouping:
metrics.DayTxsCount = numIntervals
}
}
// Get the time of the block with the first transaction involving the
// address (oldest transaction block time).
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
blockTime, err := retrieveOldestTxBlockTime(ctx, pgb.db, addr)
if err != nil {
return nil, fmt.Errorf("retrieveOldestTxBlockTime failed: error: %v", err)
}
metrics.OldestBlockTime = blockTime
return &metrics, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) AddressMetrics(addr string) (*dbtypes.AddressMetrics, error) {
// For each time grouping/interval size, get the number if intervals with
// data for the address.
var metrics dbtypes.AddressMetrics
for _, s := range dbtypes.TimeIntervals {
numIntervals, err := pgb.NumAddressIntervals(addr, s)
if err != nil {
return nil, fmt.Errorf("retrieveAddressAllTxsCount failed: error: %v", err)
}
switch s {
case dbtypes.YearGrouping:
metrics.YearTxsCount = numIntervals
case dbtypes.MonthGrouping:
metrics.MonthTxsCount = numIntervals
case dbtypes.WeekGrouping:
metrics.WeekTxsCount = numIntervals
case dbtypes.DayGrouping:
metrics.DayTxsCount = numIntervals
}
}
// Get the time of the block with the first transaction involving the
// address (oldest transaction block time).
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
blockTime, err := retrieveOldestTxBlockTime(ctx, pgb.db, addr)
if err != nil {
return nil, fmt.Errorf("retrieveOldestTxBlockTime failed: error: %v", err)
}
metrics.OldestBlockTime = blockTime
return &metrics, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"AddressMetrics",
"(",
"addr",
"string",
")",
"(",
"*",
"dbtypes",
".",
"AddressMetrics",
",",
"error",
")",
"{",
"// For each time grouping/interval size, get the number if intervals with",
"// data for the address.",
"var",
"metrics",
"dbtypes",
".",
"AddressMetrics",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"dbtypes",
".",
"TimeIntervals",
"{",
"numIntervals",
",",
"err",
":=",
"pgb",
".",
"NumAddressIntervals",
"(",
"addr",
",",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"switch",
"s",
"{",
"case",
"dbtypes",
".",
"YearGrouping",
":",
"metrics",
".",
"YearTxsCount",
"=",
"numIntervals",
"\n",
"case",
"dbtypes",
".",
"MonthGrouping",
":",
"metrics",
".",
"MonthTxsCount",
"=",
"numIntervals",
"\n",
"case",
"dbtypes",
".",
"WeekGrouping",
":",
"metrics",
".",
"WeekTxsCount",
"=",
"numIntervals",
"\n",
"case",
"dbtypes",
".",
"DayGrouping",
":",
"metrics",
".",
"DayTxsCount",
"=",
"numIntervals",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Get the time of the block with the first transaction involving the",
"// address (oldest transaction block time).",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"blockTime",
",",
"err",
":=",
"retrieveOldestTxBlockTime",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"metrics",
".",
"OldestBlockTime",
"=",
"blockTime",
"\n\n",
"return",
"&",
"metrics",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// AddressMetrics returns the block time of the oldest transaction and the
// total count for all the transactions linked to the provided address grouped
// by years, months, weeks and days time grouping in seconds.
// This helps plot more meaningful address history graphs to the user.
|
[
"AddressMetrics",
"returns",
"the",
"block",
"time",
"of",
"the",
"oldest",
"transaction",
"and",
"the",
"total",
"count",
"for",
"all",
"the",
"transactions",
"linked",
"to",
"the",
"provided",
"address",
"grouped",
"by",
"years",
"months",
"weeks",
"and",
"days",
"time",
"grouping",
"in",
"seconds",
".",
"This",
"helps",
"plot",
"more",
"meaningful",
"address",
"history",
"graphs",
"to",
"the",
"user",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1414-L1447
|
141,951 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
AddressTransactionsAll
|
func (pgb *ChainDB) AddressTransactionsAll(address string) (addressRows []*dbtypes.AddressRow, err error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
addressRows, err = RetrieveAllMainchainAddressTxns(ctx, pgb.db, address)
err = pgb.replaceCancelError(err)
return
}
|
go
|
func (pgb *ChainDB) AddressTransactionsAll(address string) (addressRows []*dbtypes.AddressRow, err error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
addressRows, err = RetrieveAllMainchainAddressTxns(ctx, pgb.db, address)
err = pgb.replaceCancelError(err)
return
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"AddressTransactionsAll",
"(",
"address",
"string",
")",
"(",
"addressRows",
"[",
"]",
"*",
"dbtypes",
".",
"AddressRow",
",",
"err",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"addressRows",
",",
"err",
"=",
"RetrieveAllMainchainAddressTxns",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"address",
")",
"\n",
"err",
"=",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"return",
"\n",
"}"
] |
// AddressTransactionsAll retrieves all non-merged main chain addresses table
// rows for the given address.
|
[
"AddressTransactionsAll",
"retrieves",
"all",
"non",
"-",
"merged",
"main",
"chain",
"addresses",
"table",
"rows",
"for",
"the",
"given",
"address",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1483-L1490
|
141,952 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
AddressHistoryAll
|
func (pgb *ChainDB) AddressHistoryAll(address string, N, offset int64) ([]*dbtypes.AddressRow, *dbtypes.AddressBalance, error) {
return pgb.AddressHistory(address, N, offset, dbtypes.AddrTxnAll)
}
|
go
|
func (pgb *ChainDB) AddressHistoryAll(address string, N, offset int64) ([]*dbtypes.AddressRow, *dbtypes.AddressBalance, error) {
return pgb.AddressHistory(address, N, offset, dbtypes.AddrTxnAll)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"AddressHistoryAll",
"(",
"address",
"string",
",",
"N",
",",
"offset",
"int64",
")",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"AddressRow",
",",
"*",
"dbtypes",
".",
"AddressBalance",
",",
"error",
")",
"{",
"return",
"pgb",
".",
"AddressHistory",
"(",
"address",
",",
"N",
",",
"offset",
",",
"dbtypes",
".",
"AddrTxnAll",
")",
"\n",
"}"
] |
// AddressHistoryAll retrieves N address rows of type AddrTxnAll, skipping over
// offset rows first, in order of block time.
|
[
"AddressHistoryAll",
"retrieves",
"N",
"address",
"rows",
"of",
"type",
"AddrTxnAll",
"skipping",
"over",
"offset",
"rows",
"first",
"in",
"order",
"of",
"block",
"time",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1507-L1509
|
141,953 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
TicketPoolBlockMaturity
|
func (pgb *ChainDB) TicketPoolBlockMaturity() int64 {
bestBlock := int64(pgb.stakeDB.Height())
return bestBlock - int64(pgb.chainParams.TicketMaturity)
}
|
go
|
func (pgb *ChainDB) TicketPoolBlockMaturity() int64 {
bestBlock := int64(pgb.stakeDB.Height())
return bestBlock - int64(pgb.chainParams.TicketMaturity)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"TicketPoolBlockMaturity",
"(",
")",
"int64",
"{",
"bestBlock",
":=",
"int64",
"(",
"pgb",
".",
"stakeDB",
".",
"Height",
"(",
")",
")",
"\n",
"return",
"bestBlock",
"-",
"int64",
"(",
"pgb",
".",
"chainParams",
".",
"TicketMaturity",
")",
"\n",
"}"
] |
// TicketPoolBlockMaturity returns the block at which all tickets with height
// greater than it are immature.
|
[
"TicketPoolBlockMaturity",
"returns",
"the",
"block",
"at",
"which",
"all",
"tickets",
"with",
"height",
"greater",
"than",
"it",
"are",
"immature",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1513-L1516
|
141,954 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
TicketPoolByDateAndInterval
|
func (pgb *ChainDB) TicketPoolByDateAndInterval(maturityBlock int64,
interval dbtypes.TimeBasedGrouping) (*dbtypes.PoolTicketsData, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
tpd, err := retrieveTicketsByDate(ctx, pgb.db, maturityBlock, interval.String())
return tpd, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) TicketPoolByDateAndInterval(maturityBlock int64,
interval dbtypes.TimeBasedGrouping) (*dbtypes.PoolTicketsData, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
tpd, err := retrieveTicketsByDate(ctx, pgb.db, maturityBlock, interval.String())
return tpd, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"TicketPoolByDateAndInterval",
"(",
"maturityBlock",
"int64",
",",
"interval",
"dbtypes",
".",
"TimeBasedGrouping",
")",
"(",
"*",
"dbtypes",
".",
"PoolTicketsData",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"tpd",
",",
"err",
":=",
"retrieveTicketsByDate",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"maturityBlock",
",",
"interval",
".",
"String",
"(",
")",
")",
"\n",
"return",
"tpd",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// TicketPoolByDateAndInterval fetches the tickets ordered by the purchase date
// interval provided and an error value.
|
[
"TicketPoolByDateAndInterval",
"fetches",
"the",
"tickets",
"ordered",
"by",
"the",
"purchase",
"date",
"interval",
"provided",
"and",
"an",
"error",
"value",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1520-L1526
|
141,955 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
PosIntervals
|
func (pgb *ChainDB) PosIntervals(limit, offset uint64) ([]*dbtypes.BlocksGroupedInfo, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
bgi, err := retrieveWindowBlocks(ctx, pgb.db, pgb.chainParams.StakeDiffWindowSize, limit, offset)
return bgi, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) PosIntervals(limit, offset uint64) ([]*dbtypes.BlocksGroupedInfo, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
bgi, err := retrieveWindowBlocks(ctx, pgb.db, pgb.chainParams.StakeDiffWindowSize, limit, offset)
return bgi, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"PosIntervals",
"(",
"limit",
",",
"offset",
"uint64",
")",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"BlocksGroupedInfo",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"bgi",
",",
"err",
":=",
"retrieveWindowBlocks",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"pgb",
".",
"chainParams",
".",
"StakeDiffWindowSize",
",",
"limit",
",",
"offset",
")",
"\n",
"return",
"bgi",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// PosIntervals retrieves the blocks at the respective stakebase windows
// interval. The term "window" is used here to describe the group of blocks
// whose count is defined by chainParams.StakeDiffWindowSize. During this
// chainParams.StakeDiffWindowSize block interval the ticket price and the
// difficulty value is constant.
|
[
"PosIntervals",
"retrieves",
"the",
"blocks",
"at",
"the",
"respective",
"stakebase",
"windows",
"interval",
".",
"The",
"term",
"window",
"is",
"used",
"here",
"to",
"describe",
"the",
"group",
"of",
"blocks",
"whose",
"count",
"is",
"defined",
"by",
"chainParams",
".",
"StakeDiffWindowSize",
".",
"During",
"this",
"chainParams",
".",
"StakeDiffWindowSize",
"block",
"interval",
"the",
"ticket",
"price",
"and",
"the",
"difficulty",
"value",
"is",
"constant",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1533-L1538
|
141,956 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
TimeBasedIntervals
|
func (pgb *ChainDB) TimeBasedIntervals(timeGrouping dbtypes.TimeBasedGrouping,
limit, offset uint64) ([]*dbtypes.BlocksGroupedInfo, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
bgi, err := retrieveTimeBasedBlockListing(ctx, pgb.db, timeGrouping.String(),
limit, offset)
return bgi, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) TimeBasedIntervals(timeGrouping dbtypes.TimeBasedGrouping,
limit, offset uint64) ([]*dbtypes.BlocksGroupedInfo, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
bgi, err := retrieveTimeBasedBlockListing(ctx, pgb.db, timeGrouping.String(),
limit, offset)
return bgi, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"TimeBasedIntervals",
"(",
"timeGrouping",
"dbtypes",
".",
"TimeBasedGrouping",
",",
"limit",
",",
"offset",
"uint64",
")",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"BlocksGroupedInfo",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"bgi",
",",
"err",
":=",
"retrieveTimeBasedBlockListing",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"timeGrouping",
".",
"String",
"(",
")",
",",
"limit",
",",
"offset",
")",
"\n",
"return",
"bgi",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// TimeBasedIntervals retrieves blocks groups by the selected time-based
// interval. For the consecutive groups the number of blocks grouped together is
// not uniform.
|
[
"TimeBasedIntervals",
"retrieves",
"blocks",
"groups",
"by",
"the",
"selected",
"time",
"-",
"based",
"interval",
".",
"For",
"the",
"consecutive",
"groups",
"the",
"number",
"of",
"blocks",
"grouped",
"together",
"is",
"not",
"uniform",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1543-L1550
|
141,957 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
TicketPoolVisualization
|
func (pgb *ChainDB) TicketPoolVisualization(interval dbtypes.TimeBasedGrouping) (*dbtypes.PoolTicketsData,
*dbtypes.PoolTicketsData, *dbtypes.PoolTicketsData, int64, error) {
// Attempt to retrieve data for the current block from cache.
heightSeen := pgb.Height() // current block seen *by the ChainDB*
if heightSeen < 0 {
return nil, nil, nil, -1, fmt.Errorf("no charts data available")
}
timeChart, priceChart, donutCharts, height, intervalFound, stale :=
TicketPoolData(interval, heightSeen)
if intervalFound && !stale {
// The cache was fresh.
return timeChart, priceChart, donutCharts, height, nil
}
// Cache is stale or empty. Attempt to gain updater status.
if !pgb.tpUpdatePermission[interval].TryLock() {
// Another goroutine is running db query to get the updated data.
if !intervalFound {
// Do not even have stale data. Must wait for the DB update to
// complete to get any data at all. Use a blocking call on the
// updater lock even though we are not going to actually do an
// update ourselves so we do not block the cache while waiting.
pgb.tpUpdatePermission[interval].Lock()
defer pgb.tpUpdatePermission[interval].Unlock()
// Try again to pull it from cache now that the update is completed.
heightSeen = pgb.Height()
timeChart, priceChart, donutCharts, height, intervalFound, stale =
TicketPoolData(interval, heightSeen)
// We waited for the updater of this interval, so it should be found
// at this point. If not, this is an error.
if !intervalFound {
log.Errorf("Charts data for interval %v failed to update.", interval)
return nil, nil, nil, 0, fmt.Errorf("no charts data available")
}
if stale {
log.Warnf("Charts data for interval %v updated, but still stale.", interval)
}
}
// else return the stale data instead of waiting.
return timeChart, priceChart, donutCharts, height, nil
}
// This goroutine is now the cache updater.
defer pgb.tpUpdatePermission[interval].Unlock()
// Retrieve chart data for best block in DB.
var err error
timeChart, priceChart, donutCharts, height, err = pgb.ticketPoolVisualization(interval)
if err != nil {
log.Errorf("Failed to fetch ticket pool data: %v", err)
return nil, nil, nil, 0, err
}
// Update the cache with the new ticket pool data.
UpdateTicketPoolData(interval, timeChart, priceChart, donutCharts, height)
return timeChart, priceChart, donutCharts, height, nil
}
|
go
|
func (pgb *ChainDB) TicketPoolVisualization(interval dbtypes.TimeBasedGrouping) (*dbtypes.PoolTicketsData,
*dbtypes.PoolTicketsData, *dbtypes.PoolTicketsData, int64, error) {
// Attempt to retrieve data for the current block from cache.
heightSeen := pgb.Height() // current block seen *by the ChainDB*
if heightSeen < 0 {
return nil, nil, nil, -1, fmt.Errorf("no charts data available")
}
timeChart, priceChart, donutCharts, height, intervalFound, stale :=
TicketPoolData(interval, heightSeen)
if intervalFound && !stale {
// The cache was fresh.
return timeChart, priceChart, donutCharts, height, nil
}
// Cache is stale or empty. Attempt to gain updater status.
if !pgb.tpUpdatePermission[interval].TryLock() {
// Another goroutine is running db query to get the updated data.
if !intervalFound {
// Do not even have stale data. Must wait for the DB update to
// complete to get any data at all. Use a blocking call on the
// updater lock even though we are not going to actually do an
// update ourselves so we do not block the cache while waiting.
pgb.tpUpdatePermission[interval].Lock()
defer pgb.tpUpdatePermission[interval].Unlock()
// Try again to pull it from cache now that the update is completed.
heightSeen = pgb.Height()
timeChart, priceChart, donutCharts, height, intervalFound, stale =
TicketPoolData(interval, heightSeen)
// We waited for the updater of this interval, so it should be found
// at this point. If not, this is an error.
if !intervalFound {
log.Errorf("Charts data for interval %v failed to update.", interval)
return nil, nil, nil, 0, fmt.Errorf("no charts data available")
}
if stale {
log.Warnf("Charts data for interval %v updated, but still stale.", interval)
}
}
// else return the stale data instead of waiting.
return timeChart, priceChart, donutCharts, height, nil
}
// This goroutine is now the cache updater.
defer pgb.tpUpdatePermission[interval].Unlock()
// Retrieve chart data for best block in DB.
var err error
timeChart, priceChart, donutCharts, height, err = pgb.ticketPoolVisualization(interval)
if err != nil {
log.Errorf("Failed to fetch ticket pool data: %v", err)
return nil, nil, nil, 0, err
}
// Update the cache with the new ticket pool data.
UpdateTicketPoolData(interval, timeChart, priceChart, donutCharts, height)
return timeChart, priceChart, donutCharts, height, nil
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"TicketPoolVisualization",
"(",
"interval",
"dbtypes",
".",
"TimeBasedGrouping",
")",
"(",
"*",
"dbtypes",
".",
"PoolTicketsData",
",",
"*",
"dbtypes",
".",
"PoolTicketsData",
",",
"*",
"dbtypes",
".",
"PoolTicketsData",
",",
"int64",
",",
"error",
")",
"{",
"// Attempt to retrieve data for the current block from cache.",
"heightSeen",
":=",
"pgb",
".",
"Height",
"(",
")",
"// current block seen *by the ChainDB*",
"\n",
"if",
"heightSeen",
"<",
"0",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"timeChart",
",",
"priceChart",
",",
"donutCharts",
",",
"height",
",",
"intervalFound",
",",
"stale",
":=",
"TicketPoolData",
"(",
"interval",
",",
"heightSeen",
")",
"\n",
"if",
"intervalFound",
"&&",
"!",
"stale",
"{",
"// The cache was fresh.",
"return",
"timeChart",
",",
"priceChart",
",",
"donutCharts",
",",
"height",
",",
"nil",
"\n",
"}",
"\n\n",
"// Cache is stale or empty. Attempt to gain updater status.",
"if",
"!",
"pgb",
".",
"tpUpdatePermission",
"[",
"interval",
"]",
".",
"TryLock",
"(",
")",
"{",
"// Another goroutine is running db query to get the updated data.",
"if",
"!",
"intervalFound",
"{",
"// Do not even have stale data. Must wait for the DB update to",
"// complete to get any data at all. Use a blocking call on the",
"// updater lock even though we are not going to actually do an",
"// update ourselves so we do not block the cache while waiting.",
"pgb",
".",
"tpUpdatePermission",
"[",
"interval",
"]",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pgb",
".",
"tpUpdatePermission",
"[",
"interval",
"]",
".",
"Unlock",
"(",
")",
"\n",
"// Try again to pull it from cache now that the update is completed.",
"heightSeen",
"=",
"pgb",
".",
"Height",
"(",
")",
"\n",
"timeChart",
",",
"priceChart",
",",
"donutCharts",
",",
"height",
",",
"intervalFound",
",",
"stale",
"=",
"TicketPoolData",
"(",
"interval",
",",
"heightSeen",
")",
"\n",
"// We waited for the updater of this interval, so it should be found",
"// at this point. If not, this is an error.",
"if",
"!",
"intervalFound",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"interval",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"stale",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"interval",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// else return the stale data instead of waiting.",
"return",
"timeChart",
",",
"priceChart",
",",
"donutCharts",
",",
"height",
",",
"nil",
"\n",
"}",
"\n",
"// This goroutine is now the cache updater.",
"defer",
"pgb",
".",
"tpUpdatePermission",
"[",
"interval",
"]",
".",
"Unlock",
"(",
")",
"\n\n",
"// Retrieve chart data for best block in DB.",
"var",
"err",
"error",
"\n",
"timeChart",
",",
"priceChart",
",",
"donutCharts",
",",
"height",
",",
"err",
"=",
"pgb",
".",
"ticketPoolVisualization",
"(",
"interval",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"// Update the cache with the new ticket pool data.",
"UpdateTicketPoolData",
"(",
"interval",
",",
"timeChart",
",",
"priceChart",
",",
"donutCharts",
",",
"height",
")",
"\n\n",
"return",
"timeChart",
",",
"priceChart",
",",
"donutCharts",
",",
"height",
",",
"nil",
"\n",
"}"
] |
// TicketPoolVisualization helps block consecutive and duplicate DB queries for
// the requested ticket pool chart data. If the data for the given interval is
// cached and fresh, it is returned. If the cached data is stale and there are
// no queries running to update the cache for the given interval, this launches
// a query and updates the cache. If there is no cached data for the interval,
// this will launch a new query for the data if one is not already running, and
// if one is running, it will wait for the query to complete.
|
[
"TicketPoolVisualization",
"helps",
"block",
"consecutive",
"and",
"duplicate",
"DB",
"queries",
"for",
"the",
"requested",
"ticket",
"pool",
"chart",
"data",
".",
"If",
"the",
"data",
"for",
"the",
"given",
"interval",
"is",
"cached",
"and",
"fresh",
"it",
"is",
"returned",
".",
"If",
"the",
"cached",
"data",
"is",
"stale",
"and",
"there",
"are",
"no",
"queries",
"running",
"to",
"update",
"the",
"cache",
"for",
"the",
"given",
"interval",
"this",
"launches",
"a",
"query",
"and",
"updates",
"the",
"cache",
".",
"If",
"there",
"is",
"no",
"cached",
"data",
"for",
"the",
"interval",
"this",
"will",
"launch",
"a",
"new",
"query",
"for",
"the",
"data",
"if",
"one",
"is",
"not",
"already",
"running",
"and",
"if",
"one",
"is",
"running",
"it",
"will",
"wait",
"for",
"the",
"query",
"to",
"complete",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1559-L1616
|
141,958 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
GetTicketInfo
|
func (pgb *ChainDB) GetTicketInfo(txid string) (*apitypes.TicketInfo, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
spendStatus, poolStatus, purchaseBlock, lotteryBlock, spendTxid, err := RetrieveTicketInfoByHash(ctx, pgb.db, txid)
if err != nil {
return nil, pgb.replaceCancelError(err)
}
var vote, revocation *string
status := strings.ToLower(poolStatus.String())
maturity := purchaseBlock.Height + uint32(pgb.chainParams.TicketMaturity)
expiration := maturity + pgb.chainParams.TicketExpiry
if pgb.Height() < int64(maturity) {
status = "immature"
}
if spendStatus == dbtypes.TicketRevoked {
status = spendStatus.String()
revocation = &spendTxid
} else if spendStatus == dbtypes.TicketVoted {
vote = &spendTxid
}
if poolStatus == dbtypes.PoolStatusMissed {
hash, height, err := RetrieveMissForTicket(ctx, pgb.db, txid)
if err != nil {
return nil, pgb.replaceCancelError(err)
}
lotteryBlock = &apitypes.TinyBlock{
Hash: hash,
Height: uint32(height),
}
}
return &apitypes.TicketInfo{
Status: status,
PurchaseBlock: purchaseBlock,
MaturityHeight: maturity,
ExpirationHeight: expiration,
LotteryBlock: lotteryBlock,
Vote: vote,
Revocation: revocation,
}, nil
}
|
go
|
func (pgb *ChainDB) GetTicketInfo(txid string) (*apitypes.TicketInfo, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
spendStatus, poolStatus, purchaseBlock, lotteryBlock, spendTxid, err := RetrieveTicketInfoByHash(ctx, pgb.db, txid)
if err != nil {
return nil, pgb.replaceCancelError(err)
}
var vote, revocation *string
status := strings.ToLower(poolStatus.String())
maturity := purchaseBlock.Height + uint32(pgb.chainParams.TicketMaturity)
expiration := maturity + pgb.chainParams.TicketExpiry
if pgb.Height() < int64(maturity) {
status = "immature"
}
if spendStatus == dbtypes.TicketRevoked {
status = spendStatus.String()
revocation = &spendTxid
} else if spendStatus == dbtypes.TicketVoted {
vote = &spendTxid
}
if poolStatus == dbtypes.PoolStatusMissed {
hash, height, err := RetrieveMissForTicket(ctx, pgb.db, txid)
if err != nil {
return nil, pgb.replaceCancelError(err)
}
lotteryBlock = &apitypes.TinyBlock{
Hash: hash,
Height: uint32(height),
}
}
return &apitypes.TicketInfo{
Status: status,
PurchaseBlock: purchaseBlock,
MaturityHeight: maturity,
ExpirationHeight: expiration,
LotteryBlock: lotteryBlock,
Vote: vote,
Revocation: revocation,
}, nil
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"GetTicketInfo",
"(",
"txid",
"string",
")",
"(",
"*",
"apitypes",
".",
"TicketInfo",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"spendStatus",
",",
"poolStatus",
",",
"purchaseBlock",
",",
"lotteryBlock",
",",
"spendTxid",
",",
"err",
":=",
"RetrieveTicketInfoByHash",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"txid",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"vote",
",",
"revocation",
"*",
"string",
"\n",
"status",
":=",
"strings",
".",
"ToLower",
"(",
"poolStatus",
".",
"String",
"(",
")",
")",
"\n",
"maturity",
":=",
"purchaseBlock",
".",
"Height",
"+",
"uint32",
"(",
"pgb",
".",
"chainParams",
".",
"TicketMaturity",
")",
"\n",
"expiration",
":=",
"maturity",
"+",
"pgb",
".",
"chainParams",
".",
"TicketExpiry",
"\n",
"if",
"pgb",
".",
"Height",
"(",
")",
"<",
"int64",
"(",
"maturity",
")",
"{",
"status",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"spendStatus",
"==",
"dbtypes",
".",
"TicketRevoked",
"{",
"status",
"=",
"spendStatus",
".",
"String",
"(",
")",
"\n",
"revocation",
"=",
"&",
"spendTxid",
"\n",
"}",
"else",
"if",
"spendStatus",
"==",
"dbtypes",
".",
"TicketVoted",
"{",
"vote",
"=",
"&",
"spendTxid",
"\n",
"}",
"\n\n",
"if",
"poolStatus",
"==",
"dbtypes",
".",
"PoolStatusMissed",
"{",
"hash",
",",
"height",
",",
"err",
":=",
"RetrieveMissForTicket",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"txid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}",
"\n",
"lotteryBlock",
"=",
"&",
"apitypes",
".",
"TinyBlock",
"{",
"Hash",
":",
"hash",
",",
"Height",
":",
"uint32",
"(",
"height",
")",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"apitypes",
".",
"TicketInfo",
"{",
"Status",
":",
"status",
",",
"PurchaseBlock",
":",
"purchaseBlock",
",",
"MaturityHeight",
":",
"maturity",
",",
"ExpirationHeight",
":",
"expiration",
",",
"LotteryBlock",
":",
"lotteryBlock",
",",
"Vote",
":",
"vote",
",",
"Revocation",
":",
"revocation",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// GetTicketInfo retrieves information about the pool and spend statuses, the
// purchase block, the lottery block, and the spending transaction.
|
[
"GetTicketInfo",
"retrieves",
"information",
"about",
"the",
"pool",
"and",
"spend",
"statuses",
"the",
"purchase",
"block",
"the",
"lottery",
"block",
"and",
"the",
"spending",
"transaction",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1663-L1706
|
141,959 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
FreshenAddressCaches
|
func (pgb *ChainDB) FreshenAddressCaches(lazyProjectFund bool, expireAddresses []string) error {
// Clear existing cache entries.
//numCleared := pgb.AddressCache.ClearAll()
numCleared := pgb.AddressCache.Clear(expireAddresses)
log.Debugf("Cleared cache for %d addresses.", numCleared)
// Do not initiate project fund queries if a reorg is in progress, or
// pre-fetch is disabled.
if !pgb.devPrefetch || pgb.InReorg {
return nil
}
// Update project fund data.
updateFundData := func() error {
log.Infof("Pre-fetching project fund data at height %d...", pgb.Height())
if err := pgb.updateProjectFundCache(); err != nil && err.Error() != "retry" {
err = pgb.replaceCancelError(err)
return fmt.Errorf("Failed to update project fund data: %v", err)
}
return nil
}
if lazyProjectFund {
go func() {
runtime.Gosched()
if err := updateFundData(); err != nil {
log.Error(err)
}
}()
return nil
}
return updateFundData()
}
|
go
|
func (pgb *ChainDB) FreshenAddressCaches(lazyProjectFund bool, expireAddresses []string) error {
// Clear existing cache entries.
//numCleared := pgb.AddressCache.ClearAll()
numCleared := pgb.AddressCache.Clear(expireAddresses)
log.Debugf("Cleared cache for %d addresses.", numCleared)
// Do not initiate project fund queries if a reorg is in progress, or
// pre-fetch is disabled.
if !pgb.devPrefetch || pgb.InReorg {
return nil
}
// Update project fund data.
updateFundData := func() error {
log.Infof("Pre-fetching project fund data at height %d...", pgb.Height())
if err := pgb.updateProjectFundCache(); err != nil && err.Error() != "retry" {
err = pgb.replaceCancelError(err)
return fmt.Errorf("Failed to update project fund data: %v", err)
}
return nil
}
if lazyProjectFund {
go func() {
runtime.Gosched()
if err := updateFundData(); err != nil {
log.Error(err)
}
}()
return nil
}
return updateFundData()
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"FreshenAddressCaches",
"(",
"lazyProjectFund",
"bool",
",",
"expireAddresses",
"[",
"]",
"string",
")",
"error",
"{",
"// Clear existing cache entries.",
"//numCleared := pgb.AddressCache.ClearAll()",
"numCleared",
":=",
"pgb",
".",
"AddressCache",
".",
"Clear",
"(",
"expireAddresses",
")",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"numCleared",
")",
"\n\n",
"// Do not initiate project fund queries if a reorg is in progress, or",
"// pre-fetch is disabled.",
"if",
"!",
"pgb",
".",
"devPrefetch",
"||",
"pgb",
".",
"InReorg",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Update project fund data.",
"updateFundData",
":=",
"func",
"(",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"pgb",
".",
"Height",
"(",
")",
")",
"\n",
"if",
"err",
":=",
"pgb",
".",
"updateProjectFundCache",
"(",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
".",
"Error",
"(",
")",
"!=",
"\"",
"\"",
"{",
"err",
"=",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"lazyProjectFund",
"{",
"go",
"func",
"(",
")",
"{",
"runtime",
".",
"Gosched",
"(",
")",
"\n",
"if",
"err",
":=",
"updateFundData",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"updateFundData",
"(",
")",
"\n",
"}"
] |
// FreshenAddressCaches resets the address balance cache by purging data for the
// addresses listed in expireAddresses, and prefetches the project fund balance
// if devPrefetch is enabled and not mid-reorg. The project fund update is run
// asynchronously if lazyProjectFund is true.
|
[
"FreshenAddressCaches",
"resets",
"the",
"address",
"balance",
"cache",
"by",
"purging",
"data",
"for",
"the",
"addresses",
"listed",
"in",
"expireAddresses",
"and",
"prefetches",
"the",
"project",
"fund",
"balance",
"if",
"devPrefetch",
"is",
"enabled",
"and",
"not",
"mid",
"-",
"reorg",
".",
"The",
"project",
"fund",
"update",
"is",
"run",
"asynchronously",
"if",
"lazyProjectFund",
"is",
"true",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1725-L1757
|
141,960 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
AddressBalance
|
func (pgb *ChainDB) AddressBalance(address string) (bal *dbtypes.AddressBalance, cacheUpdated bool, err error) {
// Check the cache first.
bestHash, height := pgb.BestBlock()
var validHeight *cache.BlockID
bal, validHeight = pgb.AddressCache.Balance(address)
if bal != nil && *bestHash == validHeight.Hash {
return
}
busy, wait, done := pgb.CacheLocks.bal.TryLock(address)
if busy {
// Let others get the wait channel while we wait.
// To return stale cache data if it is available:
// utxos, _ := pgb.AddressCache.UTXOs(address)
// if utxos != nil {
// return utxos, nil
// }
<-wait
// Try again, starting with the cache.
return pgb.AddressBalance(address)
}
// We will run the DB query, so block others from doing the same. When query
// and/or cache update is completed, broadcast to any waiters that the coast
// is clear.
defer done()
// Cache is empty or stale, so query the DB.
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
bal, err = RetrieveAddressBalance(ctx, pgb.db, address)
if err != nil {
err = pgb.replaceCancelError(err)
return
}
// Update the address cache.
cacheUpdated = pgb.AddressCache.StoreBalance(address, bal,
cache.NewBlockID(bestHash, height))
return
}
|
go
|
func (pgb *ChainDB) AddressBalance(address string) (bal *dbtypes.AddressBalance, cacheUpdated bool, err error) {
// Check the cache first.
bestHash, height := pgb.BestBlock()
var validHeight *cache.BlockID
bal, validHeight = pgb.AddressCache.Balance(address)
if bal != nil && *bestHash == validHeight.Hash {
return
}
busy, wait, done := pgb.CacheLocks.bal.TryLock(address)
if busy {
// Let others get the wait channel while we wait.
// To return stale cache data if it is available:
// utxos, _ := pgb.AddressCache.UTXOs(address)
// if utxos != nil {
// return utxos, nil
// }
<-wait
// Try again, starting with the cache.
return pgb.AddressBalance(address)
}
// We will run the DB query, so block others from doing the same. When query
// and/or cache update is completed, broadcast to any waiters that the coast
// is clear.
defer done()
// Cache is empty or stale, so query the DB.
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
bal, err = RetrieveAddressBalance(ctx, pgb.db, address)
if err != nil {
err = pgb.replaceCancelError(err)
return
}
// Update the address cache.
cacheUpdated = pgb.AddressCache.StoreBalance(address, bal,
cache.NewBlockID(bestHash, height))
return
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"AddressBalance",
"(",
"address",
"string",
")",
"(",
"bal",
"*",
"dbtypes",
".",
"AddressBalance",
",",
"cacheUpdated",
"bool",
",",
"err",
"error",
")",
"{",
"// Check the cache first.",
"bestHash",
",",
"height",
":=",
"pgb",
".",
"BestBlock",
"(",
")",
"\n",
"var",
"validHeight",
"*",
"cache",
".",
"BlockID",
"\n",
"bal",
",",
"validHeight",
"=",
"pgb",
".",
"AddressCache",
".",
"Balance",
"(",
"address",
")",
"\n",
"if",
"bal",
"!=",
"nil",
"&&",
"*",
"bestHash",
"==",
"validHeight",
".",
"Hash",
"{",
"return",
"\n",
"}",
"\n\n",
"busy",
",",
"wait",
",",
"done",
":=",
"pgb",
".",
"CacheLocks",
".",
"bal",
".",
"TryLock",
"(",
"address",
")",
"\n",
"if",
"busy",
"{",
"// Let others get the wait channel while we wait.",
"// To return stale cache data if it is available:",
"// utxos, _ := pgb.AddressCache.UTXOs(address)",
"// if utxos != nil {",
"// \treturn utxos, nil",
"// }",
"<-",
"wait",
"\n\n",
"// Try again, starting with the cache.",
"return",
"pgb",
".",
"AddressBalance",
"(",
"address",
")",
"\n",
"}",
"\n\n",
"// We will run the DB query, so block others from doing the same. When query",
"// and/or cache update is completed, broadcast to any waiters that the coast",
"// is clear.",
"defer",
"done",
"(",
")",
"\n\n",
"// Cache is empty or stale, so query the DB.",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"bal",
",",
"err",
"=",
"RetrieveAddressBalance",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Update the address cache.",
"cacheUpdated",
"=",
"pgb",
".",
"AddressCache",
".",
"StoreBalance",
"(",
"address",
",",
"bal",
",",
"cache",
".",
"NewBlockID",
"(",
"bestHash",
",",
"height",
")",
")",
"\n",
"return",
"\n",
"}"
] |
// AddressBalance attempts to retrieve balance information for a specific
// address from cache, and if cache is stale or missing data for the address, a
// DB query is used. A successful DB query will freshen the cache.
|
[
"AddressBalance",
"attempts",
"to",
"retrieve",
"balance",
"information",
"for",
"a",
"specific",
"address",
"from",
"cache",
"and",
"if",
"cache",
"is",
"stale",
"or",
"missing",
"data",
"for",
"the",
"address",
"a",
"DB",
"query",
"is",
"used",
".",
"A",
"successful",
"DB",
"query",
"will",
"freshen",
"the",
"cache",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1789-L1830
|
141,961 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
updateAddressRows
|
func (pgb *ChainDB) updateAddressRows(address string) (rows []*dbtypes.AddressRow, cacheUpdated bool, err error) {
busy, wait, done := pgb.CacheLocks.rows.TryLock(address)
if busy {
// Just wait until the updater is finished.
<-wait
err = fmt.Errorf("retry")
return
}
// We will run the DB query, so block others from doing the same. When query
// and/or cache update is completed, broadcast to any waiters that the coast
// is clear.
defer done()
hash, height := pgb.BestBlock()
blockID := cache.NewBlockID(hash, height)
// Retrieve all non-merged address transaction rows.
rows, err = pgb.AddressTransactionsAll(address)
if err != nil && err != sql.ErrNoRows {
return
}
// Update address rows cache.
cacheUpdated = pgb.AddressCache.StoreRows(address, rows, blockID)
return
}
|
go
|
func (pgb *ChainDB) updateAddressRows(address string) (rows []*dbtypes.AddressRow, cacheUpdated bool, err error) {
busy, wait, done := pgb.CacheLocks.rows.TryLock(address)
if busy {
// Just wait until the updater is finished.
<-wait
err = fmt.Errorf("retry")
return
}
// We will run the DB query, so block others from doing the same. When query
// and/or cache update is completed, broadcast to any waiters that the coast
// is clear.
defer done()
hash, height := pgb.BestBlock()
blockID := cache.NewBlockID(hash, height)
// Retrieve all non-merged address transaction rows.
rows, err = pgb.AddressTransactionsAll(address)
if err != nil && err != sql.ErrNoRows {
return
}
// Update address rows cache.
cacheUpdated = pgb.AddressCache.StoreRows(address, rows, blockID)
return
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"updateAddressRows",
"(",
"address",
"string",
")",
"(",
"rows",
"[",
"]",
"*",
"dbtypes",
".",
"AddressRow",
",",
"cacheUpdated",
"bool",
",",
"err",
"error",
")",
"{",
"busy",
",",
"wait",
",",
"done",
":=",
"pgb",
".",
"CacheLocks",
".",
"rows",
".",
"TryLock",
"(",
"address",
")",
"\n",
"if",
"busy",
"{",
"// Just wait until the updater is finished.",
"<-",
"wait",
"\n",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// We will run the DB query, so block others from doing the same. When query",
"// and/or cache update is completed, broadcast to any waiters that the coast",
"// is clear.",
"defer",
"done",
"(",
")",
"\n\n",
"hash",
",",
"height",
":=",
"pgb",
".",
"BestBlock",
"(",
")",
"\n",
"blockID",
":=",
"cache",
".",
"NewBlockID",
"(",
"hash",
",",
"height",
")",
"\n\n",
"// Retrieve all non-merged address transaction rows.",
"rows",
",",
"err",
"=",
"pgb",
".",
"AddressTransactionsAll",
"(",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"sql",
".",
"ErrNoRows",
"{",
"return",
"\n",
"}",
"\n\n",
"// Update address rows cache.",
"cacheUpdated",
"=",
"pgb",
".",
"AddressCache",
".",
"StoreRows",
"(",
"address",
",",
"rows",
",",
"blockID",
")",
"\n",
"return",
"\n",
"}"
] |
// updateAddressRows updates address rows, or waits for them to update by an
// ongoing query. On completion, the cache should be ready, although it must be
// checked again.
|
[
"updateAddressRows",
"updates",
"address",
"rows",
"or",
"waits",
"for",
"them",
"to",
"update",
"by",
"an",
"ongoing",
"query",
".",
"On",
"completion",
"the",
"cache",
"should",
"be",
"ready",
"although",
"it",
"must",
"be",
"checked",
"again",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1835-L1861
|
141,962 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
AddressRowsMerged
|
func (pgb *ChainDB) AddressRowsMerged(address string) ([]dbtypes.AddressRowMerged, error) {
// Try the address cache.
hash := pgb.BestBlockHash()
rowsCompact, validBlock := pgb.AddressCache.Rows(address)
cacheCurrent := validBlock != nil && validBlock.Hash == *hash && rowsCompact != nil
if cacheCurrent {
log.Tracef("AddressRows: rows cache HIT for %s.", address)
return dbtypes.MergeRowsCompact(rowsCompact), nil
}
log.Tracef("AddressRows: rows cache MISS for %s.", address)
// Update or wait for an update to the cached AddressRows.
rows, _, err := pgb.updateAddressRows(address)
if err != nil {
if err.Error() == "retry" {
// Try again, starting with cache.
return pgb.AddressRowsMerged(address)
}
return nil, err
}
// We have a result.
return dbtypes.MergeRows(rows)
}
|
go
|
func (pgb *ChainDB) AddressRowsMerged(address string) ([]dbtypes.AddressRowMerged, error) {
// Try the address cache.
hash := pgb.BestBlockHash()
rowsCompact, validBlock := pgb.AddressCache.Rows(address)
cacheCurrent := validBlock != nil && validBlock.Hash == *hash && rowsCompact != nil
if cacheCurrent {
log.Tracef("AddressRows: rows cache HIT for %s.", address)
return dbtypes.MergeRowsCompact(rowsCompact), nil
}
log.Tracef("AddressRows: rows cache MISS for %s.", address)
// Update or wait for an update to the cached AddressRows.
rows, _, err := pgb.updateAddressRows(address)
if err != nil {
if err.Error() == "retry" {
// Try again, starting with cache.
return pgb.AddressRowsMerged(address)
}
return nil, err
}
// We have a result.
return dbtypes.MergeRows(rows)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"AddressRowsMerged",
"(",
"address",
"string",
")",
"(",
"[",
"]",
"dbtypes",
".",
"AddressRowMerged",
",",
"error",
")",
"{",
"// Try the address cache.",
"hash",
":=",
"pgb",
".",
"BestBlockHash",
"(",
")",
"\n",
"rowsCompact",
",",
"validBlock",
":=",
"pgb",
".",
"AddressCache",
".",
"Rows",
"(",
"address",
")",
"\n",
"cacheCurrent",
":=",
"validBlock",
"!=",
"nil",
"&&",
"validBlock",
".",
"Hash",
"==",
"*",
"hash",
"&&",
"rowsCompact",
"!=",
"nil",
"\n",
"if",
"cacheCurrent",
"{",
"log",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"address",
")",
"\n",
"return",
"dbtypes",
".",
"MergeRowsCompact",
"(",
"rowsCompact",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"log",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"address",
")",
"\n\n",
"// Update or wait for an update to the cached AddressRows.",
"rows",
",",
"_",
",",
"err",
":=",
"pgb",
".",
"updateAddressRows",
"(",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
".",
"Error",
"(",
")",
"==",
"\"",
"\"",
"{",
"// Try again, starting with cache.",
"return",
"pgb",
".",
"AddressRowsMerged",
"(",
"address",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// We have a result.",
"return",
"dbtypes",
".",
"MergeRows",
"(",
"rows",
")",
"\n",
"}"
] |
// AddressRowsMerged gets the merged address rows either from cache or via DB
// query.
|
[
"AddressRowsMerged",
"gets",
"the",
"merged",
"address",
"rows",
"either",
"from",
"cache",
"or",
"via",
"DB",
"query",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1865-L1889
|
141,963 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
AddressRowsCompact
|
func (pgb *ChainDB) AddressRowsCompact(address string) ([]dbtypes.AddressRowCompact, error) {
// Try the address cache.
hash := pgb.BestBlockHash()
rowsCompact, validBlock := pgb.AddressCache.Rows(address)
cacheCurrent := validBlock != nil && validBlock.Hash == *hash && rowsCompact != nil
if cacheCurrent {
log.Tracef("AddressRows: rows cache HIT for %s.", address)
return rowsCompact, nil
}
log.Tracef("AddressRows: rows cache MISS for %s.", address)
// Update or wait for an update to the cached AddressRows.
rows, _, err := pgb.updateAddressRows(address)
if err != nil {
if err.Error() == "retry" {
// Try again, starting with cache.
return pgb.AddressRowsCompact(address)
}
return nil, err
}
// We have a result.
return dbtypes.CompactRows(rows), err
}
|
go
|
func (pgb *ChainDB) AddressRowsCompact(address string) ([]dbtypes.AddressRowCompact, error) {
// Try the address cache.
hash := pgb.BestBlockHash()
rowsCompact, validBlock := pgb.AddressCache.Rows(address)
cacheCurrent := validBlock != nil && validBlock.Hash == *hash && rowsCompact != nil
if cacheCurrent {
log.Tracef("AddressRows: rows cache HIT for %s.", address)
return rowsCompact, nil
}
log.Tracef("AddressRows: rows cache MISS for %s.", address)
// Update or wait for an update to the cached AddressRows.
rows, _, err := pgb.updateAddressRows(address)
if err != nil {
if err.Error() == "retry" {
// Try again, starting with cache.
return pgb.AddressRowsCompact(address)
}
return nil, err
}
// We have a result.
return dbtypes.CompactRows(rows), err
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"AddressRowsCompact",
"(",
"address",
"string",
")",
"(",
"[",
"]",
"dbtypes",
".",
"AddressRowCompact",
",",
"error",
")",
"{",
"// Try the address cache.",
"hash",
":=",
"pgb",
".",
"BestBlockHash",
"(",
")",
"\n",
"rowsCompact",
",",
"validBlock",
":=",
"pgb",
".",
"AddressCache",
".",
"Rows",
"(",
"address",
")",
"\n",
"cacheCurrent",
":=",
"validBlock",
"!=",
"nil",
"&&",
"validBlock",
".",
"Hash",
"==",
"*",
"hash",
"&&",
"rowsCompact",
"!=",
"nil",
"\n",
"if",
"cacheCurrent",
"{",
"log",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"address",
")",
"\n",
"return",
"rowsCompact",
",",
"nil",
"\n",
"}",
"\n\n",
"log",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"address",
")",
"\n\n",
"// Update or wait for an update to the cached AddressRows.",
"rows",
",",
"_",
",",
"err",
":=",
"pgb",
".",
"updateAddressRows",
"(",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
".",
"Error",
"(",
")",
"==",
"\"",
"\"",
"{",
"// Try again, starting with cache.",
"return",
"pgb",
".",
"AddressRowsCompact",
"(",
"address",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// We have a result.",
"return",
"dbtypes",
".",
"CompactRows",
"(",
"rows",
")",
",",
"err",
"\n",
"}"
] |
// AddressRowsCompact gets non-merged address rows either from cache or via DB
// query.
|
[
"AddressRowsCompact",
"gets",
"non",
"-",
"merged",
"address",
"rows",
"either",
"from",
"cache",
"or",
"via",
"DB",
"query",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1893-L1917
|
141,964 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
retrieveMergedTxnCount
|
func (pgb *ChainDB) retrieveMergedTxnCount(addr string, txnView dbtypes.AddrTxnViewType) (int, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
var count int64
var err error
switch txnView {
case dbtypes.AddrMergedTxnDebit:
count, err = CountMergedSpendingTxns(ctx, pgb.db, addr)
case dbtypes.AddrMergedTxnCredit:
count, err = CountMergedFundingTxns(ctx, pgb.db, addr)
case dbtypes.AddrMergedTxn:
count, err = CountMergedTxns(ctx, pgb.db, addr)
default:
return 0, fmt.Errorf("retrieveMergedTxnCount: requested count for non-merged view")
}
return int(count), err
}
|
go
|
func (pgb *ChainDB) retrieveMergedTxnCount(addr string, txnView dbtypes.AddrTxnViewType) (int, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
var count int64
var err error
switch txnView {
case dbtypes.AddrMergedTxnDebit:
count, err = CountMergedSpendingTxns(ctx, pgb.db, addr)
case dbtypes.AddrMergedTxnCredit:
count, err = CountMergedFundingTxns(ctx, pgb.db, addr)
case dbtypes.AddrMergedTxn:
count, err = CountMergedTxns(ctx, pgb.db, addr)
default:
return 0, fmt.Errorf("retrieveMergedTxnCount: requested count for non-merged view")
}
return int(count), err
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"retrieveMergedTxnCount",
"(",
"addr",
"string",
",",
"txnView",
"dbtypes",
".",
"AddrTxnViewType",
")",
"(",
"int",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"var",
"count",
"int64",
"\n",
"var",
"err",
"error",
"\n",
"switch",
"txnView",
"{",
"case",
"dbtypes",
".",
"AddrMergedTxnDebit",
":",
"count",
",",
"err",
"=",
"CountMergedSpendingTxns",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"addr",
")",
"\n",
"case",
"dbtypes",
".",
"AddrMergedTxnCredit",
":",
"count",
",",
"err",
"=",
"CountMergedFundingTxns",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"addr",
")",
"\n",
"case",
"dbtypes",
".",
"AddrMergedTxn",
":",
"count",
",",
"err",
"=",
"CountMergedTxns",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"addr",
")",
"\n",
"default",
":",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"int",
"(",
"count",
")",
",",
"err",
"\n",
"}"
] |
// retrieveMergedTxnCount queries the DB for the merged address transaction view
// row count.
|
[
"retrieveMergedTxnCount",
"queries",
"the",
"DB",
"for",
"the",
"merged",
"address",
"transaction",
"view",
"row",
"count",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1921-L1938
|
141,965 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
mergedTxnCount
|
func (pgb *ChainDB) mergedTxnCount(addr string, txnView dbtypes.AddrTxnViewType) (int, error) {
// Try the cache first.
rows, blockID := pgb.AddressCache.Rows(addr)
if blockID == nil {
// Query the DB.
return pgb.retrieveMergedTxnCount(addr, txnView)
}
return dbtypes.CountMergedRowsCompact(rows, txnView)
}
|
go
|
func (pgb *ChainDB) mergedTxnCount(addr string, txnView dbtypes.AddrTxnViewType) (int, error) {
// Try the cache first.
rows, blockID := pgb.AddressCache.Rows(addr)
if blockID == nil {
// Query the DB.
return pgb.retrieveMergedTxnCount(addr, txnView)
}
return dbtypes.CountMergedRowsCompact(rows, txnView)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"mergedTxnCount",
"(",
"addr",
"string",
",",
"txnView",
"dbtypes",
".",
"AddrTxnViewType",
")",
"(",
"int",
",",
"error",
")",
"{",
"// Try the cache first.",
"rows",
",",
"blockID",
":=",
"pgb",
".",
"AddressCache",
".",
"Rows",
"(",
"addr",
")",
"\n",
"if",
"blockID",
"==",
"nil",
"{",
"// Query the DB.",
"return",
"pgb",
".",
"retrieveMergedTxnCount",
"(",
"addr",
",",
"txnView",
")",
"\n",
"}",
"\n\n",
"return",
"dbtypes",
".",
"CountMergedRowsCompact",
"(",
"rows",
",",
"txnView",
")",
"\n",
"}"
] |
// mergedTxnCount checks cache and falls back to retrieveMergedTxnCount.
|
[
"mergedTxnCount",
"checks",
"cache",
"and",
"falls",
"back",
"to",
"retrieveMergedTxnCount",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1941-L1950
|
141,966 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
nonMergedTxnCount
|
func (pgb *ChainDB) nonMergedTxnCount(addr string, txnView dbtypes.AddrTxnViewType) (int, error) {
bal, _, err := pgb.AddressBalance(addr)
if err != nil {
return 0, err
}
var count int64
switch txnView {
case dbtypes.AddrTxnAll:
count = (bal.NumSpent * 2) + bal.NumUnspent
case dbtypes.AddrTxnCredit:
count = bal.NumSpent + bal.NumUnspent
case dbtypes.AddrTxnDebit:
count = bal.NumSpent
default:
return 0, fmt.Errorf("NonMergedTxnCount: requested count for merged view")
}
return int(count), nil
}
|
go
|
func (pgb *ChainDB) nonMergedTxnCount(addr string, txnView dbtypes.AddrTxnViewType) (int, error) {
bal, _, err := pgb.AddressBalance(addr)
if err != nil {
return 0, err
}
var count int64
switch txnView {
case dbtypes.AddrTxnAll:
count = (bal.NumSpent * 2) + bal.NumUnspent
case dbtypes.AddrTxnCredit:
count = bal.NumSpent + bal.NumUnspent
case dbtypes.AddrTxnDebit:
count = bal.NumSpent
default:
return 0, fmt.Errorf("NonMergedTxnCount: requested count for merged view")
}
return int(count), nil
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"nonMergedTxnCount",
"(",
"addr",
"string",
",",
"txnView",
"dbtypes",
".",
"AddrTxnViewType",
")",
"(",
"int",
",",
"error",
")",
"{",
"bal",
",",
"_",
",",
"err",
":=",
"pgb",
".",
"AddressBalance",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"var",
"count",
"int64",
"\n",
"switch",
"txnView",
"{",
"case",
"dbtypes",
".",
"AddrTxnAll",
":",
"count",
"=",
"(",
"bal",
".",
"NumSpent",
"*",
"2",
")",
"+",
"bal",
".",
"NumUnspent",
"\n",
"case",
"dbtypes",
".",
"AddrTxnCredit",
":",
"count",
"=",
"bal",
".",
"NumSpent",
"+",
"bal",
".",
"NumUnspent",
"\n",
"case",
"dbtypes",
".",
"AddrTxnDebit",
":",
"count",
"=",
"bal",
".",
"NumSpent",
"\n",
"default",
":",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"int",
"(",
"count",
")",
",",
"nil",
"\n",
"}"
] |
// nonMergedTxnCount gets the non-merged address transaction view row count via
// AddressBalance, which checks the cache and falls back to a DB query.
|
[
"nonMergedTxnCount",
"gets",
"the",
"non",
"-",
"merged",
"address",
"transaction",
"view",
"row",
"count",
"via",
"AddressBalance",
"which",
"checks",
"the",
"cache",
"and",
"falls",
"back",
"to",
"a",
"DB",
"query",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1954-L1971
|
141,967 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
CountTransactions
|
func (pgb *ChainDB) CountTransactions(addr string, txnView dbtypes.AddrTxnViewType) (int, error) {
merged, err := txnView.IsMerged()
if err != nil {
return 0, err
}
countFn := pgb.nonMergedTxnCount
if merged {
countFn = pgb.mergedTxnCount
}
count, err := countFn(addr, txnView)
if err != nil {
return 0, err
}
return count, nil
}
|
go
|
func (pgb *ChainDB) CountTransactions(addr string, txnView dbtypes.AddrTxnViewType) (int, error) {
merged, err := txnView.IsMerged()
if err != nil {
return 0, err
}
countFn := pgb.nonMergedTxnCount
if merged {
countFn = pgb.mergedTxnCount
}
count, err := countFn(addr, txnView)
if err != nil {
return 0, err
}
return count, nil
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"CountTransactions",
"(",
"addr",
"string",
",",
"txnView",
"dbtypes",
".",
"AddrTxnViewType",
")",
"(",
"int",
",",
"error",
")",
"{",
"merged",
",",
"err",
":=",
"txnView",
".",
"IsMerged",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"countFn",
":=",
"pgb",
".",
"nonMergedTxnCount",
"\n",
"if",
"merged",
"{",
"countFn",
"=",
"pgb",
".",
"mergedTxnCount",
"\n",
"}",
"\n\n",
"count",
",",
"err",
":=",
"countFn",
"(",
"addr",
",",
"txnView",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"count",
",",
"nil",
"\n",
"}"
] |
// CountTransactions gets the total row count for the given address and address
// transaction view.
|
[
"CountTransactions",
"gets",
"the",
"total",
"row",
"count",
"for",
"the",
"given",
"address",
"and",
"address",
"transaction",
"view",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L1975-L1991
|
141,968 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
DbTxByHash
|
func (pgb *ChainDB) DbTxByHash(txid string) (*dbtypes.Tx, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, dbTx, err := RetrieveDbTxByHash(ctx, pgb.db, txid)
return dbTx, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) DbTxByHash(txid string) (*dbtypes.Tx, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
_, dbTx, err := RetrieveDbTxByHash(ctx, pgb.db, txid)
return dbTx, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"DbTxByHash",
"(",
"txid",
"string",
")",
"(",
"*",
"dbtypes",
".",
"Tx",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"_",
",",
"dbTx",
",",
"err",
":=",
"RetrieveDbTxByHash",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"txid",
")",
"\n",
"return",
"dbTx",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// DbTxByHash retrieves a row of the transactions table corresponding to the
// given transaction hash. Transactions in valid and mainchain blocks are chosen
// first.
|
[
"DbTxByHash",
"retrieves",
"a",
"row",
"of",
"the",
"transactions",
"table",
"corresponding",
"to",
"the",
"given",
"transaction",
"hash",
".",
"Transactions",
"in",
"valid",
"and",
"mainchain",
"blocks",
"are",
"chosen",
"first",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2314-L2319
|
141,969 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
FundingOutpointIndxByVinID
|
func (pgb *ChainDB) FundingOutpointIndxByVinID(id uint64) (uint32, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
ind, err := RetrieveFundingOutpointIndxByVinID(ctx, pgb.db, id)
return ind, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) FundingOutpointIndxByVinID(id uint64) (uint32, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
ind, err := RetrieveFundingOutpointIndxByVinID(ctx, pgb.db, id)
return ind, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"FundingOutpointIndxByVinID",
"(",
"id",
"uint64",
")",
"(",
"uint32",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"ind",
",",
"err",
":=",
"RetrieveFundingOutpointIndxByVinID",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"id",
")",
"\n",
"return",
"ind",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// FundingOutpointIndxByVinID retrieves the the transaction output index of the
// previous outpoint for a transaction input specified by row ID in the vins
// table, which stores previous outpoints for each vin.
|
[
"FundingOutpointIndxByVinID",
"retrieves",
"the",
"the",
"transaction",
"output",
"index",
"of",
"the",
"previous",
"outpoint",
"for",
"a",
"transaction",
"input",
"specified",
"by",
"row",
"ID",
"in",
"the",
"vins",
"table",
"which",
"stores",
"previous",
"outpoints",
"for",
"each",
"vin",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2324-L2329
|
141,970 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
FillAddressTransactions
|
func (pgb *ChainDB) FillAddressTransactions(addrInfo *dbtypes.AddressInfo) error {
if addrInfo == nil {
return nil
}
var numUnconfirmed int64
for i, txn := range addrInfo.Transactions {
// Retrieve the most valid, most mainchain, and most recent tx with this
// hash. This means it prefers mainchain and valid blocks first.
dbTx, err := pgb.DbTxByHash(txn.TxID)
if err != nil {
return err
}
txn.Size = dbTx.Size
txn.FormattedSize = humanize.Bytes(uint64(dbTx.Size))
txn.Total = dcrutil.Amount(dbTx.Sent).ToCoin()
txn.Time = dbTx.BlockTime
if txn.Time.UNIX() > 0 {
txn.Confirmations = uint64(pgb.Height() - dbTx.BlockHeight + 1)
} else {
numUnconfirmed++
txn.Confirmations = 0
}
// Get the funding or spending transaction matching index if there is a
// matching tx hash already present. During the next database
// restructuring we may want to consider including matching tx index
// along with matching tx hash in the addresses table.
if txn.MatchedTx != `` {
if !txn.IsFunding {
// Spending transaction: lookup the previous outpoint's txout
// index by the vins table row ID.
idx, err := pgb.FundingOutpointIndxByVinID(dbTx.VinDbIds[txn.InOutID])
if err != nil {
log.Warnf("Matched Transaction Lookup failed for %s:%d: id: %d: %v",
txn.TxID, txn.InOutID, txn.InOutID, err)
} else {
addrInfo.Transactions[i].MatchedTxIndex = idx
}
} else {
// Funding transaction: lookup by the matching (spending) tx
// hash and tx index.
_, idx, _, err := pgb.SpendingTransaction(txn.TxID, txn.InOutID)
if err != nil {
log.Warnf("Matched Transaction Lookup failed for %s:%d: %v",
txn.TxID, txn.InOutID, err)
} else {
addrInfo.Transactions[i].MatchedTxIndex = idx
}
}
}
}
addrInfo.NumUnconfirmed = numUnconfirmed
return nil
}
|
go
|
func (pgb *ChainDB) FillAddressTransactions(addrInfo *dbtypes.AddressInfo) error {
if addrInfo == nil {
return nil
}
var numUnconfirmed int64
for i, txn := range addrInfo.Transactions {
// Retrieve the most valid, most mainchain, and most recent tx with this
// hash. This means it prefers mainchain and valid blocks first.
dbTx, err := pgb.DbTxByHash(txn.TxID)
if err != nil {
return err
}
txn.Size = dbTx.Size
txn.FormattedSize = humanize.Bytes(uint64(dbTx.Size))
txn.Total = dcrutil.Amount(dbTx.Sent).ToCoin()
txn.Time = dbTx.BlockTime
if txn.Time.UNIX() > 0 {
txn.Confirmations = uint64(pgb.Height() - dbTx.BlockHeight + 1)
} else {
numUnconfirmed++
txn.Confirmations = 0
}
// Get the funding or spending transaction matching index if there is a
// matching tx hash already present. During the next database
// restructuring we may want to consider including matching tx index
// along with matching tx hash in the addresses table.
if txn.MatchedTx != `` {
if !txn.IsFunding {
// Spending transaction: lookup the previous outpoint's txout
// index by the vins table row ID.
idx, err := pgb.FundingOutpointIndxByVinID(dbTx.VinDbIds[txn.InOutID])
if err != nil {
log.Warnf("Matched Transaction Lookup failed for %s:%d: id: %d: %v",
txn.TxID, txn.InOutID, txn.InOutID, err)
} else {
addrInfo.Transactions[i].MatchedTxIndex = idx
}
} else {
// Funding transaction: lookup by the matching (spending) tx
// hash and tx index.
_, idx, _, err := pgb.SpendingTransaction(txn.TxID, txn.InOutID)
if err != nil {
log.Warnf("Matched Transaction Lookup failed for %s:%d: %v",
txn.TxID, txn.InOutID, err)
} else {
addrInfo.Transactions[i].MatchedTxIndex = idx
}
}
}
}
addrInfo.NumUnconfirmed = numUnconfirmed
return nil
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"FillAddressTransactions",
"(",
"addrInfo",
"*",
"dbtypes",
".",
"AddressInfo",
")",
"error",
"{",
"if",
"addrInfo",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"numUnconfirmed",
"int64",
"\n\n",
"for",
"i",
",",
"txn",
":=",
"range",
"addrInfo",
".",
"Transactions",
"{",
"// Retrieve the most valid, most mainchain, and most recent tx with this",
"// hash. This means it prefers mainchain and valid blocks first.",
"dbTx",
",",
"err",
":=",
"pgb",
".",
"DbTxByHash",
"(",
"txn",
".",
"TxID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"txn",
".",
"Size",
"=",
"dbTx",
".",
"Size",
"\n",
"txn",
".",
"FormattedSize",
"=",
"humanize",
".",
"Bytes",
"(",
"uint64",
"(",
"dbTx",
".",
"Size",
")",
")",
"\n",
"txn",
".",
"Total",
"=",
"dcrutil",
".",
"Amount",
"(",
"dbTx",
".",
"Sent",
")",
".",
"ToCoin",
"(",
")",
"\n",
"txn",
".",
"Time",
"=",
"dbTx",
".",
"BlockTime",
"\n",
"if",
"txn",
".",
"Time",
".",
"UNIX",
"(",
")",
">",
"0",
"{",
"txn",
".",
"Confirmations",
"=",
"uint64",
"(",
"pgb",
".",
"Height",
"(",
")",
"-",
"dbTx",
".",
"BlockHeight",
"+",
"1",
")",
"\n",
"}",
"else",
"{",
"numUnconfirmed",
"++",
"\n",
"txn",
".",
"Confirmations",
"=",
"0",
"\n",
"}",
"\n\n",
"// Get the funding or spending transaction matching index if there is a",
"// matching tx hash already present. During the next database",
"// restructuring we may want to consider including matching tx index",
"// along with matching tx hash in the addresses table.",
"if",
"txn",
".",
"MatchedTx",
"!=",
"``",
"{",
"if",
"!",
"txn",
".",
"IsFunding",
"{",
"// Spending transaction: lookup the previous outpoint's txout",
"// index by the vins table row ID.",
"idx",
",",
"err",
":=",
"pgb",
".",
"FundingOutpointIndxByVinID",
"(",
"dbTx",
".",
"VinDbIds",
"[",
"txn",
".",
"InOutID",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"txn",
".",
"TxID",
",",
"txn",
".",
"InOutID",
",",
"txn",
".",
"InOutID",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"addrInfo",
".",
"Transactions",
"[",
"i",
"]",
".",
"MatchedTxIndex",
"=",
"idx",
"\n",
"}",
"\n\n",
"}",
"else",
"{",
"// Funding transaction: lookup by the matching (spending) tx",
"// hash and tx index.",
"_",
",",
"idx",
",",
"_",
",",
"err",
":=",
"pgb",
".",
"SpendingTransaction",
"(",
"txn",
".",
"TxID",
",",
"txn",
".",
"InOutID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"txn",
".",
"TxID",
",",
"txn",
".",
"InOutID",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"addrInfo",
".",
"Transactions",
"[",
"i",
"]",
".",
"MatchedTxIndex",
"=",
"idx",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"addrInfo",
".",
"NumUnconfirmed",
"=",
"numUnconfirmed",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// FillAddressTransactions is used to fill out the transaction details in an
// explorer.AddressInfo generated by dbtypes.ReduceAddressHistory, usually from
// the output of AddressHistory. This function also sets the number of
// unconfirmed transactions for the current best block in the database.
|
[
"FillAddressTransactions",
"is",
"used",
"to",
"fill",
"out",
"the",
"transaction",
"details",
"in",
"an",
"explorer",
".",
"AddressInfo",
"generated",
"by",
"dbtypes",
".",
"ReduceAddressHistory",
"usually",
"from",
"the",
"output",
"of",
"AddressHistory",
".",
"This",
"function",
"also",
"sets",
"the",
"number",
"of",
"unconfirmed",
"transactions",
"for",
"the",
"current",
"best",
"block",
"in",
"the",
"database",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2335-L2393
|
141,971 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
AddressTransactionDetails
|
func (pgb *ChainDB) AddressTransactionDetails(addr string, count, skip int64,
txnType dbtypes.AddrTxnViewType) (*apitypes.Address, error) {
// Fetch address history for given transaction range and type
addrData, _, err := pgb.addressInfo(addr, count, skip, txnType)
if err != nil {
return nil, err
}
// No transactions found. Not an error.
if addrData == nil {
return &apitypes.Address{
Address: addr,
Transactions: make([]*apitypes.AddressTxShort, 0), // not nil for JSON formatting
}, nil
}
// Convert each dbtypes.AddressTx to apitypes.AddressTxShort
txs := addrData.Transactions
txsShort := make([]*apitypes.AddressTxShort, 0, len(txs))
for i := range txs {
txsShort = append(txsShort, &apitypes.AddressTxShort{
TxID: txs[i].TxID,
Time: apitypes.TimeAPI{S: txs[i].Time},
Value: txs[i].Total,
Confirmations: int64(txs[i].Confirmations),
Size: int32(txs[i].Size),
})
}
// put a bow on it
return &apitypes.Address{
Address: addr,
Transactions: txsShort,
}, nil
}
|
go
|
func (pgb *ChainDB) AddressTransactionDetails(addr string, count, skip int64,
txnType dbtypes.AddrTxnViewType) (*apitypes.Address, error) {
// Fetch address history for given transaction range and type
addrData, _, err := pgb.addressInfo(addr, count, skip, txnType)
if err != nil {
return nil, err
}
// No transactions found. Not an error.
if addrData == nil {
return &apitypes.Address{
Address: addr,
Transactions: make([]*apitypes.AddressTxShort, 0), // not nil for JSON formatting
}, nil
}
// Convert each dbtypes.AddressTx to apitypes.AddressTxShort
txs := addrData.Transactions
txsShort := make([]*apitypes.AddressTxShort, 0, len(txs))
for i := range txs {
txsShort = append(txsShort, &apitypes.AddressTxShort{
TxID: txs[i].TxID,
Time: apitypes.TimeAPI{S: txs[i].Time},
Value: txs[i].Total,
Confirmations: int64(txs[i].Confirmations),
Size: int32(txs[i].Size),
})
}
// put a bow on it
return &apitypes.Address{
Address: addr,
Transactions: txsShort,
}, nil
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"AddressTransactionDetails",
"(",
"addr",
"string",
",",
"count",
",",
"skip",
"int64",
",",
"txnType",
"dbtypes",
".",
"AddrTxnViewType",
")",
"(",
"*",
"apitypes",
".",
"Address",
",",
"error",
")",
"{",
"// Fetch address history for given transaction range and type",
"addrData",
",",
"_",
",",
"err",
":=",
"pgb",
".",
"addressInfo",
"(",
"addr",
",",
"count",
",",
"skip",
",",
"txnType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// No transactions found. Not an error.",
"if",
"addrData",
"==",
"nil",
"{",
"return",
"&",
"apitypes",
".",
"Address",
"{",
"Address",
":",
"addr",
",",
"Transactions",
":",
"make",
"(",
"[",
"]",
"*",
"apitypes",
".",
"AddressTxShort",
",",
"0",
")",
",",
"// not nil for JSON formatting",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"// Convert each dbtypes.AddressTx to apitypes.AddressTxShort",
"txs",
":=",
"addrData",
".",
"Transactions",
"\n",
"txsShort",
":=",
"make",
"(",
"[",
"]",
"*",
"apitypes",
".",
"AddressTxShort",
",",
"0",
",",
"len",
"(",
"txs",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"txs",
"{",
"txsShort",
"=",
"append",
"(",
"txsShort",
",",
"&",
"apitypes",
".",
"AddressTxShort",
"{",
"TxID",
":",
"txs",
"[",
"i",
"]",
".",
"TxID",
",",
"Time",
":",
"apitypes",
".",
"TimeAPI",
"{",
"S",
":",
"txs",
"[",
"i",
"]",
".",
"Time",
"}",
",",
"Value",
":",
"txs",
"[",
"i",
"]",
".",
"Total",
",",
"Confirmations",
":",
"int64",
"(",
"txs",
"[",
"i",
"]",
".",
"Confirmations",
")",
",",
"Size",
":",
"int32",
"(",
"txs",
"[",
"i",
"]",
".",
"Size",
")",
",",
"}",
")",
"\n",
"}",
"\n\n",
"// put a bow on it",
"return",
"&",
"apitypes",
".",
"Address",
"{",
"Address",
":",
"addr",
",",
"Transactions",
":",
"txsShort",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// AddressTransactionDetails returns an apitypes.Address with at most the last
// count transactions of type txnType in which the address was involved,
// starting after skip transactions. This does NOT include unconfirmed
// transactions.
|
[
"AddressTransactionDetails",
"returns",
"an",
"apitypes",
".",
"Address",
"with",
"at",
"most",
"the",
"last",
"count",
"transactions",
"of",
"type",
"txnType",
"in",
"which",
"the",
"address",
"was",
"involved",
"starting",
"after",
"skip",
"transactions",
".",
"This",
"does",
"NOT",
"include",
"unconfirmed",
"transactions",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2610-L2643
|
141,972 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
ChainInfo
|
func (pgb *ChainDB) ChainInfo() *dbtypes.BlockChainData {
pgb.deployments.mtx.RLock()
defer pgb.deployments.mtx.RUnlock()
return pgb.deployments.chainInfo
}
|
go
|
func (pgb *ChainDB) ChainInfo() *dbtypes.BlockChainData {
pgb.deployments.mtx.RLock()
defer pgb.deployments.mtx.RUnlock()
return pgb.deployments.chainInfo
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"ChainInfo",
"(",
")",
"*",
"dbtypes",
".",
"BlockChainData",
"{",
"pgb",
".",
"deployments",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"pgb",
".",
"deployments",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"pgb",
".",
"deployments",
".",
"chainInfo",
"\n",
"}"
] |
// ChainInfo guarantees thread-safe access of the deployment data.
|
[
"ChainInfo",
"guarantees",
"thread",
"-",
"safe",
"access",
"of",
"the",
"deployment",
"data",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2746-L2750
|
141,973 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
Store
|
func (pgb *ChainDB) Store(blockData *blockdata.BlockData, msgBlock *wire.MsgBlock) error {
// This function must handle being run when pgb is nil (not constructed).
if pgb == nil {
return nil
}
// New blocks stored this way are considered valid and part of mainchain,
// warranting updates to existing records. When adding side chain blocks
// manually, call StoreBlock directly with appropriate flags for isValid,
// isMainchain, and updateExistingRecords, and nil winningTickets.
isValid, isMainChain, updateExistingRecords := true, true, true
// Since Store should not be used in batch block processing, addresses and
// tickets spending information is updated.
updateAddressesSpendingInfo, updateTicketsSpendingInfo := true, true
_, _, _, err := pgb.StoreBlock(msgBlock, blockData.WinningTickets,
isValid, isMainChain, updateExistingRecords, updateAddressesSpendingInfo,
updateTicketsSpendingInfo, blockData.Header.ChainWork)
return err
}
|
go
|
func (pgb *ChainDB) Store(blockData *blockdata.BlockData, msgBlock *wire.MsgBlock) error {
// This function must handle being run when pgb is nil (not constructed).
if pgb == nil {
return nil
}
// New blocks stored this way are considered valid and part of mainchain,
// warranting updates to existing records. When adding side chain blocks
// manually, call StoreBlock directly with appropriate flags for isValid,
// isMainchain, and updateExistingRecords, and nil winningTickets.
isValid, isMainChain, updateExistingRecords := true, true, true
// Since Store should not be used in batch block processing, addresses and
// tickets spending information is updated.
updateAddressesSpendingInfo, updateTicketsSpendingInfo := true, true
_, _, _, err := pgb.StoreBlock(msgBlock, blockData.WinningTickets,
isValid, isMainChain, updateExistingRecords, updateAddressesSpendingInfo,
updateTicketsSpendingInfo, blockData.Header.ChainWork)
return err
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"Store",
"(",
"blockData",
"*",
"blockdata",
".",
"BlockData",
",",
"msgBlock",
"*",
"wire",
".",
"MsgBlock",
")",
"error",
"{",
"// This function must handle being run when pgb is nil (not constructed).",
"if",
"pgb",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// New blocks stored this way are considered valid and part of mainchain,",
"// warranting updates to existing records. When adding side chain blocks",
"// manually, call StoreBlock directly with appropriate flags for isValid,",
"// isMainchain, and updateExistingRecords, and nil winningTickets.",
"isValid",
",",
"isMainChain",
",",
"updateExistingRecords",
":=",
"true",
",",
"true",
",",
"true",
"\n\n",
"// Since Store should not be used in batch block processing, addresses and",
"// tickets spending information is updated.",
"updateAddressesSpendingInfo",
",",
"updateTicketsSpendingInfo",
":=",
"true",
",",
"true",
"\n\n",
"_",
",",
"_",
",",
"_",
",",
"err",
":=",
"pgb",
".",
"StoreBlock",
"(",
"msgBlock",
",",
"blockData",
".",
"WinningTickets",
",",
"isValid",
",",
"isMainChain",
",",
"updateExistingRecords",
",",
"updateAddressesSpendingInfo",
",",
"updateTicketsSpendingInfo",
",",
"blockData",
".",
"Header",
".",
"ChainWork",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Store satisfies BlockDataSaver. Blocks stored this way are considered valid
// and part of mainchain. Store should not be used for batch block processing;
// instead, use StoreBlock and specify appropriate flags.
|
[
"Store",
"satisfies",
"BlockDataSaver",
".",
"Blocks",
"stored",
"this",
"way",
"are",
"considered",
"valid",
"and",
"part",
"of",
"mainchain",
".",
"Store",
"should",
"not",
"be",
"used",
"for",
"batch",
"block",
"processing",
";",
"instead",
"use",
"StoreBlock",
"and",
"specify",
"appropriate",
"flags",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2755-L2775
|
141,974 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
PurgeBestBlocks
|
func (pgb *ChainDB) PurgeBestBlocks(N int64) (*dbtypes.DeletionSummary, int64, error) {
res, height, _, err := DeleteBlocks(pgb.ctx, N, pgb.db)
if err != nil {
return nil, height, pgb.replaceCancelError(err)
}
summary := dbtypes.DeletionSummarySlice(res).Reduce()
return &summary, height, err
}
|
go
|
func (pgb *ChainDB) PurgeBestBlocks(N int64) (*dbtypes.DeletionSummary, int64, error) {
res, height, _, err := DeleteBlocks(pgb.ctx, N, pgb.db)
if err != nil {
return nil, height, pgb.replaceCancelError(err)
}
summary := dbtypes.DeletionSummarySlice(res).Reduce()
return &summary, height, err
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"PurgeBestBlocks",
"(",
"N",
"int64",
")",
"(",
"*",
"dbtypes",
".",
"DeletionSummary",
",",
"int64",
",",
"error",
")",
"{",
"res",
",",
"height",
",",
"_",
",",
"err",
":=",
"DeleteBlocks",
"(",
"pgb",
".",
"ctx",
",",
"N",
",",
"pgb",
".",
"db",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"height",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"summary",
":=",
"dbtypes",
".",
"DeletionSummarySlice",
"(",
"res",
")",
".",
"Reduce",
"(",
")",
"\n\n",
"return",
"&",
"summary",
",",
"height",
",",
"err",
"\n",
"}"
] |
// PurgeBestBlocks deletes all data for the N best blocks in the DB.
|
[
"PurgeBestBlocks",
"deletes",
"all",
"data",
"for",
"the",
"N",
"best",
"blocks",
"in",
"the",
"DB",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2778-L2787
|
141,975 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
TxHistoryData
|
func (pgb *ChainDB) TxHistoryData(address string, addrChart dbtypes.HistoryChart,
chartGroupings dbtypes.TimeBasedGrouping) (cd *dbtypes.ChartsData, err error) {
// First check cache for this address' chart data of the given type and
// interval.
bestHash, height := pgb.BestBlock()
var validHeight *cache.BlockID
cd, validHeight = pgb.AddressCache.HistoryChart(address, addrChart, chartGroupings)
if cd != nil && *bestHash == validHeight.Hash {
return
}
busy, wait, done := pgb.CacheLocks.bal.TryLock(address)
if busy {
// Let others get the wait channel while we wait.
// To return stale cache data if it is available:
// utxos, _ := pgb.AddressCache.UTXOs(address)
// if utxos != nil {
// return utxos, nil
// }
<-wait
// Try again, starting with the cache.
return pgb.TxHistoryData(address, addrChart, chartGroupings)
}
// We will run the DB query, so block others from doing the same. When query
// and/or cache update is completed, broadcast to any waiters that the coast
// is clear.
defer done()
timeInterval := chartGroupings.String()
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
switch addrChart {
case dbtypes.TxsType:
cd, err = retrieveTxHistoryByType(ctx, pgb.db, address, timeInterval)
case dbtypes.AmountFlow:
cd, err = retrieveTxHistoryByAmountFlow(ctx, pgb.db, address, timeInterval)
default:
cd, err = nil, fmt.Errorf("unknown error occurred")
}
err = pgb.replaceCancelError(err)
if err != nil {
return
}
// Update cache.
_ = pgb.AddressCache.StoreHistoryChart(address, addrChart, chartGroupings,
cd, cache.NewBlockID(bestHash, height))
return
}
|
go
|
func (pgb *ChainDB) TxHistoryData(address string, addrChart dbtypes.HistoryChart,
chartGroupings dbtypes.TimeBasedGrouping) (cd *dbtypes.ChartsData, err error) {
// First check cache for this address' chart data of the given type and
// interval.
bestHash, height := pgb.BestBlock()
var validHeight *cache.BlockID
cd, validHeight = pgb.AddressCache.HistoryChart(address, addrChart, chartGroupings)
if cd != nil && *bestHash == validHeight.Hash {
return
}
busy, wait, done := pgb.CacheLocks.bal.TryLock(address)
if busy {
// Let others get the wait channel while we wait.
// To return stale cache data if it is available:
// utxos, _ := pgb.AddressCache.UTXOs(address)
// if utxos != nil {
// return utxos, nil
// }
<-wait
// Try again, starting with the cache.
return pgb.TxHistoryData(address, addrChart, chartGroupings)
}
// We will run the DB query, so block others from doing the same. When query
// and/or cache update is completed, broadcast to any waiters that the coast
// is clear.
defer done()
timeInterval := chartGroupings.String()
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
switch addrChart {
case dbtypes.TxsType:
cd, err = retrieveTxHistoryByType(ctx, pgb.db, address, timeInterval)
case dbtypes.AmountFlow:
cd, err = retrieveTxHistoryByAmountFlow(ctx, pgb.db, address, timeInterval)
default:
cd, err = nil, fmt.Errorf("unknown error occurred")
}
err = pgb.replaceCancelError(err)
if err != nil {
return
}
// Update cache.
_ = pgb.AddressCache.StoreHistoryChart(address, addrChart, chartGroupings,
cd, cache.NewBlockID(bestHash, height))
return
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"TxHistoryData",
"(",
"address",
"string",
",",
"addrChart",
"dbtypes",
".",
"HistoryChart",
",",
"chartGroupings",
"dbtypes",
".",
"TimeBasedGrouping",
")",
"(",
"cd",
"*",
"dbtypes",
".",
"ChartsData",
",",
"err",
"error",
")",
"{",
"// First check cache for this address' chart data of the given type and",
"// interval.",
"bestHash",
",",
"height",
":=",
"pgb",
".",
"BestBlock",
"(",
")",
"\n",
"var",
"validHeight",
"*",
"cache",
".",
"BlockID",
"\n",
"cd",
",",
"validHeight",
"=",
"pgb",
".",
"AddressCache",
".",
"HistoryChart",
"(",
"address",
",",
"addrChart",
",",
"chartGroupings",
")",
"\n",
"if",
"cd",
"!=",
"nil",
"&&",
"*",
"bestHash",
"==",
"validHeight",
".",
"Hash",
"{",
"return",
"\n",
"}",
"\n\n",
"busy",
",",
"wait",
",",
"done",
":=",
"pgb",
".",
"CacheLocks",
".",
"bal",
".",
"TryLock",
"(",
"address",
")",
"\n",
"if",
"busy",
"{",
"// Let others get the wait channel while we wait.",
"// To return stale cache data if it is available:",
"// utxos, _ := pgb.AddressCache.UTXOs(address)",
"// if utxos != nil {",
"// \treturn utxos, nil",
"// }",
"<-",
"wait",
"\n\n",
"// Try again, starting with the cache.",
"return",
"pgb",
".",
"TxHistoryData",
"(",
"address",
",",
"addrChart",
",",
"chartGroupings",
")",
"\n",
"}",
"\n\n",
"// We will run the DB query, so block others from doing the same. When query",
"// and/or cache update is completed, broadcast to any waiters that the coast",
"// is clear.",
"defer",
"done",
"(",
")",
"\n\n",
"timeInterval",
":=",
"chartGroupings",
".",
"String",
"(",
")",
"\n\n",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"switch",
"addrChart",
"{",
"case",
"dbtypes",
".",
"TxsType",
":",
"cd",
",",
"err",
"=",
"retrieveTxHistoryByType",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"address",
",",
"timeInterval",
")",
"\n\n",
"case",
"dbtypes",
".",
"AmountFlow",
":",
"cd",
",",
"err",
"=",
"retrieveTxHistoryByAmountFlow",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"address",
",",
"timeInterval",
")",
"\n\n",
"default",
":",
"cd",
",",
"err",
"=",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"err",
"=",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// Update cache.",
"_",
"=",
"pgb",
".",
"AddressCache",
".",
"StoreHistoryChart",
"(",
"address",
",",
"addrChart",
",",
"chartGroupings",
",",
"cd",
",",
"cache",
".",
"NewBlockID",
"(",
"bestHash",
",",
"height",
")",
")",
"\n",
"return",
"\n",
"}"
] |
// TxHistoryData fetches the address history chart data for specified chart
// type and time grouping.
|
[
"TxHistoryData",
"fetches",
"the",
"address",
"history",
"chart",
"data",
"for",
"specified",
"chart",
"type",
"and",
"time",
"grouping",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2791-L2845
|
141,976 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
TicketsByPrice
|
func (pgb *ChainDB) TicketsByPrice(maturityBlock int64) (*dbtypes.PoolTicketsData, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
ptd, err := retrieveTicketByPrice(ctx, pgb.db, maturityBlock)
return ptd, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) TicketsByPrice(maturityBlock int64) (*dbtypes.PoolTicketsData, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
ptd, err := retrieveTicketByPrice(ctx, pgb.db, maturityBlock)
return ptd, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"TicketsByPrice",
"(",
"maturityBlock",
"int64",
")",
"(",
"*",
"dbtypes",
".",
"PoolTicketsData",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"ptd",
",",
"err",
":=",
"retrieveTicketByPrice",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"maturityBlock",
")",
"\n",
"return",
"ptd",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// TicketsByPrice returns chart data for tickets grouped by price. maturityBlock
// is used to define when tickets are considered live.
|
[
"TicketsByPrice",
"returns",
"chart",
"data",
"for",
"tickets",
"grouped",
"by",
"price",
".",
"maturityBlock",
"is",
"used",
"to",
"define",
"when",
"tickets",
"are",
"considered",
"live",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2849-L2854
|
141,977 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
TicketsByInputCount
|
func (pgb *ChainDB) TicketsByInputCount() (*dbtypes.PoolTicketsData, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
ptd, err := retrieveTicketsGroupedByType(ctx, pgb.db)
return ptd, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) TicketsByInputCount() (*dbtypes.PoolTicketsData, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
ptd, err := retrieveTicketsGroupedByType(ctx, pgb.db)
return ptd, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"TicketsByInputCount",
"(",
")",
"(",
"*",
"dbtypes",
".",
"PoolTicketsData",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"ptd",
",",
"err",
":=",
"retrieveTicketsGroupedByType",
"(",
"ctx",
",",
"pgb",
".",
"db",
")",
"\n",
"return",
"ptd",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// TicketsByInputCount returns chart data for tickets grouped by number of
// inputs.
|
[
"TicketsByInputCount",
"returns",
"chart",
"data",
"for",
"tickets",
"grouped",
"by",
"number",
"of",
"inputs",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2858-L2863
|
141,978 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
windowStats
|
func (pgb *ChainDB) windowStats(charts *cache.ChartData) (*sql.Rows, func(), error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
rows, err := retrieveWindowStats(ctx, pgb.db, charts)
if err != nil {
return nil, cancel, fmt.Errorf("windowStats: %v", pgb.replaceCancelError(err))
}
return rows, cancel, nil
}
|
go
|
func (pgb *ChainDB) windowStats(charts *cache.ChartData) (*sql.Rows, func(), error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
rows, err := retrieveWindowStats(ctx, pgb.db, charts)
if err != nil {
return nil, cancel, fmt.Errorf("windowStats: %v", pgb.replaceCancelError(err))
}
return rows, cancel, nil
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"windowStats",
"(",
"charts",
"*",
"cache",
".",
"ChartData",
")",
"(",
"*",
"sql",
".",
"Rows",
",",
"func",
"(",
")",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n\n",
"rows",
",",
"err",
":=",
"retrieveWindowStats",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"charts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"cancel",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
")",
"\n",
"}",
"\n\n",
"return",
"rows",
",",
"cancel",
",",
"nil",
"\n",
"}"
] |
// windowStats fetches the charts data from retrieveWindowStats.
// This is the Fetcher half of a pair that make up a cache.ChartUpdater. The
// Appender half is appendWindowStats.
|
[
"windowStats",
"fetches",
"the",
"charts",
"data",
"from",
"retrieveWindowStats",
".",
"This",
"is",
"the",
"Fetcher",
"half",
"of",
"a",
"pair",
"that",
"make",
"up",
"a",
"cache",
".",
"ChartUpdater",
".",
"The",
"Appender",
"half",
"is",
"appendWindowStats",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2868-L2877
|
141,979 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
txPerDay
|
func (pgb *ChainDB) txPerDay(timeArr []dbtypes.TimeDef, txCountArr []uint64) (
[]dbtypes.TimeDef, []uint64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
var err error
timeArr, txCountArr, err = retrieveTxPerDay(ctx, pgb.db, timeArr, txCountArr)
if err != nil {
err = fmt.Errorf("txPerDay: %v", pgb.replaceCancelError(err))
}
return timeArr, txCountArr, err
}
|
go
|
func (pgb *ChainDB) txPerDay(timeArr []dbtypes.TimeDef, txCountArr []uint64) (
[]dbtypes.TimeDef, []uint64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
var err error
timeArr, txCountArr, err = retrieveTxPerDay(ctx, pgb.db, timeArr, txCountArr)
if err != nil {
err = fmt.Errorf("txPerDay: %v", pgb.replaceCancelError(err))
}
return timeArr, txCountArr, err
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"txPerDay",
"(",
"timeArr",
"[",
"]",
"dbtypes",
".",
"TimeDef",
",",
"txCountArr",
"[",
"]",
"uint64",
")",
"(",
"[",
"]",
"dbtypes",
".",
"TimeDef",
",",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"var",
"err",
"error",
"\n",
"timeArr",
",",
"txCountArr",
",",
"err",
"=",
"retrieveTxPerDay",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"timeArr",
",",
"txCountArr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
")",
"\n",
"}",
"\n\n",
"return",
"timeArr",
",",
"txCountArr",
",",
"err",
"\n",
"}"
] |
// txPerDay fetches the tx-per-day chart data from retrieveTxPerDay.
|
[
"txPerDay",
"fetches",
"the",
"tx",
"-",
"per",
"-",
"day",
"chart",
"data",
"from",
"retrieveTxPerDay",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2907-L2919
|
141,980 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
PowerlessTickets
|
func (pgb *ChainDB) PowerlessTickets() (*apitypes.PowerlessTickets, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
return retrievePowerlessTickets(ctx, pgb.db)
}
|
go
|
func (pgb *ChainDB) PowerlessTickets() (*apitypes.PowerlessTickets, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
return retrievePowerlessTickets(ctx, pgb.db)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"PowerlessTickets",
"(",
")",
"(",
"*",
"apitypes",
".",
"PowerlessTickets",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"return",
"retrievePowerlessTickets",
"(",
"ctx",
",",
"pgb",
".",
"db",
")",
"\n",
"}"
] |
// PowerlessTickets fetches all missed and expired tickets, sorted by revocation
// status.
|
[
"PowerlessTickets",
"fetches",
"all",
"missed",
"and",
"expired",
"tickets",
"sorted",
"by",
"revocation",
"status",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2923-L2927
|
141,981 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
ticketsByBlocks
|
func (pgb *ChainDB) ticketsByBlocks(heightArr, soloArr, pooledArr []uint64) ([]uint64,
[]uint64, []uint64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
var err error
heightArr, soloArr, pooledArr, err = retrieveTicketByOutputCount(ctx,
pgb.db, 1, outputCountByAllBlocks, heightArr, soloArr, pooledArr)
if err != nil {
err = fmt.Errorf("ticketsByBlocks: %v", pgb.replaceCancelError(err))
}
return heightArr, soloArr, pooledArr, err
}
|
go
|
func (pgb *ChainDB) ticketsByBlocks(heightArr, soloArr, pooledArr []uint64) ([]uint64,
[]uint64, []uint64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
var err error
heightArr, soloArr, pooledArr, err = retrieveTicketByOutputCount(ctx,
pgb.db, 1, outputCountByAllBlocks, heightArr, soloArr, pooledArr)
if err != nil {
err = fmt.Errorf("ticketsByBlocks: %v", pgb.replaceCancelError(err))
}
return heightArr, soloArr, pooledArr, err
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"ticketsByBlocks",
"(",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
"[",
"]",
"uint64",
")",
"(",
"[",
"]",
"uint64",
",",
"[",
"]",
"uint64",
",",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"var",
"err",
"error",
"\n",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
",",
"err",
"=",
"retrieveTicketByOutputCount",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"1",
",",
"outputCountByAllBlocks",
",",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
")",
"\n",
"}",
"\n\n",
"return",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
",",
"err",
"\n",
"}"
] |
// ticketsByBlocks fetches the tickets by blocks output count chart data from
// retrieveTicketByOutputCount
// This chart has been deprecated. Leaving ticketsByBlocks for possible future
// re-appropriation, says buck54321 on April 24, 2019.
|
[
"ticketsByBlocks",
"fetches",
"the",
"tickets",
"by",
"blocks",
"output",
"count",
"chart",
"data",
"from",
"retrieveTicketByOutputCount",
"This",
"chart",
"has",
"been",
"deprecated",
".",
"Leaving",
"ticketsByBlocks",
"for",
"possible",
"future",
"re",
"-",
"appropriation",
"says",
"buck54321",
"on",
"April",
"24",
"2019",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2933-L2946
|
141,982 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
ticketsByTPWindows
|
func (pgb *ChainDB) ticketsByTPWindows(heightArr, soloArr, pooledArr []uint64) ([]uint64,
[]uint64, []uint64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
var err error
heightArr, soloArr, pooledArr, err = retrieveTicketByOutputCount(ctx, pgb.db,
pgb.chainParams.StakeDiffWindowSize, outputCountByTicketPoolWindow,
heightArr, soloArr, pooledArr)
if err != nil {
err = fmt.Errorf("ticketsByTPWindows: %v", pgb.replaceCancelError(err))
}
return heightArr, soloArr, pooledArr, err
}
|
go
|
func (pgb *ChainDB) ticketsByTPWindows(heightArr, soloArr, pooledArr []uint64) ([]uint64,
[]uint64, []uint64, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
var err error
heightArr, soloArr, pooledArr, err = retrieveTicketByOutputCount(ctx, pgb.db,
pgb.chainParams.StakeDiffWindowSize, outputCountByTicketPoolWindow,
heightArr, soloArr, pooledArr)
if err != nil {
err = fmt.Errorf("ticketsByTPWindows: %v", pgb.replaceCancelError(err))
}
return heightArr, soloArr, pooledArr, err
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"ticketsByTPWindows",
"(",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
"[",
"]",
"uint64",
")",
"(",
"[",
"]",
"uint64",
",",
"[",
"]",
"uint64",
",",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"var",
"err",
"error",
"\n",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
",",
"err",
"=",
"retrieveTicketByOutputCount",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"pgb",
".",
"chainParams",
".",
"StakeDiffWindowSize",
",",
"outputCountByTicketPoolWindow",
",",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
")",
"\n",
"}",
"\n\n",
"return",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
",",
"err",
"\n",
"}"
] |
// ticketsByTPWindows fetches the tickets by ticket pool windows count chart data
// from retrieveTicketByOutputCount.
// This chart has been deprecated. Leaving ticketsByTPWindows for possible
// future re-appropriation, says buck54321 on April 24, 2019.
|
[
"ticketsByTPWindows",
"fetches",
"the",
"tickets",
"by",
"ticket",
"pool",
"windows",
"count",
"chart",
"data",
"from",
"retrieveTicketByOutputCount",
".",
"This",
"chart",
"has",
"been",
"deprecated",
".",
"Leaving",
"ticketsByTPWindows",
"for",
"possible",
"future",
"re",
"-",
"appropriation",
"says",
"buck54321",
"on",
"April",
"24",
"2019",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2952-L2966
|
141,983 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
getChartData
|
func (pgb *ChainDB) getChartData(data map[string]*dbtypes.ChartsData,
chartT string) *dbtypes.ChartsData {
cData := data[chartT]
if cData == nil {
cData = new(dbtypes.ChartsData)
}
return cData
}
|
go
|
func (pgb *ChainDB) getChartData(data map[string]*dbtypes.ChartsData,
chartT string) *dbtypes.ChartsData {
cData := data[chartT]
if cData == nil {
cData = new(dbtypes.ChartsData)
}
return cData
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"getChartData",
"(",
"data",
"map",
"[",
"string",
"]",
"*",
"dbtypes",
".",
"ChartsData",
",",
"chartT",
"string",
")",
"*",
"dbtypes",
".",
"ChartsData",
"{",
"cData",
":=",
"data",
"[",
"chartT",
"]",
"\n",
"if",
"cData",
"==",
"nil",
"{",
"cData",
"=",
"new",
"(",
"dbtypes",
".",
"ChartsData",
")",
"\n",
"}",
"\n",
"return",
"cData",
"\n",
"}"
] |
// getChartData returns the chart data if it exists and initializes a new chart
// data instance if otherwise.
|
[
"getChartData",
"returns",
"the",
"chart",
"data",
"if",
"it",
"exists",
"and",
"initializes",
"a",
"new",
"chart",
"data",
"instance",
"if",
"otherwise",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2970-L2977
|
141,984 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
SetVinsMainchainByBlock
|
func (pgb *ChainDB) SetVinsMainchainByBlock(blockHash string) (int64, []dbtypes.UInt64Array, []dbtypes.UInt64Array, error) {
// The queries in this function should not timeout or (probably) canceled,
// so use a background context.
ctx := context.Background()
// Get vins DB IDs from the transactions table, for each tx in the block.
onlyRegularTxns := false
vinDbIDsBlk, voutDbIDsBlk, areMainchain, err :=
RetrieveTxnsVinsVoutsByBlock(ctx, pgb.db, blockHash, onlyRegularTxns)
if err != nil {
return 0, nil, nil, fmt.Errorf("unable to retrieve vin data for block %s: %v", blockHash, err)
}
// Set the is_mainchain flag for each vin.
vinsUpdated, err := pgb.setVinsMainchainForMany(vinDbIDsBlk, areMainchain)
return vinsUpdated, vinDbIDsBlk, voutDbIDsBlk, err
}
|
go
|
func (pgb *ChainDB) SetVinsMainchainByBlock(blockHash string) (int64, []dbtypes.UInt64Array, []dbtypes.UInt64Array, error) {
// The queries in this function should not timeout or (probably) canceled,
// so use a background context.
ctx := context.Background()
// Get vins DB IDs from the transactions table, for each tx in the block.
onlyRegularTxns := false
vinDbIDsBlk, voutDbIDsBlk, areMainchain, err :=
RetrieveTxnsVinsVoutsByBlock(ctx, pgb.db, blockHash, onlyRegularTxns)
if err != nil {
return 0, nil, nil, fmt.Errorf("unable to retrieve vin data for block %s: %v", blockHash, err)
}
// Set the is_mainchain flag for each vin.
vinsUpdated, err := pgb.setVinsMainchainForMany(vinDbIDsBlk, areMainchain)
return vinsUpdated, vinDbIDsBlk, voutDbIDsBlk, err
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"SetVinsMainchainByBlock",
"(",
"blockHash",
"string",
")",
"(",
"int64",
",",
"[",
"]",
"dbtypes",
".",
"UInt64Array",
",",
"[",
"]",
"dbtypes",
".",
"UInt64Array",
",",
"error",
")",
"{",
"// The queries in this function should not timeout or (probably) canceled,",
"// so use a background context.",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n\n",
"// Get vins DB IDs from the transactions table, for each tx in the block.",
"onlyRegularTxns",
":=",
"false",
"\n",
"vinDbIDsBlk",
",",
"voutDbIDsBlk",
",",
"areMainchain",
",",
"err",
":=",
"RetrieveTxnsVinsVoutsByBlock",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"blockHash",
",",
"onlyRegularTxns",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"blockHash",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Set the is_mainchain flag for each vin.",
"vinsUpdated",
",",
"err",
":=",
"pgb",
".",
"setVinsMainchainForMany",
"(",
"vinDbIDsBlk",
",",
"areMainchain",
")",
"\n",
"return",
"vinsUpdated",
",",
"vinDbIDsBlk",
",",
"voutDbIDsBlk",
",",
"err",
"\n",
"}"
] |
// SetVinsMainchainByBlock first retrieves for all transactions in the specified
// block the vin_db_ids and vout_db_ids arrays, along with mainchain status,
// from the transactions table, and then sets the is_mainchain flag in the vins
// table for each row of vins in the vin_db_ids array. The returns are the
// number of vins updated, the vin row IDs array, the vouts row IDs array, and
// an error value.
|
[
"SetVinsMainchainByBlock",
"first",
"retrieves",
"for",
"all",
"transactions",
"in",
"the",
"specified",
"block",
"the",
"vin_db_ids",
"and",
"vout_db_ids",
"arrays",
"along",
"with",
"mainchain",
"status",
"from",
"the",
"transactions",
"table",
"and",
"then",
"sets",
"the",
"is_mainchain",
"flag",
"in",
"the",
"vins",
"table",
"for",
"each",
"row",
"of",
"vins",
"in",
"the",
"vin_db_ids",
"array",
".",
"The",
"returns",
"are",
"the",
"number",
"of",
"vins",
"updated",
"the",
"vin",
"row",
"IDs",
"array",
"the",
"vouts",
"row",
"IDs",
"array",
"and",
"an",
"error",
"value",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L2985-L3001
|
141,985 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
PkScriptByVinID
|
func (pgb *ChainDB) PkScriptByVinID(id uint64) (pkScript []byte, ver uint16, err error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
pks, ver, err := RetrievePkScriptByVinID(ctx, pgb.db, id)
return pks, ver, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) PkScriptByVinID(id uint64) (pkScript []byte, ver uint16, err error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
pks, ver, err := RetrievePkScriptByVinID(ctx, pgb.db, id)
return pks, ver, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"PkScriptByVinID",
"(",
"id",
"uint64",
")",
"(",
"pkScript",
"[",
"]",
"byte",
",",
"ver",
"uint16",
",",
"err",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"pks",
",",
"ver",
",",
"err",
":=",
"RetrievePkScriptByVinID",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"id",
")",
"\n",
"return",
"pks",
",",
"ver",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// PkScriptByVinID retrieves the pkScript and script version for the row of the
// vouts table corresponding to the previous output of the vin specified by row
// ID of the vins table.
|
[
"PkScriptByVinID",
"retrieves",
"the",
"pkScript",
"and",
"script",
"version",
"for",
"the",
"row",
"of",
"the",
"vouts",
"table",
"corresponding",
"to",
"the",
"previous",
"output",
"of",
"the",
"vin",
"specified",
"by",
"row",
"ID",
"of",
"the",
"vins",
"table",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L3043-L3048
|
141,986 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
VinsForTx
|
func (pgb *ChainDB) VinsForTx(dbTx *dbtypes.Tx) ([]dbtypes.VinTxProperty, []string, []uint16, error) {
// Retrieve the pkScript and script version for the previous outpoint of
// each vin.
prevPkScripts := make([]string, 0, len(dbTx.VinDbIds))
versions := make([]uint16, 0, len(dbTx.VinDbIds))
for _, id := range dbTx.VinDbIds {
pkScript, ver, err := pgb.PkScriptByVinID(id)
if err != nil {
return nil, nil, nil, fmt.Errorf("PkScriptByVinID: %v", err)
}
prevPkScripts = append(prevPkScripts, hex.EncodeToString(pkScript))
versions = append(versions, ver)
}
// Retrieve the vins row data.
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
vins, err := RetrieveVinsByIDs(ctx, pgb.db, dbTx.VinDbIds)
if err != nil {
err = fmt.Errorf("RetrieveVinsByIDs: %v", err)
}
return vins, prevPkScripts, versions, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) VinsForTx(dbTx *dbtypes.Tx) ([]dbtypes.VinTxProperty, []string, []uint16, error) {
// Retrieve the pkScript and script version for the previous outpoint of
// each vin.
prevPkScripts := make([]string, 0, len(dbTx.VinDbIds))
versions := make([]uint16, 0, len(dbTx.VinDbIds))
for _, id := range dbTx.VinDbIds {
pkScript, ver, err := pgb.PkScriptByVinID(id)
if err != nil {
return nil, nil, nil, fmt.Errorf("PkScriptByVinID: %v", err)
}
prevPkScripts = append(prevPkScripts, hex.EncodeToString(pkScript))
versions = append(versions, ver)
}
// Retrieve the vins row data.
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
vins, err := RetrieveVinsByIDs(ctx, pgb.db, dbTx.VinDbIds)
if err != nil {
err = fmt.Errorf("RetrieveVinsByIDs: %v", err)
}
return vins, prevPkScripts, versions, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"VinsForTx",
"(",
"dbTx",
"*",
"dbtypes",
".",
"Tx",
")",
"(",
"[",
"]",
"dbtypes",
".",
"VinTxProperty",
",",
"[",
"]",
"string",
",",
"[",
"]",
"uint16",
",",
"error",
")",
"{",
"// Retrieve the pkScript and script version for the previous outpoint of",
"// each vin.",
"prevPkScripts",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"dbTx",
".",
"VinDbIds",
")",
")",
"\n",
"versions",
":=",
"make",
"(",
"[",
"]",
"uint16",
",",
"0",
",",
"len",
"(",
"dbTx",
".",
"VinDbIds",
")",
")",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"dbTx",
".",
"VinDbIds",
"{",
"pkScript",
",",
"ver",
",",
"err",
":=",
"pgb",
".",
"PkScriptByVinID",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"prevPkScripts",
"=",
"append",
"(",
"prevPkScripts",
",",
"hex",
".",
"EncodeToString",
"(",
"pkScript",
")",
")",
"\n",
"versions",
"=",
"append",
"(",
"versions",
",",
"ver",
")",
"\n",
"}",
"\n\n",
"// Retrieve the vins row data.",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"vins",
",",
"err",
":=",
"RetrieveVinsByIDs",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"dbTx",
".",
"VinDbIds",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"vins",
",",
"prevPkScripts",
",",
"versions",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// VinsForTx returns a slice of dbtypes.VinTxProperty values for each vin
// referenced by the transaction dbTx, along with the pkScript and script
// version for the corresponding prevous outpoints.
|
[
"VinsForTx",
"returns",
"a",
"slice",
"of",
"dbtypes",
".",
"VinTxProperty",
"values",
"for",
"each",
"vin",
"referenced",
"by",
"the",
"transaction",
"dbTx",
"along",
"with",
"the",
"pkScript",
"and",
"script",
"version",
"for",
"the",
"corresponding",
"prevous",
"outpoints",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L3062-L3084
|
141,987 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
VoutsForTx
|
func (pgb *ChainDB) VoutsForTx(dbTx *dbtypes.Tx) ([]dbtypes.Vout, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
vouts, err := RetrieveVoutsByIDs(ctx, pgb.db, dbTx.VoutDbIds)
return vouts, pgb.replaceCancelError(err)
}
|
go
|
func (pgb *ChainDB) VoutsForTx(dbTx *dbtypes.Tx) ([]dbtypes.Vout, error) {
ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
defer cancel()
vouts, err := RetrieveVoutsByIDs(ctx, pgb.db, dbTx.VoutDbIds)
return vouts, pgb.replaceCancelError(err)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"VoutsForTx",
"(",
"dbTx",
"*",
"dbtypes",
".",
"Tx",
")",
"(",
"[",
"]",
"dbtypes",
".",
"Vout",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"pgb",
".",
"ctx",
",",
"pgb",
".",
"queryTimeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"vouts",
",",
"err",
":=",
"RetrieveVoutsByIDs",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"dbTx",
".",
"VoutDbIds",
")",
"\n",
"return",
"vouts",
",",
"pgb",
".",
"replaceCancelError",
"(",
"err",
")",
"\n",
"}"
] |
// VoutsForTx returns a slice of dbtypes.Vout values for each vout referenced by
// the transaction dbTx.
|
[
"VoutsForTx",
"returns",
"a",
"slice",
"of",
"dbtypes",
".",
"Vout",
"values",
"for",
"each",
"vout",
"referenced",
"by",
"the",
"transaction",
"dbTx",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L3088-L3093
|
141,988 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
SetDBBestBlock
|
func (pgb *ChainDB) SetDBBestBlock() error {
pgb.bestBlock.mtx.RLock()
defer pgb.bestBlock.mtx.RUnlock()
return SetDBBestBlock(pgb.db, pgb.bestBlock.hash, pgb.bestBlock.height)
}
|
go
|
func (pgb *ChainDB) SetDBBestBlock() error {
pgb.bestBlock.mtx.RLock()
defer pgb.bestBlock.mtx.RUnlock()
return SetDBBestBlock(pgb.db, pgb.bestBlock.hash, pgb.bestBlock.height)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"SetDBBestBlock",
"(",
")",
"error",
"{",
"pgb",
".",
"bestBlock",
".",
"mtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"pgb",
".",
"bestBlock",
".",
"mtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"SetDBBestBlock",
"(",
"pgb",
".",
"db",
",",
"pgb",
".",
"bestBlock",
".",
"hash",
",",
"pgb",
".",
"bestBlock",
".",
"height",
")",
"\n",
"}"
] |
// SetDBBestBlock stores ChainDB's BestBlock data in the meta table.
|
[
"SetDBBestBlock",
"stores",
"ChainDB",
"s",
"BestBlock",
"data",
"in",
"the",
"meta",
"table",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L3340-L3344
|
141,989 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
CollectTicketSpendDBInfo
|
func (pgb *ChainDB) CollectTicketSpendDBInfo(dbTxns []*dbtypes.Tx, txDbIDs []uint64,
msgBlock *wire.MsgBlock, isMainchain bool) (spendingTxDbIDs []uint64, spendTypes []dbtypes.TicketSpendType,
ticketHashes []string, ticketDbIDs []uint64, err error) {
// This only makes sense for stake transactions. Check that the number of
// dbTxns equals the number of STransactions in msgBlock.
msgTxns := msgBlock.STransactions
if len(msgTxns) != len(dbTxns) {
err = fmt.Errorf("number of stake transactions (%d) not as expected (%d)",
len(msgTxns), len(dbTxns))
return
}
for i, tx := range dbTxns {
// Filter for votes and revokes only.
var stakeSubmissionVinInd int
var spendType dbtypes.TicketSpendType
switch tx.TxType {
case int16(stake.TxTypeSSGen):
spendType = dbtypes.TicketVoted
stakeSubmissionVinInd = 1
case int16(stake.TxTypeSSRtx):
spendType = dbtypes.TicketRevoked
default:
continue
}
// Ensure the transactions in dbTxns and msgBlock.STransactions correspond.
msgTx := msgTxns[i]
if tx.TxID != msgTx.TxHash().String() {
err = fmt.Errorf("txid of dbtypes.Tx does not match that of msgTx")
return
}
if stakeSubmissionVinInd >= len(msgTx.TxIn) {
log.Warnf("Invalid vote or ticket with %d inputs", len(msgTx.TxIn))
continue
}
spendTypes = append(spendTypes, spendType)
// vote/revoke row ID in *transactions* table
spendingTxDbIDs = append(spendingTxDbIDs, txDbIDs[i])
// ticket hash
ticketHash := msgTx.TxIn[stakeSubmissionVinInd].PreviousOutPoint.Hash.String()
ticketHashes = append(ticketHashes, ticketHash)
// ticket's row ID in *tickets* table
expireEntries := isMainchain // expire all cache entries for main chain blocks
t, err0 := pgb.unspentTicketCache.TxnDbID(ticketHash, expireEntries)
if err0 != nil {
err = fmt.Errorf("failed to retrieve ticket %s DB ID: %v", ticketHash, err0)
return
}
ticketDbIDs = append(ticketDbIDs, t)
}
return
}
|
go
|
func (pgb *ChainDB) CollectTicketSpendDBInfo(dbTxns []*dbtypes.Tx, txDbIDs []uint64,
msgBlock *wire.MsgBlock, isMainchain bool) (spendingTxDbIDs []uint64, spendTypes []dbtypes.TicketSpendType,
ticketHashes []string, ticketDbIDs []uint64, err error) {
// This only makes sense for stake transactions. Check that the number of
// dbTxns equals the number of STransactions in msgBlock.
msgTxns := msgBlock.STransactions
if len(msgTxns) != len(dbTxns) {
err = fmt.Errorf("number of stake transactions (%d) not as expected (%d)",
len(msgTxns), len(dbTxns))
return
}
for i, tx := range dbTxns {
// Filter for votes and revokes only.
var stakeSubmissionVinInd int
var spendType dbtypes.TicketSpendType
switch tx.TxType {
case int16(stake.TxTypeSSGen):
spendType = dbtypes.TicketVoted
stakeSubmissionVinInd = 1
case int16(stake.TxTypeSSRtx):
spendType = dbtypes.TicketRevoked
default:
continue
}
// Ensure the transactions in dbTxns and msgBlock.STransactions correspond.
msgTx := msgTxns[i]
if tx.TxID != msgTx.TxHash().String() {
err = fmt.Errorf("txid of dbtypes.Tx does not match that of msgTx")
return
}
if stakeSubmissionVinInd >= len(msgTx.TxIn) {
log.Warnf("Invalid vote or ticket with %d inputs", len(msgTx.TxIn))
continue
}
spendTypes = append(spendTypes, spendType)
// vote/revoke row ID in *transactions* table
spendingTxDbIDs = append(spendingTxDbIDs, txDbIDs[i])
// ticket hash
ticketHash := msgTx.TxIn[stakeSubmissionVinInd].PreviousOutPoint.Hash.String()
ticketHashes = append(ticketHashes, ticketHash)
// ticket's row ID in *tickets* table
expireEntries := isMainchain // expire all cache entries for main chain blocks
t, err0 := pgb.unspentTicketCache.TxnDbID(ticketHash, expireEntries)
if err0 != nil {
err = fmt.Errorf("failed to retrieve ticket %s DB ID: %v", ticketHash, err0)
return
}
ticketDbIDs = append(ticketDbIDs, t)
}
return
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"CollectTicketSpendDBInfo",
"(",
"dbTxns",
"[",
"]",
"*",
"dbtypes",
".",
"Tx",
",",
"txDbIDs",
"[",
"]",
"uint64",
",",
"msgBlock",
"*",
"wire",
".",
"MsgBlock",
",",
"isMainchain",
"bool",
")",
"(",
"spendingTxDbIDs",
"[",
"]",
"uint64",
",",
"spendTypes",
"[",
"]",
"dbtypes",
".",
"TicketSpendType",
",",
"ticketHashes",
"[",
"]",
"string",
",",
"ticketDbIDs",
"[",
"]",
"uint64",
",",
"err",
"error",
")",
"{",
"// This only makes sense for stake transactions. Check that the number of",
"// dbTxns equals the number of STransactions in msgBlock.",
"msgTxns",
":=",
"msgBlock",
".",
"STransactions",
"\n",
"if",
"len",
"(",
"msgTxns",
")",
"!=",
"len",
"(",
"dbTxns",
")",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"msgTxns",
")",
",",
"len",
"(",
"dbTxns",
")",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"tx",
":=",
"range",
"dbTxns",
"{",
"// Filter for votes and revokes only.",
"var",
"stakeSubmissionVinInd",
"int",
"\n",
"var",
"spendType",
"dbtypes",
".",
"TicketSpendType",
"\n",
"switch",
"tx",
".",
"TxType",
"{",
"case",
"int16",
"(",
"stake",
".",
"TxTypeSSGen",
")",
":",
"spendType",
"=",
"dbtypes",
".",
"TicketVoted",
"\n",
"stakeSubmissionVinInd",
"=",
"1",
"\n",
"case",
"int16",
"(",
"stake",
".",
"TxTypeSSRtx",
")",
":",
"spendType",
"=",
"dbtypes",
".",
"TicketRevoked",
"\n",
"default",
":",
"continue",
"\n",
"}",
"\n\n",
"// Ensure the transactions in dbTxns and msgBlock.STransactions correspond.",
"msgTx",
":=",
"msgTxns",
"[",
"i",
"]",
"\n",
"if",
"tx",
".",
"TxID",
"!=",
"msgTx",
".",
"TxHash",
"(",
")",
".",
"String",
"(",
")",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"stakeSubmissionVinInd",
">=",
"len",
"(",
"msgTx",
".",
"TxIn",
")",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"len",
"(",
"msgTx",
".",
"TxIn",
")",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"spendTypes",
"=",
"append",
"(",
"spendTypes",
",",
"spendType",
")",
"\n\n",
"// vote/revoke row ID in *transactions* table",
"spendingTxDbIDs",
"=",
"append",
"(",
"spendingTxDbIDs",
",",
"txDbIDs",
"[",
"i",
"]",
")",
"\n\n",
"// ticket hash",
"ticketHash",
":=",
"msgTx",
".",
"TxIn",
"[",
"stakeSubmissionVinInd",
"]",
".",
"PreviousOutPoint",
".",
"Hash",
".",
"String",
"(",
")",
"\n",
"ticketHashes",
"=",
"append",
"(",
"ticketHashes",
",",
"ticketHash",
")",
"\n\n",
"// ticket's row ID in *tickets* table",
"expireEntries",
":=",
"isMainchain",
"// expire all cache entries for main chain blocks",
"\n",
"t",
",",
"err0",
":=",
"pgb",
".",
"unspentTicketCache",
".",
"TxnDbID",
"(",
"ticketHash",
",",
"expireEntries",
")",
"\n",
"if",
"err0",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ticketHash",
",",
"err0",
")",
"\n",
"return",
"\n",
"}",
"\n",
"ticketDbIDs",
"=",
"append",
"(",
"ticketDbIDs",
",",
"t",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// CollectTicketSpendDBInfo processes the stake transactions in msgBlock, which
// correspond to the transaction data in dbTxns, and extracts data for votes and
// revokes, including the spent ticket hash and DB row ID.
|
[
"CollectTicketSpendDBInfo",
"processes",
"the",
"stake",
"transactions",
"in",
"msgBlock",
"which",
"correspond",
"to",
"the",
"transaction",
"data",
"in",
"dbTxns",
"and",
"extracts",
"data",
"for",
"votes",
"and",
"revokes",
"including",
"the",
"spent",
"ticket",
"hash",
"and",
"DB",
"row",
"ID",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L3900-L3957
|
141,990 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
UpdateSpendingInfoInAllTickets
|
func (pgb *ChainDB) UpdateSpendingInfoInAllTickets() (int64, error) {
// The queries in this function should not timeout or (probably) canceled,
// so use a background context.
ctx := context.Background()
// Get the full list of votes (DB IDs and heights), and spent ticket hashes
allVotesDbIDs, allVotesHeights, ticketDbIDs, err :=
RetrieveAllVotesDbIDsHeightsTicketDbIDs(ctx, pgb.db)
if err != nil {
log.Errorf("RetrieveAllVotesDbIDsHeightsTicketDbIDs: %v", err)
return 0, err
}
// To update spending info in tickets table, get the spent tickets' DB
// row IDs and block heights.
spendTypes := make([]dbtypes.TicketSpendType, len(ticketDbIDs))
for iv := range ticketDbIDs {
spendTypes[iv] = dbtypes.TicketVoted
}
poolStatuses := ticketpoolStatusSlice(dbtypes.PoolStatusVoted, len(ticketDbIDs))
// Update tickets table with spending info from new votes
var totalTicketsUpdated int64
totalTicketsUpdated, err = SetSpendingForTickets(pgb.db, ticketDbIDs,
allVotesDbIDs, allVotesHeights, spendTypes, poolStatuses)
if err != nil {
log.Warn("SetSpendingForTickets:", err)
}
// Revokes
revokeIDs, _, revokeHeights, vinDbIDs, err := RetrieveAllRevokes(ctx, pgb.db)
if err != nil {
log.Errorf("RetrieveAllRevokes: %v", err)
return 0, err
}
revokedTicketHashes := make([]string, len(vinDbIDs))
for i, vinDbID := range vinDbIDs {
revokedTicketHashes[i], err = RetrieveFundingTxByVinDbID(ctx, pgb.db, vinDbID)
if err != nil {
log.Errorf("RetrieveFundingTxByVinDbID: %v", err)
return 0, err
}
}
revokedTicketDbIDs, err := RetrieveTicketIDsByHashes(ctx, pgb.db, revokedTicketHashes)
if err != nil {
log.Errorf("RetrieveTicketIDsByHashes: %v", err)
return 0, err
}
poolStatuses = ticketpoolStatusSlice(dbtypes.PoolStatusMissed, len(revokedTicketHashes))
pgb.stakeDB.LockStakeNode()
for ih := range revokedTicketHashes {
rh, _ := chainhash.NewHashFromStr(revokedTicketHashes[ih])
if pgb.stakeDB.BestNode.ExistsExpiredTicket(*rh) {
poolStatuses[ih] = dbtypes.PoolStatusExpired
}
}
pgb.stakeDB.UnlockStakeNode()
// To update spending info in tickets table, get the spent tickets' DB
// row IDs and block heights.
spendTypes = make([]dbtypes.TicketSpendType, len(revokedTicketDbIDs))
for iv := range revokedTicketDbIDs {
spendTypes[iv] = dbtypes.TicketRevoked
}
// Update tickets table with spending info from new votes
var revokedTicketsUpdated int64
revokedTicketsUpdated, err = SetSpendingForTickets(pgb.db, revokedTicketDbIDs,
revokeIDs, revokeHeights, spendTypes, poolStatuses)
if err != nil {
log.Warn("SetSpendingForTickets:", err)
}
return totalTicketsUpdated + revokedTicketsUpdated, err
}
|
go
|
func (pgb *ChainDB) UpdateSpendingInfoInAllTickets() (int64, error) {
// The queries in this function should not timeout or (probably) canceled,
// so use a background context.
ctx := context.Background()
// Get the full list of votes (DB IDs and heights), and spent ticket hashes
allVotesDbIDs, allVotesHeights, ticketDbIDs, err :=
RetrieveAllVotesDbIDsHeightsTicketDbIDs(ctx, pgb.db)
if err != nil {
log.Errorf("RetrieveAllVotesDbIDsHeightsTicketDbIDs: %v", err)
return 0, err
}
// To update spending info in tickets table, get the spent tickets' DB
// row IDs and block heights.
spendTypes := make([]dbtypes.TicketSpendType, len(ticketDbIDs))
for iv := range ticketDbIDs {
spendTypes[iv] = dbtypes.TicketVoted
}
poolStatuses := ticketpoolStatusSlice(dbtypes.PoolStatusVoted, len(ticketDbIDs))
// Update tickets table with spending info from new votes
var totalTicketsUpdated int64
totalTicketsUpdated, err = SetSpendingForTickets(pgb.db, ticketDbIDs,
allVotesDbIDs, allVotesHeights, spendTypes, poolStatuses)
if err != nil {
log.Warn("SetSpendingForTickets:", err)
}
// Revokes
revokeIDs, _, revokeHeights, vinDbIDs, err := RetrieveAllRevokes(ctx, pgb.db)
if err != nil {
log.Errorf("RetrieveAllRevokes: %v", err)
return 0, err
}
revokedTicketHashes := make([]string, len(vinDbIDs))
for i, vinDbID := range vinDbIDs {
revokedTicketHashes[i], err = RetrieveFundingTxByVinDbID(ctx, pgb.db, vinDbID)
if err != nil {
log.Errorf("RetrieveFundingTxByVinDbID: %v", err)
return 0, err
}
}
revokedTicketDbIDs, err := RetrieveTicketIDsByHashes(ctx, pgb.db, revokedTicketHashes)
if err != nil {
log.Errorf("RetrieveTicketIDsByHashes: %v", err)
return 0, err
}
poolStatuses = ticketpoolStatusSlice(dbtypes.PoolStatusMissed, len(revokedTicketHashes))
pgb.stakeDB.LockStakeNode()
for ih := range revokedTicketHashes {
rh, _ := chainhash.NewHashFromStr(revokedTicketHashes[ih])
if pgb.stakeDB.BestNode.ExistsExpiredTicket(*rh) {
poolStatuses[ih] = dbtypes.PoolStatusExpired
}
}
pgb.stakeDB.UnlockStakeNode()
// To update spending info in tickets table, get the spent tickets' DB
// row IDs and block heights.
spendTypes = make([]dbtypes.TicketSpendType, len(revokedTicketDbIDs))
for iv := range revokedTicketDbIDs {
spendTypes[iv] = dbtypes.TicketRevoked
}
// Update tickets table with spending info from new votes
var revokedTicketsUpdated int64
revokedTicketsUpdated, err = SetSpendingForTickets(pgb.db, revokedTicketDbIDs,
revokeIDs, revokeHeights, spendTypes, poolStatuses)
if err != nil {
log.Warn("SetSpendingForTickets:", err)
}
return totalTicketsUpdated + revokedTicketsUpdated, err
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"UpdateSpendingInfoInAllTickets",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"// The queries in this function should not timeout or (probably) canceled,",
"// so use a background context.",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n\n",
"// Get the full list of votes (DB IDs and heights), and spent ticket hashes",
"allVotesDbIDs",
",",
"allVotesHeights",
",",
"ticketDbIDs",
",",
"err",
":=",
"RetrieveAllVotesDbIDsHeightsTicketDbIDs",
"(",
"ctx",
",",
"pgb",
".",
"db",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"// To update spending info in tickets table, get the spent tickets' DB",
"// row IDs and block heights.",
"spendTypes",
":=",
"make",
"(",
"[",
"]",
"dbtypes",
".",
"TicketSpendType",
",",
"len",
"(",
"ticketDbIDs",
")",
")",
"\n",
"for",
"iv",
":=",
"range",
"ticketDbIDs",
"{",
"spendTypes",
"[",
"iv",
"]",
"=",
"dbtypes",
".",
"TicketVoted",
"\n",
"}",
"\n",
"poolStatuses",
":=",
"ticketpoolStatusSlice",
"(",
"dbtypes",
".",
"PoolStatusVoted",
",",
"len",
"(",
"ticketDbIDs",
")",
")",
"\n\n",
"// Update tickets table with spending info from new votes",
"var",
"totalTicketsUpdated",
"int64",
"\n",
"totalTicketsUpdated",
",",
"err",
"=",
"SetSpendingForTickets",
"(",
"pgb",
".",
"db",
",",
"ticketDbIDs",
",",
"allVotesDbIDs",
",",
"allVotesHeights",
",",
"spendTypes",
",",
"poolStatuses",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warn",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Revokes",
"revokeIDs",
",",
"_",
",",
"revokeHeights",
",",
"vinDbIDs",
",",
"err",
":=",
"RetrieveAllRevokes",
"(",
"ctx",
",",
"pgb",
".",
"db",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"revokedTicketHashes",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"vinDbIDs",
")",
")",
"\n",
"for",
"i",
",",
"vinDbID",
":=",
"range",
"vinDbIDs",
"{",
"revokedTicketHashes",
"[",
"i",
"]",
",",
"err",
"=",
"RetrieveFundingTxByVinDbID",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"vinDbID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"revokedTicketDbIDs",
",",
"err",
":=",
"RetrieveTicketIDsByHashes",
"(",
"ctx",
",",
"pgb",
".",
"db",
",",
"revokedTicketHashes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"poolStatuses",
"=",
"ticketpoolStatusSlice",
"(",
"dbtypes",
".",
"PoolStatusMissed",
",",
"len",
"(",
"revokedTicketHashes",
")",
")",
"\n",
"pgb",
".",
"stakeDB",
".",
"LockStakeNode",
"(",
")",
"\n",
"for",
"ih",
":=",
"range",
"revokedTicketHashes",
"{",
"rh",
",",
"_",
":=",
"chainhash",
".",
"NewHashFromStr",
"(",
"revokedTicketHashes",
"[",
"ih",
"]",
")",
"\n",
"if",
"pgb",
".",
"stakeDB",
".",
"BestNode",
".",
"ExistsExpiredTicket",
"(",
"*",
"rh",
")",
"{",
"poolStatuses",
"[",
"ih",
"]",
"=",
"dbtypes",
".",
"PoolStatusExpired",
"\n",
"}",
"\n",
"}",
"\n",
"pgb",
".",
"stakeDB",
".",
"UnlockStakeNode",
"(",
")",
"\n\n",
"// To update spending info in tickets table, get the spent tickets' DB",
"// row IDs and block heights.",
"spendTypes",
"=",
"make",
"(",
"[",
"]",
"dbtypes",
".",
"TicketSpendType",
",",
"len",
"(",
"revokedTicketDbIDs",
")",
")",
"\n",
"for",
"iv",
":=",
"range",
"revokedTicketDbIDs",
"{",
"spendTypes",
"[",
"iv",
"]",
"=",
"dbtypes",
".",
"TicketRevoked",
"\n",
"}",
"\n\n",
"// Update tickets table with spending info from new votes",
"var",
"revokedTicketsUpdated",
"int64",
"\n",
"revokedTicketsUpdated",
",",
"err",
"=",
"SetSpendingForTickets",
"(",
"pgb",
".",
"db",
",",
"revokedTicketDbIDs",
",",
"revokeIDs",
",",
"revokeHeights",
",",
"spendTypes",
",",
"poolStatuses",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warn",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"totalTicketsUpdated",
"+",
"revokedTicketsUpdated",
",",
"err",
"\n",
"}"
] |
// UpdateSpendingInfoInAllTickets reviews all votes and revokes and sets this
// spending info in the tickets table.
|
[
"UpdateSpendingInfoInAllTickets",
"reviews",
"all",
"votes",
"and",
"revokes",
"and",
"sets",
"this",
"spending",
"info",
"in",
"the",
"tickets",
"table",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L4032-L4110
|
141,991 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
GetChainWork
|
func (pgb *ChainDBRPC) GetChainWork(hash *chainhash.Hash) (string, error) {
return rpcutils.GetChainWork(pgb.Client, hash)
}
|
go
|
func (pgb *ChainDBRPC) GetChainWork(hash *chainhash.Hash) (string, error) {
return rpcutils.GetChainWork(pgb.Client, hash)
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDBRPC",
")",
"GetChainWork",
"(",
"hash",
"*",
"chainhash",
".",
"Hash",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"rpcutils",
".",
"GetChainWork",
"(",
"pgb",
".",
"Client",
",",
"hash",
")",
"\n",
"}"
] |
// GetChainWork fetches the dcrjson.BlockHeaderVerbose and returns only the
// ChainWork attribute as a hex-encoded string, without 0x prefix.
|
[
"GetChainWork",
"fetches",
"the",
"dcrjson",
".",
"BlockHeaderVerbose",
"and",
"returns",
"only",
"the",
"ChainWork",
"attribute",
"as",
"a",
"hex",
"-",
"encoded",
"string",
"without",
"0x",
"prefix",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L4122-L4124
|
141,992 |
decred/dcrdata
|
db/dcrpg/pgblockchain.go
|
GenesisStamp
|
func (pgb *ChainDB) GenesisStamp() int64 {
tDef := dbtypes.NewTimeDefFromUNIX(0)
// Ignoring error and returning zero time.
pgb.db.QueryRowContext(pgb.ctx, internal.SelectGenesisTime).Scan(&tDef)
return tDef.T.Unix()
}
|
go
|
func (pgb *ChainDB) GenesisStamp() int64 {
tDef := dbtypes.NewTimeDefFromUNIX(0)
// Ignoring error and returning zero time.
pgb.db.QueryRowContext(pgb.ctx, internal.SelectGenesisTime).Scan(&tDef)
return tDef.T.Unix()
}
|
[
"func",
"(",
"pgb",
"*",
"ChainDB",
")",
"GenesisStamp",
"(",
")",
"int64",
"{",
"tDef",
":=",
"dbtypes",
".",
"NewTimeDefFromUNIX",
"(",
"0",
")",
"\n",
"// Ignoring error and returning zero time.",
"pgb",
".",
"db",
".",
"QueryRowContext",
"(",
"pgb",
".",
"ctx",
",",
"internal",
".",
"SelectGenesisTime",
")",
".",
"Scan",
"(",
"&",
"tDef",
")",
"\n",
"return",
"tDef",
".",
"T",
".",
"Unix",
"(",
")",
"\n",
"}"
] |
// GenesisStamp returns the stamp of the lowest mainchain block in the database.
|
[
"GenesisStamp",
"returns",
"the",
"stamp",
"of",
"the",
"lowest",
"mainchain",
"block",
"in",
"the",
"database",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/pgblockchain.go#L4127-L4132
|
141,993 |
decred/dcrdata
|
db/dcrpg/rewind.go
|
RetrieveTxsBlocksAboveHeight
|
func RetrieveTxsBlocksAboveHeight(ctx context.Context, db *sql.DB, height int64) (heights []int64, hashes []string, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectTxsBlocksAboveHeight, height)
if err != nil {
return
}
for rows.Next() {
var height int64
var hash string
if err = rows.Scan(&height, &hash); err != nil {
return nil, nil, err
}
heights = append(heights, height)
hashes = append(hashes, hash)
}
return
}
|
go
|
func RetrieveTxsBlocksAboveHeight(ctx context.Context, db *sql.DB, height int64) (heights []int64, hashes []string, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectTxsBlocksAboveHeight, height)
if err != nil {
return
}
for rows.Next() {
var height int64
var hash string
if err = rows.Scan(&height, &hash); err != nil {
return nil, nil, err
}
heights = append(heights, height)
hashes = append(hashes, hash)
}
return
}
|
[
"func",
"RetrieveTxsBlocksAboveHeight",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"height",
"int64",
")",
"(",
"heights",
"[",
"]",
"int64",
",",
"hashes",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"var",
"rows",
"*",
"sql",
".",
"Rows",
"\n",
"rows",
",",
"err",
"=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectTxsBlocksAboveHeight",
",",
"height",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"height",
"int64",
"\n",
"var",
"hash",
"string",
"\n",
"if",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"height",
",",
"&",
"hash",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"heights",
"=",
"append",
"(",
"heights",
",",
"height",
")",
"\n",
"hashes",
"=",
"append",
"(",
"hashes",
",",
"hash",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// RetrieveTxsBlocksAboveHeight returns all distinct mainchain block heights and
// hashes referenced in the transactions table above the given height.
|
[
"RetrieveTxsBlocksAboveHeight",
"returns",
"all",
"distinct",
"mainchain",
"block",
"heights",
"and",
"hashes",
"referenced",
"in",
"the",
"transactions",
"table",
"above",
"the",
"given",
"height",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/rewind.go#L104-L121
|
141,994 |
decred/dcrdata
|
db/dcrpg/rewind.go
|
RetrieveTxsBestBlockMainchain
|
func RetrieveTxsBestBlockMainchain(ctx context.Context, db *sql.DB) (height int64, hash string, err error) {
err = db.QueryRowContext(ctx, internal.SelectTxsBestBlock).Scan(&height, &hash)
if err == sql.ErrNoRows {
err = nil
height = -1
}
return
}
|
go
|
func RetrieveTxsBestBlockMainchain(ctx context.Context, db *sql.DB) (height int64, hash string, err error) {
err = db.QueryRowContext(ctx, internal.SelectTxsBestBlock).Scan(&height, &hash)
if err == sql.ErrNoRows {
err = nil
height = -1
}
return
}
|
[
"func",
"RetrieveTxsBestBlockMainchain",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"height",
"int64",
",",
"hash",
"string",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectTxsBestBlock",
")",
".",
"Scan",
"(",
"&",
"height",
",",
"&",
"hash",
")",
"\n",
"if",
"err",
"==",
"sql",
".",
"ErrNoRows",
"{",
"err",
"=",
"nil",
"\n",
"height",
"=",
"-",
"1",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// RetrieveTxsBestBlockMainchain returns the best mainchain block's height from
// the transactions table. If the table is empty, a height of -1, an empty hash
// string, and a nil error are returned
|
[
"RetrieveTxsBestBlockMainchain",
"returns",
"the",
"best",
"mainchain",
"block",
"s",
"height",
"from",
"the",
"transactions",
"table",
".",
"If",
"the",
"table",
"is",
"empty",
"a",
"height",
"of",
"-",
"1",
"an",
"empty",
"hash",
"string",
"and",
"a",
"nil",
"error",
"are",
"returned"
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/rewind.go#L126-L133
|
141,995 |
decred/dcrdata
|
db/dcrpg/rewind.go
|
DeleteBestBlock
|
func DeleteBestBlock(ctx context.Context, db *sql.DB) (res dbtypes.DeletionSummary, height int64, hash string, err error) {
height, hash, err = RetrieveBestBlock(ctx, db)
if err != nil {
return
}
res, err = DeleteBlockData(ctx, db, hash)
if err != nil {
return
}
height, hash, err = RetrieveBestBlock(ctx, db)
if err != nil {
return
}
err = SetDBBestBlock(db, hash, height)
return
}
|
go
|
func DeleteBestBlock(ctx context.Context, db *sql.DB) (res dbtypes.DeletionSummary, height int64, hash string, err error) {
height, hash, err = RetrieveBestBlock(ctx, db)
if err != nil {
return
}
res, err = DeleteBlockData(ctx, db, hash)
if err != nil {
return
}
height, hash, err = RetrieveBestBlock(ctx, db)
if err != nil {
return
}
err = SetDBBestBlock(db, hash, height)
return
}
|
[
"func",
"DeleteBestBlock",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"res",
"dbtypes",
".",
"DeletionSummary",
",",
"height",
"int64",
",",
"hash",
"string",
",",
"err",
"error",
")",
"{",
"height",
",",
"hash",
",",
"err",
"=",
"RetrieveBestBlock",
"(",
"ctx",
",",
"db",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"res",
",",
"err",
"=",
"DeleteBlockData",
"(",
"ctx",
",",
"db",
",",
"hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"height",
",",
"hash",
",",
"err",
"=",
"RetrieveBestBlock",
"(",
"ctx",
",",
"db",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"err",
"=",
"SetDBBestBlock",
"(",
"db",
",",
"hash",
",",
"height",
")",
"\n",
"return",
"\n",
"}"
] |
// DeleteBestBlock removes all data for the best block in the DB from every
// table via DeleteBlockData. The returned height and hash are for the best
// block after successful data removal, or the initial best block if removal
// fails as indicated by a non-nil error value.
|
[
"DeleteBestBlock",
"removes",
"all",
"data",
"for",
"the",
"best",
"block",
"in",
"the",
"DB",
"from",
"every",
"table",
"via",
"DeleteBlockData",
".",
"The",
"returned",
"height",
"and",
"hash",
"are",
"for",
"the",
"best",
"block",
"after",
"successful",
"data",
"removal",
"or",
"the",
"initial",
"best",
"block",
"if",
"removal",
"fails",
"as",
"indicated",
"by",
"a",
"non",
"-",
"nil",
"error",
"value",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/rewind.go#L253-L271
|
141,996 |
decred/dcrdata
|
db/dcrpg/rewind.go
|
DeleteBlocks
|
func DeleteBlocks(ctx context.Context, N int64, db *sql.DB) (res []dbtypes.DeletionSummary, height int64, hash string, err error) {
// If N is less than 1, get the current best block height and hash, then
// return.
if N < 1 {
height, hash, err = RetrieveBestBlock(ctx, db)
return
}
for i := int64(0); i < N; i++ {
var resi dbtypes.DeletionSummary
resi, height, hash, err = DeleteBestBlock(ctx, db)
if err != nil {
return
}
res = append(res, resi)
if hash == "" {
break
}
if (i%100 == 0 && i > 0) || i == N-1 {
log.Debugf("Removed data for %d blocks.", i+1)
}
}
return
}
|
go
|
func DeleteBlocks(ctx context.Context, N int64, db *sql.DB) (res []dbtypes.DeletionSummary, height int64, hash string, err error) {
// If N is less than 1, get the current best block height and hash, then
// return.
if N < 1 {
height, hash, err = RetrieveBestBlock(ctx, db)
return
}
for i := int64(0); i < N; i++ {
var resi dbtypes.DeletionSummary
resi, height, hash, err = DeleteBestBlock(ctx, db)
if err != nil {
return
}
res = append(res, resi)
if hash == "" {
break
}
if (i%100 == 0 && i > 0) || i == N-1 {
log.Debugf("Removed data for %d blocks.", i+1)
}
}
return
}
|
[
"func",
"DeleteBlocks",
"(",
"ctx",
"context",
".",
"Context",
",",
"N",
"int64",
",",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"res",
"[",
"]",
"dbtypes",
".",
"DeletionSummary",
",",
"height",
"int64",
",",
"hash",
"string",
",",
"err",
"error",
")",
"{",
"// If N is less than 1, get the current best block height and hash, then",
"// return.",
"if",
"N",
"<",
"1",
"{",
"height",
",",
"hash",
",",
"err",
"=",
"RetrieveBestBlock",
"(",
"ctx",
",",
"db",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"int64",
"(",
"0",
")",
";",
"i",
"<",
"N",
";",
"i",
"++",
"{",
"var",
"resi",
"dbtypes",
".",
"DeletionSummary",
"\n",
"resi",
",",
"height",
",",
"hash",
",",
"err",
"=",
"DeleteBestBlock",
"(",
"ctx",
",",
"db",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"res",
"=",
"append",
"(",
"res",
",",
"resi",
")",
"\n",
"if",
"hash",
"==",
"\"",
"\"",
"{",
"break",
"\n",
"}",
"\n",
"if",
"(",
"i",
"%",
"100",
"==",
"0",
"&&",
"i",
">",
"0",
")",
"||",
"i",
"==",
"N",
"-",
"1",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"i",
"+",
"1",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// DeleteBlocks removes all data for the N best blocks in the DB from every
// table via repeated calls to DeleteBestBlock.
|
[
"DeleteBlocks",
"removes",
"all",
"data",
"for",
"the",
"N",
"best",
"blocks",
"in",
"the",
"DB",
"from",
"every",
"table",
"via",
"repeated",
"calls",
"to",
"DeleteBestBlock",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/rewind.go#L275-L299
|
141,997 |
decred/dcrdata
|
version/version.go
|
normalizeSemString
|
func normalizeSemString(str, alphabet string) string {
var result bytes.Buffer
for _, r := range str {
if strings.ContainsRune(alphabet, r) {
result.WriteRune(r)
}
}
return result.String()
}
|
go
|
func normalizeSemString(str, alphabet string) string {
var result bytes.Buffer
for _, r := range str {
if strings.ContainsRune(alphabet, r) {
result.WriteRune(r)
}
}
return result.String()
}
|
[
"func",
"normalizeSemString",
"(",
"str",
",",
"alphabet",
"string",
")",
"string",
"{",
"var",
"result",
"bytes",
".",
"Buffer",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"str",
"{",
"if",
"strings",
".",
"ContainsRune",
"(",
"alphabet",
",",
"r",
")",
"{",
"result",
".",
"WriteRune",
"(",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
".",
"String",
"(",
")",
"\n",
"}"
] |
// normalizeSemString returns the passed string stripped of all characters
// which are not valid according to the provided semantic versioning alphabet.
|
[
"normalizeSemString",
"returns",
"the",
"passed",
"string",
"stripped",
"of",
"all",
"characters",
"which",
"are",
"not",
"valid",
"according",
"to",
"the",
"provided",
"semantic",
"versioning",
"alphabet",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/version/version.go#L74-L82
|
141,998 |
decred/dcrdata
|
explorer/mempool.go
|
matchMempoolVins
|
func matchMempoolVins(txid string, txsList []types.MempoolTx) (vins []types.MempoolVin) {
for idx := range txsList {
tx := &txsList[idx]
var inputs []types.MempoolInput
for vindex := range tx.Vin {
input := &tx.Vin[vindex]
if input.TxId != txid {
continue
}
inputs = append(inputs, *input)
}
if len(inputs) == 0 {
continue
}
vins = append(vins, types.MempoolVin{
TxId: tx.TxID,
Inputs: inputs,
})
}
return
}
|
go
|
func matchMempoolVins(txid string, txsList []types.MempoolTx) (vins []types.MempoolVin) {
for idx := range txsList {
tx := &txsList[idx]
var inputs []types.MempoolInput
for vindex := range tx.Vin {
input := &tx.Vin[vindex]
if input.TxId != txid {
continue
}
inputs = append(inputs, *input)
}
if len(inputs) == 0 {
continue
}
vins = append(vins, types.MempoolVin{
TxId: tx.TxID,
Inputs: inputs,
})
}
return
}
|
[
"func",
"matchMempoolVins",
"(",
"txid",
"string",
",",
"txsList",
"[",
"]",
"types",
".",
"MempoolTx",
")",
"(",
"vins",
"[",
"]",
"types",
".",
"MempoolVin",
")",
"{",
"for",
"idx",
":=",
"range",
"txsList",
"{",
"tx",
":=",
"&",
"txsList",
"[",
"idx",
"]",
"\n",
"var",
"inputs",
"[",
"]",
"types",
".",
"MempoolInput",
"\n",
"for",
"vindex",
":=",
"range",
"tx",
".",
"Vin",
"{",
"input",
":=",
"&",
"tx",
".",
"Vin",
"[",
"vindex",
"]",
"\n",
"if",
"input",
".",
"TxId",
"!=",
"txid",
"{",
"continue",
"\n",
"}",
"\n",
"inputs",
"=",
"append",
"(",
"inputs",
",",
"*",
"input",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"inputs",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"vins",
"=",
"append",
"(",
"vins",
",",
"types",
".",
"MempoolVin",
"{",
"TxId",
":",
"tx",
".",
"TxID",
",",
"Inputs",
":",
"inputs",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// matchMempoolVins filters relevant mempool transaction inputs whose previous
// outpoints match the specified transaction id.
|
[
"matchMempoolVins",
"filters",
"relevant",
"mempool",
"transaction",
"inputs",
"whose",
"previous",
"outpoints",
"match",
"the",
"specified",
"transaction",
"id",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/mempool.go#L11-L31
|
141,999 |
decred/dcrdata
|
explorer/mempool.go
|
GetTxMempoolInputs
|
func (exp *explorerUI) GetTxMempoolInputs(txid string, txType string) (vins []types.MempoolVin) {
// Lock the pointer from changing, and the contents of the shared struct.
inv := exp.MempoolInventory()
inv.RLock()
defer inv.RUnlock()
vins = append(vins, matchMempoolVins(txid, inv.Transactions)...)
vins = append(vins, matchMempoolVins(txid, inv.Tickets)...)
vins = append(vins, matchMempoolVins(txid, inv.Revocations)...)
vins = append(vins, matchMempoolVins(txid, inv.Votes)...)
return
}
|
go
|
func (exp *explorerUI) GetTxMempoolInputs(txid string, txType string) (vins []types.MempoolVin) {
// Lock the pointer from changing, and the contents of the shared struct.
inv := exp.MempoolInventory()
inv.RLock()
defer inv.RUnlock()
vins = append(vins, matchMempoolVins(txid, inv.Transactions)...)
vins = append(vins, matchMempoolVins(txid, inv.Tickets)...)
vins = append(vins, matchMempoolVins(txid, inv.Revocations)...)
vins = append(vins, matchMempoolVins(txid, inv.Votes)...)
return
}
|
[
"func",
"(",
"exp",
"*",
"explorerUI",
")",
"GetTxMempoolInputs",
"(",
"txid",
"string",
",",
"txType",
"string",
")",
"(",
"vins",
"[",
"]",
"types",
".",
"MempoolVin",
")",
"{",
"// Lock the pointer from changing, and the contents of the shared struct.",
"inv",
":=",
"exp",
".",
"MempoolInventory",
"(",
")",
"\n",
"inv",
".",
"RLock",
"(",
")",
"\n",
"defer",
"inv",
".",
"RUnlock",
"(",
")",
"\n",
"vins",
"=",
"append",
"(",
"vins",
",",
"matchMempoolVins",
"(",
"txid",
",",
"inv",
".",
"Transactions",
")",
"...",
")",
"\n",
"vins",
"=",
"append",
"(",
"vins",
",",
"matchMempoolVins",
"(",
"txid",
",",
"inv",
".",
"Tickets",
")",
"...",
")",
"\n",
"vins",
"=",
"append",
"(",
"vins",
",",
"matchMempoolVins",
"(",
"txid",
",",
"inv",
".",
"Revocations",
")",
"...",
")",
"\n",
"vins",
"=",
"append",
"(",
"vins",
",",
"matchMempoolVins",
"(",
"txid",
",",
"inv",
".",
"Votes",
")",
"...",
")",
"\n",
"return",
"\n",
"}"
] |
// GetTxMempoolInputs grabs very simple information about mempool transaction
// inputs that spend a particular previous transaction's outputs. The returned
// slice has just enough information to match an unspent transaction output.
|
[
"GetTxMempoolInputs",
"grabs",
"very",
"simple",
"information",
"about",
"mempool",
"transaction",
"inputs",
"that",
"spend",
"a",
"particular",
"previous",
"transaction",
"s",
"outputs",
".",
"The",
"returned",
"slice",
"has",
"just",
"enough",
"information",
"to",
"match",
"an",
"unspent",
"transaction",
"output",
"."
] |
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
|
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/explorer/mempool.go#L36-L46
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.