Skip to content

feat: canton-sdk bridge client#115

Open
sadiq1971 wants to merge 12 commits intomainfrom
feat/canton-sdk-bridge
Open

feat: canton-sdk bridge client#115
sadiq1971 wants to merge 12 commits intomainfrom
feat/canton-sdk-bridge

Conversation

@sadiq1971
Copy link
Member

Closes #95

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @sadiq1971, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the project's interaction capabilities with the Canton ledger by introducing a modular Go SDK. It provides dedicated clients for managing asset bridging, user identities, and CIP-56 compliant tokens, all built upon a robust low-level ledger client. Concurrently, it establishes a comprehensive and automated linting setup to ensure code quality and consistency across the Go codebase.

Highlights

  • New Canton SDK Bridge Client: Introduced a new Go client for interacting with Canton's Wayfinder bridge, enabling deposit/withdrawal flows and bridge-related event queries.
  • New Canton SDK Identity Client: Added a Go client for Canton identity operations, including party allocation, listing, fingerprint-to-party mapping, and user rights management.
  • New Canton SDK Token Client: Implemented a Go client for CIP-56 token operations, supporting minting, burning, balance queries, and token transfers.
  • Comprehensive Go Linter Configuration: Added a detailed .golangci.yml file to enforce a wide range of Go linting rules for correctness, security, and maintainability.
  • Automated Linter Installation in Makefile: Updated the Makefile to automatically download and use golangci-lint if not already present, streamlining the linting process.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .golangci.yml
    • Added a new Go linter configuration file with extensive rules for code quality and style.
  • Makefile
    • Updated the 'lint' target to include automatic installation of 'golangci-lint' if not found.
    • Modified the 'lint' target to execute the locally installed 'golangci-lint' binary.
  • pkg/canton-sdk/bridge/client.go
    • Added the core implementation for the Canton bridge client, providing functions for deposit processing, withdrawal initiation, and event retrieval.
  • pkg/canton-sdk/bridge/config.go
    • Added the configuration structure and validation logic for the bridge client.
  • pkg/canton-sdk/bridge/decode.go
    • Added utility functions for decoding MintEvent and BurnEvent from Canton ledger events.
  • pkg/canton-sdk/bridge/encode.go
    • Added utility functions for encoding arguments for Canton bridge commands.
  • pkg/canton-sdk/bridge/options.go
    • Added functional options for configuring the bridge client, including logger integration.
  • pkg/canton-sdk/bridge/types.go
    • Added data structures for bridge-related requests and event representations.
  • pkg/canton-sdk/client/client.go
    • Added a high-level Canton SDK client that aggregates ledger, identity, token, and bridge operations.
    • Provided a convenience adapter to initialize the SDK client from existing application configuration.
  • pkg/canton-sdk/client/config.go
    • Added the configuration structure for the main Canton SDK client.
  • pkg/canton-sdk/client/options.go
    • Added functional options for configuring the main SDK client, including logger and HTTP client.
  • pkg/canton-sdk/identity/client.go
    • Added the identity client implementation with functions for party allocation, listing, fingerprint mapping, and user rights management.
  • pkg/canton-sdk/identity/config.go
    • Added the configuration structure and validation logic for the identity client.
  • pkg/canton-sdk/identity/encode.go
    • Added a function to encode arguments for creating fingerprint mappings on Canton.
  • pkg/canton-sdk/identity/options.go
    • Added functional options for configuring the identity client, including logger integration.
  • pkg/canton-sdk/identity/types.go
    • Added data structures for identity-related requests and entities like Party and FingerprintMapping.
  • pkg/canton-sdk/ledger/auth.go
    • Added an OAuth2 client credentials provider for authenticating with the Canton ledger.
  • pkg/canton-sdk/ledger/client.go
    • Added the low-level Canton Ledger API client, managing gRPC connectivity, authentication, and service access.
  • pkg/canton-sdk/ledger/config.go
    • Added configuration structures for the ledger client, including RPC, TLS, and OAuth authentication settings.
  • pkg/canton-sdk/ledger/dial.go
    • Added utility functions for configuring gRPC dial options and loading TLS certificates.
  • pkg/canton-sdk/ledger/options.go
    • Added functional options for configuring the ledger client, including logger, HTTP client, and gRPC dial options.
  • pkg/canton-sdk/token/client.go
    • Added the token client implementation with functions for minting, burning, balance queries, and token transfers.
  • pkg/canton-sdk/token/config.go
    • Added the configuration structure and validation logic for the token client.
  • pkg/canton-sdk/token/decimal.go
    • Added utility functions for performing arithmetic operations on decimal strings.
  • pkg/canton-sdk/token/encode.go
    • Added utility functions for encoding arguments for Canton token commands like IssuerMint and Transfer.
  • pkg/canton-sdk/token/options.go
    • Added functional options for configuring the token client, including logger integration.
  • pkg/canton-sdk/token/types.go
    • Added data structures for token-related requests and entities like Holding, MintRequest, and BurnRequest.
  • pkg/canton-sdk/values/decode.go
    • Added utility functions to safely extract various value types (Text, Party, Numeric, ContractID, Timestamp) from Canton Ledger API values.
  • pkg/canton-sdk/values/encode.go
    • Added utility functions to create Canton Ledger API value types (TextValue, PartyValue, NumericValue, ContractIDValue, TimestampValue, Optional).
  • pkg/canton-sdk/values/meta.go
    • Added a utility function to extract the token symbol from CIP-56 meta records.
  • pkg/canton-sdk/values/values.go
    • Added a utility function to convert a Ledger API record into a map for easier access.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive Canton SDK for Go, organized into several packages: ledger, identity, token, bridge, client, and values. It also adds a golangci-lint configuration and updates the Makefile to support it. The changes are extensive and establish a solid foundation for the new SDK. My review focuses on ensuring the new linting configuration is correctly applied, improving the build process, and enhancing the testability and robustness of the new SDK code.

