Skip to content

Commit 12720cc

Browse files
Seulgi Kimsgkim126
authored andcommitted
Add whitelist/blacklist features
1 parent 49e0f36 commit 12720cc

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

integration_tests/Network.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { SDK } from "../";
2+
3+
describe("network", () => {
4+
let sdk: SDK;
5+
6+
beforeAll(async () => {
7+
sdk = new SDK({ server: "http://localhost:8080" });
8+
});
9+
10+
test("whitelist enabled", async () => {
11+
let { enabled } = await sdk.rpc.network.getWhitelist();
12+
expect(enabled).toBe(false);
13+
});
14+
15+
test("blacklist enabled", async () => {
16+
let { enabled } = await sdk.rpc.network.getBlacklist();
17+
expect(enabled).toBe(false);
18+
});
19+
});

src/rpc/network.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,108 @@ export class NetworkRpc {
6060
[address, port]
6161
);
6262
}
63+
64+
/**
65+
* Add the IP to whitelist
66+
* @param ip Node IP
67+
*/
68+
addToWhiteList(ip: string): Promise<null> {
69+
return this.rpc.sendRpcRequest(
70+
"net_addToWhitelist",
71+
[ip]
72+
);
73+
}
74+
75+
/**
76+
* Remove the IP from whitelist
77+
* @param ip Node IP
78+
*/
79+
removeFromWhiteList(ip: string): Promise<null> {
80+
return this.rpc.sendRpcRequest(
81+
"net_removeFromWhitelist",
82+
[ip]
83+
);
84+
}
85+
86+
/**
87+
* Add the IP to blacklist
88+
* @param ip Node IP
89+
*/
90+
addToBlacklist(ip: string): Promise<null> {
91+
return this.rpc.sendRpcRequest(
92+
"net_addToBlacklist",
93+
[ip]
94+
);
95+
}
96+
97+
/**
98+
* Remove the IP from blacklist
99+
* @param ip Node IP
100+
*/
101+
removeFromBlackList(ip: string): Promise<null> {
102+
return this.rpc.sendRpcRequest(
103+
"net_removeFromBlacklist",
104+
[ip]
105+
);
106+
}
107+
108+
/**
109+
* Enable whitelist
110+
*/
111+
enableWhiteList(): Promise<null> {
112+
return this.rpc.sendRpcRequest(
113+
"net_enableWhitelist",
114+
[]
115+
);
116+
}
117+
118+
/**
119+
* Disable whitelist
120+
*/
121+
disableWhiteList(): Promise<null> {
122+
return this.rpc.sendRpcRequest(
123+
"net_disableWhitelist",
124+
[]
125+
);
126+
}
127+
128+
/**
129+
* Enable blacklist
130+
*/
131+
enableBlackList(): Promise<null> {
132+
return this.rpc.sendRpcRequest(
133+
"net_enableBlacklist",
134+
[]
135+
);
136+
}
137+
138+
/**
139+
* Disable blacklist
140+
*/
141+
disableBlackList(): Promise<null> {
142+
return this.rpc.sendRpcRequest(
143+
"net_disableBlacklist",
144+
[]
145+
);
146+
}
147+
148+
/**
149+
* Get the status of whitelist
150+
*/
151+
getWhitelist(): Promise<{ list: string[], enabled: boolean }> {
152+
return this.rpc.sendRpcRequest(
153+
"net_getWhitelist",
154+
[]
155+
);
156+
}
157+
158+
/**
159+
* Get the status of blacklist
160+
*/
161+
getBlacklist(): Promise<{ list: string[], enabled: boolean }> {
162+
return this.rpc.sendRpcRequest(
163+
"net_getBlacklist",
164+
[]
165+
);
166+
}
63167
}

0 commit comments

Comments
 (0)