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

feat(golem-network): added getIdentity method to GolemNetwork object #1073

Open
wants to merge 3 commits into
base: beta
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/golem-network/golem-network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ const order: MarketOrderSpec = Object.freeze({
},
},
} as const);

const identity = {
identity: "0x0123456789",
role: "test-role",
name: "test-name",
};

const mockMarket = mock(MarketModuleImpl);
const mockPayment = mock(PaymentModuleImpl);
const mockActivity = mock(ActivityModuleImpl);
Expand Down Expand Up @@ -54,6 +61,7 @@ afterEach(() => {
beforeEach(() => {
when(mockStorageProvider.close()).thenResolve();
when(mockYagna.disconnect()).thenResolve();
when(mockYagna.connect()).thenResolve(identity);
});

function getGolemNetwork() {
Expand Down
16 changes: 15 additions & 1 deletion src/golem-network/golem-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { DataTransferProtocol } from "../shared/types";
import { NetworkApiAdapter } from "../shared/yagna/adapters/network-api-adapter";
import { IProposalRepository } from "../market/proposal";
import { Subscription } from "rxjs";
import { GolemUserError } from "../shared/error/golem-error";

/**
* Instance of an object or a factory function that you can call `new` on.
Expand Down Expand Up @@ -226,6 +227,8 @@ export class GolemNetwork {
*/
private cleanupTasks: (() => Promise<void> | void)[] = [];

private identity?: string;

constructor(options: Partial<GolemNetworkOptions> = {}) {
const optDefaults: GolemNetworkOptions = {
dataTransferProtocol: isNode ? "gftp" : "ws",
Expand Down Expand Up @@ -321,7 +324,7 @@ export class GolemNetwork {
*/
async connect() {
try {
await this.yagna.connect();
this.identity = (await this.yagna.connect()).identity;
await this.services.paymentApi.connect();
await this.storageProvider.init();
this.events.emit("connected");
Expand Down Expand Up @@ -632,6 +635,17 @@ export class GolemNetwork {
return this.hasConnection;
}

/**
* Yagna Node Id used by the requester.
* It depends on the Yagny Api Key used and reflects the user's eth wallet address.
*/
getIdentity(): string {
if (!this.isConnected() || !this.identity) {
throw new GolemUserError("To obtain an identity, you must first connect to the Golem Network.");
}
return this.identity;
}

/**
* Creates a new logical network within the Golem VPN infrastructure.
* Allows communication between network nodes using standard network mechanisms,
Expand Down