|
| 1 | +import { Route, Path, Controller, Get, Query } from 'tsoa' |
| 2 | +import { provideSingleton } from '../../../inversify/ioc'; |
| 3 | +import { inject } from 'inversify'; |
| 4 | +import { TYPES } from '../../../inversify/types'; |
| 5 | +import { StorageRecover } from '../service/StorageRecover'; |
| 6 | +import { Web3Configuration } from '../../blockchain/Web3Configuration'; |
| 7 | +import { logger } from '../../../Logger' |
| 8 | + |
| 9 | +@Route('storage') |
| 10 | +@provideSingleton(StorageRecoverController) |
| 11 | +export class StorageRecoverController extends Controller { |
| 12 | + |
| 13 | + constructor(@inject(TYPES.StorageRecover) private storageRecover: StorageRecover) { |
| 14 | + super() |
| 15 | + } |
| 16 | + |
| 17 | + @Get('{contractAddress}') |
| 18 | + async getStorage( |
| 19 | + @Path() contractAddress: string, |
| 20 | + @Query('startBlock') startBlock: number, |
| 21 | + @Query('endBlock') endBlock: number, |
| 22 | + @Query('blockchainHost') blockchainHost?: string, |
| 23 | + @Query('blockchainProtocol') blockchainProtocol?: string, |
| 24 | + @Query('blockchainBasicAuthUsername') blockchainBasicAuthUsername?: string, |
| 25 | + @Query('blockchainBasicAuthPassword') blockchainBasicAuthPassword?: string, |
| 26 | + @Query('existingStorage') existingStorage?: string |
| 27 | + ) { |
| 28 | + try { |
| 29 | + const config = { |
| 30 | + blockchainHost, |
| 31 | + blockchainProtocol, |
| 32 | + blockchainBasicAuthUsername, |
| 33 | + blockchainBasicAuthPassword |
| 34 | + } as Web3Configuration |
| 35 | + return this.storageRecover.recoverStorage(contractAddress, startBlock, endBlock, config, existingStorage) |
| 36 | + } catch (err) { |
| 37 | + logger.error(err) |
| 38 | + throw new Error(err.message) |
| 39 | + } |
| 40 | + } |
| 41 | +} |
0 commit comments