diff --git a/src/client/lcd/LCDClient.ts b/src/client/lcd/LCDClient.ts index 2f843ee9e..aa60cae33 100644 --- a/src/client/lcd/LCDClient.ts +++ b/src/client/lcd/LCDClient.ts @@ -3,6 +3,7 @@ import { AuthAPI, BankAPI, DistributionAPI, + FeeGrantAPI, GovAPI, MarketAPI, MintAPI, @@ -86,6 +87,7 @@ export class LCDClient { public auth: AuthAPI; public bank: BankAPI; public distribution: DistributionAPI; + public feeGrant: FeeGrantAPI; public gov: GovAPI; public market: MarketAPI; public mint: MintAPI; @@ -120,6 +122,7 @@ export class LCDClient { this.auth = new AuthAPI(this.apiRequester); this.bank = new BankAPI(this.apiRequester); this.distribution = new DistributionAPI(this.apiRequester); + this.feeGrant = new FeeGrantAPI(this.apiRequester); this.gov = new GovAPI(this.apiRequester); this.market = new MarketAPI(this.apiRequester); this.mint = new MintAPI(this.apiRequester); diff --git a/src/client/lcd/api/FeeGrantAPI.spec.ts b/src/client/lcd/api/FeeGrantAPI.spec.ts new file mode 100644 index 000000000..f7c36b304 --- /dev/null +++ b/src/client/lcd/api/FeeGrantAPI.spec.ts @@ -0,0 +1,44 @@ +import { APIRequester } from '../APIRequester'; +import { FeeGrantAPI } from './FeeGrantAPI'; + +const c = new APIRequester('https://bombay-lcd.terra.dev/'); +const feeGrant = new FeeGrantAPI(c); + +describe('FeeGrantAPI', () => { + it('allowances', async () => { + const res = await feeGrant.allowances( + 'terra1p204wtykwke52hcyt6vdh630725rdayczyzcvz' + ); + + expect(res.allowances[0]).toMatchObject({ + granter: expect.any(String), + grantee: expect.any(String), + }); + + const allowanceData = res.allowances[0].allowance.toData(); + expect(allowanceData['@type']).toMatch(/cosmos.feegrant.v1beta1/g); + + expect(res.pagination).not.toBeUndefined(); + }); + + describe('allowance', () => { + it('allowance exist', async () => { + const res = await feeGrant.allowance( + 'terra13ggppncs97f4cl90fvxqelflg0upedd0n7rnd3', + 'terra1p204wtykwke52hcyt6vdh630725rdayczyzcvz' + ); + + const allowanceData = res.toData(); + expect(allowanceData['@type']).toMatch(/cosmos.feegrant.v1beta1/g); + }); + + it('allowance not exist', async () => { + expect( + feeGrant.allowance( + 'terra1p204wtykwke52hcyt6vdh630725rdayczyzcvz', + 'terra13ggppncs97f4cl90fvxqelflg0upedd0n7rnd3' + ) + ).rejects.toThrow(); + }); + }); +}); diff --git a/src/client/lcd/api/FeeGrantAPI.ts b/src/client/lcd/api/FeeGrantAPI.ts new file mode 100644 index 000000000..d038a673b --- /dev/null +++ b/src/client/lcd/api/FeeGrantAPI.ts @@ -0,0 +1,51 @@ +import { AccAddress } from '../../../core'; +import { BaseAPI } from './BaseAPI'; +import { Allowance } from '../../../core/feegrant/allowances'; +import { Pagination, PaginationOptions } from '../APIRequester'; + +export class FeeGrantAPI extends BaseAPI { + public async allowances( + grantee: AccAddress, + params: Partial = {} + ): Promise<{ + allowances: { + granter: AccAddress; + grantee: AccAddress; + allowance: Allowance; + }[]; + pagination: Pagination; + }> { + return this.c + .get<{ + allowances: { + granter: AccAddress; + grantee: AccAddress; + allowance: Allowance.Data; + }[]; + pagination: Pagination; + }>(`/cosmos/feegrant/v1beta1/allowances/${grantee}`, params) + .then(d => ({ + allowances: d.allowances.map(allowance => ({ + granter: allowance.granter, + grantee: allowance.grantee, + allowance: Allowance.fromData(allowance.allowance), + })), + pagination: d.pagination, + })); + } + + public async allowance( + granter: AccAddress, + grantee: AccAddress + ): Promise { + return this.c + .get<{ + allowance: { + granter: AccAddress; + grantee: AccAddress; + allowance: Allowance.Data; + }; + }>(`/cosmos/feegrant/v1beta1/allowance/${granter}/${grantee}`) + .then(d => Allowance.fromData(d.allowance.allowance)); + } +} diff --git a/src/client/lcd/api/index.ts b/src/client/lcd/api/index.ts index 4b3d73c6c..15a13c8c8 100644 --- a/src/client/lcd/api/index.ts +++ b/src/client/lcd/api/index.ts @@ -1,6 +1,7 @@ export * from './AuthAPI'; export * from './BankAPI'; export * from './DistributionAPI'; +export * from './FeeGrantAPI'; export * from './GovAPI'; export * from './MarketAPI'; export * from './AuthzAPI';