bridge

package
v0.5.2 Latest Latest
Warning

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

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

Documentation

Overview

Package bridge implements optional Wayfinder bridge operations for Canton.

It provides deposit/withdrawal flows and bridge-related event queries. The bridge client is optional.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bridge

type Bridge interface {
	// IsDepositProcessed returns true if a deposit with the given EVM tx hash already exists as an active
	// PendingDeposit or DepositReceipt contract.
	IsDepositProcessed(ctx context.Context, evmTxHash string) (bool, error)

	// GetWayfinderBridgeConfigCID returns the active WayfinderBridgeConfig contract id.
	GetWayfinderBridgeConfigCID(ctx context.Context) (string, error)

	// CreatePendingDeposit creates a PendingDeposit on Canton from an EVM deposit event.
	CreatePendingDeposit(ctx context.Context, req CreatePendingDepositRequest) (*PendingDeposit, error)

	// ProcessDepositAndMint processes a PendingDeposit and mints tokens (choice on WayfinderBridgeConfig).
	ProcessDepositAndMint(ctx context.Context, req ProcessDepositRequest) (*ProcessedDeposit, error)

	// InitiateWithdrawal creates a WithdrawalRequest for a user (choice on WayfinderBridgeConfig).
	InitiateWithdrawal(ctx context.Context, req InitiateWithdrawalRequest) (string, error)

	// ProcessWithdrawal exercises the ProcessWithdrawal choice on a WithdrawalRequest contract,
	// burning tokens on Canton and creating a WithdrawalEvent. Returns the WithdrawalEvent CID.
	ProcessWithdrawal(ctx context.Context, withdrawalRequestCID string) (string, error)

	// CompleteWithdrawal marks a WithdrawalEvent as completed after the EVM release is finalized.
	CompleteWithdrawal(ctx context.Context, req CompleteWithdrawalRequest) error

	// StreamWithdrawalEvents streams WithdrawalEvent contracts with automatic reconnection.
	StreamWithdrawalEvents(ctx context.Context, offset string) <-chan *WithdrawalEvent

	// GetLatestLedgerOffset returns the ledger end
	GetLatestLedgerOffset(ctx context.Context) (int64, error)
}

Bridge defines bridge operations.

type Client

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

Client implements bridge operations.

func New

func New(cfg *Config, l ledger.Ledger, i identity.Identity, opts ...Option) (*Client, error)

New creates a new bridge client.

func (*Client) CompleteWithdrawal

func (c *Client) CompleteWithdrawal(ctx context.Context, req CompleteWithdrawalRequest) error

func (*Client) CreatePendingDeposit

func (c *Client) CreatePendingDeposit(ctx context.Context, req CreatePendingDepositRequest) (*PendingDeposit, error)

func (*Client) GetLatestLedgerOffset

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

func (*Client) GetWayfinderBridgeConfigCID

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

func (*Client) InitiateWithdrawal

func (c *Client) InitiateWithdrawal(ctx context.Context, req InitiateWithdrawalRequest) (string, error)

func (*Client) IsDepositProcessed

func (c *Client) IsDepositProcessed(ctx context.Context, evmTxHash string) (bool, error)

func (*Client) ProcessDepositAndMint

func (c *Client) ProcessDepositAndMint(ctx context.Context, req ProcessDepositRequest) (*ProcessedDeposit, error)

func (*Client) ProcessWithdrawal

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

func (*Client) StreamWithdrawalEvents

func (c *Client) StreamWithdrawalEvents(ctx context.Context, offset string) <-chan *WithdrawalEvent

type CompleteWithdrawalRequest

type CompleteWithdrawalRequest struct {
	WithdrawalEventCID string
	EvmTxHash          string
}

CompleteWithdrawalRequest contains inputs to mark a withdrawal as completed.

type Config

type Config struct {
	// DomainID is the Canton synchronizer/domain ID to submit commands against.
	DomainID string `yaml:"domain_id"`
	// UserID is the Canton user id (JWT subject) used for command submission.
	UserID string `yaml:"user_id"`
	// OperatorParty is the party that controls WayfinderBridgeConfig (the bridge operator).
	OperatorParty string `yaml:"operator_party"`
	// PackageID is the package id that contains Wayfinder.Bridge templates/choices.
	PackageID string `yaml:"package_id" validate:"required"`
	// CorePackageID is the package id for Bridge.Contracts (bridge-core package).
	// WithdrawalRequest and WithdrawalEvent live here, separate from PackageID.
	CorePackageID string `yaml:"core_package_id" validate:"required"`
	// Module is the DAML module name that contains WayfinderBridgeConfig template.
	Module string `yaml:"module" validate:"required"`
}

Config contains bridge-client configuration.

type CreatePendingDepositRequest

type CreatePendingDepositRequest struct {
	Fingerprint string
	Amount      string
	EvmTxHash   string
}

CreatePendingDepositRequest contains inputs to create a PendingDeposit from an EVM deposit event.

type InitiateWithdrawalRequest

type InitiateWithdrawalRequest struct {
	MappingCID     string
	HoldingCID     string
	Amount         string
	EvmDestination string
}

InitiateWithdrawalRequest contains inputs to initiate a withdrawal.

type Option

type Option func(*settings)

func WithLogger

func WithLogger(l *zap.Logger) Option

type PendingDeposit

type PendingDeposit struct {
	ContractID  string
	MappingCID  string
	Fingerprint string
	CreatedAt   time.Time
}

PendingDeposit describes a created pending deposit.

type ProcessDepositRequest

type ProcessDepositRequest struct {
	DepositCID string
	MappingCID string
}

ProcessDepositRequest contains inputs to process a PendingDeposit and mint tokens.

type ProcessedDeposit

type ProcessedDeposit struct {
	ContractID string
}

type WithdrawalEvent

type WithdrawalEvent struct {
	ContractID     string
	EventID        string
	TransactionID  string
	Issuer         string
	UserParty      string
	EvmDestination string
	Amount         string
	Fingerprint    string
	Status         WithdrawalStatus
}

WithdrawalEvent represents a withdrawal ready for EVM processing

type WithdrawalRequest

type WithdrawalRequest struct {
	ContractID      string
	Amount          string
	EvmDestination  string
	UserFingerprint string
	CreatedAt       time.Time
}

WithdrawalRequest describes a created withdrawal request.

type WithdrawalStatus

type WithdrawalStatus string

WithdrawalStatus represents the state of a withdrawal

const (
	WithdrawalStatusPending   WithdrawalStatus = "Pending"
	WithdrawalStatusCompleted WithdrawalStatus = "Completed"
	WithdrawalStatusFailed    WithdrawalStatus = "Failed"
)

Jump to

Keyboard shortcuts

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