Comment on lines +144 to +156
- pkg/apidb
- pkg/auth
- pkg/canton
- pkg/config
- pkg/db
- pkg/ethereum
- pkg/ethrpc
- pkg/keys
- pkg/registration
- pkg/relayer
- pkg/service
- cmd
- internal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The paths in exclusions.paths are not anchored. As the comment on line 142 points out, this can lead to unintended exclusions. For example, pkg/canton will also match pkg/canton-sdk, effectively disabling linters for the new SDK code. The paths should be anchored to match only the intended directories.

      - ^pkg/apidb/
      - ^pkg/auth/
      - ^pkg/canton/
      - ^pkg/config/
      - ^pkg/db/
      - ^pkg/ethereum/
      - ^pkg/ethrpc/
      - ^pkg/keys/
      - ^pkg/registration/
      - ^pkg/relayer/
      - ^pkg/service/
      - ^cmd/
      - ^internal/

Comment on lines +181 to +193
- pkg/apidb
- pkg/auth
- pkg/canton
- pkg/config
- pkg/db
- pkg/ethereum
- pkg/ethrpc
- pkg/keys
- pkg/registration
- pkg/relayer
- pkg/service
- cmd
- internal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the linter exclusions, the paths in formatters.exclusions.paths are not anchored. This will cause formatters to be disabled for unintended paths, such as the new pkg/canton-sdk directory. Please anchor these regex patterns to ensure they only apply to the specified directories.

      - ^pkg/apidb/
      - ^pkg/auth/
      - ^pkg/canton/
      - ^pkg/config/
      - ^pkg/db/
      - ^pkg/ethereum/
      - ^pkg/ethrpc/
      - ^pkg/keys/
      - ^pkg/registration/
      - ^pkg/relayer/
      - ^pkg/service/
      - ^cmd/
      - ^internal/


get_lint:
if [ ! -f ./bin/golangci-lint ]; then \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v2.9.0; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The version v2.9.0 specified for golangci-lint appears to be invalid. golangci-lint versions follow a v1.x.y format, so this will likely cause the installation to fail. Please use a valid and recent version, for example v1.59.1.

		curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- v1.59.1; \

Comment on lines +360 to +362
if strings.Contains(strings.ToLower(err.Error()), "already") {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error check for an already completed withdrawal is brittle as it relies on string matching the error message. It's better to inspect the gRPC status code, as noted in the TODO on the preceding line. You can use google.golang.org/grpc/status and google.golang.org/grpc/codes to check for codes.AlreadyExists. A similar pattern is already used in pkg/canton-sdk/identity/client.go.

Suggested change
if strings.Contains(strings.ToLower(err.Error()), "already") {
return nil
}
s, ok := status.FromError(err)
if ok && s.Code() == codes.AlreadyExists {
return nil
}

{Label: "fingerprint", Value: values.TextValue(req.Fingerprint)},
{Label: "amount", Value: values.NumericValue(req.Amount)},
{Label: "evmTxHash", Value: values.TextValue(req.EvmTxHash)},
{Label: "eventTime", Value: values.TimestampValue(time.Now())},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using time.Now() directly in these encoding functions makes them non-deterministic and harder to test. Consider passing the timestamp as an argument to the functions, for example by adding an EventTime field to the request structs (e.g., CreatePendingDepositRequest). If the field is not set, you could then default to time.Now(). This change would improve testability for all encode* functions in this file.

Fields: []*lapiv2.RecordField{
{Label: "recipient", Value: values.PartyValue(req.RecipientParty)},
{Label: "amount", Value: values.NumericValue(req.Amount)},
{Label: "eventTime", Value: values.TimestampValue(time.Now())},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using time.Now() directly in these encoding functions makes them non-deterministic and harder to test. Consider passing the timestamp as an argument to the functions, for example by adding an EventTime field to the request structs (e.g., MintRequest). If the field is not set, you could then default to time.Now(). This change would improve testability for encodeIssuerMintArgs and encodeIssuerBurnArgs in this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[canton-sdk] implement optional bridge client (deposit/withdrawal/events)

1 participant