repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
decred/dcrdata | db/dcrsqlite/chainmonitor.go | switchToSideChain | func (p *ChainMonitor) switchToSideChain(reorgData *txhelpers.ReorgData) (int32, *chainhash.Hash, error) {
if reorgData == nil || len(reorgData.NewChain) == 0 {
return 0, nil, fmt.Errorf("no side chain")
}
newChain := reorgData.NewChain
// newChain does not include the common ancestor.
commonAncestorHeight := int64(reorgData.NewChainHeight) - int64(len(newChain))
mainTip := p.db.GetBestBlockHeight()
if mainTip != int64(reorgData.OldChainHeight) {
log.Warnf("StakeDatabase height is %d, expected %d. Rewinding as "+
"needed to complete reorg from ancestor at %d", mainTip,
reorgData.OldChainHeight, commonAncestorHeight)
}
// Save blocks from previous side chain that is now the main chain.
log.Infof("Saving %d new blocks from previous side chain to sqlite.", len(newChain))
for i := range newChain {
// Get data by block hash, which requires the stakedb's PoolInfoCache to
// contain data for the side chain blocks already (guaranteed if stakedb
// block-connected ntfns are always handled before these).
blockDataSummary, stakeInfoSummaryExtended := p.collector.CollectAPITypes(&newChain[i])
if blockDataSummary == nil || stakeInfoSummaryExtended == nil {
log.Error("Failed to collect data for reorg.")
continue
}
// Before storing data for the new main chain block, set
// is_mainchain=false for any other block at this height.
height := int64(blockDataSummary.Height)
if err := p.db.setHeightToSideChain(height); err != nil {
log.Errorf("Failed to move blocks at height %d off of main chain: "+
"%v", height, err)
}
// If a block was cached at this height already, it was from the
// previous mainchain, so remove it.
if p.db.DB.BlockCache != nil {
p.db.DB.BlockCache.RemoveCachedBlockByHeight(height)
}
// Store this block's summary data and stake info.
if err := p.db.StoreBlockSummary(blockDataSummary); err != nil {
log.Errorf("Failed to store block summary data: %v", err)
}
if err := p.db.StoreStakeInfoExtended(stakeInfoSummaryExtended); err != nil {
log.Errorf("Failed to store stake info data: %v", err)
}
log.Infof("Promoted block %v (height %d) from side chain to main chain.",
blockDataSummary.Hash, height)
}
// Retrieve height and hash of the best block in the DB.
hash, height, err := p.db.GetBestBlockHeightHash()
if err != nil {
return 0, nil, fmt.Errorf("unable to retrieve best block: %v", err)
}
return int32(height), &hash, err
} | go | func (p *ChainMonitor) switchToSideChain(reorgData *txhelpers.ReorgData) (int32, *chainhash.Hash, error) {
if reorgData == nil || len(reorgData.NewChain) == 0 {
return 0, nil, fmt.Errorf("no side chain")
}
newChain := reorgData.NewChain
// newChain does not include the common ancestor.
commonAncestorHeight := int64(reorgData.NewChainHeight) - int64(len(newChain))
mainTip := p.db.GetBestBlockHeight()
if mainTip != int64(reorgData.OldChainHeight) {
log.Warnf("StakeDatabase height is %d, expected %d. Rewinding as "+
"needed to complete reorg from ancestor at %d", mainTip,
reorgData.OldChainHeight, commonAncestorHeight)
}
// Save blocks from previous side chain that is now the main chain.
log.Infof("Saving %d new blocks from previous side chain to sqlite.", len(newChain))
for i := range newChain {
// Get data by block hash, which requires the stakedb's PoolInfoCache to
// contain data for the side chain blocks already (guaranteed if stakedb
// block-connected ntfns are always handled before these).
blockDataSummary, stakeInfoSummaryExtended := p.collector.CollectAPITypes(&newChain[i])
if blockDataSummary == nil || stakeInfoSummaryExtended == nil {
log.Error("Failed to collect data for reorg.")
continue
}
// Before storing data for the new main chain block, set
// is_mainchain=false for any other block at this height.
height := int64(blockDataSummary.Height)
if err := p.db.setHeightToSideChain(height); err != nil {
log.Errorf("Failed to move blocks at height %d off of main chain: "+
"%v", height, err)
}
// If a block was cached at this height already, it was from the
// previous mainchain, so remove it.
if p.db.DB.BlockCache != nil {
p.db.DB.BlockCache.RemoveCachedBlockByHeight(height)
}
// Store this block's summary data and stake info.
if err := p.db.StoreBlockSummary(blockDataSummary); err != nil {
log.Errorf("Failed to store block summary data: %v", err)
}
if err := p.db.StoreStakeInfoExtended(stakeInfoSummaryExtended); err != nil {
log.Errorf("Failed to store stake info data: %v", err)
}
log.Infof("Promoted block %v (height %d) from side chain to main chain.",
blockDataSummary.Hash, height)
}
// Retrieve height and hash of the best block in the DB.
hash, height, err := p.db.GetBestBlockHeightHash()
if err != nil {
return 0, nil, fmt.Errorf("unable to retrieve best block: %v", err)
}
return int32(height), &hash, err
} | [
"func",
"(",
"p",
"*",
"ChainMonitor",
")",
"switchToSideChain",
"(",
"reorgData",
"*",
"txhelpers",
".",
"ReorgData",
")",
"(",
"int32",
",",
"*",
"chainhash",
".",
"Hash",
",",
"error",
")",
"{",
"if",
"reorgData",
"==",
"nil",
"||",
"len",
"(",
"reorgData",
".",
"NewChain",
")",
"==",
"0",
"{",
"return",
"0",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"newChain",
":=",
"reorgData",
".",
"NewChain",
"\n",
"// newChain does not include the common ancestor.",
"commonAncestorHeight",
":=",
"int64",
"(",
"reorgData",
".",
"NewChainHeight",
")",
"-",
"int64",
"(",
"len",
"(",
"newChain",
")",
")",
"\n\n",
"mainTip",
":=",
"p",
".",
"db",
".",
"GetBestBlockHeight",
"(",
")",
"\n",
"if",
"mainTip",
"!=",
"int64",
"(",
"reorgData",
".",
"OldChainHeight",
")",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"mainTip",
",",
"reorgData",
".",
"OldChainHeight",
",",
"commonAncestorHeight",
")",
"\n",
"}",
"\n\n",
"// Save blocks from previous side chain that is now the main chain.",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"len",
"(",
"newChain",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"newChain",
"{",
"// Get data by block hash, which requires the stakedb's PoolInfoCache to",
"// contain data for the side chain blocks already (guaranteed if stakedb",
"// block-connected ntfns are always handled before these).",
"blockDataSummary",
",",
"stakeInfoSummaryExtended",
":=",
"p",
".",
"collector",
".",
"CollectAPITypes",
"(",
"&",
"newChain",
"[",
"i",
"]",
")",
"\n",
"if",
"blockDataSummary",
"==",
"nil",
"||",
"stakeInfoSummaryExtended",
"==",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// Before storing data for the new main chain block, set",
"// is_mainchain=false for any other block at this height.",
"height",
":=",
"int64",
"(",
"blockDataSummary",
".",
"Height",
")",
"\n",
"if",
"err",
":=",
"p",
".",
"db",
".",
"setHeightToSideChain",
"(",
"height",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"height",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// If a block was cached at this height already, it was from the",
"// previous mainchain, so remove it.",
"if",
"p",
".",
"db",
".",
"DB",
".",
"BlockCache",
"!=",
"nil",
"{",
"p",
".",
"db",
".",
"DB",
".",
"BlockCache",
".",
"RemoveCachedBlockByHeight",
"(",
"height",
")",
"\n",
"}",
"\n\n",
"// Store this block's summary data and stake info.",
"if",
"err",
":=",
"p",
".",
"db",
".",
"StoreBlockSummary",
"(",
"blockDataSummary",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"p",
".",
"db",
".",
"StoreStakeInfoExtended",
"(",
"stakeInfoSummaryExtended",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"blockDataSummary",
".",
"Hash",
",",
"height",
")",
"\n",
"}",
"\n\n",
"// Retrieve height and hash of the best block in the DB.",
"hash",
",",
"height",
",",
"err",
":=",
"p",
".",
"db",
".",
"GetBestBlockHeightHash",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"int32",
"(",
"height",
")",
",",
"&",
"hash",
",",
"err",
"\n",
"}"
] | // switchToSideChain attempts to switch to a side chain by collecting data for
// each block in the side chain, and saving it as the new mainchain in sqlite. | [
"switchToSideChain",
"attempts",
"to",
"switch",
"to",
"a",
"side",
"chain",
"by",
"collecting",
"data",
"for",
"each",
"block",
"in",
"the",
"side",
"chain",
"and",
"saving",
"it",
"as",
"the",
"new",
"mainchain",
"in",
"sqlite",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrsqlite/chainmonitor.go#L46-L106 | train |
decred/dcrdata | db/dcrpg/queries.go | SetDBBestBlock | func SetDBBestBlock(db *sql.DB, hash string, height int64) error {
numRows, err := sqlExec(db, internal.SetMetaDBBestBlock,
"failed to update best block in meta table: ", height, hash)
if err != nil {
return err
}
if numRows != 1 {
return fmt.Errorf("failed to update exactly 1 row in meta table (%d)",
numRows)
}
return nil
} | go | func SetDBBestBlock(db *sql.DB, hash string, height int64) error {
numRows, err := sqlExec(db, internal.SetMetaDBBestBlock,
"failed to update best block in meta table: ", height, hash)
if err != nil {
return err
}
if numRows != 1 {
return fmt.Errorf("failed to update exactly 1 row in meta table (%d)",
numRows)
}
return nil
} | [
"func",
"SetDBBestBlock",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"hash",
"string",
",",
"height",
"int64",
")",
"error",
"{",
"numRows",
",",
"err",
":=",
"sqlExec",
"(",
"db",
",",
"internal",
".",
"SetMetaDBBestBlock",
",",
"\"",
"\"",
",",
"height",
",",
"hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"numRows",
"!=",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"numRows",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetDBBestBlock sets the best block hash and height in the meta table. | [
"SetDBBestBlock",
"sets",
"the",
"best",
"block",
"hash",
"and",
"height",
"in",
"the",
"meta",
"table",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L46-L57 | train |
decred/dcrdata | db/dcrpg/queries.go | closeRows | func closeRows(rows *sql.Rows) {
if e := rows.Close(); e != nil {
log.Errorf("Close of Query failed: %v", e)
}
} | go | func closeRows(rows *sql.Rows) {
if e := rows.Close(); e != nil {
log.Errorf("Close of Query failed: %v", e)
}
} | [
"func",
"closeRows",
"(",
"rows",
"*",
"sql",
".",
"Rows",
")",
"{",
"if",
"e",
":=",
"rows",
".",
"Close",
"(",
")",
";",
"e",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"e",
")",
"\n",
"}",
"\n",
"}"
] | // Maintenance functions
// closeRows closes the input sql.Rows, logging any error. | [
"Maintenance",
"functions",
"closeRows",
"closes",
"the",
"input",
"sql",
".",
"Rows",
"logging",
"any",
"error",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L99-L103 | train |
decred/dcrdata | db/dcrpg/queries.go | sqlExec | func sqlExec(db SqlExecutor, stmt, execErrPrefix string, args ...interface{}) (int64, error) {
res, err := db.Exec(stmt, args...)
if err != nil {
return 0, fmt.Errorf(execErrPrefix + " " + err.Error())
}
if res == nil {
return 0, nil
}
var N int64
N, err = res.RowsAffected()
if err != nil {
return 0, fmt.Errorf(`error in RowsAffected: %v`, err)
}
return N, err
} | go | func sqlExec(db SqlExecutor, stmt, execErrPrefix string, args ...interface{}) (int64, error) {
res, err := db.Exec(stmt, args...)
if err != nil {
return 0, fmt.Errorf(execErrPrefix + " " + err.Error())
}
if res == nil {
return 0, nil
}
var N int64
N, err = res.RowsAffected()
if err != nil {
return 0, fmt.Errorf(`error in RowsAffected: %v`, err)
}
return N, err
} | [
"func",
"sqlExec",
"(",
"db",
"SqlExecutor",
",",
"stmt",
",",
"execErrPrefix",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"int64",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"db",
".",
"Exec",
"(",
"stmt",
",",
"args",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"execErrPrefix",
"+",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"res",
"==",
"nil",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"N",
"int64",
"\n",
"N",
",",
"err",
"=",
"res",
".",
"RowsAffected",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`error in RowsAffected: %v`",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"N",
",",
"err",
"\n",
"}"
] | // sqlExec executes the SQL statement string with any optional arguments, and
// returns the nuber of rows affected. | [
"sqlExec",
"executes",
"the",
"SQL",
"statement",
"string",
"with",
"any",
"optional",
"arguments",
"and",
"returns",
"the",
"nuber",
"of",
"rows",
"affected",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L112-L127 | train |
decred/dcrdata | db/dcrpg/queries.go | sqlExecStmt | func sqlExecStmt(stmt *sql.Stmt, execErrPrefix string, args ...interface{}) (int64, error) {
res, err := stmt.Exec(args...)
if err != nil {
return 0, fmt.Errorf("%v %v", execErrPrefix, err)
}
if res == nil {
return 0, nil
}
var N int64
N, err = res.RowsAffected()
if err != nil {
return 0, fmt.Errorf(`error in RowsAffected: %v`, err)
}
return N, err
} | go | func sqlExecStmt(stmt *sql.Stmt, execErrPrefix string, args ...interface{}) (int64, error) {
res, err := stmt.Exec(args...)
if err != nil {
return 0, fmt.Errorf("%v %v", execErrPrefix, err)
}
if res == nil {
return 0, nil
}
var N int64
N, err = res.RowsAffected()
if err != nil {
return 0, fmt.Errorf(`error in RowsAffected: %v`, err)
}
return N, err
} | [
"func",
"sqlExecStmt",
"(",
"stmt",
"*",
"sql",
".",
"Stmt",
",",
"execErrPrefix",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"int64",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"stmt",
".",
"Exec",
"(",
"args",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"execErrPrefix",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"res",
"==",
"nil",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"N",
"int64",
"\n",
"N",
",",
"err",
"=",
"res",
".",
"RowsAffected",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`error in RowsAffected: %v`",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"N",
",",
"err",
"\n",
"}"
] | // sqlExecStmt executes the prepared SQL statement with any optional arguments,
// and returns the nuber of rows affected. | [
"sqlExecStmt",
"executes",
"the",
"prepared",
"SQL",
"statement",
"with",
"any",
"optional",
"arguments",
"and",
"returns",
"the",
"nuber",
"of",
"rows",
"affected",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L131-L146 | train |
decred/dcrdata | db/dcrpg/queries.go | ExistsIndex | func ExistsIndex(db *sql.DB, indexName string) (exists bool, err error) {
err = db.QueryRow(internal.IndexExists, indexName, "public").Scan(&exists)
if err == sql.ErrNoRows {
err = nil
}
return
} | go | func ExistsIndex(db *sql.DB, indexName string) (exists bool, err error) {
err = db.QueryRow(internal.IndexExists, indexName, "public").Scan(&exists)
if err == sql.ErrNoRows {
err = nil
}
return
} | [
"func",
"ExistsIndex",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"indexName",
"string",
")",
"(",
"exists",
"bool",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"internal",
".",
"IndexExists",
",",
"indexName",
",",
"\"",
"\"",
")",
".",
"Scan",
"(",
"&",
"exists",
")",
"\n",
"if",
"err",
"==",
"sql",
".",
"ErrNoRows",
"{",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // ExistsIndex checks if the specified index name exists. | [
"ExistsIndex",
"checks",
"if",
"the",
"specified",
"index",
"name",
"exists",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L149-L155 | train |
decred/dcrdata | db/dcrpg/queries.go | IsUniqueIndex | func IsUniqueIndex(db *sql.DB, indexName string) (isUnique bool, err error) {
err = db.QueryRow(internal.IndexIsUnique, indexName, "public").Scan(&isUnique)
return
} | go | func IsUniqueIndex(db *sql.DB, indexName string) (isUnique bool, err error) {
err = db.QueryRow(internal.IndexIsUnique, indexName, "public").Scan(&isUnique)
return
} | [
"func",
"IsUniqueIndex",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"indexName",
"string",
")",
"(",
"isUnique",
"bool",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"internal",
".",
"IndexIsUnique",
",",
"indexName",
",",
"\"",
"\"",
")",
".",
"Scan",
"(",
"&",
"isUnique",
")",
"\n",
"return",
"\n",
"}"
] | // IsUniqueIndex checks if the given index name is defined as UNIQUE. | [
"IsUniqueIndex",
"checks",
"if",
"the",
"given",
"index",
"name",
"is",
"defined",
"as",
"UNIQUE",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L158-L161 | train |
decred/dcrdata | db/dcrpg/queries.go | DeleteDuplicateVins | func DeleteDuplicateVins(db *sql.DB) (int64, error) {
execErrPrefix := "failed to delete duplicate vins: "
existsIdx, err := ExistsIndex(db, "uix_vin")
if err != nil {
return 0, err
} else if !existsIdx {
return sqlExec(db, internal.DeleteVinsDuplicateRows, execErrPrefix)
}
if isuniq, err := IsUniqueIndex(db, "uix_vin"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
return sqlExec(db, internal.DeleteVinsDuplicateRows, execErrPrefix)
} | go | func DeleteDuplicateVins(db *sql.DB) (int64, error) {
execErrPrefix := "failed to delete duplicate vins: "
existsIdx, err := ExistsIndex(db, "uix_vin")
if err != nil {
return 0, err
} else if !existsIdx {
return sqlExec(db, internal.DeleteVinsDuplicateRows, execErrPrefix)
}
if isuniq, err := IsUniqueIndex(db, "uix_vin"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
return sqlExec(db, internal.DeleteVinsDuplicateRows, execErrPrefix)
} | [
"func",
"DeleteDuplicateVins",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"int64",
",",
"error",
")",
"{",
"execErrPrefix",
":=",
"\"",
"\"",
"\n\n",
"existsIdx",
",",
"err",
":=",
"ExistsIndex",
"(",
"db",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"else",
"if",
"!",
"existsIdx",
"{",
"return",
"sqlExec",
"(",
"db",
",",
"internal",
".",
"DeleteVinsDuplicateRows",
",",
"execErrPrefix",
")",
"\n",
"}",
"\n\n",
"if",
"isuniq",
",",
"err",
":=",
"IsUniqueIndex",
"(",
"db",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"sql",
".",
"ErrNoRows",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"else",
"if",
"isuniq",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"sqlExec",
"(",
"db",
",",
"internal",
".",
"DeleteVinsDuplicateRows",
",",
"execErrPrefix",
")",
"\n",
"}"
] | // DeleteDuplicateVins deletes rows in vin with duplicate tx information,
// leaving the one row with the lowest id. | [
"DeleteDuplicateVins",
"deletes",
"rows",
"in",
"vin",
"with",
"duplicate",
"tx",
"information",
"leaving",
"the",
"one",
"row",
"with",
"the",
"lowest",
"id",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L165-L182 | train |
decred/dcrdata | db/dcrpg/queries.go | DeleteDuplicateVouts | func DeleteDuplicateVouts(db *sql.DB) (int64, error) {
execErrPrefix := "failed to delete duplicate vouts: "
existsIdx, err := ExistsIndex(db, "uix_vout_txhash_ind")
if err != nil {
return 0, err
} else if !existsIdx {
return sqlExec(db, internal.DeleteVoutDuplicateRows, execErrPrefix)
}
if isuniq, err := IsUniqueIndex(db, "uix_vout_txhash_ind"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
return sqlExec(db, internal.DeleteVoutDuplicateRows, execErrPrefix)
} | go | func DeleteDuplicateVouts(db *sql.DB) (int64, error) {
execErrPrefix := "failed to delete duplicate vouts: "
existsIdx, err := ExistsIndex(db, "uix_vout_txhash_ind")
if err != nil {
return 0, err
} else if !existsIdx {
return sqlExec(db, internal.DeleteVoutDuplicateRows, execErrPrefix)
}
if isuniq, err := IsUniqueIndex(db, "uix_vout_txhash_ind"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
return sqlExec(db, internal.DeleteVoutDuplicateRows, execErrPrefix)
} | [
"func",
"DeleteDuplicateVouts",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"int64",
",",
"error",
")",
"{",
"execErrPrefix",
":=",
"\"",
"\"",
"\n\n",
"existsIdx",
",",
"err",
":=",
"ExistsIndex",
"(",
"db",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"else",
"if",
"!",
"existsIdx",
"{",
"return",
"sqlExec",
"(",
"db",
",",
"internal",
".",
"DeleteVoutDuplicateRows",
",",
"execErrPrefix",
")",
"\n",
"}",
"\n\n",
"if",
"isuniq",
",",
"err",
":=",
"IsUniqueIndex",
"(",
"db",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"sql",
".",
"ErrNoRows",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"else",
"if",
"isuniq",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"sqlExec",
"(",
"db",
",",
"internal",
".",
"DeleteVoutDuplicateRows",
",",
"execErrPrefix",
")",
"\n",
"}"
] | // DeleteDuplicateVouts deletes rows in vouts with duplicate tx information,
// leaving the one row with the lowest id. | [
"DeleteDuplicateVouts",
"deletes",
"rows",
"in",
"vouts",
"with",
"duplicate",
"tx",
"information",
"leaving",
"the",
"one",
"row",
"with",
"the",
"lowest",
"id",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L186-L203 | train |
decred/dcrdata | db/dcrpg/queries.go | DeleteDuplicateTxns | func DeleteDuplicateTxns(db *sql.DB) (int64, error) {
execErrPrefix := "failed to delete duplicate transactions: "
existsIdx, err := ExistsIndex(db, "uix_tx_hashes")
if err != nil {
return 0, err
} else if !existsIdx {
return sqlExec(db, internal.DeleteTxDuplicateRows, execErrPrefix)
}
if isuniq, err := IsUniqueIndex(db, "uix_tx_hashes"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
return sqlExec(db, internal.DeleteTxDuplicateRows, execErrPrefix)
} | go | func DeleteDuplicateTxns(db *sql.DB) (int64, error) {
execErrPrefix := "failed to delete duplicate transactions: "
existsIdx, err := ExistsIndex(db, "uix_tx_hashes")
if err != nil {
return 0, err
} else if !existsIdx {
return sqlExec(db, internal.DeleteTxDuplicateRows, execErrPrefix)
}
if isuniq, err := IsUniqueIndex(db, "uix_tx_hashes"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
return sqlExec(db, internal.DeleteTxDuplicateRows, execErrPrefix)
} | [
"func",
"DeleteDuplicateTxns",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"int64",
",",
"error",
")",
"{",
"execErrPrefix",
":=",
"\"",
"\"",
"\n\n",
"existsIdx",
",",
"err",
":=",
"ExistsIndex",
"(",
"db",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"else",
"if",
"!",
"existsIdx",
"{",
"return",
"sqlExec",
"(",
"db",
",",
"internal",
".",
"DeleteTxDuplicateRows",
",",
"execErrPrefix",
")",
"\n",
"}",
"\n\n",
"if",
"isuniq",
",",
"err",
":=",
"IsUniqueIndex",
"(",
"db",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"sql",
".",
"ErrNoRows",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"else",
"if",
"isuniq",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"sqlExec",
"(",
"db",
",",
"internal",
".",
"DeleteTxDuplicateRows",
",",
"execErrPrefix",
")",
"\n",
"}"
] | // DeleteDuplicateTxns deletes rows in transactions with duplicate tx-block
// hashes, leaving the one row with the lowest id. | [
"DeleteDuplicateTxns",
"deletes",
"rows",
"in",
"transactions",
"with",
"duplicate",
"tx",
"-",
"block",
"hashes",
"leaving",
"the",
"one",
"row",
"with",
"the",
"lowest",
"id",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L207-L224 | train |
decred/dcrdata | db/dcrpg/queries.go | DeleteDuplicateTickets | func DeleteDuplicateTickets(db *sql.DB) (int64, error) {
if isuniq, err := IsUniqueIndex(db, "uix_ticket_hashes_index"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
execErrPrefix := "failed to delete duplicate tickets: "
return sqlExec(db, internal.DeleteTicketsDuplicateRows, execErrPrefix)
} | go | func DeleteDuplicateTickets(db *sql.DB) (int64, error) {
if isuniq, err := IsUniqueIndex(db, "uix_ticket_hashes_index"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
execErrPrefix := "failed to delete duplicate tickets: "
return sqlExec(db, internal.DeleteTicketsDuplicateRows, execErrPrefix)
} | [
"func",
"DeleteDuplicateTickets",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"isuniq",
",",
"err",
":=",
"IsUniqueIndex",
"(",
"db",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"sql",
".",
"ErrNoRows",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"else",
"if",
"isuniq",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"execErrPrefix",
":=",
"\"",
"\"",
"\n",
"return",
"sqlExec",
"(",
"db",
",",
"internal",
".",
"DeleteTicketsDuplicateRows",
",",
"execErrPrefix",
")",
"\n",
"}"
] | // DeleteDuplicateTickets deletes rows in tickets with duplicate tx-block
// hashes, leaving the one row with the lowest id. | [
"DeleteDuplicateTickets",
"deletes",
"rows",
"in",
"tickets",
"with",
"duplicate",
"tx",
"-",
"block",
"hashes",
"leaving",
"the",
"one",
"row",
"with",
"the",
"lowest",
"id",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L228-L236 | train |
decred/dcrdata | db/dcrpg/queries.go | DeleteDuplicateVotes | func DeleteDuplicateVotes(db *sql.DB) (int64, error) {
if isuniq, err := IsUniqueIndex(db, "uix_votes_hashes_index"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
execErrPrefix := "failed to delete duplicate votes: "
return sqlExec(db, internal.DeleteVotesDuplicateRows, execErrPrefix)
} | go | func DeleteDuplicateVotes(db *sql.DB) (int64, error) {
if isuniq, err := IsUniqueIndex(db, "uix_votes_hashes_index"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
execErrPrefix := "failed to delete duplicate votes: "
return sqlExec(db, internal.DeleteVotesDuplicateRows, execErrPrefix)
} | [
"func",
"DeleteDuplicateVotes",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"isuniq",
",",
"err",
":=",
"IsUniqueIndex",
"(",
"db",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"sql",
".",
"ErrNoRows",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"else",
"if",
"isuniq",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"execErrPrefix",
":=",
"\"",
"\"",
"\n",
"return",
"sqlExec",
"(",
"db",
",",
"internal",
".",
"DeleteVotesDuplicateRows",
",",
"execErrPrefix",
")",
"\n",
"}"
] | // DeleteDuplicateVotes deletes rows in votes with duplicate tx-block hashes,
// leaving the one row with the lowest id. | [
"DeleteDuplicateVotes",
"deletes",
"rows",
"in",
"votes",
"with",
"duplicate",
"tx",
"-",
"block",
"hashes",
"leaving",
"the",
"one",
"row",
"with",
"the",
"lowest",
"id",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L240-L248 | train |
decred/dcrdata | db/dcrpg/queries.go | DeleteDuplicateMisses | func DeleteDuplicateMisses(db *sql.DB) (int64, error) {
if isuniq, err := IsUniqueIndex(db, "uix_misses_hashes_index"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
execErrPrefix := "failed to delete duplicate misses: "
return sqlExec(db, internal.DeleteMissesDuplicateRows, execErrPrefix)
} | go | func DeleteDuplicateMisses(db *sql.DB) (int64, error) {
if isuniq, err := IsUniqueIndex(db, "uix_misses_hashes_index"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
execErrPrefix := "failed to delete duplicate misses: "
return sqlExec(db, internal.DeleteMissesDuplicateRows, execErrPrefix)
} | [
"func",
"DeleteDuplicateMisses",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"isuniq",
",",
"err",
":=",
"IsUniqueIndex",
"(",
"db",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"sql",
".",
"ErrNoRows",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"else",
"if",
"isuniq",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"execErrPrefix",
":=",
"\"",
"\"",
"\n",
"return",
"sqlExec",
"(",
"db",
",",
"internal",
".",
"DeleteMissesDuplicateRows",
",",
"execErrPrefix",
")",
"\n",
"}"
] | // DeleteDuplicateMisses deletes rows in misses with duplicate tx-block hashes,
// leaving the one row with the lowest id. | [
"DeleteDuplicateMisses",
"deletes",
"rows",
"in",
"misses",
"with",
"duplicate",
"tx",
"-",
"block",
"hashes",
"leaving",
"the",
"one",
"row",
"with",
"the",
"lowest",
"id",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L252-L260 | train |
decred/dcrdata | db/dcrpg/queries.go | DeleteDuplicateAgendas | func DeleteDuplicateAgendas(db *sql.DB) (int64, error) {
if isuniq, err := IsUniqueIndex(db, "uix_agendas_name"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
execErrPrefix := "failed to delete duplicate agendas: "
return sqlExec(db, internal.DeleteAgendasDuplicateRows, execErrPrefix)
} | go | func DeleteDuplicateAgendas(db *sql.DB) (int64, error) {
if isuniq, err := IsUniqueIndex(db, "uix_agendas_name"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
execErrPrefix := "failed to delete duplicate agendas: "
return sqlExec(db, internal.DeleteAgendasDuplicateRows, execErrPrefix)
} | [
"func",
"DeleteDuplicateAgendas",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"isuniq",
",",
"err",
":=",
"IsUniqueIndex",
"(",
"db",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"sql",
".",
"ErrNoRows",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"else",
"if",
"isuniq",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"execErrPrefix",
":=",
"\"",
"\"",
"\n",
"return",
"sqlExec",
"(",
"db",
",",
"internal",
".",
"DeleteAgendasDuplicateRows",
",",
"execErrPrefix",
")",
"\n",
"}"
] | // DeleteDuplicateAgendas deletes rows in agendas with duplicate names leaving
// the one row with the lowest id. | [
"DeleteDuplicateAgendas",
"deletes",
"rows",
"in",
"agendas",
"with",
"duplicate",
"names",
"leaving",
"the",
"one",
"row",
"with",
"the",
"lowest",
"id",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L264-L272 | train |
decred/dcrdata | db/dcrpg/queries.go | DeleteDuplicateAgendaVotes | func DeleteDuplicateAgendaVotes(db *sql.DB) (int64, error) {
if isuniq, err := IsUniqueIndex(db, "uix_agenda_votes"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
execErrPrefix := "failed to delete duplicate agenda_votes: "
return sqlExec(db, internal.DeleteAgendaVotesDuplicateRows, execErrPrefix)
} | go | func DeleteDuplicateAgendaVotes(db *sql.DB) (int64, error) {
if isuniq, err := IsUniqueIndex(db, "uix_agenda_votes"); err != nil && err != sql.ErrNoRows {
return 0, err
} else if isuniq {
return 0, nil
}
execErrPrefix := "failed to delete duplicate agenda_votes: "
return sqlExec(db, internal.DeleteAgendaVotesDuplicateRows, execErrPrefix)
} | [
"func",
"DeleteDuplicateAgendaVotes",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"isuniq",
",",
"err",
":=",
"IsUniqueIndex",
"(",
"db",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"sql",
".",
"ErrNoRows",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"else",
"if",
"isuniq",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"execErrPrefix",
":=",
"\"",
"\"",
"\n",
"return",
"sqlExec",
"(",
"db",
",",
"internal",
".",
"DeleteAgendaVotesDuplicateRows",
",",
"execErrPrefix",
")",
"\n",
"}"
] | // DeleteDuplicateAgendaVotes deletes rows in agenda_votes with duplicate
// votes-row-id and agendas-row-id leaving the one row with the lowest id. | [
"DeleteDuplicateAgendaVotes",
"deletes",
"rows",
"in",
"agenda_votes",
"with",
"duplicate",
"votes",
"-",
"row",
"-",
"id",
"and",
"agendas",
"-",
"row",
"-",
"id",
"leaving",
"the",
"one",
"row",
"with",
"the",
"lowest",
"id",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L276-L284 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveMissedVotesInBlock | func RetrieveMissedVotesInBlock(ctx context.Context, db *sql.DB, blockHash string) (ticketHashes []string, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectMissesInBlock, blockHash)
if err != nil {
return nil, err
}
defer closeRows(rows)
for rows.Next() {
var hash string
err = rows.Scan(&hash)
if err != nil {
break
}
ticketHashes = append(ticketHashes, hash)
}
return
} | go | func RetrieveMissedVotesInBlock(ctx context.Context, db *sql.DB, blockHash string) (ticketHashes []string, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectMissesInBlock, blockHash)
if err != nil {
return nil, err
}
defer closeRows(rows)
for rows.Next() {
var hash string
err = rows.Scan(&hash)
if err != nil {
break
}
ticketHashes = append(ticketHashes, hash)
}
return
} | [
"func",
"RetrieveMissedVotesInBlock",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"blockHash",
"string",
")",
"(",
"ticketHashes",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"var",
"rows",
"*",
"sql",
".",
"Rows",
"\n",
"rows",
",",
"err",
"=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectMissesInBlock",
",",
"blockHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"hash",
"string",
"\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"ticketHashes",
"=",
"append",
"(",
"ticketHashes",
",",
"hash",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // RetrieveMissedVotesInBlock gets a list of ticket hashes that were called to
// vote in the given block, but missed their vote. | [
"RetrieveMissedVotesInBlock",
"gets",
"a",
"list",
"of",
"ticket",
"hashes",
"that",
"were",
"called",
"to",
"vote",
"in",
"the",
"given",
"block",
"but",
"missed",
"their",
"vote",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L661-L680 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveMissesForTicket | func RetrieveMissesForTicket(ctx context.Context, db *sql.DB, ticketHash string) (blockHashes []string, blockHeights []int64, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectMissesForTicket, ticketHash)
if err != nil {
return nil, nil, err
}
defer closeRows(rows)
for rows.Next() {
var hash string
var height int64
err = rows.Scan(&height, &hash)
if err != nil {
break
}
blockHashes = append(blockHashes, hash)
blockHeights = append(blockHeights, height)
}
return
} | go | func RetrieveMissesForTicket(ctx context.Context, db *sql.DB, ticketHash string) (blockHashes []string, blockHeights []int64, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectMissesForTicket, ticketHash)
if err != nil {
return nil, nil, err
}
defer closeRows(rows)
for rows.Next() {
var hash string
var height int64
err = rows.Scan(&height, &hash)
if err != nil {
break
}
blockHashes = append(blockHashes, hash)
blockHeights = append(blockHeights, height)
}
return
} | [
"func",
"RetrieveMissesForTicket",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"ticketHash",
"string",
")",
"(",
"blockHashes",
"[",
"]",
"string",
",",
"blockHeights",
"[",
"]",
"int64",
",",
"err",
"error",
")",
"{",
"var",
"rows",
"*",
"sql",
".",
"Rows",
"\n",
"rows",
",",
"err",
"=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectMissesForTicket",
",",
"ticketHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"hash",
"string",
"\n",
"var",
"height",
"int64",
"\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"height",
",",
"&",
"hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"blockHashes",
"=",
"append",
"(",
"blockHashes",
",",
"hash",
")",
"\n",
"blockHeights",
"=",
"append",
"(",
"blockHeights",
",",
"height",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // RetrieveMissesForTicket gets all of the blocks in which the ticket was called
// to place a vote on the previous block. The previous block that would have
// been validated by the vote is not the block data that is returned. | [
"RetrieveMissesForTicket",
"gets",
"all",
"of",
"the",
"blocks",
"in",
"which",
"the",
"ticket",
"was",
"called",
"to",
"place",
"a",
"vote",
"on",
"the",
"previous",
"block",
".",
"The",
"previous",
"block",
"that",
"would",
"have",
"been",
"validated",
"by",
"the",
"vote",
"is",
"not",
"the",
"block",
"data",
"that",
"is",
"returned",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L685-L706 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveMissForTicket | func RetrieveMissForTicket(ctx context.Context, db *sql.DB, ticketHash string) (blockHash string, blockHeight int64, err error) {
err = db.QueryRowContext(ctx, internal.SelectMissesMainchainForTicket,
ticketHash).Scan(&blockHeight, &blockHash)
return
} | go | func RetrieveMissForTicket(ctx context.Context, db *sql.DB, ticketHash string) (blockHash string, blockHeight int64, err error) {
err = db.QueryRowContext(ctx, internal.SelectMissesMainchainForTicket,
ticketHash).Scan(&blockHeight, &blockHash)
return
} | [
"func",
"RetrieveMissForTicket",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"ticketHash",
"string",
")",
"(",
"blockHash",
"string",
",",
"blockHeight",
"int64",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectMissesMainchainForTicket",
",",
"ticketHash",
")",
".",
"Scan",
"(",
"&",
"blockHeight",
",",
"&",
"blockHash",
")",
"\n",
"return",
"\n",
"}"
] | // RetrieveMissForTicket gets the mainchain block in which the ticket was called
// to place a vote on the previous block. The previous block that would have
// been validated by the vote is not the block data that is returned. | [
"RetrieveMissForTicket",
"gets",
"the",
"mainchain",
"block",
"in",
"which",
"the",
"ticket",
"was",
"called",
"to",
"place",
"a",
"vote",
"on",
"the",
"previous",
"block",
".",
"The",
"previous",
"block",
"that",
"would",
"have",
"been",
"validated",
"by",
"the",
"vote",
"is",
"not",
"the",
"block",
"data",
"that",
"is",
"returned",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L711-L715 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveAllAgendas | func retrieveAllAgendas(db *sql.DB) (map[string]dbtypes.MileStone, error) {
rows, err := db.Query(internal.SelectAllAgendas)
if err != nil {
return nil, err
}
currentMilestones := make(map[string]dbtypes.MileStone)
defer closeRows(rows)
for rows.Next() {
var name string
var m dbtypes.MileStone
err = rows.Scan(&m.ID, &name, &m.Status, &m.VotingDone,
&m.Activated, &m.HardForked)
if err != nil {
break
}
currentMilestones[name] = m
}
return currentMilestones, err
} | go | func retrieveAllAgendas(db *sql.DB) (map[string]dbtypes.MileStone, error) {
rows, err := db.Query(internal.SelectAllAgendas)
if err != nil {
return nil, err
}
currentMilestones := make(map[string]dbtypes.MileStone)
defer closeRows(rows)
for rows.Next() {
var name string
var m dbtypes.MileStone
err = rows.Scan(&m.ID, &name, &m.Status, &m.VotingDone,
&m.Activated, &m.HardForked)
if err != nil {
break
}
currentMilestones[name] = m
}
return currentMilestones, err
} | [
"func",
"retrieveAllAgendas",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"map",
"[",
"string",
"]",
"dbtypes",
".",
"MileStone",
",",
"error",
")",
"{",
"rows",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"internal",
".",
"SelectAllAgendas",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"currentMilestones",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"dbtypes",
".",
"MileStone",
")",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"name",
"string",
"\n",
"var",
"m",
"dbtypes",
".",
"MileStone",
"\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"m",
".",
"ID",
",",
"&",
"name",
",",
"&",
"m",
".",
"Status",
",",
"&",
"m",
".",
"VotingDone",
",",
"&",
"m",
".",
"Activated",
",",
"&",
"m",
".",
"HardForked",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"currentMilestones",
"[",
"name",
"]",
"=",
"m",
"\n",
"}",
"\n\n",
"return",
"currentMilestones",
",",
"err",
"\n",
"}"
] | // retrieveAllAgendas returns all the current agendas in the db. | [
"retrieveAllAgendas",
"returns",
"all",
"the",
"current",
"agendas",
"in",
"the",
"db",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L718-L740 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveWindowBlocks | func retrieveWindowBlocks(ctx context.Context, db *sql.DB, windowSize int64, limit, offset uint64) ([]*dbtypes.BlocksGroupedInfo, error) {
rows, err := db.QueryContext(ctx, internal.SelectWindowsByLimit, windowSize, limit, offset)
if err != nil {
return nil, fmt.Errorf("retrieveWindowBlocks failed: error: %v", err)
}
defer closeRows(rows)
data := make([]*dbtypes.BlocksGroupedInfo, 0)
for rows.Next() {
var difficulty float64
var timestamp dbtypes.TimeDef
var startBlock, sbits, count int64
var blockSizes, votes, txs, revocations, tickets uint64
err = rows.Scan(&startBlock, &difficulty, &txs, &tickets, &votes,
&revocations, &blockSizes, &sbits, ×tamp, &count)
if err != nil {
return nil, err
}
endBlock := startBlock + windowSize
index := dbtypes.CalculateWindowIndex(endBlock, windowSize)
data = append(data, &dbtypes.BlocksGroupedInfo{
IndexVal: index, //window index at the endblock
EndBlock: endBlock,
Voters: votes,
Transactions: txs,
FreshStake: tickets,
Revocations: revocations,
BlocksCount: count,
TxCount: txs + tickets + revocations + votes,
Difficulty: difficulty,
TicketPrice: sbits,
Size: int64(blockSizes),
FormattedSize: humanize.Bytes(blockSizes),
StartTime: timestamp,
})
}
return data, nil
} | go | func retrieveWindowBlocks(ctx context.Context, db *sql.DB, windowSize int64, limit, offset uint64) ([]*dbtypes.BlocksGroupedInfo, error) {
rows, err := db.QueryContext(ctx, internal.SelectWindowsByLimit, windowSize, limit, offset)
if err != nil {
return nil, fmt.Errorf("retrieveWindowBlocks failed: error: %v", err)
}
defer closeRows(rows)
data := make([]*dbtypes.BlocksGroupedInfo, 0)
for rows.Next() {
var difficulty float64
var timestamp dbtypes.TimeDef
var startBlock, sbits, count int64
var blockSizes, votes, txs, revocations, tickets uint64
err = rows.Scan(&startBlock, &difficulty, &txs, &tickets, &votes,
&revocations, &blockSizes, &sbits, ×tamp, &count)
if err != nil {
return nil, err
}
endBlock := startBlock + windowSize
index := dbtypes.CalculateWindowIndex(endBlock, windowSize)
data = append(data, &dbtypes.BlocksGroupedInfo{
IndexVal: index, //window index at the endblock
EndBlock: endBlock,
Voters: votes,
Transactions: txs,
FreshStake: tickets,
Revocations: revocations,
BlocksCount: count,
TxCount: txs + tickets + revocations + votes,
Difficulty: difficulty,
TicketPrice: sbits,
Size: int64(blockSizes),
FormattedSize: humanize.Bytes(blockSizes),
StartTime: timestamp,
})
}
return data, nil
} | [
"func",
"retrieveWindowBlocks",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"windowSize",
"int64",
",",
"limit",
",",
"offset",
"uint64",
")",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"BlocksGroupedInfo",
",",
"error",
")",
"{",
"rows",
",",
"err",
":=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectWindowsByLimit",
",",
"windowSize",
",",
"limit",
",",
"offset",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"data",
":=",
"make",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"BlocksGroupedInfo",
",",
"0",
")",
"\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"difficulty",
"float64",
"\n",
"var",
"timestamp",
"dbtypes",
".",
"TimeDef",
"\n",
"var",
"startBlock",
",",
"sbits",
",",
"count",
"int64",
"\n",
"var",
"blockSizes",
",",
"votes",
",",
"txs",
",",
"revocations",
",",
"tickets",
"uint64",
"\n\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"startBlock",
",",
"&",
"difficulty",
",",
"&",
"txs",
",",
"&",
"tickets",
",",
"&",
"votes",
",",
"&",
"revocations",
",",
"&",
"blockSizes",
",",
"&",
"sbits",
",",
"&",
"timestamp",
",",
"&",
"count",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"endBlock",
":=",
"startBlock",
"+",
"windowSize",
"\n",
"index",
":=",
"dbtypes",
".",
"CalculateWindowIndex",
"(",
"endBlock",
",",
"windowSize",
")",
"\n\n",
"data",
"=",
"append",
"(",
"data",
",",
"&",
"dbtypes",
".",
"BlocksGroupedInfo",
"{",
"IndexVal",
":",
"index",
",",
"//window index at the endblock",
"EndBlock",
":",
"endBlock",
",",
"Voters",
":",
"votes",
",",
"Transactions",
":",
"txs",
",",
"FreshStake",
":",
"tickets",
",",
"Revocations",
":",
"revocations",
",",
"BlocksCount",
":",
"count",
",",
"TxCount",
":",
"txs",
"+",
"tickets",
"+",
"revocations",
"+",
"votes",
",",
"Difficulty",
":",
"difficulty",
",",
"TicketPrice",
":",
"sbits",
",",
"Size",
":",
"int64",
"(",
"blockSizes",
")",
",",
"FormattedSize",
":",
"humanize",
".",
"Bytes",
"(",
"blockSizes",
")",
",",
"StartTime",
":",
"timestamp",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"data",
",",
"nil",
"\n",
"}"
] | // retrieveWindowBlocks fetches chunks of windows using the limit and offset provided
// for a window size of chaincfg.Params.StakeDiffWindowSize. | [
"retrieveWindowBlocks",
"fetches",
"chunks",
"of",
"windows",
"using",
"the",
"limit",
"and",
"offset",
"provided",
"for",
"a",
"window",
"size",
"of",
"chaincfg",
".",
"Params",
".",
"StakeDiffWindowSize",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L804-L845 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveTimeBasedBlockListing | func retrieveTimeBasedBlockListing(ctx context.Context, db *sql.DB, timeInterval string,
limit, offset uint64) ([]*dbtypes.BlocksGroupedInfo, error) {
rows, err := db.QueryContext(ctx, internal.SelectBlocksTimeListingByLimit, timeInterval,
limit, offset)
if err != nil {
return nil, fmt.Errorf("retrieveTimeBasedBlockListing failed: error: %v", err)
}
defer closeRows(rows)
var data []*dbtypes.BlocksGroupedInfo
for rows.Next() {
var startTime, endTime, indexVal dbtypes.TimeDef
var txs, tickets, votes, revocations, blockSizes uint64
var blocksCount, endBlock int64
err = rows.Scan(&indexVal, &endBlock, &txs, &tickets, &votes,
&revocations, &blockSizes, &blocksCount, &startTime, &endTime)
if err != nil {
return nil, err
}
data = append(data, &dbtypes.BlocksGroupedInfo{
EndBlock: endBlock,
Voters: votes,
Transactions: txs,
FreshStake: tickets,
Revocations: revocations,
TxCount: txs + tickets + revocations + votes,
BlocksCount: blocksCount,
Size: int64(blockSizes),
FormattedSize: humanize.Bytes(blockSizes),
StartTime: startTime,
FormattedStartTime: startTime.Format("2006-01-02"),
EndTime: endTime,
FormattedEndTime: endTime.Format("2006-01-02"),
})
}
return data, nil
} | go | func retrieveTimeBasedBlockListing(ctx context.Context, db *sql.DB, timeInterval string,
limit, offset uint64) ([]*dbtypes.BlocksGroupedInfo, error) {
rows, err := db.QueryContext(ctx, internal.SelectBlocksTimeListingByLimit, timeInterval,
limit, offset)
if err != nil {
return nil, fmt.Errorf("retrieveTimeBasedBlockListing failed: error: %v", err)
}
defer closeRows(rows)
var data []*dbtypes.BlocksGroupedInfo
for rows.Next() {
var startTime, endTime, indexVal dbtypes.TimeDef
var txs, tickets, votes, revocations, blockSizes uint64
var blocksCount, endBlock int64
err = rows.Scan(&indexVal, &endBlock, &txs, &tickets, &votes,
&revocations, &blockSizes, &blocksCount, &startTime, &endTime)
if err != nil {
return nil, err
}
data = append(data, &dbtypes.BlocksGroupedInfo{
EndBlock: endBlock,
Voters: votes,
Transactions: txs,
FreshStake: tickets,
Revocations: revocations,
TxCount: txs + tickets + revocations + votes,
BlocksCount: blocksCount,
Size: int64(blockSizes),
FormattedSize: humanize.Bytes(blockSizes),
StartTime: startTime,
FormattedStartTime: startTime.Format("2006-01-02"),
EndTime: endTime,
FormattedEndTime: endTime.Format("2006-01-02"),
})
}
return data, nil
} | [
"func",
"retrieveTimeBasedBlockListing",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"timeInterval",
"string",
",",
"limit",
",",
"offset",
"uint64",
")",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"BlocksGroupedInfo",
",",
"error",
")",
"{",
"rows",
",",
"err",
":=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectBlocksTimeListingByLimit",
",",
"timeInterval",
",",
"limit",
",",
"offset",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"var",
"data",
"[",
"]",
"*",
"dbtypes",
".",
"BlocksGroupedInfo",
"\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"startTime",
",",
"endTime",
",",
"indexVal",
"dbtypes",
".",
"TimeDef",
"\n",
"var",
"txs",
",",
"tickets",
",",
"votes",
",",
"revocations",
",",
"blockSizes",
"uint64",
"\n",
"var",
"blocksCount",
",",
"endBlock",
"int64",
"\n\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"indexVal",
",",
"&",
"endBlock",
",",
"&",
"txs",
",",
"&",
"tickets",
",",
"&",
"votes",
",",
"&",
"revocations",
",",
"&",
"blockSizes",
",",
"&",
"blocksCount",
",",
"&",
"startTime",
",",
"&",
"endTime",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"data",
"=",
"append",
"(",
"data",
",",
"&",
"dbtypes",
".",
"BlocksGroupedInfo",
"{",
"EndBlock",
":",
"endBlock",
",",
"Voters",
":",
"votes",
",",
"Transactions",
":",
"txs",
",",
"FreshStake",
":",
"tickets",
",",
"Revocations",
":",
"revocations",
",",
"TxCount",
":",
"txs",
"+",
"tickets",
"+",
"revocations",
"+",
"votes",
",",
"BlocksCount",
":",
"blocksCount",
",",
"Size",
":",
"int64",
"(",
"blockSizes",
")",
",",
"FormattedSize",
":",
"humanize",
".",
"Bytes",
"(",
"blockSizes",
")",
",",
"StartTime",
":",
"startTime",
",",
"FormattedStartTime",
":",
"startTime",
".",
"Format",
"(",
"\"",
"\"",
")",
",",
"EndTime",
":",
"endTime",
",",
"FormattedEndTime",
":",
"endTime",
".",
"Format",
"(",
"\"",
"\"",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"data",
",",
"nil",
"\n",
"}"
] | // retrieveTimeBasedBlockListing fetches blocks in chunks based on their block
// time using the limit and offset provided. The time-based blocks groupings
// include but are not limited to day, week, month and year. | [
"retrieveTimeBasedBlockListing",
"fetches",
"blocks",
"in",
"chunks",
"based",
"on",
"their",
"block",
"time",
"using",
"the",
"limit",
"and",
"offset",
"provided",
".",
"The",
"time",
"-",
"based",
"blocks",
"groupings",
"include",
"but",
"are",
"not",
"limited",
"to",
"day",
"week",
"month",
"and",
"year",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L850-L888 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveUnspentTickets | func RetrieveUnspentTickets(ctx context.Context, db *sql.DB) (ids []uint64, hashes []string, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectUnspentTickets)
if err != nil {
return ids, hashes, err
}
defer closeRows(rows)
for rows.Next() {
var id uint64
var hash string
err = rows.Scan(&id, &hash)
if err != nil {
break
}
ids = append(ids, id)
hashes = append(hashes, hash)
}
return ids, hashes, err
} | go | func RetrieveUnspentTickets(ctx context.Context, db *sql.DB) (ids []uint64, hashes []string, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectUnspentTickets)
if err != nil {
return ids, hashes, err
}
defer closeRows(rows)
for rows.Next() {
var id uint64
var hash string
err = rows.Scan(&id, &hash)
if err != nil {
break
}
ids = append(ids, id)
hashes = append(hashes, hash)
}
return ids, hashes, err
} | [
"func",
"RetrieveUnspentTickets",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"ids",
"[",
"]",
"uint64",
",",
"hashes",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"var",
"rows",
"*",
"sql",
".",
"Rows",
"\n",
"rows",
",",
"err",
"=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectUnspentTickets",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ids",
",",
"hashes",
",",
"err",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"id",
"uint64",
"\n",
"var",
"hash",
"string",
"\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"id",
",",
"&",
"hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"ids",
"=",
"append",
"(",
"ids",
",",
"id",
")",
"\n",
"hashes",
"=",
"append",
"(",
"hashes",
",",
"hash",
")",
"\n",
"}",
"\n\n",
"return",
"ids",
",",
"hashes",
",",
"err",
"\n",
"}"
] | // RetrieveUnspentTickets gets all unspent tickets. | [
"RetrieveUnspentTickets",
"gets",
"all",
"unspent",
"tickets",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L891-L912 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveTicketStatusByHash | func RetrieveTicketStatusByHash(ctx context.Context, db *sql.DB, ticketHash string) (id uint64,
spendStatus dbtypes.TicketSpendType, poolStatus dbtypes.TicketPoolStatus, err error) {
err = db.QueryRowContext(ctx, internal.SelectTicketStatusByHash, ticketHash).
Scan(&id, &spendStatus, &poolStatus)
return
} | go | func RetrieveTicketStatusByHash(ctx context.Context, db *sql.DB, ticketHash string) (id uint64,
spendStatus dbtypes.TicketSpendType, poolStatus dbtypes.TicketPoolStatus, err error) {
err = db.QueryRowContext(ctx, internal.SelectTicketStatusByHash, ticketHash).
Scan(&id, &spendStatus, &poolStatus)
return
} | [
"func",
"RetrieveTicketStatusByHash",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"ticketHash",
"string",
")",
"(",
"id",
"uint64",
",",
"spendStatus",
"dbtypes",
".",
"TicketSpendType",
",",
"poolStatus",
"dbtypes",
".",
"TicketPoolStatus",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectTicketStatusByHash",
",",
"ticketHash",
")",
".",
"Scan",
"(",
"&",
"id",
",",
"&",
"spendStatus",
",",
"&",
"poolStatus",
")",
"\n",
"return",
"\n",
"}"
] | // RetrieveTicketStatusByHash gets the spend status and ticket pool status for
// the given ticket hash. | [
"RetrieveTicketStatusByHash",
"gets",
"the",
"spend",
"status",
"and",
"ticket",
"pool",
"status",
"for",
"the",
"given",
"ticket",
"hash",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L924-L929 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveTicketInfoByHash | func RetrieveTicketInfoByHash(ctx context.Context, db *sql.DB, ticketHash string) (spendStatus dbtypes.TicketSpendType,
poolStatus dbtypes.TicketPoolStatus, purchaseBlock, lotteryBlock *apitypes.TinyBlock, spendTxid string, err error) {
var dbid sql.NullInt64
var purchaseHash, spendHash string
var purchaseHeight, spendHeight uint32
err = db.QueryRowContext(ctx, internal.SelectTicketInfoByHash, ticketHash).
Scan(&purchaseHash, &purchaseHeight, &spendStatus, &poolStatus, &dbid)
if err != nil {
return
}
purchaseBlock = &apitypes.TinyBlock{
Hash: purchaseHash,
Height: purchaseHeight,
}
if spendStatus == dbtypes.TicketUnspent {
// ticket unspent. No further queries required.
return
}
if !dbid.Valid {
err = fmt.Errorf("Invalid spneding tx database ID")
return
}
err = db.QueryRowContext(ctx, internal.SelectTxnByDbID, dbid.Int64).
Scan(&spendHash, &spendHeight, &spendTxid)
if err != nil {
return
}
if spendStatus == dbtypes.TicketVoted {
lotteryBlock = &apitypes.TinyBlock{
Hash: spendHash,
Height: spendHeight,
}
}
return
} | go | func RetrieveTicketInfoByHash(ctx context.Context, db *sql.DB, ticketHash string) (spendStatus dbtypes.TicketSpendType,
poolStatus dbtypes.TicketPoolStatus, purchaseBlock, lotteryBlock *apitypes.TinyBlock, spendTxid string, err error) {
var dbid sql.NullInt64
var purchaseHash, spendHash string
var purchaseHeight, spendHeight uint32
err = db.QueryRowContext(ctx, internal.SelectTicketInfoByHash, ticketHash).
Scan(&purchaseHash, &purchaseHeight, &spendStatus, &poolStatus, &dbid)
if err != nil {
return
}
purchaseBlock = &apitypes.TinyBlock{
Hash: purchaseHash,
Height: purchaseHeight,
}
if spendStatus == dbtypes.TicketUnspent {
// ticket unspent. No further queries required.
return
}
if !dbid.Valid {
err = fmt.Errorf("Invalid spneding tx database ID")
return
}
err = db.QueryRowContext(ctx, internal.SelectTxnByDbID, dbid.Int64).
Scan(&spendHash, &spendHeight, &spendTxid)
if err != nil {
return
}
if spendStatus == dbtypes.TicketVoted {
lotteryBlock = &apitypes.TinyBlock{
Hash: spendHash,
Height: spendHeight,
}
}
return
} | [
"func",
"RetrieveTicketInfoByHash",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"ticketHash",
"string",
")",
"(",
"spendStatus",
"dbtypes",
".",
"TicketSpendType",
",",
"poolStatus",
"dbtypes",
".",
"TicketPoolStatus",
",",
"purchaseBlock",
",",
"lotteryBlock",
"*",
"apitypes",
".",
"TinyBlock",
",",
"spendTxid",
"string",
",",
"err",
"error",
")",
"{",
"var",
"dbid",
"sql",
".",
"NullInt64",
"\n",
"var",
"purchaseHash",
",",
"spendHash",
"string",
"\n",
"var",
"purchaseHeight",
",",
"spendHeight",
"uint32",
"\n",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectTicketInfoByHash",
",",
"ticketHash",
")",
".",
"Scan",
"(",
"&",
"purchaseHash",
",",
"&",
"purchaseHeight",
",",
"&",
"spendStatus",
",",
"&",
"poolStatus",
",",
"&",
"dbid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"purchaseBlock",
"=",
"&",
"apitypes",
".",
"TinyBlock",
"{",
"Hash",
":",
"purchaseHash",
",",
"Height",
":",
"purchaseHeight",
",",
"}",
"\n\n",
"if",
"spendStatus",
"==",
"dbtypes",
".",
"TicketUnspent",
"{",
"// ticket unspent. No further queries required.",
"return",
"\n",
"}",
"\n",
"if",
"!",
"dbid",
".",
"Valid",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectTxnByDbID",
",",
"dbid",
".",
"Int64",
")",
".",
"Scan",
"(",
"&",
"spendHash",
",",
"&",
"spendHeight",
",",
"&",
"spendTxid",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"spendStatus",
"==",
"dbtypes",
".",
"TicketVoted",
"{",
"lotteryBlock",
"=",
"&",
"apitypes",
".",
"TinyBlock",
"{",
"Hash",
":",
"spendHash",
",",
"Height",
":",
"spendHeight",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // RetrieveTicketInfoByHash retrieves the ticket spend and pool statuses as well
// as the purchase and spending block info and spending txid. | [
"RetrieveTicketInfoByHash",
"retrieves",
"the",
"ticket",
"spend",
"and",
"pool",
"statuses",
"as",
"well",
"as",
"the",
"purchase",
"and",
"spending",
"block",
"info",
"and",
"spending",
"txid",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L933-L973 | train |
decred/dcrdata | db/dcrpg/queries.go | SetPoolStatusForTicketsByHash | func SetPoolStatusForTicketsByHash(db *sql.DB, tickets []string,
poolStatuses []dbtypes.TicketPoolStatus) (int64, error) {
if len(tickets) == 0 {
return 0, nil
}
dbtx, err := db.Begin()
if err != nil {
return 0, fmt.Errorf(`unable to begin database transaction: %v`, err)
}
var stmt *sql.Stmt
stmt, err = dbtx.Prepare(internal.SetTicketPoolStatusForHash)
if err != nil {
// Already up a creek. Just return error from Prepare.
_ = dbtx.Rollback()
return 0, fmt.Errorf("tickets SELECT prepare failed: %v", err)
}
var totalTicketsUpdated int64
rowsAffected := make([]int64, len(tickets))
for i, ticket := range tickets {
rowsAffected[i], err = sqlExecStmt(stmt, "failed to set ticket pool status: ",
ticket, poolStatuses[i])
if err != nil {
_ = stmt.Close()
return 0, dbtx.Rollback()
}
totalTicketsUpdated += rowsAffected[i]
if rowsAffected[i] != 1 {
log.Warnf("Updated pool status for %d tickets, expecting just 1 (%s, %v)!",
rowsAffected[i], ticket, poolStatuses[i])
// TODO: go get the info to add it to the tickets table
}
}
_ = stmt.Close()
return totalTicketsUpdated, dbtx.Commit()
} | go | func SetPoolStatusForTicketsByHash(db *sql.DB, tickets []string,
poolStatuses []dbtypes.TicketPoolStatus) (int64, error) {
if len(tickets) == 0 {
return 0, nil
}
dbtx, err := db.Begin()
if err != nil {
return 0, fmt.Errorf(`unable to begin database transaction: %v`, err)
}
var stmt *sql.Stmt
stmt, err = dbtx.Prepare(internal.SetTicketPoolStatusForHash)
if err != nil {
// Already up a creek. Just return error from Prepare.
_ = dbtx.Rollback()
return 0, fmt.Errorf("tickets SELECT prepare failed: %v", err)
}
var totalTicketsUpdated int64
rowsAffected := make([]int64, len(tickets))
for i, ticket := range tickets {
rowsAffected[i], err = sqlExecStmt(stmt, "failed to set ticket pool status: ",
ticket, poolStatuses[i])
if err != nil {
_ = stmt.Close()
return 0, dbtx.Rollback()
}
totalTicketsUpdated += rowsAffected[i]
if rowsAffected[i] != 1 {
log.Warnf("Updated pool status for %d tickets, expecting just 1 (%s, %v)!",
rowsAffected[i], ticket, poolStatuses[i])
// TODO: go get the info to add it to the tickets table
}
}
_ = stmt.Close()
return totalTicketsUpdated, dbtx.Commit()
} | [
"func",
"SetPoolStatusForTicketsByHash",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"tickets",
"[",
"]",
"string",
",",
"poolStatuses",
"[",
"]",
"dbtypes",
".",
"TicketPoolStatus",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"len",
"(",
"tickets",
")",
"==",
"0",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"dbtx",
",",
"err",
":=",
"db",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`unable to begin database transaction: %v`",
",",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"stmt",
"*",
"sql",
".",
"Stmt",
"\n",
"stmt",
",",
"err",
"=",
"dbtx",
".",
"Prepare",
"(",
"internal",
".",
"SetTicketPoolStatusForHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Already up a creek. Just return error from Prepare.",
"_",
"=",
"dbtx",
".",
"Rollback",
"(",
")",
"\n",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"totalTicketsUpdated",
"int64",
"\n",
"rowsAffected",
":=",
"make",
"(",
"[",
"]",
"int64",
",",
"len",
"(",
"tickets",
")",
")",
"\n",
"for",
"i",
",",
"ticket",
":=",
"range",
"tickets",
"{",
"rowsAffected",
"[",
"i",
"]",
",",
"err",
"=",
"sqlExecStmt",
"(",
"stmt",
",",
"\"",
"\"",
",",
"ticket",
",",
"poolStatuses",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"_",
"=",
"stmt",
".",
"Close",
"(",
")",
"\n",
"return",
"0",
",",
"dbtx",
".",
"Rollback",
"(",
")",
"\n",
"}",
"\n",
"totalTicketsUpdated",
"+=",
"rowsAffected",
"[",
"i",
"]",
"\n",
"if",
"rowsAffected",
"[",
"i",
"]",
"!=",
"1",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"rowsAffected",
"[",
"i",
"]",
",",
"ticket",
",",
"poolStatuses",
"[",
"i",
"]",
")",
"\n",
"// TODO: go get the info to add it to the tickets table",
"}",
"\n",
"}",
"\n\n",
"_",
"=",
"stmt",
".",
"Close",
"(",
")",
"\n\n",
"return",
"totalTicketsUpdated",
",",
"dbtx",
".",
"Commit",
"(",
")",
"\n",
"}"
] | // SetPoolStatusForTicketsByHash sets the ticket pool status for the tickets
// specified by ticket purchase transaction hash. | [
"SetPoolStatusForTicketsByHash",
"sets",
"the",
"ticket",
"pool",
"status",
"for",
"the",
"tickets",
"specified",
"by",
"ticket",
"purchase",
"transaction",
"hash",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1152-L1190 | train |
decred/dcrdata | db/dcrpg/queries.go | setSpendingForTickets | func setSpendingForTickets(dbtx *sql.Tx, ticketDbIDs, spendDbIDs []uint64,
blockHeights []int64, spendTypes []dbtypes.TicketSpendType,
poolStatuses []dbtypes.TicketPoolStatus) error {
stmt, err := dbtx.Prepare(internal.SetTicketSpendingInfoForTicketDbID)
if err != nil {
return fmt.Errorf("tickets SELECT prepare failed: %v", err)
}
rowsAffected := make([]int64, len(ticketDbIDs))
for i, ticketDbID := range ticketDbIDs {
rowsAffected[i], err = sqlExecStmt(stmt, "failed to set ticket spending info: ",
ticketDbID, blockHeights[i], spendDbIDs[i], spendTypes[i], poolStatuses[i])
if err != nil {
_ = stmt.Close()
return err
}
if rowsAffected[i] != 1 {
log.Warnf("Updated spending info for %d tickets, expecting just 1!",
rowsAffected[i])
}
}
return stmt.Close()
} | go | func setSpendingForTickets(dbtx *sql.Tx, ticketDbIDs, spendDbIDs []uint64,
blockHeights []int64, spendTypes []dbtypes.TicketSpendType,
poolStatuses []dbtypes.TicketPoolStatus) error {
stmt, err := dbtx.Prepare(internal.SetTicketSpendingInfoForTicketDbID)
if err != nil {
return fmt.Errorf("tickets SELECT prepare failed: %v", err)
}
rowsAffected := make([]int64, len(ticketDbIDs))
for i, ticketDbID := range ticketDbIDs {
rowsAffected[i], err = sqlExecStmt(stmt, "failed to set ticket spending info: ",
ticketDbID, blockHeights[i], spendDbIDs[i], spendTypes[i], poolStatuses[i])
if err != nil {
_ = stmt.Close()
return err
}
if rowsAffected[i] != 1 {
log.Warnf("Updated spending info for %d tickets, expecting just 1!",
rowsAffected[i])
}
}
return stmt.Close()
} | [
"func",
"setSpendingForTickets",
"(",
"dbtx",
"*",
"sql",
".",
"Tx",
",",
"ticketDbIDs",
",",
"spendDbIDs",
"[",
"]",
"uint64",
",",
"blockHeights",
"[",
"]",
"int64",
",",
"spendTypes",
"[",
"]",
"dbtypes",
".",
"TicketSpendType",
",",
"poolStatuses",
"[",
"]",
"dbtypes",
".",
"TicketPoolStatus",
")",
"error",
"{",
"stmt",
",",
"err",
":=",
"dbtx",
".",
"Prepare",
"(",
"internal",
".",
"SetTicketSpendingInfoForTicketDbID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"rowsAffected",
":=",
"make",
"(",
"[",
"]",
"int64",
",",
"len",
"(",
"ticketDbIDs",
")",
")",
"\n",
"for",
"i",
",",
"ticketDbID",
":=",
"range",
"ticketDbIDs",
"{",
"rowsAffected",
"[",
"i",
"]",
",",
"err",
"=",
"sqlExecStmt",
"(",
"stmt",
",",
"\"",
"\"",
",",
"ticketDbID",
",",
"blockHeights",
"[",
"i",
"]",
",",
"spendDbIDs",
"[",
"i",
"]",
",",
"spendTypes",
"[",
"i",
"]",
",",
"poolStatuses",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"_",
"=",
"stmt",
".",
"Close",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"if",
"rowsAffected",
"[",
"i",
"]",
"!=",
"1",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"rowsAffected",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"stmt",
".",
"Close",
"(",
")",
"\n",
"}"
] | // setSpendingForTickets is identical to SetSpendingForTickets except it takes a
// database transaction that was begun and will be committed by the caller. | [
"setSpendingForTickets",
"is",
"identical",
"to",
"SetSpendingForTickets",
"except",
"it",
"takes",
"a",
"database",
"transaction",
"that",
"was",
"begun",
"and",
"will",
"be",
"committed",
"by",
"the",
"caller",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1234-L1257 | train |
decred/dcrdata | db/dcrpg/queries.go | InsertAddressRowsDbTx | func InsertAddressRowsDbTx(dbTx *sql.Tx, dbAs []*dbtypes.AddressRow, dupCheck, updateExistingRecords bool) ([]uint64, error) {
// Prepare the addresses row insert statement.
stmt, err := dbTx.Prepare(internal.MakeAddressRowInsertStatement(dupCheck, updateExistingRecords))
if err != nil {
return nil, err
}
// Insert each addresses table row, storing the inserted row IDs.
ids := make([]uint64, 0, len(dbAs))
for _, dbA := range dbAs {
var id uint64
err := stmt.QueryRow(dbA.Address, dbA.MatchingTxHash, dbA.TxHash,
dbA.TxVinVoutIndex, dbA.VinVoutDbID, dbA.Value, dbA.TxBlockTime,
dbA.IsFunding, dbA.ValidMainChain, dbA.TxType).Scan(&id)
if err != nil {
if err == sql.ErrNoRows {
log.Errorf("failed to insert/update an AddressRow: %v", *dbA)
continue
}
_ = stmt.Close() // try, but we want the QueryRow error back
return nil, err
}
ids = append(ids, id)
}
// Close prepared statement. Ignore errors as we'll Commit regardless.
_ = stmt.Close()
return ids, nil
} | go | func InsertAddressRowsDbTx(dbTx *sql.Tx, dbAs []*dbtypes.AddressRow, dupCheck, updateExistingRecords bool) ([]uint64, error) {
// Prepare the addresses row insert statement.
stmt, err := dbTx.Prepare(internal.MakeAddressRowInsertStatement(dupCheck, updateExistingRecords))
if err != nil {
return nil, err
}
// Insert each addresses table row, storing the inserted row IDs.
ids := make([]uint64, 0, len(dbAs))
for _, dbA := range dbAs {
var id uint64
err := stmt.QueryRow(dbA.Address, dbA.MatchingTxHash, dbA.TxHash,
dbA.TxVinVoutIndex, dbA.VinVoutDbID, dbA.Value, dbA.TxBlockTime,
dbA.IsFunding, dbA.ValidMainChain, dbA.TxType).Scan(&id)
if err != nil {
if err == sql.ErrNoRows {
log.Errorf("failed to insert/update an AddressRow: %v", *dbA)
continue
}
_ = stmt.Close() // try, but we want the QueryRow error back
return nil, err
}
ids = append(ids, id)
}
// Close prepared statement. Ignore errors as we'll Commit regardless.
_ = stmt.Close()
return ids, nil
} | [
"func",
"InsertAddressRowsDbTx",
"(",
"dbTx",
"*",
"sql",
".",
"Tx",
",",
"dbAs",
"[",
"]",
"*",
"dbtypes",
".",
"AddressRow",
",",
"dupCheck",
",",
"updateExistingRecords",
"bool",
")",
"(",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"// Prepare the addresses row insert statement.",
"stmt",
",",
"err",
":=",
"dbTx",
".",
"Prepare",
"(",
"internal",
".",
"MakeAddressRowInsertStatement",
"(",
"dupCheck",
",",
"updateExistingRecords",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Insert each addresses table row, storing the inserted row IDs.",
"ids",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"0",
",",
"len",
"(",
"dbAs",
")",
")",
"\n",
"for",
"_",
",",
"dbA",
":=",
"range",
"dbAs",
"{",
"var",
"id",
"uint64",
"\n",
"err",
":=",
"stmt",
".",
"QueryRow",
"(",
"dbA",
".",
"Address",
",",
"dbA",
".",
"MatchingTxHash",
",",
"dbA",
".",
"TxHash",
",",
"dbA",
".",
"TxVinVoutIndex",
",",
"dbA",
".",
"VinVoutDbID",
",",
"dbA",
".",
"Value",
",",
"dbA",
".",
"TxBlockTime",
",",
"dbA",
".",
"IsFunding",
",",
"dbA",
".",
"ValidMainChain",
",",
"dbA",
".",
"TxType",
")",
".",
"Scan",
"(",
"&",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"sql",
".",
"ErrNoRows",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"*",
"dbA",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"_",
"=",
"stmt",
".",
"Close",
"(",
")",
"// try, but we want the QueryRow error back",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ids",
"=",
"append",
"(",
"ids",
",",
"id",
")",
"\n",
"}",
"\n\n",
"// Close prepared statement. Ignore errors as we'll Commit regardless.",
"_",
"=",
"stmt",
".",
"Close",
"(",
")",
"\n\n",
"return",
"ids",
",",
"nil",
"\n",
"}"
] | // InsertAddressRowsDbTx is like InsertAddressRows, except that it takes a
// sql.Tx. The caller is required to Commit or Rollback the transaction
// depending on the returned error value. | [
"InsertAddressRowsDbTx",
"is",
"like",
"InsertAddressRows",
"except",
"that",
"it",
"takes",
"a",
"sql",
".",
"Tx",
".",
"The",
"caller",
"is",
"required",
"to",
"Commit",
"or",
"Rollback",
"the",
"transaction",
"depending",
"on",
"the",
"returned",
"error",
"value",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1275-L1304 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveAddressTxsCount | func retrieveAddressTxsCount(ctx context.Context, db *sql.DB, address, interval string) (count int64, err error) {
err = db.QueryRowContext(ctx, internal.MakeSelectAddressTimeGroupingCount(interval), address).Scan(&count)
return
} | go | func retrieveAddressTxsCount(ctx context.Context, db *sql.DB, address, interval string) (count int64, err error) {
err = db.QueryRowContext(ctx, internal.MakeSelectAddressTimeGroupingCount(interval), address).Scan(&count)
return
} | [
"func",
"retrieveAddressTxsCount",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"address",
",",
"interval",
"string",
")",
"(",
"count",
"int64",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"MakeSelectAddressTimeGroupingCount",
"(",
"interval",
")",
",",
"address",
")",
".",
"Scan",
"(",
"&",
"count",
")",
"\n",
"return",
"\n",
"}"
] | // retrieveAddressTxsCount return the number of record groups, where grouping is
// done by a specified time interval, for an address. | [
"retrieveAddressTxsCount",
"return",
"the",
"number",
"of",
"record",
"groups",
"where",
"grouping",
"is",
"done",
"by",
"a",
"specified",
"time",
"interval",
"for",
"an",
"address",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1338-L1341 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveAddressBalance | func RetrieveAddressBalance(ctx context.Context, db *sql.DB, address string) (balance *dbtypes.AddressBalance, err error) {
// Never return nil *AddressBalance.
balance = &dbtypes.AddressBalance{Address: address}
// The sql.Tx does not have a timeout, as the individial queries will.
var dbtx *sql.Tx
dbtx, err = db.BeginTx(context.Background(), &sql.TxOptions{
Isolation: sql.LevelDefault,
ReadOnly: true,
})
if err != nil {
err = fmt.Errorf("unable to begin database transaction: %v", err)
return
}
// Query for spent and unspent totals.
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectAddressSpentUnspentCountAndValue, address)
if err != nil {
if err == sql.ErrNoRows {
_ = dbtx.Commit()
return
}
if errRoll := dbtx.Rollback(); errRoll != nil {
log.Errorf("Rollback failed: %v", errRoll)
}
err = fmt.Errorf("failed to query spent and unspent amounts: %v", err)
return
}
var fromStake, toStake int64
for rows.Next() {
var count, totalValue int64
var noMatchingTx, isFunding, isRegular bool
err = rows.Scan(&isRegular, &count, &totalValue, &isFunding, &noMatchingTx)
if err != nil {
break
}
// Unspent == funding with no matching transaction
if isFunding && noMatchingTx {
balance.NumUnspent += count
balance.TotalUnspent += totalValue
}
// Spent == spending (but ensure a matching transaction is set)
if !isFunding {
if noMatchingTx {
log.Errorf("Found spending transactions with matching_tx_hash"+
" unset for %s!", address)
continue
}
balance.NumSpent += count
balance.TotalSpent += totalValue
if !isRegular {
toStake += totalValue
}
} else if !isRegular {
fromStake += totalValue
}
}
totalTransfer := balance.TotalSpent + balance.TotalUnspent
if totalTransfer > 0 {
balance.FromStake = float64(fromStake) / float64(totalTransfer)
}
if balance.TotalSpent > 0 {
balance.ToStake = float64(toStake) / float64(balance.TotalSpent)
}
closeRows(rows)
err = dbtx.Commit()
return
} | go | func RetrieveAddressBalance(ctx context.Context, db *sql.DB, address string) (balance *dbtypes.AddressBalance, err error) {
// Never return nil *AddressBalance.
balance = &dbtypes.AddressBalance{Address: address}
// The sql.Tx does not have a timeout, as the individial queries will.
var dbtx *sql.Tx
dbtx, err = db.BeginTx(context.Background(), &sql.TxOptions{
Isolation: sql.LevelDefault,
ReadOnly: true,
})
if err != nil {
err = fmt.Errorf("unable to begin database transaction: %v", err)
return
}
// Query for spent and unspent totals.
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectAddressSpentUnspentCountAndValue, address)
if err != nil {
if err == sql.ErrNoRows {
_ = dbtx.Commit()
return
}
if errRoll := dbtx.Rollback(); errRoll != nil {
log.Errorf("Rollback failed: %v", errRoll)
}
err = fmt.Errorf("failed to query spent and unspent amounts: %v", err)
return
}
var fromStake, toStake int64
for rows.Next() {
var count, totalValue int64
var noMatchingTx, isFunding, isRegular bool
err = rows.Scan(&isRegular, &count, &totalValue, &isFunding, &noMatchingTx)
if err != nil {
break
}
// Unspent == funding with no matching transaction
if isFunding && noMatchingTx {
balance.NumUnspent += count
balance.TotalUnspent += totalValue
}
// Spent == spending (but ensure a matching transaction is set)
if !isFunding {
if noMatchingTx {
log.Errorf("Found spending transactions with matching_tx_hash"+
" unset for %s!", address)
continue
}
balance.NumSpent += count
balance.TotalSpent += totalValue
if !isRegular {
toStake += totalValue
}
} else if !isRegular {
fromStake += totalValue
}
}
totalTransfer := balance.TotalSpent + balance.TotalUnspent
if totalTransfer > 0 {
balance.FromStake = float64(fromStake) / float64(totalTransfer)
}
if balance.TotalSpent > 0 {
balance.ToStake = float64(toStake) / float64(balance.TotalSpent)
}
closeRows(rows)
err = dbtx.Commit()
return
} | [
"func",
"RetrieveAddressBalance",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"address",
"string",
")",
"(",
"balance",
"*",
"dbtypes",
".",
"AddressBalance",
",",
"err",
"error",
")",
"{",
"// Never return nil *AddressBalance.",
"balance",
"=",
"&",
"dbtypes",
".",
"AddressBalance",
"{",
"Address",
":",
"address",
"}",
"\n\n",
"// The sql.Tx does not have a timeout, as the individial queries will.",
"var",
"dbtx",
"*",
"sql",
".",
"Tx",
"\n",
"dbtx",
",",
"err",
"=",
"db",
".",
"BeginTx",
"(",
"context",
".",
"Background",
"(",
")",
",",
"&",
"sql",
".",
"TxOptions",
"{",
"Isolation",
":",
"sql",
".",
"LevelDefault",
",",
"ReadOnly",
":",
"true",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Query for spent and unspent totals.",
"var",
"rows",
"*",
"sql",
".",
"Rows",
"\n",
"rows",
",",
"err",
"=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectAddressSpentUnspentCountAndValue",
",",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"sql",
".",
"ErrNoRows",
"{",
"_",
"=",
"dbtx",
".",
"Commit",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"errRoll",
":=",
"dbtx",
".",
"Rollback",
"(",
")",
";",
"errRoll",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"errRoll",
")",
"\n",
"}",
"\n",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"var",
"fromStake",
",",
"toStake",
"int64",
"\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"count",
",",
"totalValue",
"int64",
"\n",
"var",
"noMatchingTx",
",",
"isFunding",
",",
"isRegular",
"bool",
"\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"isRegular",
",",
"&",
"count",
",",
"&",
"totalValue",
",",
"&",
"isFunding",
",",
"&",
"noMatchingTx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"// Unspent == funding with no matching transaction",
"if",
"isFunding",
"&&",
"noMatchingTx",
"{",
"balance",
".",
"NumUnspent",
"+=",
"count",
"\n",
"balance",
".",
"TotalUnspent",
"+=",
"totalValue",
"\n",
"}",
"\n",
"// Spent == spending (but ensure a matching transaction is set)",
"if",
"!",
"isFunding",
"{",
"if",
"noMatchingTx",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"address",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"balance",
".",
"NumSpent",
"+=",
"count",
"\n",
"balance",
".",
"TotalSpent",
"+=",
"totalValue",
"\n",
"if",
"!",
"isRegular",
"{",
"toStake",
"+=",
"totalValue",
"\n",
"}",
"\n",
"}",
"else",
"if",
"!",
"isRegular",
"{",
"fromStake",
"+=",
"totalValue",
"\n",
"}",
"\n",
"}",
"\n\n",
"totalTransfer",
":=",
"balance",
".",
"TotalSpent",
"+",
"balance",
".",
"TotalUnspent",
"\n",
"if",
"totalTransfer",
">",
"0",
"{",
"balance",
".",
"FromStake",
"=",
"float64",
"(",
"fromStake",
")",
"/",
"float64",
"(",
"totalTransfer",
")",
"\n",
"}",
"\n",
"if",
"balance",
".",
"TotalSpent",
">",
"0",
"{",
"balance",
".",
"ToStake",
"=",
"float64",
"(",
"toStake",
")",
"/",
"float64",
"(",
"balance",
".",
"TotalSpent",
")",
"\n",
"}",
"\n",
"closeRows",
"(",
"rows",
")",
"\n\n",
"err",
"=",
"dbtx",
".",
"Commit",
"(",
")",
"\n",
"return",
"\n",
"}"
] | // RetrieveAddressBalance gets the numbers of spent and unspent outpoints
// for the given address, the total amounts spent and unspent, the number of
// distinct spending transactions, and the fraction spent to and received from
// stake-related trasnsactions. | [
"RetrieveAddressBalance",
"gets",
"the",
"numbers",
"of",
"spent",
"and",
"unspent",
"outpoints",
"for",
"the",
"given",
"address",
"the",
"total",
"amounts",
"spent",
"and",
"unspent",
"the",
"number",
"of",
"distinct",
"spending",
"transactions",
"and",
"the",
"fraction",
"spent",
"to",
"and",
"received",
"from",
"stake",
"-",
"related",
"trasnsactions",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1347-L1419 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveAllMainchainAddressTxns | func RetrieveAllMainchainAddressTxns(ctx context.Context, db *sql.DB, address string) ([]*dbtypes.AddressRow, error) {
rows, err := db.QueryContext(ctx, internal.SelectAddressAllMainchainByAddress, address)
if err != nil {
return nil, err
}
defer closeRows(rows)
return scanAddressQueryRows(rows, creditDebitQuery)
} | go | func RetrieveAllMainchainAddressTxns(ctx context.Context, db *sql.DB, address string) ([]*dbtypes.AddressRow, error) {
rows, err := db.QueryContext(ctx, internal.SelectAddressAllMainchainByAddress, address)
if err != nil {
return nil, err
}
defer closeRows(rows)
return scanAddressQueryRows(rows, creditDebitQuery)
} | [
"func",
"RetrieveAllMainchainAddressTxns",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"address",
"string",
")",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"AddressRow",
",",
"error",
")",
"{",
"rows",
",",
"err",
":=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectAddressAllMainchainByAddress",
",",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"return",
"scanAddressQueryRows",
"(",
"rows",
",",
"creditDebitQuery",
")",
"\n",
"}"
] | // RetrieveAllMainchainAddressTxns retrieves all non-merged and valid_mainchain
// rows of the address table pertaining to the given address. | [
"RetrieveAllMainchainAddressTxns",
"retrieves",
"all",
"non",
"-",
"merged",
"and",
"valid_mainchain",
"rows",
"of",
"the",
"address",
"table",
"pertaining",
"to",
"the",
"given",
"address",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1558-L1566 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveAllAddressMergedTxns | func RetrieveAllAddressMergedTxns(ctx context.Context, db *sql.DB, address string, onlyValidMainchain bool) ([]uint64, []*dbtypes.AddressRow, error) {
rows, err := db.QueryContext(ctx, internal.SelectAddressMergedViewAll, address)
if err != nil {
return nil, nil, err
}
defer closeRows(rows)
addr, err := scanAddressMergedRows(rows, address, mergedQuery,
onlyValidMainchain)
return nil, addr, err
} | go | func RetrieveAllAddressMergedTxns(ctx context.Context, db *sql.DB, address string, onlyValidMainchain bool) ([]uint64, []*dbtypes.AddressRow, error) {
rows, err := db.QueryContext(ctx, internal.SelectAddressMergedViewAll, address)
if err != nil {
return nil, nil, err
}
defer closeRows(rows)
addr, err := scanAddressMergedRows(rows, address, mergedQuery,
onlyValidMainchain)
return nil, addr, err
} | [
"func",
"RetrieveAllAddressMergedTxns",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"address",
"string",
",",
"onlyValidMainchain",
"bool",
")",
"(",
"[",
"]",
"uint64",
",",
"[",
"]",
"*",
"dbtypes",
".",
"AddressRow",
",",
"error",
")",
"{",
"rows",
",",
"err",
":=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectAddressMergedViewAll",
",",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"addr",
",",
"err",
":=",
"scanAddressMergedRows",
"(",
"rows",
",",
"address",
",",
"mergedQuery",
",",
"onlyValidMainchain",
")",
"\n",
"return",
"nil",
",",
"addr",
",",
"err",
"\n",
"}"
] | // RetrieveAllAddressMergedTxns retrieves all merged rows of the address table
// pertaining to the given address. Specify only valid_mainchain=true rows via
// the onlyValidMainchain argument. | [
"RetrieveAllAddressMergedTxns",
"retrieves",
"all",
"merged",
"rows",
"of",
"the",
"address",
"table",
"pertaining",
"to",
"the",
"given",
"address",
".",
"Specify",
"only",
"valid_mainchain",
"=",
"true",
"rows",
"via",
"the",
"onlyValidMainchain",
"argument",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1571-L1581 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveAddressMergedDebitTxns | func RetrieveAddressMergedDebitTxns(ctx context.Context, db *sql.DB, address string, N, offset int64) ([]*dbtypes.AddressRow, error) {
return retrieveAddressTxns(ctx, db, address, N, offset,
internal.SelectAddressMergedDebitView, mergedDebitQuery)
} | go | func RetrieveAddressMergedDebitTxns(ctx context.Context, db *sql.DB, address string, N, offset int64) ([]*dbtypes.AddressRow, error) {
return retrieveAddressTxns(ctx, db, address, N, offset,
internal.SelectAddressMergedDebitView, mergedDebitQuery)
} | [
"func",
"RetrieveAddressMergedDebitTxns",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"address",
"string",
",",
"N",
",",
"offset",
"int64",
")",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"AddressRow",
",",
"error",
")",
"{",
"return",
"retrieveAddressTxns",
"(",
"ctx",
",",
"db",
",",
"address",
",",
"N",
",",
"offset",
",",
"internal",
".",
"SelectAddressMergedDebitView",
",",
"mergedDebitQuery",
")",
"\n",
"}"
] | // Merged address transactions queries. | [
"Merged",
"address",
"transactions",
"queries",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1602-L1605 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveAddressTxns | func retrieveAddressTxns(ctx context.Context, db *sql.DB, address string, N, offset int64,
statement string, queryType int) ([]*dbtypes.AddressRow, error) {
rows, err := db.QueryContext(ctx, statement, address, N, offset)
if err != nil {
return nil, err
}
defer closeRows(rows)
switch queryType {
case mergedCreditQuery, mergedDebitQuery, mergedQuery:
onlyValidMainchain := true
addr, err := scanAddressMergedRows(rows, address, queryType, onlyValidMainchain)
return addr, err
default:
return scanAddressQueryRows(rows, queryType)
}
} | go | func retrieveAddressTxns(ctx context.Context, db *sql.DB, address string, N, offset int64,
statement string, queryType int) ([]*dbtypes.AddressRow, error) {
rows, err := db.QueryContext(ctx, statement, address, N, offset)
if err != nil {
return nil, err
}
defer closeRows(rows)
switch queryType {
case mergedCreditQuery, mergedDebitQuery, mergedQuery:
onlyValidMainchain := true
addr, err := scanAddressMergedRows(rows, address, queryType, onlyValidMainchain)
return addr, err
default:
return scanAddressQueryRows(rows, queryType)
}
} | [
"func",
"retrieveAddressTxns",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"address",
"string",
",",
"N",
",",
"offset",
"int64",
",",
"statement",
"string",
",",
"queryType",
"int",
")",
"(",
"[",
"]",
"*",
"dbtypes",
".",
"AddressRow",
",",
"error",
")",
"{",
"rows",
",",
"err",
":=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"statement",
",",
"address",
",",
"N",
",",
"offset",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"switch",
"queryType",
"{",
"case",
"mergedCreditQuery",
",",
"mergedDebitQuery",
",",
"mergedQuery",
":",
"onlyValidMainchain",
":=",
"true",
"\n",
"addr",
",",
"err",
":=",
"scanAddressMergedRows",
"(",
"rows",
",",
"address",
",",
"queryType",
",",
"onlyValidMainchain",
")",
"\n",
"return",
"addr",
",",
"err",
"\n",
"default",
":",
"return",
"scanAddressQueryRows",
"(",
"rows",
",",
"queryType",
")",
"\n",
"}",
"\n",
"}"
] | // Address transaction query helpers. | [
"Address",
"transaction",
"query",
"helpers",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1619-L1635 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveAddressIoCsv | func retrieveAddressIoCsv(ctx context.Context, db *sql.DB, address string) (csvRows [][]string, err error) {
dbRows, err := db.QueryContext(ctx, internal.SelectAddressCsvView, address)
if err != nil {
return nil, err
}
defer closeRows(dbRows)
var txHash, matchingTxHash, strValidMainchain, strDirection string
var validMainchain, isFunding bool
var value uint64
var ioIndex, txType int
var blockTime dbtypes.TimeDef
// header row
csvRows = append(csvRows, []string{"tx_hash", "direction", "io_index", "valid_mainchain", "value", "time_stamp", "tx_type", "matching_tx_hash"})
for dbRows.Next() {
err = dbRows.Scan(&txHash, &validMainchain, &matchingTxHash,
&value, &blockTime, &isFunding, &ioIndex, &txType)
if err != nil {
return nil, fmt.Errorf("retrieveAddressIoCsv Scan error: %v", err)
}
if validMainchain {
strValidMainchain = "1"
} else {
strValidMainchain = "0"
}
if isFunding {
strDirection = "1"
} else {
strDirection = "-1"
}
csvRows = append(csvRows, []string{
txHash,
strDirection,
strconv.Itoa(ioIndex),
strValidMainchain,
strconv.FormatFloat(dcrutil.Amount(value).ToCoin(), 'f', -1, 64),
strconv.FormatInt(blockTime.UNIX(), 10),
txhelpers.TxTypeToString(txType),
matchingTxHash,
})
}
return
} | go | func retrieveAddressIoCsv(ctx context.Context, db *sql.DB, address string) (csvRows [][]string, err error) {
dbRows, err := db.QueryContext(ctx, internal.SelectAddressCsvView, address)
if err != nil {
return nil, err
}
defer closeRows(dbRows)
var txHash, matchingTxHash, strValidMainchain, strDirection string
var validMainchain, isFunding bool
var value uint64
var ioIndex, txType int
var blockTime dbtypes.TimeDef
// header row
csvRows = append(csvRows, []string{"tx_hash", "direction", "io_index", "valid_mainchain", "value", "time_stamp", "tx_type", "matching_tx_hash"})
for dbRows.Next() {
err = dbRows.Scan(&txHash, &validMainchain, &matchingTxHash,
&value, &blockTime, &isFunding, &ioIndex, &txType)
if err != nil {
return nil, fmt.Errorf("retrieveAddressIoCsv Scan error: %v", err)
}
if validMainchain {
strValidMainchain = "1"
} else {
strValidMainchain = "0"
}
if isFunding {
strDirection = "1"
} else {
strDirection = "-1"
}
csvRows = append(csvRows, []string{
txHash,
strDirection,
strconv.Itoa(ioIndex),
strValidMainchain,
strconv.FormatFloat(dcrutil.Amount(value).ToCoin(), 'f', -1, 64),
strconv.FormatInt(blockTime.UNIX(), 10),
txhelpers.TxTypeToString(txType),
matchingTxHash,
})
}
return
} | [
"func",
"retrieveAddressIoCsv",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"address",
"string",
")",
"(",
"csvRows",
"[",
"]",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"dbRows",
",",
"err",
":=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectAddressCsvView",
",",
"address",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"dbRows",
")",
"\n\n",
"var",
"txHash",
",",
"matchingTxHash",
",",
"strValidMainchain",
",",
"strDirection",
"string",
"\n",
"var",
"validMainchain",
",",
"isFunding",
"bool",
"\n",
"var",
"value",
"uint64",
"\n",
"var",
"ioIndex",
",",
"txType",
"int",
"\n",
"var",
"blockTime",
"dbtypes",
".",
"TimeDef",
"\n\n",
"// header row",
"csvRows",
"=",
"append",
"(",
"csvRows",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
")",
"\n\n",
"for",
"dbRows",
".",
"Next",
"(",
")",
"{",
"err",
"=",
"dbRows",
".",
"Scan",
"(",
"&",
"txHash",
",",
"&",
"validMainchain",
",",
"&",
"matchingTxHash",
",",
"&",
"value",
",",
"&",
"blockTime",
",",
"&",
"isFunding",
",",
"&",
"ioIndex",
",",
"&",
"txType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"validMainchain",
"{",
"strValidMainchain",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"strValidMainchain",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"isFunding",
"{",
"strDirection",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"strDirection",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"csvRows",
"=",
"append",
"(",
"csvRows",
",",
"[",
"]",
"string",
"{",
"txHash",
",",
"strDirection",
",",
"strconv",
".",
"Itoa",
"(",
"ioIndex",
")",
",",
"strValidMainchain",
",",
"strconv",
".",
"FormatFloat",
"(",
"dcrutil",
".",
"Amount",
"(",
"value",
")",
".",
"ToCoin",
"(",
")",
",",
"'f'",
",",
"-",
"1",
",",
"64",
")",
",",
"strconv",
".",
"FormatInt",
"(",
"blockTime",
".",
"UNIX",
"(",
")",
",",
"10",
")",
",",
"txhelpers",
".",
"TxTypeToString",
"(",
"txType",
")",
",",
"matchingTxHash",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // retrieveAddressIoCsv grabs rows for an address and formats them as a 2-D
// array of strings for CSV-formatting. | [
"retrieveAddressIoCsv",
"grabs",
"rows",
"for",
"an",
"address",
"and",
"formats",
"them",
"as",
"a",
"2",
"-",
"D",
"array",
"of",
"strings",
"for",
"CSV",
"-",
"formatting",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1639-L1687 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveOldestTxBlockTime | func retrieveOldestTxBlockTime(ctx context.Context, db *sql.DB, addr string) (blockTime dbtypes.TimeDef, err error) {
err = db.QueryRowContext(ctx, internal.SelectAddressOldestTxBlockTime, addr).Scan(&blockTime)
return
} | go | func retrieveOldestTxBlockTime(ctx context.Context, db *sql.DB, addr string) (blockTime dbtypes.TimeDef, err error) {
err = db.QueryRowContext(ctx, internal.SelectAddressOldestTxBlockTime, addr).Scan(&blockTime)
return
} | [
"func",
"retrieveOldestTxBlockTime",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"addr",
"string",
")",
"(",
"blockTime",
"dbtypes",
".",
"TimeDef",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectAddressOldestTxBlockTime",
",",
"addr",
")",
".",
"Scan",
"(",
"&",
"blockTime",
")",
"\n",
"return",
"\n",
"}"
] | // retrieveOldestTxBlockTime helps choose the most appropriate address page
// graph grouping to load by default depending on when the first transaction to
// the specific address was made. | [
"retrieveOldestTxBlockTime",
"helps",
"choose",
"the",
"most",
"appropriate",
"address",
"page",
"graph",
"grouping",
"to",
"load",
"by",
"default",
"depending",
"on",
"when",
"the",
"first",
"transaction",
"to",
"the",
"specific",
"address",
"was",
"made",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1803-L1806 | train |
decred/dcrdata | db/dcrpg/queries.go | InsertVinsStmt | func InsertVinsStmt(stmt *sql.Stmt, dbVins dbtypes.VinTxPropertyARRAY, checked bool, doUpsert bool) ([]uint64, error) {
// TODO/Question: Should we skip inserting coinbase txns, which have same PrevTxHash?
ids := make([]uint64, 0, len(dbVins))
for _, vin := range dbVins {
var id uint64
err := stmt.QueryRow(vin.TxID, vin.TxIndex, vin.TxTree,
vin.PrevTxHash, vin.PrevTxIndex, vin.PrevTxTree,
vin.ValueIn, vin.IsValid, vin.IsMainchain, vin.Time, vin.TxType).Scan(&id)
if err != nil {
return ids, fmt.Errorf("InsertVins INSERT exec failed: %v", err)
}
ids = append(ids, id)
}
return ids, nil
} | go | func InsertVinsStmt(stmt *sql.Stmt, dbVins dbtypes.VinTxPropertyARRAY, checked bool, doUpsert bool) ([]uint64, error) {
// TODO/Question: Should we skip inserting coinbase txns, which have same PrevTxHash?
ids := make([]uint64, 0, len(dbVins))
for _, vin := range dbVins {
var id uint64
err := stmt.QueryRow(vin.TxID, vin.TxIndex, vin.TxTree,
vin.PrevTxHash, vin.PrevTxIndex, vin.PrevTxTree,
vin.ValueIn, vin.IsValid, vin.IsMainchain, vin.Time, vin.TxType).Scan(&id)
if err != nil {
return ids, fmt.Errorf("InsertVins INSERT exec failed: %v", err)
}
ids = append(ids, id)
}
return ids, nil
} | [
"func",
"InsertVinsStmt",
"(",
"stmt",
"*",
"sql",
".",
"Stmt",
",",
"dbVins",
"dbtypes",
".",
"VinTxPropertyARRAY",
",",
"checked",
"bool",
",",
"doUpsert",
"bool",
")",
"(",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"// TODO/Question: Should we skip inserting coinbase txns, which have same PrevTxHash?",
"ids",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"0",
",",
"len",
"(",
"dbVins",
")",
")",
"\n",
"for",
"_",
",",
"vin",
":=",
"range",
"dbVins",
"{",
"var",
"id",
"uint64",
"\n",
"err",
":=",
"stmt",
".",
"QueryRow",
"(",
"vin",
".",
"TxID",
",",
"vin",
".",
"TxIndex",
",",
"vin",
".",
"TxTree",
",",
"vin",
".",
"PrevTxHash",
",",
"vin",
".",
"PrevTxIndex",
",",
"vin",
".",
"PrevTxTree",
",",
"vin",
".",
"ValueIn",
",",
"vin",
".",
"IsValid",
",",
"vin",
".",
"IsMainchain",
",",
"vin",
".",
"Time",
",",
"vin",
".",
"TxType",
")",
".",
"Scan",
"(",
"&",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ids",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"ids",
"=",
"append",
"(",
"ids",
",",
"id",
")",
"\n",
"}",
"\n\n",
"return",
"ids",
",",
"nil",
"\n",
"}"
] | // InsertVinsStmt is like InsertVins, except that it takes a sql.Stmt. The
// caller is required to Close the transaction. | [
"InsertVinsStmt",
"is",
"like",
"InsertVins",
"except",
"that",
"it",
"takes",
"a",
"sql",
".",
"Stmt",
".",
"The",
"caller",
"is",
"required",
"to",
"Close",
"the",
"transaction",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1899-L1914 | train |
decred/dcrdata | db/dcrpg/queries.go | InsertVinsDbTxn | func InsertVinsDbTxn(dbTx *sql.Tx, dbVins dbtypes.VinTxPropertyARRAY, checked bool, doUpsert bool) ([]uint64, error) {
stmt, err := dbTx.Prepare(internal.MakeVinInsertStatement(checked, doUpsert))
if err != nil {
return nil, err
}
// TODO/Question: Should we skip inserting coinbase txns, which have same PrevTxHash?
ids, err := InsertVinsStmt(stmt, dbVins, checked, doUpsert)
errClose := stmt.Close()
if err != nil {
return nil, err
}
if errClose != nil {
return nil, err
}
return ids, nil
} | go | func InsertVinsDbTxn(dbTx *sql.Tx, dbVins dbtypes.VinTxPropertyARRAY, checked bool, doUpsert bool) ([]uint64, error) {
stmt, err := dbTx.Prepare(internal.MakeVinInsertStatement(checked, doUpsert))
if err != nil {
return nil, err
}
// TODO/Question: Should we skip inserting coinbase txns, which have same PrevTxHash?
ids, err := InsertVinsStmt(stmt, dbVins, checked, doUpsert)
errClose := stmt.Close()
if err != nil {
return nil, err
}
if errClose != nil {
return nil, err
}
return ids, nil
} | [
"func",
"InsertVinsDbTxn",
"(",
"dbTx",
"*",
"sql",
".",
"Tx",
",",
"dbVins",
"dbtypes",
".",
"VinTxPropertyARRAY",
",",
"checked",
"bool",
",",
"doUpsert",
"bool",
")",
"(",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"stmt",
",",
"err",
":=",
"dbTx",
".",
"Prepare",
"(",
"internal",
".",
"MakeVinInsertStatement",
"(",
"checked",
",",
"doUpsert",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// TODO/Question: Should we skip inserting coinbase txns, which have same PrevTxHash?",
"ids",
",",
"err",
":=",
"InsertVinsStmt",
"(",
"stmt",
",",
"dbVins",
",",
"checked",
",",
"doUpsert",
")",
"\n",
"errClose",
":=",
"stmt",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"errClose",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ids",
",",
"nil",
"\n",
"}"
] | // InsertVinsDbTxn is like InsertVins, except that it takes a sql.Tx. The caller
// is required to Commit or Rollback the transaction depending on the returned
// error value. | [
"InsertVinsDbTxn",
"is",
"like",
"InsertVins",
"except",
"that",
"it",
"takes",
"a",
"sql",
".",
"Tx",
".",
"The",
"caller",
"is",
"required",
"to",
"Commit",
"or",
"Rollback",
"the",
"transaction",
"depending",
"on",
"the",
"returned",
"error",
"value",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1919-L1936 | train |
decred/dcrdata | db/dcrpg/queries.go | InsertVins | func InsertVins(db *sql.DB, dbVins dbtypes.VinTxPropertyARRAY, checked bool, updateOnConflict ...bool) ([]uint64, error) {
dbtx, err := db.Begin()
if err != nil {
return nil, fmt.Errorf("unable to begin database transaction: %v", err)
}
doUpsert := true
if len(updateOnConflict) > 0 {
doUpsert = updateOnConflict[0]
}
ids, err := InsertVinsDbTxn(dbtx, dbVins, checked, doUpsert)
if err != nil {
_ = dbtx.Rollback() // try, but we want the Prepare error back
return nil, err
}
return ids, dbtx.Commit()
} | go | func InsertVins(db *sql.DB, dbVins dbtypes.VinTxPropertyARRAY, checked bool, updateOnConflict ...bool) ([]uint64, error) {
dbtx, err := db.Begin()
if err != nil {
return nil, fmt.Errorf("unable to begin database transaction: %v", err)
}
doUpsert := true
if len(updateOnConflict) > 0 {
doUpsert = updateOnConflict[0]
}
ids, err := InsertVinsDbTxn(dbtx, dbVins, checked, doUpsert)
if err != nil {
_ = dbtx.Rollback() // try, but we want the Prepare error back
return nil, err
}
return ids, dbtx.Commit()
} | [
"func",
"InsertVins",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"dbVins",
"dbtypes",
".",
"VinTxPropertyARRAY",
",",
"checked",
"bool",
",",
"updateOnConflict",
"...",
"bool",
")",
"(",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"dbtx",
",",
"err",
":=",
"db",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"doUpsert",
":=",
"true",
"\n",
"if",
"len",
"(",
"updateOnConflict",
")",
">",
"0",
"{",
"doUpsert",
"=",
"updateOnConflict",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"ids",
",",
"err",
":=",
"InsertVinsDbTxn",
"(",
"dbtx",
",",
"dbVins",
",",
"checked",
",",
"doUpsert",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"_",
"=",
"dbtx",
".",
"Rollback",
"(",
")",
"// try, but we want the Prepare error back",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ids",
",",
"dbtx",
".",
"Commit",
"(",
")",
"\n",
"}"
] | // InsertVins is like InsertVin, except that it operates on a slice of vin data. | [
"InsertVins",
"is",
"like",
"InsertVin",
"except",
"that",
"it",
"operates",
"on",
"a",
"slice",
"of",
"vin",
"data",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1939-L1957 | train |
decred/dcrdata | db/dcrpg/queries.go | InsertVoutsStmt | func InsertVoutsStmt(stmt *sql.Stmt, dbVouts []*dbtypes.Vout, checked bool, doUpsert bool) ([]uint64, []dbtypes.AddressRow, error) {
addressRows := make([]dbtypes.AddressRow, 0, len(dbVouts)) // may grow with multisig
ids := make([]uint64, 0, len(dbVouts))
for _, vout := range dbVouts {
var id uint64
err := stmt.QueryRow(
vout.TxHash, vout.TxIndex, vout.TxTree, vout.Value, vout.Version,
vout.ScriptPubKey, vout.ScriptPubKeyData.ReqSigs,
vout.ScriptPubKeyData.Type,
pq.Array(vout.ScriptPubKeyData.Addresses)).Scan(&id)
if err != nil {
if err == sql.ErrNoRows {
continue
}
return nil, nil, err
}
for _, addr := range vout.ScriptPubKeyData.Addresses {
addressRows = append(addressRows, dbtypes.AddressRow{
Address: addr,
TxHash: vout.TxHash,
TxVinVoutIndex: vout.TxIndex,
VinVoutDbID: id,
TxType: vout.TxType,
Value: vout.Value,
// Not set here are: ValidMainchain, MatchingTxHash, IsFunding,
// AtomsCredit, AtomsDebit, and TxBlockTime.
})
}
ids = append(ids, id)
}
return ids, addressRows, nil
} | go | func InsertVoutsStmt(stmt *sql.Stmt, dbVouts []*dbtypes.Vout, checked bool, doUpsert bool) ([]uint64, []dbtypes.AddressRow, error) {
addressRows := make([]dbtypes.AddressRow, 0, len(dbVouts)) // may grow with multisig
ids := make([]uint64, 0, len(dbVouts))
for _, vout := range dbVouts {
var id uint64
err := stmt.QueryRow(
vout.TxHash, vout.TxIndex, vout.TxTree, vout.Value, vout.Version,
vout.ScriptPubKey, vout.ScriptPubKeyData.ReqSigs,
vout.ScriptPubKeyData.Type,
pq.Array(vout.ScriptPubKeyData.Addresses)).Scan(&id)
if err != nil {
if err == sql.ErrNoRows {
continue
}
return nil, nil, err
}
for _, addr := range vout.ScriptPubKeyData.Addresses {
addressRows = append(addressRows, dbtypes.AddressRow{
Address: addr,
TxHash: vout.TxHash,
TxVinVoutIndex: vout.TxIndex,
VinVoutDbID: id,
TxType: vout.TxType,
Value: vout.Value,
// Not set here are: ValidMainchain, MatchingTxHash, IsFunding,
// AtomsCredit, AtomsDebit, and TxBlockTime.
})
}
ids = append(ids, id)
}
return ids, addressRows, nil
} | [
"func",
"InsertVoutsStmt",
"(",
"stmt",
"*",
"sql",
".",
"Stmt",
",",
"dbVouts",
"[",
"]",
"*",
"dbtypes",
".",
"Vout",
",",
"checked",
"bool",
",",
"doUpsert",
"bool",
")",
"(",
"[",
"]",
"uint64",
",",
"[",
"]",
"dbtypes",
".",
"AddressRow",
",",
"error",
")",
"{",
"addressRows",
":=",
"make",
"(",
"[",
"]",
"dbtypes",
".",
"AddressRow",
",",
"0",
",",
"len",
"(",
"dbVouts",
")",
")",
"// may grow with multisig",
"\n",
"ids",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"0",
",",
"len",
"(",
"dbVouts",
")",
")",
"\n",
"for",
"_",
",",
"vout",
":=",
"range",
"dbVouts",
"{",
"var",
"id",
"uint64",
"\n",
"err",
":=",
"stmt",
".",
"QueryRow",
"(",
"vout",
".",
"TxHash",
",",
"vout",
".",
"TxIndex",
",",
"vout",
".",
"TxTree",
",",
"vout",
".",
"Value",
",",
"vout",
".",
"Version",
",",
"vout",
".",
"ScriptPubKey",
",",
"vout",
".",
"ScriptPubKeyData",
".",
"ReqSigs",
",",
"vout",
".",
"ScriptPubKeyData",
".",
"Type",
",",
"pq",
".",
"Array",
"(",
"vout",
".",
"ScriptPubKeyData",
".",
"Addresses",
")",
")",
".",
"Scan",
"(",
"&",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"sql",
".",
"ErrNoRows",
"{",
"continue",
"\n",
"}",
"\n",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"addr",
":=",
"range",
"vout",
".",
"ScriptPubKeyData",
".",
"Addresses",
"{",
"addressRows",
"=",
"append",
"(",
"addressRows",
",",
"dbtypes",
".",
"AddressRow",
"{",
"Address",
":",
"addr",
",",
"TxHash",
":",
"vout",
".",
"TxHash",
",",
"TxVinVoutIndex",
":",
"vout",
".",
"TxIndex",
",",
"VinVoutDbID",
":",
"id",
",",
"TxType",
":",
"vout",
".",
"TxType",
",",
"Value",
":",
"vout",
".",
"Value",
",",
"// Not set here are: ValidMainchain, MatchingTxHash, IsFunding,",
"// AtomsCredit, AtomsDebit, and TxBlockTime.",
"}",
")",
"\n",
"}",
"\n",
"ids",
"=",
"append",
"(",
"ids",
",",
"id",
")",
"\n",
"}",
"\n\n",
"return",
"ids",
",",
"addressRows",
",",
"nil",
"\n",
"}"
] | // InsertVoutsStmt is like InsertVouts, except that it takes a sql.Stmt. The
// caller is required to Close the statement. | [
"InsertVoutsStmt",
"is",
"like",
"InsertVouts",
"except",
"that",
"it",
"takes",
"a",
"sql",
".",
"Stmt",
".",
"The",
"caller",
"is",
"required",
"to",
"Close",
"the",
"statement",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L1985-L2017 | train |
decred/dcrdata | db/dcrpg/queries.go | InsertVoutsDbTxn | func InsertVoutsDbTxn(dbTx *sql.Tx, dbVouts []*dbtypes.Vout, checked bool, doUpsert bool) ([]uint64, []dbtypes.AddressRow, error) {
stmt, err := dbTx.Prepare(internal.MakeVoutInsertStatement(checked, doUpsert))
if err != nil {
return nil, nil, err
}
ids, addressRows, err := InsertVoutsStmt(stmt, dbVouts, checked, doUpsert)
errClose := stmt.Close()
if err != nil {
return nil, nil, err
}
if errClose != nil {
return nil, nil, err
}
return ids, addressRows, stmt.Close()
} | go | func InsertVoutsDbTxn(dbTx *sql.Tx, dbVouts []*dbtypes.Vout, checked bool, doUpsert bool) ([]uint64, []dbtypes.AddressRow, error) {
stmt, err := dbTx.Prepare(internal.MakeVoutInsertStatement(checked, doUpsert))
if err != nil {
return nil, nil, err
}
ids, addressRows, err := InsertVoutsStmt(stmt, dbVouts, checked, doUpsert)
errClose := stmt.Close()
if err != nil {
return nil, nil, err
}
if errClose != nil {
return nil, nil, err
}
return ids, addressRows, stmt.Close()
} | [
"func",
"InsertVoutsDbTxn",
"(",
"dbTx",
"*",
"sql",
".",
"Tx",
",",
"dbVouts",
"[",
"]",
"*",
"dbtypes",
".",
"Vout",
",",
"checked",
"bool",
",",
"doUpsert",
"bool",
")",
"(",
"[",
"]",
"uint64",
",",
"[",
"]",
"dbtypes",
".",
"AddressRow",
",",
"error",
")",
"{",
"stmt",
",",
"err",
":=",
"dbTx",
".",
"Prepare",
"(",
"internal",
".",
"MakeVoutInsertStatement",
"(",
"checked",
",",
"doUpsert",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ids",
",",
"addressRows",
",",
"err",
":=",
"InsertVoutsStmt",
"(",
"stmt",
",",
"dbVouts",
",",
"checked",
",",
"doUpsert",
")",
"\n",
"errClose",
":=",
"stmt",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"errClose",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ids",
",",
"addressRows",
",",
"stmt",
".",
"Close",
"(",
")",
"\n",
"}"
] | // InsertVoutsDbTxn is like InsertVouts, except that it takes a sql.Tx. The
// caller is required to Commit or Rollback the transaction depending on the
// returned error value. | [
"InsertVoutsDbTxn",
"is",
"like",
"InsertVouts",
"except",
"that",
"it",
"takes",
"a",
"sql",
".",
"Tx",
".",
"The",
"caller",
"is",
"required",
"to",
"Commit",
"or",
"Rollback",
"the",
"transaction",
"depending",
"on",
"the",
"returned",
"error",
"value",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2022-L2038 | train |
decred/dcrdata | db/dcrpg/queries.go | InsertVouts | func InsertVouts(db *sql.DB, dbVouts []*dbtypes.Vout, checked bool, updateOnConflict ...bool) ([]uint64, []dbtypes.AddressRow, error) {
// All inserts in atomic DB transaction
dbTx, err := db.Begin()
if err != nil {
return nil, nil, fmt.Errorf("unable to begin database transaction: %v", err)
}
doUpsert := true
if len(updateOnConflict) > 0 {
doUpsert = updateOnConflict[0]
}
ids, addressRows, err := InsertVoutsDbTxn(dbTx, dbVouts, checked, doUpsert)
if err != nil {
_ = dbTx.Rollback() // try, but we want the Prepare error back
return nil, nil, err
}
return ids, addressRows, dbTx.Commit()
} | go | func InsertVouts(db *sql.DB, dbVouts []*dbtypes.Vout, checked bool, updateOnConflict ...bool) ([]uint64, []dbtypes.AddressRow, error) {
// All inserts in atomic DB transaction
dbTx, err := db.Begin()
if err != nil {
return nil, nil, fmt.Errorf("unable to begin database transaction: %v", err)
}
doUpsert := true
if len(updateOnConflict) > 0 {
doUpsert = updateOnConflict[0]
}
ids, addressRows, err := InsertVoutsDbTxn(dbTx, dbVouts, checked, doUpsert)
if err != nil {
_ = dbTx.Rollback() // try, but we want the Prepare error back
return nil, nil, err
}
return ids, addressRows, dbTx.Commit()
} | [
"func",
"InsertVouts",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"dbVouts",
"[",
"]",
"*",
"dbtypes",
".",
"Vout",
",",
"checked",
"bool",
",",
"updateOnConflict",
"...",
"bool",
")",
"(",
"[",
"]",
"uint64",
",",
"[",
"]",
"dbtypes",
".",
"AddressRow",
",",
"error",
")",
"{",
"// All inserts in atomic DB transaction",
"dbTx",
",",
"err",
":=",
"db",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"doUpsert",
":=",
"true",
"\n",
"if",
"len",
"(",
"updateOnConflict",
")",
">",
"0",
"{",
"doUpsert",
"=",
"updateOnConflict",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"ids",
",",
"addressRows",
",",
"err",
":=",
"InsertVoutsDbTxn",
"(",
"dbTx",
",",
"dbVouts",
",",
"checked",
",",
"doUpsert",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"_",
"=",
"dbTx",
".",
"Rollback",
"(",
")",
"// try, but we want the Prepare error back",
"\n",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ids",
",",
"addressRows",
",",
"dbTx",
".",
"Commit",
"(",
")",
"\n",
"}"
] | // InsertVouts is like InsertVout, except that it operates on a slice of vout
// data. | [
"InsertVouts",
"is",
"like",
"InsertVout",
"except",
"that",
"it",
"operates",
"on",
"a",
"slice",
"of",
"vout",
"data",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2042-L2061 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveFundingOutpointByTxIn | func RetrieveFundingOutpointByTxIn(ctx context.Context, db *sql.DB, txHash string,
vinIndex uint32) (id uint64, tx string, index uint32, tree int8, err error) {
err = db.QueryRowContext(ctx, internal.SelectFundingOutpointByTxIn, txHash, vinIndex).
Scan(&id, &tx, &index, &tree)
return
} | go | func RetrieveFundingOutpointByTxIn(ctx context.Context, db *sql.DB, txHash string,
vinIndex uint32) (id uint64, tx string, index uint32, tree int8, err error) {
err = db.QueryRowContext(ctx, internal.SelectFundingOutpointByTxIn, txHash, vinIndex).
Scan(&id, &tx, &index, &tree)
return
} | [
"func",
"RetrieveFundingOutpointByTxIn",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"txHash",
"string",
",",
"vinIndex",
"uint32",
")",
"(",
"id",
"uint64",
",",
"tx",
"string",
",",
"index",
"uint32",
",",
"tree",
"int8",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectFundingOutpointByTxIn",
",",
"txHash",
",",
"vinIndex",
")",
".",
"Scan",
"(",
"&",
"id",
",",
"&",
"tx",
",",
"&",
"index",
",",
"&",
"tree",
")",
"\n",
"return",
"\n",
"}"
] | // RetrieveFundingOutpointByTxIn gets the previous outpoint for a transaction
// input specified by transaction hash and input index. | [
"RetrieveFundingOutpointByTxIn",
"gets",
"the",
"previous",
"outpoint",
"for",
"a",
"transaction",
"input",
"specified",
"by",
"transaction",
"hash",
"and",
"input",
"index",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2139-L2144 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveFundingOutpointByVinID | func RetrieveFundingOutpointByVinID(ctx context.Context, db *sql.DB, vinDbID uint64) (tx string, index uint32, tree int8, err error) {
err = db.QueryRowContext(ctx, internal.SelectFundingOutpointByVinID, vinDbID).
Scan(&tx, &index, &tree)
return
} | go | func RetrieveFundingOutpointByVinID(ctx context.Context, db *sql.DB, vinDbID uint64) (tx string, index uint32, tree int8, err error) {
err = db.QueryRowContext(ctx, internal.SelectFundingOutpointByVinID, vinDbID).
Scan(&tx, &index, &tree)
return
} | [
"func",
"RetrieveFundingOutpointByVinID",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"vinDbID",
"uint64",
")",
"(",
"tx",
"string",
",",
"index",
"uint32",
",",
"tree",
"int8",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectFundingOutpointByVinID",
",",
"vinDbID",
")",
".",
"Scan",
"(",
"&",
"tx",
",",
"&",
"index",
",",
"&",
"tree",
")",
"\n",
"return",
"\n",
"}"
] | // RetrieveFundingOutpointByVinID gets the previous outpoint for a transaction
// input specified by row ID in the vins table. | [
"RetrieveFundingOutpointByVinID",
"gets",
"the",
"previous",
"outpoint",
"for",
"a",
"transaction",
"input",
"specified",
"by",
"row",
"ID",
"in",
"the",
"vins",
"table",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2148-L2152 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveFundingOutpointIndxByVinID | func RetrieveFundingOutpointIndxByVinID(ctx context.Context, db *sql.DB, vinDbID uint64) (idx uint32, err error) {
err = db.QueryRowContext(ctx, internal.SelectFundingOutpointIndxByVinID, vinDbID).Scan(&idx)
return
} | go | func RetrieveFundingOutpointIndxByVinID(ctx context.Context, db *sql.DB, vinDbID uint64) (idx uint32, err error) {
err = db.QueryRowContext(ctx, internal.SelectFundingOutpointIndxByVinID, vinDbID).Scan(&idx)
return
} | [
"func",
"RetrieveFundingOutpointIndxByVinID",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"vinDbID",
"uint64",
")",
"(",
"idx",
"uint32",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectFundingOutpointIndxByVinID",
",",
"vinDbID",
")",
".",
"Scan",
"(",
"&",
"idx",
")",
"\n",
"return",
"\n",
"}"
] | // RetrieveFundingOutpointIndxByVinID gets the transaction output index of the
// previous outpoint for a transaction input specified by row ID in the vins
// table. | [
"RetrieveFundingOutpointIndxByVinID",
"gets",
"the",
"transaction",
"output",
"index",
"of",
"the",
"previous",
"outpoint",
"for",
"a",
"transaction",
"input",
"specified",
"by",
"row",
"ID",
"in",
"the",
"vins",
"table",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2157-L2160 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveFundingTxByTxIn | func RetrieveFundingTxByTxIn(ctx context.Context, db *sql.DB, txHash string, vinIndex uint32) (id uint64, tx string, err error) {
err = db.QueryRowContext(ctx, internal.SelectFundingTxByTxIn, txHash, vinIndex).
Scan(&id, &tx)
return
} | go | func RetrieveFundingTxByTxIn(ctx context.Context, db *sql.DB, txHash string, vinIndex uint32) (id uint64, tx string, err error) {
err = db.QueryRowContext(ctx, internal.SelectFundingTxByTxIn, txHash, vinIndex).
Scan(&id, &tx)
return
} | [
"func",
"RetrieveFundingTxByTxIn",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"txHash",
"string",
",",
"vinIndex",
"uint32",
")",
"(",
"id",
"uint64",
",",
"tx",
"string",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectFundingTxByTxIn",
",",
"txHash",
",",
"vinIndex",
")",
".",
"Scan",
"(",
"&",
"id",
",",
"&",
"tx",
")",
"\n",
"return",
"\n",
"}"
] | // RetrieveFundingTxByTxIn gets the transaction hash of the previous outpoint
// for a transaction input specified by hash and input index. | [
"RetrieveFundingTxByTxIn",
"gets",
"the",
"transaction",
"hash",
"of",
"the",
"previous",
"outpoint",
"for",
"a",
"transaction",
"input",
"specified",
"by",
"hash",
"and",
"input",
"index",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2164-L2168 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveFundingTxByVinDbID | func RetrieveFundingTxByVinDbID(ctx context.Context, db *sql.DB, vinDbID uint64) (tx string, err error) {
err = db.QueryRowContext(ctx, internal.SelectFundingTxByVinID, vinDbID).Scan(&tx)
return
} | go | func RetrieveFundingTxByVinDbID(ctx context.Context, db *sql.DB, vinDbID uint64) (tx string, err error) {
err = db.QueryRowContext(ctx, internal.SelectFundingTxByVinID, vinDbID).Scan(&tx)
return
} | [
"func",
"RetrieveFundingTxByVinDbID",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"vinDbID",
"uint64",
")",
"(",
"tx",
"string",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectFundingTxByVinID",
",",
"vinDbID",
")",
".",
"Scan",
"(",
"&",
"tx",
")",
"\n",
"return",
"\n",
"}"
] | // RetrieveFundingTxByVinDbID gets the transaction hash of the previous outpoint
// for a transaction input specified by row ID in the vins table. This function
// is used only in UpdateSpendingInfoInAllTickets, so it should not be subject
// to timeouts. | [
"RetrieveFundingTxByVinDbID",
"gets",
"the",
"transaction",
"hash",
"of",
"the",
"previous",
"outpoint",
"for",
"a",
"transaction",
"input",
"specified",
"by",
"row",
"ID",
"in",
"the",
"vins",
"table",
".",
"This",
"function",
"is",
"used",
"only",
"in",
"UpdateSpendingInfoInAllTickets",
"so",
"it",
"should",
"not",
"be",
"subject",
"to",
"timeouts",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2174-L2177 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveSpendingTxByTxOut | func RetrieveSpendingTxByTxOut(ctx context.Context, db *sql.DB, txHash string,
voutIndex uint32) (id uint64, tx string, vin uint32, tree int8, err error) {
err = db.QueryRowContext(ctx, internal.SelectSpendingTxByPrevOut,
txHash, voutIndex).Scan(&id, &tx, &vin, &tree)
return
} | go | func RetrieveSpendingTxByTxOut(ctx context.Context, db *sql.DB, txHash string,
voutIndex uint32) (id uint64, tx string, vin uint32, tree int8, err error) {
err = db.QueryRowContext(ctx, internal.SelectSpendingTxByPrevOut,
txHash, voutIndex).Scan(&id, &tx, &vin, &tree)
return
} | [
"func",
"RetrieveSpendingTxByTxOut",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"txHash",
"string",
",",
"voutIndex",
"uint32",
")",
"(",
"id",
"uint64",
",",
"tx",
"string",
",",
"vin",
"uint32",
",",
"tree",
"int8",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectSpendingTxByPrevOut",
",",
"txHash",
",",
"voutIndex",
")",
".",
"Scan",
"(",
"&",
"id",
",",
"&",
"tx",
",",
"&",
"vin",
",",
"&",
"tree",
")",
"\n",
"return",
"\n",
"}"
] | // RetrieveSpendingTxByTxOut gets any spending transaction input info for a
// previous outpoint specified by funding transaction hash and vout number. This
// function is called by SpendingTransaction, an important part of the address
// page loading. | [
"RetrieveSpendingTxByTxOut",
"gets",
"any",
"spending",
"transaction",
"input",
"info",
"for",
"a",
"previous",
"outpoint",
"specified",
"by",
"funding",
"transaction",
"hash",
"and",
"vout",
"number",
".",
"This",
"function",
"is",
"called",
"by",
"SpendingTransaction",
"an",
"important",
"part",
"of",
"the",
"address",
"page",
"loading",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2218-L2223 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveSpendingTxsByFundingTx | func RetrieveSpendingTxsByFundingTx(ctx context.Context, db *sql.DB, fundingTxID string) (dbIDs []uint64,
txns []string, vinInds []uint32, voutInds []uint32, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectSpendingTxsByPrevTx, fundingTxID)
if err != nil {
return
}
defer closeRows(rows)
for rows.Next() {
var id uint64
var tx string
var vin, vout uint32
err = rows.Scan(&id, &tx, &vin, &vout)
if err != nil {
break
}
dbIDs = append(dbIDs, id)
txns = append(txns, tx)
vinInds = append(vinInds, vin)
voutInds = append(voutInds, vout)
}
return
} | go | func RetrieveSpendingTxsByFundingTx(ctx context.Context, db *sql.DB, fundingTxID string) (dbIDs []uint64,
txns []string, vinInds []uint32, voutInds []uint32, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectSpendingTxsByPrevTx, fundingTxID)
if err != nil {
return
}
defer closeRows(rows)
for rows.Next() {
var id uint64
var tx string
var vin, vout uint32
err = rows.Scan(&id, &tx, &vin, &vout)
if err != nil {
break
}
dbIDs = append(dbIDs, id)
txns = append(txns, tx)
vinInds = append(vinInds, vin)
voutInds = append(voutInds, vout)
}
return
} | [
"func",
"RetrieveSpendingTxsByFundingTx",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"fundingTxID",
"string",
")",
"(",
"dbIDs",
"[",
"]",
"uint64",
",",
"txns",
"[",
"]",
"string",
",",
"vinInds",
"[",
"]",
"uint32",
",",
"voutInds",
"[",
"]",
"uint32",
",",
"err",
"error",
")",
"{",
"var",
"rows",
"*",
"sql",
".",
"Rows",
"\n",
"rows",
",",
"err",
"=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectSpendingTxsByPrevTx",
",",
"fundingTxID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"id",
"uint64",
"\n",
"var",
"tx",
"string",
"\n",
"var",
"vin",
",",
"vout",
"uint32",
"\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"id",
",",
"&",
"tx",
",",
"&",
"vin",
",",
"&",
"vout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"dbIDs",
"=",
"append",
"(",
"dbIDs",
",",
"id",
")",
"\n",
"txns",
"=",
"append",
"(",
"txns",
",",
"tx",
")",
"\n",
"vinInds",
"=",
"append",
"(",
"vinInds",
",",
"vin",
")",
"\n",
"voutInds",
"=",
"append",
"(",
"voutInds",
",",
"vout",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // RetrieveSpendingTxsByFundingTx gets info on all spending transaction inputs
// for the given funding transaction specified by DB row ID. This function is
// called by SpendingTransactions, an important part of the transaction page
// loading, among other functions.. | [
"RetrieveSpendingTxsByFundingTx",
"gets",
"info",
"on",
"all",
"spending",
"transaction",
"inputs",
"for",
"the",
"given",
"funding",
"transaction",
"specified",
"by",
"DB",
"row",
"ID",
".",
"This",
"function",
"is",
"called",
"by",
"SpendingTransactions",
"an",
"important",
"part",
"of",
"the",
"transaction",
"page",
"loading",
"among",
"other",
"functions",
".."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2229-L2254 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveSpendingTxsByFundingTxWithBlockHeight | func RetrieveSpendingTxsByFundingTxWithBlockHeight(ctx context.Context, db *sql.DB, fundingTxID string) (aSpendByFunHash []*apitypes.SpendByFundingHash, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectSpendingTxsByPrevTxWithBlockHeight, fundingTxID)
if err != nil {
return
}
defer closeRows(rows)
for rows.Next() {
var addr apitypes.SpendByFundingHash
err = rows.Scan(&addr.FundingTxVoutIndex,
&addr.SpendingTxHash, &addr.SpendingTxVinIndex, &addr.BlockHeight)
if err != nil {
return
}
aSpendByFunHash = append(aSpendByFunHash, &addr)
}
return
} | go | func RetrieveSpendingTxsByFundingTxWithBlockHeight(ctx context.Context, db *sql.DB, fundingTxID string) (aSpendByFunHash []*apitypes.SpendByFundingHash, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectSpendingTxsByPrevTxWithBlockHeight, fundingTxID)
if err != nil {
return
}
defer closeRows(rows)
for rows.Next() {
var addr apitypes.SpendByFundingHash
err = rows.Scan(&addr.FundingTxVoutIndex,
&addr.SpendingTxHash, &addr.SpendingTxVinIndex, &addr.BlockHeight)
if err != nil {
return
}
aSpendByFunHash = append(aSpendByFunHash, &addr)
}
return
} | [
"func",
"RetrieveSpendingTxsByFundingTxWithBlockHeight",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"fundingTxID",
"string",
")",
"(",
"aSpendByFunHash",
"[",
"]",
"*",
"apitypes",
".",
"SpendByFundingHash",
",",
"err",
"error",
")",
"{",
"var",
"rows",
"*",
"sql",
".",
"Rows",
"\n",
"rows",
",",
"err",
"=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectSpendingTxsByPrevTxWithBlockHeight",
",",
"fundingTxID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"addr",
"apitypes",
".",
"SpendByFundingHash",
"\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"addr",
".",
"FundingTxVoutIndex",
",",
"&",
"addr",
".",
"SpendingTxHash",
",",
"&",
"addr",
".",
"SpendingTxVinIndex",
",",
"&",
"addr",
".",
"BlockHeight",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"aSpendByFunHash",
"=",
"append",
"(",
"aSpendByFunHash",
",",
"&",
"addr",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // RetrieveSpendingTxsByFundingTxWithBlockHeight will retrieve all transactions,
// indexes and block heights funded by a specific transaction. This function is
// used by the DCR to Insight transaction converter. | [
"RetrieveSpendingTxsByFundingTxWithBlockHeight",
"will",
"retrieve",
"all",
"transactions",
"indexes",
"and",
"block",
"heights",
"funded",
"by",
"a",
"specific",
"transaction",
".",
"This",
"function",
"is",
"used",
"by",
"the",
"DCR",
"to",
"Insight",
"transaction",
"converter",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2259-L2278 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveVinByID | func RetrieveVinByID(ctx context.Context, db *sql.DB, vinDbID uint64) (prevOutHash string, prevOutVoutInd uint32,
prevOutTree int8, txHash string, txVinInd uint32, txTree int8, valueIn int64, err error) {
var blockTime dbtypes.TimeDef
var isValid, isMainchain bool
var txType uint32
err = db.QueryRowContext(ctx, internal.SelectAllVinInfoByID, vinDbID).
Scan(&txHash, &txVinInd, &txTree, &isValid, &isMainchain, &blockTime,
&prevOutHash, &prevOutVoutInd, &prevOutTree, &valueIn, &txType)
return
} | go | func RetrieveVinByID(ctx context.Context, db *sql.DB, vinDbID uint64) (prevOutHash string, prevOutVoutInd uint32,
prevOutTree int8, txHash string, txVinInd uint32, txTree int8, valueIn int64, err error) {
var blockTime dbtypes.TimeDef
var isValid, isMainchain bool
var txType uint32
err = db.QueryRowContext(ctx, internal.SelectAllVinInfoByID, vinDbID).
Scan(&txHash, &txVinInd, &txTree, &isValid, &isMainchain, &blockTime,
&prevOutHash, &prevOutVoutInd, &prevOutTree, &valueIn, &txType)
return
} | [
"func",
"RetrieveVinByID",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"vinDbID",
"uint64",
")",
"(",
"prevOutHash",
"string",
",",
"prevOutVoutInd",
"uint32",
",",
"prevOutTree",
"int8",
",",
"txHash",
"string",
",",
"txVinInd",
"uint32",
",",
"txTree",
"int8",
",",
"valueIn",
"int64",
",",
"err",
"error",
")",
"{",
"var",
"blockTime",
"dbtypes",
".",
"TimeDef",
"\n",
"var",
"isValid",
",",
"isMainchain",
"bool",
"\n",
"var",
"txType",
"uint32",
"\n",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectAllVinInfoByID",
",",
"vinDbID",
")",
".",
"Scan",
"(",
"&",
"txHash",
",",
"&",
"txVinInd",
",",
"&",
"txTree",
",",
"&",
"isValid",
",",
"&",
"isMainchain",
",",
"&",
"blockTime",
",",
"&",
"prevOutHash",
",",
"&",
"prevOutVoutInd",
",",
"&",
"prevOutTree",
",",
"&",
"valueIn",
",",
"&",
"txType",
")",
"\n",
"return",
"\n",
"}"
] | // RetrieveVinByID gets from the vins table for the provided row ID. | [
"RetrieveVinByID",
"gets",
"from",
"the",
"vins",
"table",
"for",
"the",
"provided",
"row",
"ID",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2281-L2290 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveVinsByIDs | func RetrieveVinsByIDs(ctx context.Context, db *sql.DB, vinDbIDs []uint64) ([]dbtypes.VinTxProperty, error) {
vins := make([]dbtypes.VinTxProperty, len(vinDbIDs))
for i, id := range vinDbIDs {
vin := &vins[i]
err := db.QueryRowContext(ctx, internal.SelectAllVinInfoByID, id).Scan(&vin.TxID,
&vin.TxIndex, &vin.TxTree, &vin.IsValid, &vin.IsMainchain,
&vin.Time, &vin.PrevTxHash, &vin.PrevTxIndex, &vin.PrevTxTree,
&vin.ValueIn, &vin.TxType)
if err != nil {
return nil, err
}
}
return vins, nil
} | go | func RetrieveVinsByIDs(ctx context.Context, db *sql.DB, vinDbIDs []uint64) ([]dbtypes.VinTxProperty, error) {
vins := make([]dbtypes.VinTxProperty, len(vinDbIDs))
for i, id := range vinDbIDs {
vin := &vins[i]
err := db.QueryRowContext(ctx, internal.SelectAllVinInfoByID, id).Scan(&vin.TxID,
&vin.TxIndex, &vin.TxTree, &vin.IsValid, &vin.IsMainchain,
&vin.Time, &vin.PrevTxHash, &vin.PrevTxIndex, &vin.PrevTxTree,
&vin.ValueIn, &vin.TxType)
if err != nil {
return nil, err
}
}
return vins, nil
} | [
"func",
"RetrieveVinsByIDs",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"vinDbIDs",
"[",
"]",
"uint64",
")",
"(",
"[",
"]",
"dbtypes",
".",
"VinTxProperty",
",",
"error",
")",
"{",
"vins",
":=",
"make",
"(",
"[",
"]",
"dbtypes",
".",
"VinTxProperty",
",",
"len",
"(",
"vinDbIDs",
")",
")",
"\n",
"for",
"i",
",",
"id",
":=",
"range",
"vinDbIDs",
"{",
"vin",
":=",
"&",
"vins",
"[",
"i",
"]",
"\n",
"err",
":=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectAllVinInfoByID",
",",
"id",
")",
".",
"Scan",
"(",
"&",
"vin",
".",
"TxID",
",",
"&",
"vin",
".",
"TxIndex",
",",
"&",
"vin",
".",
"TxTree",
",",
"&",
"vin",
".",
"IsValid",
",",
"&",
"vin",
".",
"IsMainchain",
",",
"&",
"vin",
".",
"Time",
",",
"&",
"vin",
".",
"PrevTxHash",
",",
"&",
"vin",
".",
"PrevTxIndex",
",",
"&",
"vin",
".",
"PrevTxTree",
",",
"&",
"vin",
".",
"ValueIn",
",",
"&",
"vin",
".",
"TxType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"vins",
",",
"nil",
"\n",
"}"
] | // RetrieveVinsByIDs retrieves vin details for the rows of the vins table
// specified by the provided row IDs. This function is an important part of the
// transaction page. | [
"RetrieveVinsByIDs",
"retrieves",
"vin",
"details",
"for",
"the",
"rows",
"of",
"the",
"vins",
"table",
"specified",
"by",
"the",
"provided",
"row",
"IDs",
".",
"This",
"function",
"is",
"an",
"important",
"part",
"of",
"the",
"transaction",
"page",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2295-L2308 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveVoutsByIDs | func RetrieveVoutsByIDs(ctx context.Context, db *sql.DB, voutDbIDs []uint64) ([]dbtypes.Vout, error) {
vouts := make([]dbtypes.Vout, len(voutDbIDs))
for i, id := range voutDbIDs {
vout := &vouts[i]
var id0 uint64
var reqSigs uint32
var scriptType, addresses string
err := db.QueryRowContext(ctx, internal.SelectVoutByID, id).Scan(&id0, &vout.TxHash,
&vout.TxIndex, &vout.TxTree, &vout.Value, &vout.Version,
&vout.ScriptPubKey, &reqSigs, &scriptType, &addresses)
if err != nil {
return nil, err
}
// Parse the addresses array
replacer := strings.NewReplacer("{", "", "}", "")
addresses = replacer.Replace(addresses)
vout.ScriptPubKeyData.ReqSigs = reqSigs
vout.ScriptPubKeyData.Type = scriptType
// If there are no addresses, the Addresses should be nil or length
// zero. However, strings.Split will return [""] if addresses is "".
// If that is the case, leave it as a nil slice.
if len(addresses) > 0 {
vout.ScriptPubKeyData.Addresses = strings.Split(addresses, ",")
}
}
return vouts, nil
} | go | func RetrieveVoutsByIDs(ctx context.Context, db *sql.DB, voutDbIDs []uint64) ([]dbtypes.Vout, error) {
vouts := make([]dbtypes.Vout, len(voutDbIDs))
for i, id := range voutDbIDs {
vout := &vouts[i]
var id0 uint64
var reqSigs uint32
var scriptType, addresses string
err := db.QueryRowContext(ctx, internal.SelectVoutByID, id).Scan(&id0, &vout.TxHash,
&vout.TxIndex, &vout.TxTree, &vout.Value, &vout.Version,
&vout.ScriptPubKey, &reqSigs, &scriptType, &addresses)
if err != nil {
return nil, err
}
// Parse the addresses array
replacer := strings.NewReplacer("{", "", "}", "")
addresses = replacer.Replace(addresses)
vout.ScriptPubKeyData.ReqSigs = reqSigs
vout.ScriptPubKeyData.Type = scriptType
// If there are no addresses, the Addresses should be nil or length
// zero. However, strings.Split will return [""] if addresses is "".
// If that is the case, leave it as a nil slice.
if len(addresses) > 0 {
vout.ScriptPubKeyData.Addresses = strings.Split(addresses, ",")
}
}
return vouts, nil
} | [
"func",
"RetrieveVoutsByIDs",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"voutDbIDs",
"[",
"]",
"uint64",
")",
"(",
"[",
"]",
"dbtypes",
".",
"Vout",
",",
"error",
")",
"{",
"vouts",
":=",
"make",
"(",
"[",
"]",
"dbtypes",
".",
"Vout",
",",
"len",
"(",
"voutDbIDs",
")",
")",
"\n",
"for",
"i",
",",
"id",
":=",
"range",
"voutDbIDs",
"{",
"vout",
":=",
"&",
"vouts",
"[",
"i",
"]",
"\n",
"var",
"id0",
"uint64",
"\n",
"var",
"reqSigs",
"uint32",
"\n",
"var",
"scriptType",
",",
"addresses",
"string",
"\n",
"err",
":=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectVoutByID",
",",
"id",
")",
".",
"Scan",
"(",
"&",
"id0",
",",
"&",
"vout",
".",
"TxHash",
",",
"&",
"vout",
".",
"TxIndex",
",",
"&",
"vout",
".",
"TxTree",
",",
"&",
"vout",
".",
"Value",
",",
"&",
"vout",
".",
"Version",
",",
"&",
"vout",
".",
"ScriptPubKey",
",",
"&",
"reqSigs",
",",
"&",
"scriptType",
",",
"&",
"addresses",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// Parse the addresses array",
"replacer",
":=",
"strings",
".",
"NewReplacer",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"addresses",
"=",
"replacer",
".",
"Replace",
"(",
"addresses",
")",
"\n\n",
"vout",
".",
"ScriptPubKeyData",
".",
"ReqSigs",
"=",
"reqSigs",
"\n",
"vout",
".",
"ScriptPubKeyData",
".",
"Type",
"=",
"scriptType",
"\n",
"// If there are no addresses, the Addresses should be nil or length",
"// zero. However, strings.Split will return [\"\"] if addresses is \"\".",
"// If that is the case, leave it as a nil slice.",
"if",
"len",
"(",
"addresses",
")",
">",
"0",
"{",
"vout",
".",
"ScriptPubKeyData",
".",
"Addresses",
"=",
"strings",
".",
"Split",
"(",
"addresses",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"vouts",
",",
"nil",
"\n",
"}"
] | // RetrieveVoutsByIDs retrieves vout details for the rows of the vouts table
// specified by the provided row IDs. This function is an important part of the
// transaction page. | [
"RetrieveVoutsByIDs",
"retrieves",
"vout",
"details",
"for",
"the",
"rows",
"of",
"the",
"vouts",
"table",
"specified",
"by",
"the",
"provided",
"row",
"IDs",
".",
"This",
"function",
"is",
"an",
"important",
"part",
"of",
"the",
"transaction",
"page",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2313-L2340 | train |
decred/dcrdata | db/dcrpg/queries.go | SetSpendingForVinDbIDs | func SetSpendingForVinDbIDs(db *sql.DB, vinDbIDs []uint64) ([]int64, int64, error) {
// Get funding details for vin and set them in the address table.
dbtx, err := db.Begin()
if err != nil {
return nil, 0, fmt.Errorf(`unable to begin database transaction: %v`, err)
}
var vinGetStmt *sql.Stmt
vinGetStmt, err = dbtx.Prepare(internal.SelectVinVoutPairByID)
if err != nil {
log.Errorf("Vin SELECT prepare failed: %v", err)
// Already up a creek. Just return error from Prepare.
_ = dbtx.Rollback()
return nil, 0, err
}
bail := func() error {
// Already up a creek. Just return error from Prepare.
_ = vinGetStmt.Close()
return dbtx.Rollback()
}
addressRowsUpdated := make([]int64, len(vinDbIDs))
var totalUpdated int64
for iv, vinDbID := range vinDbIDs {
// Get the funding tx outpoint from the vins table.
var prevOutHash, txHash string
var prevOutVoutInd, txVinInd uint32
err = vinGetStmt.QueryRow(vinDbID).Scan(
&txHash, &txVinInd, &prevOutHash, &prevOutVoutInd)
if err != nil {
return addressRowsUpdated, 0, fmt.Errorf(`SelectVinVoutPairByID: `+
`%v + %v (rollback)`, err, bail())
}
// Skip coinbase inputs.
if bytes.Equal(zeroHashStringBytes, []byte(prevOutHash)) {
continue
}
// Set the spending tx info (addresses table) for the funding transaction
// rows indicated by the vin DB ID.
addressRowsUpdated[iv], err = setSpendingForFundingOP(dbtx,
prevOutHash, prevOutVoutInd, txHash, txVinInd)
if err != nil {
return addressRowsUpdated, 0, fmt.Errorf(`insertSpendingTxByPrptStmt: `+
`%v + %v (rollback)`, err, bail())
}
totalUpdated += addressRowsUpdated[iv]
}
// Close prepared statements. Ignore errors as we'll Commit regardless.
_ = vinGetStmt.Close()
return addressRowsUpdated, totalUpdated, dbtx.Commit()
} | go | func SetSpendingForVinDbIDs(db *sql.DB, vinDbIDs []uint64) ([]int64, int64, error) {
// Get funding details for vin and set them in the address table.
dbtx, err := db.Begin()
if err != nil {
return nil, 0, fmt.Errorf(`unable to begin database transaction: %v`, err)
}
var vinGetStmt *sql.Stmt
vinGetStmt, err = dbtx.Prepare(internal.SelectVinVoutPairByID)
if err != nil {
log.Errorf("Vin SELECT prepare failed: %v", err)
// Already up a creek. Just return error from Prepare.
_ = dbtx.Rollback()
return nil, 0, err
}
bail := func() error {
// Already up a creek. Just return error from Prepare.
_ = vinGetStmt.Close()
return dbtx.Rollback()
}
addressRowsUpdated := make([]int64, len(vinDbIDs))
var totalUpdated int64
for iv, vinDbID := range vinDbIDs {
// Get the funding tx outpoint from the vins table.
var prevOutHash, txHash string
var prevOutVoutInd, txVinInd uint32
err = vinGetStmt.QueryRow(vinDbID).Scan(
&txHash, &txVinInd, &prevOutHash, &prevOutVoutInd)
if err != nil {
return addressRowsUpdated, 0, fmt.Errorf(`SelectVinVoutPairByID: `+
`%v + %v (rollback)`, err, bail())
}
// Skip coinbase inputs.
if bytes.Equal(zeroHashStringBytes, []byte(prevOutHash)) {
continue
}
// Set the spending tx info (addresses table) for the funding transaction
// rows indicated by the vin DB ID.
addressRowsUpdated[iv], err = setSpendingForFundingOP(dbtx,
prevOutHash, prevOutVoutInd, txHash, txVinInd)
if err != nil {
return addressRowsUpdated, 0, fmt.Errorf(`insertSpendingTxByPrptStmt: `+
`%v + %v (rollback)`, err, bail())
}
totalUpdated += addressRowsUpdated[iv]
}
// Close prepared statements. Ignore errors as we'll Commit regardless.
_ = vinGetStmt.Close()
return addressRowsUpdated, totalUpdated, dbtx.Commit()
} | [
"func",
"SetSpendingForVinDbIDs",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"vinDbIDs",
"[",
"]",
"uint64",
")",
"(",
"[",
"]",
"int64",
",",
"int64",
",",
"error",
")",
"{",
"// Get funding details for vin and set them in the address table.",
"dbtx",
",",
"err",
":=",
"db",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`unable to begin database transaction: %v`",
",",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"vinGetStmt",
"*",
"sql",
".",
"Stmt",
"\n",
"vinGetStmt",
",",
"err",
"=",
"dbtx",
".",
"Prepare",
"(",
"internal",
".",
"SelectVinVoutPairByID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"// Already up a creek. Just return error from Prepare.",
"_",
"=",
"dbtx",
".",
"Rollback",
"(",
")",
"\n",
"return",
"nil",
",",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"bail",
":=",
"func",
"(",
")",
"error",
"{",
"// Already up a creek. Just return error from Prepare.",
"_",
"=",
"vinGetStmt",
".",
"Close",
"(",
")",
"\n",
"return",
"dbtx",
".",
"Rollback",
"(",
")",
"\n",
"}",
"\n\n",
"addressRowsUpdated",
":=",
"make",
"(",
"[",
"]",
"int64",
",",
"len",
"(",
"vinDbIDs",
")",
")",
"\n",
"var",
"totalUpdated",
"int64",
"\n\n",
"for",
"iv",
",",
"vinDbID",
":=",
"range",
"vinDbIDs",
"{",
"// Get the funding tx outpoint from the vins table.",
"var",
"prevOutHash",
",",
"txHash",
"string",
"\n",
"var",
"prevOutVoutInd",
",",
"txVinInd",
"uint32",
"\n",
"err",
"=",
"vinGetStmt",
".",
"QueryRow",
"(",
"vinDbID",
")",
".",
"Scan",
"(",
"&",
"txHash",
",",
"&",
"txVinInd",
",",
"&",
"prevOutHash",
",",
"&",
"prevOutVoutInd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"addressRowsUpdated",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`SelectVinVoutPairByID: `",
"+",
"`%v + %v (rollback)`",
",",
"err",
",",
"bail",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Skip coinbase inputs.",
"if",
"bytes",
".",
"Equal",
"(",
"zeroHashStringBytes",
",",
"[",
"]",
"byte",
"(",
"prevOutHash",
")",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"// Set the spending tx info (addresses table) for the funding transaction",
"// rows indicated by the vin DB ID.",
"addressRowsUpdated",
"[",
"iv",
"]",
",",
"err",
"=",
"setSpendingForFundingOP",
"(",
"dbtx",
",",
"prevOutHash",
",",
"prevOutVoutInd",
",",
"txHash",
",",
"txVinInd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"addressRowsUpdated",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`insertSpendingTxByPrptStmt: `",
"+",
"`%v + %v (rollback)`",
",",
"err",
",",
"bail",
"(",
")",
")",
"\n",
"}",
"\n\n",
"totalUpdated",
"+=",
"addressRowsUpdated",
"[",
"iv",
"]",
"\n",
"}",
"\n\n",
"// Close prepared statements. Ignore errors as we'll Commit regardless.",
"_",
"=",
"vinGetStmt",
".",
"Close",
"(",
")",
"\n\n",
"return",
"addressRowsUpdated",
",",
"totalUpdated",
",",
"dbtx",
".",
"Commit",
"(",
")",
"\n",
"}"
] | // SetSpendingForVinDbIDs updates rows of the addresses table with spending
// information from the rows of the vins table specified by vinDbIDs. This does
// not insert the spending transaction into the addresses table. | [
"SetSpendingForVinDbIDs",
"updates",
"rows",
"of",
"the",
"addresses",
"table",
"with",
"spending",
"information",
"from",
"the",
"rows",
"of",
"the",
"vins",
"table",
"specified",
"by",
"vinDbIDs",
".",
"This",
"does",
"not",
"insert",
"the",
"spending",
"transaction",
"into",
"the",
"addresses",
"table",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2386-L2443 | train |
decred/dcrdata | db/dcrpg/queries.go | SetSpendingForVinDbID | func SetSpendingForVinDbID(db *sql.DB, vinDbID uint64) (int64, error) {
// Get funding details for the vin and set them in the address table.
dbtx, err := db.Begin()
if err != nil {
return 0, fmt.Errorf(`unable to begin database transaction: %v`, err)
}
// Get the funding tx outpoint from the vins table.
var prevOutHash, txHash string
var prevOutVoutInd, txVinInd uint32
err = dbtx.QueryRow(internal.SelectVinVoutPairByID, vinDbID).
Scan(&txHash, &txVinInd, &prevOutHash, &prevOutVoutInd)
if err != nil {
return 0, fmt.Errorf(`SetSpendingByVinID: %v + %v `+
`(rollback)`, err, dbtx.Rollback())
}
// Skip coinbase inputs.
if bytes.Equal(zeroHashStringBytes, []byte(prevOutHash)) {
return 0, dbtx.Rollback()
}
// Set the spending tx info (addresses table) for the funding transaction
// rows indicated by the vin DB ID.
N, err := setSpendingForFundingOP(dbtx, prevOutHash, prevOutVoutInd,
txHash, txVinInd)
if err != nil {
return 0, fmt.Errorf(`RowsAffected: %v + %v (rollback)`,
err, dbtx.Rollback())
}
return N, dbtx.Commit()
} | go | func SetSpendingForVinDbID(db *sql.DB, vinDbID uint64) (int64, error) {
// Get funding details for the vin and set them in the address table.
dbtx, err := db.Begin()
if err != nil {
return 0, fmt.Errorf(`unable to begin database transaction: %v`, err)
}
// Get the funding tx outpoint from the vins table.
var prevOutHash, txHash string
var prevOutVoutInd, txVinInd uint32
err = dbtx.QueryRow(internal.SelectVinVoutPairByID, vinDbID).
Scan(&txHash, &txVinInd, &prevOutHash, &prevOutVoutInd)
if err != nil {
return 0, fmt.Errorf(`SetSpendingByVinID: %v + %v `+
`(rollback)`, err, dbtx.Rollback())
}
// Skip coinbase inputs.
if bytes.Equal(zeroHashStringBytes, []byte(prevOutHash)) {
return 0, dbtx.Rollback()
}
// Set the spending tx info (addresses table) for the funding transaction
// rows indicated by the vin DB ID.
N, err := setSpendingForFundingOP(dbtx, prevOutHash, prevOutVoutInd,
txHash, txVinInd)
if err != nil {
return 0, fmt.Errorf(`RowsAffected: %v + %v (rollback)`,
err, dbtx.Rollback())
}
return N, dbtx.Commit()
} | [
"func",
"SetSpendingForVinDbID",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"vinDbID",
"uint64",
")",
"(",
"int64",
",",
"error",
")",
"{",
"// Get funding details for the vin and set them in the address table.",
"dbtx",
",",
"err",
":=",
"db",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`unable to begin database transaction: %v`",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Get the funding tx outpoint from the vins table.",
"var",
"prevOutHash",
",",
"txHash",
"string",
"\n",
"var",
"prevOutVoutInd",
",",
"txVinInd",
"uint32",
"\n",
"err",
"=",
"dbtx",
".",
"QueryRow",
"(",
"internal",
".",
"SelectVinVoutPairByID",
",",
"vinDbID",
")",
".",
"Scan",
"(",
"&",
"txHash",
",",
"&",
"txVinInd",
",",
"&",
"prevOutHash",
",",
"&",
"prevOutVoutInd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`SetSpendingByVinID: %v + %v `",
"+",
"`(rollback)`",
",",
"err",
",",
"dbtx",
".",
"Rollback",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Skip coinbase inputs.",
"if",
"bytes",
".",
"Equal",
"(",
"zeroHashStringBytes",
",",
"[",
"]",
"byte",
"(",
"prevOutHash",
")",
")",
"{",
"return",
"0",
",",
"dbtx",
".",
"Rollback",
"(",
")",
"\n",
"}",
"\n\n",
"// Set the spending tx info (addresses table) for the funding transaction",
"// rows indicated by the vin DB ID.",
"N",
",",
"err",
":=",
"setSpendingForFundingOP",
"(",
"dbtx",
",",
"prevOutHash",
",",
"prevOutVoutInd",
",",
"txHash",
",",
"txVinInd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`RowsAffected: %v + %v (rollback)`",
",",
"err",
",",
"dbtx",
".",
"Rollback",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"N",
",",
"dbtx",
".",
"Commit",
"(",
")",
"\n",
"}"
] | // SetSpendingForVinDbID updates rows of the addresses table with spending
// information from the row of the vins table specified by vinDbID. This does
// not insert the spending transaction into the addresses table. | [
"SetSpendingForVinDbID",
"updates",
"rows",
"of",
"the",
"addresses",
"table",
"with",
"spending",
"information",
"from",
"the",
"row",
"of",
"the",
"vins",
"table",
"specified",
"by",
"vinDbID",
".",
"This",
"does",
"not",
"insert",
"the",
"spending",
"transaction",
"into",
"the",
"addresses",
"table",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2448-L2480 | train |
decred/dcrdata | db/dcrpg/queries.go | SetSpendingForFundingOP | func SetSpendingForFundingOP(db SqlExecutor, fundingTxHash string, fundingTxVoutIndex uint32,
spendingTxHash string, _ /*spendingTxVinIndex*/ uint32) (int64, error) {
// Update the matchingTxHash for the funding tx output. matchingTxHash here
// is the hash of the funding tx.
res, err := db.Exec(internal.SetAddressMatchingTxHashForOutpoint,
spendingTxHash, fundingTxHash, fundingTxVoutIndex)
if err != nil || res == nil {
return 0, fmt.Errorf("SetAddressMatchingTxHashForOutpoint: %v", err)
}
return res.RowsAffected()
} | go | func SetSpendingForFundingOP(db SqlExecutor, fundingTxHash string, fundingTxVoutIndex uint32,
spendingTxHash string, _ /*spendingTxVinIndex*/ uint32) (int64, error) {
// Update the matchingTxHash for the funding tx output. matchingTxHash here
// is the hash of the funding tx.
res, err := db.Exec(internal.SetAddressMatchingTxHashForOutpoint,
spendingTxHash, fundingTxHash, fundingTxVoutIndex)
if err != nil || res == nil {
return 0, fmt.Errorf("SetAddressMatchingTxHashForOutpoint: %v", err)
}
return res.RowsAffected()
} | [
"func",
"SetSpendingForFundingOP",
"(",
"db",
"SqlExecutor",
",",
"fundingTxHash",
"string",
",",
"fundingTxVoutIndex",
"uint32",
",",
"spendingTxHash",
"string",
",",
"_",
"/*spendingTxVinIndex*/",
"uint32",
")",
"(",
"int64",
",",
"error",
")",
"{",
"// Update the matchingTxHash for the funding tx output. matchingTxHash here",
"// is the hash of the funding tx.",
"res",
",",
"err",
":=",
"db",
".",
"Exec",
"(",
"internal",
".",
"SetAddressMatchingTxHashForOutpoint",
",",
"spendingTxHash",
",",
"fundingTxHash",
",",
"fundingTxVoutIndex",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"res",
"==",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"res",
".",
"RowsAffected",
"(",
")",
"\n",
"}"
] | // SetSpendingForFundingOP updates funding rows of the addresses table with the
// provided spending transaction output info. | [
"SetSpendingForFundingOP",
"updates",
"funding",
"rows",
"of",
"the",
"addresses",
"table",
"with",
"the",
"provided",
"spending",
"transaction",
"output",
"info",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2484-L2495 | train |
decred/dcrdata | db/dcrpg/queries.go | InsertSpendingAddressRow | func InsertSpendingAddressRow(db *sql.DB, fundingTxHash string,
fundingTxVoutIndex uint32, fundingTxTree int8, spendingTxHash string,
spendingTxVinIndex uint32, vinDbID uint64, utxoData *dbtypes.UTXOData,
checked, updateExisting, isValidMainchain bool,
txType int16, updateFundingRow bool, spendingTXBlockTime dbtypes.TimeDef) (int64, error) {
// Only allow atomic transactions to happen
dbtx, err := db.Begin()
if err != nil {
return 0, fmt.Errorf(`unable to begin database transaction: %v`, err)
}
c, err := insertSpendingAddressRow(dbtx, fundingTxHash, fundingTxVoutIndex,
fundingTxTree, spendingTxHash, spendingTxVinIndex, vinDbID, utxoData, checked,
updateExisting, isValidMainchain, txType, updateFundingRow, spendingTXBlockTime)
if err != nil {
return 0, fmt.Errorf(`RowsAffected: %v + %v (rollback)`,
err, dbtx.Rollback())
}
return c, dbtx.Commit()
} | go | func InsertSpendingAddressRow(db *sql.DB, fundingTxHash string,
fundingTxVoutIndex uint32, fundingTxTree int8, spendingTxHash string,
spendingTxVinIndex uint32, vinDbID uint64, utxoData *dbtypes.UTXOData,
checked, updateExisting, isValidMainchain bool,
txType int16, updateFundingRow bool, spendingTXBlockTime dbtypes.TimeDef) (int64, error) {
// Only allow atomic transactions to happen
dbtx, err := db.Begin()
if err != nil {
return 0, fmt.Errorf(`unable to begin database transaction: %v`, err)
}
c, err := insertSpendingAddressRow(dbtx, fundingTxHash, fundingTxVoutIndex,
fundingTxTree, spendingTxHash, spendingTxVinIndex, vinDbID, utxoData, checked,
updateExisting, isValidMainchain, txType, updateFundingRow, spendingTXBlockTime)
if err != nil {
return 0, fmt.Errorf(`RowsAffected: %v + %v (rollback)`,
err, dbtx.Rollback())
}
return c, dbtx.Commit()
} | [
"func",
"InsertSpendingAddressRow",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"fundingTxHash",
"string",
",",
"fundingTxVoutIndex",
"uint32",
",",
"fundingTxTree",
"int8",
",",
"spendingTxHash",
"string",
",",
"spendingTxVinIndex",
"uint32",
",",
"vinDbID",
"uint64",
",",
"utxoData",
"*",
"dbtypes",
".",
"UTXOData",
",",
"checked",
",",
"updateExisting",
",",
"isValidMainchain",
"bool",
",",
"txType",
"int16",
",",
"updateFundingRow",
"bool",
",",
"spendingTXBlockTime",
"dbtypes",
".",
"TimeDef",
")",
"(",
"int64",
",",
"error",
")",
"{",
"// Only allow atomic transactions to happen",
"dbtx",
",",
"err",
":=",
"db",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`unable to begin database transaction: %v`",
",",
"err",
")",
"\n",
"}",
"\n\n",
"c",
",",
"err",
":=",
"insertSpendingAddressRow",
"(",
"dbtx",
",",
"fundingTxHash",
",",
"fundingTxVoutIndex",
",",
"fundingTxTree",
",",
"spendingTxHash",
",",
"spendingTxVinIndex",
",",
"vinDbID",
",",
"utxoData",
",",
"checked",
",",
"updateExisting",
",",
"isValidMainchain",
",",
"txType",
",",
"updateFundingRow",
",",
"spendingTXBlockTime",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"`RowsAffected: %v + %v (rollback)`",
",",
"err",
",",
"dbtx",
".",
"Rollback",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"c",
",",
"dbtx",
".",
"Commit",
"(",
")",
"\n",
"}"
] | // InsertSpendingAddressRow inserts a new spending tx row, and updates any
// corresponding funding tx row. | [
"InsertSpendingAddressRow",
"inserts",
"a",
"new",
"spending",
"tx",
"row",
"and",
"updates",
"any",
"corresponding",
"funding",
"tx",
"row",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2512-L2532 | train |
decred/dcrdata | db/dcrpg/queries.go | insertSpendingAddressRow | func insertSpendingAddressRow(tx *sql.Tx, fundingTxHash string, fundingTxVoutIndex uint32,
fundingTxTree int8, spendingTxHash string, spendingTxVinIndex uint32, vinDbID uint64,
utxoData *dbtypes.UTXOData, checked, updateExisting, validMainchain bool, txType int16,
updateFundingRow bool, blockT ...dbtypes.TimeDef) (int64, error) {
// Select addresses and value from the matching funding tx output. A maximum
// of one row and a minimum of none are expected.
var addrs []string
var value uint64
// When no previous output information is provided, query the vouts table
// for the addresses and value.
if utxoData == nil {
// The addresses column of the vouts table contains an array of
// addresses that the pkScript pays to (i.e. >1 for multisig).
var addrArray string
err := tx.QueryRow(internal.SelectAddressByTxHash,
fundingTxHash, fundingTxVoutIndex, fundingTxTree).Scan(&addrArray, &value)
switch err {
case sql.ErrNoRows, nil:
// If no row found or error is nil, continue
default:
return 0, fmt.Errorf("SelectAddressByTxHash: %v", err)
}
// Get address list.
replacer := strings.NewReplacer("{", "", "}", "")
addrArray = replacer.Replace(addrArray)
addrs = strings.Split(addrArray, ",")
} else {
addrs = utxoData.Addresses
value = uint64(utxoData.Value)
}
// Check if the block time was provided.
var blockTime dbtypes.TimeDef
if len(blockT) > 0 {
blockTime = blockT[0]
} else {
// Fetch the block time from the tx table.
err := tx.QueryRow(internal.SelectTxBlockTimeByHash, spendingTxHash).Scan(&blockTime)
if err != nil {
return 0, fmt.Errorf("SelectTxBlockTimeByHash: %v", err)
}
}
// Insert the addresses table row(s) for the spending tx.
sqlStmt := internal.MakeAddressRowInsertStatement(checked, updateExisting)
for i := range addrs {
var isFunding bool // spending
var rowID uint64
err := tx.QueryRow(sqlStmt, addrs[i], fundingTxHash, spendingTxHash,
spendingTxVinIndex, vinDbID, value, blockTime, isFunding,
validMainchain, txType).Scan(&rowID)
if err != nil {
return 0, fmt.Errorf("InsertAddressRow: %v", err)
}
}
if updateFundingRow {
// Update the matching funding addresses row with the spending info.
return setSpendingForFundingOP(tx, fundingTxHash, fundingTxVoutIndex,
spendingTxHash, spendingTxVinIndex)
}
return 0, nil
} | go | func insertSpendingAddressRow(tx *sql.Tx, fundingTxHash string, fundingTxVoutIndex uint32,
fundingTxTree int8, spendingTxHash string, spendingTxVinIndex uint32, vinDbID uint64,
utxoData *dbtypes.UTXOData, checked, updateExisting, validMainchain bool, txType int16,
updateFundingRow bool, blockT ...dbtypes.TimeDef) (int64, error) {
// Select addresses and value from the matching funding tx output. A maximum
// of one row and a minimum of none are expected.
var addrs []string
var value uint64
// When no previous output information is provided, query the vouts table
// for the addresses and value.
if utxoData == nil {
// The addresses column of the vouts table contains an array of
// addresses that the pkScript pays to (i.e. >1 for multisig).
var addrArray string
err := tx.QueryRow(internal.SelectAddressByTxHash,
fundingTxHash, fundingTxVoutIndex, fundingTxTree).Scan(&addrArray, &value)
switch err {
case sql.ErrNoRows, nil:
// If no row found or error is nil, continue
default:
return 0, fmt.Errorf("SelectAddressByTxHash: %v", err)
}
// Get address list.
replacer := strings.NewReplacer("{", "", "}", "")
addrArray = replacer.Replace(addrArray)
addrs = strings.Split(addrArray, ",")
} else {
addrs = utxoData.Addresses
value = uint64(utxoData.Value)
}
// Check if the block time was provided.
var blockTime dbtypes.TimeDef
if len(blockT) > 0 {
blockTime = blockT[0]
} else {
// Fetch the block time from the tx table.
err := tx.QueryRow(internal.SelectTxBlockTimeByHash, spendingTxHash).Scan(&blockTime)
if err != nil {
return 0, fmt.Errorf("SelectTxBlockTimeByHash: %v", err)
}
}
// Insert the addresses table row(s) for the spending tx.
sqlStmt := internal.MakeAddressRowInsertStatement(checked, updateExisting)
for i := range addrs {
var isFunding bool // spending
var rowID uint64
err := tx.QueryRow(sqlStmt, addrs[i], fundingTxHash, spendingTxHash,
spendingTxVinIndex, vinDbID, value, blockTime, isFunding,
validMainchain, txType).Scan(&rowID)
if err != nil {
return 0, fmt.Errorf("InsertAddressRow: %v", err)
}
}
if updateFundingRow {
// Update the matching funding addresses row with the spending info.
return setSpendingForFundingOP(tx, fundingTxHash, fundingTxVoutIndex,
spendingTxHash, spendingTxVinIndex)
}
return 0, nil
} | [
"func",
"insertSpendingAddressRow",
"(",
"tx",
"*",
"sql",
".",
"Tx",
",",
"fundingTxHash",
"string",
",",
"fundingTxVoutIndex",
"uint32",
",",
"fundingTxTree",
"int8",
",",
"spendingTxHash",
"string",
",",
"spendingTxVinIndex",
"uint32",
",",
"vinDbID",
"uint64",
",",
"utxoData",
"*",
"dbtypes",
".",
"UTXOData",
",",
"checked",
",",
"updateExisting",
",",
"validMainchain",
"bool",
",",
"txType",
"int16",
",",
"updateFundingRow",
"bool",
",",
"blockT",
"...",
"dbtypes",
".",
"TimeDef",
")",
"(",
"int64",
",",
"error",
")",
"{",
"// Select addresses and value from the matching funding tx output. A maximum",
"// of one row and a minimum of none are expected.",
"var",
"addrs",
"[",
"]",
"string",
"\n",
"var",
"value",
"uint64",
"\n\n",
"// When no previous output information is provided, query the vouts table",
"// for the addresses and value.",
"if",
"utxoData",
"==",
"nil",
"{",
"// The addresses column of the vouts table contains an array of",
"// addresses that the pkScript pays to (i.e. >1 for multisig).",
"var",
"addrArray",
"string",
"\n",
"err",
":=",
"tx",
".",
"QueryRow",
"(",
"internal",
".",
"SelectAddressByTxHash",
",",
"fundingTxHash",
",",
"fundingTxVoutIndex",
",",
"fundingTxTree",
")",
".",
"Scan",
"(",
"&",
"addrArray",
",",
"&",
"value",
")",
"\n",
"switch",
"err",
"{",
"case",
"sql",
".",
"ErrNoRows",
",",
"nil",
":",
"// If no row found or error is nil, continue",
"default",
":",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Get address list.",
"replacer",
":=",
"strings",
".",
"NewReplacer",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"addrArray",
"=",
"replacer",
".",
"Replace",
"(",
"addrArray",
")",
"\n",
"addrs",
"=",
"strings",
".",
"Split",
"(",
"addrArray",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"addrs",
"=",
"utxoData",
".",
"Addresses",
"\n",
"value",
"=",
"uint64",
"(",
"utxoData",
".",
"Value",
")",
"\n",
"}",
"\n\n",
"// Check if the block time was provided.",
"var",
"blockTime",
"dbtypes",
".",
"TimeDef",
"\n",
"if",
"len",
"(",
"blockT",
")",
">",
"0",
"{",
"blockTime",
"=",
"blockT",
"[",
"0",
"]",
"\n",
"}",
"else",
"{",
"// Fetch the block time from the tx table.",
"err",
":=",
"tx",
".",
"QueryRow",
"(",
"internal",
".",
"SelectTxBlockTimeByHash",
",",
"spendingTxHash",
")",
".",
"Scan",
"(",
"&",
"blockTime",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Insert the addresses table row(s) for the spending tx.",
"sqlStmt",
":=",
"internal",
".",
"MakeAddressRowInsertStatement",
"(",
"checked",
",",
"updateExisting",
")",
"\n",
"for",
"i",
":=",
"range",
"addrs",
"{",
"var",
"isFunding",
"bool",
"// spending",
"\n",
"var",
"rowID",
"uint64",
"\n",
"err",
":=",
"tx",
".",
"QueryRow",
"(",
"sqlStmt",
",",
"addrs",
"[",
"i",
"]",
",",
"fundingTxHash",
",",
"spendingTxHash",
",",
"spendingTxVinIndex",
",",
"vinDbID",
",",
"value",
",",
"blockTime",
",",
"isFunding",
",",
"validMainchain",
",",
"txType",
")",
".",
"Scan",
"(",
"&",
"rowID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"updateFundingRow",
"{",
"// Update the matching funding addresses row with the spending info.",
"return",
"setSpendingForFundingOP",
"(",
"tx",
",",
"fundingTxHash",
",",
"fundingTxVoutIndex",
",",
"spendingTxHash",
",",
"spendingTxVinIndex",
")",
"\n",
"}",
"\n",
"return",
"0",
",",
"nil",
"\n",
"}"
] | // insertSpendingAddressRow inserts a new row in the addresses table for a new
// transaction input, and updates the spending information for the addresses
// table row corresponding to the previous outpoint. | [
"insertSpendingAddressRow",
"inserts",
"a",
"new",
"row",
"in",
"the",
"addresses",
"table",
"for",
"a",
"new",
"transaction",
"input",
"and",
"updates",
"the",
"spending",
"information",
"for",
"the",
"addresses",
"table",
"row",
"corresponding",
"to",
"the",
"previous",
"outpoint",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2537-L2602 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveTotalAgendaVotesCount | func retrieveTotalAgendaVotesCount(ctx context.Context, db *sql.DB, agendaID string,
votingStartHeight, votingDoneHeight int64) (yes, abstain, no uint32, err error) {
var total uint32
err = db.QueryRowContext(ctx, internal.SelectAgendaVoteTotals, dbtypes.Yes,
dbtypes.Abstain, dbtypes.No, agendaID, votingStartHeight,
votingDoneHeight).Scan(&yes, &abstain, &no, &total)
return
} | go | func retrieveTotalAgendaVotesCount(ctx context.Context, db *sql.DB, agendaID string,
votingStartHeight, votingDoneHeight int64) (yes, abstain, no uint32, err error) {
var total uint32
err = db.QueryRowContext(ctx, internal.SelectAgendaVoteTotals, dbtypes.Yes,
dbtypes.Abstain, dbtypes.No, agendaID, votingStartHeight,
votingDoneHeight).Scan(&yes, &abstain, &no, &total)
return
} | [
"func",
"retrieveTotalAgendaVotesCount",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"agendaID",
"string",
",",
"votingStartHeight",
",",
"votingDoneHeight",
"int64",
")",
"(",
"yes",
",",
"abstain",
",",
"no",
"uint32",
",",
"err",
"error",
")",
"{",
"var",
"total",
"uint32",
"\n\n",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectAgendaVoteTotals",
",",
"dbtypes",
".",
"Yes",
",",
"dbtypes",
".",
"Abstain",
",",
"dbtypes",
".",
"No",
",",
"agendaID",
",",
"votingStartHeight",
",",
"votingDoneHeight",
")",
".",
"Scan",
"(",
"&",
"yes",
",",
"&",
"abstain",
",",
"&",
"no",
",",
"&",
"total",
")",
"\n\n",
"return",
"\n",
"}"
] | // retrieveTotalAgendaVotesCount returns the Cumulative vote choices count for
// the provided agenda id. votingDoneHeight references the height at which the
// agenda ID voting is considered complete. | [
"retrieveTotalAgendaVotesCount",
"returns",
"the",
"Cumulative",
"vote",
"choices",
"count",
"for",
"the",
"provided",
"agenda",
"id",
".",
"votingDoneHeight",
"references",
"the",
"height",
"at",
"which",
"the",
"agenda",
"ID",
"voting",
"is",
"considered",
"complete",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2671-L2680 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveDbTxByHash | func RetrieveDbTxByHash(ctx context.Context, db *sql.DB, txHash string) (id uint64, dbTx *dbtypes.Tx, err error) {
dbTx = new(dbtypes.Tx)
vinDbIDs := dbtypes.UInt64Array(dbTx.VinDbIds)
voutDbIDs := dbtypes.UInt64Array(dbTx.VoutDbIds)
err = db.QueryRowContext(ctx, internal.SelectFullTxByHash, txHash).Scan(&id,
&dbTx.BlockHash, &dbTx.BlockHeight, &dbTx.BlockTime, &dbTx.Time,
&dbTx.TxType, &dbTx.Version, &dbTx.Tree, &dbTx.TxID, &dbTx.BlockIndex,
&dbTx.Locktime, &dbTx.Expiry, &dbTx.Size, &dbTx.Spent, &dbTx.Sent,
&dbTx.Fees, &dbTx.NumVin, &vinDbIDs, &dbTx.NumVout, &voutDbIDs,
&dbTx.IsValidBlock, &dbTx.IsMainchainBlock)
dbTx.VinDbIds = vinDbIDs
dbTx.VoutDbIds = voutDbIDs
return
} | go | func RetrieveDbTxByHash(ctx context.Context, db *sql.DB, txHash string) (id uint64, dbTx *dbtypes.Tx, err error) {
dbTx = new(dbtypes.Tx)
vinDbIDs := dbtypes.UInt64Array(dbTx.VinDbIds)
voutDbIDs := dbtypes.UInt64Array(dbTx.VoutDbIds)
err = db.QueryRowContext(ctx, internal.SelectFullTxByHash, txHash).Scan(&id,
&dbTx.BlockHash, &dbTx.BlockHeight, &dbTx.BlockTime, &dbTx.Time,
&dbTx.TxType, &dbTx.Version, &dbTx.Tree, &dbTx.TxID, &dbTx.BlockIndex,
&dbTx.Locktime, &dbTx.Expiry, &dbTx.Size, &dbTx.Spent, &dbTx.Sent,
&dbTx.Fees, &dbTx.NumVin, &vinDbIDs, &dbTx.NumVout, &voutDbIDs,
&dbTx.IsValidBlock, &dbTx.IsMainchainBlock)
dbTx.VinDbIds = vinDbIDs
dbTx.VoutDbIds = voutDbIDs
return
} | [
"func",
"RetrieveDbTxByHash",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"txHash",
"string",
")",
"(",
"id",
"uint64",
",",
"dbTx",
"*",
"dbtypes",
".",
"Tx",
",",
"err",
"error",
")",
"{",
"dbTx",
"=",
"new",
"(",
"dbtypes",
".",
"Tx",
")",
"\n",
"vinDbIDs",
":=",
"dbtypes",
".",
"UInt64Array",
"(",
"dbTx",
".",
"VinDbIds",
")",
"\n",
"voutDbIDs",
":=",
"dbtypes",
".",
"UInt64Array",
"(",
"dbTx",
".",
"VoutDbIds",
")",
"\n",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectFullTxByHash",
",",
"txHash",
")",
".",
"Scan",
"(",
"&",
"id",
",",
"&",
"dbTx",
".",
"BlockHash",
",",
"&",
"dbTx",
".",
"BlockHeight",
",",
"&",
"dbTx",
".",
"BlockTime",
",",
"&",
"dbTx",
".",
"Time",
",",
"&",
"dbTx",
".",
"TxType",
",",
"&",
"dbTx",
".",
"Version",
",",
"&",
"dbTx",
".",
"Tree",
",",
"&",
"dbTx",
".",
"TxID",
",",
"&",
"dbTx",
".",
"BlockIndex",
",",
"&",
"dbTx",
".",
"Locktime",
",",
"&",
"dbTx",
".",
"Expiry",
",",
"&",
"dbTx",
".",
"Size",
",",
"&",
"dbTx",
".",
"Spent",
",",
"&",
"dbTx",
".",
"Sent",
",",
"&",
"dbTx",
".",
"Fees",
",",
"&",
"dbTx",
".",
"NumVin",
",",
"&",
"vinDbIDs",
",",
"&",
"dbTx",
".",
"NumVout",
",",
"&",
"voutDbIDs",
",",
"&",
"dbTx",
".",
"IsValidBlock",
",",
"&",
"dbTx",
".",
"IsMainchainBlock",
")",
"\n",
"dbTx",
".",
"VinDbIds",
"=",
"vinDbIDs",
"\n",
"dbTx",
".",
"VoutDbIds",
"=",
"voutDbIDs",
"\n",
"return",
"\n",
"}"
] | // RetrieveDbTxByHash retrieves a row of the transactions table corresponding to
// the given transaction hash. Transactions in valid and mainchain blocks are
// chosen first. This function is used by FillAddressTransactions, an important
// component of the addresses page. | [
"RetrieveDbTxByHash",
"retrieves",
"a",
"row",
"of",
"the",
"transactions",
"table",
"corresponding",
"to",
"the",
"given",
"transaction",
"hash",
".",
"Transactions",
"in",
"valid",
"and",
"mainchain",
"blocks",
"are",
"chosen",
"first",
".",
"This",
"function",
"is",
"used",
"by",
"FillAddressTransactions",
"an",
"important",
"component",
"of",
"the",
"addresses",
"page",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2783-L2796 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveFullTxByHash | func RetrieveFullTxByHash(ctx context.Context, db *sql.DB, txHash string) (id uint64,
blockHash string, blockHeight int64, blockTime, timeVal dbtypes.TimeDef,
txType int16, version int32, tree int8, blockInd uint32,
lockTime, expiry int32, size uint32, spent, sent, fees int64,
numVin int32, vinDbIDs []int64, numVout int32, voutDbIDs []int64,
isValidBlock, isMainchainBlock bool, err error) {
var hash string
err = db.QueryRowContext(ctx, internal.SelectFullTxByHash, txHash).Scan(&id, &blockHash,
&blockHeight, &blockTime, &timeVal, &txType, &version, &tree,
&hash, &blockInd, &lockTime, &expiry, &size, &spent, &sent, &fees,
&numVin, &vinDbIDs, &numVout, &voutDbIDs,
&isValidBlock, &isMainchainBlock)
return
} | go | func RetrieveFullTxByHash(ctx context.Context, db *sql.DB, txHash string) (id uint64,
blockHash string, blockHeight int64, blockTime, timeVal dbtypes.TimeDef,
txType int16, version int32, tree int8, blockInd uint32,
lockTime, expiry int32, size uint32, spent, sent, fees int64,
numVin int32, vinDbIDs []int64, numVout int32, voutDbIDs []int64,
isValidBlock, isMainchainBlock bool, err error) {
var hash string
err = db.QueryRowContext(ctx, internal.SelectFullTxByHash, txHash).Scan(&id, &blockHash,
&blockHeight, &blockTime, &timeVal, &txType, &version, &tree,
&hash, &blockInd, &lockTime, &expiry, &size, &spent, &sent, &fees,
&numVin, &vinDbIDs, &numVout, &voutDbIDs,
&isValidBlock, &isMainchainBlock)
return
} | [
"func",
"RetrieveFullTxByHash",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"txHash",
"string",
")",
"(",
"id",
"uint64",
",",
"blockHash",
"string",
",",
"blockHeight",
"int64",
",",
"blockTime",
",",
"timeVal",
"dbtypes",
".",
"TimeDef",
",",
"txType",
"int16",
",",
"version",
"int32",
",",
"tree",
"int8",
",",
"blockInd",
"uint32",
",",
"lockTime",
",",
"expiry",
"int32",
",",
"size",
"uint32",
",",
"spent",
",",
"sent",
",",
"fees",
"int64",
",",
"numVin",
"int32",
",",
"vinDbIDs",
"[",
"]",
"int64",
",",
"numVout",
"int32",
",",
"voutDbIDs",
"[",
"]",
"int64",
",",
"isValidBlock",
",",
"isMainchainBlock",
"bool",
",",
"err",
"error",
")",
"{",
"var",
"hash",
"string",
"\n",
"err",
"=",
"db",
".",
"QueryRowContext",
"(",
"ctx",
",",
"internal",
".",
"SelectFullTxByHash",
",",
"txHash",
")",
".",
"Scan",
"(",
"&",
"id",
",",
"&",
"blockHash",
",",
"&",
"blockHeight",
",",
"&",
"blockTime",
",",
"&",
"timeVal",
",",
"&",
"txType",
",",
"&",
"version",
",",
"&",
"tree",
",",
"&",
"hash",
",",
"&",
"blockInd",
",",
"&",
"lockTime",
",",
"&",
"expiry",
",",
"&",
"size",
",",
"&",
"spent",
",",
"&",
"sent",
",",
"&",
"fees",
",",
"&",
"numVin",
",",
"&",
"vinDbIDs",
",",
"&",
"numVout",
",",
"&",
"voutDbIDs",
",",
"&",
"isValidBlock",
",",
"&",
"isMainchainBlock",
")",
"\n",
"return",
"\n",
"}"
] | // RetrieveFullTxByHash gets all data from the transactions table for the
// transaction specified by its hash. Transactions in valid and mainchain blocks
// are chosen first. See also RetrieveDbTxByHash. | [
"RetrieveFullTxByHash",
"gets",
"all",
"data",
"from",
"the",
"transactions",
"table",
"for",
"the",
"transaction",
"specified",
"by",
"its",
"hash",
".",
"Transactions",
"in",
"valid",
"and",
"mainchain",
"blocks",
"are",
"chosen",
"first",
".",
"See",
"also",
"RetrieveDbTxByHash",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2801-L2814 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveTxnsVinsByBlock | func RetrieveTxnsVinsByBlock(ctx context.Context, db *sql.DB, blockHash string) (vinDbIDs []dbtypes.UInt64Array,
areValid []bool, areMainchain []bool, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectTxnsVinsByBlock, blockHash)
if err != nil {
return
}
defer closeRows(rows)
for rows.Next() {
var ids dbtypes.UInt64Array
var isValid, isMainchain bool
err = rows.Scan(&ids, &isValid, &isMainchain)
if err != nil {
break
}
vinDbIDs = append(vinDbIDs, ids)
areValid = append(areValid, isValid)
areMainchain = append(areMainchain, isMainchain)
}
return
} | go | func RetrieveTxnsVinsByBlock(ctx context.Context, db *sql.DB, blockHash string) (vinDbIDs []dbtypes.UInt64Array,
areValid []bool, areMainchain []bool, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectTxnsVinsByBlock, blockHash)
if err != nil {
return
}
defer closeRows(rows)
for rows.Next() {
var ids dbtypes.UInt64Array
var isValid, isMainchain bool
err = rows.Scan(&ids, &isValid, &isMainchain)
if err != nil {
break
}
vinDbIDs = append(vinDbIDs, ids)
areValid = append(areValid, isValid)
areMainchain = append(areMainchain, isMainchain)
}
return
} | [
"func",
"RetrieveTxnsVinsByBlock",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"blockHash",
"string",
")",
"(",
"vinDbIDs",
"[",
"]",
"dbtypes",
".",
"UInt64Array",
",",
"areValid",
"[",
"]",
"bool",
",",
"areMainchain",
"[",
"]",
"bool",
",",
"err",
"error",
")",
"{",
"var",
"rows",
"*",
"sql",
".",
"Rows",
"\n",
"rows",
",",
"err",
"=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectTxnsVinsByBlock",
",",
"blockHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"ids",
"dbtypes",
".",
"UInt64Array",
"\n",
"var",
"isValid",
",",
"isMainchain",
"bool",
"\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"ids",
",",
"&",
"isValid",
",",
"&",
"isMainchain",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"vinDbIDs",
"=",
"append",
"(",
"vinDbIDs",
",",
"ids",
")",
"\n",
"areValid",
"=",
"append",
"(",
"areValid",
",",
"isValid",
")",
"\n",
"areMainchain",
"=",
"append",
"(",
"areMainchain",
",",
"isMainchain",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // RetrieveTxnsVinsByBlock retrieves for all the transactions in the specified
// block the vin_db_ids arrays, is_valid, and is_mainchain. This function is
// used by handleVinsTableMainchainupgrade, so it should not be subject to
// timeouts. | [
"RetrieveTxnsVinsByBlock",
"retrieves",
"for",
"all",
"the",
"transactions",
"in",
"the",
"specified",
"block",
"the",
"vin_db_ids",
"arrays",
"is_valid",
"and",
"is_mainchain",
".",
"This",
"function",
"is",
"used",
"by",
"handleVinsTableMainchainupgrade",
"so",
"it",
"should",
"not",
"be",
"subject",
"to",
"timeouts",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2857-L2879 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveTxnsVinsVoutsByBlock | func RetrieveTxnsVinsVoutsByBlock(ctx context.Context, db *sql.DB, blockHash string, onlyRegular bool) (vinDbIDs, voutDbIDs []dbtypes.UInt64Array,
areMainchain []bool, err error) {
stmt := internal.SelectTxnsVinsVoutsByBlock
if onlyRegular {
stmt = internal.SelectRegularTxnsVinsVoutsByBlock
}
var rows *sql.Rows
rows, err = db.QueryContext(ctx, stmt, blockHash)
if err != nil {
return
}
defer closeRows(rows)
for rows.Next() {
var vinIDs, voutIDs dbtypes.UInt64Array
var isMainchain bool
err = rows.Scan(&vinIDs, &voutIDs, &isMainchain)
if err != nil {
break
}
vinDbIDs = append(vinDbIDs, vinIDs)
voutDbIDs = append(voutDbIDs, voutIDs)
areMainchain = append(areMainchain, isMainchain)
}
return
} | go | func RetrieveTxnsVinsVoutsByBlock(ctx context.Context, db *sql.DB, blockHash string, onlyRegular bool) (vinDbIDs, voutDbIDs []dbtypes.UInt64Array,
areMainchain []bool, err error) {
stmt := internal.SelectTxnsVinsVoutsByBlock
if onlyRegular {
stmt = internal.SelectRegularTxnsVinsVoutsByBlock
}
var rows *sql.Rows
rows, err = db.QueryContext(ctx, stmt, blockHash)
if err != nil {
return
}
defer closeRows(rows)
for rows.Next() {
var vinIDs, voutIDs dbtypes.UInt64Array
var isMainchain bool
err = rows.Scan(&vinIDs, &voutIDs, &isMainchain)
if err != nil {
break
}
vinDbIDs = append(vinDbIDs, vinIDs)
voutDbIDs = append(voutDbIDs, voutIDs)
areMainchain = append(areMainchain, isMainchain)
}
return
} | [
"func",
"RetrieveTxnsVinsVoutsByBlock",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"blockHash",
"string",
",",
"onlyRegular",
"bool",
")",
"(",
"vinDbIDs",
",",
"voutDbIDs",
"[",
"]",
"dbtypes",
".",
"UInt64Array",
",",
"areMainchain",
"[",
"]",
"bool",
",",
"err",
"error",
")",
"{",
"stmt",
":=",
"internal",
".",
"SelectTxnsVinsVoutsByBlock",
"\n",
"if",
"onlyRegular",
"{",
"stmt",
"=",
"internal",
".",
"SelectRegularTxnsVinsVoutsByBlock",
"\n",
"}",
"\n\n",
"var",
"rows",
"*",
"sql",
".",
"Rows",
"\n",
"rows",
",",
"err",
"=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"stmt",
",",
"blockHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"vinIDs",
",",
"voutIDs",
"dbtypes",
".",
"UInt64Array",
"\n",
"var",
"isMainchain",
"bool",
"\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"vinIDs",
",",
"&",
"voutIDs",
",",
"&",
"isMainchain",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"vinDbIDs",
"=",
"append",
"(",
"vinDbIDs",
",",
"vinIDs",
")",
"\n",
"voutDbIDs",
"=",
"append",
"(",
"voutDbIDs",
",",
"voutIDs",
")",
"\n",
"areMainchain",
"=",
"append",
"(",
"areMainchain",
",",
"isMainchain",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // RetrieveTxnsVinsVoutsByBlock retrieves for all the transactions in the
// specified block the vin_db_ids and vout_db_ids arrays. This function is used
// only by UpdateLastAddressesValid and other setting functions, where it should
// not be subject to a timeout. | [
"RetrieveTxnsVinsVoutsByBlock",
"retrieves",
"for",
"all",
"the",
"transactions",
"in",
"the",
"specified",
"block",
"the",
"vin_db_ids",
"and",
"vout_db_ids",
"arrays",
".",
"This",
"function",
"is",
"used",
"only",
"by",
"UpdateLastAddressesValid",
"and",
"other",
"setting",
"functions",
"where",
"it",
"should",
"not",
"be",
"subject",
"to",
"a",
"timeout",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2885-L2912 | train |
decred/dcrdata | db/dcrpg/queries.go | RetrieveTxsByBlockHash | func RetrieveTxsByBlockHash(ctx context.Context, db *sql.DB, blockHash string) (ids []uint64, txs []string,
blockInds []uint32, trees []int8, blockTimes []dbtypes.TimeDef, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectTxsByBlockHash, blockHash)
if err != nil {
return
}
defer closeRows(rows)
for rows.Next() {
var id uint64
var blockTime dbtypes.TimeDef
var tx string
var bind uint32
var tree int8
err = rows.Scan(&id, &tx, &bind, &tree, &blockTime)
if err != nil {
break
}
ids = append(ids, id)
txs = append(txs, tx)
blockInds = append(blockInds, bind)
trees = append(trees, tree)
blockTimes = append(blockTimes, blockTime)
}
return
} | go | func RetrieveTxsByBlockHash(ctx context.Context, db *sql.DB, blockHash string) (ids []uint64, txs []string,
blockInds []uint32, trees []int8, blockTimes []dbtypes.TimeDef, err error) {
var rows *sql.Rows
rows, err = db.QueryContext(ctx, internal.SelectTxsByBlockHash, blockHash)
if err != nil {
return
}
defer closeRows(rows)
for rows.Next() {
var id uint64
var blockTime dbtypes.TimeDef
var tx string
var bind uint32
var tree int8
err = rows.Scan(&id, &tx, &bind, &tree, &blockTime)
if err != nil {
break
}
ids = append(ids, id)
txs = append(txs, tx)
blockInds = append(blockInds, bind)
trees = append(trees, tree)
blockTimes = append(blockTimes, blockTime)
}
return
} | [
"func",
"RetrieveTxsByBlockHash",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"blockHash",
"string",
")",
"(",
"ids",
"[",
"]",
"uint64",
",",
"txs",
"[",
"]",
"string",
",",
"blockInds",
"[",
"]",
"uint32",
",",
"trees",
"[",
"]",
"int8",
",",
"blockTimes",
"[",
"]",
"dbtypes",
".",
"TimeDef",
",",
"err",
"error",
")",
"{",
"var",
"rows",
"*",
"sql",
".",
"Rows",
"\n",
"rows",
",",
"err",
"=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectTxsByBlockHash",
",",
"blockHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"id",
"uint64",
"\n",
"var",
"blockTime",
"dbtypes",
".",
"TimeDef",
"\n",
"var",
"tx",
"string",
"\n",
"var",
"bind",
"uint32",
"\n",
"var",
"tree",
"int8",
"\n",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"id",
",",
"&",
"tx",
",",
"&",
"bind",
",",
"&",
"tree",
",",
"&",
"blockTime",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"ids",
"=",
"append",
"(",
"ids",
",",
"id",
")",
"\n",
"txs",
"=",
"append",
"(",
"txs",
",",
"tx",
")",
"\n",
"blockInds",
"=",
"append",
"(",
"blockInds",
",",
"bind",
")",
"\n",
"trees",
"=",
"append",
"(",
"trees",
",",
"tree",
")",
"\n",
"blockTimes",
"=",
"append",
"(",
"blockTimes",
",",
"blockTime",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // RetrieveTxsByBlockHash retrieves all transactions in a given block. This is
// used by update functions, so care should be taken to not timeout in these
// cases. | [
"RetrieveTxsByBlockHash",
"retrieves",
"all",
"transactions",
"in",
"a",
"given",
"block",
".",
"This",
"is",
"used",
"by",
"update",
"functions",
"so",
"care",
"should",
"be",
"taken",
"to",
"not",
"timeout",
"in",
"these",
"cases",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L2928-L2956 | train |
decred/dcrdata | db/dcrpg/queries.go | appendChartBlocks | func appendChartBlocks(charts *cache.ChartData, rows *sql.Rows) error {
defer closeRows(rows)
// In order to store chainwork values as uint64, they are represented
// as exahash (10^18) for work, and terahash/s (10^12) for hashrate.
bigExa := big.NewInt(int64(1e18))
badRows := 0
// badRow is used to log chainwork errors without returning an error from
// retrieveChartBlocks.
badRow := func() {
badRows++
}
var timeDef dbtypes.TimeDef
var workhex string
var count, size, height uint64
var rowCount int32
blocks := charts.Blocks
for rows.Next() {
rowCount++
// Get the chainwork.
err := rows.Scan(&height, &size, &timeDef, &workhex, &count)
if err != nil {
return err
}
bigwork, ok := new(big.Int).SetString(workhex, 16)
if !ok {
badRow()
continue
}
bigwork.Div(bigwork, bigExa)
if !bigwork.IsUint64() {
badRow()
// Something is wrong, but pretend that no work was done to keep the
// datasets sized properly.
bigwork = big.NewInt(int64(blocks.Chainwork[len(blocks.Chainwork)-1]))
}
blocks.Chainwork = append(blocks.Chainwork, bigwork.Uint64())
blocks.TxCount = append(blocks.TxCount, count)
blocks.Time = append(blocks.Time, uint64(timeDef.T.Unix()))
blocks.BlockSize = append(blocks.BlockSize, size)
}
if badRows > 0 {
log.Errorf("%d rows have invalid chainwork values.", badRows)
}
chainLen := len(blocks.Chainwork)
if rowCount > 0 && uint64(chainLen-1) != height {
return fmt.Errorf("retrieveChartBlocks: height misalignment. last height = %d. data length = %d", height, chainLen)
}
if len(blocks.Time) != chainLen || len(blocks.TxCount) != chainLen {
return fmt.Errorf("retrieveChartBlocks: data length misalignment. len(chainwork) = %d, len(stamps) = %d, len(counts) = %d",
chainLen, len(blocks.Time), len(blocks.TxCount))
}
return nil
} | go | func appendChartBlocks(charts *cache.ChartData, rows *sql.Rows) error {
defer closeRows(rows)
// In order to store chainwork values as uint64, they are represented
// as exahash (10^18) for work, and terahash/s (10^12) for hashrate.
bigExa := big.NewInt(int64(1e18))
badRows := 0
// badRow is used to log chainwork errors without returning an error from
// retrieveChartBlocks.
badRow := func() {
badRows++
}
var timeDef dbtypes.TimeDef
var workhex string
var count, size, height uint64
var rowCount int32
blocks := charts.Blocks
for rows.Next() {
rowCount++
// Get the chainwork.
err := rows.Scan(&height, &size, &timeDef, &workhex, &count)
if err != nil {
return err
}
bigwork, ok := new(big.Int).SetString(workhex, 16)
if !ok {
badRow()
continue
}
bigwork.Div(bigwork, bigExa)
if !bigwork.IsUint64() {
badRow()
// Something is wrong, but pretend that no work was done to keep the
// datasets sized properly.
bigwork = big.NewInt(int64(blocks.Chainwork[len(blocks.Chainwork)-1]))
}
blocks.Chainwork = append(blocks.Chainwork, bigwork.Uint64())
blocks.TxCount = append(blocks.TxCount, count)
blocks.Time = append(blocks.Time, uint64(timeDef.T.Unix()))
blocks.BlockSize = append(blocks.BlockSize, size)
}
if badRows > 0 {
log.Errorf("%d rows have invalid chainwork values.", badRows)
}
chainLen := len(blocks.Chainwork)
if rowCount > 0 && uint64(chainLen-1) != height {
return fmt.Errorf("retrieveChartBlocks: height misalignment. last height = %d. data length = %d", height, chainLen)
}
if len(blocks.Time) != chainLen || len(blocks.TxCount) != chainLen {
return fmt.Errorf("retrieveChartBlocks: data length misalignment. len(chainwork) = %d, len(stamps) = %d, len(counts) = %d",
chainLen, len(blocks.Time), len(blocks.TxCount))
}
return nil
} | [
"func",
"appendChartBlocks",
"(",
"charts",
"*",
"cache",
".",
"ChartData",
",",
"rows",
"*",
"sql",
".",
"Rows",
")",
"error",
"{",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"// In order to store chainwork values as uint64, they are represented",
"// as exahash (10^18) for work, and terahash/s (10^12) for hashrate.",
"bigExa",
":=",
"big",
".",
"NewInt",
"(",
"int64",
"(",
"1e18",
")",
")",
"\n",
"badRows",
":=",
"0",
"\n",
"// badRow is used to log chainwork errors without returning an error from",
"// retrieveChartBlocks.",
"badRow",
":=",
"func",
"(",
")",
"{",
"badRows",
"++",
"\n",
"}",
"\n\n",
"var",
"timeDef",
"dbtypes",
".",
"TimeDef",
"\n",
"var",
"workhex",
"string",
"\n",
"var",
"count",
",",
"size",
",",
"height",
"uint64",
"\n",
"var",
"rowCount",
"int32",
"\n",
"blocks",
":=",
"charts",
".",
"Blocks",
"\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"rowCount",
"++",
"\n",
"// Get the chainwork.",
"err",
":=",
"rows",
".",
"Scan",
"(",
"&",
"height",
",",
"&",
"size",
",",
"&",
"timeDef",
",",
"&",
"workhex",
",",
"&",
"count",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"bigwork",
",",
"ok",
":=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"SetString",
"(",
"workhex",
",",
"16",
")",
"\n",
"if",
"!",
"ok",
"{",
"badRow",
"(",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"bigwork",
".",
"Div",
"(",
"bigwork",
",",
"bigExa",
")",
"\n",
"if",
"!",
"bigwork",
".",
"IsUint64",
"(",
")",
"{",
"badRow",
"(",
")",
"\n",
"// Something is wrong, but pretend that no work was done to keep the",
"// datasets sized properly.",
"bigwork",
"=",
"big",
".",
"NewInt",
"(",
"int64",
"(",
"blocks",
".",
"Chainwork",
"[",
"len",
"(",
"blocks",
".",
"Chainwork",
")",
"-",
"1",
"]",
")",
")",
"\n",
"}",
"\n",
"blocks",
".",
"Chainwork",
"=",
"append",
"(",
"blocks",
".",
"Chainwork",
",",
"bigwork",
".",
"Uint64",
"(",
")",
")",
"\n",
"blocks",
".",
"TxCount",
"=",
"append",
"(",
"blocks",
".",
"TxCount",
",",
"count",
")",
"\n",
"blocks",
".",
"Time",
"=",
"append",
"(",
"blocks",
".",
"Time",
",",
"uint64",
"(",
"timeDef",
".",
"T",
".",
"Unix",
"(",
")",
")",
")",
"\n",
"blocks",
".",
"BlockSize",
"=",
"append",
"(",
"blocks",
".",
"BlockSize",
",",
"size",
")",
"\n",
"}",
"\n",
"if",
"badRows",
">",
"0",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"badRows",
")",
"\n",
"}",
"\n",
"chainLen",
":=",
"len",
"(",
"blocks",
".",
"Chainwork",
")",
"\n",
"if",
"rowCount",
">",
"0",
"&&",
"uint64",
"(",
"chainLen",
"-",
"1",
")",
"!=",
"height",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"height",
",",
"chainLen",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"blocks",
".",
"Time",
")",
"!=",
"chainLen",
"||",
"len",
"(",
"blocks",
".",
"TxCount",
")",
"!=",
"chainLen",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"chainLen",
",",
"len",
"(",
"blocks",
".",
"Time",
")",
",",
"len",
"(",
"blocks",
".",
"TxCount",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Append the results from retrieveChartBlocks to the provided ChartData.
// This is the Appender half of a pair that make up a cache.ChartUpdater. | [
"Append",
"the",
"results",
"from",
"retrieveChartBlocks",
"to",
"the",
"provided",
"ChartData",
".",
"This",
"is",
"the",
"Appender",
"half",
"of",
"a",
"pair",
"that",
"make",
"up",
"a",
"cache",
".",
"ChartUpdater",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3001-L3057 | train |
decred/dcrdata | db/dcrpg/queries.go | appendWindowStats | func appendWindowStats(charts *cache.ChartData, rows *sql.Rows) error {
defer closeRows(rows)
windows := charts.Windows
for rows.Next() {
var timestamp time.Time
var price uint64
var difficulty float64
if err := rows.Scan(&price, ×tamp, &difficulty); err != nil {
return err
}
windows.TicketPrice = append(windows.TicketPrice, price)
windows.PowDiff = append(windows.PowDiff, difficulty)
windows.Time = append(windows.Time, uint64(timestamp.Unix()))
}
return nil
} | go | func appendWindowStats(charts *cache.ChartData, rows *sql.Rows) error {
defer closeRows(rows)
windows := charts.Windows
for rows.Next() {
var timestamp time.Time
var price uint64
var difficulty float64
if err := rows.Scan(&price, ×tamp, &difficulty); err != nil {
return err
}
windows.TicketPrice = append(windows.TicketPrice, price)
windows.PowDiff = append(windows.PowDiff, difficulty)
windows.Time = append(windows.Time, uint64(timestamp.Unix()))
}
return nil
} | [
"func",
"appendWindowStats",
"(",
"charts",
"*",
"cache",
".",
"ChartData",
",",
"rows",
"*",
"sql",
".",
"Rows",
")",
"error",
"{",
"defer",
"closeRows",
"(",
"rows",
")",
"\n",
"windows",
":=",
"charts",
".",
"Windows",
"\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"timestamp",
"time",
".",
"Time",
"\n",
"var",
"price",
"uint64",
"\n",
"var",
"difficulty",
"float64",
"\n",
"if",
"err",
":=",
"rows",
".",
"Scan",
"(",
"&",
"price",
",",
"&",
"timestamp",
",",
"&",
"difficulty",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"windows",
".",
"TicketPrice",
"=",
"append",
"(",
"windows",
".",
"TicketPrice",
",",
"price",
")",
"\n",
"windows",
".",
"PowDiff",
"=",
"append",
"(",
"windows",
".",
"PowDiff",
",",
"difficulty",
")",
"\n",
"windows",
".",
"Time",
"=",
"append",
"(",
"windows",
".",
"Time",
",",
"uint64",
"(",
"timestamp",
".",
"Unix",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Appends the results from retrieveWindowStats to the provided ChartData.
// This is the Appender half of a pair that make up a cache.ChartUpdater. | [
"Appends",
"the",
"results",
"from",
"retrieveWindowStats",
"to",
"the",
"provided",
"ChartData",
".",
"This",
"is",
"the",
"Appender",
"half",
"of",
"a",
"pair",
"that",
"make",
"up",
"a",
"cache",
".",
"ChartUpdater",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3076-L3092 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveCoinSupply | func retrieveCoinSupply(ctx context.Context, db *sql.DB, charts *cache.ChartData) (*sql.Rows, error) {
rows, err := db.QueryContext(ctx, internal.SelectCoinSupply, charts.NewAtomsTip())
if err != nil {
return nil, err
}
return rows, nil
} | go | func retrieveCoinSupply(ctx context.Context, db *sql.DB, charts *cache.ChartData) (*sql.Rows, error) {
rows, err := db.QueryContext(ctx, internal.SelectCoinSupply, charts.NewAtomsTip())
if err != nil {
return nil, err
}
return rows, nil
} | [
"func",
"retrieveCoinSupply",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"charts",
"*",
"cache",
".",
"ChartData",
")",
"(",
"*",
"sql",
".",
"Rows",
",",
"error",
")",
"{",
"rows",
",",
"err",
":=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectCoinSupply",
",",
"charts",
".",
"NewAtomsTip",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"rows",
",",
"nil",
"\n",
"}"
] | // retrieveCoinSupply fetches the coin supply data from the vins table. | [
"retrieveCoinSupply",
"fetches",
"the",
"coin",
"supply",
"data",
"from",
"the",
"vins",
"table",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3095-L3101 | train |
decred/dcrdata | db/dcrpg/queries.go | appendCoinSupply | func appendCoinSupply(charts *cache.ChartData, rows *sql.Rows) error {
defer closeRows(rows)
blocks := charts.Blocks
for rows.Next() {
var value int64
var timestamp time.Time
if err := rows.Scan(×tamp, &value); err != nil {
return err
}
blocks.NewAtoms = append(blocks.NewAtoms, uint64(value))
}
// Set the genesis block to zero because the DB stores it as -1
if len(blocks.NewAtoms) > 0 {
blocks.NewAtoms[0] = 0
}
return nil
} | go | func appendCoinSupply(charts *cache.ChartData, rows *sql.Rows) error {
defer closeRows(rows)
blocks := charts.Blocks
for rows.Next() {
var value int64
var timestamp time.Time
if err := rows.Scan(×tamp, &value); err != nil {
return err
}
blocks.NewAtoms = append(blocks.NewAtoms, uint64(value))
}
// Set the genesis block to zero because the DB stores it as -1
if len(blocks.NewAtoms) > 0 {
blocks.NewAtoms[0] = 0
}
return nil
} | [
"func",
"appendCoinSupply",
"(",
"charts",
"*",
"cache",
".",
"ChartData",
",",
"rows",
"*",
"sql",
".",
"Rows",
")",
"error",
"{",
"defer",
"closeRows",
"(",
"rows",
")",
"\n",
"blocks",
":=",
"charts",
".",
"Blocks",
"\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"value",
"int64",
"\n",
"var",
"timestamp",
"time",
".",
"Time",
"\n",
"if",
"err",
":=",
"rows",
".",
"Scan",
"(",
"&",
"timestamp",
",",
"&",
"value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"blocks",
".",
"NewAtoms",
"=",
"append",
"(",
"blocks",
".",
"NewAtoms",
",",
"uint64",
"(",
"value",
")",
")",
"\n",
"}",
"\n",
"// Set the genesis block to zero because the DB stores it as -1",
"if",
"len",
"(",
"blocks",
".",
"NewAtoms",
")",
">",
"0",
"{",
"blocks",
".",
"NewAtoms",
"[",
"0",
"]",
"=",
"0",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Append the results from retrieveCoinSupply to the provided ChartData.
// This is the Appender half of a pair that make up a cache.ChartUpdater. | [
"Append",
"the",
"results",
"from",
"retrieveCoinSupply",
"to",
"the",
"provided",
"ChartData",
".",
"This",
"is",
"the",
"Appender",
"half",
"of",
"a",
"pair",
"that",
"make",
"up",
"a",
"cache",
".",
"ChartUpdater",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3105-L3122 | train |
decred/dcrdata | db/dcrpg/queries.go | retrievePowerlessTickets | func retrievePowerlessTickets(ctx context.Context, db *sql.DB) (*apitypes.PowerlessTickets, error) {
rows, err := db.QueryContext(ctx, internal.SelectTicketSpendTypeByBlock, -1)
if err != nil {
return nil, err
}
defer closeRows(rows)
unspentType := int16(dbtypes.TicketUnspent)
revokedType := int16(dbtypes.TicketRevoked)
revoked := make([]apitypes.PowerlessTicket, 0)
unspent := make([]apitypes.PowerlessTicket, 0)
for rows.Next() {
var height uint32
var spendType int16
var price float64
if err = rows.Scan(&height, &spendType, &price); err != nil {
return nil, err
}
ticket := apitypes.PowerlessTicket{
Height: height,
Price: price,
}
switch spendType {
case unspentType:
unspent = append(unspent, ticket)
case revokedType:
revoked = append(revoked, ticket)
}
}
return &apitypes.PowerlessTickets{
Revoked: revoked,
Unspent: unspent,
}, nil
} | go | func retrievePowerlessTickets(ctx context.Context, db *sql.DB) (*apitypes.PowerlessTickets, error) {
rows, err := db.QueryContext(ctx, internal.SelectTicketSpendTypeByBlock, -1)
if err != nil {
return nil, err
}
defer closeRows(rows)
unspentType := int16(dbtypes.TicketUnspent)
revokedType := int16(dbtypes.TicketRevoked)
revoked := make([]apitypes.PowerlessTicket, 0)
unspent := make([]apitypes.PowerlessTicket, 0)
for rows.Next() {
var height uint32
var spendType int16
var price float64
if err = rows.Scan(&height, &spendType, &price); err != nil {
return nil, err
}
ticket := apitypes.PowerlessTicket{
Height: height,
Price: price,
}
switch spendType {
case unspentType:
unspent = append(unspent, ticket)
case revokedType:
revoked = append(revoked, ticket)
}
}
return &apitypes.PowerlessTickets{
Revoked: revoked,
Unspent: unspent,
}, nil
} | [
"func",
"retrievePowerlessTickets",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"*",
"apitypes",
".",
"PowerlessTickets",
",",
"error",
")",
"{",
"rows",
",",
"err",
":=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectTicketSpendTypeByBlock",
",",
"-",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"unspentType",
":=",
"int16",
"(",
"dbtypes",
".",
"TicketUnspent",
")",
"\n",
"revokedType",
":=",
"int16",
"(",
"dbtypes",
".",
"TicketRevoked",
")",
"\n",
"revoked",
":=",
"make",
"(",
"[",
"]",
"apitypes",
".",
"PowerlessTicket",
",",
"0",
")",
"\n",
"unspent",
":=",
"make",
"(",
"[",
"]",
"apitypes",
".",
"PowerlessTicket",
",",
"0",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"height",
"uint32",
"\n",
"var",
"spendType",
"int16",
"\n",
"var",
"price",
"float64",
"\n",
"if",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"height",
",",
"&",
"spendType",
",",
"&",
"price",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"ticket",
":=",
"apitypes",
".",
"PowerlessTicket",
"{",
"Height",
":",
"height",
",",
"Price",
":",
"price",
",",
"}",
"\n",
"switch",
"spendType",
"{",
"case",
"unspentType",
":",
"unspent",
"=",
"append",
"(",
"unspent",
",",
"ticket",
")",
"\n",
"case",
"revokedType",
":",
"revoked",
"=",
"append",
"(",
"revoked",
",",
"ticket",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"apitypes",
".",
"PowerlessTickets",
"{",
"Revoked",
":",
"revoked",
",",
"Unspent",
":",
"unspent",
",",
"}",
",",
"nil",
"\n",
"}"
] | // retrievePowerlessTickets fetches missed or expired tickets sorted by
// revocation status. | [
"retrievePowerlessTickets",
"fetches",
"missed",
"or",
"expired",
"tickets",
"sorted",
"by",
"revocation",
"status",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3126-L3160 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveTxPerDay | func retrieveTxPerDay(ctx context.Context, db *sql.DB, timeArr []dbtypes.TimeDef,
txCountArr []uint64) ([]dbtypes.TimeDef, []uint64, error) {
var since time.Time
if c := len(timeArr); c > 0 {
since = timeArr[c-1].T
// delete the last entry to avoid duplicates
timeArr = timeArr[:c-1]
txCountArr = txCountArr[:c-1]
}
rows, err := db.QueryContext(ctx, internal.SelectTxsPerDay, since)
if err != nil {
return timeArr, txCountArr, err
}
defer closeRows(rows)
for rows.Next() {
var blockTime time.Time
var count uint64
if err = rows.Scan(&blockTime, &count); err != nil {
return timeArr, txCountArr, err
}
timeArr = append(timeArr, dbtypes.NewTimeDef(blockTime))
txCountArr = append(txCountArr, count)
}
return timeArr, txCountArr, nil
} | go | func retrieveTxPerDay(ctx context.Context, db *sql.DB, timeArr []dbtypes.TimeDef,
txCountArr []uint64) ([]dbtypes.TimeDef, []uint64, error) {
var since time.Time
if c := len(timeArr); c > 0 {
since = timeArr[c-1].T
// delete the last entry to avoid duplicates
timeArr = timeArr[:c-1]
txCountArr = txCountArr[:c-1]
}
rows, err := db.QueryContext(ctx, internal.SelectTxsPerDay, since)
if err != nil {
return timeArr, txCountArr, err
}
defer closeRows(rows)
for rows.Next() {
var blockTime time.Time
var count uint64
if err = rows.Scan(&blockTime, &count); err != nil {
return timeArr, txCountArr, err
}
timeArr = append(timeArr, dbtypes.NewTimeDef(blockTime))
txCountArr = append(txCountArr, count)
}
return timeArr, txCountArr, nil
} | [
"func",
"retrieveTxPerDay",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"timeArr",
"[",
"]",
"dbtypes",
".",
"TimeDef",
",",
"txCountArr",
"[",
"]",
"uint64",
")",
"(",
"[",
"]",
"dbtypes",
".",
"TimeDef",
",",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"var",
"since",
"time",
".",
"Time",
"\n\n",
"if",
"c",
":=",
"len",
"(",
"timeArr",
")",
";",
"c",
">",
"0",
"{",
"since",
"=",
"timeArr",
"[",
"c",
"-",
"1",
"]",
".",
"T",
"\n\n",
"// delete the last entry to avoid duplicates",
"timeArr",
"=",
"timeArr",
"[",
":",
"c",
"-",
"1",
"]",
"\n",
"txCountArr",
"=",
"txCountArr",
"[",
":",
"c",
"-",
"1",
"]",
"\n",
"}",
"\n\n",
"rows",
",",
"err",
":=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectTxsPerDay",
",",
"since",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"timeArr",
",",
"txCountArr",
",",
"err",
"\n",
"}",
"\n\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"blockTime",
"time",
".",
"Time",
"\n",
"var",
"count",
"uint64",
"\n",
"if",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"blockTime",
",",
"&",
"count",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"timeArr",
",",
"txCountArr",
",",
"err",
"\n",
"}",
"\n\n",
"timeArr",
"=",
"append",
"(",
"timeArr",
",",
"dbtypes",
".",
"NewTimeDef",
"(",
"blockTime",
")",
")",
"\n",
"txCountArr",
"=",
"append",
"(",
"txCountArr",
",",
"count",
")",
"\n",
"}",
"\n",
"return",
"timeArr",
",",
"txCountArr",
",",
"nil",
"\n",
"}"
] | // retrieveTxPerDay fetches data for tx-per-day chart from the blocks table. | [
"retrieveTxPerDay",
"fetches",
"data",
"for",
"tx",
"-",
"per",
"-",
"day",
"chart",
"from",
"the",
"blocks",
"table",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3163-L3193 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveTicketByOutputCount | func retrieveTicketByOutputCount(ctx context.Context, db *sql.DB, interval int64,
dataType outputCountType, heightArr, soloArr, pooledArr []uint64) ([]uint64,
[]uint64, []uint64, error) {
var since uint64
if c := len(heightArr); c > 0 {
since = heightArr[c-1]
// drop the last entry to avoid duplication.
if dataType == outputCountByTicketPoolWindow {
heightArr = heightArr[:c-1]
soloArr = soloArr[:c-1]
pooledArr = pooledArr[:c-1]
}
}
var query string
var args []interface{}
switch dataType {
case outputCountByAllBlocks:
query = internal.SelectTicketsOutputCountByAllBlocks
args = []interface{}{stake.TxTypeSStx, since}
case outputCountByTicketPoolWindow:
query = internal.SelectTicketsOutputCountByTPWindow
since = since * uint64(interval)
args = []interface{}{stake.TxTypeSStx, since, interval}
default:
return heightArr, soloArr, pooledArr,
fmt.Errorf("unknown output count type '%v'", dataType)
}
rows, err := db.QueryContext(ctx, query, args...)
if err != nil {
return heightArr, soloArr, pooledArr, err
}
defer closeRows(rows)
for rows.Next() {
var height, solo, pooled uint64
if err = rows.Scan(&height, &solo, &pooled); err != nil {
return heightArr, soloArr, pooledArr, err
}
heightArr = append(heightArr, height)
soloArr = append(soloArr, solo)
pooledArr = append(pooledArr, pooled)
}
return heightArr, soloArr, pooledArr, nil
} | go | func retrieveTicketByOutputCount(ctx context.Context, db *sql.DB, interval int64,
dataType outputCountType, heightArr, soloArr, pooledArr []uint64) ([]uint64,
[]uint64, []uint64, error) {
var since uint64
if c := len(heightArr); c > 0 {
since = heightArr[c-1]
// drop the last entry to avoid duplication.
if dataType == outputCountByTicketPoolWindow {
heightArr = heightArr[:c-1]
soloArr = soloArr[:c-1]
pooledArr = pooledArr[:c-1]
}
}
var query string
var args []interface{}
switch dataType {
case outputCountByAllBlocks:
query = internal.SelectTicketsOutputCountByAllBlocks
args = []interface{}{stake.TxTypeSStx, since}
case outputCountByTicketPoolWindow:
query = internal.SelectTicketsOutputCountByTPWindow
since = since * uint64(interval)
args = []interface{}{stake.TxTypeSStx, since, interval}
default:
return heightArr, soloArr, pooledArr,
fmt.Errorf("unknown output count type '%v'", dataType)
}
rows, err := db.QueryContext(ctx, query, args...)
if err != nil {
return heightArr, soloArr, pooledArr, err
}
defer closeRows(rows)
for rows.Next() {
var height, solo, pooled uint64
if err = rows.Scan(&height, &solo, &pooled); err != nil {
return heightArr, soloArr, pooledArr, err
}
heightArr = append(heightArr, height)
soloArr = append(soloArr, solo)
pooledArr = append(pooledArr, pooled)
}
return heightArr, soloArr, pooledArr, nil
} | [
"func",
"retrieveTicketByOutputCount",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"interval",
"int64",
",",
"dataType",
"outputCountType",
",",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
"[",
"]",
"uint64",
")",
"(",
"[",
"]",
"uint64",
",",
"[",
"]",
"uint64",
",",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"var",
"since",
"uint64",
"\n\n",
"if",
"c",
":=",
"len",
"(",
"heightArr",
")",
";",
"c",
">",
"0",
"{",
"since",
"=",
"heightArr",
"[",
"c",
"-",
"1",
"]",
"\n\n",
"// drop the last entry to avoid duplication.",
"if",
"dataType",
"==",
"outputCountByTicketPoolWindow",
"{",
"heightArr",
"=",
"heightArr",
"[",
":",
"c",
"-",
"1",
"]",
"\n",
"soloArr",
"=",
"soloArr",
"[",
":",
"c",
"-",
"1",
"]",
"\n",
"pooledArr",
"=",
"pooledArr",
"[",
":",
"c",
"-",
"1",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"var",
"query",
"string",
"\n",
"var",
"args",
"[",
"]",
"interface",
"{",
"}",
"\n",
"switch",
"dataType",
"{",
"case",
"outputCountByAllBlocks",
":",
"query",
"=",
"internal",
".",
"SelectTicketsOutputCountByAllBlocks",
"\n",
"args",
"=",
"[",
"]",
"interface",
"{",
"}",
"{",
"stake",
".",
"TxTypeSStx",
",",
"since",
"}",
"\n\n",
"case",
"outputCountByTicketPoolWindow",
":",
"query",
"=",
"internal",
".",
"SelectTicketsOutputCountByTPWindow",
"\n",
"since",
"=",
"since",
"*",
"uint64",
"(",
"interval",
")",
"\n",
"args",
"=",
"[",
"]",
"interface",
"{",
"}",
"{",
"stake",
".",
"TxTypeSStx",
",",
"since",
",",
"interval",
"}",
"\n\n",
"default",
":",
"return",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dataType",
")",
"\n",
"}",
"\n\n",
"rows",
",",
"err",
":=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"query",
",",
"args",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
",",
"err",
"\n",
"}",
"\n\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"height",
",",
"solo",
",",
"pooled",
"uint64",
"\n",
"if",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"height",
",",
"&",
"solo",
",",
"&",
"pooled",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
",",
"err",
"\n",
"}",
"\n\n",
"heightArr",
"=",
"append",
"(",
"heightArr",
",",
"height",
")",
"\n",
"soloArr",
"=",
"append",
"(",
"soloArr",
",",
"solo",
")",
"\n",
"pooledArr",
"=",
"append",
"(",
"pooledArr",
",",
"pooled",
")",
"\n",
"}",
"\n\n",
"return",
"heightArr",
",",
"soloArr",
",",
"pooledArr",
",",
"nil",
"\n",
"}"
] | // retrieveTicketByOutputCount fetches the data for ticket-by-outputs-windows
// chart if outputCountType outputCountByTicketPoolWindow is passed and
// ticket-by-outputs-blocks if outputCountType outputCountByAllBlocks is passed. | [
"retrieveTicketByOutputCount",
"fetches",
"the",
"data",
"for",
"ticket",
"-",
"by",
"-",
"outputs",
"-",
"windows",
"chart",
"if",
"outputCountType",
"outputCountByTicketPoolWindow",
"is",
"passed",
"and",
"ticket",
"-",
"by",
"-",
"outputs",
"-",
"blocks",
"if",
"outputCountType",
"outputCountByAllBlocks",
"is",
"passed",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3198-L3250 | train |
decred/dcrdata | db/dcrpg/queries.go | InsertProposalVote | func InsertProposalVote(db *sql.DB, proposalRowID uint64, ticket, choice string,
checked bool) (uint64, error) {
var id uint64
err := db.QueryRow(internal.InsertProposalVotesRow, proposalRowID, ticket, choice).Scan(&id)
return id, err
} | go | func InsertProposalVote(db *sql.DB, proposalRowID uint64, ticket, choice string,
checked bool) (uint64, error) {
var id uint64
err := db.QueryRow(internal.InsertProposalVotesRow, proposalRowID, ticket, choice).Scan(&id)
return id, err
} | [
"func",
"InsertProposalVote",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"proposalRowID",
"uint64",
",",
"ticket",
",",
"choice",
"string",
",",
"checked",
"bool",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"var",
"id",
"uint64",
"\n",
"err",
":=",
"db",
".",
"QueryRow",
"(",
"internal",
".",
"InsertProposalVotesRow",
",",
"proposalRowID",
",",
"ticket",
",",
"choice",
")",
".",
"Scan",
"(",
"&",
"id",
")",
"\n",
"return",
"id",
",",
"err",
"\n",
"}"
] | // InsertProposalVote add the proposal votes entries to the proposal_votes table. | [
"InsertProposalVote",
"add",
"the",
"proposal",
"votes",
"entries",
"to",
"the",
"proposal_votes",
"table",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3264-L3269 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveLastCommitTime | func retrieveLastCommitTime(db *sql.DB) (timestamp time.Time, err error) {
err = db.QueryRow(internal.SelectProposalsLastCommitTime).Scan(×tamp)
return
} | go | func retrieveLastCommitTime(db *sql.DB) (timestamp time.Time, err error) {
err = db.QueryRow(internal.SelectProposalsLastCommitTime).Scan(×tamp)
return
} | [
"func",
"retrieveLastCommitTime",
"(",
"db",
"*",
"sql",
".",
"DB",
")",
"(",
"timestamp",
"time",
".",
"Time",
",",
"err",
"error",
")",
"{",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"internal",
".",
"SelectProposalsLastCommitTime",
")",
".",
"Scan",
"(",
"&",
"timestamp",
")",
"\n",
"return",
"\n",
"}"
] | // retrieveLastCommitTime returns the last commit timestamp whole proposal votes
// data was fetched and updated in both proposals and proposal_votes table. | [
"retrieveLastCommitTime",
"returns",
"the",
"last",
"commit",
"timestamp",
"whole",
"proposal",
"votes",
"data",
"was",
"fetched",
"and",
"updated",
"in",
"both",
"proposals",
"and",
"proposal_votes",
"table",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3273-L3276 | train |
decred/dcrdata | db/dcrpg/queries.go | retrieveProposalVotesData | func retrieveProposalVotesData(ctx context.Context, db *sql.DB,
proposalToken string) (*dbtypes.ProposalChartsData, error) {
rows, err := db.QueryContext(ctx, internal.SelectProposalVotesChartData, proposalToken)
if err != nil {
return nil, err
}
defer closeRows(rows)
data := new(dbtypes.ProposalChartsData)
for rows.Next() {
var yes, no uint64
var timestamp time.Time
if err = rows.Scan(×tamp, &no, &yes); err != nil {
return nil, err
}
data.No = append(data.No, no)
data.Yes = append(data.Yes, yes)
data.Time = append(data.Time, dbtypes.NewTimeDef(timestamp))
}
return data, err
} | go | func retrieveProposalVotesData(ctx context.Context, db *sql.DB,
proposalToken string) (*dbtypes.ProposalChartsData, error) {
rows, err := db.QueryContext(ctx, internal.SelectProposalVotesChartData, proposalToken)
if err != nil {
return nil, err
}
defer closeRows(rows)
data := new(dbtypes.ProposalChartsData)
for rows.Next() {
var yes, no uint64
var timestamp time.Time
if err = rows.Scan(×tamp, &no, &yes); err != nil {
return nil, err
}
data.No = append(data.No, no)
data.Yes = append(data.Yes, yes)
data.Time = append(data.Time, dbtypes.NewTimeDef(timestamp))
}
return data, err
} | [
"func",
"retrieveProposalVotesData",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"sql",
".",
"DB",
",",
"proposalToken",
"string",
")",
"(",
"*",
"dbtypes",
".",
"ProposalChartsData",
",",
"error",
")",
"{",
"rows",
",",
"err",
":=",
"db",
".",
"QueryContext",
"(",
"ctx",
",",
"internal",
".",
"SelectProposalVotesChartData",
",",
"proposalToken",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"defer",
"closeRows",
"(",
"rows",
")",
"\n\n",
"data",
":=",
"new",
"(",
"dbtypes",
".",
"ProposalChartsData",
")",
"\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"var",
"yes",
",",
"no",
"uint64",
"\n",
"var",
"timestamp",
"time",
".",
"Time",
"\n\n",
"if",
"err",
"=",
"rows",
".",
"Scan",
"(",
"&",
"timestamp",
",",
"&",
"no",
",",
"&",
"yes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"data",
".",
"No",
"=",
"append",
"(",
"data",
".",
"No",
",",
"no",
")",
"\n",
"data",
".",
"Yes",
"=",
"append",
"(",
"data",
".",
"Yes",
",",
"yes",
")",
"\n",
"data",
".",
"Time",
"=",
"append",
"(",
"data",
".",
"Time",
",",
"dbtypes",
".",
"NewTimeDef",
"(",
"timestamp",
")",
")",
"\n",
"}",
"\n\n",
"return",
"data",
",",
"err",
"\n",
"}"
] | // retrieveProposalVotesData returns the votes datat associated with the
// provided proposal token. | [
"retrieveProposalVotesData",
"returns",
"the",
"votes",
"datat",
"associated",
"with",
"the",
"provided",
"proposal",
"token",
"."
] | 02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6 | https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3280-L3304 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.