Documentation
¶
Index ¶
- func NewMockSigner() sign.Signer
- type ActionGateway
- type Handler
- func (h *Handler) GetChannels(c *rpc.Context)
- func (h *Handler) GetEscrowChannel(c *rpc.Context)
- func (h *Handler) GetHomeChannel(c *rpc.Context)
- func (h *Handler) GetLastKeyStates(c *rpc.Context)
- func (h *Handler) GetLatestState(c *rpc.Context)
- func (h *Handler) RequestCreation(c *rpc.Context)
- func (h *Handler) SubmitSessionKeyState(c *rpc.Context)
- func (h *Handler) SubmitState(c *rpc.Context)
- type MemoryStore
- type MockActionGateway
- type MockAssetStore
- type MockMemoryStore
- type MockSigValidator
- type MockStatePacker
- type MockStore
- func (m *MockStore) BeginTx() (Store, func() error, func() error)
- func (m *MockStore) CheckOpenChannel(wallet, asset string) (string, bool, error)
- func (m *MockStore) CreateChannel(channel core.Channel) error
- func (m *MockStore) EnsureNoOngoingStateTransitions(wallet, asset string) error
- func (m *MockStore) GetActiveHomeChannel(wallet, asset string) (*core.Channel, error)
- func (m *MockStore) GetAppCount(ownerWallet string) (uint64, error)
- func (m *MockStore) GetChannelByID(channelID string) (*core.Channel, error)
- func (m *MockStore) GetLastChannelSessionKeyStates(wallet string, sessionKey *string) ([]core.ChannelSessionKeyStateV1, error)
- func (m *MockStore) GetLastChannelSessionKeyVersion(wallet, sessionKey string) (uint64, error)
- func (m *MockStore) GetLastUserState(wallet, asset string, signed bool) (*core.State, error)
- func (m *MockStore) GetTotalUserStaked(wallet string) (decimal.Decimal, error)
- func (m *MockStore) GetUserActionCount(wallet string, gatedAction core.GatedAction, window time.Duration) (uint64, error)
- func (m *MockStore) GetUserActionCounts(userWallet string, window time.Duration) (map[core.GatedAction]uint64, error)
- func (m *MockStore) GetUserChannels(wallet string, status *core.ChannelStatus, asset *string, ...) ([]core.Channel, uint32, error)
- func (m *MockStore) LockUserState(wallet, asset string) (decimal.Decimal, error)
- func (m *MockStore) RecordAction(wallet string, gatedAction core.GatedAction) error
- func (m *MockStore) RecordTransaction(tx core.Transaction) error
- func (m *MockStore) ScheduleInitiateEscrowWithdrawal(stateID string, chainID uint64) error
- func (m *MockStore) StoreChannelSessionKeyState(state core.ChannelSessionKeyStateV1) error
- func (m *MockStore) StoreUserState(state core.State) error
- func (m *MockStore) ValidateChannelSessionKeyForAsset(wallet, sessionKey, asset, metadataHash string) (bool, error)
- type SigValidator
- type SigValidatorType
- type Store
- type StoreTxHandler
- type StoreTxProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMockSigner ¶
Types ¶
type ActionGateway ¶
type ActionGateway interface {
// AllowAction checks if a user is allowed to perform a specific gated action based on their past activity and allowances.
AllowAction(tx action_gateway.Store, userAddress string, gatedAction core.GatedAction) error
}
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manages channel state transitions and provides RPC endpoints for state submission.
func NewHandler ¶
func NewHandler( useStoreInTx StoreTxProvider, memoryStore MemoryStore, actionGateway ActionGateway, nodeSigner *core.ChannelDefaultSigner, stateAdvancer core.StateAdvancer, statePacker core.StatePacker, nodeAddress string, minChallenge uint32, m metrics.RuntimeMetricExporter, maxSessionKeyIDs int, ) *Handler
NewHandler creates a new Handler instance with the provided dependencies.
func (*Handler) GetChannels ¶
GetChannels retrieves all channels for a user with optional status/asset/type filtering and pagination.
func (*Handler) GetEscrowChannel ¶
GetEscrowChannel retrieves current on-chain escrow channel information.
func (*Handler) GetHomeChannel ¶
GetHomeChannel retrieves current on-chain home channel information.
func (*Handler) GetLastKeyStates ¶
GetLastKeyStates retrieves the latest channel session key states for a user with optional filtering by session key.
func (*Handler) GetLatestState ¶
GetLatestState retrieves the current state of the user stored on the Node.
func (*Handler) RequestCreation ¶
RequestCreation processes channel creation requests from users. It validates the channel definition and initial state, checks for existing channels, signs the state with the node's key, and persists the new pending state and channel.
func (*Handler) SubmitSessionKeyState ¶
SubmitSessionKeyState processes channel session key state submissions for registration and updates.
func (*Handler) SubmitState ¶
SubmitState processes user-submitted state transitions, validates them against the current state, verifies user signatures, signs the new state with the node's key, and persists changes. For transfer transitions, it automatically creates corresponding receiver states. For certain transitions (escrow lock, etc.), it schedules blockchain actions.
type MemoryStore ¶
type MemoryStore interface {
// IsAssetSupported checks if a given asset (token) is supported on the specified blockchain.
IsAssetSupported(asset, tokenAddress string, blockchainID uint64) (bool, error)
// GetAssetDecimals checks if an asset exists and returns its decimals in YN
GetAssetDecimals(asset string) (uint8, error)
// GetTokenDecimals returns the decimals for a token on a specific blockchain
GetTokenDecimals(blockchainID uint64, tokenAddress string) (uint8, error)
}
type MockActionGateway ¶
type MockActionGateway struct {
Err error
}
func (*MockActionGateway) AllowAction ¶
func (m *MockActionGateway) AllowAction(_ action_gateway.Store, _ string, _ core.GatedAction) error
type MockAssetStore ¶
MockAssetStore is a mock implementation of the core.AssetStore interface
func (*MockAssetStore) GetAssetDecimals ¶
func (m *MockAssetStore) GetAssetDecimals(asset string) (uint8, error)
func (*MockAssetStore) GetTokenDecimals ¶
func (m *MockAssetStore) GetTokenDecimals(blockchainID uint64, tokenAddress string) (uint8, error)
type MockMemoryStore ¶
MockMemoryStore is a mock implementation of the MemoryStore interface
func (*MockMemoryStore) GetAssetDecimals ¶
func (m *MockMemoryStore) GetAssetDecimals(asset string) (uint8, error)
func (*MockMemoryStore) GetTokenDecimals ¶
func (m *MockMemoryStore) GetTokenDecimals(blockchainID uint64, tokenAddress string) (uint8, error)
func (*MockMemoryStore) IsAssetSupported ¶
func (m *MockMemoryStore) IsAssetSupported(asset, tokenAddress string, blockchainID uint64) (bool, error)
type MockSigValidator ¶
MockSigValidator is a mock implementation of the SigValidator interface
type MockStatePacker ¶
type MockStore ¶
MockStore is a mock implementation of the Store interface
func (*MockStore) CheckOpenChannel ¶
func (*MockStore) EnsureNoOngoingStateTransitions ¶
func (*MockStore) GetActiveHomeChannel ¶
func (*MockStore) GetChannelByID ¶
func (*MockStore) GetLastChannelSessionKeyStates ¶
func (*MockStore) GetLastChannelSessionKeyVersion ¶
func (*MockStore) GetLastUserState ¶
func (*MockStore) GetTotalUserStaked ¶
func (*MockStore) GetUserActionCount ¶
func (*MockStore) GetUserActionCounts ¶
func (*MockStore) GetUserChannels ¶
func (*MockStore) LockUserState ¶
func (*MockStore) RecordAction ¶
func (m *MockStore) RecordAction(wallet string, gatedAction core.GatedAction) error
func (*MockStore) RecordTransaction ¶
func (m *MockStore) RecordTransaction(tx core.Transaction) error
func (*MockStore) ScheduleInitiateEscrowWithdrawal ¶
func (*MockStore) StoreChannelSessionKeyState ¶
func (m *MockStore) StoreChannelSessionKeyState(state core.ChannelSessionKeyStateV1) error
type SigValidator ¶
type SigValidator interface {
// Verify checks that the signature is valid for the given data and wallet address.
// Returns an error if the signature is invalid or cannot be verified.
Verify(wallet string, data, sig []byte) error
}
SigValidator validates cryptographic signatures on state transitions.
type SigValidatorType ¶
type SigValidatorType string
SigValidatorType identifies the signature validation algorithm to use.
const EcdsaSigValidatorType SigValidatorType = "ecdsa"
EcdsaSigValidatorType represents the ECDSA (Elliptic Curve Digital Signature Algorithm) validator, used for Ethereum-style signature verification.
type Store ¶
type Store interface {
// LockUserState locks a user's balance for update, must be used within a transaction.
// Returns the current balance.
LockUserState(wallet, asset string) (decimal.Decimal, error)
// GetLastUserState retrieves the most recent state for a user's asset.
// If signed is true, only returns states with both user and node signatures.
// Returns nil state if no matching state exists.
GetLastUserState(wallet, asset string, signed bool) (*core.State, error)
// CheckOpenChannel verifies if a user has an active channel for the given asset
// and returns the approved signature validators if such a channel exists.
CheckOpenChannel(wallet, asset string) (string, bool, error)
// StoreUserState persists a new user state to the database.
StoreUserState(state core.State) error
// EnsureNoOngoingStateTransitions validates that no blockchain operations are pending
// that would conflict with submitting a new state transition.
EnsureNoOngoingStateTransitions(wallet, asset string) error
// ScheduleInitiateEscrowWithdrawal queues a blockchain action to initiate
// withdrawal from an escrow channel (triggered by escrow_lock transition).
ScheduleInitiateEscrowWithdrawal(stateID string, chainID uint64) error
// RecordTransaction creates a transaction record linking state transitions
// to track the history of operations (deposits, withdrawals, transfers, etc.).
RecordTransaction(tx core.Transaction) error
// CreateChannel creates a new channel entity in the database.
// This is called during channel creation before the channel exists on-chain.
// The channel starts with OnChainStateVersion=0 to indicate it's pending blockchain confirmation.
CreateChannel(channel core.Channel) error
// GetChannelByID retrieves a channel by its unique identifier.
// Returns nil if the channel doesn't exist.
GetChannelByID(channelID string) (*core.Channel, error)
// GetActiveHomeChannel retrieves the active home channel for a user's wallet and asset.
// Returns nil if no home channel exists for the given wallet and asset.
GetActiveHomeChannel(wallet, asset string) (*core.Channel, error)
// GetUserChannels retrieves all channels for a user with optional status, asset, and type filters.
GetUserChannels(wallet string, status *core.ChannelStatus, asset *string, channelType *core.ChannelType, limit, offset uint32) ([]core.Channel, uint32, error)
// StoreChannelSessionKeyState persists a channel session key state.
StoreChannelSessionKeyState(state core.ChannelSessionKeyStateV1) error
// GetLastChannelSessionKeyVersion returns the latest version for a (wallet, sessionKey) pair.
// Returns 0 if no state exists.
GetLastChannelSessionKeyVersion(wallet, sessionKey string) (uint64, error)
// GetLastChannelSessionKeyStates retrieves the latest channel session key states for a user,
// optionally filtered by session key.
GetLastChannelSessionKeyStates(wallet string, sessionKey *string) ([]core.ChannelSessionKeyStateV1, error)
// ValidateChannelSessionKeyForAsset checks that a valid, non-expired session key state
// exists at its latest version for the (wallet, sessionKey) pair, includes the given asset,
// and matches the metadata hash.
ValidateChannelSessionKeyForAsset(wallet, sessionKey, asset, metadataHash string) (bool, error)
action_gateway.Store
}
Store defines the persistence layer interface for channel state management. All methods should be implemented to work within database transactions.
type StoreTxHandler ¶
StoreTxHandler is a function that executes Store operations within a transaction. If the handler returns an error, the transaction is rolled back; otherwise it's committed.
type StoreTxProvider ¶
type StoreTxProvider func(StoreTxHandler) error
StoreTxProvider wraps Store operations in a database transaction. It accepts a StoreTxHandler and manages transaction lifecycle (begin, commit, rollback). Returns an error if the handler fails or the transaction cannot be committed.