Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
Update flip kick and tend transformers due to contract changes
Browse files Browse the repository at this point in the history
* Update FlipperAddress to new local ganache address

* Update flip_kick table

* Update flipkick transformer to handle new signature and abi

* Update tend table

* Update tend converter
  • Loading branch information
elizabethengelman authored Sep 4, 2018
1 parent 42341e5 commit f298a1a
Show file tree
Hide file tree
Showing 33 changed files with 147 additions and 448 deletions.
10 changes: 3 additions & 7 deletions db/migrations/1532468319_create_flip_kick_table.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ CREATE TABLE maker.flip_kick (
db_id SERIAL PRIMARY KEY,
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
id NUMERIC NOT NULL UNIQUE,
mom VARCHAR,
vat VARCHAR,
ilk VARCHAR,
lot NUMERIC,
bid NUMERIC,
guy VARCHAR,
gal VARCHAR,
"end" TIMESTAMP WITH TIME ZONE,
era TIMESTAMP WITH TIME ZONE,
lad VARCHAR,
tab NUMERIC
urn VARCHAR,
tab NUMERIC,
raw_log JSONB
);

This file was deleted.

This file was deleted.

5 changes: 2 additions & 3 deletions db/migrations/1534295712_create_tend_table.up.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
CREATE TABLE maker.tend (
db_id SERIAL PRIMARY KEY,
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
id NUMERIC NOT NULL UNIQUE,
bid_id NUMERIC NOT NULL UNIQUE,
lot NUMERIC,
bid NUMERIC,
guy BYTEA,
guy VARCHAR,
tic NUMERIC,
era TIMESTAMP WITH TIME ZONE,
tx_idx INTEGER NOT NUll,
raw_log JSONB
);

This file was deleted.

This file was deleted.

17 changes: 6 additions & 11 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,13 @@ CREATE TABLE maker.flip_kick (
db_id integer NOT NULL,
header_id integer NOT NULL,
id numeric NOT NULL,
vat character varying,
ilk character varying,
lot numeric,
bid numeric,
guy character varying,
gal character varying,
"end" timestamp with time zone,
era timestamp with time zone,
lad character varying,
urn character varying,
tab numeric,
raw_log json
raw_log jsonb
);


Expand Down Expand Up @@ -200,12 +196,11 @@ ALTER SEQUENCE maker.price_feeds_id_seq OWNED BY maker.price_feeds.id;
CREATE TABLE maker.tend (
db_id integer NOT NULL,
header_id integer NOT NULL,
id numeric NOT NULL,
bid_id numeric NOT NULL,
lot numeric,
bid numeric,
guy bytea,
guy character varying,
tic numeric,
era timestamp with time zone,
tx_idx integer NOT NULL,
raw_log jsonb
);
Expand Down Expand Up @@ -766,11 +761,11 @@ ALTER TABLE ONLY maker.price_feeds


--
-- Name: tend tend_id_key; Type: CONSTRAINT; Schema: maker; Owner: -
-- Name: tend tend_bid_id_key; Type: CONSTRAINT; Schema: maker; Owner: -
--

ALTER TABLE ONLY maker.tend
ADD CONSTRAINT tend_id_key UNIQUE (id);
ADD CONSTRAINT tend_bid_id_key UNIQUE (bid_id);


--
Expand Down
2 changes: 1 addition & 1 deletion pkg/transformers/flip_kick/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package flip_kick
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"

