-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * wip * WIP * decoding direct and indeirecr assets and messages works * connect everything * fix building contract scripts * fix building contract scripts * wip * WIP * tree migrated to SQLite * wip * wip * bridgesync working with sqlite * pass tests * minor cleaning * add GetBlockByLER func * handle err not found * merge develop * use memory for sqlite on the tests * increase timestamp to pass UT * review * add callbacks on db tx * lint * fix compilation * fix linter II * fix linter III * fix linter * increase linter TO * fix UTs and lint * increase linter TO * add PR requests
- Loading branch information
1 parent
0959afc
commit 8a74627
Showing
40 changed files
with
1,442 additions
and
1,187 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
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
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,23 @@ | ||
package migrations | ||
|
||
import ( | ||
_ "embed" | ||
|
||
"github.com/0xPolygon/cdk/db" | ||
"github.com/0xPolygon/cdk/db/types" | ||
treeMigrations "github.com/0xPolygon/cdk/tree/migrations" | ||
) | ||
|
||
//go:embed bridgesync0001.sql | ||
var mig001 string | ||
|
||
func RunMigrations(dbPath string) error { | ||
migrations := []types.Migration{ | ||
{ | ||
ID: "bridgesync0001", | ||
SQL: mig001, | ||
}, | ||
} | ||
migrations = append(migrations, treeMigrations.Migrations...) | ||
return db.RunMigrations(dbPath, migrations) | ||
} |
Oops, something went wrong.