import { DeveloperClient , JSONRPCProvider , JSONRPCRequest , JSONRPCResponse , NEOONEDataProvider , } from '@neo-one/client-core' ; import { constants } from '@neo-one/utils' ; import { FullNode , FullNodeOptions } from './FullNode' ; let startPromise ; const start = async ( options , provider , build ) => { if ( startPromise === undefined ) { const node = new FullNode ( options , new DeveloperClient ( new NEOONEDataProvider ( { network : constants . LOCAL_NETWORK_NAME , rpcURL : provider } ) ) , build ) ; startPromise = node . start ( ) . then ( ( ) => node ) ; } return startPromise ; } ; const handleRequest = async ( options , provider , build , req ) => { const node = await start ( options , provider , build ) ; const { watchTimeoutMS , params = [ ] } = req ; return node . handleRequest ( { jsonrpc : '2.0' , id : 1 , method : req . method , params : watchTimeoutMS === undefined ? params : params . concat ( [ watchTimeoutMS ] ) } ) ; } ; export interface JSONRPCLocalProviderOptions { readonly options : FullNodeOptions ; readonly build : ( ) => Promise < void > ; } export class JSONRPCLocalProvider extends JSONRPCProvider { public constructor ( private readonly options ) { super ( ) ; } public async request ( req ) { const options = await this . getOptions ( ) ; const response = await handleRequest ( options . options , this , options . build , req ) ; return this . handleResponse ( response ) ; } private async getOptions ( ) { return this . options ; } }