{"modulePath":"github.com/pushchain/push-chain-node","version":"v0.0.49","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package common\n\n## Constants\n\n```go\nconst (\n\tDefaultFastConfirmations     uint64 = 5\n\tDefaultStandardConfirmations uint64 = 12\n)\n```\nSafe fallback confirmation depths used when the registry configures 0 and instant routes are not enabled.\n\n## Functions\n\n```go\nfunc ConfirmationDepth(latestHeight, txHeight uint64) (depth uint64, ok bool)\n```\nConfirmationDepth returns latestHeight - txHeight + 1, the confirmation count with the inclusion block counted as one. ok is false when latestHeight \\\u003c txHeight (a cross-RPC height skew); callers must defer rather than trust the depth, since the unchecked subtraction would underflow.\n\n```go\nfunc EncodeUint256Result(v *big.Int) ([]byte, error)\n```\nEncodeUint256Result canonically encodes a balance/amount as abi.encode(uint256) so read results are byte-identical across validators and decodable by the requesting contract. The bounds check guards against a malicious RPC value that would not fit (FillBytes panics on overflow).\n\n```go\nfunc NewReadErrorResult(code ucallbacktypes.ReadErrorCode) *ucallbacktypes.ReadResult\n```\nNewReadErrorResult builds an ERROR observation carrying a deterministic error code. ResultData stays empty and only the code (never local error text) is voted, so every validator observing the same failure converges on one ballot.\n\n## Types\n\n```go\ntype ChainClient interface {\n\t// Start initializes and starts the chain client\n\tStart(ctx context.Context) error\n\n\t// Stop gracefully shuts down the chain client\n\tStop() error\n\n\t// IsHealthy checks if the chain client is operational\n\tIsHealthy() bool\n\n\t// GetTxBuilder returns the TxBuilder for this chain\n\t// Returns an error if txBuilder is not supported for this chain (e.g., Push chain)\n\tGetTxBuilder() (TxBuilder, error)\n\n\t// GetReadRequestHandler returns the handler executing read requests\n\t// destined for this chain\n\t// Returns an error if reads are not available (e.g. client not started)\n\tGetReadRequestHandler() (ReadRequestHandler, error)\n}\n```\nChainClient defines the interface for chain-specific implementations\n\n```go\ntype ChainStore struct {\n\t// contains filtered or unexported fields\n}\n```\nChainStore provides database operations for chain state and events\n\n```go\nfunc NewChainStore(database *db.DB) *ChainStore\n```\nNewChainStore creates a new chain store\n\n```go\nfunc (cs *ChainStore) DeleteTerminalEvents(updatedBefore any) (int64, error)\n```\nDeleteTerminalEvents deletes events in terminal states (COMPLETED, REVERTED, EXPIRED) that were updated before the given time\n\n```go\nfunc (cs *ChainStore) GetChainHeight() (uint64, error)\n```\nGetChainHeight returns the last processed block height for the chain. Creates a new entry with height 0 if one doesn't exist (atomic via FirstOrCreate).\n\n```go\nfunc (cs *ChainStore) GetConfirmedEvents(limit int) ([]store.Event, error)\n```\nGetConfirmedEvents fetches confirmed events ordered by creation time\n\n```go\nfunc (cs *ChainStore) GetPendingEvents(limit int) ([]store.Event, error)\n```\nGetPendingEvents fetches pending events ordered by creation time\n\n```go\nfunc (cs *ChainStore) InsertEventIfNotExists(event *store.Event) (bool, error)\n```\nInsertEventIfNotExists inserts an event if it doesn't already exist (by EventID) Returns (true, nil) if a new event was inserted, (false, nil) if it already existed, or (false, error) if insertion failed\n\n```go\nfunc (cs *ChainStore) UpdateChainHeight(blockHeight uint64) error\n```\nUpdateChainHeight updates the last processed block height for the chain. Creates a new entry if one doesn't exist (atomic via FirstOrCreate). Only updates if the new height is greater than the current one.\n\n```go\nfunc (cs *ChainStore) UpdateEventStatus(eventID string, oldStatus, newStatus string) (int64, error)\n```\nUpdateEventStatus updates the status of an event by event ID\n\n```go\nfunc (cs *ChainStore) UpdateStatusAndEventData(eventID, oldStatus, newStatus string, eventData []byte) (int64, error)\n```\nUpdateStatusAndEventData atomically flips the event status and updates the event data in one DB write. The update is conditional on the event currently having oldStatus (compare-and-swap semantics). Returns the number of rows affected (0 means the event was already in a different status).\n\n```go\nfunc (cs *ChainStore) UpdateStatusAndVoteTxHash(eventID, oldStatus, newStatus, voteTxHash string) (int64, error)\n```\nUpdateStatusAndVoteTxHash atomically flips the event status and records the vote tx hash in one DB write. The update is conditional on the event currently having oldStatus (compare-and-swap semantics). Returns the number of rows affected (0 means the event was already in a different status).\n\n```go\ntype EventCleaner struct {\n\t// contains filtered or unexported fields\n}\n```\nEventCleaner handles periodic cleanup of old confirmed events for a chain\n\n```go\nfunc NewEventCleaner(\n\tdatabase *db.DB,\n\tcleanupIntervalSeconds *int,\n\tretentionPeriodSeconds *int,\n\tchainID string,\n\tlogger zerolog.Logger,\n) *EventCleaner\n```\nNewEventCleaner creates a new event cleaner for a chain\n\n```go\nfunc (ec *EventCleaner) Start(ctx context.Context) error\n```\nStart begins the periodic cleanup process\n\n```go\nfunc (ec *EventCleaner) Stop()\n```\nStop gracefully stops the event cleaner and waits for the cleanup goroutine to exit. No-op if not running.\n\nWaiting matters on shutdown: the goroutine runs queries against the chain database, and returning before it finishes lets the caller close that database underneath an in-flight cleanup.\n\n```go\ntype EventHandler interface {\n\tHandleEvent(ctx context.Context, event *store.Event) error\n}\n```\nEventHandler processes one CONFIRMED event of a registered type. Handlers own the event's status transitions; a returned error is logged and the event is retried next tick.\n\n```go\ntype EventProcessor struct {\n\t// contains filtered or unexported fields\n}\n```\nEventProcessor drains CONFIRMED events from the chain's database and dispatches them to the handler registered for their type. Event types without a handler are ignored.\n\n```go\nfunc NewEventProcessor(\n\tdatabase *db.DB,\n\tchainID string,\n\tlogger zerolog.Logger,\n) *EventProcessor\n```\nNewEventProcessor creates a new event processor. Register handlers before Start.\n\n```go\nfunc (ep *EventProcessor) IsRunning() bool\n```\nIsRunning returns whether the processor is currently running\n\n```go\nfunc (ep *EventProcessor) RegisterHandler(eventType string, handler EventHandler)\n```\nRegisterHandler registers a handler for an event type. Must be called before Start.\n\n```go\nfunc (ep *EventProcessor) Start(ctx context.Context) error\n```\nStart begins processing events\n\n```go\nfunc (ep *EventProcessor) Stop() error\n```\nStop gracefully stops the event processor\n\n```go\ntype FundMigrationData struct {\n\tFrom           string   // Old TSS address (derived from old pubkey)\n\tTo             string   // New TSS address (derived from current pubkey)\n\tGasPrice       *big.Int // Gas price from the migration event\n\tGasLimit       uint64   // Gas limit from the migration event\n\tL1GasFee       *big.Int // Extra L1 data-availability fee (wei); 0 for non-L2 chains\n\tTransferAmount *big.Int // sweep amount pinned on chain; never derived from a live balance\n}\n```\nFundMigrationData contains the data needed to build a fund migration transaction. Populated by the coordinator from the migration event + derived addresses.\n\n```go\ntype InboundObservation struct {\n\tSourceChain         string `json:\"sourceChain\"`\n\tLogIndex            uint   `json:\"logIndex\"`\n\tSender              string `json:\"sender\"`\n\tRecipient           string `json:\"recipient\"`\n\tToken               string `json:\"bridgeToken\"`\n\tAmount              string `json:\"bridgeAmount\"`         // uint256 as decimal string\n\tRawPayload          string `json:\"rawPayload,omitempty\"` // hex-encoded raw payload bytes from source chain\n\tVerificationData    string `json:\"verificationData\"`\n\tRevertFundRecipient string `json:\"revertFundRecipient,omitempty\"`\n\tTxType              uint   `json:\"txType\"`  // enum backing uint as decimal string\n\tFromCEA             bool   `json:\"fromCEA\"` // true if inbound is initiated by a CEA\n}\n```\nInboundObservation is the inbound observation payload stored for INBOUND events\n\n```go\ntype InboundObservationEventProcessor struct {\n\t// contains filtered or unexported fields\n}\n```\nInboundObservationEventProcessor handles INBOUND events: it builds the inbound observation from the stored event and votes it on Push chain.\n\n```go\nfunc NewInboundObservationEventProcessor(\n\tsigner VoteSigner,\n\tdatabase *db.DB,\n\tlogger zerolog.Logger,\n) *InboundObservationEventProcessor\n```\nNewInboundObservationEventProcessor creates the handler for INBOUND events.\n\n```go\nfunc (p *InboundObservationEventProcessor) HandleEvent(ctx context.Context, event *store.Event) error\n```\nHandleEvent implements EventHandler for INBOUND events.\n\n```go\ntype OutboundObservation struct {\n\tTxID          string `json:\"tx_id\"`                  // bytes32 hex-encoded (0x...)\n\tUniversalTxID string `json:\"universal_tx_id\"`        // bytes32 hex-encoded (0x...)\n\tGasFeeUsed    string `json:\"gas_fee_used,omitempty\"` // gas fee used in wei (decimal string)\n\t// PC20 export only: wrapper token address deployed/minted on the destination\n\t// at settlement (observed in the finalize event). Core uses it to flip the\n\t// PC20 deploy flag; empty for non-PC20 settlements.\n\tPc20WrapperAddress string `json:\"pc20_wrapper_address,omitempty\"`\n}\n```\nOutboundObservation is the outbound observation payload stored for OUTBOUND events Event structure: - txID at 1st indexed position (bytes32) - universalTxID at 2nd indexed position (bytes32)\n\n```go\ntype OutboundObservationEventProcessor struct {\n\t// contains filtered or unexported fields\n}\n```\nOutboundObservationEventProcessor handles OUTBOUND events: it builds the outbound observation from the stored event and votes it on Push chain.\n\n```go\nfunc NewOutboundObservationEventProcessor(\n\tsigner VoteSigner,\n\tdatabase *db.DB,\n\tlogger zerolog.Logger,\n) *OutboundObservationEventProcessor\n```\nNewOutboundObservationEventProcessor creates the handler for OUTBOUND events.\n\n```go\nfunc (p *OutboundObservationEventProcessor) HandleEvent(ctx context.Context, event *store.Event) error\n```\nHandleEvent implements EventHandler for OUTBOUND events.\n\n```go\ntype ReadRequestHandler interface {\n\tExecuteRead(ctx context.Context, req *ucallbacktypes.ReadRequest) (*ucallbacktypes.ReadResult, error)\n}\n```\nReadRequestHandler executes a read request on one destination chain. Consumed by the push watcher's read processor.\n\n```go\ntype TxBuilder interface {\n\t// GetOutboundSigningRequest creates a signing request from outbound event data\n\tGetOutboundSigningRequest(ctx context.Context, data *uetypes.OutboundCreatedEvent, nonce uint64) (*UnsignedSigningReq, error)\n\n\t// GetNextNonce returns the next nonce for the given signer on this chain (for seeding local nonce).\n\t// useFinalized: for EVM, if true use finalized block nonce (aggressive/replace stuck); if false use pending. SVM ignores this.\n\tGetNextNonce(ctx context.Context, signerAddress string, useFinalized bool) (uint64, error)\n\n\t// BroadcastOutboundSigningRequest assembles and broadcasts a signed transaction from the signing request, event data, and signature\n\tBroadcastOutboundSigningRequest(ctx context.Context, req *UnsignedSigningReq, data *uetypes.OutboundCreatedEvent, signature []byte) (string, error)\n\n\t// VerifyBroadcastedTx checks the status of a broadcasted transaction on the destination chain.\n\t// Returns (found, blockHeight, confirmations, status, error):\n\t// - err != nil: the chain could not be queried. Callers must retry and must not\n\t//   treat this as evidence about whether the tx executed.\n\t// - found=false, err=nil: the chain answered and the tx is not there.\n\t// - found=true: tx exists on-chain\n\t//   - blockHeight: the block in which the tx was mined\n\t//   - confirmations: number of blocks since the tx was mined (0 = just mined)\n\t//   - status: 0 = failed/reverted, 1 = success\n\tVerifyBroadcastedTx(ctx context.Context, txHash string) (found bool, blockHeight uint64, confirmations uint64, status uint8, err error)\n\n\t// IsAlreadyExecuted checks whether a transaction with the given txID has already been\n\t// executed on the destination chain (e.g., by another relayer).\n\t// For SVM: checks if the ExecutedTx PDA exists on-chain, AND returns the\n\t//   unix timestamp of the latest finalized block. Callers use this as the\n\t//   cluster's \"now\" to gate deadline-based give-up/REVERT decisions and to\n\t//   detect cluster halt or finalization stall (queryBlockTime far behind\n\t//   wall-clock). 0 means freshness couldn't be determined.\n\t// For EVM: returns (false, 0, nil). EVM uses nonce-based replay protection.\n\tIsAlreadyExecuted(ctx context.Context, txID string) (executed bool, queryBlockTime int64, err error)\n\n\t// GetGasFeeUsed returns the gas fee used by a transaction on the destination chain.\n\t// EVM: gasUsed * effectiveGasPrice + OP-Stack l1Fee, as a decimal string; errors\n\t// when the fee cannot be determined so callers retry instead of recording an\n\t// under-reported fee.\n\t// SVM: returns \"0\" (gas accounting is handled via vault gasFee reimbursement).\n\tGetGasFeeUsed(ctx context.Context, txHash string) (string, error)\n\n\t// GetFundMigrationSigningRequest builds a native token transfer for fund migration,\n\t// transferring the maximum possible balance (balance minus gas cost).\n\tGetFundMigrationSigningRequest(ctx context.Context, data *FundMigrationData, nonce uint64) (*UnsignedSigningReq, error)\n\n\t// BroadcastFundMigrationTx assembles and broadcasts a signed fund migration transaction.\n\tBroadcastFundMigrationTx(ctx context.Context, req *UnsignedSigningReq, data *FundMigrationData, signature []byte) (string, error)\n}\n```\nTxBuilder builds and broadcasts transactions for outbound transfers\n\n```go\ntype UnsignedSigningReq struct {\n\tSigningHash []byte // Hash to be signed by TSS\n\tNonce       uint64 // evm - TSS Address nonce | svm - PDA nonce\n\n}\n```\nUnsignedSigningReq contains the request for signing an outbound or fund-migration transaction.\n\n```go\ntype VoteSigner interface {\n\tVoteInbound(ctx context.Context, inbound *uexecutortypes.Inbound) (string, error)\n\tVoteOutbound(ctx context.Context, txID string, utxID string, observation *uexecutortypes.OutboundObservation) (string, error)\n}\n```\nVoteSigner is the subset of pushsigner.Signer used by the event processors. Defined here (consumer-side) so tests can provide mock implementations.\n\n","path":"github.com/pushchain/push-chain-node/universalClient/externalchains/common","name":"common","synopsis":"","isRedistributable":true}
