Skip to content

Commit

Permalink
Merge pull request #314 from logion-network/fix/fetch-for-any-account
Browse files Browse the repository at this point in the history
Add address type when fetching loc requests.
  • Loading branch information
benoitdevos committed Jul 8, 2024
2 parents e6a84a3 + 6d57a66 commit 0de77fb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion resources/schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/logion/controllers/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
11 changes: 10 additions & 1 deletion src/logion/controllers/locrequest.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,16 @@ export class LocRequestController extends ApiController {
@Async()
async fetchRequests(specificationView: FetchLocRequestsSpecificationView): Promise<FetchLocRequestsResponseView> {
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 = {
Expand Down

0 comments on commit 0de77fb

Please sign in to comment.