diff --git a/packages/client-node/integration/LegalOfficer.ts b/packages/client-node/integration/LegalOfficer.ts index ed52820f..90bae042 100644 --- a/packages/client-node/integration/LegalOfficer.ts +++ b/packages/client-node/integration/LegalOfficer.ts @@ -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; @@ -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", diff --git a/packages/client/package.json b/packages/client/package.json index ca4cfd5a..381de02b 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -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", diff --git a/packages/client/src/LegalOfficerClient.ts b/packages/client/src/LegalOfficerClient.ts index 51a59314..55e3ba1a 100644 --- a/packages/client/src/LegalOfficerClient.ts +++ b/packages/client/src/LegalOfficerClient.ts @@ -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; @@ -17,7 +18,7 @@ interface BackendLegalOfficer { } export interface CreateOrUpdateLegalOfficer { - node: string; + account: ValidAccountId; userIdentity: UserIdentity; postalAddress: LegalOfficerPostalAddress; additionalDetails: string; @@ -38,7 +39,7 @@ export class LegalOfficerClient { private readonly token: string | undefined; - private api: LogionNodeApiClass; + private readonly api: LogionNodeApiClass; async getLegalOfficers(): Promise { const onchain = await this.api.polkadot.query.loAuthorityList.legalOfficerSet.entries(); @@ -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); } diff --git a/packages/node-api/package.json b/packages/node-api/package.json index fc3499db..1fdb621b 100644 --- a/packages/node-api/package.json +++ b/packages/node-api/package.json @@ -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", diff --git a/packages/node-api/src/Connection.ts b/packages/node-api/src/Connection.ts index 0c97c4cd..998e2000 100644 --- a/packages/node-api/src/Connection.ts +++ b/packages/node-api/src/Connection.ts @@ -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 @@ -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}'`); diff --git a/packages/node-api/test/Util.ts b/packages/node-api/test/Util.ts index 22d7b548..cdab80bd 100644 --- a/packages/node-api/test/Util.ts +++ b/packages/node-api/test/Util.ts @@ -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(value: string): T { @@ -26,10 +26,10 @@ 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, }, }; } @@ -37,10 +37,10 @@ export function mockSoloRuntimeVersion() { export function mockParaRuntimeVersion() { return { specName: { - toString: () => EXPECTED_SPEC_NAME, + toString: () => LOGION_SPEC_NAME, }, specVersion: { - toBigInt: () => EXPECTED_PARA_VERSION, + toBigInt: () => MIN_SUPPORTED_PARA_VERSION, }, }; } @@ -51,7 +51,7 @@ export function mockRuntimeVersionUnexpectedSpecName() { toString: () => "not-logion", }, specVersion: { - toBigInt: () => EXPECTED_PARA_VERSION, + toBigInt: () => MIN_SUPPORTED_PARA_VERSION, }, }; } @@ -59,7 +59,7 @@ export function mockRuntimeVersionUnexpectedSpecName() { export function mockRuntimeVersionUnexpectedSpecVersion() { return { specName: { - toString: () => EXPECTED_SPEC_NAME, + toString: () => LOGION_SPEC_NAME, }, specVersion: { toBigInt: () => 42n,