forked from cerc-io/ipld-eth-server
Add log index to Tend
This commit is contained in:
parent
e0253cce55
commit
db52955669
@ -4,9 +4,10 @@ CREATE TABLE maker.tend (
|
|||||||
bid_id NUMERIC NOT NULL UNIQUE,
|
bid_id NUMERIC NOT NULL UNIQUE,
|
||||||
lot NUMERIC,
|
lot NUMERIC,
|
||||||
bid NUMERIC,
|
bid NUMERIC,
|
||||||
guy VARCHAR,
|
guy TEXT,
|
||||||
tic NUMERIC,
|
tic NUMERIC,
|
||||||
|
log_idx INTEGER NOT NUll,
|
||||||
tx_idx INTEGER NOT NUll,
|
tx_idx INTEGER NOT NUll,
|
||||||
raw_log JSONB,
|
raw_log JSONB,
|
||||||
UNIQUE (header_id, tx_idx)
|
UNIQUE (header_id, tx_idx, log_idx)
|
||||||
);
|
);
|
||||||
|
@ -685,8 +685,9 @@ CREATE TABLE maker.tend (
|
|||||||
bid_id numeric NOT NULL,
|
bid_id numeric NOT NULL,
|
||||||
lot numeric,
|
lot numeric,
|
||||||
bid numeric,
|
bid numeric,
|
||||||
guy character varying,
|
guy text,
|
||||||
tic numeric,
|
tic numeric,
|
||||||
|
log_idx integer NOT NULL,
|
||||||
tx_idx integer NOT NULL,
|
tx_idx integer NOT NULL,
|
||||||
raw_log jsonb
|
raw_log jsonb
|
||||||
);
|
);
|
||||||
@ -1994,11 +1995,11 @@ ALTER TABLE ONLY maker.price_feeds
|
|||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: tend tend_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
|
-- Name: tend tend_header_id_tx_idx_log_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
ALTER TABLE ONLY maker.tend
|
ALTER TABLE ONLY maker.tend
|
||||||
ADD CONSTRAINT tend_header_id_tx_idx_key UNIQUE (header_id, tx_idx);
|
ADD CONSTRAINT tend_header_id_tx_idx_log_idx_key UNIQUE (header_id, tx_idx, log_idx);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
|
@ -44,6 +44,7 @@ func (TendConverter) ToModels(ethLogs []types.Log) (results []interface{}, err e
|
|||||||
//TODO: it is likely that the tic value will need to be added to an emitted event,
|
//TODO: it is likely that the tic value will need to be added to an emitted event,
|
||||||
//so this will need to be updated at that point
|
//so this will need to be updated at that point
|
||||||
transactionIndex := ethLog.TxIndex
|
transactionIndex := ethLog.TxIndex
|
||||||
|
logIndex := ethLog.Index
|
||||||
|
|
||||||
rawJson, err := json.Marshal(ethLog)
|
rawJson, err := json.Marshal(ethLog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -57,6 +58,7 @@ func (TendConverter) ToModels(ethLogs []types.Log) (results []interface{}, err e
|
|||||||
Bid: bidValue,
|
Bid: bidValue,
|
||||||
Guy: guy,
|
Guy: guy,
|
||||||
Tic: tic,
|
Tic: tic,
|
||||||
|
LogIndex: logIndex,
|
||||||
TransactionIndex: transactionIndex,
|
TransactionIndex: transactionIndex,
|
||||||
Raw: raw,
|
Raw: raw,
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ type TendModel struct {
|
|||||||
Bid string
|
Bid string
|
||||||
Guy string
|
Guy string
|
||||||
Tic string
|
Tic string
|
||||||
|
LogIndex uint `db:"log_idx"`
|
||||||
TransactionIndex uint `db:"tx_idx"`
|
TransactionIndex uint `db:"tx_idx"`
|
||||||
Raw string `db:"raw_log"`
|
Raw string `db:"raw_log"`
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@ func (repository TendRepository) Create(headerId int64, models []interface{}) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec(
|
_, err = tx.Exec(
|
||||||
`INSERT into maker.tend (header_id, bid_id, lot, bid, guy, tic, tx_idx, raw_log)
|
`INSERT into maker.tend (header_id, bid_id, lot, bid, guy, tic, log_idx, tx_idx, raw_log)
|
||||||
VALUES($1, $2, $3, $4, $5, $6, $7, $8)`,
|
VALUES($1, $2, $3::NUMERIC, $4::NUMERIC, $5, $6::NUMERIC, $7, $8, $9)`,
|
||||||
headerId, tend.BidId, tend.Lot, tend.Bid, tend.Guy, tend.Tic, tend.TransactionIndex, tend.Raw,
|
headerId, tend.BidId, tend.Lot, tend.Bid, tend.Guy, tend.Tic, tend.LogIndex, tend.TransactionIndex, tend.Raw,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,19 +50,19 @@ var _ = Describe("TendRepository", func() {
|
|||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
headerId, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
headerId, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = tendRepository.Create(headerId, []interface{}{test_data.TendModel})
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("persists a tend record", func() {
|
It("persists a tend record", func() {
|
||||||
|
err = tendRepository.Create(headerId, []interface{}{test_data.TendModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var count int
|
var count int
|
||||||
err = db.QueryRow(`SELECT count(*) from maker.tend`).Scan(&count)
|
err = db.QueryRow(`SELECT count(*) from maker.tend`).Scan(&count)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(count).To(Equal(1))
|
Expect(count).To(Equal(1))
|
||||||
|
|
||||||
dbResult := tend.TendModel{}
|
dbResult := tend.TendModel{}
|
||||||
err = db.Get(&dbResult, `SELECT bid_id, lot, bid, guy, tic, tx_idx, raw_log FROM maker.tend WHERE header_id = $1`, headerId)
|
err = db.Get(&dbResult, `SELECT bid_id, lot, bid, guy, tic, log_idx, tx_idx, raw_log FROM maker.tend WHERE header_id = $1`, headerId)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
Expect(dbResult.BidId).To(Equal(test_data.TendModel.BidId))
|
Expect(dbResult.BidId).To(Equal(test_data.TendModel.BidId))
|
||||||
@ -70,11 +70,28 @@ var _ = Describe("TendRepository", func() {
|
|||||||
Expect(dbResult.Bid).To(Equal(test_data.TendModel.Bid))
|
Expect(dbResult.Bid).To(Equal(test_data.TendModel.Bid))
|
||||||
Expect(dbResult.Guy).To(Equal(test_data.TendModel.Guy))
|
Expect(dbResult.Guy).To(Equal(test_data.TendModel.Guy))
|
||||||
Expect(dbResult.Tic).To(Equal(test_data.TendModel.Tic))
|
Expect(dbResult.Tic).To(Equal(test_data.TendModel.Tic))
|
||||||
|
Expect(dbResult.LogIndex).To(Equal(test_data.TendModel.LogIndex))
|
||||||
Expect(dbResult.TransactionIndex).To(Equal(test_data.TendModel.TransactionIndex))
|
Expect(dbResult.TransactionIndex).To(Equal(test_data.TendModel.TransactionIndex))
|
||||||
Expect(dbResult.Raw).To(MatchJSON(test_data.RawLogNoteJson))
|
Expect(dbResult.Raw).To(MatchJSON(test_data.RawLogNoteJson))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("marks header as checked", func() {
|
It("marks header as checked", func() {
|
||||||
|
err = tendRepository.Create(headerId, []interface{}{test_data.TendModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
var headerChecked bool
|
||||||
|
err = db.Get(&headerChecked, `SELECT tend_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 = tendRepository.Create(headerId, []interface{}{test_data.TendModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var headerChecked bool
|
var headerChecked bool
|
||||||
err = db.Get(&headerChecked, `SELECT tend_checked FROM public.checked_headers WHERE header_id = $1`, headerId)
|
err = db.Get(&headerChecked, `SELECT tend_checked FROM public.checked_headers WHERE header_id = $1`, headerId)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
@ -83,11 +100,17 @@ var _ = Describe("TendRepository", func() {
|
|||||||
|
|
||||||
It("returns an error if inserting a tend record fails", func() {
|
It("returns an error if inserting a tend record fails", func() {
|
||||||
err = tendRepository.Create(headerId, []interface{}{test_data.TendModel})
|
err = tendRepository.Create(headerId, []interface{}{test_data.TendModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
err = tendRepository.Create(headerId, []interface{}{test_data.TendModel})
|
||||||
|
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
|
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("deletes the tend record if its corresponding header record is deleted", func() {
|
It("deletes the tend record if its corresponding header record is deleted", func() {
|
||||||
|
err = tendRepository.Create(headerId, []interface{}{test_data.TendModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var count int
|
var count int
|
||||||
err = db.QueryRow(`SELECT count(*) from maker.tend`).Scan(&count)
|
err = db.QueryRow(`SELECT count(*) from maker.tend`).Scan(&count)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
@ -61,6 +61,7 @@ var TendModel = tend.TendModel{
|
|||||||
Bid: tendBid,
|
Bid: tendBid,
|
||||||
Guy: tendGuy,
|
Guy: tendGuy,
|
||||||
Tic: TendTic,
|
Tic: TendTic,
|
||||||
|
LogIndex: TendLogNote.Index,
|
||||||
TransactionIndex: TendLogNote.TxIndex,
|
TransactionIndex: TendLogNote.TxIndex,
|
||||||
Raw: string(RawLogNoteJson),
|
Raw: string(RawLogNoteJson),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user