diff --git a/.env.example b/.env.example index 83c2204..6a16bc5 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,17 @@ -NATIVE_RPC=http://localhost:26657 -NATIVE_GRPC=127.0.0.1:9090 LOG_FILE_PATH="" # If empty, logs to STDOUT LOG_LEVEL="debug" +NATIVE_RPC=http://localhost:26657 +NATIVE_GRPC=127.0.0.1:9090 + +IKA_RPC=http://127.0.0.1:9000 +IKA_SIGNER_MNEMONIC="" +IKA_GAS_ACC="" +IKA_GAS_BUDGET="" +IKA_NATIVE_LC_PACKAGE="" +IKA_NATIVE_LC_MODULE="" +IKA_NATIVE_LC_FUNCTION="" + BTC_RPC_USER="user" BTC_RPC_PASS="pass" BTC_RPC="localhost:18334" diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md index 8f4ca4d..5eceaa4 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.md +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -7,15 +7,20 @@ about: Create a proposal to request a feature ## Summary -## Problem Definition - + +## Context + +#### Why do we need this feature? What problems may be addressed by introducing this feature? + +#### What are the benefits by including this feature? + +#### Are there any disadvantages of including this feature? ## Proposal + + --- ## For Admin Use diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 2df542e..ea5064c 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -2,7 +2,7 @@ ## Description -closes: #XXXX +Closes: #XXXX --- @@ -14,6 +14,17 @@ please add links to any relevant follow up issues._ I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title + - [ ] added `!` to the type prefix if API or client breaking change - [ ] added appropriate labels to the PR - [ ] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting)) diff --git a/.github/workflows/govulncheck.yml b/.github/workflows/govulncheck.yml index 8a85474..3365a55 100644 --- a/.github/workflows/govulncheck.yml +++ b/.github/workflows/govulncheck.yml @@ -26,5 +26,5 @@ jobs: id: govulncheck if: env.GIT_DIFF with: - go-version-input: 1.22 + go-version-input: 1.23 go-package: ./... diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a5b829a..d6f75ca 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,7 +22,7 @@ jobs: - uses: actions/setup-go@v5 if: env.GIT_DIFF with: - go-version: "1.22" + go-version: "1.23" cache: true - name: golangci-lint main diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1e993e7..2e741dd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -41,7 +41,7 @@ jobs: - uses: actions/setup-go@v5 if: env.GIT_DIFF with: - go-version: "1.22" + go-version: "1.23" cache: true - name: Test and Create Coverage Report if: env.GIT_DIFF @@ -73,7 +73,7 @@ jobs: # - uses: actions/setup-go@v5 # if: env.GIT_DIFF # with: - # go-version: "1.22" + # go-version: "1.23" # cache: true # - name: Test E2E diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 52fbd80..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,132 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -We as members, contributors, and leaders pledge to make participation in our -community a harassment-free experience for everyone, regardless of age, body -size, visible or invisible disability, ethnicity, sex characteristics, gender -identity and expression, level of experience, education, socio-economic status, -nationality, personal appearance, race, caste, color, religion, or sexual -identity and orientation. - -We pledge to act and interact in ways that contribute to an open, welcoming, -diverse, inclusive, and healthy community. - -## Our Standards - -Examples of behavior that contributes to a positive environment for our -community include: - -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, - and learning from the experience -* Focusing on what is best not just for us as individuals, but for the overall - community - -Examples of unacceptable behavior include: - -* The use of sexualized language or imagery, and sexual attention or advances of - any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email address, - without their explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Enforcement Responsibilities - -Community leaders are responsible for clarifying and enforcing our standards of -acceptable behavior and will take appropriate and fair corrective action in -response to any behavior that they deem inappropriate, threatening, offensive, -or harmful. - -Community leaders have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct, and will communicate reasons for moderation -decisions when appropriate. - -## Scope - -This Code of Conduct applies within all community spaces, and also applies when -an individual is officially representing the community in public spaces. -Examples of representing our community include using an official email address, -posting via an official social media account, or acting as an appointed -representative at an online or offline event. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at using -[Native Discord](https://discord.gg/gonative). -All complaints will be reviewed and investigated promptly and fairly. - -All community leaders are obligated to respect the privacy and security of the -reporter of any incident. - -## Enforcement Guidelines - -Community leaders will follow these Community Impact Guidelines in determining -the consequences for any action they deem in violation of this Code of Conduct: - -### 1. Correction - -**Community Impact**: Use of inappropriate language or other behavior deemed -unprofessional or unwelcome in the community. - -**Consequence**: A private, written warning from community leaders, providing -clarity around the nature of the violation and an explanation of why the -behavior was inappropriate. A public apology may be requested. - -### 2. Warning - -**Community Impact**: A violation through a single incident or series of -actions. - -**Consequence**: A warning with consequences for continued behavior. No -interaction with the people involved, including unsolicited interaction with -those enforcing the Code of Conduct, for a specified period of time. This -includes avoiding interactions in community spaces as well as external channels -like social media. Violating these terms may lead to a temporary or permanent -ban. - -### 3. Temporary Ban - -**Community Impact**: A serious violation of community standards, including -sustained inappropriate behavior. - -**Consequence**: A temporary ban from any sort of interaction or public -communication with the community for a specified period of time. No public or -private interaction with the people involved, including unsolicited interaction -with those enforcing the Code of Conduct, is allowed during this period. -Violating these terms may lead to a permanent ban. - -### 4. Permanent Ban - -**Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an -individual, or aggression toward or disparagement of classes of individuals. - -**Consequence**: A permanent ban from any sort of public interaction within the -community. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 2.1, available at -[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. - -Community Impact Guidelines were inspired by -[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. - -For answers to common questions about this code of conduct, see the FAQ at -[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at -[https://www.contributor-covenant.org/translations][translations]. - -[homepage]: https://www.contributor-covenant.org -[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html -[Mozilla CoC]: https://github.com/mozilla/diversity -[FAQ]: https://www.contributor-covenant.org/faq -[translations]: https://www.contributor-covenant.org/translations diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index f089ab5..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,101 +0,0 @@ -# Contributing - -Thank you for considering making contributions to the Native network! 🌟 - -Contributing to this repo can mean many things such as participating in -discussions or proposing new features, improvements or bug fixes. To ensure a -smooth and timely workflow for all contributors, the general procedure for -contributing has been established: - -1. If you would like to contribute, first do your best to check if discussions - already exist as either a Github [Discussion](https://github.com/gonative-cc/relayer/discussions), - [Issue](https://github.com/gonative-cc/relayer/issues) or - [PR](https://github.com/gonative-cc/relayer/pulls). Be sure to also check out - our public [Discord](https://discord.gg/gonative). Existing discussions will help you - gain context on the current status of the proposed contribution or topic. If - one does not exist, feel free to start one. -2. If you would like to create a [Github Issue](https://github.com/gonative-cc/relayer/issues), - either [open](https://github.com/gonative-cc/relayer/issues/new/choose) or - [find](https://github.com/gonative-cc/relayer/issues) an issue you'd like to - help with. If the issue already exists, attempt to participate in thoughtful - discussion on that issue. -3. If you would like to contribute: - 1. If the issue is a proposal, ensure that the proposal has been discussed - and accepted. - 2. Ensure that nobody else has already begun working on this issue. If they - have, make sure to contact them to potentially collaborate. - 3. If nobody has been assigned for the issue and you would like to work on it, - make a comment on the issue to inform the community of your intentions to - begin work. - 4. Follow standard GitHub best practices, i.e. fork the repo, branch from the - HEAD of `master`, make commits, and submit a PR to `master` - - For core developers working within the repo, to ensure a clear ownership - of branches, branches must be named with the convention `{moniker}/{issue#}-branch-name`. - 5. Be sure to submit the PR in `Draft` mode. Submit your PR early, even if - it's incomplete as this indicates to the community you're working on - something and allows them to provide comments early in the development - process. - 6. When the code is complete it can be marked `Ready for Review` and follow - the PR readiness checklist. - -## Coding Guidelines - -We follow the Cosmos SDK [Coding Guidelines](https://github.com/cosmos/cosmos-sdk/blob/master/CODING_GUIDELINES.md). Specifically: - -- API & Design SHOULD be proposed and reviewed before the implementaion. -- Minimize code duplication -- Define [Acceptance tests](https://github.com/cosmos/cosmos-sdk/blob/master/CODING_GUIDELINES.md#acceptance-tests) or while implementing new features. - - Prefer use of acceptance test framework, like [gocuke](https://github.com/regen-network/gocuke/) - - For unit tests or integration tests use [go mock](https://github.com/golang/mock) for creating mocks. Generate mock interface implementations using `go generate`. -- Make sure you update the [CHANGELOG](CHANGELOG.md) - -## Requesting Reviews - -In order to accommodate the review process, the author of the PR must complete the author checklist (from the pull request template) to the best of their abilities before marking the PR as "Ready for Review". If you would like to receive early feedback on the PR, open the PR as a "Draft" and leave a comment in the PR indicating that you would like early feedback and tagging whoever you would like to receive feedback from. - -Codeowners are marked automatically as the reviewers. - -All PRs require at least one approval before they can be merged. - -## Design Documents - -When proposing a design decision for the Native network, please start by -opening an [Issue](https://github.com/gonative-cc/relayer/issues/new/choose) or a -[Discussion](https://github.com/gonative-cc/relayer/discussions/new) with a summary -of the proposal. - -Once the proposal has been discussed and there is rough alignment on a high-level -approach to the design, a [design doc](https://github.com/gonative-cc/relayer/blob/master/docs/design_docs/README.md) can be drafted in a dedicated pull request. -We are following this process to ensure all involved parties are in agreement before any party begins coding the proposed implementation. - -## Branching Model - -The Native network repo adheres to the [trunk based development branching](https://trunkbaseddevelopment.com/) -model and utilizes [semantic versioning](https://semver.org/). - -### PR Targeting - -Ensure that you base and target your PR against the `master` branch. - -All feature additions should be targeted against `master`. Bug fixes for an -outstanding release candidate should be targeted against the release candidate -branch. - -### PR & Merge Procedure - -- Ensure the PR branch is rebased on `master`. -- Ensure you provided unit tests and integration tests. -- Run `make test-unit test-e2e` to ensure that all tests pass. -- Merge the PR! - -## Release procedure - -We follow [Semantic Versioning](https://semver.org/) (from v3.0.0): - -- major version update (eg 2.x.x -> 3.0.0) has API breaking changes or signals major feature update. -- minor version update (eg 2.1.x -> 2.2.0) has no API nor state machine breaking changes. It can provide new functionality or bug fixes. -- patch version update (eg 2.1.0 -> 2.1.1) has no API nor state machine breaking changes nor new features. It only contains backwards compatible bug fixes. - -### Major Release Procedure - -All major changes related to major version update are first released for testnet. We use `-betaX` (eg `2.0.0-beta1`, `2.0.0-beta2` ...) releases for testnet. Once the code is stabilized we create a release candidate (eg `2.0.0-rc1`). If no issues are found the latest release candidate become the major release. diff --git a/Makefile b/Makefile index bfe536f..3290a50 100644 --- a/Makefile +++ b/Makefile @@ -11,9 +11,9 @@ out: build: out .git/hooks/pre-commit go build -o ./out ./cmd/* -run: +start: @if [ ! -f .env ]; then echo "Create .env file by copying and updating .env.example"; exit 1; fi - @./out/rly-pera start --block 8713586 + @./out/native-ika start --block 8713586 clean: rm -rf out @@ -39,7 +39,7 @@ lint-fix-go-all: @gofmt -w -s -l . -.PHONY: build run clean setup +.PHONY: build start clean setup .PHONY: lint lint-all lint-fix-all lint-fix-go-all ############################################################################### diff --git a/README.md b/README.md index db0ee8a..eec58a4 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,13 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/gonative-cc/relayer?style=flat-square)](https://goreportcard.com/report/github.com/gonative-cc/relayer) [![Version](https://img.shields.io/github/tag/gonative-cc/relayer.svg?style=flat-square)](https://github.com/gonative-cc/relayer) [![License: MPL-2.0](https://img.shields.io/github/license/gonative-cc/relayer.svg?style=flat-square)](https://github.com/gonative-cc/relayer/blob/main/LICENSE) -[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](./CODE_OF_CONDUCT.md) +[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](https://github.com/gonative-cc/contributig/blob/master/CODE_OF_CONDUCT.md) ## Summary A software that monitors and relayers: -- CometBFT blocks to update Native -> Pera light client +- CometBFT blocks to update Native -> Ika light client - Bitcoin blocks to update Bitcoin -> Native light client - Bitcoin SPV proofs to verify dWallet holdings - Native -> Bitcoin transaction relayer @@ -29,11 +29,21 @@ Status scheme: Mock -> WIP -> alpha -> beta -> production ``` -| Service | status | -| :------------ | :----- | -| Native-\>Pera | WIP | -| Bitcoin SPV | | -| Native-\>Bitcoin | WIP | +| Service | status | +| :--------------- | :----- | +| Native-\>Ika | WIP | +| Bitcoin SPV | | +| Native-\>Bitcoin | WIP | + +## Contributing + +Participating in open source is often a highly collaborative experience. We’re encouraged to create in public view, and we’re incentivized to welcome contributions of all kinds from people around the world. + +Check out [contributing repo](https://github.com/gonative-cc/contributig) for our guidelines & policies for how to contribute. Note: we require DCO! Thank you to all those who have contributed! + +### Security + +Check out [SECURITY.md](./SECURITY.md) for security concerns. ## Setup @@ -53,8 +63,8 @@ In order to run Native -> Bitcoin relayer PoC: 1. Run `make setup` (will setup git hooks) 2. Install and make sure it is in your PATH: - - [markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2) - - [revive](https://github.com/mgechev/revive) + - [markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2) + - [revive](https://github.com/mgechev/revive) ### Coding notes @@ -67,16 +77,6 @@ In order to run Native -> Bitcoin relayer PoC: log.Info().Int("block", minimumBlockHeight).Msg("Start relaying msgs") ``` -## Contributing - -Check out [CONTRIBUTING.md](./CONTRIBUTING.md) for our guidelines & policies for how we develop the Cosmos Hub. Thank you to all those who have contributed! - -[CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) - participating in open source is often a highly collaborative experience. We’re encouraged to create in public view, and we’re incentivized to welcome contributions of all kinds from people around the world. Every contributor must follow our Code of Conduct. - -### Security - -Check out [SECURITY.md](./SECURITY.md) for security concerns. - ## Talk to us - Follow the Native team's activities on the [Native X/Twitter account](https://x.com/NativeNetwork). diff --git a/SECURITY.md b/SECURITY.md index c562e9a..0415c8e 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -1,68 +1,15 @@ # Security Policy -## Introduction +## Supported Versions -Security researchers are essential in identifying vulnerabilities that may impact the Native Network. If you have discovered a security vulnerability related to Native Network or any repository managed by Native, we encourage you to notify us using one of the methods outlined below. +Only the latest point release is supported. For example, if the latest release is v2.1.2 then: -### Guidelines for Responsible Vulnerability Testing and Reporting +| Version | Supported | +| ------- | ------------------ | +| 2.1.x | :white_check_mark: | +| 2.0.x | :x: | +| < 2.0 | :x: | -1. **Refrain from testing vulnerabilities on our publicly accessible environments** -2. **Do NOT report security vulnerabilities through public channels, including GitHub issues** +## Reporting a Vulnerability -## Reporting Security Issues - -To privately report a security vulnerability, please choose one of the following options: - -### 1. Email - -Send your detailed vulnerability report to `security@gonative.cc`. - -### 2. GitHub Private Vulnerability Reporting - -- For this project, utilize [relayer](https://github.com/gonative-cc/relayer/security/advisories/new) GitHub Private Vulnerability Reporting. -- For Native Network, utilize [gonative](https://github.com/gonative-cc/gonative/security/advisories/new) GitHub Private Vulnerability Reporting. - -## Submit Vulnerability Report - -When reporting a vulnerability through either method, please include the following details to aid in our assessment: - -- Type of vulnerability -- Description of the vulnerability -- Steps to reproduce the issue -- Impact of the issue -- Explanation of how an attacker could exploit it - -## Vulnerability Disclosure Process - -1. **Initial Report**: Submit the vulnerability via one of the above channels. -2. **Confirmation**: We will confirm receipt of your report within 48 hours. -3. **Assessment**: Our security team will evaluate the vulnerability and inform you of its severity and the estimated time frame for resolution. -4. **Resolution**: Once fixed, you will be contacted to verify the solution. -5. **Public Disclosure**: Details of the vulnerability may be publicly disclosed after ensuring it poses no further risk. - -During the vulnerability disclosure process, we ask security researchers to keep vulnerabilities and communications around vulnerability submissions private and confidential until a patch is developed. Should a security issue require a network upgrade, additional time may be needed to raise a governance proposal and complete the upgrade. - -During this time: - -- Avoid exploiting any vulnerabilities you discover. -- Demonstrate good faith by not disrupting or degrading Osmosis's services. - -## Severity Characterization - -| Severity | Description | -|--------------|-------------------------------------------------------------------------| -| **CRITICAL** | Immediate threat to critical systems (e.g., chain halts, funds at risk) | -| **HIGH** | Significant impact on major functionality | -| **MEDIUM** | Impacts minor features or exposes non-sensitive data | -| **LOW** | Minimal impact | - -## Bug Bounty - -Though we don't have an official bug bounty program, we generally offer rewards to security researchers who responsibly disclose vulnerabilities to us. Bounties are generally awarded for vulnerabilities classified as **high** or **critical** severity. Bounty amounts will be determined during the disclosure process, after the severity has been assessed. Please note that in order to collect a bounty, the reporter must go through a KYC process. - -> [!WARNING] -> Targeting our production environments will disqualify you from receiving any bounty. - -## Feedback on this Policy - -For recommendations on how to improve this policy, either submit a pull request or send an email to `security@gonative.cc`. +See [contributing repo](https://github.com/gonative-cc/contributig) for reporting security vulnerability or sharing a security feedback. diff --git a/cmd/native-ika/cli.go b/cmd/native-ika/cli.go index f3f5c22..1112252 100644 --- a/cmd/native-ika/cli.go +++ b/cmd/native-ika/cli.go @@ -4,6 +4,9 @@ import ( "fmt" "os" + "github.com/block-vision/sui-go-sdk/signer" + "github.com/block-vision/sui-go-sdk/sui" + "github.com/gonative-cc/relayer/ika" "github.com/gonative-cc/relayer/native" "github.com/gonative-cc/relayer/native/blockchain" "github.com/rs/zerolog/log" @@ -16,12 +19,19 @@ const ( EnvChainGRPC = "NATIVE_GRPC" FlagMinimumBlockHeight = "block" defaultPort = "8080" + IkaChain = "IKA_RPC" + IkaSignerMnemonic = "IKA_SIGNER_MNEMONIC" + IkaNativeLcPackage = "IKA_NATIVE_LC_PACKAGE" + IkaNativeLcModule = "IKA_NATIVE_LC_MODULE" + IkaNativeLcFunction = "IKA_NATIVE_LC_FUNCTION" + IkaGasAcc = "IKA_GAS_ACC" + IkaGasBudget = "IKA_GAS_BUDGET" ) var ( rootCmd = &cobra.Command{ - Use: "rly-pera", - Short: "An relayer for Native <-> Pera MPC", + Use: "native-ika", + Short: "An relayer for Native <-> Ika MPC", } ) @@ -53,9 +63,31 @@ func CmdStart() *cobra.Command { if err != nil { return err } + c := sui.NewSuiClient(os.Getenv(IkaChain)).(*sui.Client) + + signer, err := signer.NewSignertWithMnemonic(os.Getenv(IkaSignerMnemonic)) + if err != nil { + return err + } + logger := log.With().Str("module", "native").Logger() ctx := cmd.Context() - idx, err := native.NewIndexer(ctx, b, logger, minimumBlockHeight) + + lcContract := ika.SuiCtrCall{ + Package: os.Getenv(IkaNativeLcPackage), + Module: os.Getenv(IkaNativeLcModule), + Function: os.Getenv(IkaNativeLcFunction), + } + if err := lcContract.Validate(); err != nil { + return err + } + ikaClient, err := ika.NewClient(c, signer, lcContract, + os.Getenv(IkaGasAcc), os.Getenv(IkaGasBudget)) + if err != nil { + return err + } + + idx, err := native.NewIndexer(ctx, b, logger, minimumBlockHeight, ikaClient) if err != nil { return err } @@ -71,8 +103,10 @@ func CmdStart() *cobra.Command { // just prints the env file. func printEnv() { fmt.Printf( - "__ENVS used__\n%s = %s\n%s = %s\n-----------------\n", + "__ENVS used__\n%s = %s\n%s = %s\n%s = %s\n%s = %s\n-----------------\n", EnvChainRPC, os.Getenv(EnvChainRPC), EnvChainGRPC, os.Getenv(EnvChainGRPC), + IkaChain, os.Getenv(IkaChain), + IkaNativeLcFunction, os.Getenv(IkaNativeLcFunction), ) } diff --git a/go.mod b/go.mod index 2e198dc..b3808d7 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,9 @@ module github.com/gonative-cc/relayer -go 1.22.7 +go 1.23 require ( + github.com/block-vision/sui-go-sdk v1.0.6 github.com/btcsuite/btcd v0.24.2 github.com/cometbft/cometbft v0.38.15 github.com/cosmos/cosmos-sdk v0.50.10 @@ -24,7 +25,7 @@ require ( cosmossdk.io/depinject v1.0.0 // indirect cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.4.1 // indirect - cosmossdk.io/math v1.3.0 // indirect + cosmossdk.io/math v1.4.0 // indirect cosmossdk.io/store v1.1.1 // indirect cosmossdk.io/x/tx v0.13.5 // indirect filippo.io/edwards25519 v1.0.0 // indirect @@ -75,6 +76,9 @@ require ( github.com/go-kit/kit v0.13.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.12.0 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/gogo/googleapis v1.4.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -110,6 +114,7 @@ require ( github.com/klauspost/compress v1.17.9 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect + github.com/leodido/go-urn v1.2.2 // indirect github.com/lib/pq v1.10.9 // indirect github.com/linxGnu/grocksdb v1.8.14 // indirect github.com/magiconair/properties v1.8.7 // indirect @@ -119,6 +124,7 @@ require ( github.com/minio/highwayhash v1.0.3 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/mr-tron/base58 v1.2.0 // indirect github.com/mtibben/percent v0.2.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect @@ -147,6 +153,10 @@ require ( github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect github.com/tidwall/btree v1.7.0 // indirect + github.com/tidwall/gjson v1.14.4 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect + github.com/tyler-smith/go-bip39 v1.1.0 // indirect github.com/zondax/hid v0.9.2 // indirect github.com/zondax/ledger-go v0.14.3 // indirect go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect @@ -158,6 +168,7 @@ require ( golang.org/x/sys v0.26.0 // indirect golang.org/x/term v0.25.0 // indirect golang.org/x/text v0.19.0 // indirect + golang.org/x/time v0.5.0 // indirect google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect diff --git a/go.sum b/go.sum index ff2f4ec..b84010a 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,8 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U= cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM= cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU= -cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= -cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= +cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ= +cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk= cosmossdk.io/store v1.1.1 h1:NA3PioJtWDVU7cHHeyvdva5J/ggyLDkyH0hGHl2804Y= cosmossdk.io/store v1.1.1/go.mod h1:8DwVTz83/2PSI366FERGbWSH7hL6sB7HbYp8bqksNwM= cosmossdk.io/x/tx v0.13.5 h1:FdnU+MdmFWn1pTsbfU0OCf2u6mJ8cqc1H4OMG418MLw= @@ -71,6 +71,8 @@ github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2 github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bits-and-blooms/bitset v1.8.0 h1:FD+XqgOZDUxxZ8hzoBFuV9+cGWY9CslN6d5MS5JVb4c= github.com/bits-and-blooms/bitset v1.8.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= +github.com/block-vision/sui-go-sdk v1.0.6 h1:FysCc4TJC8v4BEBbCjJPDR4iR5eKqJT1dxGwsT67etg= +github.com/block-vision/sui-go-sdk v1.0.6/go.mod h1:FyK1vGE8lWm9QA1fdQpf1agfXQSMbPT8AV1BICgx6d8= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A= @@ -269,6 +271,14 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.12.0 h1:E4gtWgxWxp8YSxExrQFv5BpCahla0PVF2oTTEYaWQGI= +github.com/go-playground/validator/v10 v10.12.0/go.mod h1:hCAPuzYvKdP33pxWa+2+6AIKXEKqjIUyqsNCtbsSJrA= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= @@ -461,6 +471,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/leodido/go-urn v1.2.2 h1:7z68G0FCGvDk646jz1AelTYNYWrTNm0bEcFAo147wt4= +github.com/leodido/go-urn v1.2.2/go.mod h1:kUaIbLZWttglzwNuG0pgsh5vuV6u2YcGBYz1hIPjtOQ= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= @@ -507,6 +519,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= +github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -639,6 +653,7 @@ github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/rwtodd/Go.Sed v0.0.0-20210816025313-55464686f9ef/go.mod h1:8AEUvGVi2uQ5b24BIhcr0GCcpd/RNAFWaN2CJFrWIIQ= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= @@ -692,6 +707,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= @@ -704,8 +720,16 @@ github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2l github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= +github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM= +github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= +github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= +github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= @@ -888,6 +912,8 @@ golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/ika/client.go b/ika/client.go new file mode 100644 index 0000000..6230e17 --- /dev/null +++ b/ika/client.go @@ -0,0 +1,80 @@ +package ika + +import ( + "context" + + "github.com/block-vision/sui-go-sdk/models" + "github.com/block-vision/sui-go-sdk/signer" + "github.com/block-vision/sui-go-sdk/sui" + tmtypes "github.com/cometbft/cometbft/types" + "github.com/rs/zerolog" +) + +// Client is a wrapper around the Sui client that provides functionality +// for interacting with Ika +type Client struct { + c *sui.Client + Signer *signer.Signer + LcPackage string + Module string + Function string + GasAddr string + GasBudget string +} + +// NewClient creates a new Client instance +func NewClient( + c *sui.Client, + signer *signer.Signer, + ctr SuiCtrCall, + gasAddr, gasBudget string, +) (*Client, error) { + i := &Client{ + c: c, + Signer: signer, + LcPackage: ctr.Package, + Module: ctr.Module, + Function: ctr.Function, + GasAddr: gasAddr, + GasBudget: gasBudget, + } + return i, nil +} + +// UpdateLC sends light blocks to the Native Light Client module in the Ika blockchain. +// It returns the transaction response and an error if any occurred. +func (p *Client) UpdateLC( + ctx context.Context, + lb *tmtypes.LightBlock, + logger zerolog.Logger, +) (models.SuiTransactionBlockResponse, error) { + req := models.MoveCallRequest{ + Signer: p.Signer.Address, + PackageObjectId: p.LcPackage, + Module: p.Module, + Function: p.Function, + TypeArguments: []interface{}{}, + Arguments: []interface{}{ + lb, + }, + Gas: &p.GasAddr, + GasBudget: p.GasBudget, + } + resp, err := p.c.MoveCall(ctx, req) + if err != nil { + logger.Err(err).Msg("Error calling move function:") + return models.SuiTransactionBlockResponse{}, err // Return zero value for the response + } + + // TODO: verify if we need to call this + return p.c.SignAndExecuteTransactionBlock(ctx, models.SignAndExecuteTransactionBlockRequest{ + TxnMetaData: resp, + PriKey: p.Signer.PriKey, + Options: models.SuiTransactionBlockOptions{ + ShowInput: true, + ShowRawInput: true, + ShowEffects: true, + }, + RequestType: "WaitForLocalExecution", + }) +} diff --git a/ika/sui.go b/ika/sui.go new file mode 100644 index 0000000..ef9c7eb --- /dev/null +++ b/ika/sui.go @@ -0,0 +1,27 @@ +package ika + +import ( + "errors" + "strings" +) + +// SuiCtrCall defines a contract path to call in Sui +type SuiCtrCall struct { + Package, Module, Function string +} + +// Validate the fields of the struct +func (ctr SuiCtrCall) Validate() error { + return errors.Join( + checkNotEmpty("package", ctr.Package), + checkNotEmpty("module", ctr.Module), + checkNotEmpty("function", ctr.Function), + ) +} + +func checkNotEmpty(name, s string) error { + if strings.TrimSpace(s) == "" { + return errors.New(name + " must be defined") + } + return nil +} diff --git a/native/account.go b/native/account.go new file mode 100644 index 0000000..6ec9565 --- /dev/null +++ b/native/account.go @@ -0,0 +1,3 @@ +package native + +// Account related functions will go here diff --git a/native/blockchian.go b/native/blockchain.go similarity index 92% rename from native/blockchian.go rename to native/blockchain.go index 772d5fe..0c79edc 100644 --- a/native/blockchian.go +++ b/native/blockchain.go @@ -17,6 +17,6 @@ type Blockchain interface { DecodeTx(tx tmtypes.Tx) (sdktypes.Tx, error) SubscribeNewBlock(ctx context.Context) (<-chan *tmtypes.Block, error) Block(ctx context.Context, height int64) (blk *tmtypes.Block, minimumBlkHeight int, err error) - CheckTx(ctx context.Context, tx tmtypes.Tx) (err error) + CheckTx(ctx context.Context, tx tmtypes.Tx) error LightProvider() provtypes.Provider } diff --git a/native/handlers.go b/native/handlers.go index f09d3e9..216c12b 100644 --- a/native/handlers.go +++ b/native/handlers.go @@ -15,7 +15,7 @@ func (i *Indexer) HandleNewBlock(ctx context.Context, blk *tmtypes.Block) error return i.HandleBlock(ctx, blk) } -// HandleBlock handles the receive of an block from the chain. +// HandleBlock handles the receive of a block from the chain. func (i *Indexer) HandleBlock(ctx context.Context, blk *tmtypes.Block) error { // light block lb, err := i.b.LightProvider().LightBlock(ctx, blk.Header.Height) @@ -23,6 +23,13 @@ func (i *Indexer) HandleBlock(ctx context.Context, blk *tmtypes.Block) error { return err } i.logger.Info().Int64("light block", lb.SignedHeader.Header.Height).Msg("Light Block ") + + txrsp, err := i.ika.UpdateLC(ctx, lb, i.logger) + if err != nil { + return err + } + i.logger.Debug().Any("transaction response", txrsp).Msg("After making transaction") + for _, tx := range blk.Data.Txs { if err := i.HandleTx(ctx, int(blk.Header.Height), int(blk.Time.Unix()), tx); err != nil { i.logger.Err(err).Int64("height", blk.Height).Msg("error handling block") diff --git a/native/indexer.go b/native/indexer.go index 935adb9..6fede5b 100644 --- a/native/indexer.go +++ b/native/indexer.go @@ -5,9 +5,8 @@ import ( "sync" "time" - "golang.org/x/sync/errgroup" - tmtypes "github.com/cometbft/cometbft/types" + "github.com/gonative-cc/relayer/ika" "github.com/rs/zerolog" ) @@ -22,16 +21,19 @@ type Indexer struct { // defines the lowest block that the node has available in store. // Usually nodes prun blocks after 2 weeks. lowestBlock int + logger zerolog.Logger - logger zerolog.Logger + ika *ika.Client } // NewIndexer returns a new indexer struct with open connections. -func NewIndexer(ctx context.Context, b Blockchain, logger zerolog.Logger, startBlockHeight int) (*Indexer, error) { +func NewIndexer(ctx context.Context, b Blockchain, logger zerolog.Logger, + startBlockHeight int, ika *ika.Client) (*Indexer, error) { i := &Indexer{ b: b, logger: logger.With().Str("package", "indexer").Logger(), lowestBlock: startBlockHeight, + ika: ika, } return i, i.onStart(ctx) } @@ -162,11 +164,5 @@ func (i *Indexer) loadChainHeader(_ context.Context) error { // Close closes all the open connections. func (i *Indexer) Close(ctx context.Context) error { - g, ctx := errgroup.WithContext(ctx) - - g.Go(func() error { - return i.b.Close(ctx) - }) - - return g.Wait() + return i.b.Close(ctx) }