api

package
v0.11.0-rc8 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0, MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TrackerV1Prefix is the url prefix for the bridge tracker service
	TrackerV1Prefix = "/tracker/v1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

API is the HTTP service of the bridge tracker: the REST and WebSocket endpoints served on the shared HTTP server. Each endpoint's business logic is built once, at construction time, into its own command/handler object below — the API struct only wires routes to them, it does not hold the supervised registry, logger or instance identity itself.

func NewAPI

func NewAPI(
	logger aggkitcommon.Logger,
	configSHA1 string,
	supervised domain.SupervisedRegistry,
	activity domain.ActivityQuerier,
	bridgeAddressResolver domain.BridgeAddressResolver,
	registerResolveTimeout time.Duration,
	cors aggkitcommon.CORSConfig,
) *API

NewAPI returns the tracker HTTP service serving the given supervised registry. registerResolveTimeout is how long GetTxStatus waits, the first time a tx is registered, for the tracking engine's immediate resolution attempt to produce an update before answering (see getTxStatusCommand); <= 0 disables the wait. cors governs which origins may open the WebSocket endpoint (see wsHandler). activity may be nil, in which case the GET /activity/from/{from_address} endpoint is not registered at all (see RegisterRoutes). bridgeAddressResolver may be nil, in which case neither GET /bridge-address nor GET /bridge-address/{network_id} is registered at all (see RegisterRoutes)

func (*API) RegisterRoutes

func (a *API) RegisterRoutes(router gin.IRouter)

RegisterRoutes registers all bridge tracker routes on router. Route-level documentation (see swagger.json/swagger.yaml, generated via `make generate-swagger-docs`) lives on the actual handler each route dispatches to: getTxStatusCommand.Execute, healthCommand.Execute and wsHandler.TxStatusWSHandler

type ActivityItem

type ActivityItem struct {
	// Bridge is the raw bridge event, exactly as returned by the origin network's bridge
	// service, unmodified
	Bridge *bridgeservicetypes.BridgeResponse `json:"bridge"`
	// BridgeNetworkID is the network whose bridge service reported Bridge — not necessarily
	// Bridge.OriginNetwork, which is the origin network of the bridged asset and can differ for
	// a re-bridged asset (see domain.ScannedBridge)
	BridgeNetworkID uint32 `json:"bridge_network_id"`
	// Claimed is the tri-state result of the destination bridge contract's isClaimed() call
	// the last time it was checked: "false" (confirmed unclaimed), "true" (claimed), or
	// "error" if the check itself failed (e.g. no bridge contract address configured for the
	// destination network) — callers must not read "error" as "false"
	Claimed string `json:"claimed"`
	// ClaimNetworkID is the network whose bridge service reported Claim (the bridge's
	// destination network); only present alongside Claim
	ClaimNetworkID uint32 `json:"claim_network_id,omitempty"`
	// Claim is the raw claim record, exactly as returned by the destination network's bridge
	// service, unmodified, once Claimed is true and the indexer has recorded it
	Claim *bridgeservicetypes.ClaimResponse `json:"claim,omitempty"`
	// CreationTimestamp is when this bridge was first cached by the activity endpoint (unix
	// seconds); it never changes after that
	CreationTimestamp uint64 `json:"creation_timestamp"`
	// LastUpdatedTimestamp is when this item's claim/tracking state was last (re)checked (unix
	// seconds), whether or not anything about it actually changed. Stops advancing once the
	// bridge is claimed with its claim record fetched — nothing left to recheck
	LastUpdatedTimestamp uint64 `json:"last_updated_timestamp"`
	// Tracking is the bridge tracker's current status for this bridge; only present when the
	// request set includeTracking=true and the bridge is still unclaimed
	Tracking *TrackingData `json:"tracking,omitempty"`
	// Errors holds the message of whatever check failed the last time this item was refreshed,
	// keyed by which check it was — currently only "claim", present when Claimed is "error"
	Errors map[string]string `json:"errors,omitempty"`
}

ActivityItem is one bridge found for the requested from_address. Bridge and Claim are the bridge service's own response shapes (see bridgeservice/types), reported exactly as-is rather than remapped into a bespoke model; BridgeNetworkID/ClaimNetworkID sit alongside them (not inside) since the caller needs to know which bridge service produced each one

type ActivityResponse

type ActivityResponse struct {
	// FromAddress is the address requested
	FromAddress common.Address `json:"from_address"`
	// Bridges holds every bridge found for FromAddress across every configured bridge service
	Bridges []ActivityItem `json:"bridges"`
	// Warnings lists every network whose bridge service could not be scanned this call; absent
	// when every configured network was scanned successfully. Bridges may be incomplete for the
	// networks listed here, but is still valid for every other network
	Warnings []ActivityWarningItem `json:"warnings,omitempty"`
}

ActivityResponse is the body of GET /activity/from/{from_address}

type ActivityWarningItem

type ActivityWarningItem struct {
	// NetworkID is the network whose bridge service could not be scanned
	NetworkID uint32 `json:"network_id"`
	// Message is the error encountered while scanning NetworkID
	Message string `json:"message"`
}

ActivityWarningItem reports one network's bridge service that could not be scanned while building this response — Bridges is still whatever every other network reported, just possibly incomplete for the networks listed here

type BridgeAddressItem

type BridgeAddressItem struct {
	// NetworkID is the network BridgeAddress belongs to
	NetworkID uint32 `json:"network_id"`
	// BridgeAddress is the bridge contract address on NetworkID
	BridgeAddress common.Address `json:"bridge_address"`
}

BridgeAddressItem is the bridge contract address of one network

type BridgeAddressResponse

type BridgeAddressResponse struct {
	// Bridges holds the bridge contract address of every network currently known
	Bridges []BridgeAddressItem `json:"bridges"`
}