var FlipKickConfig = shared.TransformerConfig{
ContractAddresses: "0x08cb6176addcca2e1d1ffe21bee464b72ee4cd8d", //this is a temporary address deployed locally
ContractAddresses: shared.FlipperContractAddress,
ContractAbi: shared.FlipperABI,
Topics: []string{shared.FlipKickSignature},
StartingBlockNumber: 0,
Expand Down
18 changes: 0 additions & 18 deletions pkg/transformers/flip_kick/constants.go

This file was deleted.

20 changes: 4 additions & 16 deletions pkg/transformers/flip_kick/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package flip_kick
import (
"encoding/json"
"errors"
"strings"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -45,7 +44,7 @@ func (FlipKickConverter) ToEntity(contractAddress string, contractAbi string, et

contract := bind.NewBoundContract(address, abi, nil, nil, nil)

err = contract.UnpackLog(entity, "FlipKick", ethLog)
err = contract.UnpackLog(entity, "Kick", ethLog)
if err != nil {
return entity, err
}
Expand All @@ -54,24 +53,17 @@ func (FlipKickConverter) ToEntity(contractAddress string, contractAbi string, et
}

func (FlipKickConverter) ToModel(flipKick FlipKickEntity) (FlipKickModel, error) {
//TODO: Confirm if the following values can be/ever will be nil

if flipKick.Id == nil {
return FlipKickModel{}, errors.New("FlipKick log ID cannot be nil.")
}

id := flipKick.Id.String()
vat := strings.ToLower(flipKick.Vat.String())
ilk := strings.ToLower(common.ToHex(flipKick.Ilk[:]))
lot := utilities.ConvertNilToEmptyString(flipKick.Lot.String())
bid := utilities.ConvertNilToEmptyString(flipKick.Bid.String())
guy := strings.ToLower(flipKick.Guy.String())
gal := strings.ToLower(flipKick.Gal.String())
gal := flipKick.Gal.String()
endValue := utilities.ConvertNilToZeroTimeValue(flipKick.End)
end := time.Unix(endValue, 0)
eraValue := utilities.ConvertNilToZeroTimeValue(flipKick.Era)
era := time.Unix(eraValue, 0)
lad := strings.ToLower(flipKick.Lad.String())
urn := common.BytesToAddress(flipKick.Urn[:common.AddressLength]).String()
tab := utilities.ConvertNilToEmptyString(flipKick.Tab.String())
rawLogJson, err := json.Marshal(flipKick.Raw)
if err != nil {
Expand All @@ -81,15 +73,11 @@ func (FlipKickConverter) ToModel(flipKick FlipKickEntity) (FlipKickModel, error)

return FlipKickModel{
Id: id,
Vat: vat,
Ilk: ilk,
Lot: lot,
Bid: bid,
Guy: guy,
Gal: gal,
End: end,
Era: era,
Lad: lad,
Urn: urn,
Tab: tab,
Raw: rawLogString,
}, nil
Expand Down
17 changes: 4 additions & 13 deletions pkg/transformers/flip_kick/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,28 @@ var _ = Describe("FlipKick Converter", func() {

Describe("ToEntity", func() {
It("converts an Eth Log to a FlipKickEntity", func() {
entity, err := converter.ToEntity(test_data.FlipAddress, shared.FlipperABI, test_data.EthFlipKickLog)
entity, err := converter.ToEntity(shared.FlipperContractAddress, shared.FlipperABI, test_data.EthFlipKickLog)

Expect(err).NotTo(HaveOccurred())
Expect(entity.Id).To(Equal(test_data.FlipKickEntity.Id))
Expect(entity.Vat).To(Equal(test_data.FlipKickEntity.Vat))
Expect(entity.Ilk).To(Equal(test_data.FlipKickEntity.Ilk))
Expect(entity.Lot).To(Equal(test_data.FlipKickEntity.Lot))
Expect(entity.Bid).To(Equal(test_data.FlipKickEntity.Bid))
Expect(entity.Guy).To(Equal(test_data.FlipKickEntity.Guy))
Expect(entity.Gal).To(Equal(test_data.FlipKickEntity.Gal))
Expect(entity.End).To(Equal(test_data.FlipKickEntity.End))
Expect(entity.Era).To(Equal(test_data.FlipKickEntity.Era))
Expect(entity.Lad).To(Equal(test_data.FlipKickEntity.Lad))
Expect(entity.Urn).To(Equal(test_data.FlipKickEntity.Urn))
Expect(entity.Tab).To(Equal(test_data.FlipKickEntity.Tab))
Expect(entity.Raw).To(Equal(test_data.FlipKickEntity.Raw))
})

It("returns an error if converting log to entity fails", func() {
_, err := converter.ToEntity(test_data.FlipAddress, "error abi", test_data.EthFlipKickLog)
_, err := converter.ToEntity(shared.FlipperContractAddress, "error abi", test_data.EthFlipKickLog)

Expect(err).To(HaveOccurred())
})
})

Describe("ToModel", func() {
var emptyAddressHex = "0x0000000000000000000000000000000000000000"
var emptyByteArrayHex = "0x0000000000000000000000000000000000000000000000000000000000000000"
var emptyString = ""
var emptyTime = time.Unix(0, 0)
var emptyEntity = flip_kick.FlipKickEntity{}
Expand Down Expand Up @@ -87,15 +82,11 @@ var _ = Describe("FlipKick Converter", func() {

Expect(err).NotTo(HaveOccurred())
Expect(model.Id).To(Equal("1"))
Expect(model.Vat).To(Equal(emptyAddressHex))
Expect(model.Ilk).To(Equal(emptyByteArrayHex))
Expect(model.Lot).To(Equal(emptyString))
Expect(model.Bid).To(Equal(emptyString))
Expect(model.Guy).To(Equal(emptyAddressHex))
Expect(model.Gal).To(Equal(emptyAddressHex))
Expect(model.End).To(Equal(emptyTime))
Expect(model.Era).To(Equal(emptyTime))
Expect(model.Lad).To(Equal(emptyAddressHex))
Expect(model.Urn).To(Equal(emptyAddressHex))
Expect(model.Tab).To(Equal(emptyString))
Expect(model.Raw).To(Equal(emptyRawLog))
})
Expand Down
6 changes: 1 addition & 5 deletions pkg/transformers/flip_kick/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ import (

type FlipKickEntity struct {
Id *big.Int
Vat common.Address
Ilk [32]byte
Lot *big.Int
Bid *big.Int
Guy common.Address
Gal common.Address
End *big.Int
Era *big.Int
Lad common.Address
Urn [32]byte
Tab *big.Int
Raw types.Log
}
Loading

0 comments on commit f298a1a

Please sign in to comment.