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

Commit

Permalink
Fix confusion between nflip and flip
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ar committed Feb 20, 2019
1 parent 56ca455 commit fb47a74
Showing 6 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions db/migrations/20190215160236_create_cat_storage_tables.sql
Original file line number Diff line number Diff line change
@@ -62,31 +62,31 @@ CREATE TABLE maker.cat_flip_ilk (
id SERIAL PRIMARY KEY,
block_number BIGINT,
block_hash TEXT,
nflip NUMERIC NOT NULL,
flip NUMERIC NOT NULL,
ilk TEXT
);

CREATE TABLE maker.cat_flip_urn (
id SERIAL PRIMARY KEY,
block_number BIGINT,
block_hash TEXT,
nflip NUMERIC NOT NULL,
flip NUMERIC NOT NULL,
urn TEXT
);

CREATE TABLE maker.cat_flip_ink (
id SERIAL PRIMARY KEY,
block_number BIGINT,
block_hash TEXT,
nflip NUMERIC NOT NULL,
flip NUMERIC NOT NULL,
ink NUMERIC NOT NULL
);

CREATE TABLE maker.cat_flip_tab (
id SERIAL PRIMARY KEY,
block_number BIGINT,
block_hash TEXT,
nflip NUMERIC NOT NULL,
flip NUMERIC NOT NULL,
tab NUMERIC NOT NULL
);

8 changes: 4 additions & 4 deletions db/schema.sql
Original file line number Diff line number Diff line change
@@ -212,7 +212,7 @@ CREATE TABLE maker.cat_flip_ilk (
id integer NOT NULL,
block_number bigint,
block_hash text,
nflip numeric NOT NULL,
flip numeric NOT NULL,
ilk text
);

@@ -245,7 +245,7 @@ CREATE TABLE maker.cat_flip_ink (
id integer NOT NULL,
block_number bigint,
block_hash text,
nflip numeric NOT NULL,
flip numeric NOT NULL,
ink numeric NOT NULL
);

@@ -278,7 +278,7 @@ CREATE TABLE maker.cat_flip_tab (
id integer NOT NULL,
block_number bigint,
block_hash text,
nflip numeric NOT NULL,
flip numeric NOT NULL,
tab numeric NOT NULL
);

@@ -311,7 +311,7 @@ CREATE TABLE maker.cat_flip_urn (
id integer NOT NULL,
block_number bigint,
block_hash text,
nflip numeric NOT NULL,
flip numeric NOT NULL,
urn text
);

28 changes: 14 additions & 14 deletions pkg/transformers/storage_diffs/maker/cat/repository.go
Original file line number Diff line number Diff line change
@@ -116,46 +116,46 @@ func (repository *CatStorageRepository) insertIlkLump(blockNumber int, blockHash

// Flips mapping: uint256 => ilk, urn bytes32; ink, tab uint256 (both wad)
func (repository *CatStorageRepository) insertFlipIlk(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, ilk string) error {
nflip, err := getFlip(metadata.Keys)
flip, err := getFlip(metadata.Keys)
if err != nil {
return err
}
_, writeErr := repository.db.Exec(
`INSERT INTO maker.cat_flip_ilk (block_number, block_hash, nflip, ilk) VALUES ($1, $2, $3, $4)`,
blockNumber, blockHash, nflip, ilk)
`INSERT INTO maker.cat_flip_ilk (block_number, block_hash, flip, ilk) VALUES ($1, $2, $3, $4)`,
blockNumber, blockHash, flip, ilk)
return writeErr
}

func (repository *CatStorageRepository) insertFlipUrn(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, urn string) error {
nflip, err := getFlip(metadata.Keys)
flip, err := getFlip(metadata.Keys)
if err != nil {
return err
}
_, writeErr := repository.db.Exec(
`INSERT INTO maker.cat_flip_urn (block_number, block_hash, nflip, urn) VALUES ($1, $2, $3, $4)`,
blockNumber, blockHash, nflip, urn)
`INSERT INTO maker.cat_flip_urn (block_number, block_hash, flip, urn) VALUES ($1, $2, $3, $4)`,
blockNumber, blockHash, flip, urn)
return writeErr
}

func (repository *CatStorageRepository) insertFlipInk(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, ink string) error {
nflip, err := getFlip(metadata.Keys)
flip, err := getFlip(metadata.Keys)
if err != nil {
return err
}
_, writeErr := repository.db.Exec(
`INSERT INTO maker.cat_flip_ink (block_number, block_hash, nflip, ink) VALUES ($1, $2, $3, $4)`,
blockNumber, blockHash, nflip, ink)
`INSERT INTO maker.cat_flip_ink (block_number, block_hash, flip, ink) VALUES ($1, $2, $3, $4)`,
blockNumber, blockHash, flip, ink)
return writeErr
}

