diff --git a/contracts/contract.js b/contracts/contract.js index 9d81419ed..116400d41 100644 --- a/contracts/contract.js +++ b/contracts/contract.js @@ -147,8 +147,19 @@ function Contract(address, contractInterface, signerOrProvider) { var noncePromise = null; if (transaction.nonce) { noncePromise = Promise.resolve(transaction.nonce) + } else if (signer.getTransactionCount) { + noncePromise = signer.getTransactionCount; + if (!(noncePromise instanceof Promise)) { + noncePromise = Promise.resolve(noncePromise); + } } else { - noncePromise = provider.getTransactionCount(signer.address, 'pending'); + var addressPromise = signer.getAddress(); + if (!(addressPromise instanceof Promise)) { + addressPromise = Promise.resolve(addressPromise); + } + noncePromise = addressPromise.then(function(address) { + return provider.getTransactionCount(address, 'pending'); + }); } var gasPricePromise = null; @@ -207,7 +218,7 @@ function Contract(address, contractInterface, signerOrProvider) { function handleEvent(log) { try { - var result = eventInfo.parse(log.data); + var result = eventInfo.parse(log.topics, log.data); eventCallback.apply(log, Array.prototype.slice.call(result)); } catch (error) { console.log(error); @@ -244,7 +255,8 @@ function Contract(address, contractInterface, signerOrProvider) { } utils.defineProperty(Contract, 'getDeployTransaction', function(bytecode, contractInterface) { - if (typeof(contractInterface) === 'string') { + + if (!(contractInterface instanceof Interface)) { contractInterface = new Interface(contractInterface); } diff --git a/contracts/interface.js b/contracts/interface.js index e909c9575..0d6d3a7a9 100644 --- a/contracts/interface.js +++ b/contracts/interface.js @@ -432,7 +432,6 @@ function Interface(abi) { case 'event': var func = (function() { var inputTypes = getKeys(method.inputs, 'type'); - var inputNames = getKeys(method.inputs, 'name', true); var func = function() { var signature = method.name + '(' + getKeys(method.inputs, 'type').join(',') + ')'; var result = { @@ -441,12 +440,50 @@ function Interface(abi) { signature: signature, topics: [utils.keccak256(utils.toUtf8Bytes(signature))], }; - result.parse = function(data) { - return Interface.decodeParams( - inputNames, - inputTypes, + + result.parse = function(topics, data) { + + // Strip the signature off of non-anonymous topics + if (!method.anonymous) { topics = topics.slice(1); } + + var inputNamesIndexed = [], inputNamesNonIndexed = []; + var inputTypesIndexed = [], inputTypesNonIndexed = []; + method.inputs.forEach(function(input) { + if (input.indexed) { + inputNamesIndexed.push(input.name); + inputTypesIndexed.push(input.type); + } else { + inputNamesNonIndexed.push(input.name); + inputTypesNonIndexed.push(input.type); + } + }); + + var resultIndexed = Interface.decodeParams( + inputNamesIndexed, + inputTypesIndexed, + utils.concat(topics) + ); + + var resultNonIndexed = Interface.decodeParams( + inputNamesNonIndexed, + inputTypesNonIndexed, utils.arrayify(data) ); + + var result = new Result(); + var nonIndexedIndex = 0, indexedIndex = 0; + method.inputs.forEach(function(input, i) { + if (input.indexed) { + result[i] = resultIndexed[indexedIndex++]; + } else { + result[i] = resultNonIndexed[nonIndexedIndex++]; + } + if (input.name) { result[input.name] = result[i]; } + }); + + result.length = method.inputs.length; + + return result; }; return populateDescription(new EventDescription(), result); } @@ -470,7 +507,7 @@ function Interface(abi) { } }; - abi.forEach(addMethod, this); + this.abi.forEach(addMethod, this); // If there wasn't a constructor, create the default constructor if (!deploy) { diff --git a/contracts/package.json b/contracts/package.json index 22321eae8..8feb22e7f 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -1,6 +1,6 @@ { "name": "ethers-contracts", - "version": "2.0.0", + "version": "2.0.1", "description": "Contract and Interface (ABI) library for Ethereum.", "bugs": { "url": "http://github.com/ethers-io/ethers.js/issues",