Added From field to transactions

This commit is contained in:
Matt Krump
2017-11-09 16:51:22 -06:00
parent 84205a21ea
commit c7bd6de7da
9 changed files with 57 additions and 28 deletions
+7 -5
View File
@@ -99,9 +99,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_gaslimit, tx_gasprice, tx_value)
VALUES ($1, $2, $3, $4, $5, $6, $7)`,
blockId, transaction.Hash, transaction.Nonce, transaction.To, transaction.GasLimit, transaction.GasPrice, transaction.Value)
(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)
if err != nil {
return err
}
@@ -138,20 +138,22 @@ func (repository Postgres) loadBlock(blockRows *sql.Rows) core.Block {
}
}
func (repository Postgres) loadTransactions(blockId int64) []core.Transaction {
transactionRows, _ := repository.Db.Query(`SELECT tx_hash, tx_nonce, tx_to, tx_gaslimit, tx_gasprice, tx_value FROM transactions`)
transactionRows, _ := repository.Db.Query(`SELECT tx_hash, tx_nonce, tx_to, tx_from, tx_gaslimit, tx_gasprice, tx_value FROM transactions`)
var transactions []core.Transaction
for transactionRows.Next() {
var hash string
var nonce uint64
var to string
var from string
var gasLimit int64
var gasPrice int64
var value int64
transactionRows.Scan(&hash, &nonce, &to, &gasLimit, &gasPrice, &value)
transactionRows.Scan(&hash, &nonce, &to, &from, &gasLimit, &gasPrice, &value)
transaction := core.Transaction{
Hash: hash,
Nonce: nonce,
To: to,
From: from,
GasLimit: gasLimit,
GasPrice: gasPrice,
Value: value,
+3
View File
@@ -111,6 +111,7 @@ var _ = Describe("Repositories", func() {
gasPrice := int64(3)
nonce := uint64(10000)
to := "1234567890"
from := "0987654321"
value := int64(10)
transaction := core.Transaction{
Hash: "x1234",
@@ -118,6 +119,7 @@ var _ = Describe("Repositories", func() {
GasLimit: gasLimit,
Nonce: nonce,
To: to,
From: from,
Value: value,
}
block := core.Block{
@@ -132,6 +134,7 @@ var _ = Describe("Repositories", func() {
savedTransaction := savedBlock.Transactions[0]
Expect(savedTransaction.Hash).To(Equal(transaction.Hash))
Expect(savedTransaction.To).To(Equal(to))
Expect(savedTransaction.From).To(Equal(from))
Expect(savedTransaction.Nonce).To(Equal(nonce))
Expect(savedTransaction.GasLimit).To(Equal(gasLimit))
Expect(savedTransaction.GasPrice).To(Equal(gasPrice))