id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
142,000
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
142,001
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
142,002
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
142,003
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
142,004
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
142,005
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
142,006
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
142,007
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
142,008
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
142,009
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
142,010
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
142,011
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
142,012
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
142,013
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
142,014
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
142,015
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
142,016
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
142,017
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
142,018
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
142,019
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, &timestamp, &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, &timestamp, &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
142,020
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
142,021
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
142,022
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
142,023
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
142,024
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
142,025
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
142,026
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
142,027
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
142,028
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
142,029
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
142,030
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
142,031
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
142,032
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
142,033
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
142,034
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
142,035
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
142,036
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
142,037
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
142,038
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
142,039
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
142,040
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
142,041
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
142,042
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
142,043
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
142,044
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
142,045
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
142,046
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
142,047
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
142,048
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
142,049
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
142,050
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
142,051
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
142,052
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
142,053
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
142,054
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
142,055
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
142,056
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
142,057
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
142,058
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
142,059
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
142,060
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
142,061
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
142,062
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
142,063
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
142,064
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, &timestamp, &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, &timestamp, &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
142,065
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
142,066
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(&timestamp, &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(&timestamp, &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
142,067
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
142,068
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
142,069
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
142,070
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
142,071
decred/dcrdata
db/dcrpg/queries.go
retrieveLastCommitTime
func retrieveLastCommitTime(db *sql.DB) (timestamp time.Time, err error) { err = db.QueryRow(internal.SelectProposalsLastCommitTime).Scan(&timestamp) return }
go
func retrieveLastCommitTime(db *sql.DB) (timestamp time.Time, err error) { err = db.QueryRow(internal.SelectProposalsLastCommitTime).Scan(&timestamp) 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
142,072
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(&timestamp, &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(&timestamp, &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
142,073
decred/dcrdata
db/dcrpg/queries.go
InsertBlockPrevNext
func InsertBlockPrevNext(db *sql.DB, blockDbID uint64, hash, prev, next string) error { rows, err := db.Query(internal.InsertBlockPrevNext, blockDbID, prev, hash, next) if err == nil { return rows.Close() } return err }
go
func InsertBlockPrevNext(db *sql.DB, blockDbID uint64, hash, prev, next string) error { rows, err := db.Query(internal.InsertBlockPrevNext, blockDbID, prev, hash, next) if err == nil { return rows.Close() } return err }
[ "func", "InsertBlockPrevNext", "(", "db", "*", "sql", ".", "DB", ",", "blockDbID", "uint64", ",", "hash", ",", "prev", ",", "next", "string", ")", "error", "{", "rows", ",", "err", ":=", "db", ".", "Query", "(", "internal", ".", "InsertBlockPrevNext", ",", "blockDbID", ",", "prev", ",", "hash", ",", "next", ")", "\n", "if", "err", "==", "nil", "{", "return", "rows", ".", "Close", "(", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// InsertBlockPrevNext inserts a new row of the block_chain table.
[ "InsertBlockPrevNext", "inserts", "a", "new", "row", "of", "the", "block_chain", "table", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3322-L3329
142,074
decred/dcrdata
db/dcrpg/queries.go
RetrieveBlockVoteCount
func RetrieveBlockVoteCount(ctx context.Context, db *sql.DB, hash string) (numVotes int16, err error) { err = db.QueryRowContext(ctx, internal.SelectBlockVoteCount, hash).Scan(&numVotes) return }
go
func RetrieveBlockVoteCount(ctx context.Context, db *sql.DB, hash string) (numVotes int16, err error) { err = db.QueryRowContext(ctx, internal.SelectBlockVoteCount, hash).Scan(&numVotes) return }
[ "func", "RetrieveBlockVoteCount", "(", "ctx", "context", ".", "Context", ",", "db", "*", "sql", ".", "DB", ",", "hash", "string", ")", "(", "numVotes", "int16", ",", "err", "error", ")", "{", "err", "=", "db", ".", "QueryRowContext", "(", "ctx", ",", "internal", ".", "SelectBlockVoteCount", ",", "hash", ")", ".", "Scan", "(", "&", "numVotes", ")", "\n", "return", "\n", "}" ]
// RetrieveBlockVoteCount gets the number of votes mined in a block.
[ "RetrieveBlockVoteCount", "gets", "the", "number", "of", "votes", "mined", "in", "a", "block", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3380-L3383
142,075
decred/dcrdata
db/dcrpg/queries.go
RetrieveBlocksHashesAll
func RetrieveBlocksHashesAll(ctx context.Context, db *sql.DB) ([]string, error) { var hashes []string rows, err := db.QueryContext(ctx, internal.SelectBlocksHashes) if err != nil { return hashes, err } defer closeRows(rows) for rows.Next() { var hash string err = rows.Scan(&hash) if err != nil { break } hashes = append(hashes, hash) } return hashes, err }
go
func RetrieveBlocksHashesAll(ctx context.Context, db *sql.DB) ([]string, error) { var hashes []string rows, err := db.QueryContext(ctx, internal.SelectBlocksHashes) if err != nil { return hashes, err } defer closeRows(rows) for rows.Next() { var hash string err = rows.Scan(&hash) if err != nil { break } hashes = append(hashes, hash) } return hashes, err }
[ "func", "RetrieveBlocksHashesAll", "(", "ctx", "context", ".", "Context", ",", "db", "*", "sql", ".", "DB", ")", "(", "[", "]", "string", ",", "error", ")", "{", "var", "hashes", "[", "]", "string", "\n", "rows", ",", "err", ":=", "db", ".", "QueryContext", "(", "ctx", ",", "internal", ".", "SelectBlocksHashes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "hashes", ",", "err", "\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", "hashes", "=", "append", "(", "hashes", ",", "hash", ")", "\n", "}", "\n", "return", "hashes", ",", "err", "\n", "}" ]
// RetrieveBlocksHashesAll retrieve the hash of every block in the blocks table, // ordered by their row ID.
[ "RetrieveBlocksHashesAll", "retrieve", "the", "hash", "of", "every", "block", "in", "the", "blocks", "table", "ordered", "by", "their", "row", "ID", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3387-L3405
142,076
decred/dcrdata
db/dcrpg/queries.go
RetrieveSideChainBlocks
func RetrieveSideChainBlocks(ctx context.Context, db *sql.DB) (blocks []*dbtypes.BlockStatus, err error) { var rows *sql.Rows rows, err = db.QueryContext(ctx, internal.SelectSideChainBlocks) if err != nil { return } defer closeRows(rows) for rows.Next() { var bs dbtypes.BlockStatus err = rows.Scan(&bs.IsValid, &bs.Height, &bs.PrevHash, &bs.Hash, &bs.NextHash) if err != nil { return } blocks = append(blocks, &bs) } return }
go
func RetrieveSideChainBlocks(ctx context.Context, db *sql.DB) (blocks []*dbtypes.BlockStatus, err error) { var rows *sql.Rows rows, err = db.QueryContext(ctx, internal.SelectSideChainBlocks) if err != nil { return } defer closeRows(rows) for rows.Next() { var bs dbtypes.BlockStatus err = rows.Scan(&bs.IsValid, &bs.Height, &bs.PrevHash, &bs.Hash, &bs.NextHash) if err != nil { return } blocks = append(blocks, &bs) } return }
[ "func", "RetrieveSideChainBlocks", "(", "ctx", "context", ".", "Context", ",", "db", "*", "sql", ".", "DB", ")", "(", "blocks", "[", "]", "*", "dbtypes", ".", "BlockStatus", ",", "err", "error", ")", "{", "var", "rows", "*", "sql", ".", "Rows", "\n", "rows", ",", "err", "=", "db", ".", "QueryContext", "(", "ctx", ",", "internal", ".", "SelectSideChainBlocks", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "defer", "closeRows", "(", "rows", ")", "\n\n", "for", "rows", ".", "Next", "(", ")", "{", "var", "bs", "dbtypes", ".", "BlockStatus", "\n", "err", "=", "rows", ".", "Scan", "(", "&", "bs", ".", "IsValid", ",", "&", "bs", ".", "Height", ",", "&", "bs", ".", "PrevHash", ",", "&", "bs", ".", "Hash", ",", "&", "bs", ".", "NextHash", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "blocks", "=", "append", "(", "blocks", ",", "&", "bs", ")", "\n", "}", "\n", "return", "\n", "}" ]
// RetrieveSideChainBlocks retrieves the block chain status for all known side // chain blocks.
[ "RetrieveSideChainBlocks", "retrieves", "the", "block", "chain", "status", "for", "all", "known", "side", "chain", "blocks", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3417-L3435
142,077
decred/dcrdata
db/dcrpg/queries.go
RetrieveBlockStatus
func RetrieveBlockStatus(ctx context.Context, db *sql.DB, hash string) (bs dbtypes.BlockStatus, err error) { err = db.QueryRowContext(ctx, internal.SelectBlockStatus, hash).Scan(&bs.IsValid, &bs.IsMainchain, &bs.Height, &bs.PrevHash, &bs.Hash, &bs.NextHash) return }
go
func RetrieveBlockStatus(ctx context.Context, db *sql.DB, hash string) (bs dbtypes.BlockStatus, err error) { err = db.QueryRowContext(ctx, internal.SelectBlockStatus, hash).Scan(&bs.IsValid, &bs.IsMainchain, &bs.Height, &bs.PrevHash, &bs.Hash, &bs.NextHash) return }
[ "func", "RetrieveBlockStatus", "(", "ctx", "context", ".", "Context", ",", "db", "*", "sql", ".", "DB", ",", "hash", "string", ")", "(", "bs", "dbtypes", ".", "BlockStatus", ",", "err", "error", ")", "{", "err", "=", "db", ".", "QueryRowContext", "(", "ctx", ",", "internal", ".", "SelectBlockStatus", ",", "hash", ")", ".", "Scan", "(", "&", "bs", ".", "IsValid", ",", "&", "bs", ".", "IsMainchain", ",", "&", "bs", ".", "Height", ",", "&", "bs", ".", "PrevHash", ",", "&", "bs", ".", "Hash", ",", "&", "bs", ".", "NextHash", ")", "\n", "return", "\n", "}" ]
// RetrieveBlockStatus retrieves the block chain status for the block with the // specified hash.
[ "RetrieveBlockStatus", "retrieves", "the", "block", "chain", "status", "for", "the", "block", "with", "the", "specified", "hash", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3484-L3488
142,078
decred/dcrdata
db/dcrpg/queries.go
RetrieveBlockFlags
func RetrieveBlockFlags(ctx context.Context, db *sql.DB, hash string) (isValid bool, isMainchain bool, err error) { err = db.QueryRowContext(ctx, internal.SelectBlockFlags, hash).Scan(&isValid, &isMainchain) return }
go
func RetrieveBlockFlags(ctx context.Context, db *sql.DB, hash string) (isValid bool, isMainchain bool, err error) { err = db.QueryRowContext(ctx, internal.SelectBlockFlags, hash).Scan(&isValid, &isMainchain) return }
[ "func", "RetrieveBlockFlags", "(", "ctx", "context", ".", "Context", ",", "db", "*", "sql", ".", "DB", ",", "hash", "string", ")", "(", "isValid", "bool", ",", "isMainchain", "bool", ",", "err", "error", ")", "{", "err", "=", "db", ".", "QueryRowContext", "(", "ctx", ",", "internal", ".", "SelectBlockFlags", ",", "hash", ")", ".", "Scan", "(", "&", "isValid", ",", "&", "isMainchain", ")", "\n", "return", "\n", "}" ]
// RetrieveBlockFlags retrieves the block's is_valid and is_mainchain flags.
[ "RetrieveBlockFlags", "retrieves", "the", "block", "s", "is_valid", "and", "is_mainchain", "flags", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3491-L3494
142,079
decred/dcrdata
db/dcrpg/queries.go
RetrieveBlockSummaryByTimeRange
func RetrieveBlockSummaryByTimeRange(ctx context.Context, db *sql.DB, minTime, maxTime int64, limit int) ([]dbtypes.BlockDataBasic, error) { var blocks []dbtypes.BlockDataBasic var stmt *sql.Stmt var rows *sql.Rows var err error // int64 -> time.Time is required to query TIMESTAMPTZ columns. minT := time.Unix(minTime, 0) maxT := time.Unix(maxTime, 0) if limit == 0 { stmt, err = db.Prepare(internal.SelectBlockByTimeRangeSQLNoLimit) if err != nil { return nil, err } rows, err = stmt.QueryContext(ctx, minT, maxT) } else { stmt, err = db.Prepare(internal.SelectBlockByTimeRangeSQL) if err != nil { return nil, err } rows, err = stmt.QueryContext(ctx, minT, maxT, limit) } _ = stmt.Close() if err != nil { log.Error(err) return nil, err } defer closeRows(rows) for rows.Next() { var dbBlock dbtypes.BlockDataBasic var blockTime dbtypes.TimeDef err = rows.Scan(&dbBlock.Hash, &dbBlock.Height, &dbBlock.Size, &blockTime, &dbBlock.NumTx) if err != nil { log.Errorf("Unable to scan for block fields: %v", err) } dbBlock.Time = blockTime blocks = append(blocks, dbBlock) } if err = rows.Err(); err != nil { log.Error(err) } return blocks, nil }
go
func RetrieveBlockSummaryByTimeRange(ctx context.Context, db *sql.DB, minTime, maxTime int64, limit int) ([]dbtypes.BlockDataBasic, error) { var blocks []dbtypes.BlockDataBasic var stmt *sql.Stmt var rows *sql.Rows var err error // int64 -> time.Time is required to query TIMESTAMPTZ columns. minT := time.Unix(minTime, 0) maxT := time.Unix(maxTime, 0) if limit == 0 { stmt, err = db.Prepare(internal.SelectBlockByTimeRangeSQLNoLimit) if err != nil { return nil, err } rows, err = stmt.QueryContext(ctx, minT, maxT) } else { stmt, err = db.Prepare(internal.SelectBlockByTimeRangeSQL) if err != nil { return nil, err } rows, err = stmt.QueryContext(ctx, minT, maxT, limit) } _ = stmt.Close() if err != nil { log.Error(err) return nil, err } defer closeRows(rows) for rows.Next() { var dbBlock dbtypes.BlockDataBasic var blockTime dbtypes.TimeDef err = rows.Scan(&dbBlock.Hash, &dbBlock.Height, &dbBlock.Size, &blockTime, &dbBlock.NumTx) if err != nil { log.Errorf("Unable to scan for block fields: %v", err) } dbBlock.Time = blockTime blocks = append(blocks, dbBlock) } if err = rows.Err(); err != nil { log.Error(err) } return blocks, nil }
[ "func", "RetrieveBlockSummaryByTimeRange", "(", "ctx", "context", ".", "Context", ",", "db", "*", "sql", ".", "DB", ",", "minTime", ",", "maxTime", "int64", ",", "limit", "int", ")", "(", "[", "]", "dbtypes", ".", "BlockDataBasic", ",", "error", ")", "{", "var", "blocks", "[", "]", "dbtypes", ".", "BlockDataBasic", "\n", "var", "stmt", "*", "sql", ".", "Stmt", "\n", "var", "rows", "*", "sql", ".", "Rows", "\n", "var", "err", "error", "\n\n", "// int64 -> time.Time is required to query TIMESTAMPTZ columns.", "minT", ":=", "time", ".", "Unix", "(", "minTime", ",", "0", ")", "\n", "maxT", ":=", "time", ".", "Unix", "(", "maxTime", ",", "0", ")", "\n\n", "if", "limit", "==", "0", "{", "stmt", ",", "err", "=", "db", ".", "Prepare", "(", "internal", ".", "SelectBlockByTimeRangeSQLNoLimit", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "rows", ",", "err", "=", "stmt", ".", "QueryContext", "(", "ctx", ",", "minT", ",", "maxT", ")", "\n", "}", "else", "{", "stmt", ",", "err", "=", "db", ".", "Prepare", "(", "internal", ".", "SelectBlockByTimeRangeSQL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "rows", ",", "err", "=", "stmt", ".", "QueryContext", "(", "ctx", ",", "minT", ",", "maxT", ",", "limit", ")", "\n", "}", "\n", "_", "=", "stmt", ".", "Close", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "closeRows", "(", "rows", ")", "\n\n", "for", "rows", ".", "Next", "(", ")", "{", "var", "dbBlock", "dbtypes", ".", "BlockDataBasic", "\n", "var", "blockTime", "dbtypes", ".", "TimeDef", "\n", "err", "=", "rows", ".", "Scan", "(", "&", "dbBlock", ".", "Hash", ",", "&", "dbBlock", ".", "Height", ",", "&", "dbBlock", ".", "Size", ",", "&", "blockTime", ",", "&", "dbBlock", ".", "NumTx", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "dbBlock", ".", "Time", "=", "blockTime", "\n", "blocks", "=", "append", "(", "blocks", ",", "dbBlock", ")", "\n", "}", "\n", "if", "err", "=", "rows", ".", "Err", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Error", "(", "err", ")", "\n", "}", "\n", "return", "blocks", ",", "nil", "\n", "}" ]
// RetrieveBlockSummaryByTimeRange retrieves the slice of block summaries for // the given time range. The limit specifies the number of most recent block // summaries to return. A limit of 0 indicates all blocks in the time range // should be included.
[ "RetrieveBlockSummaryByTimeRange", "retrieves", "the", "slice", "of", "block", "summaries", "for", "the", "given", "time", "range", ".", "The", "limit", "specifies", "the", "number", "of", "most", "recent", "block", "summaries", "to", "return", ".", "A", "limit", "of", "0", "indicates", "all", "blocks", "in", "the", "time", "range", "should", "be", "included", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3500-L3546
142,080
decred/dcrdata
db/dcrpg/queries.go
RetrievePreviousHashByBlockHash
func RetrievePreviousHashByBlockHash(ctx context.Context, db *sql.DB, hash string) (previousHash string, err error) { err = db.QueryRowContext(ctx, internal.SelectBlocksPreviousHash, hash).Scan(&previousHash) return }
go
func RetrievePreviousHashByBlockHash(ctx context.Context, db *sql.DB, hash string) (previousHash string, err error) { err = db.QueryRowContext(ctx, internal.SelectBlocksPreviousHash, hash).Scan(&previousHash) return }
[ "func", "RetrievePreviousHashByBlockHash", "(", "ctx", "context", ".", "Context", ",", "db", "*", "sql", ".", "DB", ",", "hash", "string", ")", "(", "previousHash", "string", ",", "err", "error", ")", "{", "err", "=", "db", ".", "QueryRowContext", "(", "ctx", ",", "internal", ".", "SelectBlocksPreviousHash", ",", "hash", ")", ".", "Scan", "(", "&", "previousHash", ")", "\n", "return", "\n", "}" ]
// RetrievePreviousHashByBlockHash retrieves the previous block hash for the // given block from the blocks table.
[ "RetrievePreviousHashByBlockHash", "retrieves", "the", "previous", "block", "hash", "for", "the", "given", "block", "from", "the", "blocks", "table", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3550-L3553
142,081
decred/dcrdata
db/dcrpg/queries.go
SetMainchainByBlockHash
func SetMainchainByBlockHash(db *sql.DB, hash string, isMainchain bool) (previousHash string, err error) { err = db.QueryRow(internal.UpdateBlockMainchain, hash, isMainchain).Scan(&previousHash) return }
go
func SetMainchainByBlockHash(db *sql.DB, hash string, isMainchain bool) (previousHash string, err error) { err = db.QueryRow(internal.UpdateBlockMainchain, hash, isMainchain).Scan(&previousHash) return }
[ "func", "SetMainchainByBlockHash", "(", "db", "*", "sql", ".", "DB", ",", "hash", "string", ",", "isMainchain", "bool", ")", "(", "previousHash", "string", ",", "err", "error", ")", "{", "err", "=", "db", ".", "QueryRow", "(", "internal", ".", "UpdateBlockMainchain", ",", "hash", ",", "isMainchain", ")", ".", "Scan", "(", "&", "previousHash", ")", "\n", "return", "\n", "}" ]
// SetMainchainByBlockHash is used to set the is_mainchain flag for the given // block. This is required to handle a reoganization.
[ "SetMainchainByBlockHash", "is", "used", "to", "set", "the", "is_mainchain", "flag", "for", "the", "given", "block", ".", "This", "is", "required", "to", "handle", "a", "reoganization", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3557-L3560
142,082
decred/dcrdata
db/dcrpg/queries.go
UpdateVotesMainchain
func UpdateVotesMainchain(db *sql.DB, blockHash string, isMainchain bool) (int64, error) { numRows, err := sqlExec(db, internal.UpdateVotesMainchainByBlock, "failed to update votes is_mainchain: ", isMainchain, blockHash) if err != nil { return 0, err } return numRows, nil }
go
func UpdateVotesMainchain(db *sql.DB, blockHash string, isMainchain bool) (int64, error) { numRows, err := sqlExec(db, internal.UpdateVotesMainchainByBlock, "failed to update votes is_mainchain: ", isMainchain, blockHash) if err != nil { return 0, err } return numRows, nil }
[ "func", "UpdateVotesMainchain", "(", "db", "*", "sql", ".", "DB", ",", "blockHash", "string", ",", "isMainchain", "bool", ")", "(", "int64", ",", "error", ")", "{", "numRows", ",", "err", ":=", "sqlExec", "(", "db", ",", "internal", ".", "UpdateVotesMainchainByBlock", ",", "\"", "\"", ",", "isMainchain", ",", "blockHash", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "numRows", ",", "nil", "\n", "}" ]
// UpdateVotesMainchain sets the is_mainchain column for the votes in the // specified block.
[ "UpdateVotesMainchain", "sets", "the", "is_mainchain", "column", "for", "the", "votes", "in", "the", "specified", "block", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3616-L3623
142,083
decred/dcrdata
db/dcrpg/queries.go
UpdateTicketsMainchain
func UpdateTicketsMainchain(db *sql.DB, blockHash string, isMainchain bool) (int64, error) { numRows, err := sqlExec(db, internal.UpdateTicketsMainchainByBlock, "failed to update tickets is_mainchain: ", isMainchain, blockHash) if err != nil { return 0, err } return numRows, nil }
go
func UpdateTicketsMainchain(db *sql.DB, blockHash string, isMainchain bool) (int64, error) { numRows, err := sqlExec(db, internal.UpdateTicketsMainchainByBlock, "failed to update tickets is_mainchain: ", isMainchain, blockHash) if err != nil { return 0, err } return numRows, nil }
[ "func", "UpdateTicketsMainchain", "(", "db", "*", "sql", ".", "DB", ",", "blockHash", "string", ",", "isMainchain", "bool", ")", "(", "int64", ",", "error", ")", "{", "numRows", ",", "err", ":=", "sqlExec", "(", "db", ",", "internal", ".", "UpdateTicketsMainchainByBlock", ",", "\"", "\"", ",", "isMainchain", ",", "blockHash", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "numRows", ",", "nil", "\n", "}" ]
// UpdateTicketsMainchain sets the is_mainchain column for the tickets in the // specified block.
[ "UpdateTicketsMainchain", "sets", "the", "is_mainchain", "column", "for", "the", "tickets", "in", "the", "specified", "block", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3627-L3634
142,084
decred/dcrdata
db/dcrpg/queries.go
UpdateLastBlockValid
func UpdateLastBlockValid(db *sql.DB, blockDbID uint64, isValid bool) error { numRows, err := sqlExec(db, internal.UpdateLastBlockValid, "failed to update last block validity: ", blockDbID, isValid) if err != nil { return err } if numRows != 1 { return fmt.Errorf("UpdateLastBlockValid failed to update exactly 1 row"+ "(%d)", numRows) } return nil }
go
func UpdateLastBlockValid(db *sql.DB, blockDbID uint64, isValid bool) error { numRows, err := sqlExec(db, internal.UpdateLastBlockValid, "failed to update last block validity: ", blockDbID, isValid) if err != nil { return err } if numRows != 1 { return fmt.Errorf("UpdateLastBlockValid failed to update exactly 1 row"+ "(%d)", numRows) } return nil }
[ "func", "UpdateLastBlockValid", "(", "db", "*", "sql", ".", "DB", ",", "blockDbID", "uint64", ",", "isValid", "bool", ")", "error", "{", "numRows", ",", "err", ":=", "sqlExec", "(", "db", ",", "internal", ".", "UpdateLastBlockValid", ",", "\"", "\"", ",", "blockDbID", ",", "isValid", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "numRows", "!=", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "numRows", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UpdateLastBlockValid updates the is_valid column of the block specified by // the row id for the blocks table.
[ "UpdateLastBlockValid", "updates", "the", "is_valid", "column", "of", "the", "block", "specified", "by", "the", "row", "id", "for", "the", "blocks", "table", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3670-L3681
142,085
decred/dcrdata
db/dcrpg/queries.go
UpdateLastVins
func UpdateLastVins(db *sql.DB, blockHash string, isValid, isMainchain bool) error { // Retrieve the hash for every transaction in this block. A context with no // deadline or cancellation function is used since this UpdateLastVins needs // to complete to ensure DB integrity. _, txs, _, trees, timestamps, err := RetrieveTxsByBlockHash(context.Background(), db, blockHash) if err != nil { return err } for i, txHash := range txs { n, err := sqlExec(db, internal.SetIsValidIsMainchainByTxHash, "failed to update last vins tx validity: ", isValid, isMainchain, txHash, timestamps[i], trees[i]) if err != nil { return err } if n < 1 { return fmt.Errorf(" failed to update at least 1 row") } } return nil }
go
func UpdateLastVins(db *sql.DB, blockHash string, isValid, isMainchain bool) error { // Retrieve the hash for every transaction in this block. A context with no // deadline or cancellation function is used since this UpdateLastVins needs // to complete to ensure DB integrity. _, txs, _, trees, timestamps, err := RetrieveTxsByBlockHash(context.Background(), db, blockHash) if err != nil { return err } for i, txHash := range txs { n, err := sqlExec(db, internal.SetIsValidIsMainchainByTxHash, "failed to update last vins tx validity: ", isValid, isMainchain, txHash, timestamps[i], trees[i]) if err != nil { return err } if n < 1 { return fmt.Errorf(" failed to update at least 1 row") } } return nil }
[ "func", "UpdateLastVins", "(", "db", "*", "sql", ".", "DB", ",", "blockHash", "string", ",", "isValid", ",", "isMainchain", "bool", ")", "error", "{", "// Retrieve the hash for every transaction in this block. A context with no", "// deadline or cancellation function is used since this UpdateLastVins needs", "// to complete to ensure DB integrity.", "_", ",", "txs", ",", "_", ",", "trees", ",", "timestamps", ",", "err", ":=", "RetrieveTxsByBlockHash", "(", "context", ".", "Background", "(", ")", ",", "db", ",", "blockHash", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "for", "i", ",", "txHash", ":=", "range", "txs", "{", "n", ",", "err", ":=", "sqlExec", "(", "db", ",", "internal", ".", "SetIsValidIsMainchainByTxHash", ",", "\"", "\"", ",", "isValid", ",", "isMainchain", ",", "txHash", ",", "timestamps", "[", "i", "]", ",", "trees", "[", "i", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "n", "<", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UpdateLastVins updates the is_valid and is_mainchain columns in the vins // table for all of the transactions in the block specified by the given block // hash.
[ "UpdateLastVins", "updates", "the", "is_valid", "and", "is_mainchain", "columns", "in", "the", "vins", "table", "for", "all", "of", "the", "transactions", "in", "the", "block", "specified", "by", "the", "given", "block", "hash", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3686-L3709
142,086
decred/dcrdata
db/dcrpg/queries.go
UpdateBlockNext
func UpdateBlockNext(db SqlExecutor, blockDbID uint64, next string) error { res, err := db.Exec(internal.UpdateBlockNext, blockDbID, next) if err != nil { return err } numRows, err := res.RowsAffected() if err != nil { return err } if numRows != 1 { return fmt.Errorf("%s (%d)", notOneRowErrMsg, numRows) } return nil }
go
func UpdateBlockNext(db SqlExecutor, blockDbID uint64, next string) error { res, err := db.Exec(internal.UpdateBlockNext, blockDbID, next) if err != nil { return err } numRows, err := res.RowsAffected() if err != nil { return err } if numRows != 1 { return fmt.Errorf("%s (%d)", notOneRowErrMsg, numRows) } return nil }
[ "func", "UpdateBlockNext", "(", "db", "SqlExecutor", ",", "blockDbID", "uint64", ",", "next", "string", ")", "error", "{", "res", ",", "err", ":=", "db", ".", "Exec", "(", "internal", ".", "UpdateBlockNext", ",", "blockDbID", ",", "next", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "numRows", ",", "err", ":=", "res", ".", "RowsAffected", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "numRows", "!=", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "notOneRowErrMsg", ",", "numRows", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UpdateBlockNext sets the next block's hash for the specified row of the // block_chain table specified by DB row ID.
[ "UpdateBlockNext", "sets", "the", "next", "block", "s", "hash", "for", "the", "specified", "row", "of", "the", "block_chain", "table", "specified", "by", "DB", "row", "ID", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3739-L3752
142,087
decred/dcrdata
db/dcrpg/queries.go
UpdateBlockNextByHash
func UpdateBlockNextByHash(db SqlExecutor, this, next string) error { res, err := db.Exec(internal.UpdateBlockNextByHash, this, next) if err != nil { return err } numRows, err := res.RowsAffected() if err != nil { return err } if numRows != 1 { return fmt.Errorf("%s (%d)", notOneRowErrMsg, numRows) } return nil }
go
func UpdateBlockNextByHash(db SqlExecutor, this, next string) error { res, err := db.Exec(internal.UpdateBlockNextByHash, this, next) if err != nil { return err } numRows, err := res.RowsAffected() if err != nil { return err } if numRows != 1 { return fmt.Errorf("%s (%d)", notOneRowErrMsg, numRows) } return nil }
[ "func", "UpdateBlockNextByHash", "(", "db", "SqlExecutor", ",", "this", ",", "next", "string", ")", "error", "{", "res", ",", "err", ":=", "db", ".", "Exec", "(", "internal", ".", "UpdateBlockNextByHash", ",", "this", ",", "next", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "numRows", ",", "err", ":=", "res", ".", "RowsAffected", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "numRows", "!=", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "notOneRowErrMsg", ",", "numRows", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UpdateBlockNextByHash sets the next block's hash for the block in the // block_chain table specified by hash.
[ "UpdateBlockNextByHash", "sets", "the", "next", "block", "s", "hash", "for", "the", "block", "in", "the", "block_chain", "table", "specified", "by", "hash", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3756-L3769
142,088
decred/dcrdata
db/dcrpg/queries.go
UpdateBlockNextByNextHash
func UpdateBlockNextByNextHash(db SqlExecutor, currentNext, newNext string) error { res, err := db.Exec(internal.UpdateBlockNextByNextHash, currentNext, newNext) if err != nil { return err } numRows, err := res.RowsAffected() if err != nil { return err } if numRows != 1 { return fmt.Errorf("%s (%d)", notOneRowErrMsg, numRows) } return nil }
go
func UpdateBlockNextByNextHash(db SqlExecutor, currentNext, newNext string) error { res, err := db.Exec(internal.UpdateBlockNextByNextHash, currentNext, newNext) if err != nil { return err } numRows, err := res.RowsAffected() if err != nil { return err } if numRows != 1 { return fmt.Errorf("%s (%d)", notOneRowErrMsg, numRows) } return nil }
[ "func", "UpdateBlockNextByNextHash", "(", "db", "SqlExecutor", ",", "currentNext", ",", "newNext", "string", ")", "error", "{", "res", ",", "err", ":=", "db", ".", "Exec", "(", "internal", ".", "UpdateBlockNextByNextHash", ",", "currentNext", ",", "newNext", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "numRows", ",", "err", ":=", "res", ".", "RowsAffected", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "numRows", "!=", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "notOneRowErrMsg", ",", "numRows", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UpdateBlockNextByNextHash sets the next block's hash for the block in the // block_chain table with a current next_hash specified by hash.
[ "UpdateBlockNextByNextHash", "sets", "the", "next", "block", "s", "hash", "for", "the", "block", "in", "the", "block_chain", "table", "with", "a", "current", "next_hash", "specified", "by", "hash", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/db/dcrpg/queries.go#L3773-L3786
142,089
decred/dcrdata
exchanges/bot.go
copyStates
func copyStates(m map[string]*ExchangeState) map[string]*ExchangeState { c := make(map[string]*ExchangeState) for k, v := range m { c[k] = v } return c }
go
func copyStates(m map[string]*ExchangeState) map[string]*ExchangeState { c := make(map[string]*ExchangeState) for k, v := range m { c[k] = v } return c }
[ "func", "copyStates", "(", "m", "map", "[", "string", "]", "*", "ExchangeState", ")", "map", "[", "string", "]", "*", "ExchangeState", "{", "c", ":=", "make", "(", "map", "[", "string", "]", "*", "ExchangeState", ")", "\n", "for", "k", ",", "v", ":=", "range", "m", "{", "c", "[", "k", "]", "=", "v", "\n", "}", "\n", "return", "c", "\n", "}" ]
// Copy an ExchangeState map.
[ "Copy", "an", "ExchangeState", "map", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L107-L113
142,090
decred/dcrdata
exchanges/bot.go
copy
func (state ExchangeBotState) copy() *ExchangeBotState { state.DcrBtc = copyStates(state.DcrBtc) state.FiatIndices = copyStates(state.FiatIndices) return &state }
go
func (state ExchangeBotState) copy() *ExchangeBotState { state.DcrBtc = copyStates(state.DcrBtc) state.FiatIndices = copyStates(state.FiatIndices) return &state }
[ "func", "(", "state", "ExchangeBotState", ")", "copy", "(", ")", "*", "ExchangeBotState", "{", "state", ".", "DcrBtc", "=", "copyStates", "(", "state", ".", "DcrBtc", ")", "\n", "state", ".", "FiatIndices", "=", "copyStates", "(", "state", ".", "FiatIndices", ")", "\n", "return", "&", "state", "\n", "}" ]
// Creates a pointer to a copy of the ExchangeBotState.
[ "Creates", "a", "pointer", "to", "a", "copy", "of", "the", "ExchangeBotState", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L116-L120
142,091
decred/dcrdata
exchanges/bot.go
VolumeOrderedExchanges
func (state *ExchangeBotState) VolumeOrderedExchanges() []*tokenedExchange { xcList := make([]*tokenedExchange, 0, len(state.DcrBtc)) for token, state := range state.DcrBtc { xcList = append(xcList, &tokenedExchange{ Token: token, State: state, }) } sort.Slice(xcList, func(i, j int) bool { return xcList[i].State.Volume > xcList[j].State.Volume }) return xcList }
go
func (state *ExchangeBotState) VolumeOrderedExchanges() []*tokenedExchange { xcList := make([]*tokenedExchange, 0, len(state.DcrBtc)) for token, state := range state.DcrBtc { xcList = append(xcList, &tokenedExchange{ Token: token, State: state, }) } sort.Slice(xcList, func(i, j int) bool { return xcList[i].State.Volume > xcList[j].State.Volume }) return xcList }
[ "func", "(", "state", "*", "ExchangeBotState", ")", "VolumeOrderedExchanges", "(", ")", "[", "]", "*", "tokenedExchange", "{", "xcList", ":=", "make", "(", "[", "]", "*", "tokenedExchange", ",", "0", ",", "len", "(", "state", ".", "DcrBtc", ")", ")", "\n", "for", "token", ",", "state", ":=", "range", "state", ".", "DcrBtc", "{", "xcList", "=", "append", "(", "xcList", ",", "&", "tokenedExchange", "{", "Token", ":", "token", ",", "State", ":", "state", ",", "}", ")", "\n", "}", "\n", "sort", ".", "Slice", "(", "xcList", ",", "func", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "xcList", "[", "i", "]", ".", "State", ".", "Volume", ">", "xcList", "[", "j", "]", ".", "State", ".", "Volume", "\n", "}", ")", "\n", "return", "xcList", "\n", "}" ]
// VolumeOrderedExchanges returns a list of tokenedExchange sorted by volume, // highest volume first.
[ "VolumeOrderedExchanges", "returns", "a", "list", "of", "tokenedExchange", "sorted", "by", "volume", "highest", "volume", "first", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L137-L149
142,092
decred/dcrdata
exchanges/bot.go
NewUpdateChannels
func NewUpdateChannels() *UpdateChannels { return &UpdateChannels{ Exchange: make(chan *ExchangeUpdate, 16), Index: make(chan *IndexUpdate, 16), Quit: make(chan struct{}), } }
go
func NewUpdateChannels() *UpdateChannels { return &UpdateChannels{ Exchange: make(chan *ExchangeUpdate, 16), Index: make(chan *IndexUpdate, 16), Quit: make(chan struct{}), } }
[ "func", "NewUpdateChannels", "(", ")", "*", "UpdateChannels", "{", "return", "&", "UpdateChannels", "{", "Exchange", ":", "make", "(", "chan", "*", "ExchangeUpdate", ",", "16", ")", ",", "Index", ":", "make", "(", "chan", "*", "IndexUpdate", ",", "16", ")", ",", "Quit", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n", "}" ]
// NewUpdateChannels creates a new initialized set of UpdateChannels.
[ "NewUpdateChannels", "creates", "a", "new", "initialized", "set", "of", "UpdateChannels", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L176-L182
142,093
decred/dcrdata
exchanges/bot.go
connectMasterBot
func (bot *ExchangeBot) connectMasterBot(ctx context.Context, delay time.Duration) (dcrrates.DCRRates_SubscribeExchangesClient, error) { if bot.masterConnection != nil { bot.masterConnection.Close() } if delay > 0 { expiration := time.NewTimer(delay) select { case <-expiration.C: case <-ctx.Done(): return nil, fmt.Errorf("Context cancelled before reconnection") } } conn, err := grpc.Dial(bot.config.MasterBot, grpc.WithTransportCredentials(bot.TLSCredentials)) if err != nil { log.Warnf("gRPC connection error when trying to connect to %s. Falling back to direct connection: %v", bot.config.MasterBot, err) return nil, err } bot.masterConnection = conn grpcClient := dcrrates.NewDCRRatesClient(conn) stream, err := grpcClient.SubscribeExchanges(ctx, &dcrrates.ExchangeSubscription{ BtcIndex: bot.BtcIndex, Exchanges: bot.subscribedExchanges(), }) if err != nil { return nil, err } return stream, nil }
go
func (bot *ExchangeBot) connectMasterBot(ctx context.Context, delay time.Duration) (dcrrates.DCRRates_SubscribeExchangesClient, error) { if bot.masterConnection != nil { bot.masterConnection.Close() } if delay > 0 { expiration := time.NewTimer(delay) select { case <-expiration.C: case <-ctx.Done(): return nil, fmt.Errorf("Context cancelled before reconnection") } } conn, err := grpc.Dial(bot.config.MasterBot, grpc.WithTransportCredentials(bot.TLSCredentials)) if err != nil { log.Warnf("gRPC connection error when trying to connect to %s. Falling back to direct connection: %v", bot.config.MasterBot, err) return nil, err } bot.masterConnection = conn grpcClient := dcrrates.NewDCRRatesClient(conn) stream, err := grpcClient.SubscribeExchanges(ctx, &dcrrates.ExchangeSubscription{ BtcIndex: bot.BtcIndex, Exchanges: bot.subscribedExchanges(), }) if err != nil { return nil, err } return stream, nil }
[ "func", "(", "bot", "*", "ExchangeBot", ")", "connectMasterBot", "(", "ctx", "context", ".", "Context", ",", "delay", "time", ".", "Duration", ")", "(", "dcrrates", ".", "DCRRates_SubscribeExchangesClient", ",", "error", ")", "{", "if", "bot", ".", "masterConnection", "!=", "nil", "{", "bot", ".", "masterConnection", ".", "Close", "(", ")", "\n", "}", "\n", "if", "delay", ">", "0", "{", "expiration", ":=", "time", ".", "NewTimer", "(", "delay", ")", "\n", "select", "{", "case", "<-", "expiration", ".", "C", ":", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "conn", ",", "err", ":=", "grpc", ".", "Dial", "(", "bot", ".", "config", ".", "MasterBot", ",", "grpc", ".", "WithTransportCredentials", "(", "bot", ".", "TLSCredentials", ")", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Warnf", "(", "\"", "\"", ",", "bot", ".", "config", ".", "MasterBot", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "bot", ".", "masterConnection", "=", "conn", "\n", "grpcClient", ":=", "dcrrates", ".", "NewDCRRatesClient", "(", "conn", ")", "\n", "stream", ",", "err", ":=", "grpcClient", ".", "SubscribeExchanges", "(", "ctx", ",", "&", "dcrrates", ".", "ExchangeSubscription", "{", "BtcIndex", ":", "bot", ".", "BtcIndex", ",", "Exchanges", ":", "bot", ".", "subscribedExchanges", "(", ")", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "stream", ",", "nil", "\n", "}" ]
// Attempt DCRRates connection after delay.
[ "Attempt", "DCRRates", "connection", "after", "delay", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L462-L489
142,094
decred/dcrdata
exchanges/bot.go
subscribedExchanges
func (bot *ExchangeBot) subscribedExchanges() []string { xcList := make([]string, len(bot.Exchanges)) for token := range bot.Exchanges { xcList = append(xcList, token) } return xcList }
go
func (bot *ExchangeBot) subscribedExchanges() []string { xcList := make([]string, len(bot.Exchanges)) for token := range bot.Exchanges { xcList = append(xcList, token) } return xcList }
[ "func", "(", "bot", "*", "ExchangeBot", ")", "subscribedExchanges", "(", ")", "[", "]", "string", "{", "xcList", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "bot", ".", "Exchanges", ")", ")", "\n", "for", "token", ":=", "range", "bot", ".", "Exchanges", "{", "xcList", "=", "append", "(", "xcList", ",", "token", ")", "\n", "}", "\n", "return", "xcList", "\n", "}" ]
// A list of exchanges which the ExchangeBot is monitoring.
[ "A", "list", "of", "exchanges", "which", "the", "ExchangeBot", "is", "monitoring", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L492-L498
142,095
decred/dcrdata
exchanges/bot.go
UpdateChannels
func (bot *ExchangeBot) UpdateChannels() *UpdateChannels { update := make(chan *ExchangeUpdate, 16) index := make(chan *IndexUpdate, 16) quit := make(chan struct{}) bot.mtx.Lock() defer bot.mtx.Unlock() bot.updateChans = append(bot.updateChans, update) bot.indexChans = append(bot.indexChans, index) bot.quitChans = append(bot.quitChans, quit) return &UpdateChannels{ Exchange: update, Index: index, Quit: quit, } }
go
func (bot *ExchangeBot) UpdateChannels() *UpdateChannels { update := make(chan *ExchangeUpdate, 16) index := make(chan *IndexUpdate, 16) quit := make(chan struct{}) bot.mtx.Lock() defer bot.mtx.Unlock() bot.updateChans = append(bot.updateChans, update) bot.indexChans = append(bot.indexChans, index) bot.quitChans = append(bot.quitChans, quit) return &UpdateChannels{ Exchange: update, Index: index, Quit: quit, } }
[ "func", "(", "bot", "*", "ExchangeBot", ")", "UpdateChannels", "(", ")", "*", "UpdateChannels", "{", "update", ":=", "make", "(", "chan", "*", "ExchangeUpdate", ",", "16", ")", "\n", "index", ":=", "make", "(", "chan", "*", "IndexUpdate", ",", "16", ")", "\n", "quit", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "bot", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "bot", ".", "mtx", ".", "Unlock", "(", ")", "\n", "bot", ".", "updateChans", "=", "append", "(", "bot", ".", "updateChans", ",", "update", ")", "\n", "bot", ".", "indexChans", "=", "append", "(", "bot", ".", "indexChans", ",", "index", ")", "\n", "bot", ".", "quitChans", "=", "append", "(", "bot", ".", "quitChans", ",", "quit", ")", "\n", "return", "&", "UpdateChannels", "{", "Exchange", ":", "update", ",", "Index", ":", "index", ",", "Quit", ":", "quit", ",", "}", "\n", "}" ]
// UpdateChannels creates an UpdateChannels, which holds a channel to receive // exchange updates and a channel which is closed when the start loop exits.
[ "UpdateChannels", "creates", "an", "UpdateChannels", "which", "holds", "a", "channel", "to", "receive", "exchange", "updates", "and", "a", "channel", "which", "is", "closed", "when", "the", "start", "loop", "exits", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L502-L516
142,096
decred/dcrdata
exchanges/bot.go
ConvertedState
func (bot *ExchangeBot) ConvertedState(code string) (*ExchangeBotState, error) { bot.mtx.RLock() defer bot.mtx.RUnlock() fiatIndices := make(map[string]*ExchangeState) for token, indices := range bot.indexMap { for symbol, price := range indices { if symbol == code { fiatIndices[token] = &ExchangeState{Price: price} } } } dcrPrice, volume := bot.processState(bot.currentState.DcrBtc, true) btcPrice, _ := bot.processState(fiatIndices, false) if dcrPrice == 0 || btcPrice == 0 { bot.failed = true return nil, fmt.Errorf("Unable to process price for currency %s", code) } state := ExchangeBotState{ BtcIndex: code, Volume: volume * btcPrice, Price: dcrPrice * btcPrice, DcrBtc: bot.currentState.DcrBtc, FiatIndices: fiatIndices, } return state.copy(), nil }
go
func (bot *ExchangeBot) ConvertedState(code string) (*ExchangeBotState, error) { bot.mtx.RLock() defer bot.mtx.RUnlock() fiatIndices := make(map[string]*ExchangeState) for token, indices := range bot.indexMap { for symbol, price := range indices { if symbol == code { fiatIndices[token] = &ExchangeState{Price: price} } } } dcrPrice, volume := bot.processState(bot.currentState.DcrBtc, true) btcPrice, _ := bot.processState(fiatIndices, false) if dcrPrice == 0 || btcPrice == 0 { bot.failed = true return nil, fmt.Errorf("Unable to process price for currency %s", code) } state := ExchangeBotState{ BtcIndex: code, Volume: volume * btcPrice, Price: dcrPrice * btcPrice, DcrBtc: bot.currentState.DcrBtc, FiatIndices: fiatIndices, } return state.copy(), nil }
[ "func", "(", "bot", "*", "ExchangeBot", ")", "ConvertedState", "(", "code", "string", ")", "(", "*", "ExchangeBotState", ",", "error", ")", "{", "bot", ".", "mtx", ".", "RLock", "(", ")", "\n", "defer", "bot", ".", "mtx", ".", "RUnlock", "(", ")", "\n", "fiatIndices", ":=", "make", "(", "map", "[", "string", "]", "*", "ExchangeState", ")", "\n", "for", "token", ",", "indices", ":=", "range", "bot", ".", "indexMap", "{", "for", "symbol", ",", "price", ":=", "range", "indices", "{", "if", "symbol", "==", "code", "{", "fiatIndices", "[", "token", "]", "=", "&", "ExchangeState", "{", "Price", ":", "price", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "dcrPrice", ",", "volume", ":=", "bot", ".", "processState", "(", "bot", ".", "currentState", ".", "DcrBtc", ",", "true", ")", "\n", "btcPrice", ",", "_", ":=", "bot", ".", "processState", "(", "fiatIndices", ",", "false", ")", "\n", "if", "dcrPrice", "==", "0", "||", "btcPrice", "==", "0", "{", "bot", ".", "failed", "=", "true", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "code", ")", "\n", "}", "\n\n", "state", ":=", "ExchangeBotState", "{", "BtcIndex", ":", "code", ",", "Volume", ":", "volume", "*", "btcPrice", ",", "Price", ":", "dcrPrice", "*", "btcPrice", ",", "DcrBtc", ":", "bot", ".", "currentState", ".", "DcrBtc", ",", "FiatIndices", ":", "fiatIndices", ",", "}", "\n\n", "return", "state", ".", "copy", "(", ")", ",", "nil", "\n", "}" ]
// ConvertedState returns an ExchangeBotState with a base of the provided // currency code, if available.
[ "ConvertedState", "returns", "an", "ExchangeBotState", "with", "a", "base", "of", "the", "provided", "currency", "code", "if", "available", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L548-L576
142,097
decred/dcrdata
exchanges/bot.go
StateBytes
func (bot *ExchangeBot) StateBytes() []byte { bot.mtx.RLock() defer bot.mtx.RUnlock() return bot.currentStateBytes }
go
func (bot *ExchangeBot) StateBytes() []byte { bot.mtx.RLock() defer bot.mtx.RUnlock() return bot.currentStateBytes }
[ "func", "(", "bot", "*", "ExchangeBot", ")", "StateBytes", "(", ")", "[", "]", "byte", "{", "bot", ".", "mtx", ".", "RLock", "(", ")", "\n", "defer", "bot", ".", "mtx", ".", "RUnlock", "(", ")", "\n", "return", "bot", ".", "currentStateBytes", "\n", "}" ]
// StateBytes is a JSON-encoded byte array of the currentState.
[ "StateBytes", "is", "a", "JSON", "-", "encoded", "byte", "array", "of", "the", "currentState", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L579-L583
142,098
decred/dcrdata
exchanges/bot.go
ConvertedStateBytes
func (bot *ExchangeBot) ConvertedStateBytes(symbol string) ([]byte, error) { state, err := bot.ConvertedState(symbol) if err != nil { return nil, err } return bot.jsonify(state) }
go
func (bot *ExchangeBot) ConvertedStateBytes(symbol string) ([]byte, error) { state, err := bot.ConvertedState(symbol) if err != nil { return nil, err } return bot.jsonify(state) }
[ "func", "(", "bot", "*", "ExchangeBot", ")", "ConvertedStateBytes", "(", "symbol", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "state", ",", "err", ":=", "bot", ".", "ConvertedState", "(", "symbol", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "bot", ".", "jsonify", "(", "state", ")", "\n", "}" ]
// ConvertedStateBytes gives a JSON-encoded byte array of the currentState // with a base of the provided currency code, if available.
[ "ConvertedStateBytes", "gives", "a", "JSON", "-", "encoded", "byte", "array", "of", "the", "currentState", "with", "a", "base", "of", "the", "provided", "currency", "code", "if", "available", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L594-L600
142,099
decred/dcrdata
exchanges/bot.go
AvailableIndices
func (bot *ExchangeBot) AvailableIndices() []string { bot.mtx.RLock() defer bot.mtx.RUnlock() var indices sort.StringSlice add := func(index string) { for _, symbol := range indices { if symbol == index { return } } indices = append(indices, index) } for _, fiatIndices := range bot.indexMap { for symbol := range fiatIndices { add(symbol) } } sort.Sort(indices) return indices }
go
func (bot *ExchangeBot) AvailableIndices() []string { bot.mtx.RLock() defer bot.mtx.RUnlock() var indices sort.StringSlice add := func(index string) { for _, symbol := range indices { if symbol == index { return } } indices = append(indices, index) } for _, fiatIndices := range bot.indexMap { for symbol := range fiatIndices { add(symbol) } } sort.Sort(indices) return indices }
[ "func", "(", "bot", "*", "ExchangeBot", ")", "AvailableIndices", "(", ")", "[", "]", "string", "{", "bot", ".", "mtx", ".", "RLock", "(", ")", "\n", "defer", "bot", ".", "mtx", ".", "RUnlock", "(", ")", "\n", "var", "indices", "sort", ".", "StringSlice", "\n", "add", ":=", "func", "(", "index", "string", ")", "{", "for", "_", ",", "symbol", ":=", "range", "indices", "{", "if", "symbol", "==", "index", "{", "return", "\n", "}", "\n", "}", "\n", "indices", "=", "append", "(", "indices", ",", "index", ")", "\n", "}", "\n", "for", "_", ",", "fiatIndices", ":=", "range", "bot", ".", "indexMap", "{", "for", "symbol", ":=", "range", "fiatIndices", "{", "add", "(", "symbol", ")", "\n", "}", "\n", "}", "\n", "sort", ".", "Sort", "(", "indices", ")", "\n", "return", "indices", "\n", "}" ]
// AvailableIndices creates a fresh slice of all available index currency codes.
[ "AvailableIndices", "creates", "a", "fresh", "slice", "of", "all", "available", "index", "currency", "codes", "." ]
02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6
https://github.com/decred/dcrdata/blob/02d6f8e648f7e2c5cf78ea92fb17b1d4aa4a99f6/exchanges/bot.go#L603-L622