diff --git a/backend/src/stellar/stellar.exceptions.ts b/backend/src/stellar/stellar.exceptions.ts new file mode 100644 index 0000000..0fc5db5 --- /dev/null +++ b/backend/src/stellar/stellar.exceptions.ts @@ -0,0 +1,24 @@ +import { HttpException, HttpStatus } from '@nestjs/common'; + +/** + * Custom exception for Stellar RPC errors + */ +export class StellarRpcException extends HttpException { + constructor( + message: string, + public readonly originalError?: any, + public readonly contractId?: string, + public readonly method?: string, + ) { + super( + { + message, + error: 'Stellar RPC Error', + originalError: originalError?.message || originalError, + contractId, + method, + }, + HttpStatus.BAD_GATEWAY, + ); + } +} \ No newline at end of file diff --git a/backend/src/stellar/stellar.service.ts b/backend/src/stellar/stellar.service.ts index 9823a17..64a0641 100644 --- a/backend/src/stellar/stellar.service.ts +++ b/backend/src/stellar/stellar.service.ts @@ -1,6 +1,18 @@ import { Injectable, OnModuleInit, Logger } from '@nestjs/common'; -import { rpc, Contract } from '@stellar/stellar-sdk'; +import { rpc, Contract, Address, xdr } from '@stellar/stellar-sdk'; import { ConfigService } from '../config/config.service'; +import { StellarRpcException } from './stellar.exceptions'; +import { + ChainType, + GetOwnerResult, + ResolveStellarResult, + GetChainAddressResult, + GetVaultBalanceResult, + GetScheduledPaymentResult, + IsVaultActiveResult, + GetCreatedAtResult, + ScheduledPayment, +} from './stellar.types'; @Injectable() export class StellarService implements OnModuleInit { diff --git a/backend/src/stellar/stellar.types.ts b/backend/src/stellar/stellar.types.ts new file mode 100644 index 0000000..103f86e --- /dev/null +++ b/backend/src/stellar/stellar.types.ts @@ -0,0 +1,49 @@ +/** + * TypeScript interfaces for Stellar contract return types + */ + +export enum ChainType { + Evm = 'Evm', + Bitcoin = 'Bitcoin', + Solana = 'Solana', + Cosmos = 'Cosmos', +} + +export enum PrivacyMode { + Normal = 'Normal', + Shielded = 'Shielded', +} + +export interface ScheduledPayment { + from: string; + to: string; + token: string; + amount: string; + release_at: number; + executed: boolean; +} + +export interface VaultConfig { + owner: string; + token: string; + created_at: number; +} + +export interface VaultState { + balance: string; + is_active: boolean; +} + +export interface ResolveData { + wallet: string; + memo?: number; +} + +// Contract method return types +export type GetOwnerResult = string | null; +export type ResolveStellarResult = string; +export type GetChainAddressResult = string | null; +export type GetVaultBalanceResult = string | null; +export type GetScheduledPaymentResult = ScheduledPayment | null; +export type IsVaultActiveResult = boolean | null; +export type GetCreatedAtResult = number | null; \ No newline at end of file