bridge

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 9 Imported by: 0

README

Bridge Structure:

Manages connections to multiple blockchain networks Handles pending and completed transactions Integrates with the validator set Includes state management for cross-chain synchronization

Transaction Processing:

Verifies transaction validity and signatures Monitors source chain confirmations Processes transactions on destination chains Implements atomic operations with rollback capabilities

Security Features:

Validator signature verification Required confirmation thresholds Transaction timeout handling Asset locking mechanisms

State Management:

Tracks connection status for each chain Maintains transaction status history Handles async processing with proper error handling

Documentation

Overview

Package bridge implements asset management for the ATLYS protocol

Package bridge implements the cross-chain communication protocol for ATLYS

Package bridge implements state management for the ATLYS protocol

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	Symbol          string
	Name            string
	Decimals        uint8
	TotalSupply     uint64
	NativeChain     string
	SupportedChains map[string]*AssetInfo
	LastUpdate      time.Time
}

Asset represents a registered asset across chains

type AssetConfig

type AssetConfig struct {
	LockTimeout        time.Duration
	MinLockAmount      uint64
	MaxLockAmount      uint64
	RateUpdateInterval time.Duration
}

AssetConfig contains configuration parameters for asset management

type AssetInfo

type AssetInfo struct {
	ContractAddress string
	TotalLocked     uint64
	TotalMinted     uint64
	LastHeight      uint64
}

AssetInfo contains chain-specific asset information

type AssetManager

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

AssetManager handles cross-chain asset transfers and management

func NewAssetManager

func NewAssetManager(config *AssetConfig) *AssetManager

NewAssetManager creates a new instance of AssetManager

func (*AssetManager) CleanExpiredLocks

func (am *AssetManager) CleanExpiredLocks()

CleanExpiredLocks removes expired locked assets

func (*AssetManager) GetAssetInfo

func (am *AssetManager) GetAssetInfo(symbol string) (*Asset, error)

GetAssetInfo returns information about a registered asset

func (*AssetManager) GetExchangeRate

func (am *AssetManager) GetExchangeRate(sourceChain string, baseAsset string, quoteAsset string) (uint64, error)

GetExchangeRate returns the current exchange rate for an asset pair

func (*AssetManager) GetLockedAssets

func (am *AssetManager) GetLockedAssets(txHash types.Hash) (*LockedAsset, error)

GetLockedAssets returns information about locked assets

func (*AssetManager) LockAssets

func (am *AssetManager) LockAssets(ctx context.Context, tx *types.Transaction) (*LockedAsset, error)

LockAssets locks assets for cross-chain transfer

func (*AssetManager) RegisterAsset

func (am *AssetManager) RegisterAsset(asset *Asset) error

RegisterAsset adds a new asset to the registry

func (*AssetManager) RegisterAssetPair

func (am *AssetManager) RegisterAssetPair(pair *AssetPair) error

RegisterAssetPair creates a new cross-chain asset pair

func (*AssetManager) ReleaseAssets

func (am *AssetManager) ReleaseAssets(txHash types.Hash) error

ReleaseAssets releases locked assets

func (*AssetManager) TransferAssets

func (am *AssetManager) TransferAssets(ctx context.Context, txHash types.Hash) error

TransferAssets completes a cross-chain asset transfer

func (*AssetManager) UpdateExchangeRate

func (am *AssetManager) UpdateExchangeRate(sourceChain string, baseAsset string, quoteAsset string, newRate uint64) error

UpdateExchangeRate updates the exchange rate for an asset pair

type AssetPair

type AssetPair struct {
	BaseAsset    string
	QuoteAsset   string
	SourceChain  string
	DestChain    string
	ExchangeRate uint64 // Base rate multiplied by 10^8
	UpdateTime   time.Time
}

AssetPair represents a cross-chain asset pair configuration

type Bridge

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

Bridge manages cross-chain communication and transaction processing

func NewBridge

func NewBridge(vs *consensus.ValidatorSet, config *BridgeConfig) *Bridge

NewBridge creates a new instance of the ATLYS bridge

func (*Bridge) GetTransactionStatus

func (b *Bridge) GetTransactionStatus(txHash types.Hash) (*TransactionStatus, error)

GetTransactionStatus returns the current status of a transaction

func (*Bridge) ProcessCrossChainTx

func (b *Bridge) ProcessCrossChainTx(ctx context.Context, tx *types.Transaction) error

ProcessCrossChainTx handles cross-chain transaction processing

func (*Bridge) RegisterChain

func (b *Bridge) RegisterChain(chainID string, client interface{}) error

