Skip to content

feat: wired canton-sdk#116

Open
sadiq1971 wants to merge 15 commits intomainfrom
feat/canton-sdk-wiring
Open

feat: wired canton-sdk#116
sadiq1971 wants to merge 15 commits intomainfrom
feat/canton-sdk-wiring

Conversation

@sadiq1971
Copy link
Member

@sadiq1971 sadiq1971 commented Feb 16, 2026

Closes #96

@sadiq1971 sadiq1971 changed the title feat feat: wired canton-sdk Feb 16, 2026
@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 overhauls the Canton client integration by introducing a new, modular Canton SDK. This refactoring aims to improve the maintainability and extensibility of the codebase by breaking down the previous monolithic client into specialized sub-clients for ledger, identity, token, and bridge operations. Additionally, it integrates golangci-lint to ensure higher code quality and consistency across the project. The changes impact how various services interact with the Canton ledger, leading to a more structured and robust system.

Highlights

  • New Canton SDK: Replaced the monolithic pkg/canton client with a modular pkg/canton-sdk structure, comprising ledger, identity, token, and bridge sub-clients for improved organization and extensibility.
  • Improved Code Quality: Integrated golangci-lint with a comprehensive configuration to enforce Go code quality, correctness, and security standards across the project.
  • Refactored Canton Interactions: Updated api-server and relayer components to utilize the new Canton SDK's specialized clients for identity, token, and bridge operations, streamlining interactions with the Canton ledger.
  • Centralized Ledger API Handling: Introduced a dedicated ledger client within the SDK to manage gRPC connectivity, TLS, and OAuth2 authentication for Canton Ledger API v2.
  • Streamlined Token Operations: Implemented a specific token client for CIP-56 token management, including minting, burning, transfers, and balance queries.
  • Dedicated Bridge Functionality: Created a bridge client for handling Canton-specific deposit and withdrawal flows, separating this logic from the core client.

