JS API interface for parity_chainStatus
This commit is contained in:
parent
e1adc9606f
commit
d89ee5432e
@ -66,6 +66,20 @@ export function outBlock (block) {
|
||||
return block;
|
||||
}
|
||||
|
||||
export function outChainStatus (status) {
|
||||
if (status) {
|
||||
Object.keys(status).forEach((key) => {
|
||||
switch (key) {
|
||||
case 'blockGap':
|
||||
status[key] = status[key].map(outNumber);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
export function outDate (date) {
|
||||
return new Date(outNumber(date).toNumber() * 1000);
|
||||
}
|
||||
@ -77,6 +91,7 @@ export function outHistogram (histogram) {
|
||||
case 'bucketBounds':
|
||||
case 'counts':
|
||||
histogram[key] = histogram[key].map(outNumber);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
import BigNumber from 'bignumber.js';
|
||||
|
||||
import { outBlock, outAccountInfo, outAddress, outDate, outHistogram, outNumber, outPeers, outReceipt, outSyncing, outTransaction, outTrace } from './output';
|
||||
import { outBlock, outAccountInfo, outAddress, outChainStatus, outDate, outHistogram, outNumber, outPeers, outReceipt, outSyncing, outTransaction, outTrace } from './output';
|
||||
import { isAddress, isBigNumber, isInstanceOf } from '../../../test/types';
|
||||
|
||||
describe('api/format/output', () => {
|
||||
@ -114,6 +114,18 @@ describe('api/format/output', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('outChainStatus', () => {
|
||||
it('formats blockGap values', () => {
|
||||
const status = {
|
||||
blockGap: [0x1234, '0x5678']
|
||||
};
|
||||
|
||||
expect(outChainStatus(status)).to.deep.equal({
|
||||
blockGap: [new BigNumber(0x1234), new BigNumber(0x5678)]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('outDate', () => {
|
||||
it('converts a second date in unix timestamp', () => {
|
||||
expect(outDate(0x57513668)).to.deep.equal(new Date('2016-06-03T07:48:56.000Z'));
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import { inAddress, inData, inHex, inNumber16, inOptions } from '../../format/input';
|
||||
import { outAccountInfo, outAddress, outHistogram, outNumber, outPeers, outTransaction } from '../../format/output';
|
||||
import { outAccountInfo, outAddress, outChainStatus, outHistogram, outNumber, outPeers, outTransaction } from '../../format/output';
|
||||
|
||||
export default class Parity {
|
||||
constructor (transport) {
|
||||
@ -44,6 +44,12 @@ export default class Parity {
|
||||
.execute('parity_addReservedPeer', encode);
|
||||
}
|
||||
|
||||
chainStatus () {
|
||||
return this._transport
|
||||
.execute('parity_chainStatus')
|
||||
.then(outChainStatus);
|
||||
}
|
||||
|
||||
changePassword (account, password, newPassword) {
|
||||
return this._transport
|
||||
.execute('parity_changePassword', inAddress(account), password, newPassword);
|
||||
|
@ -14,6 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
|
||||
import { isBigNumber } from '../../../../test/types';
|
||||
|
||||
@ -45,6 +46,22 @@ describe('api/rpc/parity', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('chainStatus', () => {
|
||||
it('retrieves the chain status', () => {
|
||||
mockHttp([{ method: 'parity_chainStatus', reply: {
|
||||
result: {
|
||||
'blockGap': [0x123, 0x456]
|
||||
}
|
||||
} }]);
|
||||
|
||||
return instance.chainStatus().then((result) => {
|
||||
expect(result).to.deep.equal({
|
||||
'blockGap': [new BigNumber(0x123), new BigNumber(0x456)]
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('gasFloorTarget', () => {
|
||||
it('returns the gasfloor, formatted', () => {
|
||||
mockHttp([{ method: 'parity_gasFloorTarget', reply: { result: '0x123456' } }]);
|
||||
|
@ -86,6 +86,22 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
chainStatus: {
|
||||
desc: 'Returns the information on warp sync blocks',
|
||||
params: [],
|
||||
returns: {
|
||||
type: Object,
|
||||
desc: 'The status object',
|
||||
details: {
|
||||
blockGap: {
|
||||
type: Array,
|
||||
desc: 'Describes the gap in the blockchain, if there is one: (first, last)',
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
checkRequest: {
|
||||
desc: 'Returns the transactionhash of the requestId (received from parity_postTransaction) if the request was confirmed',
|
||||
params: [
|
||||
|
Loading…
Reference in New Issue
Block a user