Fix confusion between nflip and flip

This commit is contained in:
Edvard 2019-02-20 14:04:35 +01:00
parent 56ca45509f
commit fb47a747f6
6 changed files with 28 additions and 28 deletions

View File

@ -62,7 +62,7 @@ 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
);
@ -70,7 +70,7 @@ 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
);
@ -78,7 +78,7 @@ 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
);
@ -86,7 +86,7 @@ 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
);

View File

@ -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
);

View File

@ -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
}

View File

@ -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)
})

View File

@ -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