|
| 1 | +import { Controller, Post, Get, Body, Query } from '@nestjs/common'; |
| 2 | +import { TokenFactoryService } from './token-factory.service'; |
| 3 | +import { MintDto } from './dto/mint.dto'; |
| 4 | +import { SetAdminDto } from './dto/set-admin.dto'; |
| 5 | +import { ApproveDto } from './dto/approve.dto'; |
| 6 | +import { TransferDto } from './dto/transfer.dto'; |
| 7 | +import { TransferFromDto } from './dto/transfer-from.dto'; |
| 8 | +import { BurnDto } from './dto/burn.dto'; |
| 9 | +import { BurnFromDto } from './dto/burn-from.dto'; |
| 10 | + |
| 11 | +@Controller('token-factory') |
| 12 | +export class TokenFactoryController { |
| 13 | + constructor(private readonly tokenFactoryService: TokenFactoryService) {} |
| 14 | + |
| 15 | + // ── POST endpoints (writes) ── |
| 16 | + |
| 17 | + @Post('mint') |
| 18 | + async mint(@Body() dto: MintDto) { |
| 19 | + const unsignedXdr = await this.tokenFactoryService.mint(dto); |
| 20 | + return { unsignedXdr }; |
| 21 | + } |
| 22 | + |
| 23 | + @Post('set-admin') |
| 24 | + async setAdmin(@Body() dto: SetAdminDto) { |
| 25 | + const unsignedXdr = await this.tokenFactoryService.setAdmin(dto); |
| 26 | + return { unsignedXdr }; |
| 27 | + } |
| 28 | + |
| 29 | + @Post('approve') |
| 30 | + async approve(@Body() dto: ApproveDto) { |
| 31 | + const unsignedXdr = await this.tokenFactoryService.approve(dto); |
| 32 | + return { unsignedXdr }; |
| 33 | + } |
| 34 | + |
| 35 | + @Post('transfer') |
| 36 | + async transfer(@Body() dto: TransferDto) { |
| 37 | + const unsignedXdr = await this.tokenFactoryService.transfer(dto); |
| 38 | + return { unsignedXdr }; |
| 39 | + } |
| 40 | + |
| 41 | + @Post('transfer-from') |
| 42 | + async transferFrom(@Body() dto: TransferFromDto) { |
| 43 | + const unsignedXdr = await this.tokenFactoryService.transferFrom(dto); |
| 44 | + return { unsignedXdr }; |
| 45 | + } |
| 46 | + |
| 47 | + @Post('burn') |
| 48 | + async burn(@Body() dto: BurnDto) { |
| 49 | + const unsignedXdr = await this.tokenFactoryService.burn(dto); |
| 50 | + return { unsignedXdr }; |
| 51 | + } |
| 52 | + |
| 53 | + @Post('burn-from') |
| 54 | + async burnFrom(@Body() dto: BurnFromDto) { |
| 55 | + const unsignedXdr = await this.tokenFactoryService.burnFrom(dto); |
| 56 | + return { unsignedXdr }; |
| 57 | + } |
| 58 | + |
| 59 | + // ── GET endpoints (reads) ── |
| 60 | + |
| 61 | + @Get('balance') |
| 62 | + async getBalance( |
| 63 | + @Query('contractId') contractId: string, |
| 64 | + @Query('address') address: string, |
| 65 | + @Query('callerPublicKey') callerPublicKey: string, |
| 66 | + ) { |
| 67 | + const balance = await this.tokenFactoryService.getBalance(contractId, address, callerPublicKey); |
| 68 | + return { balance: String(balance) }; |
| 69 | + } |
| 70 | + |
| 71 | + @Get('allowance') |
| 72 | + async getAllowance( |
| 73 | + @Query('contractId') contractId: string, |
| 74 | + @Query('from') from: string, |
| 75 | + @Query('spender') spender: string, |
| 76 | + @Query('callerPublicKey') callerPublicKey: string, |
| 77 | + ) { |
| 78 | + const allowance = await this.tokenFactoryService.getAllowance( |
| 79 | + contractId, |
| 80 | + from, |
| 81 | + spender, |
| 82 | + callerPublicKey, |
| 83 | + ); |
| 84 | + return { allowance: String(allowance) }; |
| 85 | + } |
| 86 | + |
| 87 | + @Get('decimals') |
| 88 | + async getDecimals( |
| 89 | + @Query('contractId') contractId: string, |
| 90 | + @Query('callerPublicKey') callerPublicKey: string, |
| 91 | + ) { |
| 92 | + const decimals = await this.tokenFactoryService.getDecimals(contractId, callerPublicKey); |
| 93 | + return { decimals }; |
| 94 | + } |
| 95 | + |
| 96 | + @Get('name') |
| 97 | + async getName( |
| 98 | + @Query('contractId') contractId: string, |
| 99 | + @Query('callerPublicKey') callerPublicKey: string, |
| 100 | + ) { |
| 101 | + const name = await this.tokenFactoryService.getName(contractId, callerPublicKey); |
| 102 | + return { name: String(name) }; |
| 103 | + } |
| 104 | + |
| 105 | + @Get('symbol') |
| 106 | + async getSymbol( |
| 107 | + @Query('contractId') contractId: string, |
| 108 | + @Query('callerPublicKey') callerPublicKey: string, |
| 109 | + ) { |
| 110 | + const symbol = await this.tokenFactoryService.getSymbol(contractId, callerPublicKey); |
| 111 | + return { symbol: String(symbol) }; |
| 112 | + } |
| 113 | + |
| 114 | + @Get('escrow-id') |
| 115 | + async getEscrowId( |
| 116 | + @Query('contractId') contractId: string, |
| 117 | + @Query('callerPublicKey') callerPublicKey: string, |
| 118 | + ) { |
| 119 | + const escrowId = await this.tokenFactoryService.getEscrowId(contractId, callerPublicKey); |
| 120 | + return { escrowId: String(escrowId) }; |
| 121 | + } |
| 122 | +} |
0 commit comments