🧠 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 configuration file for golangci-lint with extensive rules for code quality.
  • Makefile
    • Updated lint target to automatically download and use golangci-lint v2.9.0.
  • cmd/api-server/main.go
    • Updated Canton client initialization to use canton-sdk/client and its sub-clients (Token, Identity).
  • cmd/relayer/main.go
    • Updated Canton client initialization to use canton-sdk/client and its Bridge sub-client.
  • pkg/apidb/events.go
    • Updated Canton import to canton-sdk/token.
  • pkg/apidb/reconcile.go
    • Refactored Reconciler to use canton-sdk/token interface and updated method calls.
  • pkg/canton-sdk/bridge/client.go
    • Added new client for Canton bridge operations.
  • pkg/canton-sdk/bridge/config.go
    • Added configuration structure for the bridge client.
  • pkg/canton-sdk/bridge/decode.go
    • Added decoding utilities for bridge-related Canton values.
  • pkg/canton-sdk/bridge/encode.go
    • Added encoding utilities for bridge-related Canton commands.
  • pkg/canton-sdk/bridge/options.go
    • Added options pattern for configuring the bridge client.
  • pkg/canton-sdk/bridge/types.go
    • Added types for bridge operations like PendingDeposit and WithdrawalEvent.
  • pkg/canton-sdk/client/client.go
    • Added new top-level Canton SDK client facade.
  • pkg/canton-sdk/client/config.go
    • Added configuration structure for the main SDK client.
  • pkg/canton-sdk/client/options.go
    • Added options pattern for configuring the main SDK client.
  • pkg/canton-sdk/identity/client.go
    • Added new client for Canton identity management.
  • pkg/canton-sdk/identity/config.go
    • Added configuration structure for the identity client.
  • pkg/canton-sdk/identity/encode.go
    • Added encoding utilities for identity-related Canton commands.
  • pkg/canton-sdk/identity/options.go
    • Added options pattern for configuring the identity client.
  • pkg/canton-sdk/identity/types.go
    • Added types for identity operations like Party and FingerprintMapping.
  • pkg/canton-sdk/lapi/v2/admin/command_inspection_service.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/admin/command_inspection_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/admin/identity_provider_config_service.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/admin/identity_provider_config_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/admin/object_meta.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/admin/package_management_service.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/admin/package_management_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/admin/participant_pruning_service.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/admin/participant_pruning_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/admin/party_management_service.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/admin/party_management_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/admin/user_management_service.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/admin/user_management_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 admin services.
  • pkg/canton-sdk/lapi/v2/command_completion_service.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/command_completion_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/command_service.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/command_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/command_submission_service.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/command_submission_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/commands.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/completion.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/crypto.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/event.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/event_query_service.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/event_query_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/experimental_features.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/offset_checkpoint.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/package_reference.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/package_service.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/package_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/reassignment.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/reassignment_commands.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/state_service.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/state_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/topology_transaction.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/trace_context.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/transaction.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/transaction_filter.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/update_service.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/update_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/value.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/version_service.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/lapi/v2/version_service_grpc.pb.go
    • Renamed package for Canton Ledger API v2 core services.
  • pkg/canton-sdk/ledger/auth.go
    • Added authentication provider for the ledger client.
  • pkg/canton-sdk/ledger/client.go
    • Added new low-level Canton Ledger API client.
  • pkg/canton-sdk/ledger/config.go
    • Added configuration structure for the ledger client.
  • pkg/canton-sdk/ledger/dial.go
    • Added gRPC dial options and TLS configuration loading for the ledger client.
  • pkg/canton-sdk/ledger/options.go
    • Added options pattern for configuring the ledger client.
  • pkg/canton-sdk/token/client.go
    • Added new client for CIP-56 token operations.
  • pkg/canton-sdk/token/config.go
    • Added configuration structure for the token client.
  • pkg/canton-sdk/token/decimal.go
    • Added decimal string utility functions for token amounts.
  • pkg/canton-sdk/token/decode.go
    • Added decoding utilities for token-related Canton values.
  • pkg/canton-sdk/token/encode.go
    • Added encoding utilities for token-related Canton commands.
  • pkg/canton-sdk/token/options.go
    • Added options pattern for configuring the token client.
  • pkg/canton-sdk/token/types.go
    • Added types for token operations like Holding, MintRequest, and BurnEvent.
  • pkg/canton-sdk/values/decode.go
    • Added decoding utilities for generic Canton Ledger API value types.
  • pkg/canton-sdk/values/encode.go
    • Added encoding utilities for generic Canton Ledger API value types.
  • pkg/canton-sdk/values/meta.go
    • Added utility to extract token symbol from CIP-56 meta records.
  • pkg/canton-sdk/values/values.go
    • Added helper utilities for working with Canton Ledger API value types.
  • pkg/canton/client.go
    • Removed old monolithic Canton client.
  • pkg/canton/client_test.go
    • Removed corresponding test file for the old Canton client.
  • pkg/canton/encoding.go
    • Removed old encoding utilities for Canton values.
  • pkg/canton/encoding_test.go
    • Removed corresponding test file for old encoding utilities.
  • pkg/canton/mocks_test.go
    • Removed corresponding mock file for the old Canton client.
  • pkg/canton/stream.go
    • Removed old streaming logic for Canton events.
  • pkg/canton/types.go
    • Removed old Canton-related types.
  • pkg/ethrpc/eth_api.go
    • Removed old Canton client dependency and introduced local decimal conversion helpers.
  • pkg/registration/handler.go
    • Updated Canton client usage to canton-sdk/identity for party allocation and fingerprint mapping.
  • pkg/relayer/engine.go
    • Updated Canton client usage to canton-sdk/bridge and adjusted offset loading logic.
  • pkg/relayer/engine_test.go
    • Updated mock Canton client to reflect new canton-sdk/bridge interface.
  • pkg/relayer/handlers.go
    • Updated Canton client usage to canton-sdk/bridge for deposit and withdrawal processing.
  • pkg/relayer/handlers_test.go
    • Updated mock Canton client to reflect new canton-sdk/bridge interface.
  • pkg/relayer/mocks_test.go
    • Updated mock Canton client to reflect new canton-sdk/bridge interface.
  • pkg/relayer/processor.go
    • Added // todo comments for error handling in event processing.
  • pkg/service/token.go
    • Updated Canton client usage to canton-sdk/token for token transfers and removed GetCantonClient.
Activity
  • The author sadiq1971 initiated this pull request.
  • A new .golangci.yml file was added, indicating the introduction of static analysis for Go code.
  • The Makefile was updated to include a get_lint target, ensuring the linter is installed and used consistently.
  • Extensive refactoring occurred across multiple pkg directories, specifically migrating from a monolithic pkg/canton client to a modular pkg/canton-sdk structure.
  • Existing client code in cmd/api-server, cmd/relayer, pkg/apidb, pkg/ethrpc, pkg/registration, pkg/relayer, and pkg/service was updated to integrate with the new SDK.
  • Old Canton client files and their corresponding tests were removed.
  • New packages bridge, client, identity, ledger, token, and values were introduced under pkg/canton-sdk to provide specialized functionalities.
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 significant and valuable refactoring by creating a new canton-sdk package to encapsulate all interactions with the Canton ledger. This is a great improvement for code structure and maintainability. The old pkg/canton is removed, and its functionality is now provided by the new SDK. The changes in cmd/api-server and cmd/relayer correctly adopt this new SDK.

