Updating documentation for RPCs (#5392)
* Removing minBlocks occurrencies * Docs for new RPCs. * Fixing linting issues, updating *withToken documentatiojn. * Adding missing RPCs. Fixing tests. * Fixing lint issues.
This commit is contained in:
@@ -165,10 +165,6 @@ export function inOptions (_options = {}) {
|
||||
options[key] = inNumber16((new BigNumber(options[key])).round());
|
||||
break;
|
||||
|
||||
case 'minBlock':
|
||||
options[key] = options[key] ? inNumber16(options[key]) : null;
|
||||
break;
|
||||
|
||||
case 'value':
|
||||
case 'nonce':
|
||||
options[key] = inNumber16(options[key]);
|
||||
@@ -211,3 +207,36 @@ export function inTraceType (whatTrace) {
|
||||
|
||||
return whatTrace;
|
||||
}
|
||||
|
||||
function inDeriveType (derive) {
|
||||
return derive && derive.type === 'hard' ? 'hard' : 'soft';
|
||||
}
|
||||
|
||||
export function inDeriveHash (derive) {
|
||||
const hash = derive && derive.hash ? derive.hash : derive;
|
||||
const type = inDeriveType(derive);
|
||||
|
||||
return {
|
||||
hash: inHex(hash),
|
||||
type
|
||||
};
|
||||
}
|
||||
|
||||
export function inDeriveIndex (derive) {
|
||||
if (!derive) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!isArray(derive)) {
|
||||
derive = [derive];
|
||||
}
|
||||
|
||||
return derive.map(item => {
|
||||
const index = inNumber10(item && item.index ? item.index : item);
|
||||
|
||||
return {
|
||||
index,
|
||||
type: inDeriveType(item)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,7 +16,11 @@
|
||||
|
||||
import BigNumber from 'bignumber.js';
|
||||
|
||||
import { inAddress, inBlockNumber, inData, inFilter, inHex, inNumber10, inNumber16, inOptions, inTraceType } from './input';
|
||||
import {
|
||||
inAddress, inBlockNumber, inData, inFilter, inHex,
|
||||
inNumber10, inNumber16, inOptions, inTraceType,
|
||||
inDeriveHash, inDeriveIndex
|
||||
} from './input';
|
||||
import { isAddress } from '../../../test/types';
|
||||
|
||||
describe('api/format/input', () => {
|
||||
@@ -215,7 +219,7 @@ describe('api/format/input', () => {
|
||||
expect(formatted.to).to.equal('');
|
||||
});
|
||||
|
||||
['gas', 'gasPrice', 'value', 'minBlock', 'nonce'].forEach((input) => {
|
||||
['gas', 'gasPrice', 'value', 'nonce'].forEach((input) => {
|
||||
it(`formats ${input} number as hexnumber`, () => {
|
||||
const block = {};
|
||||
|
||||
@@ -226,8 +230,8 @@ describe('api/format/input', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('passes minBlock as null when specified as such', () => {
|
||||
expect(inOptions({ minBlock: null })).to.deep.equal({ minBlock: null });
|
||||
it('passes condition as null when specified as such', () => {
|
||||
expect(inOptions({ condition: null })).to.deep.equal({ condition: null });
|
||||
});
|
||||
|
||||
it('ignores and passes through unknown keys', () => {
|
||||
@@ -272,4 +276,66 @@ describe('api/format/input', () => {
|
||||
expect(inTraceType(type)).to.deep.equal([type]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('inDeriveHash', () => {
|
||||
it('returns derive hash', () => {
|
||||
expect(inDeriveHash(1)).to.deep.equal({
|
||||
hash: '0x1',
|
||||
type: 'soft'
|
||||
});
|
||||
|
||||
expect(inDeriveHash(null)).to.deep.equal({
|
||||
hash: '0x',
|
||||
type: 'soft'
|
||||
});
|
||||
|
||||
expect(inDeriveHash({
|
||||
hash: 5
|
||||
})).to.deep.equal({
|
||||
hash: '0x5',
|
||||
type: 'soft'
|
||||
});
|
||||
|
||||
expect(inDeriveHash({
|
||||
hash: 5,
|
||||
type: 'hard'
|
||||
})).to.deep.equal({
|
||||
hash: '0x5',
|
||||
type: 'hard'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('inDeriveIndex', () => {
|
||||
it('returns derive hash', () => {
|
||||
expect(inDeriveIndex(null)).to.deep.equal([]);
|
||||
expect(inDeriveIndex([])).to.deep.equal([]);
|
||||
|
||||
expect(inDeriveIndex([1])).to.deep.equal([{
|
||||
index: 1,
|
||||
type: 'soft'
|
||||
}]);
|
||||
|
||||
expect(inDeriveIndex({
|
||||
index: 1
|
||||
})).to.deep.equal([{
|
||||
index: 1,
|
||||
type: 'soft'
|
||||
}]);
|
||||
|
||||
expect(inDeriveIndex([{
|
||||
index: 1,
|
||||
type: 'hard'
|
||||
}, 5])).to.deep.equal([
|
||||
{
|
||||
index: 1,
|
||||
type: 'hard'
|
||||
},
|
||||
{
|
||||
index: 5,
|
||||
type: 'soft'
|
||||
}
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -284,12 +284,6 @@ export function outTransaction (tx) {
|
||||
tx[key] = outTransactionCondition(tx[key]);
|
||||
break;
|
||||
|
||||
case 'minBlock':
|
||||
tx[key] = tx[key]
|
||||
? outNumber(tx[key])
|
||||
: null;
|
||||
break;
|
||||
|
||||
case 'creates':
|
||||
case 'from':
|
||||
case 'to':
|
||||
|
||||
@@ -392,7 +392,7 @@ describe('api/format/output', () => {
|
||||
});
|
||||
});
|
||||
|
||||
['blockNumber', 'gasPrice', 'gas', 'minBlock', 'nonce', 'transactionIndex', 'value'].forEach((input) => {
|
||||
['blockNumber', 'gasPrice', 'gas', 'nonce', 'transactionIndex', 'value'].forEach((input) => {
|
||||
it(`formats ${input} number as hexnumber`, () => {
|
||||
const block = {};
|
||||
|
||||
@@ -404,8 +404,8 @@ describe('api/format/output', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('passes minBlock as null when null', () => {
|
||||
expect(outTransaction({ minBlock: null })).to.deep.equal({ minBlock: null });
|
||||
it('passes condition as null when null', () => {
|
||||
expect(outTransaction({ condition: null })).to.deep.equal({ condition: null });
|
||||
});
|
||||
|
||||
it('ignores and passes through unknown keys', () => {
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import { inAddress, inAddresses, inData, inHex, inNumber16, inOptions, inBlockNumber } from '../../format/input';
|
||||
import {
|
||||
inAddress, inAddresses, inData, inHex, inNumber16, inOptions, inBlockNumber, inDeriveHash, inDeriveIndex
|
||||
} from '../../format/input';
|
||||
import { outAccountInfo, outAddress, outAddresses, outChainStatus, outHistogram, outHwAccountInfo, outNodeKind, outNumber, outPeers, outRecentDapps, outTransaction, outVaultMeta } from '../../format/output';
|
||||
|
||||
export default class Parity {
|
||||
@@ -117,6 +119,18 @@ export default class Parity {
|
||||
.execute('parity_devLogsLevels');
|
||||
}
|
||||
|
||||
deriveAddressHash (address, password, hash, shouldSave) {
|
||||
return this._transport
|
||||
.execute('parity_deriveAddressHash', inAddress(address), password, inDeriveHash(hash), !!shouldSave)
|
||||
.then(outAddress);
|
||||
}
|
||||
|
||||
deriveAddressIndex (address, password, index, shouldSave) {
|
||||
return this._transport
|
||||
.execute('parity_deriveAddressIndex', inAddress(address), password, inDeriveIndex(index), !!shouldSave)
|
||||
.then(outAddress);
|
||||
}
|
||||
|
||||
dropNonReservedPeers () {
|
||||
return this._transport
|
||||
.execute('parity_dropNonReservedPeers');
|
||||
@@ -137,6 +151,11 @@ export default class Parity {
|
||||
.execute('parity_executeUpgrade');
|
||||
}
|
||||
|
||||
exportAccount (address, password) {
|
||||
return this._transport
|
||||
.execute('parity_exportAccount', inAddress(address), password);
|
||||
}
|
||||
|
||||
extraData () {
|
||||
return this._transport
|
||||
.execute('parity_extraData');
|
||||
@@ -401,6 +420,12 @@ export default class Parity {
|
||||
.execute('parity_removeReservedPeer', encode);
|
||||
}
|
||||
|
||||
removeTransaction (hash) {
|
||||
return this._transport
|
||||
.execute('parity_removeTransaction', inHex(hash))
|
||||
.then(outTransaction);
|
||||
}
|
||||
|
||||
rpcSettings () {
|
||||
return this._transport
|
||||
.execute('parity_rpcSettings');
|
||||
|
||||
Reference in New Issue
Block a user