Skip to content

Commit 99c2141

Browse files
committed
- Added nodePublicKey in NodeInfo
- Cache nodePublicKey in RepoFactory
1 parent 901af8e commit 99c2141

File tree

11 files changed

+78
-19
lines changed

11 files changed

+78
-19
lines changed

e2e/infrastructure/NodeHttp.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe('NodeHttp', () => {
4242
expect(nodeInfo.publicKey).not.to.be.undefined;
4343
expect(nodeInfo.roles).not.to.be.undefined;
4444
expect(nodeInfo.version).not.to.be.undefined;
45+
expect(nodeInfo.nodePublicKey).not.to.be.undefined;
4546
});
4647
});
4748

@@ -93,7 +94,7 @@ describe('NodeHttp', () => {
9394

9495
describe('getUnlockedAccount', () => {
9596
it('should return unlocked account', async () => {
96-
const unlockedAccount = await nodeRepository.getUnlockedAccount('test').toPromise();
97+
const unlockedAccount = await nodeRepository.getUnlockedAccount().toPromise();
9798
expect(unlockedAccount).not.to.be.null;
9899
expect(unlockedAccount.length).greaterThan(0);
99100
});

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"ripemd160": "^2.0.2",
114114
"rxjs": "^6.6.3",
115115
"rxjs-compat": "^6.6.3",
116-
"symbol-openapi-typescript-fetch-client": "0.10.1-SNAPSHOT.202011091143",
116+
"symbol-openapi-typescript-fetch-client": "0.10.1-SNAPSHOT.202011141947",
117117
"tweetnacl": "^1.0.3",
118118
"ws": "^7.3.1"
119119
},

src/infrastructure/NodeHttp.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,10 @@ export class NodeHttp extends Http implements NodeRepository {
113113

114114
/**
115115
* Return unlocked harvesting account from node.
116-
* @param peer Peer node host name.
117116
* @returns Observable<string[]>
118117
*/
119-
getUnlockedAccount(peer: string): Observable<string[]> {
120-
return this.call(this.nodeRoutesApi.getUnlockedAccount(peer), (body) => {
118+
getUnlockedAccount(): Observable<string[]> {
119+
return this.call(this.nodeRoutesApi.getUnlockedAccount(), (body) => {
121120
return body.unlockedAccount;
122121
});
123122
}
@@ -138,6 +137,7 @@ export class NodeHttp extends Http implements NodeRepository {
138137
this.getNodeRoles(nodeInfo.roles.valueOf()),
139138
nodeInfo.host,
140139
nodeInfo.friendlyName,
140+
nodeInfo.nodePublicKey,
141141
);
142142
}
143143

src/infrastructure/NodeRepository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface NodeRepository {
5454

5555
/**
5656
* Gets blockchain storage info.
57+
* @param hostName Peer node host name.
5758
* @returns Observable<StorageInfo>
5859
*/
5960
getStorageInfo(): Observable<StorageInfo>;
@@ -66,8 +67,7 @@ export interface NodeRepository {
6667

6768
/**
6869
* Return unlocked harvesting account from node.
69-
* @param peer Peer node host name.
7070
* @returns Observable<string[]>
7171
*/
72-
getUnlockedAccount(peer: string): Observable<string[]>;
72+
getUnlockedAccount(): Observable<string[]>;
7373
}

src/infrastructure/RepositoryFactory.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,9 @@ export interface RepositoryFactory {
153153
* @returns the network currencies.
154154
*/
155155
getCurrencies(): Observable<NetworkCurrencies>;
156+
157+
/**
158+
* @returns the node public key
159+
*/
160+
getNodePublicKey(): Observable<string | undefined>;
156161
}

src/infrastructure/RepositoryFactoryConfig.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ export interface RepositoryFactoryConfig {
5151
* The preconfigured symbol network currencies for offline access. They are loaded from server by default if not provided.
5252
*/
5353
networkCurrencies?: NetworkCurrencies;
54+
55+
/**
56+
* The node public key used for NodeKeyLink transaction in delegated harvesting.
57+
*/
58+
nodePublicKey?: string;
5459
}

src/infrastructure/RepositoryFactoryHttp.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class RepositoryFactoryHttp implements RepositoryFactory {
7373
private readonly epochAdjustment: Observable<number>;
7474
private readonly networkProperties: Observable<NetworkConfiguration>;
7575
private readonly networkCurrencies: Observable<NetworkCurrencies>;
76+
private readonly nodePublicKey: Observable<string | undefined>;
7677
/**
7778
* Constructor
7879
* @param url the server url.
@@ -93,13 +94,14 @@ export class RepositoryFactoryHttp implements RepositoryFactory {
9394
}),
9495
),
9596
);
96-
this.generationHash = configs?.generationHash
97-
? observableOf(configs.generationHash)
98-
: this.cache(() =>
99-
this.createNodeRepository()
100-
.getNodeInfo()
101-
.pipe(map((b) => b.networkGenerationHashSeed)),
102-
);
97+
if (configs?.generationHash && configs?.nodePublicKey) {
98+
this.generationHash = observableOf(configs.generationHash);
99+
this.nodePublicKey = observableOf(configs.nodePublicKey);
100+
} else {
101+
const nodeInfoObservable = this.createNodeRepository().getNodeInfo();
102+
this.generationHash = this.cache(() => nodeInfoObservable.pipe(map((b) => b.networkGenerationHashSeed)));
103+
this.nodePublicKey = this.cache(() => nodeInfoObservable.pipe(map((b) => b.nodePublicKey)));
104+
}
103105
this.websocketUrl = configs?.websocketUrl ? configs?.websocketUrl : `${url.replace(/\/$/, '')}/ws`;
104106
this.websocketInjected = configs?.websocketInjected;
105107
this.networkCurrencies = configs?.networkCurrencies
@@ -198,4 +200,10 @@ export class RepositoryFactoryHttp implements RepositoryFactory {
198200
getCurrencies(): Observable<NetworkCurrencies> {
199201
return this.networkCurrencies;
200202
}
203+
/**
204+
* @returns the node public key
205+
*/
206+
getNodePublicKey(): Observable<string | undefined> {
207+
return this.nodePublicKey;
208+
}
201209
}

src/model/node/NodeInfo.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class NodeInfo {
2929
* @param roles
3030
* @param host
3131
* @param friendlyName
32+
* @param nodePublicKey
3233
*/
3334
constructor(
3435
/**
@@ -63,5 +64,9 @@ export class NodeInfo {
6364
* The name of the node.
6465
*/
6566
public readonly friendlyName: string,
67+
/**
68+
* The node public key used for NodeKeyLink transaction.
69+
*/
70+
public readonly nodePublicKey?: string,
6671
) {}
6772
}

test/infrastructure/NodeHttp.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ describe('NodeHttp', () => {
203203
it('getUnlockedAccount', async () => {
204204
const body = { unlockedAccount: ['key1', 'key2'] };
205205

206-
when(nodeRoutesApi.getUnlockedAccount('test')).thenReturn(Promise.resolve(body));
206+
when(nodeRoutesApi.getUnlockedAccount()).thenReturn(Promise.resolve(body));
207207

208-
const unlockedAccount = await nodeRepository.getUnlockedAccount('test').toPromise();
208+
const unlockedAccount = await nodeRepository.getUnlockedAccount().toPromise();
209209
expect(unlockedAccount).to.be.not.null;
210210
expect(unlockedAccount[0]).to.be.equal('key1');
211211
expect(unlockedAccount[1]).to.be.equal('key2');

0 commit comments

Comments
 (0)