ledger

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package ledger implements the low-level Canton Ledger API client.

It manages gRPC connectivity, TLS configuration, OAuth2 authentication, and exposes typed access to Ledger API v2 services including State, Command, Update, and Admin services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	ClientID     string `yaml:"client_id" validate:"required"`
	ClientSecret string `yaml:"client_secret" validate:"required"`
	Audience     string `yaml:"audience" validate:"required"`
	TokenURL     string `yaml:"token_url" validate:"required"`

	// ExpiryLeeway specifies how long before actual token expiry
	// the token should be considered expired. If zero, a default is applied.
	ExpiryLeeway time.Duration `yaml:"expiry_leeway" default:"60s"`
}

AuthConfig defines OAuth2 client credentials settings used for authenticating against the Canton participant.

type AuthProvider

type AuthProvider interface {
	// Token returns a valid access token and its expiry time.
	// Implementations must cache and refresh tokens as needed.
	Token(ctx context.Context) (token string, expiry time.Time, err error)
}

AuthProvider defines how the ledger client obtains and refreshes authentication tokens.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the concrete implementation of the Ledger interface.

It encapsulates the gRPC connection, Ledger API service clients, and authentication handling.

func New

func New(cfg *Config, opts ...Option) (*Client, error)

New creates a new Ledger client using the provided configuration.

func (*Client) AuthContext

func (c *Client) AuthContext(ctx context.Context) context.Context

func (*Client) Close

func (c *Client) Close() error

func (*Client) Command

func (c *Client) Command() lapiv2.CommandServiceClient

func (*Client) Conn

func (c *Client) Conn() *grpc.ClientConn

func (*Client) GetActiveContractsByInterface

func (c *Client) GetActiveContractsByInterface(
	ctx context.Context,
	activeAtOffset int64,
	parties []string,
	interfaceID *lapiv2.Identifier,
) ([]*lapiv2.CreatedEvent, error)

func (*Client) GetActiveContractsByTemplate

func (c *Client) GetActiveContractsByTemplate(
	ctx context.Context,
	activeAtOffset int64,
	parties []string,
	templateID *lapiv2.Identifier,
) ([]*lapiv2.CreatedEvent, error)

func (*Client) GetLedgerEnd

func (c *Client) GetLedgerEnd(ctx context.Context) (int64, error)

func (*Client) Interactive

func (*Client) InvalidateToken

func (c *Client) InvalidateToken()

func (*Client) JWTSubject

func (c *Client) JWTSubject(ctx context.Context) (string, error)

func (*Client) PartyAdmin

func (*Client) State

func (c *Client) State() lapiv2.StateServiceClient

func (*Client) Update

func (c *Client) Update() lapiv2.UpdateServiceClient

func (*Client) UserAdmin

type Config

type Config struct {
	RPCURL         string `yaml:"rpc_url" validate:"required"`
	LedgerID       string `yaml:"ledger_id" default:""`
	MaxMessageSize int    `yaml:"max_inbound_message_size" default:"52428800"`

	TLS  *TLSConfig  `yaml:"tls" validate:"required"`
	Auth *AuthConfig `yaml:"auth" validate:"required"`
}

Config contains the configuration required to establish a connection to a Canton participant.

type Ledger

type Ledger interface {
	// AuthContext attaches authorization metadata to the given context.
	AuthContext(ctx context.Context) context.Context

	// InvalidateToken invalidates the token.
	InvalidateToken()

	// JWTSubject returns the JWT subject ("sub") from the current access token.
	JWTSubject(ctx context.Context) (string, error)

	// State returns the Ledger API StateService client.
	State() lapiv2.StateServiceClient

	// Command returns the Ledger API CommandService client.
	Command() lapiv2.CommandServiceClient

	// Update returns the Ledger API UpdateService client.
	Update() lapiv2.UpdateServiceClient

	// PartyAdmin returns the PartyManagementService client.
	PartyAdmin() adminv2.PartyManagementServiceClient

	// UserAdmin returns the UserManagementService client.
	UserAdmin() adminv2.UserManagementServiceClient

	// Interactive returns the InteractiveSubmissionService client
	// for prepare/sign/execute transaction flows with external parties.
	Interactive() interactivev2.InteractiveSubmissionServiceClient

	// GetLedgerEnd retrieves the current absolute ledger offset.
	GetLedgerEnd(ctx context.Context) (int64, error)

	// GetActiveContractsByTemplate retrieves active contracts filtered
	// by template identifier and visible parties at the given offset.
	GetActiveContractsByTemplate(
		ctx context.Context,
		activeAtOffset int64,
		parties []string,
		templateID *lapiv2.Identifier,
	) ([]*lapiv2.CreatedEvent, error)

	// GetActiveContractsByInterface retrieves active contracts filtered
	// by interface identifier and visible parties at the given offset.
	GetActiveContractsByInterface(
		ctx context.Context,
		activeAtOffset int64,
		parties []string,
		interfaceID *lapiv2.Identifier,
	) ([]*lapiv2.CreatedEvent, error)

	// Conn returns the underlying gRPC client connection.
	Conn() *grpc.ClientConn

	// Close closes the underlying gRPC connection.
	Close() error
}

Ledger defines the public Canton ledger client interface.

It provides authenticated access to Ledger API services and common helper operations such as querying the ledger end and retrieving active contracts by template.

type OAuthClientCredentialsProvider

type OAuthClientCredentialsProvider struct {
	// contains filtered or unexported fields
}

OAuthClientCredentialsProvider implements AuthProvider using the OAuth2 client credentials flow.

func NewOAuthClientCredentialsProvider

func NewOAuthClientCredentialsProvider(cfg *AuthConfig, httpClient *http.Client) *OAuthClientCredentialsProvider

NewOAuthClientCredentialsProvider creates a new OAuthClientCredentialsProvider instance.

func (*OAuthClientCredentialsProvider) Token

type Option

type Option func(*settings)

Option configures ledger client settings using the functional options pattern.

func WithAuthProvider

func WithAuthProvider(p AuthProvider) Option

WithAuthProvider overrides the default authentication provider.

func WithGRPCDialOptions

func WithGRPCDialOptions(opts ...grpc.DialOption) Option

WithGRPCDialOptions appends additional gRPC dial options.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets a custom HTTP client for authentication requests.

func WithLogger

func WithLogger(l *zap.Logger) Option

WithLogger sets a custom logger for the ledger client.

type TLSConfig

type TLSConfig struct {
	Enabled            bool   `yaml:"enabled" default:"false"`
	CertFile           string `yaml:"cert_file" default:""`
	KeyFile            string `yaml:"key_file" default:""`
	CAFile             string `yaml:"ca_file" default:""`
	InsecureSkipVerify bool   `yaml:"insecure_skip_verify" default:"false"`
}

TLSConfig defines transport security settings for the gRPC connection.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL