Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 5e4724b

Browse files
authored
Merge pull request #2657 from princesinha19/admin_methods
Geth Admin management API's implemented (web3-eth-admin)
2 parents 617c2dd + 2b1f122 commit 5e4724b

34 files changed

+1985
-1
lines changed

packages/web3-core-method/src/index.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
/**
1818
* @file index.js
19-
* @author Samuel Furter <[email protected]>
19+
* @author Samuel Furter <[email protected]>, Prince Sinha <[email protected]>
2020
* @date 2018
2121
*/
2222

@@ -118,3 +118,14 @@ export PostMethod from './methods/shh/PostMethod';
118118
export SetMaxMessageSizeMethod from './methods/shh/SetMaxMessageSizeMethod';
119119
export SetMinPoWMethod from './methods/shh/SetMinPoWMethod';
120120
export ShhVersionMethod from './methods/shh/ShhVersionMethod';
121+
122+
// Admin
123+
export AddPeerMethod from './methods/admin/AddPeerMethod';
124+
export DataDirectoryMethod from './methods/admin/DataDirectoryMethod';
125+
export NodeInfoMethod from './methods/admin/NodeInfoMethod';
126+
export PeersMethod from './methods/admin/PeersMethod';
127+
export SetSolcMethod from './methods/admin/SetSolcMethod';
128+
export StartRpcMethod from './methods/admin/StartRpcMethod';
129+
export StartWsMethod from './methods/admin/StartWsMethod';
130+
export StopRpcMethod from './methods/admin/StopRpcMethod';
131+
export StopWsMethod from './methods/admin/StopWsMethod';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
/**
18+
* @file AddPeerMethod.js
19+
* @author Prince Sinha <[email protected]>
20+
* @date 2019
21+
*/
22+
23+
import AbstractMethod from '../../../lib/methods/AbstractMethod';
24+
25+
export default class AddPeerMethod extends AbstractMethod {
26+
/**
27+
* @param {Utils} utils
28+
* @param {Object} formatters
29+
* @param {AbstractWeb3Module} moduleInstance
30+
*
31+
* @constructor
32+
*/
33+
constructor(utils, formatters, moduleInstance) {
34+
super('admin_addPeer', 1, utils, formatters, moduleInstance);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
/**
18+
* @file DataDirectoryMethod.js
19+
* @author Prince Sinha <[email protected]>
20+
* @date 2019
21+
*/
22+
23+
import AbstractMethod from '../../../lib/methods/AbstractMethod';
24+
25+
export default class DataDirectoryMethod extends AbstractMethod {
26+
/**
27+
* @param {Utils} utils
28+
* @param {Object} formatters
29+
* @param {AbstractWeb3Module} moduleInstance
30+
*
31+
* @constructor
32+
*/
33+
constructor(utils, formatters, moduleInstance) {
34+
super('admin_datadir', 0, utils, formatters, moduleInstance);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
/**
18+
* @file NodeInfoMethod.js
19+
* @author Prince Sinha <[email protected]>
20+
* @date 2019
21+
*/
22+
23+
import AbstractMethod from '../../../lib/methods/AbstractMethod';
24+
25+
export default class NodeInfoMethod extends AbstractMethod {
26+
/**
27+
* @param {Utils} utils
28+
* @param {Object} formatters
29+
* @param {AbstractWeb3Module} moduleInstance
30+
*
31+
* @constructor
32+
*/
33+
constructor(utils, formatters, moduleInstance) {
34+
super('admin_nodeInfo', 0, utils, formatters, moduleInstance);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
/**
18+
* @file PeersMethod.js
19+
* @author Prince Sinha <[email protected]>
20+
* @date 2019
21+
*/
22+
23+
import AbstractMethod from '../../../lib/methods/AbstractMethod';
24+
25+
export default class PeersMethod extends AbstractMethod {
26+
/**
27+
* @param {Utils} utils
28+
* @param {Object} formatters
29+
* @param {AbstractWeb3Module} moduleInstance
30+
*
31+
* @constructor
32+
*/
33+
constructor(utils, formatters, moduleInstance) {
34+
super('admin_peers', 0, utils, formatters, moduleInstance);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
/**
18+
* @file SetSolcMethod.js
19+
* @author Prince Sinha <[email protected]>
20+
* @date 2019
21+
*/
22+
23+
import AbstractMethod from '../../../lib/methods/AbstractMethod';
24+
25+
export default class SetSolcMethod extends AbstractMethod {
26+
/**
27+
* @param {Utils} utils
28+
* @param {Object} formatters
29+
* @param {AbstractWeb3Module} moduleInstance
30+
*
31+
* @constructor
32+
*/
33+
constructor(utils, formatters, moduleInstance) {
34+
super('admin_setSolc', 1, utils, formatters, moduleInstance);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
/**
18+
* @file StartRpcMethod.js
19+
* @author Prince Sinha <[email protected]>
20+
* @date 2019
21+
*/
22+
23+
import AbstractMethod from '../../../lib/methods/AbstractMethod';
24+
25+
export default class StartRpcMethod extends AbstractMethod {
26+
/**
27+
* @param {Utils} utils
28+
* @param {Object} formatters
29+
* @param {AbstractWeb3Module} moduleInstance
30+
*
31+
* @constructor
32+
*/
33+
constructor(utils, formatters, moduleInstance) {
34+
super('admin_startRPC', 4, utils, formatters, moduleInstance);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
/**
18+
* @file StartWsMethod.js
19+
* @author Prince Sinha <[email protected]>
20+
* @date 2019
21+
*/
22+
23+
import AbstractMethod from '../../../lib/methods/AbstractMethod';
24+
25+
export default class StartWsMethod extends AbstractMethod {
26+
/**
27+
* @param {Utils} utils
28+
* @param {Object} formatters
29+
* @param {AbstractWeb3Module} moduleInstance
30+
*
31+
* @constructor
32+
*/
33+
constructor(utils, formatters, moduleInstance) {
34+
super('admin_startWS', 4, utils, formatters, moduleInstance);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
/**
18+
* @file StopRpcMethod.js
19+
* @author Prince Sinha <[email protected]>
20+
* @date 2019
21+
*/
22+
23+
import AbstractMethod from '../../../lib/methods/AbstractMethod';
24+
25+
export default class StopRpcMethod extends AbstractMethod {
26+
/**
27+
* @param {Utils} utils
28+
* @param {Object} formatters
29+
* @param {AbstractWeb3Module} moduleInstance
30+
*
31+
* @constructor
32+
*/
33+
constructor(utils, formatters, moduleInstance) {
34+
super('admin_stopRPC', 0, utils, formatters, moduleInstance);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
/**
18+
* @file StopWsMethod.js
19+
* @author Prince Sinha <[email protected]>
20+
* @date 2019
21+
*/
22+
23+
import AbstractMethod from '../../../lib/methods/AbstractMethod';
24+
25+
export default class StopWsMethod extends AbstractMethod {
26+
/**
27+
* @param {Utils} utils
28+
* @param {Object} formatters
29+
* @param {AbstractWeb3Module} moduleInstance
30+
*
31+
* @constructor
32+
*/
33+
constructor(utils, formatters, moduleInstance) {
34+
super('admin_stopWS', 0, utils, formatters, moduleInstance);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {formatters} from 'web3-core-helpers';
2+
import AbstractMethod from '../../../../lib/methods/AbstractMethod';
3+
import AddPeerMethod from '../../../../src/methods/admin/AddPeerMethod';
4+
5+
// Mocks
6+
jest.mock('web3-core-helpers');
7+
8+
/**
9+
* AddPeerMethod test
10+
*/
11+
describe('AdminAddPeerMethodTest', () => {
12+
let method;
13+
14+
beforeEach(() => {
15+
method = new AddPeerMethod(null, formatters, {});
16+
});
17+
18+
it('constructor check', () => {
19+
expect(method).toBeInstanceOf(AbstractMethod);
20+
21+
expect(method.rpcMethod).toEqual('admin_addPeer');
22+
23+
expect(method.parametersAmount).toEqual(1);
24+
25+
expect(method.utils).toEqual(null);
26+
27+
expect(method.formatters).toEqual(formatters);
28+
});
29+
});

0 commit comments

Comments
 (0)