This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from vulcanize/vdb-354-queue-unrecognized-diffs
(VDB-354) queue unrecognized diffs
- Loading branch information
Showing
11 changed files
with
238 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- +goose Up | ||
CREATE TABLE public.queued_storage ( | ||
id SERIAL PRIMARY KEY, | ||
block_height BIGINT, | ||
block_hash BYTEA, | ||
contract BYTEA, | ||
storage_key BYTEA, | ||
storage_value BYTEA | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE public.queued_storage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package shared | ||
|
||
import ( | ||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" | ||
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared" | ||
) | ||
|
||
type IStorageQueue interface { | ||
Add(row shared.StorageDiffRow) error | ||
} | ||
|
||
type StorageQueue struct { | ||
db *postgres.DB | ||
} | ||
|
||
func NewStorageQueue(db *postgres.DB) StorageQueue { | ||
return StorageQueue{db: db} | ||
} | ||
|
||
func (queue StorageQueue) Add(row shared.StorageDiffRow) error { | ||
_, err := queue.db.Exec(`INSERT INTO public.queued_storage (contract, | ||
block_hash, block_height, storage_key, storage_value) VALUES | ||
($1, $2, $3, $4, $5)`, row.Contract.Bytes(), row.BlockHash.Bytes(), | ||
row.BlockHeight, row.StorageKey.Bytes(), row.StorageValue.Bytes()) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package shared_test | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
shared2 "github.com/vulcanize/vulcanizedb/libraries/shared" | ||
"github.com/vulcanize/vulcanizedb/pkg/transformers/storage_diffs/shared" | ||
"github.com/vulcanize/vulcanizedb/test_config" | ||
) | ||
|
||
var _ = Describe("Storage queue", func() { | ||
It("adds a storage row to the db", func() { | ||
row := shared.StorageDiffRow{ | ||
Contract: common.HexToAddress("0x123456"), | ||
BlockHash: common.HexToHash("0x678901"), | ||
BlockHeight: 987, | ||
StorageKey: common.HexToHash("0x654321"), | ||
StorageValue: common.HexToHash("0x198765"), | ||
} | ||
db := test_config.NewTestDB(test_config.NewTestNode()) | ||
queue := shared2.NewStorageQueue(db) | ||
|
||
addErr := queue.Add(row) | ||
|
||
Expect(addErr).NotTo(HaveOccurred()) | ||
var result shared.StorageDiffRow | ||
getErr := db.Get(&result, `SELECT contract, block_hash, block_height, storage_key, storage_value FROM public.queued_storage`) | ||
Expect(getErr).NotTo(HaveOccurred()) | ||
Expect(result).To(Equal(row)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.