Add transaction index to flip kick

This commit is contained in:
Rob Mulholand 2018-09-10 16:02:11 -05:00
parent a843de5eb7
commit b2ba7ee1e3
8 changed files with 54 additions and 50 deletions

View File

@ -8,5 +8,6 @@ CREATE TABLE maker.flip_kick (
"end" TIMESTAMP WITH TIME ZONE, "end" TIMESTAMP WITH TIME ZONE,
urn VARCHAR, urn VARCHAR,
tab NUMERIC, tab NUMERIC,
tx_idx INTEGER NOT NUll,
raw_log JSONB raw_log JSONB
); );

View File

@ -233,6 +233,7 @@ CREATE TABLE maker.flip_kick (
"end" timestamp with time zone, "end" timestamp with time zone,
urn character varying, urn character varying,
tab numeric, tab numeric,
tx_idx integer NOT NULL,
raw_log jsonb raw_log jsonb
); );

View File

@ -49,6 +49,7 @@ func (FlipKickConverter) ToEntity(contractAddress string, contractAbi string, et
return entity, err return entity, err
} }
entity.Raw = ethLog entity.Raw = ethLog
entity.TransactionIndex = ethLog.TxIndex
return entity, nil return entity, nil
} }
@ -72,13 +73,14 @@ func (FlipKickConverter) ToModel(flipKick FlipKickEntity) (FlipKickModel, error)
rawLogString := string(rawLogJson) rawLogString := string(rawLogJson)
return FlipKickModel{ return FlipKickModel{
Id: id, Id: id,
Lot: lot, Lot: lot,
Bid: bid, Bid: bid,
Gal: gal, Gal: gal,
End: end, End: end,
Urn: urn, Urn: urn,
Tab: tab, Tab: tab,
Raw: rawLogString, TransactionIndex: flipKick.TransactionIndex,
Raw: rawLogString,
}, nil }, nil
} }

View File

@ -22,12 +22,13 @@ import (
) )
type FlipKickEntity struct { type FlipKickEntity struct {
Id *big.Int Id *big.Int
Lot *big.Int Lot *big.Int
Bid *big.Int Bid *big.Int
Gal common.Address Gal common.Address
End *big.Int End *big.Int
Urn [32]byte Urn [32]byte
Tab *big.Int Tab *big.Int
Raw types.Log TransactionIndex uint
Raw types.Log
} }

View File

@ -17,12 +17,13 @@ package flip_kick
import "time" import "time"
type FlipKickModel struct { type FlipKickModel struct {
Id string Id string
Lot string Lot string
Bid string Bid string
Gal string Gal string
End time.Time End time.Time
Urn string Urn string
Tab string Tab string
Raw string `db:"raw_log"` TransactionIndex uint `db:"tx_idx"`
Raw string `db:"raw_log"`
} }

View File

@ -35,16 +35,11 @@ func NewFlipKickRepository(db *postgres.DB) FlipKickRepository {
} }
func (fkr FlipKickRepository) Create(headerId int64, flipKick FlipKickModel) error { func (fkr FlipKickRepository) Create(headerId int64, flipKick FlipKickModel) error {
_, err := fkr.DB.Exec( _, err := fkr.DB.Exec(
`INSERT into maker.flip_kick (header_id, id, lot, bid, gal, "end", urn, tab, raw_log) `INSERT into maker.flip_kick (header_id, id, lot, bid, gal, "end", urn, tab, tx_idx, raw_log)
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)`, VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`,
headerId, flipKick.Id, flipKick.Lot, flipKick.Bid, flipKick.Gal, flipKick.End, flipKick.Urn, flipKick.Tab, flipKick.Raw, headerId, flipKick.Id, flipKick.Lot, flipKick.Bid, flipKick.Gal, flipKick.End, flipKick.Urn, flipKick.Tab, flipKick.TransactionIndex, flipKick.Raw,
) )
return err
if err != nil {
return err
}
return nil
} }
func (fkr FlipKickRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (fkr FlipKickRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {

View File

@ -71,6 +71,7 @@ var _ = Describe("FlipKick Repository", func() {
Expect(dbResult.End.Equal(flipKick.End)).To(BeTrue()) Expect(dbResult.End.Equal(flipKick.End)).To(BeTrue())
Expect(dbResult.Urn).To(Equal(flipKick.Urn)) Expect(dbResult.Urn).To(Equal(flipKick.Urn))
Expect(dbResult.Tab).To(Equal(flipKick.Tab)) Expect(dbResult.Tab).To(Equal(flipKick.Tab))
Expect(dbResult.TransactionIndex).To(Equal(flipKick.TransactionIndex))
Expect(dbResult.Raw).To(MatchJSON(flipKick.Raw)) Expect(dbResult.Raw).To(MatchJSON(flipKick.Raw))
}) })

View File

@ -61,32 +61,34 @@ var EthFlipKickLog = types.Log{
Data: hexutil.MustDecode(flipKickData), Data: hexutil.MustDecode(flipKickData),
BlockNumber: uint64(FlipKickBlockNumber), BlockNumber: uint64(FlipKickBlockNumber),
TxHash: common.HexToHash(flipKickTransactionHash), TxHash: common.HexToHash(flipKickTransactionHash),
TxIndex: 0, TxIndex: 999,
BlockHash: common.HexToHash(flipKickBlockHash), BlockHash: common.HexToHash(flipKickBlockHash),
Index: 0, Index: 0,
Removed: false, Removed: false,
} }
var FlipKickEntity = flip_kick.FlipKickEntity{ var FlipKickEntity = flip_kick.FlipKickEntity{
Id: id, Id: id,
Lot: lot, Lot: lot,
Bid: bid, Bid: bid,
Gal: common.HexToAddress(gal), Gal: common.HexToAddress(gal),
End: big.NewInt(end), End: big.NewInt(end),
Urn: urn, Urn: urn,
Tab: tab, Tab: tab,
Raw: EthFlipKickLog, TransactionIndex: EthFlipKickLog.TxIndex,
Raw: EthFlipKickLog,
} }
var FlipKickModel = flip_kick.FlipKickModel{ var FlipKickModel = flip_kick.FlipKickModel{
Id: idString, Id: idString,
Lot: lotString, Lot: lotString,
Bid: bidString, Bid: bidString,
Gal: gal, Gal: gal,
End: time.Unix(end, 0), End: time.Unix(end, 0),
Urn: urnString, Urn: urnString,
Tab: tabString, Tab: tabString,
Raw: rawLogString, TransactionIndex: EthFlipKickLog.TxIndex,
Raw: rawLogString,
} }
type FlipKickDBRow struct { type FlipKickDBRow struct {