forked from tornado-packages/ethers.js
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d54609a458 | ||
|
|
f682861e0b | ||
|
|
023a20ff47 | ||
|
|
e39cd84923 | ||
|
|
5020897f10 |
2
_version.d.ts
vendored
2
_version.d.ts
vendored
@@ -1 +1 @@
|
||||
export declare const version = "4.0.5";
|
||||
export declare const version = "4.0.6";
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = "4.0.5";
|
||||
exports.version = "4.0.6";
|
||||
|
||||
16
dist/ethers.js
vendored
16
dist/ethers.js
vendored
@@ -1,7 +1,7 @@
|
||||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ethers = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = "4.0.5";
|
||||
exports.version = "4.0.6";
|
||||
|
||||
},{}],2:[function(require,module,exports){
|
||||
"use strict";
|
||||
@@ -14088,15 +14088,17 @@ var _EventDescription = /** @class */ (function (_super) {
|
||||
topics.push(this.topic);
|
||||
}
|
||||
params.forEach(function (arg, index) {
|
||||
if (arg === null) {
|
||||
topics.push(null);
|
||||
return;
|
||||
}
|
||||
var param = _this.inputs[index];
|
||||
if (!param.indexed) {
|
||||
errors.throwError('cannot filter non-indexed parameters; must be null', errors.INVALID_ARGUMENT, { argument: (param.name || index), value: arg });
|
||||
if (arg != null) {
|
||||
errors.throwError('cannot filter non-indexed parameters; must be null', errors.INVALID_ARGUMENT, { argument: (param.name || index), value: arg });
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (param.type === 'string') {
|
||||
if (arg == null) {
|
||||
topics.push(null);
|
||||
}
|
||||
else if (param.type === 'string') {
|
||||
topics.push(hash_1.id(arg));
|
||||
}
|
||||
else if (param.type === 'bytes') {
|
||||
|
||||
2
dist/ethers.min.js
vendored
2
dist/ethers.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/ethers.min.js.map
vendored
2
dist/ethers.min.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/ethers.types.txt
vendored
2
dist/ethers.types.txt
vendored
@@ -260,7 +260,7 @@ declare module 'ethers/utils/shims' {
|
||||
}
|
||||
|
||||
declare module 'ethers/_version' {
|
||||
export const version = "4.0.5";
|
||||
export const version = "4.0.6";
|
||||
}
|
||||
|
||||
declare module 'ethers/utils/bignumber' {
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ethers",
|
||||
"version": "4.0.5",
|
||||
"version": "4.0.6",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ethers",
|
||||
"version": "4.0.5",
|
||||
"version": "4.0.6",
|
||||
"description": "Ethereum wallet library.",
|
||||
"main": "./index.js",
|
||||
"types": "./index.d.ts",
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const version = "4.0.5";
|
||||
export const version = "4.0.6";
|
||||
|
||||
@@ -1212,6 +1212,8 @@ export class BaseProvider extends Provider {
|
||||
return !(event.once);
|
||||
});
|
||||
|
||||
if (this.listenerCount() === 0) { this.polling = false; }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1261,6 +1263,7 @@ export class BaseProvider extends Provider {
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
defineReadOnly(Provider, 'inherits', inheritable(Provider));
|
||||
|
||||
@@ -6,11 +6,14 @@ import { BaseProvider } from './base-provider';
|
||||
|
||||
import { Signer } from '../abstract-signer';
|
||||
|
||||
import * as errors from '../errors';
|
||||
|
||||
import { getAddress } from '../utils/address';
|
||||
import { BigNumber } from '../utils/bignumber';
|
||||
import { hexlify, hexStripZeros } from '../utils/bytes';
|
||||
import { getNetwork } from '../utils/networks';
|
||||
import { defineReadOnly, resolveProperties, shallowCopy } from '../utils/properties';
|
||||
import { checkProperties, defineReadOnly, shallowCopy } from '../utils/properties';
|
||||
import { populateTransaction } from '../utils/transaction';
|
||||
import { toUtf8Bytes } from '../utils/utf8';
|
||||
import { fetchJson, poll } from '../utils/web';
|
||||
|
||||
@@ -18,9 +21,8 @@ import { fetchJson, poll } from '../utils/web';
|
||||
import { Arrayish } from '../utils/bytes';
|
||||
import { Network, Networkish } from '../utils/networks';
|
||||
import { ConnectionInfo } from '../utils/web';
|
||||
import { BlockTag, TransactionRequest, TransactionResponse } from '../providers/abstract-provider';
|
||||
|
||||
import * as errors from '../errors';
|
||||
import { BlockTag, TransactionRequest, TransactionResponse } from '../providers/abstract-provider';
|
||||
|
||||
function timer(timeout: number): Promise<any> {
|
||||
return new Promise(function(resolve) {
|
||||
@@ -78,15 +80,6 @@ export class JsonRpcSigner extends Signer {
|
||||
}
|
||||
}
|
||||
|
||||
/* May add back in the future; for now it is considered confusing. :)
|
||||
get address(): string {
|
||||
if (!this._address) {
|
||||
errors.throwError('no sync sync address available; use getAddress', errors.UNSUPPORTED_OPERATION, { operation: 'address' });
|
||||
}
|
||||
return this._address
|
||||
}
|
||||
*/
|
||||
|
||||
getAddress(): Promise<string> {
|
||||
if (this._address) {
|
||||
return Promise.resolve(this._address);
|
||||
@@ -110,21 +103,18 @@ export class JsonRpcSigner extends Signer {
|
||||
}
|
||||
|
||||
sendTransaction(transaction: TransactionRequest): Promise<TransactionResponse> {
|
||||
let tx: TransactionRequest = shallowCopy(transaction);
|
||||
|
||||
if (tx.from == null) {
|
||||
tx.from = this.getAddress().then((address) => {
|
||||
if (!address) { return null; }
|
||||
return address.toLowerCase();
|
||||
});
|
||||
}
|
||||
// Once populateTransaction resolves, the from address will be populated from getAddress
|
||||
let from: string = null;
|
||||
let getAddress = this.getAddress().then((address) => {
|
||||
if (address) { from = address.toLowerCase(); }
|
||||
return from;
|
||||
});
|
||||
|
||||
if (transaction.gasLimit == null) {
|
||||
tx.gasLimit = this.provider.estimateGas(tx);
|
||||
}
|
||||
|
||||
return resolveProperties(tx).then((tx) => {
|
||||
return this.provider.send('eth_sendTransaction', [ JsonRpcProvider.hexlifyTransaction(tx) ]).then((hash) => {
|
||||
return populateTransaction(transaction, this.provider, getAddress).then((tx) => {
|
||||
let hexTx = JsonRpcProvider.hexlifyTransaction(tx);
|
||||
hexTx.from = from;
|
||||
return this.provider.send('eth_sendTransaction', [ hexTx ]).then((hash) => {
|
||||
return poll(() => {
|
||||
return this.provider.getTransaction(hash).then((tx: TransactionResponse) => {
|
||||
if (tx === null) { return undefined; }
|
||||
@@ -376,21 +366,19 @@ export class JsonRpcProvider extends BaseProvider {
|
||||
// NOTE: This allows a TransactionRequest, but all values should be resolved
|
||||
// before this is called
|
||||
static hexlifyTransaction(transaction: TransactionRequest, allowExtra?: { [key: string]: boolean }): { [key: string]: string } {
|
||||
if (!allowExtra) { allowExtra = {}; }
|
||||
|
||||
for (let key in transaction) {
|
||||
if (!allowedTransactionKeys[key] && !allowExtra[key]) {
|
||||
errors.throwError('invalid key - ' + key, errors.INVALID_ARGUMENT, {
|
||||
argument: 'transaction',
|
||||
value: transaction,
|
||||
key: key
|
||||
});
|
||||
// Check only allowed properties are given
|
||||
let allowed = shallowCopy(allowedTransactionKeys);
|
||||
if (allowExtra) {
|
||||
for (let key in allowExtra) {
|
||||
if (allowExtra[key]) { allowed[key] = true; }
|
||||
}
|
||||
}
|
||||
checkProperties(transaction, allowed);
|
||||
|
||||
let result: { [key: string]: string } = {};
|
||||
|
||||
// Some nodes (INFURA ropsten; INFURA mainnet is fine) don't like extra zeros.
|
||||
// Some nodes (INFURA ropsten; INFURA mainnet is fine) don't like leading zeros.
|
||||
['gasLimit', 'gasPrice', 'nonce', 'value'].forEach(function(key) {
|
||||
if ((<any>transaction)[key] == null) { return; }
|
||||
let value = hexStripZeros(hexlify((<any>transaction)[key]));
|
||||
|
||||
@@ -14,10 +14,11 @@ import { sha256 } from './sha2';
|
||||
import { keccak256 as solidityKeccak256, pack as solidityPack, sha256 as soliditySha256 } from './solidity';
|
||||
import { randomBytes } from './random-bytes';
|
||||
import { getNetwork } from './networks';
|
||||
import { deepCopy, defineReadOnly, resolveProperties, shallowCopy } from './properties';
|
||||
import { checkProperties, deepCopy, defineReadOnly, resolveProperties, shallowCopy } from './properties';
|
||||
import * as RLP from './rlp';
|
||||
import { computeAddress, computePublicKey, recoverAddress, recoverPublicKey, verifyMessage } from './secp256k1';
|
||||
import { SigningKey } from './signing-key';
|
||||
import { populateTransaction } from './transaction';
|
||||
import { parse as parseTransaction, serialize as serializeTransaction } from './transaction';
|
||||
import { formatBytes32String, parseBytes32String, toUtf8Bytes, toUtf8String } from './utf8';
|
||||
import { commify, formatEther, parseEther, formatUnits, parseUnits } from './units';
|
||||
@@ -60,6 +61,7 @@ export {
|
||||
fetchJson,
|
||||
getNetwork,
|
||||
|
||||
checkProperties,
|
||||
deepCopy,
|
||||
defineReadOnly,
|
||||
resolveProperties,
|
||||
@@ -122,6 +124,7 @@ export {
|
||||
joinSignature,
|
||||
|
||||
parseTransaction,
|
||||
populateTransaction,
|
||||
serializeTransaction,
|
||||
|
||||
getJsonWalletAddress,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
import * as errors from '../errors';
|
||||
|
||||
export function defineReadOnly(object: any, name: string, value: any): void {
|
||||
Object.defineProperty(object, name, {
|
||||
enumerable: true,
|
||||
@@ -42,6 +44,25 @@ export function resolveProperties(object: any): Promise<any> {
|
||||
});
|
||||
}
|
||||
|
||||
export function checkProperties(object: any, properties: { [ name: string ]: boolean }): void {
|
||||
if (!object || typeof(object) !== 'object') {
|
||||
errors.throwError('invalid object', errors.INVALID_ARGUMENT, {
|
||||
argument: 'object',
|
||||
value: object
|
||||
});
|
||||
}
|
||||
|
||||
Object.keys(object).forEach((key) => {
|
||||
if (!properties[key]) {
|
||||
errors.throwError('invalid object key - ' + key, errors.INVALID_ARGUMENT, {
|
||||
argument: 'transaction',
|
||||
value: object,
|
||||
key: key
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function shallowCopy(object: any): any {
|
||||
let result: any = {};
|
||||
for (var key in object) { result[key] = object[key]; }
|
||||
|
||||
@@ -9,6 +9,7 @@ import { getAddress } from './address';
|
||||
import { BigNumber, bigNumberify } from './bignumber';
|
||||
import { arrayify, hexlify, hexZeroPad, splitSignature, stripZeros, } from './bytes';
|
||||
import { keccak256 } from './keccak256';
|
||||
import { checkProperties, resolveProperties, shallowCopy } from './properties';
|
||||
|
||||
import * as RLP from './rlp';
|
||||
|
||||
@@ -19,6 +20,8 @@ import * as RLP from './rlp';
|
||||
import { Arrayish, Signature } from './bytes';
|
||||
import { BigNumberish } from './bignumber';
|
||||
|
||||
import { Provider } from '../providers/abstract-provider';
|
||||
|
||||
///////////////////////////////
|
||||
// Exported Types
|
||||
|
||||
@@ -65,7 +68,7 @@ function handleNumber(value: string): BigNumber {
|
||||
return bigNumberify(value);
|
||||
}
|
||||
|
||||
var transactionFields = [
|
||||
const transactionFields = [
|
||||
{ name: 'nonce', maxLength: 32 },
|
||||
{ name: 'gasPrice', maxLength: 32 },
|
||||
{ name: 'gasLimit', maxLength: 32 },
|
||||
@@ -74,8 +77,14 @@ var transactionFields = [
|
||||
{ name: 'data' },
|
||||
];
|
||||
|
||||
const allowedTransactionKeys: { [ key: string ]: boolean } = {
|
||||
chainId: true, data: true, gasLimit: true, gasPrice:true, nonce: true, to: true, value: true
|
||||
}
|
||||
|
||||
export function serialize(transaction: UnsignedTransaction, signature?: Arrayish | Signature): string {
|
||||
var raw: Array<string | Uint8Array> = [];
|
||||
checkProperties(transaction, allowedTransactionKeys);
|
||||
|
||||
let raw: Array<string | Uint8Array> = [];
|
||||
|
||||
transactionFields.forEach(function(fieldInfo) {
|
||||
let value = (<any>transaction)[fieldInfo.name] || ([]);
|
||||
@@ -115,7 +124,7 @@ export function serialize(transaction: UnsignedTransaction, signature?: Arrayish
|
||||
let sig = splitSignature(signature);
|
||||
|
||||
// We pushed a chainId and null r, s on for hashing only; remove those
|
||||
var v = 27 + sig.recoveryParam
|
||||
let v = 27 + sig.recoveryParam
|
||||
if (raw.length === 9) {
|
||||
raw.pop();
|
||||
raw.pop();
|
||||
@@ -171,7 +180,7 @@ export function parse(rawTransaction: Arrayish): Transaction {
|
||||
tx.chainId = Math.floor((tx.v - 35) / 2);
|
||||
if (tx.chainId < 0) { tx.chainId = 0; }
|
||||
|
||||
var recoveryParam = tx.v - 27;
|
||||
let recoveryParam = tx.v - 27;
|
||||
|
||||
let raw = transaction.slice(0, 6);
|
||||
|
||||
@@ -182,7 +191,7 @@ export function parse(rawTransaction: Arrayish): Transaction {
|
||||
recoveryParam -= tx.chainId * 2 + 8;
|
||||
}
|
||||
|
||||
var digest = keccak256(RLP.encode(raw));
|
||||
let digest = keccak256(RLP.encode(raw));
|
||||
try {
|
||||
tx.from = recoverAddress(digest, { r: hexlify(tx.r), s: hexlify(tx.s), recoveryParam: recoveryParam });
|
||||
} catch (error) {
|
||||
@@ -194,3 +203,41 @@ export function parse(rawTransaction: Arrayish): Transaction {
|
||||
|
||||
return tx;
|
||||
}
|
||||
|
||||
export function populateTransaction(transaction: any, provider: Provider, from: string | Promise<string>): Promise<Transaction> {
|
||||
|
||||
if (!Provider.isProvider(provider)) {
|
||||
errors.throwError('missing provider', errors.INVALID_ARGUMENT, {
|
||||
argument: 'provider',
|
||||
value: provider
|
||||
});
|
||||
}
|
||||
|
||||
checkProperties(transaction, allowedTransactionKeys);
|
||||
|
||||
let tx = shallowCopy(transaction);
|
||||
|
||||
if (tx.to != null) {
|
||||
tx.to = provider.resolveName(tx.to);
|
||||
}
|
||||
|
||||
if (tx.gasPrice == null) {
|
||||
tx.gasPrice = provider.getGasPrice();
|
||||
}
|
||||
|
||||
if (tx.nonce == null) {
|
||||
tx.nonce = provider.getTransactionCount(from);
|
||||
}
|
||||
|
||||
if (tx.gasLimit == null) {
|
||||
let estimate = shallowCopy(tx);
|
||||
estimate.from = from;
|
||||
tx.gasLimit = provider.estimateGas(estimate);
|
||||
}
|
||||
|
||||
if (tx.chainId == null) {
|
||||
tx.chainId = provider.getNetwork().then((network) => network.chainId);
|
||||
}
|
||||
|
||||
return resolveProperties(tx);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { XMLHttpRequest } from 'xmlhttprequest';
|
||||
|
||||
import { encode as base64Encode } from './base64';
|
||||
import { shallowCopy } from './properties';
|
||||
import { toUtf8Bytes } from './utf8';
|
||||
|
||||
import * as errors from '../errors';
|
||||
@@ -180,6 +181,7 @@ export function fetchJson(connection: string | ConnectionInfo, json: string, pro
|
||||
|
||||
export function poll(func: () => Promise<any>, options?: PollOptions): Promise<any> {
|
||||
if (!options) { options = {}; }
|
||||
options = shallowCopy(options);
|
||||
if (options.floor == null) { options.floor = 0; }
|
||||
if (options.ceiling == null) { options.ceiling = 10000; }
|
||||
if (options.interval == null) { options.interval = 250; }
|
||||
|
||||
@@ -10,7 +10,7 @@ import { defineReadOnly, resolveProperties, shallowCopy } from './utils/properti
|
||||
import { randomBytes } from './utils/random-bytes';
|
||||
import * as secretStorage from './utils/secret-storage';
|
||||
import { SigningKey } from './utils/signing-key';
|
||||
import { serialize as serializeTransaction } from './utils/transaction';
|
||||
import { populateTransaction, serialize as serializeTransaction } from './utils/transaction';
|
||||
import { Wordlist } from './utils/wordlist';
|
||||
|
||||
// Imported Abstracts
|
||||
@@ -24,10 +24,6 @@ import { BlockTag, TransactionRequest, TransactionResponse } from './providers/a
|
||||
|
||||
import * as errors from './errors';
|
||||
|
||||
const allowedTransactionKeys: { [ key: string ]: boolean } = {
|
||||
chainId: true, data: true, gasLimit: true, gasPrice:true, nonce: true, to: true, value: true
|
||||
}
|
||||
|
||||
export class Wallet extends AbstractSigner {
|
||||
|
||||
readonly provider: Provider;
|
||||
@@ -72,19 +68,10 @@ export class Wallet extends AbstractSigner {
|
||||
}
|
||||
|
||||
sign(transaction: TransactionRequest): Promise<string> {
|
||||
for (let key in transaction) {
|
||||
if (!allowedTransactionKeys[key]) {
|
||||
errors.throwError('unsupported transaction property - ' + key, errors.INVALID_ARGUMENT, {
|
||||
argument: 'transaction',
|
||||
value: transaction,
|
||||
key: key
|
||||
});
|
||||
}
|
||||
}
|
||||
return resolveProperties(transaction).then((tx) => {
|
||||
let rawTx = serializeTransaction(tx);
|
||||
let signature = this.signingKey.signDigest(keccak256(rawTx));
|
||||
return Promise.resolve(serializeTransaction(tx, signature));
|
||||
return serializeTransaction(tx, signature);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -104,37 +91,11 @@ export class Wallet extends AbstractSigner {
|
||||
}
|
||||
|
||||
sendTransaction(transaction: TransactionRequest): Promise<TransactionResponse> {
|
||||
if (!this.provider) { throw new Error('missing provider'); }
|
||||
|
||||
if (!transaction || typeof(transaction) !== 'object') {
|
||||
throw new Error('invalid transaction object');
|
||||
}
|
||||
|
||||
let tx = shallowCopy(transaction);
|
||||
|
||||
if (tx.to != null) {
|
||||
tx.to = this.provider.resolveName(tx.to);
|
||||
}
|
||||
|
||||
if (tx.gasPrice == null) {
|
||||
tx.gasPrice = this.provider.getGasPrice();
|
||||
}
|
||||
|
||||
if (tx.nonce == null) {
|
||||
tx.nonce = this.getTransactionCount();
|
||||
}
|
||||
|
||||
if (tx.gasLimit == null) {
|
||||
let estimate = shallowCopy(tx);
|
||||
estimate.from = this.getAddress();
|
||||
tx.gasLimit = this.provider.estimateGas(estimate);
|
||||
}
|
||||
|
||||
if (tx.chainId == null) {
|
||||
tx.chainId = this.provider.getNetwork().then((network) => network.chainId);
|
||||
}
|
||||
|
||||
return this.provider.sendTransaction(this.sign(tx));
|
||||
return populateTransaction(transaction, this.provider, this.address).then((tx) => {
|
||||
return this.sign(tx).then((signedTransaction) => {
|
||||
return this.provider.sendTransaction(signedTransaction);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
encrypt(password: Arrayish | string, options?: any, progressCallback?: ProgressCallback): Promise<string> {
|
||||
|
||||
55
tests/local-tests.js
Normal file
55
tests/local-tests.js
Normal file
@@ -0,0 +1,55 @@
|
||||
// These are test cases that cannot be run on Travis CI, but running them locally can
|
||||
// help prevent certain bugs from getting committed.
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
var ethers = require('..');
|
||||
|
||||
var wallet = new ethers.Wallet("0x0123456789012345678901234567890123456789012345678901234567890123");
|
||||
|
||||
describe("Local JSON-RPC", function() {
|
||||
|
||||
// https://github.com/ethers-io/ethers.js/issues/306
|
||||
it ("sends a transaction", function() {
|
||||
this.timeout(10000);
|
||||
|
||||
var provider = new ethers.providers.JsonRpcProvider();
|
||||
var signer = provider.getSigner(1);
|
||||
|
||||
return signer.sendTransaction({
|
||||
to: wallet.address,
|
||||
value: 1
|
||||
}).then(function(tx) {
|
||||
console.log(tx);
|
||||
return tx.wait().then(() => {
|
||||
console.log("Mined", provider);
|
||||
});
|
||||
}, function(error) {
|
||||
console.log(error);
|
||||
assert.ok(false, "throws an error");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it("sends a wallet transactin", function() {
|
||||
this.timeout(10000);
|
||||
|
||||
var provider = new ethers.providers.JsonRpcProvider();
|
||||
var signer = wallet.connect(provider);
|
||||
|
||||
return signer.sendTransaction({
|
||||
to: provider.getSigner(1).getAddress(),
|
||||
value: 2
|
||||
}).then(function(tx) {
|
||||
console.log(tx);
|
||||
return tx.wait().then(() => {
|
||||
console.log("Mined");
|
||||
});
|
||||
}, function(error) {
|
||||
console.log(error);
|
||||
assert.ok(false, "throws an error");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -441,3 +441,72 @@ describe('Test Fixed Bytes Coder', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test Filters', function() {
|
||||
// @TODO: Add a LOT more tests here
|
||||
function doTest(test) {
|
||||
it(test.name, function() {
|
||||
var iface = new ethers.utils.Interface([ test.signature ]);
|
||||
var eventDescription = iface.events[test.event];
|
||||
var filter = eventDescription.encodeTopics(test.args);
|
||||
assert.equal(filter.length, test.expected.length, 'filter length matches - ' + test.name);
|
||||
filter.forEach(function(expected, index) {
|
||||
assert.equal(expected, test.expected[index], 'signature topic matches - ' + index + ' - ' + test.name);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var Tests = [
|
||||
|
||||
// Skips null in non-indexed fields
|
||||
// See: https://github.com/ethers-io/ethers.js/issues/305
|
||||
{
|
||||
name: "creates correct filters for null non-indexed fields",
|
||||
|
||||
args: [ null, 2, null, null ],
|
||||
event: "LogSomething",
|
||||
signature: "event LogSomething(int hup, int indexed two, bool three, address indexed four)",
|
||||
|
||||
expected: [
|
||||
"0xf6b983969813047dce97b9ff8a48cfb0a13306eb2caae2ef186b280bc27491c8",
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000002"
|
||||
]
|
||||
},
|
||||
|
||||
// https://etherscan.io/tx/0x820cc57bc77be44d8f4f024a18e18f64a8b6e62a82a3d7897db5970dbe181ba1
|
||||
{
|
||||
name: "transfer filtering from",
|
||||
|
||||
args: [
|
||||
"0x59DEa134510ebce4a0c7146595dc8A61Eb9D0D79"
|
||||
],
|
||||
event: "Transfer",
|
||||
signature: "event Transfer(address indexed from, address indexed to, uint value)",
|
||||
|
||||
expected: [
|
||||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
||||
"0x00000000000000000000000059dea134510ebce4a0c7146595dc8a61eb9d0d79"
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "transfer filtering to",
|
||||
|
||||
args: [
|
||||
null,
|
||||
"0x851b9167B7cbf772D38eFaf89705b35022880A07"
|
||||
],
|
||||
event: "Transfer",
|
||||
signature: "event Transfer(address indexed from, address indexed to, uint value)",
|
||||
|
||||
expected: [
|
||||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
||||
null,
|
||||
"0x000000000000000000000000851b9167b7cbf772d38efaf89705b35022880a07"
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
Tests.forEach(function(test) {
|
||||
doTest(test);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -128,15 +128,17 @@ var _EventDescription = /** @class */ (function (_super) {
|
||||
topics.push(this.topic);
|
||||
}
|
||||
params.forEach(function (arg, index) {
|
||||
if (arg === null) {
|
||||
topics.push(null);
|
||||
return;
|
||||
}
|
||||
var param = _this.inputs[index];
|
||||
if (!param.indexed) {
|
||||
errors.throwError('cannot filter non-indexed parameters; must be null', errors.INVALID_ARGUMENT, { argument: (param.name || index), value: arg });
|
||||
if (arg != null) {
|
||||
errors.throwError('cannot filter non-indexed parameters; must be null', errors.INVALID_ARGUMENT, { argument: (param.name || index), value: arg });
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (param.type === 'string') {
|
||||
if (arg == null) {
|
||||
topics.push(null);
|
||||
}
|
||||
else if (param.type === 'string') {
|
||||
topics.push(hash_1.id(arg));
|
||||
}
|
||||
else if (param.type === 'bytes') {
|
||||
|
||||
Reference in New Issue
Block a user