Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/prod'
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitdevos committed May 13, 2024
2 parents 3822cff + 0820a10 commit 1d811c7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/logion/model/verifiedissuerselection.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export class VerifiedIssuerSelectionRepository {
return this.repository.findBy(dbSpec);
}

async unselectAll(issuer: string) {
async unselectAll(issuerAccount: ValidAccountId) {
const issuer = issuerAccount.getAddress(DB_SS58_PREFIX);
await this.repository.update({ issuer }, { selected: false });
}
}
Expand Down
49 changes: 23 additions & 26 deletions src/logion/services/locsynchronization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,35 +227,32 @@ export class LocSynchronizer {
const nominated = extrinsic.call.method === "nominateIssuer";
const legalOfficerAddress = ValidAccountId.polkadot(requireDefined(extrinsic.signer));
if(await this.directoryService.isLegalOfficerAddressOnNode(legalOfficerAddress)) {
const issuerAddress = Adapters.asString(extrinsic.call.args["issuer"]);
const identityLoc = await this.getIssuerIdentityLoc(legalOfficerAddress, issuerAddress);
if(identityLoc) {
logger.info("Handling nomination/dismissal of issuer %s", issuerAddress);
if(!nominated) {
this.verifiedIssuerSelectionService.unselectAll(issuerAddress);
}
this.notifyVerifiedIssuerNominatedDismissed({
legalOfficerAddress,
nominated,
issuer: identityLoc.getDescription().userIdentity,
});
const issuerAccount = ValidAccountId.polkadot(Adapters.asString(extrinsic.call.args["issuer"]));
const identityLoc = await this.getIssuerIdentityLoc(legalOfficerAddress, issuerAccount);
logger.info("Handling nomination/dismissal of issuer %s", issuerAccount.address);
if(!nominated) {
this.verifiedIssuerSelectionService.unselectAll(issuerAccount);
}
this.notifyVerifiedIssuerNominatedDismissed({
legalOfficerAddress,
nominated,
issuer: identityLoc.getDescription().userIdentity,
});
}
}

private async getIssuerIdentityLoc(legalOfficerAddress: ValidAccountId, issuerAddress: string) {
const api = await this.polkadotService.readyApi();
const verifiedIssuer = await api.polkadot.query.logionLoc.verifiedIssuersMap(legalOfficerAddress.address, issuerAddress);
if(verifiedIssuer.isNone) {
throw new Error(`${issuerAddress} is not an issuer of LO ${legalOfficerAddress}`);
}

const identityLocId = api.adapters.fromLocId(verifiedIssuer.unwrap().identityLoc);
const identityLoc = await this.locRequestRepository.findById(identityLocId.toString());
if(!identityLoc) {
private async getIssuerIdentityLoc(legalOfficerAddress: ValidAccountId, issuerAddress: ValidAccountId): Promise<LocRequestAggregateRoot> {
const identityLocs = await this.locRequestRepository.findBy({
expectedLocTypes: [ "Identity" ],
expectedIdentityLocType: "Polkadot",
expectedOwnerAddress: [ legalOfficerAddress ],
expectedRequesterAddress: issuerAddress,
expectedStatuses: [ "CLOSED" ]
});
if(identityLocs.length < 1) {
throw new Error("No Identity LOC available for issuer");
}
return identityLoc;
return identityLocs[0];
}

private async notifyVerifiedIssuerNominatedDismissed(args: {
Expand Down Expand Up @@ -283,13 +280,13 @@ export class LocSynchronizer {
private async handleIssuerSelectedUnselected(extrinsic: JsonExtrinsic) {
const legalOfficerAddress = ValidAccountId.polkadot(requireDefined(extrinsic.signer));
if(await this.directoryService.isLegalOfficerAddressOnNode(legalOfficerAddress)) {
const issuerAddress = Adapters.asString(extrinsic.call.args["issuer"]);
const identityLoc = await this.getIssuerIdentityLoc(legalOfficerAddress, issuerAddress);
const issuerAccount = ValidAccountId.polkadot(Adapters.asString(extrinsic.call.args["issuer"]));
const identityLoc = await this.getIssuerIdentityLoc(legalOfficerAddress, issuerAccount);
const selected = extrinsic.call.args["selected"] as boolean;
const requestId = extractUuid("loc_id", extrinsic.call.args);
const locRequest = requireDefined(await this.locRequestRepository.findById(requestId));

logger.info("Handling selection/unselection of issuer %s", issuerAddress);
logger.info("Handling selection/unselection of issuer %s", issuerAccount.address);
this.verifiedIssuerSelectionService.selectUnselect(locRequest, identityLoc, selected);
this.notifyVerifiedIssuerSelectedUnselected({
legalOfficerAddress,
Expand Down
9 changes: 5 additions & 4 deletions src/logion/services/verifiedissuerselection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DefaultTransactional, requireDefined } from "@logion/rest-api-core";
import { injectable } from "inversify";
import { LocRequestAggregateRoot } from "../model/locrequest.model.js";
import { VerifiedIssuerAggregateRoot, VerifiedIssuerSelectionFactory, VerifiedIssuerSelectionId, VerifiedIssuerSelectionRepository } from "../model/verifiedissuerselection.model.js";
import { ValidAccountId } from "@logion/node-api";

export abstract class VerifiedIssuerSelectionService {

Expand Down Expand Up @@ -29,8 +30,8 @@ export abstract class VerifiedIssuerSelectionService {
} // else (!selection && !select) -> skip
}

async unselectAll(issuerAddress: string) {
await this.verifiedIssuerSelectionRepository.unselectAll(issuerAddress);
async unselectAll(issuerAccount: ValidAccountId) {
await this.verifiedIssuerSelectionRepository.unselectAll(issuerAccount);
}
}

Expand All @@ -55,8 +56,8 @@ export class TransactionalVerifiedIssuerSelectionService extends VerifiedIssuerS
}

@DefaultTransactional()
async unselectAll(issuerAddress: string) {
return super.unselectAll(issuerAddress);
async unselectAll(issuerAccount: ValidAccountId) {
return super.unselectAll(issuerAccount);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe("VerifiedIssuerSelectionRepository - write", () => {
});

it("unselects by issuer LOC ID", async () => {
await repository.unselectAll("5EBxoSssqNo23FvsDeUxjyQScnfEiGxJaNwuwqBH2Twe35BX");
await repository.unselectAll(ValidAccountId.polkadot("5EBxoSssqNo23FvsDeUxjyQScnfEiGxJaNwuwqBH2Twe35BX"));
checkNumOfRows(`SELECT * FROM issuer_selection WHERE issuer = '5EBxoSssqNo23FvsDeUxjyQScnfEiGxJaNwuwqBH2Twe35BX' AND selected IS TRUE`, 0);
});
});

0 comments on commit 1d811c7

Please sign in to comment.