Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use client-node #9

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions integration/Main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { waitReady } from "@polkadot/wasm-crypto";
import { Adapters, UUID, Currency, buildApiClass } from "@logion/node-api";
import axios from "axios";
import { AcceptedRequest, KeyringSigner, LogionClient, OpenLoc, PendingRequest, Signer } from "@logion/client";
import { NodeAxiosFileUploader } from "@logion/client-node";
import { IKeyringPair, ISubmittableResult } from "@polkadot/types/types";
import { SubmittableExtrinsic } from "@polkadot/api/promise/types";

Expand Down Expand Up @@ -59,7 +60,8 @@ async function setup(): Promise<void> {

let client = await LogionClient.create({
rpcEndpoints: [ "ws://127.0.0.1:9944" ],
directoryEndpoint: "http://localhost:8090"
directoryEndpoint: "http://localhost:8090",
buildFileUploader: () => new NodeAxiosFileUploader(),
});
const signer = new KeyringSigner(keyring, GATEWAY_SIGN_SEND_STRAGEGY);
client = await client.authenticate([
Expand Down Expand Up @@ -116,7 +118,7 @@ async function createIdentityLoc(params: { client: LogionClient, signer: Signer
const pendingRequesterIdentityLoc = await requesterLocs.requestIdentityLoc({
description: "My identity LOC",
draft: false,
legalOfficer: requesterClient.getLegalOfficer(ALICE),
legalOfficerAddress: ALICE,
userIdentity,
userPostalAddress,
});
Expand All @@ -125,10 +127,10 @@ async function createIdentityLoc(params: { client: LogionClient, signer: Signer
const pendingAliceIdentityLoc = aliceLocs.findById(identityLocId) as PendingRequest;
await pendingAliceIdentityLoc.legalOfficer.accept({ signer });
const acceptedRequesterIdentityLoc = await pendingRequesterIdentityLoc.refresh() as AcceptedRequest;
await acceptedRequesterIdentityLoc.open({ signer });
await acceptedRequesterIdentityLoc.open({ signer, autoPublish: false });
aliceLocs = await aliceClient.locsState({ spec: { ownerAddress: ALICE, locTypes: ["Identity"], statuses: ["OPEN"] } });
const openAliceIdentityLoc = aliceLocs.findById(identityLocId) as OpenLoc;
await openAliceIdentityLoc.legalOfficer.close({ signer });
await openAliceIdentityLoc.legalOfficer.close({ signer, autoAck: false });

return identityLocId;
}
Expand All @@ -144,17 +146,19 @@ async function createCollectionLoc(params: { client: LogionClient, signer: Signe
const pendingRequesterLoc = await requesterLocs.requestCollectionLoc({
description: "My collection LOC",
draft: false,
legalOfficer: requesterClient.getLegalOfficer(ALICE),
legalOfficerAddress: ALICE,
valueFee: 0n,
legalFee: 0n,
});
const collectionLocId = pendingRequesterLoc.data().id;
let aliceLocs = await aliceClient.locsState({ spec: { ownerAddress: ALICE, locTypes: ["Collection"], statuses: ["REVIEW_PENDING"] } });
const pendingAliceLoc = aliceLocs.findById(collectionLocId) as PendingRequest;
await pendingAliceLoc.legalOfficer.accept({ signer });
const acceptedRequesterLoc = await pendingRequesterLoc.refresh() as AcceptedRequest;
await acceptedRequesterLoc.openCollection({ collectionCanUpload: false, collectionMaxSize: 1, signer });
await acceptedRequesterLoc.openCollection({ collectionCanUpload: false, collectionMaxSize: 1, autoPublish: false, signer });
aliceLocs = await aliceClient.locsState({ spec: { ownerAddress: ALICE, locTypes: ["Collection"], statuses: ["OPEN"] } });
const openAliceIdentityLoc = aliceLocs.findById(collectionLocId) as OpenLoc;
await openAliceIdentityLoc.legalOfficer.close({ signer });
await openAliceIdentityLoc.legalOfficer.close({ signer, autoAck: false });

return collectionLocId;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"coverage": "nyc yarn run test"
},
"dependencies": {
"@logion/client": "^0.28.3",
"@logion/client-node": "^0.1.0-1",
"ansi-regex": "^6.0.1",
"body-parser": "^1.19.1",
"bson": "^4.6.1",
Expand Down
8 changes: 4 additions & 4 deletions src/services/logion.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { injectable } from "inversify";
import { Keyring } from '@polkadot/api';
import { LogionClient, LogionClientConfig } from '@logion/client';
import FormData from "form-data";
import { LogionClient } from '@logion/client';
import { NodeAxiosFileUploader } from "@logion/client-node";

@injectable()
export class LogionService {

async buildApi(config: LogionClientConfig): Promise<LogionClient> {
async buildApi(config: { rpcEndpoints: string[], directoryEndpoint: string }): Promise<LogionClient> {
return await LogionClient.create({
...config,
formDataLikeFactory: () => new FormData(),
buildFileUploader: () => new NodeAxiosFileUploader(),
});
}

Expand Down
Loading