Skip to content

Commit 44b1b13

Browse files
authored
feat(golem-network): added getIdentity method to GolemNetwork object (#1073)
1 parent db4968f commit 44b1b13

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/golem-network/golem-network.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ const order: MarketOrderSpec = Object.freeze({
2525
},
2626
},
2727
} as const);
28+
29+
const identity = {
30+
identity: "0x0123456789",
31+
role: "test-role",
32+
name: "test-name",
33+
};
34+
2835
const mockMarket = mock(MarketModuleImpl);
2936
const mockPayment = mock(PaymentModuleImpl);
3037
const mockActivity = mock(ActivityModuleImpl);
@@ -54,6 +61,7 @@ afterEach(() => {
5461
beforeEach(() => {
5562
when(mockStorageProvider.close()).thenResolve();
5663
when(mockYagna.disconnect()).thenResolve();
64+
when(mockYagna.connect()).thenResolve(identity);
5765
});
5866

5967
function getGolemNetwork() {

src/golem-network/golem-network.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export class GolemNetwork {
254254
*/
255255
private cleanupTasks: (() => Promise<void> | void)[] = [];
256256

257+
private identity?: string;
257258
private registeredPlugins: GolemPluginRegistration[] = [];
258259

259260
constructor(options: Partial<GolemNetworkOptions> = {}) {
@@ -367,7 +368,7 @@ export class GolemNetwork {
367368
*/
368369
async connect() {
369370
try {
370-
await this.yagna.connect();
371+
this.identity = (await this.yagna.connect()).identity;
371372
await this.services.paymentApi.connect();
372373
await this.storageProvider.init();
373374
await this.connectPlugins();
@@ -694,6 +695,17 @@ export class GolemNetwork {
694695
return this.hasConnection;
695696
}
696697

698+
/**
699+
* Yagna Node Id used by the requester.
700+
* It depends on the Yagny Api Key used and reflects the user's eth wallet address.
701+
*/
702+
getIdentity(): string {
703+
if (!this.isConnected() || !this.identity) {
704+
throw new GolemUserError("To obtain an identity, you must first connect to the Golem Network.");
705+
}
706+
return this.identity;
707+
}
708+
697709
/**
698710
* Creates a new logical network within the Golem VPN infrastructure.
699711
* Allows communication between network nodes using standard network mechanisms,

0 commit comments

Comments
 (0)