RegisterChain adds a new blockchain to the bridge

type BridgeConfig

type BridgeConfig struct {
	RequiredConfirmations uint64
	MaxPendingTx          uint64
	BlockTimeout          time.Duration
	ValidatorQuorum       float64
}

BridgeConfig contains configuration parameters for the bridge

type ChainConnection

type ChainConnection struct {
	ChainID        string
	LastBlock      uint64
	LastUpdateTime time.Time
	Status         ConnectionStatus
	Client         interface{} // Chain-specific client interface
}

ChainConnection represents a connection to a specific blockchain

type ChainState

type ChainState struct {
	ChainID           string
	LastHeight        uint64
	LastStateRoot     types.Hash
	LastUpdateTime    time.Time
	PendingUpdates    map[uint64]*StateUpdate
	CrossChainAnchors map[string]uint64 // Maps chain ID to last anchored height
}

ChainState represents the current state of a blockchain

type ConnectionStatus

type ConnectionStatus int

ConnectionStatus represents the current state of a chain connection

const (
	StatusDisconnected ConnectionStatus = iota
	StatusConnecting
	StatusActive
	StatusError
)

type LockStatus

type LockStatus int

LockStatus represents the current status of locked assets

const (
	StatusLocked LockStatus = iota
	StatusReleased
	StatusTransferred
	StatusExpired
)

type LockedAsset

type LockedAsset struct {
	TxHash         types.Hash
	SourceChain    string
	DestChain      string
	Asset          string
	Amount         uint64
	Owner          types.Address
	LockTime       time.Time
	ExpirationTime time.Time
	Status         LockStatus
}

LockedAsset represents assets locked for cross-chain transfer

type StateConfig

type StateConfig struct {
	UpdateInterval    time.Duration
	MaxPendingUpdates uint64
	ProofExpiration   time.Duration
	MinValidators     uint64
}

StateConfig contains configuration parameters for state management

type StateManager

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

StateManager handles cross-chain state synchronization and verification

func NewStateManager

func NewStateManager(config *StateConfig) *StateManager

NewStateManager creates a new instance of StateManager

func (*StateManager) GenerateStateProof

func (sm *StateManager) GenerateStateProof(sourceChain, destChain string, height uint64) (*StateProof, error)

GenerateStateProof creates a proof for cross-chain verification

func (*StateManager) GetChainState

func (sm *StateManager) GetChainState(chainID string) (*ChainState, error)

GetChainState returns the current state of a chain

func (*StateManager) GetLastAnchoredHeight

func (sm *StateManager) GetLastAnchoredHeight(sourceChain, targetChain string) (uint64, error)

GetLastAnchoredHeight returns the last anchored height between two chains

func (*StateManager) RegisterChain

func (sm *StateManager) RegisterChain(chainID string) error

RegisterChain initializes state tracking for a new chain

func (*StateManager) UpdateChainState

func (sm *StateManager) UpdateChainState(chainID string, height uint64, stateRoot types.Hash, validators []types.ValidatorAddress) error

UpdateChainState processes a new state update from a chain

func (*StateManager) UpdateCrossChainAnchor

func (sm *StateManager) UpdateCrossChainAnchor(sourceChain, targetChain string, height uint64) error

UpdateCrossChainAnchor updates the last anchored height for cross-chain references

func (*StateManager) ValidateStateUpdate

func (sm *StateManager) ValidateStateUpdate(chainID string, height uint64, signature []byte, validator types.ValidatorAddress) error

ValidateStateUpdate verifies a state update with validator signatures

func (*StateManager) VerifyStateProof

func (sm *StateManager) VerifyStateProof(proof *StateProof) error

VerifyStateProof verifies a cross-chain state proof

type StateProof

type StateProof struct {
	SourceChain      string
	DestinationChain string
	Height           uint64
	StateRoot        types.Hash
	ProofData        []byte
	Timestamp        time.Time
	ValidatorSigs    map[types.ValidatorAddress][]byte
}

StateProof contains proof data for cross-chain verification

type StateUpdate

type StateUpdate struct {
	Height     uint64
	StateRoot  types.Hash
	Timestamp  time.Time
	Validators []types.ValidatorAddress
	Signatures map[types.ValidatorAddress][]byte
}

StateUpdate represents a pending state update

type TransactionStatus

type TransactionStatus struct {
	SourceConfirmations      uint64
	DestinationConfirmations uint64
	Status                   string
	LastUpdateTime           time.Time
	Error                    error
}

TransactionStatus tracks the state of cross-chain transactions

Jump to

Keyboard shortcuts

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