Rename node table and node column

This commit is contained in:
Matt Krump
2018-03-21 13:24:13 -05:00
committed by Matt K
parent 02b23ef748
commit 1b4e57a5b4
6 changed files with 96 additions and 52 deletions
+3 -3
View File
@@ -39,13 +39,13 @@ func NewDB(databaseConfig config.Database, node core.Node) (*DB, error) {
func (db *DB) CreateNode(node *core.Node) error {
var nodeId int64
err := db.QueryRow(
`INSERT INTO nodes (genesis_block, network_id, node_id, client_name)
`INSERT INTO eth_nodes (genesis_block, network_id, eth_node_id, client_name)
VALUES ($1, $2, $3, $4)
ON CONFLICT (genesis_block, network_id, node_id)
ON CONFLICT (genesis_block, network_id, eth_node_id)
DO UPDATE
SET genesis_block = $1,
network_id = $2,
node_id = $3,
eth_node_id = $3,
client_name = $4
RETURNING id`,
node.GenesisBlock, node.NetworkID, node.ID, node.ClientName).Scan(&nodeId)
@@ -79,7 +79,7 @@ func (blockRepository BlockRepository) GetBlock(blockNumber int64) (core.Block,
reward,
uncles_reward
FROM blocks
WHERE node_id = $1 AND number = $2`, blockRepository.NodeID, blockNumber)
WHERE eth_node_id = $1 AND number = $2`, blockRepository.NodeID, blockNumber)
savedBlock, err := blockRepository.loadBlock(blockRows)
if err != nil {
switch err {
@@ -97,7 +97,7 @@ func (blockRepository BlockRepository) insertBlock(block core.Block) error {
tx, _ := blockRepository.DB.BeginTx(context.Background(), nil)
err := tx.QueryRow(
`INSERT INTO blocks
(node_id, number, gaslimit, gasused, time, difficulty, hash, nonce, parenthash, size, uncle_hash, is_final, miner, extra_data, reward, uncles_reward)
(eth_node_id, number, gaslimit, gasused, time, difficulty, hash, nonce, parenthash, size, uncle_hash, is_final, miner, extra_data, reward, uncles_reward)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
RETURNING id `,
blockRepository.NodeID, block.Number, block.GasLimit, block.GasUsed, block.Time, block.Difficulty, block.Hash, block.Nonce, block.ParentHash, block.Size, block.UncleHash, block.IsFinal, block.Miner, block.ExtraData, block.Reward, block.UnclesReward).
@@ -190,7 +190,7 @@ func (blockRepository BlockRepository) getBlockHash(block core.Block) (string, b
blockRepository.DB.Get(&retrievedBlockHash,
`SELECT hash
FROM blocks
WHERE number = $1 AND node_id = $2`,
WHERE number = $1 AND eth_node_id = $2`,
block.Number, blockRepository.NodeID)
return retrievedBlockHash, blockExists(retrievedBlockHash)
}
@@ -218,7 +218,7 @@ func (blockRepository BlockRepository) removeBlock(blockNumber int64) error {
_, err := blockRepository.DB.Exec(
`DELETE FROM
blocks
WHERE number=$1 AND node_id=$2`,
WHERE number=$1 AND eth_node_id=$2`,
blockNumber, blockRepository.NodeID)
if err != nil {
return postgres.ErrDBDeleteFailed