From 6d57a6671fdfadbc98127ef98e86f28cc50143fb Mon Sep 17 00:00:00 2001 From: Benoit Devos Date: Fri, 5 Jul 2024 11:57:15 +0200 Subject: [PATCH] feat: add address type when fetching loc requests. logion-network/logion-internal#1312 --- resources/schemas.json | 5 ++++- src/logion/controllers/components.ts | 3 ++- src/logion/controllers/locrequest.controller.ts | 11 ++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/resources/schemas.json b/resources/schemas.json index bcf1e27..abe5a2d 100644 --- a/resources/schemas.json +++ b/resources/schemas.json @@ -1215,7 +1215,10 @@ }, "requesterAddress": { "type": "string", - "description": "The SS58 address of the requester in expected LOC Requests" + "description": "The address of the requester in expected LOC Requests" + }, + "requesterAddressType": { + "$ref": "#/components/schemas/AddressType" }, "statuses": { "type": "array", diff --git a/src/logion/controllers/components.ts b/src/logion/controllers/components.ts index f63364e..c638569 100644 --- a/src/logion/controllers/components.ts +++ b/src/logion/controllers/components.ts @@ -653,8 +653,9 @@ export interface components { FetchLocRequestsSpecificationView: { /** @description The SS58 address of the owner in expected LOC Requests */ ownerAddress?: string; - /** @description The SS58 address of the requester in expected LOC Requests */ + /** @description The address of the requester in expected LOC Requests */ requesterAddress?: string; + requesterAddressType?: components["schemas"]["AddressType"]; /** @description The statuses of expected LOC Requests */ statuses?: components["schemas"]["LocRequestStatus"][]; /** @description The type of the LOC to fetch */ diff --git a/src/logion/controllers/locrequest.controller.ts b/src/logion/controllers/locrequest.controller.ts index 7f794ca..fe8bda3 100644 --- a/src/logion/controllers/locrequest.controller.ts +++ b/src/logion/controllers/locrequest.controller.ts @@ -389,7 +389,16 @@ export class LocRequestController extends ApiController { @Async() async fetchRequests(specificationView: FetchLocRequestsSpecificationView): Promise { const authenticatedUser = await this.authenticationService.authenticatedUser(this.request); - const requester = specificationView.requesterAddress ? ValidAccountId.polkadot(specificationView.requesterAddress) : undefined; + let requester: ValidAccountId | undefined = undefined; + const address = specificationView.requesterAddress; + if (address) { + const type = specificationView.requesterAddressType; + if (type) { + requester = validAccountId({ address, type }) + } else { + requester = ValidAccountId.fromUnknown(address) + } + } const owner = specificationView.ownerAddress ? ValidAccountId.polkadot(specificationView.ownerAddress) : undefined; authenticatedUser.require(authenticatedUser => authenticatedUser.isOneOf([ requester, owner ])); const specification: FetchLocRequestsSpecification = {