@@ -148,8 +148,19 @@ function Contract(address, contractInterface, signerOrProvider) {
148148 var noncePromise = null ;
149149 if ( transaction . nonce ) {
150150 noncePromise = Promise . resolve ( transaction . nonce )
151+ } else if ( signer . getTransactionCount ) {
152+ noncePromise = signer . getTransactionCount ;
153+ if ( ! ( noncePromise instanceof Promise ) ) {
154+ noncePromise = Promise . resolve ( noncePromise ) ;
155+ }
151156 } else {
152- noncePromise = provider . getTransactionCount ( signer . address , 'pending' ) ;
157+ var addressPromise = signer . getAddress ( ) ;
158+ if ( ! ( addressPromise instanceof Promise ) ) {
159+ addressPromise = Promise . resolve ( addressPromise ) ;
160+ }
161+ noncePromise = addressPromise . then ( function ( address ) {
162+ return provider . getTransactionCount ( address , 'pending' ) ;
163+ } ) ;
153164 }
154165
155166 var gasPricePromise = null ;
@@ -208,7 +219,7 @@ function Contract(address, contractInterface, signerOrProvider) {
208219
209220 function handleEvent ( log ) {
210221 try {
211- var result = eventInfo . parse ( log . data ) ;
222+ var result = eventInfo . parse ( log . topics , log . data ) ;
212223 eventCallback . apply ( log , Array . prototype . slice . call ( result ) ) ;
213224 } catch ( error ) {
214225 console . log ( error ) ;
@@ -245,7 +256,8 @@ function Contract(address, contractInterface, signerOrProvider) {
245256}
246257
247258utils . defineProperty ( Contract , 'getDeployTransaction' , function ( bytecode , contractInterface ) {
248- if ( typeof ( contractInterface ) === 'string' ) {
259+
260+ if ( ! ( contractInterface instanceof Interface ) ) {
249261 contractInterface = new Interface ( contractInterface ) ;
250262 }
251263
@@ -708,7 +720,6 @@ function Interface(abi) {
708720 case 'event' :
709721 var func = ( function ( ) {
710722 var inputTypes = getKeys ( method . inputs , 'type' ) ;
711- var inputNames = getKeys ( method . inputs , 'name' , true ) ;
712723 var func = function ( ) {
713724 var signature = method . name + '(' + getKeys ( method . inputs , 'type' ) . join ( ',' ) + ')' ;
714725 var result = {
@@ -717,12 +728,50 @@ function Interface(abi) {
717728 signature : signature ,
718729 topics : [ utils . keccak256 ( utils . toUtf8Bytes ( signature ) ) ] ,
719730 } ;
720- result . parse = function ( data ) {
721- return Interface . decodeParams (
722- inputNames ,
723- inputTypes ,
731+
732+ result . parse = function ( topics , data ) {
733+
734+ // Strip the signature off of non-anonymous topics
735+ if ( ! method . anonymous ) { topics = topics . slice ( 1 ) ; }
736+
737+ var inputNamesIndexed = [ ] , inputNamesNonIndexed = [ ] ;
738+ var inputTypesIndexed = [ ] , inputTypesNonIndexed = [ ] ;
739+ method . inputs . forEach ( function ( input ) {
740+ if ( input . indexed ) {
741+ inputNamesIndexed . push ( input . name ) ;
742+ inputTypesIndexed . push ( input . type ) ;
743+ } else {
744+ inputNamesNonIndexed . push ( input . name ) ;
745+ inputTypesNonIndexed . push ( input . type ) ;
746+ }
747+ } ) ;
748+
749+ var resultIndexed = Interface . decodeParams (
750+ inputNamesIndexed ,
751+ inputTypesIndexed ,
752+ utils . concat ( topics )
753+ ) ;
754+
755+ var resultNonIndexed = Interface . decodeParams (
756+ inputNamesNonIndexed ,
757+ inputTypesNonIndexed ,
724758 utils . arrayify ( data )
725759 ) ;
760+
761+ var result = new Result ( ) ;
762+ var nonIndexedIndex = 0 , indexedIndex = 0 ;
763+ method . inputs . forEach ( function ( input , i ) {
764+ if ( input . indexed ) {
765+ result [ i ] = resultIndexed [ indexedIndex ++ ] ;
766+ } else {
767+ result [ i ] = resultNonIndexed [ nonIndexedIndex ++ ] ;
768+ }
769+ if ( input . name ) { result [ input . name ] = result [ i ] ; }
770+ } ) ;
771+
772+ result . length = method . inputs . length ;
773+
774+ return result ;
726775 } ;
727776 return populateDescription ( new EventDescription ( ) , result ) ;
728777 }
@@ -746,7 +795,7 @@ function Interface(abi) {
746795 }
747796 } ;
748797
749- abi . forEach ( addMethod , this ) ;
798+ this . abi . forEach ( addMethod , this ) ;
750799
751800 // If there wasn't a constructor, create the default constructor
752801 if ( ! deploy ) {
0 commit comments