Add tx fields

This commit is contained in:
Matt Krump
2017-12-28 17:23:56 -06:00
parent 7a09839c23
commit 351d315a4c
8 changed files with 25 additions and 11 deletions
+10 -6
View File
@@ -294,9 +294,9 @@ func (repository Postgres) createTransactions(tx *sql.Tx, blockId int64, transac
for _, transaction := range transactions {
_, err := tx.Exec(
`INSERT INTO transactions
(block_id, tx_hash, tx_nonce, tx_to, tx_from, tx_gaslimit, tx_gasprice, tx_value)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`,
blockId, transaction.Hash, transaction.Nonce, transaction.To, transaction.From, transaction.GasLimit, transaction.GasPrice, transaction.Value)
(block_id, tx_hash, tx_nonce, tx_to, tx_from, tx_gaslimit, tx_gasprice, tx_value, tx_input_data)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
blockId, transaction.Hash, transaction.Nonce, transaction.To, transaction.From, transaction.GasLimit, transaction.GasPrice, transaction.Value, transaction.Data)
if err != nil {
return err
}
@@ -332,7 +332,8 @@ func (repository Postgres) loadBlock(blockRows *sql.Row) (core.Block, error) {
tx_from,
tx_gaslimit,
tx_gasprice,
tx_value
tx_value,
tx_input_data
FROM transactions
WHERE block_id = $1
ORDER BY tx_hash`, blockId)
@@ -392,8 +393,9 @@ func (repository Postgres) loadTransactions(transactionRows *sql.Rows) []core.Tr
var from string
var gasLimit int64
var gasPrice int64
var inputData string
var value int64
transactionRows.Scan(&hash, &nonce, &to, &from, &gasLimit, &gasPrice, &value)
transactionRows.Scan(&hash, &nonce, &to, &from, &gasLimit, &gasPrice, &value, &inputData)
transaction := core.Transaction{
Hash: hash,
Nonce: nonce,
@@ -402,6 +404,7 @@ func (repository Postgres) loadTransactions(transactionRows *sql.Rows) []core.Tr
GasLimit: gasLimit,
GasPrice: gasPrice,
Value: value,
Data: inputData,
}
transactions = append(transactions, transaction)
}
@@ -416,7 +419,8 @@ func (repository Postgres) addTransactions(contract core.Contract) core.Contract
tx_from,
tx_gaslimit,
tx_gasprice,
tx_value
tx_value,
tx_input_data
FROM transactions
WHERE tx_to = $1
ORDER BY block_id DESC`, contract.Hash)
+3
View File
@@ -191,6 +191,7 @@ func AssertRepositoryBehavior(buildRepository func(node core.Node) repositories.
to := "1234567890"
from := "0987654321"
value := int64(10)
inputData := "0xf7d8c8830000000000000000000000000000000000000000000000000000000000037788000000000000000000000000000000000000000000000000000000000003bd14"
transaction := core.Transaction{
Hash: "x1234",
GasPrice: gasPrice,
@@ -199,6 +200,7 @@ func AssertRepositoryBehavior(buildRepository func(node core.Node) repositories.
To: to,
From: from,
Value: value,
Data: inputData,
}
block := core.Block{
Number: 123,
@@ -210,6 +212,7 @@ func AssertRepositoryBehavior(buildRepository func(node core.Node) repositories.
savedBlock, _ := repository.FindBlockByNumber(123)
Expect(len(savedBlock.Transactions)).To(Equal(1))
savedTransaction := savedBlock.Transactions[0]
Expect(savedTransaction.Data).To(Equal(transaction.Data))
Expect(savedTransaction.Hash).To(Equal(transaction.Hash))
Expect(savedTransaction.To).To(Equal(to))
Expect(savedTransaction.From).To(Equal(from))