Documentation
¶
Overview ¶
Package neoaccounts provides API routes for the neoaccounts service.
Package neoaccounts provides HTTP handlers for the neoaccounts service.
Package neoaccounts provides pool management for the neoaccounts service.
Package neoaccounts provides a centralized neoaccounts service for other marbles. Private keys never leave this service - other services request accounts and submit transactions for signing.
Package neoaccounts provides transaction signing for the neoaccounts service.
Index ¶
- Constants
- type AccountInfo
- type BatchSignInput
- type BatchSignResponse
- type Config
- type ContractParam
- type DeployContractInput
- type DeployContractResponse
- type DeployMasterInput
- type DeployMasterResponse
- type FundAccountInput
- type FundAccountResponse
- type InvokeContractInput
- type InvokeContractResponse
- type InvokeMasterInput
- type ListAccountsInput
- type ListAccountsResponse
- type MasterKeyAttestation
- type MasterKeySummary
- type PoolInfoResponse
- type ReleaseAccountsInput
- type ReleaseAccountsResponse
- type RequestAccountsInput
- type RequestAccountsResponse
- type Service
- func (s *Service) BatchSign(ctx context.Context, serviceID string, requests []SignRequest) *BatchSignResponse
- func (s *Service) DeployContract(ctx context.Context, serviceID, accountID, nefBase64, manifestJSON string, ...) (*DeployContractResponse, error)
- func (s *Service) DeployMaster(ctx context.Context, nefBase64, manifestJSON string, data any) (*DeployMasterResponse, error)
- func (s *Service) FundAccount(ctx context.Context, toAddress string, amount int64, tokenAddress string) (*FundAccountResponse, error)
- func (s *Service) GetPoolInfo(ctx context.Context) (*PoolInfoResponse, error)
- func (s *Service) InvokeContract(ctx context.Context, serviceID, accountID, contractAddress, method string, ...) (*InvokeContractResponse, error)
- func (s *Service) InvokeMaster(ctx context.Context, contractAddress, method string, params []ContractParam, ...) (*InvokeContractResponse, error)
- func (s *Service) ListAccountsByService(ctx context.Context, serviceID, tokenType string, minBalance *int64) ([]AccountInfo, error)
- func (s *Service) ListLowBalanceAccounts(ctx context.Context, tokenType string, maxBalance int64, limit int) ([]AccountInfo, error)
- func (s *Service) ReleaseAccounts(ctx context.Context, serviceID string, accountIDs []string) (int, error)
- func (s *Service) ReleaseAllByService(ctx context.Context, serviceID string) (int, error)
- func (s *Service) RequestAccounts(ctx context.Context, serviceID string, count int, purpose string) (accounts []AccountInfo, lockID string, err error)
- func (s *Service) SignTransaction(ctx context.Context, serviceID, accountID string, txHash []byte) (*SignTransactionResponse, error)
- func (s *Service) SimulateContract(ctx context.Context, serviceID, accountID, contractAddress, method string, ...) (*SimulateContractResponse, error)
- func (s *Service) Transfer(ctx context.Context, serviceID, accountID, toAddress string, amount int64, ...) (string, error)
- func (s *Service) TransferWithData(ctx context.Context, serviceID, accountID, toAddress string, amount int64, ...) (string, error)
- func (s *Service) UpdateBalance(ctx context.Context, serviceID, accountID, tokenType string, delta int64, ...) (oldBalance, newBalance, txCount int64, err error)
- func (s *Service) UpdateContract(ctx context.Context, ...) (*UpdateContractResponse, error)
- type SignRequest
- type SignTransactionInput
- type SignTransactionResponse
- type SimulateContractInput
- type SimulateContractResponse
- type TokenBalance
- type TokenStats
- type TransferInput
- type TransferResponse
- type TransferWithDataInput
- type TransferWithDataResponse
- type UpdateBalanceInput
- type UpdateBalanceResponse
- type UpdateContractInput
- type UpdateContractResponse
Constants ¶
const ( ServiceID = "neoaccounts" ServiceName = "Account Pool Service" Version = "2.0.0" // Updated for multi-token support // Pool configuration MinPoolAccounts = 1000 MaxPoolAccounts = 50000 BatchCreateSize = 100 // Number of accounts to create in each batch RotationRate = 0.1 // 10% of accounts rotated per day RotationMinAge = 24 // Minimum age in hours before rotation // Lock timeout - accounts locked longer than this can be force-released LockTimeout = 24 * time.Hour )
const ( SecretTEEPrivateKey = "TEE_PRIVATE_KEY" SecretTEEWalletPrivateKey = "TEE_WALLET_PRIVATE_KEY" SecretNeoTestnetWIF = "NEO_TESTNET_WIF" )
Secret names for TEE wallet keys - these should be defined in MarbleRun manifest
const ( TokenTypeNEO = neoaccountstypes.TokenTypeNEO TokenTypeGAS = neoaccountstypes.TokenTypeGAS )
Re-export token constants for convenience
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountInfo ¶
type AccountInfo = neoaccountstypes.AccountInfo
AccountInfo represents public account information returned to clients. Private keys are never exposed. Balances are tracked per-token.
func AccountInfoFromAccount ¶
func AccountInfoFromAccount(acc *neoaccountssupabase.Account) AccountInfo
AccountInfoFromAccount converts Account to AccountInfo with empty balances.
func AccountInfoFromWithBalances ¶
func AccountInfoFromWithBalances(acc *neoaccountssupabase.AccountWithBalances) AccountInfo
AccountInfoFromWithBalances converts AccountWithBalances to AccountInfo.
type BatchSignInput ¶
type BatchSignInput = neoaccountstypes.BatchSignInput
BatchSignInput for signing multiple transactions.
type BatchSignResponse ¶
type BatchSignResponse = neoaccountstypes.BatchSignResponse
BatchSignResponse returns multiple signatures.
type Config ¶
type Config struct {
Marble *marble.Marble
DB database.RepositoryInterface
NeoAccountsRepo neoaccountssupabase.RepositoryInterface
ChainClient *chain.Client
}
Config holds NeoAccounts service configuration.
type ContractParam ¶
type ContractParam = neoaccountstypes.ContractParam
ContractParam represents a parameter for contract invocation.
type DeployContractInput ¶
type DeployContractInput = neoaccountstypes.DeployContractInput
DeployContractInput deploys a new contract using a pool account.
type DeployContractResponse ¶
type DeployContractResponse = neoaccountstypes.DeployContractResponse
DeployContractResponse returns the deployment result.
type DeployMasterInput ¶
type DeployMasterInput = neoaccountstypes.DeployMasterInput
DeployMasterInput deploys a contract using the master wallet.
type DeployMasterResponse ¶
type DeployMasterResponse = neoaccountstypes.DeployMasterResponse
DeployMasterResponse returns the deployment result using master wallet.
type FundAccountInput ¶
type FundAccountInput = neoaccountstypes.FundAccountInput
FundAccountInput funds a pool account from the master wallet.
type FundAccountResponse ¶
type FundAccountResponse = neoaccountstypes.FundAccountResponse
FundAccountResponse returns the funding result.
type InvokeContractInput ¶
type InvokeContractInput = neoaccountstypes.InvokeContractInput
InvokeContractInput invokes a contract method using a pool account.
type InvokeContractResponse ¶
type InvokeContractResponse = neoaccountstypes.InvokeContractResponse
InvokeContractResponse returns the invocation result.
type InvokeMasterInput ¶
type InvokeMasterInput = neoaccountstypes.InvokeMasterInput
InvokeMasterInput invokes a contract using the master wallet (TEE operations).
type ListAccountsInput ¶
type ListAccountsInput struct {
ServiceID string `json:"service_id"` // Required: only list accounts locked by this service
Token string `json:"token,omitempty"` // Optional: filter by token type
MinBalance *int64 `json:"min_balance,omitempty"` // Optional: minimum balance for specified token
}
ListAccountsInput for listing accounts with filters.
type ListAccountsResponse ¶
type ListAccountsResponse = neoaccountstypes.ListAccountsResponse
ListAccountsResponse returns filtered accounts.
type MasterKeyAttestation ¶
type MasterKeyAttestation = neoaccountstypes.MasterKeyAttestation
MasterKeyAttestation is a non-sensitive bundle proving the master key hash is bound to enclave report data.
type MasterKeySummary ¶
type MasterKeySummary struct {
Hash string `json:"hash"`
PubKeyHex string `json:"pubkey,omitempty"`
AttestationHash string `json:"attestation_hash,omitempty"`
Source string `json:"source"`
RequiresHash bool `json:"requires_hash"`
}
MasterKeySummary exposes non-sensitive metadata for off-chain attestation verification and on-chain anchoring without revealing the key material.
type PoolInfoResponse ¶
type PoolInfoResponse = neoaccountstypes.PoolInfoResponse
PoolInfoResponse returns pool statistics with per-token breakdowns.
type ReleaseAccountsInput ¶
type ReleaseAccountsInput = neoaccountstypes.ReleaseAccountsInput
ReleaseAccountsInput for releasing previously requested accounts.
type ReleaseAccountsResponse ¶
type ReleaseAccountsResponse = neoaccountstypes.ReleaseAccountsResponse
ReleaseAccountsResponse confirms release.
type RequestAccountsInput ¶
type RequestAccountsInput = neoaccountstypes.RequestAccountsInput
RequestAccountsInput for requesting accounts from the pool.
type RequestAccountsResponse ¶
type RequestAccountsResponse = neoaccountstypes.RequestAccountsResponse
RequestAccountsResponse returns the requested accounts.
type Service ¶
type Service struct {
*commonservice.BaseService
// contains filtered or unexported fields
}
Service implements the NeoAccounts service marble.
func (*Service) BatchSign ¶
func (s *Service) BatchSign(ctx context.Context, serviceID string, requests []SignRequest) *BatchSignResponse
BatchSign signs multiple transaction hashes.
func (*Service) DeployContract ¶
func (s *Service) DeployContract(ctx context.Context, serviceID, accountID, nefBase64, manifestJSON string, data any) (*DeployContractResponse, error)
DeployContract deploys a new smart contract using a pool account. All signing happens inside TEE - private keys never leave the enclave.
func (*Service) DeployMaster ¶
func (s *Service) DeployMaster(ctx context.Context, nefBase64, manifestJSON string, data any) (*DeployMasterResponse, error)
DeployMaster deploys a new smart contract using the master wallet (TEE_PRIVATE_KEY). This is used for deploying contracts where the master account needs to be the Admin. All signing happens inside TEE - private keys never leave the enclave.
func (*Service) FundAccount ¶
func (s *Service) FundAccount(ctx context.Context, toAddress string, amount int64, tokenAddress string) (*FundAccountResponse, error)
FundAccount transfers tokens from the master wallet (TEE_PRIVATE_KEY) to a target address. This is used to fund pool accounts with GAS for transaction fees. Unlike Transfer(), this uses the master wallet directly, not a pool account. After successful transfer, updates the database balance for the target account.
func (*Service) GetPoolInfo ¶
func (s *Service) GetPoolInfo(ctx context.Context) (*PoolInfoResponse, error)
GetPoolInfo returns pool statistics with per-token breakdowns.
func (*Service) InvokeContract ¶
func (s *Service) InvokeContract(ctx context.Context, serviceID, accountID, contractAddress, method string, params []ContractParam, scope string) (*InvokeContractResponse, error)
InvokeContract invokes a contract method using a pool account. All signing happens inside TEE - private keys never leave the enclave.
func (*Service) InvokeMaster ¶
func (s *Service) InvokeMaster(ctx context.Context, contractAddress, method string, params []ContractParam, scope string) (*InvokeContractResponse, error)
InvokeMaster invokes a contract method using the master wallet (TEE_PRIVATE_KEY). This is used for TEE operations like PriceFeed and RandomnessLog that require the caller to be a registered TEE signer in AppRegistry. Unlike InvokeContract(), this uses the master wallet directly, not a pool account.
func (*Service) ListAccountsByService ¶
func (s *Service) ListAccountsByService(ctx context.Context, serviceID, tokenType string, minBalance *int64) ([]AccountInfo, error)
ListAccountsByService returns accounts locked by a specific service. DESIGN: Read-only operation, no mutex needed - data comes from DB.
func (*Service) ListLowBalanceAccounts ¶
func (s *Service) ListLowBalanceAccounts(ctx context.Context, tokenType string, maxBalance int64, limit int) ([]AccountInfo, error)
ListLowBalanceAccounts returns accounts with balance below the specified threshold. This is useful for auto top-up workers that need to find accounts requiring funding. DESIGN: Read-only operation, no mutex needed - data comes from DB.
func (*Service) ReleaseAccounts ¶
func (s *Service) ReleaseAccounts(ctx context.Context, serviceID string, accountIDs []string) (int, error)
ReleaseAccounts releases previously locked accounts. DESIGN: Uses atomic DB operations, no mutex needed for concurrent safety.
func (*Service) ReleaseAllByService ¶
ReleaseAllByService releases all accounts locked by a service. DESIGN: Uses atomic DB operations per account, no global mutex needed.
func (*Service) RequestAccounts ¶
func (s *Service) RequestAccounts(ctx context.Context, serviceID string, count int, purpose string) (accounts []AccountInfo, lockID string, err error)
RequestAccounts locks and returns accounts for a service. DESIGN: Database operations (TryLockAccount) are atomic at DB level. The mutex is only used for in-memory operations to avoid holding locks during I/O.
func (*Service) SignTransaction ¶
func (s *Service) SignTransaction(ctx context.Context, serviceID, accountID string, txHash []byte) (*SignTransactionResponse, error)
SignTransaction signs a transaction hash with an account's private key. The account must be locked by the requesting service.
func (*Service) SimulateContract ¶
func (s *Service) SimulateContract(ctx context.Context, serviceID, accountID, contractAddress, method string, params []ContractParam) (*SimulateContractResponse, error)
SimulateContract simulates a contract invocation without signing or broadcasting.
func (*Service) Transfer ¶
func (s *Service) Transfer(ctx context.Context, serviceID, accountID, toAddress string, amount int64, tokenHash string) (string, error)
Transfer transfers tokens from a pool account to a target address. The account must be locked by the requesting service.
The transfer is executed as an on-chain NEP-17 `transfer(from,to,amount,data)` invocation signed by the pool account's derived private key.
func (*Service) TransferWithData ¶
func (s *Service) TransferWithData(ctx context.Context, serviceID, accountID, toAddress string, amount int64, data string) (string, error)
TransferWithData transfers GAS from a pool account to a target address with optional data. The data parameter is passed to the OnNEP17Payment callback of the receiving contract. This is used for payments to contracts like PaymentHub that need to identify the payment source.
func (*Service) UpdateBalance ¶
func (s *Service) UpdateBalance(ctx context.Context, serviceID, accountID, tokenType string, delta int64, absolute *int64) (oldBalance, newBalance, txCount int64, err error)
UpdateBalance updates an account's token balance. SECURITY FIX: Added integer overflow/underflow protection. Uses atomic DB operations with lock verification to prevent race conditions.
func (*Service) UpdateContract ¶
func (s *Service) UpdateContract(ctx context.Context, serviceID, accountID, contractAddress, nefBase64, manifestJSON string, data any) (*UpdateContractResponse, error)
UpdateContract updates an existing smart contract using a pool account. All signing happens inside TEE - private keys never leave the enclave.
type SignRequest ¶
type SignRequest = neoaccountstypes.SignRequest
SignRequest represents a single signing request within a batch.
type SignTransactionInput ¶
type SignTransactionInput = neoaccountstypes.SignTransactionInput
SignTransactionInput for signing a transaction with an account's private key.
type SignTransactionResponse ¶
type SignTransactionResponse = neoaccountstypes.SignTransactionResponse
SignTransactionResponse returns the signature.
type SimulateContractInput ¶
type SimulateContractInput = neoaccountstypes.SimulateContractInput
SimulateContractInput simulates a contract invocation without signing.
type SimulateContractResponse ¶
type SimulateContractResponse = neoaccountstypes.SimulateContractResponse
SimulateContractResponse returns the simulation result.
type TokenBalance ¶
type TokenBalance = neoaccountstypes.TokenBalance
TokenBalance is the API representation of a token balance.
type TokenStats ¶
type TokenStats = neoaccountstypes.TokenStats
TokenStats represents aggregated statistics for a token type.
type TransferInput ¶
type TransferInput = neoaccountstypes.TransferInput
TransferInput for transferring tokens from a pool account.
type TransferResponse ¶
type TransferResponse = neoaccountstypes.TransferResponse
TransferResponse returns the transfer result.
type TransferWithDataInput ¶
type TransferWithDataInput = neoaccountstypes.TransferWithDataInput
TransferWithDataInput for transferring GAS with data to a contract.
type TransferWithDataResponse ¶
type TransferWithDataResponse = neoaccountstypes.TransferWithDataResponse
TransferWithDataResponse returns the transfer with data result.
type UpdateBalanceInput ¶
type UpdateBalanceInput = neoaccountstypes.UpdateBalanceInput
UpdateBalanceInput for updating an account's token balance.
type UpdateBalanceResponse ¶
type UpdateBalanceResponse = neoaccountstypes.UpdateBalanceResponse
UpdateBalanceResponse confirms balance update.
type UpdateContractInput ¶
type UpdateContractInput = neoaccountstypes.UpdateContractInput
UpdateContractInput updates an existing contract using a pool account.
type UpdateContractResponse ¶
type UpdateContractResponse = neoaccountstypes.UpdateContractResponse
UpdateContractResponse returns the update result.