My review focuses on a few critical issues in the configuration and some areas for improvement in the new SDK implementation, including a critical misconfiguration in .golangci.yml that disables linting, a bug in the Makefile that prevents downloading the linter, some brittle error handling, and code duplication.

.golangci.yml Outdated
Comment on lines 143 to 156
paths:
- 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.

critical

The paths in linters.exclusions.paths are not anchored. This will cause golangci-lint to exclude any file path that contains these substrings. For example, a path like my/pkg/internal/stuff.go would be excluded because it contains internal. This effectively disables linting for almost the entire codebase. The comment on line 142 correctly states that these should be anchored. You should anchor all paths to match only the intended directories at the root of the project, for example by prefixing them with ^ (e.g., ^pkg/apidb/).

.golangci.yml Outdated
Comment on lines 180 to 193
paths:
- 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.

critical

Similar to the linters exclusions, the paths in formatters.exclusions.paths are not anchored. This will disable formatting for a large portion of the codebase unintentionally. Please anchor all paths with ^ to ensure they only match directories at the project root.

Comment on lines +31 to +33
if [ ! -f ./bin/golangci-lint ]; then \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v2.9.0; \
fi;
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The version v2.9.0 for golangci-lint is invalid and will cause the get_lint target to fail. The latest version of golangci-lint is v1.59.1. Please use a valid version. Also, the install script is invoked in a way that might not place the binary in ./bin. It's better to explicitly use the -b flag to specify the output directory.

	if [ ! -f ./bin/golangci-lint ]; then \
		curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin v1.59.1; \
	fi;

Comment on lines +382 to +388
if err != nil {
// TODO: Match grpc error code without hard-wiring exact text.
if strings.Contains(strings.ToLower(err.Error()), "already") {
return nil
}
return fmt.Errorf("complete withdrawal: %w", err)
}
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 handling for an already completed withdrawal is brittle as it relies on string matching the error message. This can break if the error message from the upstream service changes. It's better to check for the specific gRPC status code, similar to how isAuthError is implemented. You should check for codes.AlreadyExists. The TODO on line 383 also points this out.

Suggested change
if err != nil {
// TODO: Match grpc error code without hard-wiring exact text.
if strings.Contains(strings.ToLower(err.Error()), "already") {
return nil
}
return fmt.Errorf("complete withdrawal: %w", err)
}
if err != nil {
s, ok := status.FromError(err)
if ok && s.Code() == codes.AlreadyExists {
return nil
}
return fmt.Errorf("complete withdrawal: %w", err)
}

CorePackageID: cfg.CorePackageID,
BridgeModule: cfg.BridgeModule,
CIP56PackageID: cfg.CIP56PackageID,
// TODO: why bridge config needs the common package id
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This TODO indicates a point of confusion in the configuration. It would be beneficial to investigate this and either add a comment explaining the reason or refactor the configuration to make it clearer. Please create a follow-up ticket to track this.

Comment on lines +3 to +4
// Todo: split this into multiple files (source & destination) that will implement source and destination respectively.
// Current name 'handlers' doesn't represent clear context
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This is a good observation. To improve code organization, it would be beneficial to split this file into source.go and destination.go to better separate the concerns of different bridge endpoints. Please create a follow-up ticket to track this refactoring.

Comment on lines +62 to +63
SourceChain: "canton", // todo: use constant
DestinationChain: "ethereum", // todo: use constant
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 constants for chain names like canton and ethereum would improve readability and prevent typos. Please consider defining these as constants in a relevant package.

@@ -1,10 +1,12 @@
package relayer

// TODO: remove the mock impl and use mockery to generate mock
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 a tool like mockery to auto-generate mocks would be more maintainable than manually creating them. Please consider creating a ticket to switch to auto-generated mocks.

Comment on lines +152 to 153
// todo: log error if update fails on db.
p.store.UpdateTransferStatus(event.ID, db.TransferStatusFailed, 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

This todo is important. It's crucial to handle and log errors that might occur when updating the transfer status in the database to avoid silent failures and inconsistent state.

}

// Update status to completed
// todo: handle error
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the failure case, it's important to handle and log any potential errors when updating the transfer status to 'completed' to ensure the database state is consistent.

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] wire SDK, migrate callers, and remove monolithic client

1 participant