BridgeAddressResponse is the body of GET /bridge-address

type BridgeEventData

type BridgeEventData struct {
	// LeafType is the string representation of the kind of leaf the bridge created (asset or message)
	LeafType string `json:"leaf_type"`
	// OriginNetwork is the network where the bridged asset originates from
	OriginNetwork uint32 `json:"origin_network"`
	// OriginAddress is the address of the asset on the origin network
	OriginAddress common.Address `json:"origin_address"`
	// DestinationNetwork is the network the bridge exits to (0 -> Mainnet)
	DestinationNetwork uint32 `json:"destination_network"`
	// DestinationAddress is the address that receives the asset on the destination network
	DestinationAddress common.Address `json:"destination_address"`
	// Amount is the amount of the asset being bridged, as a decimal string — a plain JSON
	// number would risk losing precision on wei-scale amounts in clients that decode numbers
	// as float64 (e.g. JavaScript)
	Amount string `json:"amount"`
	// DepositCount is the index of the bridge leaf in the origin exit tree
	DepositCount uint32 `json:"deposit_count"`
}

BridgeEventData holds the fields taken directly from the on-chain BridgeEvent log, as opposed to context resolved around it (block number/index/timestamp, tracking network) — see BridgeStatus

type BridgeStatus

type BridgeStatus struct {
	// BridgeType is the string representation of the bridge's direction (e.g. "L1->L2")
	BridgeType string `json:"bridge_type"`
	// BlockNumber is the block, on the origin network, where the BridgeEvent was emitted
	BlockNumber uint64 `json:"block_number"`
	// LogIndex is the position of the BridgeEvent log within BlockNumber
	LogIndex uint32 `json:"log_index"`
	// BlockTimestamp is the timestamp of the block, on the origin network, where the BridgeEvent was emitted
	BlockTimestamp uint64 `json:"block_timestamp"`
	// Event holds the facts unpacked directly from the on-chain BridgeEvent log
	Event BridgeEventData `json:"event"`
}

BridgeStatus is part of the response of GET /tracker/v1/tx/{txHash} (see TrackingData), identifying the bridge that TrackingData.AllSteps describes

type BridgeStepPath

type BridgeStepPath struct {
	// StepIndex is this step's position within the parent TrackingData.AllSteps list
	StepIndex int `json:"step_index"`
	// StepName is the string representation of the bridge step (e.g. "PendingInclusion")
	StepName string `json:"step_name"`
	// Status is the string representation of the step's status (e.g. "done")
	Status           string          `json:"status"`
	StartDate        *time.Time      `json:"start_date,omitempty"`
	EndDate          *time.Time      `json:"end_date,omitempty"`
	ExpectedDuration *types.Duration `json:"expected_duration,omitempty"`
	// Result is the data the step has produced so far; its shape depends on Step:
	// *types.GERUpdateResult (StepWaitingGERUpdate), *types.InjectedGERResult
	// (StepWaitingGERInjection), *types.LERUpdateResult (StepWaitingLERUpdate),
	// *types.PendingInclusionResult (StepPendingInclusion), *types.CertificateData
	// (StepCertificatePending), *types.L1SettledGERResult (StepWaitL1SettledGER) or
	// *types.ClaimResult (StepClaimed). nil until
	// the step produces one, and for steps that never do. Most steps only set this once Done,
	// but StepCertificatePending (Status still InProgress) may already carry the certificate's
	// current, not yet settled, status — see domain.ErrCertificateNotSettled
	Result any `json:"result,omitempty"`
	// Error carries the error details when Status is types.StepStatusError, nil otherwise
	Error *types.ErrorStep `json:"error,omitempty"`
}

BridgeStepPath describes one step of the expected path of a bridge, as returned by the API

type TrackingData

type TrackingData struct {
	// TrackingStatus is the string representation of the bridge's lifecycle status
	TrackingStatus string `json:"tracking_status"`
	// NetworkID is the network of the request (0 -> Mainnet)
	NetworkID uint32 `json:"network_id"`
	// TxHash is the transaction hash of the request
	TxHash common.Hash `json:"tx_hash"`
	// BridgeStatus is nil until the tracker resolves the bridge; from then on it carries
	// the full BridgeStatus. Marshaled explicitly as null while unresolved (no omitempty)
	// so clients can poll on its presence without an extra field to check
	BridgeStatus *BridgeStatus `json:"bridge_status"`
	// StepIndex is the index into AllSteps of the step that explains TrackingStatus: the
	// step currently in progress when Running, the step in error when Error, or the last
	// step (Claimed) when Finished. nil while BridgeStatus/AllSteps are nil
	StepIndex *int `json:"step_index"`
	// AllSteps holds all expected steps of the bridge's route; GER/LER, certificate and
	// claim data are reported per step in each entry's Result. nil while BridgeStatus is nil
	AllSteps []BridgeStepPath `json:"all_steps"`
	// Error mirrors whatever currently explains the bridge not progressing, if anything: a
	// terminal give-up to even resolve it (e.g. the tx does not exist on the network or is
	// not a bridge transaction — TrackingStatus is Error and BridgeStatus/StepIndex/AllSteps
	// stay nil forever), a transient FindBridge failure still being retried (TrackingStatus
	// is unaffected), or the same error already nested in AllSteps[StepIndex].Error once the
	// bridge is otherwise resolved. nil while nothing has failed
	Error *types.ErrorStep `json:"error"`
}

TrackingData is the body of every GET /tracker/v1/network/{network_id}/tx/{tx_hash} response (always 200 OK) and of every WebSocket "status" message: TrackingStatus carries the bridge's full lifecycle, and BridgeStatus carries the detail behind it once resolved

Directories

Path Synopsis
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.

Jump to

Keyboard shortcuts

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