import * as utils from './utils/utils' ; import * as formatters from './utils/formatters' ; import { SolidityEvent } from './SolidityEvent' ; import { RequestManager } from './RequestManager' ; import { EthFilter } from './Filter' ; import { AbiEvent , FilterOptions , LogObject } from './Schema' ; export class AllSolidityEvents { constructor ( public _requestManager , public _json , public _address ) { } encode ( options = { } ) { let result = { address : this . _address } ; if ( options . fromBlock !== undefined ) result . fromBlock = formatters . inputBlockNumberFormatter ( options . fromBlock ) || undefined ; if ( options . toBlock !== undefined ) result . toBlock = formatters . inputBlockNumberFormatter ( options . toBlock ) || undefined ; return result ; } decode ( data ) { data . data = data . data || '' ; let eventTopic = utils . isArray ( data . topics ) && utils . isString ( data . topics [ 0 ] ) ? data . topics [ 0 ] . slice ( 2 ) : '' ; let match = this . _json . filter ( function ( j ) { return eventTopic === utils . sha3 ( utils . transformToFullName ( j ) ) ; } ) [ 0 ] ; if ( ! match ) { return formatters . outputLogFormatter ( data ) ; } let event = new SolidityEvent ( this . _requestManager , match , this . _address ) ; return event . decode ( data ) ; } async execute ( options ) { let filterOptions = this . encode ( options ) ; let formatter = this . decode . bind ( this ) ; return new EthFilter < any > ( this . _requestManager , filterOptions , formatter ) ; } getAllEventsFunction ( ) { return this . execute . bind ( this ) ; } }