Add tx fields
This commit is contained in:
parent
7a09839c23
commit
351d315a4c
@ -0,0 +1,2 @@
|
||||
ALTER TABLE transactions
|
||||
DROP COLUMN tx_input_data;
|
@ -0,0 +1,2 @@
|
||||
ALTER TABLE transactions
|
||||
ADD COLUMN tx_input_data VARCHAR;
|
@ -168,7 +168,8 @@ CREATE TABLE transactions (
|
||||
tx_gasprice numeric,
|
||||
tx_value numeric,
|
||||
block_id integer NOT NULL,
|
||||
tx_from character varying(66)
|
||||
tx_from character varying(66),
|
||||
tx_input_data character varying
|
||||
);
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@ package core
|
||||
|
||||
type Transaction struct {
|
||||
Hash string
|
||||
Data []byte
|
||||
Data string
|
||||
Nonce uint64
|
||||
To string
|
||||
From string
|
||||
|
@ -44,15 +44,16 @@ func GethBlockToCoreBlock(gethBlock *types.Block, client GethClient) core.Block
|
||||
}
|
||||
|
||||
func gethTransToCoreTrans(transaction *types.Transaction, from *common.Address) core.Transaction {
|
||||
data := hexutil.Encode(transaction.Data())
|
||||
return core.Transaction{
|
||||
Hash: transaction.Hash().Hex(),
|
||||
Data: transaction.Data(),
|
||||
Nonce: transaction.Nonce(),
|
||||
To: strings.ToLower(addressToHex(transaction.To())),
|
||||
From: strings.ToLower(addressToHex(from)),
|
||||
GasLimit: transaction.Gas().Int64(),
|
||||
GasPrice: transaction.GasPrice().Int64(),
|
||||
Value: transaction.Value().Int64(),
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,8 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
amount := big.NewInt(10)
|
||||
gasLimit := big.NewInt(5000)
|
||||
gasPrice := big.NewInt(3)
|
||||
payload := []byte("1234")
|
||||
input := "0xf7d8c8830000000000000000000000000000000000000000000000000000000000037788000000000000000000000000000000000000000000000000000000000003bd14"
|
||||
payload, _ := hexutil.Decode(input)
|
||||
|
||||
gethTransaction := types.NewTransaction(nonce, to, amount, gasLimit, gasPrice, payload)
|
||||
|
||||
@ -214,7 +215,7 @@ var _ = Describe("Conversion of GethBlock to core.Block", func() {
|
||||
|
||||
Expect(len(coreBlock.Transactions)).To(Equal(1))
|
||||
coreTransaction := coreBlock.Transactions[0]
|
||||
Expect(coreTransaction.Data).To(Equal(gethTransaction.Data()))
|
||||
Expect(coreTransaction.Data).To(Equal(input))
|
||||
Expect(coreTransaction.To).To(Equal(gethTransaction.To().Hex()))
|
||||
Expect(coreTransaction.From).To(Equal("0x0000000000000000000000000000000000000123"))
|
||||
Expect(coreTransaction.GasLimit).To(Equal(gethTransaction.Gas().Int64()))
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user