import { H256 } from "codechain-primitives" ; import { Rpc } from "." ; export class DevelRpc { private rpc : Rpc ; hidden constructor ( rpc ) { this . rpc = rpc ; } param offset param limit returns public getStateTrieKeys ( offset , limit ) { if ( typeof offset !== "number" || ! Number . isInteger ( offset ) || offset < 0 ) { throw Error ( `Expected the first argument to be non-negative integer but found ${ offset }` ) ; } if ( typeof limit !== "number" || ! Number . isInteger ( limit ) || limit <= 0 ) { throw Error ( `Expected the second argument to be posivit integer but found ${ limit }` ) ; } return new Promise ( ( resolve , reject ) => { this . rpc . sendRpcRequest ( "devel_getStateTrieKeys" , [ offset , limit ] ) . then ( result => { if ( ! Array . isArray ( result ) ) { return reject ( Error ( `Expected devel_getStateTrieKeys to return an array but it returned ${ result }` ) ) ; } result . forEach ( ( value , index , arr ) => { try { arr [ index ] = new H256 ( value ) ; } catch ( e ) { return reject ( Error ( `Expected devel_getStateTrieKeys() to return an array of H256, but an error occurred: ${ e . toString ( ) }` ) ) ; } } ) ; resolve ( result ) ; } ) . catch ( reject ) ; } ) ; } param key returns public getStateTrieValue ( key ) { if ( ! H256 . check ( key ) ) { throw Error ( `Expected the first argument to be an H256 value but found ${ key }` ) ; } return new Promise ( ( resolve , reject ) => { this . rpc . sendRpcRequest ( "devel_getStateTrieValue" , [ `0x${ H256 . ensure ( key ) . value }` ] ) . then ( result => { if ( ! Array . isArray ( result ) ) { return reject ( Error ( `Expected devel_getStateTrieValue to return an array but it returned ${ result }` ) ) ; } result . forEach ( ( value , index ) => { if ( typeof value !== "string" ) { return reject ( Error ( `Expected devel_getStateTrieValue to return an array of strings but found ${ value } at ${ index }` ) ) ; } } ) ; resolve ( result ) ; } ) . catch ( reject ) ; } ) ; } returns public startSealing ( ) { return new Promise ( ( resolve , reject ) => { this . rpc . sendRpcRequest ( "devel_startSealing" , [ ] ) . then ( result => { if ( result === null ) { return resolve ( null ) ; } reject ( Error ( `Expected devel_startSealing to return null but it returned ${ result }` ) ) ; } ) . catch ( reject ) ; } ) ; } returns public stopSealing ( ) { return new Promise ( ( resolve , reject ) => { this . rpc . sendRpcRequest ( "devel_stopSealing" , [ ] ) . then ( result => { if ( result === null ) { return resolve ( null ) ; } reject ( Error ( `Expected devel_stopSealing to return null but it returned ${ result }` ) ) ; } ) . catch ( reject ) ; } ) ; } }