{"modulePath":"github.com/stickychin/code-server","version":"v0.0.0-20250522011653-c6effd41c6ef","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package nonce\n\n## Constants\n\n```go\nconst (\n\tEnvironmentInstanceSolanaMainnet = \"mainnet\"\n\tEnvironmentInstanceSolanaDevnet  = \"devnet\"\n\tEnvironmentInstanceSolanaTestnet = \"testnet\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\tErrNonceNotFound = errors.New(\"no records could be found\")\n\tErrInvalidNonce  = errors.New(\"invalid nonce\")\n)\n```\n\n## Types\n\n```go\ntype Environment uint8\n```\n\n```go\nconst (\n\tEnvironmentUnknown Environment = iota\n\tEnvironmentSolana              // Environment instance is the cluster name (ie. mainnet, devnet, testnet, etc)\n\tEnvironmentCvm                 // Environment instance is the VM public key\n)\n```\n\n```go\nfunc (e Environment) String() string\n```\n\n```go\ntype Purpose uint8\n```\nSplit nonce pool across different use cases. This has an added benefit of:\n\n  - Solving for race conditions without distributed locks.\n  - Avoiding different use cases from starving each other and ending up in a deadlocked state. Concretely, it would be really bad if clients could starve internal processes from creating transactions that would allow us to progress and submit existing transactions.\n\n```go\nconst (\n\tPurposeUnknown Purpose = iota\n\tPurposeClientTransaction\n\tPurposeInternalServerProcess\n\tPurposeOnDemandTransaction\n)\n```\n\n```go\nfunc (p Purpose) String() string\n```\n\n```go\ntype Record struct {\n\tId uint64\n\n\tAddress   string\n\tAuthority string\n\tBlockhash string\n\n\tEnvironment         Environment\n\tEnvironmentInstance string\n\n\tPurpose Purpose\n\tState   State\n\n\tSignature string\n}\n```\n\n```go\nfunc (r *Record) Clone() Record\n```\n\n```go\nfunc (r *Record) CopyTo(dst *Record)\n```\n\n```go\nfunc (r *Record) GetPublicKey() (ed25519.PublicKey, error)\n```\n\n```go\nfunc (v *Record) Validate() error\n```\n\n```go\ntype State uint8\n```\n\n```go\nconst (\n\tStateUnknown   State = iota\n\tStateReleased        // The nonce is almost ready but we don't know its blockhash yet.\n\tStateAvailable       // The nonce is available to be used by a payment intent, subscription, or other nonce-related transaction/instruction.\n\tStateReserved        // The nonce is reserved by a payment intent, subscription, or other nonce-related transaction/instruction.\n\tStateInvalid         // The nonce account is invalid (e.g. insufficient funds, etc).\n)\n```\n\n```go\nfunc (s State) String() string\n```\n\n```go\ntype Store interface {\n\t// Count returns the total count of nonce accounts within an environment instance\n\tCount(ctx context.Context, env Environment, instance string) (uint64, error)\n\n\t// CountByState returns the total count of nonce accounts in the provided state within\n\t// an environment instance\n\tCountByState(ctx context.Context, env Environment, instance string, state State) (uint64, error)\n\n\t// CountByStateAndPurpose returns the total count of nonce accounts in the provided\n\t// state and use case within an environment instance\n\tCountByStateAndPurpose(ctx context.Context, env Environment, instance string, state State, purpose Purpose) (uint64, error)\n\n\t// Save creates or updates nonce metadata in the store.\n\tSave(ctx context.Context, record *Record) error\n\n\t// Get finds the nonce record for a given address.\n\t//\n\t// Returns ErrNotFound if no record is found.\n\tGet(ctx context.Context, address string) (*Record, error)\n\n\t// GetAllByState returns nonce records in the store for a given confirmation state\n\t// within an environment intance.\n\t//\n\t// Returns ErrNotFound if no records are found.\n\tGetAllByState(ctx context.Context, env Environment, instance string, state State, cursor query.Cursor, limit uint64, direction query.Ordering) ([]*Record, error)\n\n\t// GetRandomAvailableByPurpose gets a random available nonce for a purpose within\n\t// an environment instance.\n\t//\n\t// Returns ErrNotFound if no records are found.\n\tGetRandomAvailableByPurpose(ctx context.Context, env Environment, instance string, purpose Purpose) (*Record, error)\n}\n```\n\n","path":"github.com/stickychin/code-server/pkg/code/data/nonce","name":"nonce","synopsis":"","isRedistributable":true}
