Help us shape the future of Go! Take the 2026 Go Developer Survey

client

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0, MIT Imports: 14 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// DefaultTimeout is the default HTTP client timeout
	DefaultTimeout = 30 * time.Second
)

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a resource is not found (HTTP 404)

Functions

This section is empty.

Types

type Client

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

Client is a client for the bridgeservice REST API

func New

func New(cfg Config) *Client

New creates a new bridgeservice client

Example
package main

import (
	"fmt"
	"time"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	// Create a client with default timeout (30 seconds)
	_ = client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	fmt.Printf("Client created with base URL: %s\n", "http://localhost:8080")

	// Create a client with custom timeout
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
		Timeout: 10 * time.Second,
	})

	_ = c
}

func (*Client) GetBridgeByDepositCount

func (c *Client) GetBridgeByDepositCount(
	ctx context.Context, networkID uint32, depositCount uint32,
) (*types.BridgeResponse, error)

GetBridgeByDepositCount retrieves the bridge for the given network and deposit count. Returns ErrNotFound if the bridge does not exist in bridge or bridge_archive.

func (*Client) GetBridges

func (c *Client) GetBridges(ctx context.Context, params GetBridgesParams) (*types.BridgesResult, error)

GetBridges retrieves paginated bridge events

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	// Minimal parameters
	resp, err := c.GetBridges(context.Background(), client.GetBridgesParams{
		NetworkID: 1,
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Total bridges: %d\n", resp.Count)

	// With optional parameters
	pageNum := uint32(1)
	pageSize := uint32(20)
	depositCount := uint64(10)
	fromAddr := "0x1234567890123456789012345678901234567890"

	resp, err = c.GetBridges(context.Background(), client.GetBridgesParams{
		NetworkID:    1,
		PageNumber:   &pageNum,
		PageSize:     &pageSize,
		DepositCount: &depositCount,
		FromAddress:  &fromAddr,
		NetworkIDs:   []uint32{2, 3},
	})
	if err != nil {
		log.Fatal(err)
	}

	for _, bridge := range resp.Bridges {
		fmt.Printf("Bridge at block %d\n", bridge.BlockNum)
	}
}

func (*Client) GetBridgesByContent

func (c *Client) GetBridgesByContent(
	ctx context.Context, params GetBridgesByContentParams,
) (*types.BridgesByContentResult, error)

GetBridgesByContent retrieves bridges matching the given content fields for the specified network.

func (*Client) GetClaimProof

func (c *Client) GetClaimProof(
	ctx context.Context, networkID, leafIndex, depositCount uint32,
) (*types.ClaimProof, error)

GetClaimProof retrieves Merkle proofs for claim verification

Uses doRequestAllowNotFound: when the underlying syncers have not yet indexed the data needed to build the proof, the endpoint returns HTTP 404, surfaced here as ErrNotFound so callers can treat it as "retry later" rather than a hard error.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	proof, err := c.GetClaimProof(context.Background(), 1, 10, 5)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Claim proof retrieved for L1 Info Tree Index: %d\n", proof.L1InfoTreeLeaf.L1InfoTreeIndex)
}

func (*Client) GetClaims

func (c *Client) GetClaims(ctx context.Context, params GetClaimsParams) (*types.ClaimsResult, error)

GetClaims retrieves paginated claims

Example
package main

import (
	"context"
	"fmt"
	"log"
	"math/big"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	includeAll := true
	globalIndex := big.NewInt(123)

	resp, err := c.GetClaims(context.Background(), client.GetClaimsParams{
		NetworkID:        1,
		IncludeAllFields: &includeAll,
		GlobalIndex:      globalIndex,
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Total claims: %d\n", resp.Count)
}

func (*Client) GetClaimsByGER

func (c *Client) GetClaimsByGER(ctx context.Context, networkID uint32, ger string) (*types.ClaimsByGERResult, error)

GetClaimsByGER retrieves all claims matching the given global exit root (0x-prefixed hex hash) for the specified network (0 for L1, L2 network ID otherwise).

func (*Client) GetInjectedL1InfoLeaf

func (c *Client) GetInjectedL1InfoLeaf(
	ctx context.Context, networkID, leafIndex int,
) (*types.L1InfoTreeLeafResponse, error)

GetInjectedL1InfoLeaf retrieves an injected L1 info tree leaf.

Uses doRequestAllowNotFound: when the destination network has not yet injected a global exit root covering the requested leaf index, the endpoint returns HTTP 404, surfaced here as ErrNotFound so callers can treat it as "retry later" rather than a hard error.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	resp, err := c.GetInjectedL1InfoLeaf(context.Background(), 2, 5)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("L1 Info Tree Index: %d, Block: %d\n", resp.L1InfoTreeIndex, resp.BlockNumber)
}

func (*Client) GetL1InfoTreeIndex

func (c *Client) GetL1InfoTreeIndex(ctx context.Context, networkID, depositCount int) (uint32, error)

GetL1InfoTreeIndex retrieves the L1 Info Tree index for a bridge

Uses doRequestAllowNotFound: when the deposit has not yet been indexed by the relevant syncers, the endpoint returns HTTP 404, surfaced here as ErrNotFound so callers can treat it as "retry later" rather than a hard error.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	index, err := c.GetL1InfoTreeIndex(context.Background(), 1, 10)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("L1 Info Tree Index: %d\n", index)
}

