-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
119 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import express, { Request, Response } from 'express'; | ||
import { inject, injectable } from 'inversify'; | ||
import { ControllerBase } from './ControllerBase'; | ||
import { IControllerBase } from './IControllerBase'; | ||
import { ContainerTypes } from '../containertypes'; | ||
import { IBurnService } from '../services/BurnService'; | ||
import { NetworkType } from '../networks'; | ||
|
||
@injectable() | ||
export class BurnController extends ControllerBase implements IControllerBase { | ||
constructor(@inject(ContainerTypes.BurnService) private _burnService: IBurnService) { | ||
super(); | ||
} | ||
|
||
public register(app: express.Application): void { | ||
/** | ||
* @description Burn events route | ||
*/ | ||
app.route('/api/v1/:network/burn/events').get(async (req: Request, res: Response) => { | ||
/* | ||
#swagger.description = 'Retrieves burn events for a given network.' | ||
#swagger.tags = ['Burn'] | ||
#swagger.parameters['network'] = { | ||
in: 'path', | ||
description: 'The network name. Supported networks: astar, shiden, shibuya', | ||
required: true, | ||
enum: ['astar', 'shiden', 'shibuya'] | ||
} | ||
*/ | ||
try { | ||
const network = req.params.network as NetworkType; | ||
res.json(await this._burnService.getBurnEvents(network)); | ||
} catch (err) { | ||
this.handleError(res, err as Error); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { injectable } from 'inversify'; | ||
import { NetworkType } from '../networks'; | ||
import axios from 'axios'; | ||
import { DappStakingV3IndexerBase } from './DappStakingV3IndexerBase'; | ||
|
||
export type BurnEvent = { | ||
blockNumber: number; | ||
timestamp: number; | ||
amount: bigint; | ||
user: string; | ||
}; | ||
|
||
export interface IBurnService { | ||
getBurnEvents(network: NetworkType): Promise<BurnEvent[]>; | ||
} | ||
|
||
@injectable() | ||
export class BurnService extends DappStakingV3IndexerBase implements IBurnService { | ||
public async getBurnEvents(network: NetworkType): Promise<BurnEvent[]> { | ||
this.GuardNetwork(network); | ||
|
||
try { | ||
const result = await axios.post(this.getApiUrl(network), { | ||
query: `query { | ||
burns(orderBy: id_ASC) { | ||
blockNumber | ||
timestamp | ||
user | ||
amount | ||
} | ||
}`, | ||
}); | ||
|
||
return result.data.data.burns; | ||
} catch (e) { | ||
console.error(e); | ||
return []; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Guard } from '../guard'; | ||
import { NetworkType } from '../networks'; | ||
import { ServiceBase } from './ServiceBase'; | ||
|
||
export class DappStakingV3IndexerBase extends ServiceBase { | ||
protected GuardNetwork(network: NetworkType) { | ||
Guard.ThrowIfUndefined('network', network); | ||
if (!['shibuya', 'shiden', 'astar'].includes(network)) { | ||
throw new Error(`This method is not supported for the network ${network}`); | ||
} | ||
} | ||
|
||
protected getApiUrl(network: NetworkType): string { | ||
// For local development: `http://localhost:4350/graphql`; | ||
return `https://astar-network.squids.live/dapps-staking-indexer-${network}/graphql`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters