Fixed getDeployTransaction with ABI objects and added support for indexed parameters in event logs.
This commit is contained in:
parent
4b41c0e1a2
commit
1531793084
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user