-
Notifications
You must be signed in to change notification settings - Fork 1
/
permissioning.js
52 lines (44 loc) · 2.43 KB
/
permissioning.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const providers = require('hyperledger-besu-ethers').providers;
const provider = new providers.BesuProvider('http://localhost:20000');
async function example() {
// Add accounts to node's whitelisted accounts
let result = await provider.addAccountsToWhitelist([
'0xb9b81ee349c3807e46bc71aa2632203c5b462032',
'0xb9b81ee349c3807e46bc71aa2632203c5b462034',
]);
console.log(result); // Success
// Get node's whitelisted accounts
const accounts = await provider.getAccountsWhitelist();
console.log(accounts); // ["0xb9b81ee349c3807e46bc71aa2632203c5b462032", "0xb9b81ee349c3807e46bc71aa2632203c5b462034"]
// Remove accounts from node's whitelisted accounts
result = await provider.removeAccountsFromWhitelist([
'0xb9b81ee349c3807e46bc71aa2632203c5b462032',
'0xb9b81ee349c3807e46bc71aa2632203c5b462034',
]);
console.log(result); // Success
// Add nodes to node's whitelisted nodes
result = await provider.addNodesToWhitelist([
'enode://7e4ef30e9ec683f26ad76ffca5b5148fa7a6575f4cfad4eb0f52f9c3d8335f4a9b6f9e66fcc73ef95ed7a2a52784d4f372e7750ac8ae0b544309a5b391a23dd7@127.0.0.1:30303',
'enode://2feb33b3c6c4a8f77d84a5ce44954e83e5f163e7a65f7f7a7fec499ceb0ddd76a46ef635408c513d64c076470eac86b7f2c8ae4fcd112cb28ce82c0d64ec2c94@127.0.0.1:30304',
]);
console.log(result); // Success
// Get node's whitelisted nodes
const nodes = await provider.getNodesWhitelist();
console.log(nodes);
/*
[
"enode://7b61d5ee4b44335873e6912cb5dd3e3877c860ba21417c9b9ef1f7e500a82213737d4b269046d0669fb2299a234ca03443f25fe5f706b693b3669e5c92478ade@127.0.0.1:30305",
"enode://2feb33b3c6c4a8f77d84a5ce44954e83e5f163e7a65f7f7a7fec499ceb0ddd76a46ef635408c513d64c076470eac86b7f2c8ae4fcd112cb28ce82c0d64ec2c94@127.0.0.1:30304"
]
*/
// Remove nodes from node's whitelisted nodes
result = await provider.removeNodesFromWhitelist([
'enode://7e4ef30e9ec683f26ad76ffca5b5148fa7a6575f4cfad4eb0f52f9c3d8335f4a9b6f9e66fcc73ef95ed7a2a52784d4f372e7750ac8ae0b544309a5b391a23dd7@127.0.0.1:30303',
'enode://2feb33b3c6c4a8f77d84a5ce44954e83e5f163e7a65f7f7a7fec499ceb0ddd76a46ef635408c513d64c076470eac86b7f2c8ae4fcd112cb28ce82c0d64ec2c94@127.0.0.1:30304',
]);
console.log(result); // Success
// Reload permissions from the node's configuration file
result = await provider.reloadPermissionsFromFile();
console.log(result); // Success
}
example();