Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
values.forEach((value, index) => {
let param = eventFragment.inputs[index];
if (!param.indexed) {
if (value != null) {
logger.throwArgumentError("cannot filter non-indexed parameters; must be null", ("contract." + param.name), value);
}
return;
}
if (value == null) {
topics.push(null);
}
else if (param.type === "string") {
topics.push(id(value));
}
else if (param.type === "bytes") {
topics.push(keccak256(hexlify(value)));
}
else if (param.type.indexOf("[") !== -1 || param.type.substring(0, 5) === "tuple") {
logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
}
else {
// Check addresses are valid
if (param.type === "address") {
this._abiCoder.encode(["address"], [value]);
}
topics.push(hexZeroPad(hexlify(value), 32));
}
});
// Trim off trailing nulls
values.forEach(function (value, index) {
var param = eventFragment.inputs[index];
if (!param.indexed) {
if (value != null) {
logger.throwArgumentError("cannot filter non-indexed parameters; must be null", ("contract." + param.name), value);
}
return;
}
if (value == null) {
topics.push(null);
}
else if (param.type === "string") {
topics.push(hash_1.id(value));
}
else if (param.type === "bytes") {
topics.push(keccak256_1.keccak256(bytes_1.hexlify(value)));
}
else if (param.type.indexOf("[") !== -1 || param.type.substring(0, 5) === "tuple") {
logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
}
else {
// Check addresses are valid
if (param.type === "address") {
_this._abiCoder.encode(["address"], [value]);
}
topics.push(bytes_1.hexZeroPad(bytes_1.hexlify(value), 32));
}
});
// Trim off trailing nulls
case 1:
address = _b.sent();
_b.label = 2;
case 2:
address = this.formatter.address(address);
reverseName = address.substring(2).toLowerCase() + ".addr.reverse";
return [4 /*yield*/, this._getResolver(reverseName)];
case 3:
resolverAddress = _b.sent();
if (!resolverAddress) {
return [2 /*return*/, null];
}
_a = bytes_1.arrayify;
return [4 /*yield*/, this.call({
to: resolverAddress,
data: ("0x691f3431" + hash_1.namehash(reverseName).substring(2))
})];
case 4:
bytes = _a.apply(void 0, [_b.sent()]);
// Strip off the dynamic string pointer (0x20)
if (bytes.length < 32 || !bignumber_1.BigNumber.from(bytes.slice(0, 32)).eq(32)) {
return [2 /*return*/, null];
}
bytes = bytes.slice(32);
// Not a length-prefixed string
if (bytes.length < 32) {
return [2 /*return*/, null];
}
length = bignumber_1.BigNumber.from(bytes.slice(0, 32)).toNumber();
bytes = bytes.slice(32);
// Length longer than available data
if (length > bytes.length) {
_c.label = 2;
case 2:
// If it is already an address, nothing to resolve
try {
return [2 /*return*/, Promise.resolve(this.formatter.address(name))];
}
catch (error) { }
return [4 /*yield*/, this._getResolver(name)];
case 3:
resolverAddress = _c.sent();
if (!resolverAddress) {
return [2 /*return*/, null];
}
transaction = {
to: resolverAddress,
data: ("0x3b3b57de" + hash_1.namehash(name).substring(2))
};
_b = (_a = this.formatter).callAddress;
return [4 /*yield*/, this.call(transaction)];
case 4: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
}
});
});
return __awaiter(this, void 0, void 0, function* () {
// Get the resolver from the blockchain
const network = yield this.getNetwork();
// No ENS...
if (!network.ensAddress) {
logger.throwError("network does not support ENS", Logger.errors.UNSUPPORTED_OPERATION, { operation: "ENS", network: network.name });
}
// keccak256("resolver(bytes32)")
const transaction = {
to: network.ensAddress,
data: ("0x0178b8bf" + namehash(name).substring(2))
};
return this.formatter.callAddress(yield this.call(transaction));
});
}
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, this.getNetwork()];
case 1:
network = _c.sent();
// No ENS...
if (!network.ensAddress) {
logger.throwError("network does not support ENS", logger_1.Logger.errors.UNSUPPORTED_OPERATION, { operation: "ENS", network: network.name });
}
transaction = {
to: network.ensAddress,
data: ("0x0178b8bf" + hash_1.namehash(name).substring(2))
};
_b = (_a = this.formatter).callAddress;
return [4 /*yield*/, this.call(transaction)];
case 2: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
}
});
});
name = yield name;
}
// If it is already an address, nothing to resolve
try {
return Promise.resolve(this.formatter.address(name));
}
catch (error) { }
// Get the addr from the resovler
const resolverAddress = yield this._getResolver(name);
if (!resolverAddress) {
return null;
}
// keccak256("addr(bytes32)")
const transaction = {
to: resolverAddress,
data: ("0x3b3b57de" + namehash(name).substring(2))
};
return this.formatter.callAddress(yield this.call(transaction));
});
}
Wordlist.check = function (wordlist) {
var words = [];
for (var i = 0; i < 2048; i++) {
var word = wordlist.getWord(i);
if (i !== wordlist.getWordIndex(word)) {
return "0x";
}
words.push(word);
}
return hash_1.id(words.join("\n") + "\n");
};
Wordlist.register = function (lang, name) {
Interface.prototype._sighashify = function (functionFragment) {
return bytes_1.hexDataSlice(hash_1.id(functionFragment.format()), 0, 4);
};
Interface.prototype._topicify = function (eventFragment) {
function check(wordlist) {
var words = [];
for (var i = 0; i < 2048; i++) {
var word = wordlist.getWord(i);
if (i !== wordlist.getWordIndex(word)) {
return "0x";
}
words.push(word);
}
return hash_1.id(words.join("\n") + "\n");
}
exports.check = check;