-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ler2block #61
Merged
Merged
Ler2block #61
Changes from 22 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
af021ee
wip
arnaubennassar f80e900
wip
arnaubennassar cace932
WIP
arnaubennassar 8b90e2e
decoding direct and indeirecr assets and messages works
arnaubennassar de8d8a7
connect everything
arnaubennassar b4ad84e
fix building contract scripts
arnaubennassar f3d4af6
fix building contract scripts
arnaubennassar 9ea9b29
wip
arnaubennassar eac43c8
WIP
arnaubennassar 78a2aca
tree migrated to SQLite
arnaubennassar 07d6571
wip
arnaubennassar d18914a
wip
arnaubennassar 37cf940
bridgesync working with sqlite
arnaubennassar 3083e5c
pass tests
arnaubennassar 10b17f9
minor cleaning
arnaubennassar 6e07803
add GetBlockByLER func
arnaubennassar a90926c
handle err not found
arnaubennassar 30a7891
merge develop
arnaubennassar d0b035d
merge develop
arnaubennassar c245cfd
use memory for sqlite on the tests
arnaubennassar 9842ad5
increase timestamp to pass UT
arnaubennassar a212233
review
arnaubennassar d17db59
add callbacks on db tx
arnaubennassar f05383e
fix conflicts
arnaubennassar 3d5a2ab
lint
arnaubennassar f541a20
fix compilation
arnaubennassar 76b5b44
fix linter II
arnaubennassar 9b39da5
fix linter III
arnaubennassar 4a9d124
fix linter
arnaubennassar 3f28c15
increase linter TO
arnaubennassar 1f2b35b
fix UTs and lint
arnaubennassar 12904e5
increase linter TO
arnaubennassar 34ad89d
add PR requests
arnaubennassar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
-- +migrate Down | ||
DROP TABLE IF EXISTS block; | ||
DROP TABLE IF EXISTS claim; | ||
DROP TABLE IF EXISTS bridge; | ||
|
||
-- +migrate Up | ||
CREATE TABLE block ( | ||
num BIGINT PRIMARY KEY | ||
); | ||
|
||
CREATE TABLE bridge ( | ||
block_num INTEGER NOT NULL REFERENCES block(num) ON DELETE CASCADE, | ||
block_pos INTEGER NOT NULL, | ||
leaf_type INTEGER NOT NULL, | ||
origin_network INTEGER NOT NULL, | ||
origin_address VARCHAR NOT NULL, | ||
destination_network INTEGER NOT NULL, | ||
destination_address VARCHAR NOT NULL, | ||
amount DECIMAL(78, 0) NOT NULL, | ||
metadata BLOB, | ||
deposit_count INTEGER NOT NULL, | ||
PRIMARY KEY (block_num, block_pos) | ||
); | ||
|
||
CREATE TABLE claim ( | ||
block_num INTEGER NOT NULL REFERENCES block(num) ON DELETE CASCADE, | ||
block_pos INTEGER NOT NULL, | ||
global_index DECIMAL(78, 0) NOT NULL, | ||
origin_network INTEGER NOT NULL, | ||
origin_address VARCHAR NOT NULL, | ||
destination_address VARCHAR NOT NULL, | ||
amount DECIMAL(78, 0) NOT NULL, | ||
proof_local_exit_root VARCHAR, | ||
proof_rollup_exit_root VARCHAR, | ||
mainnet_exit_root VARCHAR, | ||
rollup_exit_root VARCHAR, | ||
global_exit_root VARCHAR, | ||
destination_network INTEGER NOT NULL, | ||
metadata BLOB, | ||
is_message BOOLEAN, | ||
PRIMARY KEY (block_num, block_pos) | ||
); |
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,61 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"path" | ||
"testing" | ||
|
||
"github.com/0xPolygon/cdk/db" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test001(t *testing.T) { | ||
dbPath := path.Join(t.TempDir(), "file::memory:?cache=shared") | ||
|
||
err := RunMigrations(dbPath) | ||
require.NoError(t, err) | ||
db, err := db.NewSQLiteDB(dbPath) | ||
require.NoError(t, err) | ||
|
||
ctx := context.Background() | ||
tx, err := db.BeginTx(ctx, nil) | ||
require.NoError(t, err) | ||
|
||
_, err = tx.Exec(` | ||
INSERT INTO block (num) VALUES (1); | ||
|
||
INSERT INTO bridge ( | ||
block_num, | ||
block_pos, | ||
leaf_type, | ||
origin_network, | ||
origin_address, | ||
destination_network, | ||
destination_address, | ||
amount, | ||
metadata, | ||
deposit_count | ||
) VALUES (1, 0, 0, 0, '0x0000', 0, '0x0000', 0, NULL, 0); | ||
|
||
INSERT INTO claim ( | ||
block_num, | ||
block_pos, | ||
global_index, | ||
origin_network, | ||
origin_address, | ||
destination_address, | ||
amount, | ||
proof_local_exit_root, | ||
proof_rollup_exit_root, | ||
mainnet_exit_root, | ||
rollup_exit_root, | ||
global_exit_root, | ||
destination_network, | ||
metadata, | ||
is_message | ||
) VALUES (1, 0, 0, 0, '0x0000', '0x0000', 0, '0x000,0x000', '0x000,0x000', '0x000', '0x000', '0x0', 0, NULL, FALSE); | ||
`) | ||
require.NoError(t, err) | ||
err = tx.Commit() | ||
require.NoError(t, 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,35 @@ | ||
package migrations | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/0xPolygon/cdk/db" | ||
treeMigrations "github.com/0xPolygon/cdk/tree/migrations" | ||
migrate "github.com/rubenv/sql-migrate" | ||
|
||
_ "embed" | ||
) | ||
|
||
const upDownSeparator = "-- +migrate Up" | ||
|
||
//go:embed bridgesync0001.sql | ||
var mig001 string | ||
var mig001splitted = strings.Split(mig001, upDownSeparator) | ||
|
||
var bridgeMigrations = &migrate.MemoryMigrationSource{ | ||
Migrations: []*migrate.Migration{ | ||
{ | ||
Id: "bridgesync001", | ||
Up: []string{mig001splitted[1]}, | ||
Down: []string{mig001splitted[0]}, | ||
}, | ||
}, | ||
} | ||
|
||
func RunMigrations(dbPath string) error { | ||
migs := append( | ||
bridgeMigrations.Migrations, | ||
treeMigrations.Migrations.Migrations..., | ||
) | ||
return db.RunMigrations(dbPath, &migrate.MemoryMigrationSource{Migrations: migs}) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file and
./l1infotreesync/migrations/migrations.go
looks pretty much the same.. is not possible to move this to db package?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it's syncer has it's own migrations, it would be odd IMO to have a "centralized" package that imports the migrations files of each syncer, and has functions to run those specific for each syncer