forked from cerc-io/ipld-eth-server
Update table columns (#26)
* Update block table names * Update transaction table names
This commit is contained in:
+13
-13
@@ -1,20 +1,20 @@
|
||||
package core
|
||||
|
||||
type Block struct {
|
||||
Reward float64 `db:"block_reward"`
|
||||
Difficulty int64 `db:"block_difficulty"`
|
||||
ExtraData string `db:"block_extra_data"`
|
||||
GasLimit int64 `db:"block_gaslimit"`
|
||||
GasUsed int64 `db:"block_gasused"`
|
||||
Hash string `db:"block_hash"`
|
||||
Reward float64 `db:"reward"`
|
||||
Difficulty int64 `db:"difficulty"`
|
||||
ExtraData string `db:"extra_data"`
|
||||
GasLimit int64 `db:"gaslimit"`
|
||||
GasUsed int64 `db:"gasused"`
|
||||
Hash string `db:"hash"`
|
||||
IsFinal bool `db:"is_final"`
|
||||
Miner string `db:"block_miner"`
|
||||
Nonce string `db:"block_nonce"`
|
||||
Number int64 `db:"block_number"`
|
||||
ParentHash string `db:"block_parenthash"`
|
||||
Size int64 `db:"block_size"`
|
||||
Time int64 `db:"block_time"`
|
||||
Miner string `db:"miner"`
|
||||
Nonce string `db:"nonce"`
|
||||
Number int64 `db:"number"`
|
||||
ParentHash string `db:"parenthash"`
|
||||
Size int64 `db:"size"`
|
||||
Time int64 `db:"time"`
|
||||
Transactions []Transaction
|
||||
UncleHash string `db:"uncle_hash"`
|
||||
UnclesReward float64 `db:"block_uncles_reward"`
|
||||
UnclesReward float64 `db:"uncles_reward"`
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package core
|
||||
|
||||
type Transaction struct {
|
||||
Hash string `db:"tx_hash"`
|
||||
Data string `db:"tx_input_data"`
|
||||
Nonce uint64 `db:"tx_nonce"`
|
||||
Hash string `db:"hash"`
|
||||
Data string `db:"input_data"`
|
||||
Nonce uint64 `db:"nonce"`
|
||||
To string `db:"tx_to"`
|
||||
From string `db:"tx_from"`
|
||||
GasLimit int64 `db:"tx_gaslimit"`
|
||||
GasPrice int64 `db:"tx_gasprice"`
|
||||
GasLimit int64 `db:"gaslimit"`
|
||||
GasPrice int64 `db:"gasprice"`
|
||||
Receipt
|
||||
Value string `db:"tx_value"`
|
||||
Value string `db:"value"`
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func (db DB) SetBlocksStatus(chainHead int64) {
|
||||
cutoff := chainHead - blocksFromHeadBeforeFinal
|
||||
db.DB.Exec(`
|
||||
UPDATE blocks SET is_final = TRUE
|
||||
WHERE is_final = FALSE AND block_number < $1`,
|
||||
WHERE is_final = FALSE AND number < $1`,
|
||||
cutoff)
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ func (db DB) MissingBlockNumbers(startingBlockNumber int64, highestBlockNumber i
|
||||
FROM (
|
||||
SELECT generate_series($1::INT, $2::INT) AS all_block_numbers) series
|
||||
LEFT JOIN blocks
|
||||
ON block_number = all_block_numbers
|
||||
WHERE block_number ISNULL`,
|
||||
ON number = all_block_numbers
|
||||
WHERE number ISNULL`,
|
||||
startingBlockNumber,
|
||||
highestBlockNumber)
|
||||
return numbers
|
||||
@@ -59,23 +59,23 @@ func (db DB) MissingBlockNumbers(startingBlockNumber int64, highestBlockNumber i
|
||||
func (db DB) FindBlockByNumber(blockNumber int64) (core.Block, error) {
|
||||
blockRows := db.DB.QueryRowx(
|
||||
`SELECT id,
|
||||
block_number,
|
||||
block_gaslimit,
|
||||
block_gasused,
|
||||
block_time,
|
||||
block_difficulty,
|
||||
block_hash,
|
||||
block_nonce,
|
||||
block_parenthash,
|
||||
block_size,
|
||||
number,
|
||||
gaslimit,
|
||||
gasused,
|
||||
time,
|
||||
difficulty,
|
||||
hash,
|
||||
nonce,
|
||||
parenthash,
|
||||
size,
|
||||
uncle_hash,
|
||||
is_final,
|
||||
block_miner,
|
||||
block_extra_data,
|
||||
block_reward,
|
||||
block_uncles_reward
|
||||
miner,
|
||||
extra_data,
|
||||
reward,
|
||||
uncles_reward
|
||||
FROM blocks
|
||||
WHERE node_id = $1 AND block_number = $2`, db.nodeId, blockNumber)
|
||||
WHERE node_id = $1 AND number = $2`, db.nodeId, blockNumber)
|
||||
savedBlock, err := db.loadBlock(blockRows)
|
||||
if err != nil {
|
||||
switch err {
|
||||
@@ -93,7 +93,7 @@ func (db DB) insertBlock(block core.Block) error {
|
||||
tx, _ := db.DB.BeginTx(context.Background(), nil)
|
||||
err := tx.QueryRow(
|
||||
`INSERT INTO blocks
|
||||
(node_id, block_number, block_gaslimit, block_gasused, block_time, block_difficulty, block_hash, block_nonce, block_parenthash, block_size, uncle_hash, is_final, block_miner, block_extra_data, block_reward, block_uncles_reward)
|
||||
(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 `,
|
||||
db.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).
|
||||
@@ -135,7 +135,7 @@ func (db DB) createTransaction(tx *sql.Tx, blockId int64, transaction core.Trans
|
||||
var transactionId int
|
||||
err := tx.QueryRow(
|
||||
`INSERT INTO transactions
|
||||
(block_id, tx_hash, tx_nonce, tx_to, tx_from, tx_gaslimit, tx_gasprice, tx_value, tx_input_data)
|
||||
(block_id, hash, nonce, tx_to, tx_from, gaslimit, gasprice, value, input_data)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8::NUMERIC, $9)
|
||||
RETURNING id`,
|
||||
blockId, transaction.Hash, transaction.Nonce, transaction.To, transaction.From, transaction.GasLimit, transaction.GasPrice, nullStringToZero(transaction.Value), transaction.Data).
|
||||
@@ -184,9 +184,9 @@ func (db DB) createReceipt(tx *sql.Tx, transactionId int, receipt core.Receipt)
|
||||
func (db DB) getBlockHash(block core.Block) (string, bool) {
|
||||
var retrievedBlockHash string
|
||||
db.DB.Get(&retrievedBlockHash,
|
||||
`SELECT block_hash
|
||||
`SELECT hash
|
||||
FROM blocks
|
||||
WHERE block_number = $1 AND node_id = $2`,
|
||||
WHERE number = $1 AND node_id = $2`,
|
||||
block.Number, db.nodeId)
|
||||
return retrievedBlockHash, blockExists(retrievedBlockHash)
|
||||
}
|
||||
@@ -214,7 +214,7 @@ func (db DB) removeBlock(blockNumber int64) error {
|
||||
_, err := db.DB.Exec(
|
||||
`DELETE FROM
|
||||
blocks
|
||||
WHERE block_number=$1 AND node_id=$2`,
|
||||
WHERE number=$1 AND node_id=$2`,
|
||||
blockNumber, db.nodeId)
|
||||
if err != nil {
|
||||
return ErrDBDeleteFailed
|
||||
@@ -233,17 +233,17 @@ func (db DB) loadBlock(blockRows *sqlx.Row) (core.Block, error) {
|
||||
return core.Block{}, err
|
||||
}
|
||||
transactionRows, err := db.DB.Queryx(`
|
||||
SELECT tx_hash,
|
||||
tx_nonce,
|
||||
SELECT hash,
|
||||
nonce,
|
||||
tx_to,
|
||||
tx_from,
|
||||
tx_gaslimit,
|
||||
tx_gasprice,
|
||||
tx_value,
|
||||
tx_input_data
|
||||
gaslimit,
|
||||
gasprice,
|
||||
value,
|
||||
input_data
|
||||
FROM transactions
|
||||
WHERE block_id = $1
|
||||
ORDER BY tx_hash`, block.ID)
|
||||
ORDER BY hash`, block.ID)
|
||||
if err != nil {
|
||||
return core.Block{}, err
|
||||
}
|
||||
|
||||
@@ -51,14 +51,14 @@ func (db DB) FindContract(contractHash string) (core.Contract, error) {
|
||||
|
||||
func (db DB) addTransactions(contract core.Contract) core.Contract {
|
||||
transactionRows, _ := db.DB.Queryx(`
|
||||
SELECT tx_hash,
|
||||
tx_nonce,
|
||||
SELECT hash,
|
||||
nonce,
|
||||
tx_to,
|
||||
tx_from,
|
||||
tx_gaslimit,
|
||||
tx_gasprice,
|
||||
tx_value,
|
||||
tx_input_data
|
||||
gaslimit,
|
||||
gasprice,
|
||||
value,
|
||||
input_data
|
||||
FROM transactions
|
||||
WHERE tx_to = $1
|
||||
ORDER BY block_id DESC`, contract.Hash)
|
||||
|
||||
Reference in New Issue
Block a user