{"id":20189873,"url":"https://github.com/crossbell-box/bridge-core","last_synced_at":"2026-05-12T00:32:33.607Z","repository":{"id":65661667,"uuid":"585204813","full_name":"Crossbell-Box/bridge-core","owner":"Crossbell-Box","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-15T02:14:47.000Z","size":272,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-13T18:50:34.013Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Crossbell-Box.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-04T15:27:14.000Z","updated_at":"2023-01-10T16:30:25.000Z","dependencies_parsed_at":"2023-12-15T03:28:41.701Z","dependency_job_id":"e7442809-9489-4282-9f53-a7942561810c","html_url":"https://github.com/Crossbell-Box/bridge-core","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Crossbell-Box%2Fbridge-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Crossbell-Box%2Fbridge-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Crossbell-Box%2Fbridge-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Crossbell-Box%2Fbridge-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Crossbell-Box","download_url":"https://codeload.github.com/Crossbell-Box/bridge-core/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241624753,"owners_count":19992940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T03:39:22.647Z","updated_at":"2026-05-12T00:32:33.563Z","avatar_url":"https://github.com/Crossbell-Box.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bridge-core\nBridge core is an event fetching library. This library automatically fetch logs from chain then invoke the perspective events. Callback functions will be provided in application side.\n## How to create an applicationn\n### Preparation\n\nFirstly, we need to clone ronin for go-ethereum replacement later.\n```\ngit clone https://github.com/axieinfinity/ronin.git\n```\n\nCreate a `go` application\n```\nmkdir app\ncd app\ngo mod init app\n```\n\nInside `go.mod`, we add this line. By doing this, we replace go-ethereum module by ronin module which cloned from above\n\n```\nreplace github.com/ethereum/go-ethereum =\u003e ../ronin\n```\n\nGet `migration` package. We need it for migration.\n```\ngo get -v github.com/axieinfinity/bridge-migrations\n```\n\nCreate `main.go`, we need to migrate to a postgres database by using `gorm`\n```go\nimport (\n\tmigration \"github.com/axieinfinity/bridge-migrations\"\n\t\"gorm.io/driver/postgres\"\n\t\"gorm.io/gorm\"\n)\n\n\nfunc main() {\n    connectionString := fmt.Sprintf(\"host=%s user=%s password=%s dbname=%s port=%d sslmode=disable\", \"localhost\", \"user\", \"password\", \"dbname\", 5432)\n\tdb, err := gorm.Open(postgres.Open(connectionString), \u0026gorm.Config{})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tif err := migration.Migrate(db, config); err != nil {\n\t\tpanic(err)\n\t}\n}\n\t\n```\n\n### Implementation\nFirst, we need to provide an implementation of `Listener` interface. Then, we add methods determining event callbacks to the implementation struct. Type of callback method\n```go\ntype Callback func(fromChainId *big.Int, tx bridgeCore.Transaction, data []byte) error\n```\n\nFor delegating a callback on event, we implement callback methods following the above type\n```go\nfunc (l *ConreteListener) WithdrewCallback(fromChainId *big.Int, tx bridge_core.Transaction, data []byte) error {\n\t// implementation here\n}\n```\n\nNext, we create an instance of controller. Before creating, we need to call `AddListener` method which receives `ChainName` and an initalizing function returning an instance of `Listener`.\n\nType of init function:\n```go\ntype Init func(ctx context.Context, lsConfig *bridge_core.LsConfig, store stores.MainStore, helpers utils.Utils) bridge_core.Listener\n```\n\n```go\nfunc CreateController(cfg *bridge_core.Config, db *gorm.DB) *bridge_core.Controller {\n\tbridge_core.AddListener(\"Ethereum\", InitEthereum)\n\tbridge_core.AddListener(\"Ronin\", InitRonin)\n\tcontroller, err := bridge_core.New(cfg, db, nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn controller\n}\n\nfunc InitEthereum(ctx context.Context, lsConfig *bridge_core.LsConfig, store stores.MainStore, helpers utils.Utils) bridge_core.Listener {\n\t// implementation here\n}\n\nfunc InitRonin(ctx context.Context, lsConfig *bridge_core.LsConfig, store stores.MainStore, helpers utils.Utils) bridge_core.Listener {\n\t// implementation here\n}\n```\n\n### Configuration\nwe need a configuration:\n```go\n\tconfig := \u0026bridge_core.Config{\n\t\tListeners: map[string]*bridge_core.LsConfig{\n\t\t\t\"Ethereum\": {\n\t\t\t\tChainId: \"0x03\",\n\t\t\t\tName:    \"Ethereum\",\n\t\t\t\tRpcUrl:  \"url\",\n\t\t\t\tSubscriptions: map[string]*bridge_core.Subscribe{\n\t\t\t\t\t\"WithdrewSubscription\": {\n\t\t\t\t\t\tTo:   \"0x4E4D9B21B157CCD52b978C3a3BCd1dc5eBAE7167\",\n\t\t\t\t\t\tType: 1, // 0 for listening, 1 for callback\n\t\t\t\t\t\tCallBacks: map[string]string{\n\t\t\t\t\t\t\t\"Ethereum\": \"WithdrewCallback\", // Key: Value is Chain name: method name\n\t\t\t\t\t\t},\n\t\t\t\t\t\tHandler: \u0026bridge_core.Handler{\n\t\t\t\t\t\t\tContract: \"EthereumGateway\", // contract name\n\t\t\t\t\t\t\tName:     \"Withdrew\",        // Event name\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t\"Ronin\": {\n\t\t\t\tChainId: \"0x7e5\",\n\t\t\t\tName:    \"Ronin\",\n\t\t\t\tRpcUrl:  \"url\",\n\t\t\t\tSubscriptions: map[string]*bridge_core.Subscribe{\n\t\t\t\t\t\"DepositedCallback\": {\n\t\t\t\t\t\tTo:   \"0xA8D61A5427a778be28Bd9bb5990956b33385c738\",\n\t\t\t\t\t\tType: 1, // 0 for listening, 1 for callback\n\t\t\t\t\t\tCallBacks: map[string]string{\n\t\t\t\t\t\t\t\"Ronin\": \"DepositedCallback\", // Key: Value is Chain name: method name\n\t\t\t\t\t\t},\n\t\t\t\t\t\tHandler: \u0026bridge_core.Handler{\n\t\t\t\t\t\t\tContract: \"RoninGateway\", // contract name\n\t\t\t\t\t\t\tName:     \"Deposited\",    // Event name\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t}\n```\n\nConfig includes a map representing the configuration on this chain. This configuration includes chain id, a map of subscription provides information about event listener and callback, these information are provided inside `Handler` and `Callbacks` perspectively.\n\n## Examples\nSee [Example](examples/) for sample use cases.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrossbell-box%2Fbridge-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrossbell-box%2Fbridge-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrossbell-box%2Fbridge-core/lists"}