Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Updating documentation for RPCs #5392

Merged
merged 6 commits into from
Apr 8, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions js/scripts/build-rpc-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ Object.keys(rustMethods).forEach((group) => {
});
});

function printType (type) {
function printType (type, obj) {
if (!type) {
throw new Error(`Invalid type in ${JSON.stringify(obj)}`);
}

return type.print || `\`${type.name}\``;
}

function formatDescription (obj, prefix = '', indent = '') {
const optional = obj.optional ? '(optional) ' : '';
const defaults = obj.default ? `(default: \`${obj.default}\`) ` : '';

return `${indent}${prefix}${printType(obj.type)} - ${optional}${defaults}${obj.desc}`;
return `${indent}${prefix}${printType(obj.type, obj)} - ${optional}${defaults}${obj.desc}`;
}

function formatType (obj) {
Expand Down
35 changes: 31 additions & 4 deletions js/src/api/format/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -211,3 +207,34 @@ export function inTraceType (whatTrace) {

return whatTrace;
}

function inDeriveType (derive) {
return derive && derive.type === 'hard' ? 'hard' : 'soft';
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would put a new line after here as well

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter requires a new line

return {
index,
type: inDeriveType(item)
}
});
}
74 changes: 70 additions & 4 deletions js/src/api/format/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 = {};

Expand All @@ -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', () => {
Expand Down Expand Up @@ -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'
}
]);
});
});
});
6 changes: 0 additions & 6 deletions js/src/api/format/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
6 changes: 3 additions & 3 deletions js/src/api/format/output.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand All @@ -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', () => {
Expand Down
27 changes: 26 additions & 1 deletion js/src/api/rpc/parity/parity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
Loading