From 7080c0a74f1c8e6ce7f331dbb6c8bd08f82902e1 Mon Sep 17 00:00:00 2001 From: Taka Goto Date: Thu, 4 Oct 2018 13:56:44 -0500 Subject: [PATCH 1/3] migration to update columns --- db/migrations/1538670026_blah.down.sql | 11 +++++++++++ db/migrations/1538670026_blah.up.sql | 7 +++++++ db/schema.sql | 12 ++++++------ 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 db/migrations/1538670026_blah.down.sql create mode 100644 db/migrations/1538670026_blah.up.sql diff --git a/db/migrations/1538670026_blah.down.sql b/db/migrations/1538670026_blah.down.sql new file mode 100644 index 00000000..a262a6a8 --- /dev/null +++ b/db/migrations/1538670026_blah.down.sql @@ -0,0 +1,11 @@ +ALTER TABLE maker.bite + MODIFY ilk bytea; + +ALTER TABLE maker.bite + MODIFY urn bytea; + +ALTER TABLE maker.frob + MODIFY ilk bytea; + +ALTER TABLE maker.frob + MODIFY urn bytea; diff --git a/db/migrations/1538670026_blah.up.sql b/db/migrations/1538670026_blah.up.sql new file mode 100644 index 00000000..730241d9 --- /dev/null +++ b/db/migrations/1538670026_blah.up.sql @@ -0,0 +1,7 @@ +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; diff --git a/db/schema.sql b/db/schema.sql index 7e5ac73f..0081a856 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 10.3 --- Dumped by pg_dump version 10.3 +-- Dumped from database version 10.4 +-- Dumped by pg_dump version 10.4 SET statement_timeout = 0; SET lock_timeout = 0; @@ -64,8 +64,8 @@ SET default_with_oids = false; CREATE TABLE maker.bite ( id integer NOT NULL, header_id integer NOT NULL, - ilk bytea, - urn bytea, + ilk text, + urn text, ink character varying, art character varying, iart character varying, @@ -490,8 +490,8 @@ ALTER SEQUENCE maker.flop_kick_id_seq OWNED BY maker.flop_kick.id; CREATE TABLE maker.frob ( id integer NOT NULL, header_id integer NOT NULL, - ilk bytea, - urn bytea, + ilk text, + urn text, dink numeric, dart numeric, ink numeric, From 7e6302c6623d75a2d5a76639c04f6d9c5cd38eaa Mon Sep 17 00:00:00 2001 From: Taka Goto Date: Thu, 4 Oct 2018 16:35:51 -0500 Subject: [PATCH 2/3] update bite to take in string for urn and ilk --- cmd/root.go | 6 +++--- pkg/transformers/bite/converter_test.go | 4 ++-- pkg/transformers/bite/entity.go | 4 ++-- pkg/transformers/bite/model.go | 4 ++-- pkg/transformers/test_data/bite.go | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 500c8be6..e4c28607 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -64,9 +64,9 @@ func database(cmd *cobra.Command, args []string) { ipc = viper.GetString("client.ipcpath") levelDbPath = viper.GetString("client.leveldbpath") databaseConfig = config.Database{ - Name: viper.GetString("database.name"), - Hostname: viper.GetString("database.hostname"), - Port: viper.GetInt("database.port"), + Name: "vulcanize_public", + Hostname: "localhost", + Port: 5432, User: viper.GetString("database.user"), Password: viper.GetString("database.password"), } diff --git a/pkg/transformers/bite/converter_test.go b/pkg/transformers/bite/converter_test.go index e33b218a..af14588d 100644 --- a/pkg/transformers/bite/converter_test.go +++ b/pkg/transformers/bite/converter_test.go @@ -79,8 +79,8 @@ var _ = Describe("Bite Converter", func() { Expect(err).NotTo(HaveOccurred()) expectedModel := bite.BiteModel{ Id: "1", - Ilk: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - Urn: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + Ilk: "", + Urn: "", Ink: "", Art: "", IArt: "", diff --git a/pkg/transformers/bite/entity.go b/pkg/transformers/bite/entity.go index aa80b81e..f088f2a2 100644 --- a/pkg/transformers/bite/entity.go +++ b/pkg/transformers/bite/entity.go @@ -21,8 +21,8 @@ import ( type BiteEntity struct { Id *big.Int - Ilk [32]byte - Urn [32]byte + Ilk string + Urn string Ink *big.Int Art *big.Int Tab *big.Int diff --git a/pkg/transformers/bite/model.go b/pkg/transformers/bite/model.go index a951eb74..678a59fe 100644 --- a/pkg/transformers/bite/model.go +++ b/pkg/transformers/bite/model.go @@ -16,8 +16,8 @@ package bite type BiteModel struct { Id string - Ilk []byte - Urn []byte + Ilk string + Urn string Ink string Art string IArt string diff --git a/pkg/transformers/test_data/bite.go b/pkg/transformers/test_data/bite.go index efdccb8e..e2af6d13 100644 --- a/pkg/transformers/test_data/bite.go +++ b/pkg/transformers/test_data/bite.go @@ -40,8 +40,8 @@ var ( biteIArt = big.NewInt(5) biteRawJson, _ = json.Marshal(EthBiteLog) biteRawString = string(biteRawJson) - biteIlk = [32]byte{102, 97, 107, 101, 32, 105, 108, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} - biteLad = [32]byte{102, 97, 107, 101, 32, 108, 97, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + biteIlk = "ilk" + biteLad = "urn" biteId = int64(1) ) @@ -76,8 +76,8 @@ var BiteEntity = bite.BiteEntity{ var BiteModel = bite.BiteModel{ Id: strconv.FormatInt(biteId, 10), - Ilk: biteIlk[:], - Urn: biteLad[:], + Ilk: biteIlk, + Urn: biteLad, Ink: biteInk.String(), Art: biteArt.String(), Tab: biteTab.String(), From 347a33968701f1512016885ca251d7309219ac57 Mon Sep 17 00:00:00 2001 From: Taka Goto Date: Sun, 7 Oct 2018 21:51:37 -0500 Subject: [PATCH 3/3] update frob and bite converters and repository --- cmd/root.go | 6 ++--- db/migrations/1538670026_blah.down.sql | 11 ---------- ...026_update_frob_bite_urn_ilk_type.down.sql | 7 ++++++ ...0026_update_frob_bite_urn_ilk_type.up.sql} | 0 pkg/transformers/bite/converter.go | 11 +++++----- pkg/transformers/bite/converter_test.go | 4 ++-- pkg/transformers/bite/entity.go | 4 ++-- pkg/transformers/frob/converter.go | 5 +++-- pkg/transformers/frob/model.go | 4 ++-- pkg/transformers/test_data/bite.go | 10 +++++---- pkg/transformers/test_data/frob.go | 22 ++++++++++--------- 11 files changed, 43 insertions(+), 41 deletions(-) delete mode 100644 db/migrations/1538670026_blah.down.sql create mode 100644 db/migrations/1538670026_update_frob_bite_urn_ilk_type.down.sql rename db/migrations/{1538670026_blah.up.sql => 1538670026_update_frob_bite_urn_ilk_type.up.sql} (100%) diff --git a/cmd/root.go b/cmd/root.go index e4c28607..500c8be6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -64,9 +64,9 @@ func database(cmd *cobra.Command, args []string) { ipc = viper.GetString("client.ipcpath") levelDbPath = viper.GetString("client.leveldbpath") databaseConfig = config.Database{ - Name: "vulcanize_public", - Hostname: "localhost", - Port: 5432, + Name: viper.GetString("database.name"), + Hostname: viper.GetString("database.hostname"), + Port: viper.GetInt("database.port"), User: viper.GetString("database.user"), Password: viper.GetString("database.password"), } diff --git a/db/migrations/1538670026_blah.down.sql b/db/migrations/1538670026_blah.down.sql deleted file mode 100644 index a262a6a8..00000000 --- a/db/migrations/1538670026_blah.down.sql +++ /dev/null @@ -1,11 +0,0 @@ -ALTER TABLE maker.bite - MODIFY ilk bytea; - -ALTER TABLE maker.bite - MODIFY urn bytea; - -ALTER TABLE maker.frob - MODIFY ilk bytea; - -ALTER TABLE maker.frob - MODIFY urn bytea; diff --git a/db/migrations/1538670026_update_frob_bite_urn_ilk_type.down.sql b/db/migrations/1538670026_update_frob_bite_urn_ilk_type.down.sql new file mode 100644 index 00000000..e134b3f3 --- /dev/null +++ b/db/migrations/1538670026_update_frob_bite_urn_ilk_type.down.sql @@ -0,0 +1,7 @@ +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; diff --git a/db/migrations/1538670026_blah.up.sql b/db/migrations/1538670026_update_frob_bite_urn_ilk_type.up.sql similarity index 100% rename from db/migrations/1538670026_blah.up.sql rename to db/migrations/1538670026_update_frob_bite_urn_ilk_type.up.sql diff --git a/pkg/transformers/bite/converter.go b/pkg/transformers/bite/converter.go index 3d97ff20..020b7540 100644 --- a/pkg/transformers/bite/converter.go +++ b/pkg/transformers/bite/converter.go @@ -19,6 +19,7 @@ package bite import ( "encoding/json" "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/vulcanize/vulcanizedb/pkg/geth" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" @@ -34,7 +35,7 @@ type BiteConverter struct{} func (BiteConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]BiteEntity, error) { var entities []BiteEntity for _, ethLog := range ethLogs { - entity := BiteEntity{} + entity := &BiteEntity{} address := ethLog.Address abi, err := geth.ParseAbi(contractAbi) if err != nil { @@ -43,7 +44,7 @@ func (BiteConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]Bite contract := bind.NewBoundContract(address, abi, nil, nil, nil) - err = contract.UnpackLog(&entity, "Bite", ethLog) + err = contract.UnpackLog(entity, "Bite", ethLog) if err != nil { return nil, err } @@ -51,7 +52,7 @@ func (BiteConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]Bite entity.Raw = ethLog entity.TransactionIndex = ethLog.TxIndex - entities = append(entities, entity) + entities = append(entities, *entity) } return entities, nil @@ -61,8 +62,8 @@ func (converter BiteConverter) ToModels(entities []BiteEntity) ([]BiteModel, err var models []BiteModel for _, entity := range entities { id := entity.Id - ilk := entity.Ilk[:] - urn := entity.Urn[:] + ilk := common.BytesToAddress(entity.Ilk[:common.AddressLength]).String() + urn := common.BytesToAddress(entity.Urn[:common.AddressLength]).String() ink := entity.Ink art := entity.Art iArt := entity.IArt diff --git a/pkg/transformers/bite/converter_test.go b/pkg/transformers/bite/converter_test.go index af14588d..de4aacb9 100644 --- a/pkg/transformers/bite/converter_test.go +++ b/pkg/transformers/bite/converter_test.go @@ -79,8 +79,8 @@ var _ = Describe("Bite Converter", func() { Expect(err).NotTo(HaveOccurred()) expectedModel := bite.BiteModel{ Id: "1", - Ilk: "", - Urn: "", + Ilk: "0x0000000000000000000000000000000000000000", + Urn: "0x0000000000000000000000000000000000000000", Ink: "", Art: "", IArt: "", diff --git a/pkg/transformers/bite/entity.go b/pkg/transformers/bite/entity.go index f088f2a2..aa80b81e 100644 --- a/pkg/transformers/bite/entity.go +++ b/pkg/transformers/bite/entity.go @@ -21,8 +21,8 @@ import ( type BiteEntity struct { Id *big.Int - Ilk string - Urn string + Ilk [32]byte + Urn [32]byte Ink *big.Int Art *big.Int Tab *big.Int diff --git a/pkg/transformers/frob/converter.go b/pkg/transformers/frob/converter.go index a5d6f7cf..937da13a 100644 --- a/pkg/transformers/frob/converter.go +++ b/pkg/transformers/frob/converter.go @@ -19,6 +19,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "encoding/json" + "github.com/ethereum/go-ethereum/common" "github.com/vulcanize/vulcanizedb/pkg/geth" ) @@ -56,8 +57,8 @@ func (FrobConverter) ToModels(entities []FrobEntity) ([]FrobModel, error) { return nil, err } model := FrobModel{ - Ilk: entity.Ilk[:], - Urn: entity.Urn[:], + Ilk: common.BytesToAddress(entity.Ilk[:common.AddressLength]).String(), + Urn: common.BytesToAddress(entity.Urn[:common.AddressLength]).String(), Ink: entity.Ink.String(), Art: entity.Art.String(), Dink: entity.Dink.String(), diff --git a/pkg/transformers/frob/model.go b/pkg/transformers/frob/model.go index 566fe8e3..bbb31f37 100644 --- a/pkg/transformers/frob/model.go +++ b/pkg/transformers/frob/model.go @@ -15,8 +15,8 @@ package frob type FrobModel struct { - Ilk []byte - Urn []byte + Ilk string + Urn string Ink string Art string Dink string diff --git a/pkg/transformers/test_data/bite.go b/pkg/transformers/test_data/bite.go index e2af6d13..71adefee 100644 --- a/pkg/transformers/test_data/bite.go +++ b/pkg/transformers/test_data/bite.go @@ -40,8 +40,10 @@ var ( biteIArt = big.NewInt(5) biteRawJson, _ = json.Marshal(EthBiteLog) biteRawString = string(biteRawJson) - biteIlk = "ilk" - biteLad = "urn" + biteIlk = [32]byte{102, 97, 107, 101, 32, 105, 108, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + biteLad = [32]byte{102, 97, 107, 101, 32, 108, 97, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + biteIlkString = "0x66616b6520696c6B000000000000000000000000" + biteLadString = "0x66616B65206c6164000000000000000000000000" biteId = int64(1) ) @@ -76,8 +78,8 @@ var BiteEntity = bite.BiteEntity{ var BiteModel = bite.BiteModel{ Id: strconv.FormatInt(biteId, 10), - Ilk: biteIlk, - Urn: biteLad, + Ilk: biteIlkString, + Urn: biteLadString, Ink: biteInk.String(), Art: biteArt.String(), Tab: biteTab.String(), diff --git a/pkg/transformers/test_data/frob.go b/pkg/transformers/test_data/frob.go index 37334f4a..129dd929 100644 --- a/pkg/transformers/test_data/frob.go +++ b/pkg/transformers/test_data/frob.go @@ -33,14 +33,16 @@ var ( var ( // need to set bytes as 0 or else the big Int 0 evaluates differently from the one unpacked by the abi - art = big.NewInt(20) - dink = big.NewInt(10) - dart = big.NewInt(0).SetBytes([]byte{0}) - iArt = big.NewInt(25) - frobLad = [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 217, 34, 137, 65, 83, 190, 158, 239, 123, 114, 24, 220, 86, 93, 29, 12, 226, 160, 146} - gem, _ = big.NewInt(0).SetString("115792089237316195423570985008687907853269984665640564039457584007913129639926", 10) - ink = big.NewInt(15) - ilk = [32]byte{102, 97, 107, 101, 32, 105, 108, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + art = big.NewInt(20) + dink = big.NewInt(10) + dart = big.NewInt(0).SetBytes([]byte{0}) + iArt = big.NewInt(25) + frobLad = [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 217, 34, 137, 65, 83, 190, 158, 239, 123, 114, 24, 220, 86, 93, 29, 12, 226, 160, 146} + gem, _ = big.NewInt(0).SetString("115792089237316195423570985008687907853269984665640564039457584007913129639926", 10) + ink = big.NewInt(15) + ilk = [32]byte{102, 97, 107, 101, 32, 105, 108, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + frobIlkString = "0x66616b6520696c6B000000000000000000000000" + frobUrnString = "0x00000000000000000000000064D922894153BE9E" ) var EthFrobLog = types.Log{ @@ -73,8 +75,8 @@ var FrobEntity = frob.FrobEntity{ var rawFrobLog, _ = json.Marshal(EthFrobLog) var FrobModel = frob.FrobModel{ - Ilk: ilk[:], - Urn: frobLad[:], + Ilk: frobIlkString, + Urn: frobUrnString, Ink: ink.String(), Art: art.String(), Dink: dink.String(),