forked from cerc-io/ipld-eth-server
Add log index to Frob
This commit is contained in:
parent
b3d00fe3c5
commit
a0a86871b5
@ -1,14 +1,15 @@
|
||||
CREATE TABLE maker.frob (
|
||||
id SERIAL PRIMARY KEY,
|
||||
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
|
||||
ilk bytea,
|
||||
urn bytea,
|
||||
ilk TEXT,
|
||||
urn TEXT,
|
||||
dink NUMERIC,
|
||||
dart NUMERIC,
|
||||
ink NUMERIC,
|
||||
art NUMERIC,
|
||||
iart NUMERIC,
|
||||
log_idx INTEGER NOT NUll,
|
||||
tx_idx INTEGER NOT NUll,
|
||||
raw_log JSONB,
|
||||
UNIQUE (header_id, tx_idx)
|
||||
UNIQUE (header_id, tx_idx, log_idx)
|
||||
);
|
@ -1,7 +0,0 @@
|
||||
ALTER TABLE maker.bite
|
||||
ALTER COLUMN ilk SET DATA TYPE bytea,
|
||||
ALTER COLUMN urn SET DATA TYPE bytea;
|
||||
|
||||
ALTER TABLE maker.frob
|
||||
ALTER COLUMN ilk SET DATA TYPE bytea,
|
||||
ALTER COLUMN urn SET DATA TYPE bytea;
|
@ -1,7 +0,0 @@
|
||||
ALTER TABLE maker.bite
|
||||
ALTER COLUMN ilk SET DATA TYPE text,
|
||||
ALTER COLUMN urn SET DATA TYPE text;
|
||||
|
||||
ALTER TABLE maker.frob
|
||||
ALTER COLUMN ilk SET DATA TYPE text,
|
||||
ALTER COLUMN urn SET DATA TYPE text;
|
@ -507,6 +507,7 @@ CREATE TABLE maker.frob (
|
||||
ink numeric,
|
||||
art numeric,
|
||||
iart numeric,
|
||||
log_idx integer NOT NULL,
|
||||
tx_idx integer NOT NULL,
|
||||
raw_log jsonb
|
||||
);
|
||||
@ -1912,11 +1913,11 @@ ALTER TABLE ONLY maker.flop_kick
|
||||
|
||||
|
||||
--
|
||||
-- Name: frob frob_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
|
||||
-- Name: frob frob_header_id_tx_idx_log_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY maker.frob
|
||||
ADD CONSTRAINT frob_header_id_tx_idx_key UNIQUE (header_id, tx_idx);
|
||||
ADD CONSTRAINT frob_header_id_tx_idx_log_idx_key UNIQUE (header_id, tx_idx, log_idx);
|
||||
|
||||
|
||||
--
|
||||
|
@ -42,6 +42,10 @@ func (FrobConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]Frob
|
||||
}
|
||||
contract := bind.NewBoundContract(address, abi, nil, nil, nil)
|
||||
err = contract.UnpackLog(&entity, "Frob", ethLog)
|
||||
if err != nil {
|
||||
return entities, err
|
||||
}
|
||||
entity.LogIndex = ethLog.Index
|
||||
entity.TransactionIndex = ethLog.TxIndex
|
||||
entity.Raw = ethLog
|
||||
entities = append(entities, entity)
|
||||
@ -65,6 +69,7 @@ func (FrobConverter) ToModels(entities []FrobEntity) ([]FrobModel, error) {
|
||||
Dink: entity.Dink.String(),
|
||||
Dart: entity.Dart.String(),
|
||||
IArt: entity.IArt.String(),
|
||||
LogIndex: entity.LogIndex,
|
||||
TransactionIndex: entity.TransactionIndex,
|
||||
Raw: rawLog,
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ type FrobEntity struct {
|
||||
Dink *big.Int
|
||||
Dart *big.Int
|
||||
IArt *big.Int
|
||||
LogIndex uint
|
||||
TransactionIndex uint
|
||||
Raw types.Log
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ type FrobModel struct {
|
||||
Dink string
|
||||
Dart string
|
||||
IArt string
|
||||
LogIndex uint `db:"log_idx"`
|
||||
TransactionIndex uint `db:"tx_idx"`
|
||||
Raw []byte `db:"raw_log"`
|
||||
}
|
||||
|
@ -39,9 +39,9 @@ func (repository FrobRepository) Create(headerID int64, models []FrobModel) erro
|
||||
return err
|
||||
}
|
||||
for _, model := range models {
|
||||
_, err = tx.Exec(`INSERT INTO maker.frob (header_id, art, dart, dink, iart, ilk, ink, urn, raw_log, tx_idx)
|
||||
VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5::NUMERIC, $6, $7::NUMERIC, $8, $9, $10)`,
|
||||
headerID, model.Art, model.Dart, model.Dink, model.IArt, model.Ilk, model.Ink, model.Urn, model.Raw, model.TransactionIndex)
|
||||
_, err = tx.Exec(`INSERT INTO maker.frob (header_id, art, dart, dink, iart, ilk, ink, urn, raw_log, log_idx, tx_idx)
|
||||
VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5::NUMERIC, $6, $7::NUMERIC, $8, $9, $10, $11)`,
|
||||
headerID, model.Art, model.Dart, model.Dink, model.IArt, model.Ilk, model.Ink, model.Urn, model.Raw, model.LogIndex, model.TransactionIndex)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
|
@ -51,14 +51,14 @@ var _ = Describe("Frob repository", func() {
|
||||
BeforeEach(func() {
|
||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = frobRepository.Create(headerID, []frob.FrobModel{test_data.FrobModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("adds a frob", func() {
|
||||
err = frobRepository.Create(headerID, []frob.FrobModel{test_data.FrobModel})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
var dbFrob frob.FrobModel
|
||||
err = db.Get(&dbFrob, `SELECT art, dart, dink, iart, ilk, ink, urn, tx_idx, raw_log FROM maker.frob WHERE header_id = $1`, headerID)
|
||||
err = db.Get(&dbFrob, `SELECT art, dart, dink, iart, ilk, ink, urn, log_idx, tx_idx, raw_log FROM maker.frob WHERE header_id = $1`, headerID)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(dbFrob.Ilk).To(Equal(test_data.FrobModel.Ilk))
|
||||
Expect(dbFrob.Urn).To(Equal(test_data.FrobModel.Urn))
|
||||
@ -67,11 +67,28 @@ var _ = Describe("Frob repository", func() {
|
||||
Expect(dbFrob.Dink).To(Equal(test_data.FrobModel.Dink))
|
||||
Expect(dbFrob.Dart).To(Equal(test_data.FrobModel.Dart))
|
||||
Expect(dbFrob.IArt).To(Equal(test_data.FrobModel.IArt))
|
||||
Expect(dbFrob.LogIndex).To(Equal(test_data.FrobModel.LogIndex))
|
||||
Expect(dbFrob.TransactionIndex).To(Equal(test_data.FrobModel.TransactionIndex))
|
||||
Expect(dbFrob.Raw).To(MatchJSON(test_data.FrobModel.Raw))
|
||||
})
|
||||
|
||||
It("marks header as checked for logs", func() {
|
||||
err = frobRepository.Create(headerID, []frob.FrobModel{test_data.FrobModel})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
var headerChecked bool
|
||||
err = db.Get(&headerChecked, `SELECT frob_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(headerChecked).To(BeTrue())
|
||||
})
|
||||
|
||||
It("updates the header to checked if checked headers row already exists", func() {
|
||||
_, err = db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerID)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = frobRepository.Create(headerID, []frob.FrobModel{test_data.FrobModel})
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
var headerChecked bool
|
||||
err = db.Get(&headerChecked, `SELECT frob_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -79,6 +96,9 @@ var _ = Describe("Frob repository", func() {
|
||||
})
|
||||
|
||||
It("does not duplicate frob events", func() {
|
||||
err = frobRepository.Create(headerID, []frob.FrobModel{test_data.FrobModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = frobRepository.Create(headerID, []frob.FrobModel{test_data.FrobModel})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
@ -86,11 +106,14 @@ var _ = Describe("Frob repository", func() {
|
||||
})
|
||||
|
||||
It("removes frob if corresponding header is deleted", func() {
|
||||
err = frobRepository.Create(headerID, []frob.FrobModel{test_data.FrobModel})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
var dbFrob frob.FrobModel
|
||||
err = db.Get(&dbFrob, `SELECT art, iart, ilk, ink, urn, tx_idx, raw_log FROM maker.frob WHERE header_id = $1`, headerID)
|
||||
err = db.Get(&dbFrob, `SELECT art, iart, ilk, ink, urn, log_idx, tx_idx, raw_log FROM maker.frob WHERE header_id = $1`, headerID)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err).To(MatchError(sql.ErrNoRows))
|
||||
})
|
||||
|
@ -57,7 +57,7 @@ var EthFrobLog = types.Log{
|
||||
TxHash: common.HexToHash(TemporaryFrobTransaction),
|
||||
TxIndex: 123,
|
||||
BlockHash: TemporaryFrobBlockHash,
|
||||
Index: 0,
|
||||
Index: 7,
|
||||
Removed: false,
|
||||
}
|
||||
|
||||
@ -69,6 +69,7 @@ var FrobEntity = frob.FrobEntity{
|
||||
Dink: dink,
|
||||
Dart: dart,
|
||||
IArt: iArt,
|
||||
LogIndex: EthFrobLog.Index,
|
||||
TransactionIndex: EthFrobLog.TxIndex,
|
||||
Raw: EthFrobLog,
|
||||
}
|
||||
@ -82,6 +83,7 @@ var FrobModel = frob.FrobModel{
|
||||
Dink: dink.String(),
|
||||
Dart: dart.String(),
|
||||
IArt: iArt.String(),
|
||||
LogIndex: EthFrobLog.Index,
|
||||
TransactionIndex: EthFrobLog.TxIndex,
|
||||
Raw: rawFrobLog,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user