func (*Client) GetL1InfoTreeLeafByGER added in v0.11.0

func (c *Client) GetL1InfoTreeLeafByGER(ctx context.Context, ger string) (*types.L1InfoTreeLeafResponse, error)

GetL1InfoTreeLeafByGER retrieves the L1 info tree leaf for the given Global Exit Root. The L1 info tree only exists on L1, so this must always be called against the L1 bridge service (networkID 0).

Uses doRequestAllowNotFound: a GER not yet part of the L1 info tree (e.g. still propagating) answers HTTP 404, surfaced here as ErrNotFound so callers can treat it as "retry later".

func (*Client) GetLastReorgEvent

func (c *Client) GetLastReorgEvent(ctx context.Context, networkID int) (*bridgesync.LastReorg, error)

GetLastReorgEvent retrieves the last reorganization event

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	// For L1 (networkID = 0)
	resp, err := c.GetLastReorgEvent(context.Background(), 0)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Last reorg from block %d to block %d\n", resp.FromBlock, resp.ToBlock)
}

func (*Client) GetLegacyTokenMigrations

func (c *Client) GetLegacyTokenMigrations(
	ctx context.Context, params GetLegacyTokenMigrationsParams,
) (*types.LegacyTokenMigrationsResult, error)

GetLegacyTokenMigrations retrieves legacy token migrations

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	resp, err := c.GetLegacyTokenMigrations(context.Background(), client.GetLegacyTokenMigrationsParams{
		NetworkID: 2,
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Total legacy token migrations: %d\n", resp.Count)
}

func (*Client) GetRemoveGEREvents

func (c *Client) GetRemoveGEREvents(
	ctx context.Context, params GetRemoveGEREventsParams,
) (*types.RemoveGEREventsResult, error)

GetRemoveGEREvents retrieves removed GER (Global Exit Root) events

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	ger := "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
	limit := 25

	resp, err := c.GetRemoveGEREvents(context.Background(), client.GetRemoveGEREventsParams{
		GlobalExitRoot: &ger,
		Limit:          &limit,
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Total remove GER events: %d\n", resp.Count)
}

func (*Client) GetRootByLER added in v0.11.0

func (c *Client) GetRootByLER(ctx context.Context, networkID uint32, ler string) (*types.RootByLERResponse, error)

GetRootByLER resolves ler to the position (deposit-count index) it had in networkID's local exit tree when it was computed, letting a caller order two LERs (or compare a known deposit count against one) without walking or syncing the whole tree itself.

Uses doRequestAllowNotFound: an unresolved ler (not synced yet by networkID's bridge service) results in ErrNotFound, which callers should treat as "retry later" rather than a hard error.

func (*Client) GetSetClaims

func (c *Client) GetSetClaims(ctx context.Context, params GetSetClaimsParams) (*types.SetClaimsResult, error)

GetSetClaims retrieves set claims (L2 only)

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	pageNum := 1
	pageSize := 10

	resp, err := c.GetSetClaims(context.Background(), client.GetSetClaimsParams{
		PageNumber: &pageNum,
		PageSize:   &pageSize,
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Total set claims: %d\n", resp.Count)
}

func (*Client) GetSettlements added in v0.11.0

func (c *Client) GetSettlements(ctx context.Context, params GetSettlementsParams) (*types.SettlementsResult, error)

GetSettlements retrieves a paginated list of the L1 events that settled a new local exit root for the network this bridge-service instance is bound to (see issue #1817), most recent first.

Uses doRequestAllowNotFound: an older bridge-service instance that predates this endpoint answers HTTP 404 (no such route), surfaced here as ErrNotFound so callers can fall back to reading the same history straight off L1 instead (see bridgetracker/sources.CertificateSource. EarliestSettlementTxCovering).

func (*Client) GetSyncStatus

func (c *Client) GetSyncStatus(ctx context.Context) (*types.SyncStatus, error)

GetSyncStatus retrieves the bridge synchronization status

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	resp, err := c.GetSyncStatus(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("L1 Synced: %v, L2 Synced: %v, L2GERSync active: %v\n",
		resp.L1Info.IsSynced, resp.L2Info.IsSynced, resp.L2GERInfo.IsActive)
}

func (*Client) GetTokenMappings

func (c *Client) GetTokenMappings(
	ctx context.Context, params GetTokenMappingsParams,
) (*types.TokenMappingsResult, error)

GetTokenMappings retrieves token mappings

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	tokenAddr := "0xabcdef0123456789abcdef0123456789abcdef01"

	resp, err := c.GetTokenMappings(context.Background(), client.GetTokenMappingsParams{
		NetworkID:          1,
		OriginTokenAddress: &tokenAddr,
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Total token mappings: %d\n", resp.Count)
}

func (*Client) GetUnsetClaims

func (c *Client) GetUnsetClaims(ctx context.Context, params GetUnsetClaimsParams) (*types.UnsetClaimsResult, error)

GetUnsetClaims retrieves unset claims (L2 only)

Example
package main

import (
	"context"
	"fmt"
	"log"
	"math/big"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	pageNum := 1
	pageSize := 10
	globalIndex := big.NewInt(456)

	resp, err := c.GetUnsetClaims(context.Background(), client.GetUnsetClaimsParams{
		PageNumber:  &pageNum,
		PageSize:    &pageSize,
		GlobalIndex: globalIndex,
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Total unset claims: %d\n", resp.Count)
}

func (*Client) HealthCheck

func (c *Client) HealthCheck(ctx context.Context) (*types.HealthCheckResponse, error)

HealthCheck performs a health check

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/agglayer/aggkit/bridgeservice/client"
)

func main() {
	c := client.New(client.Config{
		BaseURL: "http://localhost:8080",
	})

	resp, err := c.HealthCheck(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Status: %s\n", resp.Status)
}

type Config

type Config struct {
	BaseURL string
	Timeout time.Duration
}

Config contains configuration for the client

type GetBridgesByContentParams

type GetBridgesByContentParams struct {
	NetworkID          uint32
	LeafType           uint8
	OriginAddress      string
	DestinationNetwork uint32
	DestinationAddress string
	Amount             *big.Int
	Metadata           []byte
}

GetBridgesByContentParams holds the content fields for GetBridgesByContent

type GetBridgesParams

type GetBridgesParams struct {
	NetworkID    uint32
	PageNumber   *uint32
	PageSize     *uint32
	DepositCount *uint64
	FromAddress  *string
	NetworkIDs   []uint32
}

GetBridgesParams contains parameters for GetBridges

type GetClaimsParams

type GetClaimsParams struct {
	NetworkID        uint32
	PageNumber       *uint32
	PageSize         *uint32
	NetworkIDs       []uint32
	IncludeAllFields *bool
	GlobalIndex      *big.Int
}

GetClaimsParams contains parameters for GetClaims

type GetLegacyTokenMigrationsParams

type GetLegacyTokenMigrationsParams struct {
	NetworkID  int
	PageNumber *int
	PageSize   *int
}

GetLegacyTokenMigrationsParams contains parameters for GetLegacyTokenMigrations

type GetRemoveGEREventsParams

type GetRemoveGEREventsParams struct {
	GlobalExitRoot *string
	Limit          *int
}

GetRemoveGEREventsParams contains parameters for GetRemoveGEREvents

type GetSetClaimsParams

type GetSetClaimsParams struct {
	PageNumber  *int
	PageSize    *int
	GlobalIndex *big.Int
}

GetSetClaimsParams contains parameters for GetSetClaims

type GetSettlementsParams added in v0.11.0

type GetSettlementsParams struct {
	PageNumber *uint32
	PageSize   *uint32
}

GetSettlementsParams contains parameters for GetSettlements

type GetTokenMappingsParams

type GetTokenMappingsParams struct {
	NetworkID          int
	PageNumber         *int
	PageSize           *int
	OriginTokenAddress *string
}

GetTokenMappingsParams contains parameters for GetTokenMappings

type GetUnsetClaimsParams

type GetUnsetClaimsParams struct {
	PageNumber  *int
	PageSize    *int
	GlobalIndex *big.Int
}

GetUnsetClaimsParams contains parameters for GetUnsetClaims

Jump to

Keyboard shortcuts

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