func (repository *CatStorageRepository) insertFlipTab(blockNumber int, blockHash string, metadata shared.StorageValueMetadata, tab string) error {
nflip, err := getFlip(metadata.Keys)
flip, err := getFlip(metadata.Keys)
if err != nil {
return err
}
_, writeErr := repository.db.Exec(
`INSERT INTO maker.cat_flip_tab (block_number, block_hash, nflip, tab) VALUES ($1, $2, $3, $4)`,
blockNumber, blockHash, nflip, tab)
`INSERT INTO maker.cat_flip_tab (block_number, block_hash, flip, tab) VALUES ($1, $2, $3, $4)`,
blockNumber, blockHash, flip, tab)
return writeErr
}

@@ -168,9 +168,9 @@ func getIlk(keys map[shared.Key]string) (string, error) {
}

func getFlip(keys map[shared.Key]string) (string, error) {
nflip, ok := keys[shared.Flip]
flip, ok := keys[shared.Flip]
if !ok {
return "", shared.ErrMetadataMalformed{MissingData: shared.Flip}
}
return nflip, nil
return flip, nil
}
8 changes: 4 additions & 4 deletions pkg/transformers/storage_diffs/maker/cat/repository_test.go
Original file line number Diff line number Diff line change
@@ -172,7 +172,7 @@ var _ = Describe("Cat storage repository", func() {
err := repo.Create(fakeBlockNumber, fakeBlockHash, flipIlkMetadata, fakeBytes32)
Expect(err).NotTo(HaveOccurred())

err = db.Get(&result, `SELECT block_number, block_hash, nflip AS key, ilk AS value FROM maker.cat_flip_ilk`)
err = db.Get(&result, `SELECT block_number, block_hash, flip AS key, ilk AS value FROM maker.cat_flip_ilk`)
Expect(err).NotTo(HaveOccurred())
AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeUint256, fakeBytes32)
})
@@ -192,7 +192,7 @@ var _ = Describe("Cat storage repository", func() {
err := repo.Create(fakeBlockNumber, fakeBlockHash, flipUrnMetadata, fakeBytes32)
Expect(err).NotTo(HaveOccurred())

err = db.Get(&result, `SELECT block_number, block_hash, nflip AS key, urn AS value FROM maker.cat_flip_urn`)
err = db.Get(&result, `SELECT block_number, block_hash, flip AS key, urn AS value FROM maker.cat_flip_urn`)
Expect(err).NotTo(HaveOccurred())
AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeUint256, fakeBytes32)
})
@@ -212,7 +212,7 @@ var _ = Describe("Cat storage repository", func() {
err := repo.Create(fakeBlockNumber, fakeBlockHash, flipInkMetadata, fakeUint256)
Expect(err).NotTo(HaveOccurred())

err = db.Get(&result, `SELECT block_number, block_hash, nflip AS key, ink AS value FROM maker.cat_flip_ink`)
err = db.Get(&result, `SELECT block_number, block_hash, flip AS key, ink AS value FROM maker.cat_flip_ink`)
Expect(err).NotTo(HaveOccurred())
AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeUint256, fakeUint256)
})
@@ -232,7 +232,7 @@ var _ = Describe("Cat storage repository", func() {
err := repo.Create(fakeBlockNumber, fakeBlockHash, flipTabMetadata, fakeUint256)
Expect(err).NotTo(HaveOccurred())

err = db.Get(&result, `SELECT block_number, block_hash, nflip AS key, tab AS value FROM maker.cat_flip_tab`)
err = db.Get(&result, `SELECT block_number, block_hash, flip AS key, tab AS value FROM maker.cat_flip_tab`)
Expect(err).NotTo(HaveOccurred())
AssertMapping(result, fakeBlockNumber, fakeBlockHash, fakeUint256, fakeUint256)
})
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ func (repository *MakerStorageRepository) GetDaiKeys() ([]string, error) {

func (repository *MakerStorageRepository) GetMaxFlip() (*big.Int, error) {
var maxFlip big.Int
err := repository.db.Get(&maxFlip, `SELECT MAX(nflip) FROM maker.bite`)
err := repository.db.Get(&maxFlip, `SELECT MAX(nflip) FROM maker.cat_nflip`)
if err == sql.ErrNoRows {
// No flips have occurred; this is different from flip 0 having occurred
return nil, nil
Original file line number Diff line number Diff line change
@@ -46,4 +46,4 @@ func AssertDoubleMapping(res DoubleMappingRes, blockNumber int, blockHash, keyOn
Expect(res.KeyOne).To(Equal(keyOne))
Expect(res.KeyTwo).To(Equal(keyTwo))
Expect(res.Value).To(Equal(value))
}
}

0 comments on commit fb47a74

Please sign in to comment.