import { Account , AddressString , Block , Contract , GetOptions , Hash256String , IterOptions , NetworkSettings , NetworkType , RawApplicationLogData , RawCallReceipt , RawTransactionData , RelayTransactionResult , ScriptBuilderParam , Transaction , TransactionModel , TransactionReceipt , UInt160Hex , } from '@neo-one/client-common' ; import BigNumber from 'bignumber.js' ; import { BehaviorSubject , Observable } from 'rxjs' ; import { UnknownNetworkError } from '../errors' ; import { Provider } from '../user' ; import { NEOONEDataProvider , NEOONEDataProviderOptions } from './NEOONEDataProvider' ; /**
 * Implements the `Provider` interface expected by a `LocalUserAccountProvider` using a NEO•ONE node.
 */ export class NEOONEProvider implements Provider { public readonly networks$ : Observable < readonly NetworkType [ ] > ; private readonly networksInternal$ : BehaviorSubject < readonly NetworkType [ ] > ; private readonly mutableProviders : { [ key ] : NEOONEDataProvider | undefined ; } ; public constructor ( options = [ ] ) { this . networksInternal$ = new BehaviorSubject < readonly NetworkType [ ] > ( [ ] ) ; this . networks$ = this . networksInternal$ ; this . mutableProviders = { } ; const networks = options . map ( ( opts ) => { this . mutableProviders [ opts . network ] = opts instanceof NEOONEDataProvider ? opts : new NEOONEDataProvider ( opts ) ; return opts . network ; } ) ; this . networksInternal$ . next ( networks ) ; } public getNetworks ( ) { return this . networksInternal$ . getValue ( ) ; } public addNetwork ( options ) { const { network , rpcURL } = options ; this . mutableProviders [ network ] = new NEOONEDataProvider ( { network , rpcURL } ) ; const networks = this . networksInternal$ . value . filter ( ( net ) => network !== net ) . concat ( [ network ] ) ; this . networksInternal$ . next ( networks ) ; } public async getUnclaimed ( network , address ) { return this . getProvider ( network ) . getUnclaimed ( address ) ; } public async relayTransaction ( network , transaction ) { return this . getProvider ( network ) . relayTransaction ( transaction ) ; } public async getTransactionReceipt ( network , hash , options ? ) { return this . getProvider ( network ) . getTransactionReceipt ( hash , options ) ; } public async getTransactionData ( network , hash ) { return this . getProvider ( network ) . getTransactionData ( hash ) ; } public async getApplicationLogData ( network , hash ) { return this . getProvider ( network ) . getApplicationLogData ( hash ) ; } public async testInvoke ( network , script ) { return this . getProvider ( network ) . testInvoke ( script ) ; } public async getFeePerByte ( network ) { return this . getProvider ( network ) . getFeePerByte ( ) ; } public async getExecFeeFactor ( network ) { return this . getProvider ( network ) . getExecFeeFactor ( ) ; } public async getVerificationCost ( network , hash , transaction ) { return this . getProvider ( network ) . getVerificationCost ( hash , transaction ) ; } public async testTransaction ( network , transaction ) { return this . getProvider ( network ) . testTransaction ( transaction ) ; } public async call ( network , contract , method , params ) { return this . getProvider ( network ) . call ( contract , method , params ) ; } public async getNetworkSettings ( network ) { return this . getProvider ( network ) . getNetworkSettings ( ) ; } public async getBlockCount ( network ) { return this . getProvider ( network ) . getBlockCount ( ) ; } public async getTransaction ( network , hash ) { return this . getProvider ( network ) . getTransaction ( hash ) ; } public read ( network ) { return this . getProvider ( network ) ; } public async getAccount ( network , address ) { return this . getProvider ( network ) . getAccount ( address ) ; } public async getContract ( network , address ) { return this . getProvider ( network ) . getContract ( address ) ; } public iterBlocks ( network , options = { } ) { return this . getProvider ( network ) . iterBlocks ( options ) ; } private getProvider ( network ) { const provider = this . mutableProviders [ network ] ; if ( provider === undefined ) { throw new UnknownNetworkError ( network ) ; } return provider ; } }