Add store logs with receipts
This commit is contained in:
parent
a9bea4f492
commit
431be46005
@ -102,6 +102,7 @@ func (repository *InMemory) CreateOrUpdateBlock(block core.Block) error {
|
||||
repository.blocks[block.Number] = block
|
||||
for _, transaction := range block.Transactions {
|
||||
repository.receipts[transaction.Hash] = transaction.Receipt
|
||||
repository.logs[transaction.TxHash] = transaction.Logs
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -344,6 +344,9 @@ func (repository Postgres) createTransaction(tx *sql.Tx, blockId int64, transact
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(transaction.Receipt.Logs) > 0 {
|
||||
err = repository.CreateLogs(transaction.Receipt.Logs)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -504,6 +504,87 @@ func AssertRepositoryBehavior(buildRepository func(node core.Node) repositories.
|
||||
{blockNumber: 1, Index: 1}},
|
||||
))
|
||||
})
|
||||
|
||||
It("saves the logs attached to a receipt", func() {
|
||||
logs := []core.Log{{
|
||||
Address: "0x8a4774fe82c63484afef97ca8d89a6ea5e21f973",
|
||||
BlockNumber: 4745407,
|
||||
Data: "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000645a68669900000000000000000000000000000000000000000000003397684ab5869b0000000000000000000000000000000000000000000000000000000000005a36053200000000000000000000000099041f808d598b782d5a3e498681c2452a31da08",
|
||||
Index: 86,
|
||||
Topics: map[int]string{
|
||||
0: "0x5a68669900000000000000000000000000000000000000000000000000000000",
|
||||
1: "0x000000000000000000000000d0148dad63f73ce6f1b6c607e3413dcf1ff5f030",
|
||||
2: "0x00000000000000000000000000000000000000000000003397684ab5869b0000",
|
||||
3: "0x000000000000000000000000000000000000000000000000000000005a360532",
|
||||
},
|
||||
TxHash: "0x002c4799161d809b23f67884eb6598c9df5894929fe1a9ead97ca175d360f547",
|
||||
}, {
|
||||
Address: "0x99041f808d598b782d5a3e498681c2452a31da08",
|
||||
BlockNumber: 4745407,
|
||||
Data: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000418178358",
|
||||
Index: 87,
|
||||
Topics: map[int]string{
|
||||
0: "0x1817835800000000000000000000000000000000000000000000000000000000",
|
||||
1: "0x0000000000000000000000008a4774fe82c63484afef97ca8d89a6ea5e21f973",
|
||||
2: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
3: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
},
|
||||
TxHash: "0x002c4799161d809b23f67884eb6598c9df5894929fe1a9ead97ca175d360f547",
|
||||
}, {
|
||||
Address: "0x99041f808d598b782d5a3e498681c2452a31da08",
|
||||
BlockNumber: 4745407,
|
||||
Data: "0x00000000000000000000000000000000000000000000003338f64c8423af4000",
|
||||
Index: 88,
|
||||
Topics: map[int]string{
|
||||
0: "0x296ba4ca62c6c21c95e828080cb8aec7481b71390585605300a8a76f9e95b527",
|
||||
},
|
||||
TxHash: "0x002c4799161d809b23f67884eb6598c9df5894929fe1a9ead97ca175d360f547",
|
||||
},
|
||||
}
|
||||
receipt := core.Receipt{
|
||||
ContractAddress: "",
|
||||
CumulativeGasUsed: 7481414,
|
||||
GasUsed: 60711,
|
||||
Logs: logs,
|
||||
Bloom: "0x00000800000000000000001000000000000000400000000080000000000000000000400000010000000000000000000000000000040000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800004000000000000001000000000000000000000000000002000000480000000000000002000000000000000020000000000000000000000000000000000000000080000000000180000c00000000000000002000002000000040000000000000000000000000000010000000000020000000000000000000002000000000000000000000000400800000000000000000",
|
||||
Status: 1,
|
||||
TxHash: "0x002c4799161d809b23f67884eb6598c9df5894929fe1a9ead97ca175d360f547",
|
||||
}
|
||||
transaction :=
|
||||
core.Transaction{
|
||||
Hash: receipt.TxHash,
|
||||
Receipt: receipt,
|
||||
}
|
||||
|
||||
block := core.Block{Transactions: []core.Transaction{transaction}}
|
||||
repository.CreateOrUpdateBlock(block)
|
||||
retrievedLogs := repository.FindLogs("0x99041f808d598b782d5a3e498681c2452a31da08", 4745407)
|
||||
|
||||
Expect(retrievedLogs).To(Not(BeZero()))
|
||||
})
|
||||
|
||||
It("saves the logs attached to a receipt", func() {
|
||||
logs := make([]core.Log, 0)
|
||||
receipt := core.Receipt{
|
||||
Logs: logs,
|
||||
TxHash: "0x002c4799161d809b23f67884eb6598c9df5894929fe1a9ead97ca175d360f547",
|
||||
}
|
||||
transaction := core.Transaction{
|
||||
Hash: receipt.TxHash,
|
||||
Receipt: receipt,
|
||||
}
|
||||
|
||||
block := core.Block{
|
||||
Transactions: []core.Transaction{transaction},
|
||||
}
|
||||
repository.CreateOrUpdateBlock(block)
|
||||
|
||||
retrievedLogs := repository.FindLogs("0x99041f808d598b782d5a3e498681c2452a31da08", 4745407)
|
||||
_, err := repository.FindReceipt(receipt.TxHash)
|
||||
|
||||
Expect(err).To(Not(HaveOccurred()))
|
||||
Expect(retrievedLogs).To(BeZero())
|
||||
})
|
||||
})
|
||||
|
||||
Describe("Saving receipts", func() {
|
||||
|
Loading…
Reference in New Issue
Block a user