Skip to content

Commit

Permalink
Merge pull request #272 from logion-network/fix/create-or-update-llo
Browse files Browse the repository at this point in the history
Query the baseUrl when calling createOrUpdate.
  • Loading branch information
gdethier committed Jun 24, 2024
2 parents f494b9c + 977c98f commit c570e3a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
5 changes: 2 additions & 3 deletions packages/client-node/integration/LegalOfficer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { State } from "./Utils.js";
import { LegalOfficer } from "@logion/client/dist/Types.js";
import { LegalOfficer, CreateOrUpdateLegalOfficer } from "@logion/client";
export async function backendConfig(state: State) {
const { client, requesterAccount, alice } = state;

Expand All @@ -23,8 +23,7 @@ export async function workload(state: State) {

export async function updateLegalOfficer(state: State) {
const { client, alice } = state;
const updatedAlice: LegalOfficer = {
node: alice.node,
const updatedAlice: CreateOrUpdateLegalOfficer = {
userIdentity: {
firstName: "Alice",
lastName: "updated-last-name",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@logion/client",
"version": "0.46.0-2",
"version": "0.46.0-6",
"description": "logion SDK for client applications",
"main": "dist/index.js",
"packageManager": "yarn@3.2.0",
Expand Down
15 changes: 11 additions & 4 deletions packages/client/src/LegalOfficerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AxiosFactory } from "./AxiosFactory.js";
import { LegalOfficer, LegalOfficerClass, LegalOfficerPostalAddress, UserIdentity } from "./Types.js";
import { MultiSourceHttpClient, aggregateArrays, Endpoint, MultiSourceHttpClientState } from "./Http.js";
import { newBackendError } from "./Error.js";
import { requireDefined } from "./assertions.js";

interface BackendLegalOfficer {
userIdentity: UserIdentity;
Expand All @@ -17,7 +18,7 @@ interface BackendLegalOfficer {
}

export interface CreateOrUpdateLegalOfficer {
node: string;
account: ValidAccountId;
userIdentity: UserIdentity;
postalAddress: LegalOfficerPostalAddress;
additionalDetails: string;
Expand All @@ -38,7 +39,7 @@ export class LegalOfficerClient {

private readonly token: string | undefined;

private api: LogionNodeApiClass;
private readonly api: LogionNodeApiClass;

async getLegalOfficers(): Promise<LegalOfficerClass[]> {
const onchain = await this.api.polkadot.query.loAuthorityList.legalOfficerSet.entries();
Expand Down Expand Up @@ -144,9 +145,15 @@ export class LegalOfficerClient {
if(!this.authenticated) {
throw new Error("Authentication is required");
}
const legalOfficerData = await this.api.queries.getLegalOfficerData(legalOfficer.account);
try {
const backend = this.axiosFactory.buildAxiosInstance(legalOfficer.node, this.token);
await backend.put('/api/legal-officer', legalOfficer);
const endpoint = requireDefined(
legalOfficerData?.hostData?.baseUrl,
() => new Error(`Unable to find node of LLO ${ legalOfficer.account.address }`)
)
const backend = this.axiosFactory.buildAxiosInstance(endpoint, this.token);
const { userIdentity, postalAddress, additionalDetails } = legalOfficer;
await backend.put('/api/legal-officer', { userIdentity, postalAddress, additionalDetails });
} catch(e) {
throw newBackendError(e);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/node-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@logion/node-api",
"version": "0.31.1",
"version": "0.31.2-1",
"description": "logion API",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
14 changes: 8 additions & 6 deletions packages/node-api/src/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import { Lgnt } from "./Currency.js"

export type ChainType = "Solo" | "Para";

export const EXPECTED_SPEC_NAME = "logion";
export const LOGION_SPEC_NAME = "logion";

export const EXPECTED_SOLO_VERSION = 164n;
export const SOLO_VERSION = 164n;

export const EXPECTED_PARA_VERSION = 4000n;
export const MIN_SUPPORTED_PARA_VERSION = 4000n; // Inclusive

export const MAX_SUPPORTED_PARA_VERSION = 5000n; // Exclusive

/**
* A Logion chain client. An instance of this class provides
Expand Down Expand Up @@ -88,14 +90,14 @@ export class LogionNodeApiClass {

private detectChainType(): ChainType {
const chainSpecName = this.polkadot.runtimeVersion.specName.toString();
if(chainSpecName !== EXPECTED_SPEC_NAME) {
if(chainSpecName !== LOGION_SPEC_NAME) {
throw new Error(`Unexpected chain '${chainSpecName}'`);
}

const chainSpecVersion = this.polkadot.runtimeVersion.specVersion.toBigInt();
if(chainSpecVersion === EXPECTED_SOLO_VERSION) {
if(chainSpecVersion === SOLO_VERSION) {
return "Solo";
} else if(chainSpecVersion === EXPECTED_PARA_VERSION) {
} else if(chainSpecVersion >= MIN_SUPPORTED_PARA_VERSION && chainSpecVersion < MAX_SUPPORTED_PARA_VERSION) {
return "Para";
} else {
throw new Error(`Unsupported runtime version '${chainSpecVersion}'`);
Expand Down
14 changes: 7 additions & 7 deletions packages/node-api/test/Util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Codec } from '@polkadot/types-codec/types';
import { EXPECTED_PARA_VERSION, EXPECTED_SOLO_VERSION, EXPECTED_SPEC_NAME, SS58_PREFIX } from '../src/index.js';
import { MIN_SUPPORTED_PARA_VERSION, SOLO_VERSION, LOGION_SPEC_NAME, SS58_PREFIX } from '../src/index.js';
import { bool } from "@polkadot/types-codec";

export function mockCodecWithToString<T extends Codec>(value: string): T {
Expand All @@ -26,21 +26,21 @@ export function mockBool(value: boolean): bool {
export function mockSoloRuntimeVersion() {
return {
specName: {
toString: () => EXPECTED_SPEC_NAME,
toString: () => LOGION_SPEC_NAME,
},
specVersion: {
toBigInt: () => EXPECTED_SOLO_VERSION,
toBigInt: () => SOLO_VERSION,
},
};
}

export function mockParaRuntimeVersion() {
return {
specName: {
toString: () => EXPECTED_SPEC_NAME,
toString: () => LOGION_SPEC_NAME,
},
specVersion: {
toBigInt: () => EXPECTED_PARA_VERSION,
toBigInt: () => MIN_SUPPORTED_PARA_VERSION,
},
};
}
Expand All @@ -51,15 +51,15 @@ export function mockRuntimeVersionUnexpectedSpecName() {
toString: () => "not-logion",
},
specVersion: {
toBigInt: () => EXPECTED_PARA_VERSION,
toBigInt: () => MIN_SUPPORTED_PARA_VERSION,
},
};
}

export function mockRuntimeVersionUnexpectedSpecVersion() {
return {
specName: {
toString: () => EXPECTED_SPEC_NAME,
toString: () => LOGION_SPEC_NAME,
},
specVersion: {
toBigInt: () => 42n,
Expand Down

0 comments on commit c570e3a

Please sign in to comment.