admin: updated dist files
This commit is contained in:
parent
9ca3dc557d
commit
77f691b3bc
2
packages/abi/lib/_version.d.ts
vendored
Normal file
2
packages/abi/lib/_version.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export declare const version = "@ethersproject/abi@6.0.0-beta.1";
|
||||
//# sourceMappingURL=_version.d.ts.map
|
1
packages/abi/lib/_version.d.ts.map
Normal file
1
packages/abi/lib/_version.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"_version.d.ts","sourceRoot":"","sources":["../src.ts/_version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,oCAAoC,CAAC"}
|
2
packages/abi/lib/_version.js
Normal file
2
packages/abi/lib/_version.js
Normal file
@ -0,0 +1,2 @@
|
||||
export const version = "@ethersproject/abi@6.0.0-beta.1";
|
||||
//# sourceMappingURL=_version.js.map
|
1
packages/abi/lib/_version.js.map
Normal file
1
packages/abi/lib/_version.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"_version.js","sourceRoot":"","sources":["../src.ts/_version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,iCAAiC,CAAC"}
|
14
packages/abi/lib/abi-coder.d.ts
vendored
Normal file
14
packages/abi/lib/abi-coder.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
import { Result } from "./coders/abstract-coder.js";
|
||||
import { ParamType } from "./fragments.js";
|
||||
import type { BytesLike } from "@ethersproject/bytes";
|
||||
export declare type CoerceFunc = (type: string, value: any) => any;
|
||||
export declare class AbiCoder {
|
||||
#private;
|
||||
readonly coerceFunc: null | CoerceFunc;
|
||||
constructor(coerceFunc?: CoerceFunc);
|
||||
getDefaultValue(types: ReadonlyArray<string | ParamType>): Result;
|
||||
encode(types: ReadonlyArray<string | ParamType>, values: ReadonlyArray<any>): string;
|
||||
decode(types: ReadonlyArray<string | ParamType>, data: BytesLike, loose?: boolean): Result;
|
||||
}
|
||||
export declare const defaultAbiCoder: AbiCoder;
|
||||
//# sourceMappingURL=abi-coder.d.ts.map
|
1
packages/abi/lib/abi-coder.d.ts.map
Normal file
1
packages/abi/lib/abi-coder.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"abi-coder.d.ts","sourceRoot":"","sources":["../src.ts/abi-coder.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,MAAM,EAAU,MAAM,4BAA4B,CAAC;AAU3E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAMtD,oBAAY,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;AAE3D,qBAAa,QAAQ;;IACjB,QAAQ,CAAC,UAAU,EAAG,IAAI,GAAG,UAAU,CAAC;gBAE5B,UAAU,CAAC,EAAE,UAAU;IAiDnC,eAAe,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM;IAMjE,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,MAAM;IAWpF,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM;CAK7F;AAGD,eAAO,MAAM,eAAe,EAAE,QAAyB,CAAC"}
|
88
packages/abi/lib/abi-coder.js
Normal file
88
packages/abi/lib/abi-coder.js
Normal file
@ -0,0 +1,88 @@
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var _AbiCoder_instances, _AbiCoder_getCoder;
|
||||
// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
|
||||
//import { arrayify } from "@ethersproject/bytes";
|
||||
import { defineProperties } from "@ethersproject/properties";
|
||||
import { logger } from "./logger.js";
|
||||
import { Reader, Writer } from "./coders/abstract-coder.js";
|
||||
import { AddressCoder } from "./coders/address.js";
|
||||
import { ArrayCoder } from "./coders/array.js";
|
||||
import { BooleanCoder } from "./coders/boolean.js";
|
||||
import { BytesCoder } from "./coders/bytes.js";
|
||||
import { FixedBytesCoder } from "./coders/fixed-bytes.js";
|
||||
import { NullCoder } from "./coders/null.js";
|
||||
import { NumberCoder } from "./coders/number.js";
|
||||
import { StringCoder } from "./coders/string.js";
|
||||
import { TupleCoder } from "./coders/tuple.js";
|
||||
import { ParamType } from "./fragments.js";
|
||||
const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
|
||||
const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
|
||||
export class AbiCoder {
|
||||
constructor(coerceFunc) {
|
||||
_AbiCoder_instances.add(this);
|
||||
defineProperties(this, { coerceFunc }, {}, { coerceFunc: null });
|
||||
}
|
||||
getDefaultValue(types) {
|
||||
const coders = types.map((type) => __classPrivateFieldGet(this, _AbiCoder_instances, "m", _AbiCoder_getCoder).call(this, ParamType.from(type)));
|
||||
const coder = new TupleCoder(coders, "_");
|
||||
return coder.defaultValue();
|
||||
}
|
||||
encode(types, values) {
|
||||
logger.assertArgumentCount(values.length, types.length, "types/values length mismatch");
|
||||
const coders = types.map((type) => __classPrivateFieldGet(this, _AbiCoder_instances, "m", _AbiCoder_getCoder).call(this, ParamType.from(type)));
|
||||
const coder = (new TupleCoder(coders, "_"));
|
||||
const writer = new Writer();
|
||||
coder.encode(writer, values);
|
||||
return writer.data;
|
||||
}
|
||||
decode(types, data, loose) {
|
||||
const coders = types.map((type) => __classPrivateFieldGet(this, _AbiCoder_instances, "m", _AbiCoder_getCoder).call(this, ParamType.from(type)));
|
||||
const coder = new TupleCoder(coders, "_");
|
||||
return coder.decode(new Reader(data, this.coerceFunc, loose));
|
||||
}
|
||||
}
|
||||
_AbiCoder_instances = new WeakSet(), _AbiCoder_getCoder = function _AbiCoder_getCoder(param) {
|
||||
if (param.isArray()) {
|
||||
return new ArrayCoder(__classPrivateFieldGet(this, _AbiCoder_instances, "m", _AbiCoder_getCoder).call(this, param.arrayChildren), param.arrayLength, param.name);
|
||||
}
|
||||
if (param.isTuple()) {
|
||||
return new TupleCoder(param.components.map((c) => __classPrivateFieldGet(this, _AbiCoder_instances, "m", _AbiCoder_getCoder).call(this, c)), param.name);
|
||||
}
|
||||
switch (param.baseType) {
|
||||
case "address":
|
||||
return new AddressCoder(param.name);
|
||||
case "bool":
|
||||
return new BooleanCoder(param.name);
|
||||
case "string":
|
||||
return new StringCoder(param.name);
|
||||
case "bytes":
|
||||
return new BytesCoder(param.name);
|
||||
case "":
|
||||
return new NullCoder(param.name);
|
||||
}
|
||||
// u?int[0-9]*
|
||||
let match = param.type.match(paramTypeNumber);
|
||||
if (match) {
|
||||
let size = parseInt(match[2] || "256");
|
||||
if (size === 0 || size > 256 || (size % 8) !== 0) {
|
||||
logger.throwArgumentError("invalid " + match[1] + " bit length", "param", param);
|
||||
}
|
||||
return new NumberCoder(size / 8, (match[1] === "int"), param.name);
|
||||
}
|
||||
// bytes[0-9]+
|
||||
match = param.type.match(paramTypeBytes);
|
||||
if (match) {
|
||||
let size = parseInt(match[1]);
|
||||
if (size === 0 || size > 32) {
|
||||
logger.throwArgumentError("invalid bytes length", "param", param);
|
||||
}
|
||||
return new FixedBytesCoder(size, param.name);
|
||||
}
|
||||
return logger.throwArgumentError("invalid type", "type", param.type);
|
||||
};
|
||||
export const defaultAbiCoder = new AbiCoder();
|
||||
//# sourceMappingURL=abi-coder.js.map
|
1
packages/abi/lib/abi-coder.js.map
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,CAAC,GAAG,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;SACpF;QACD,OAAO,IAAI,WAAW,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;KACtE;IAED,cAAc;IACd,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IACzC,IAAI,KAAK,EAAE;QACP,IAAI,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,GAAG,EAAE,EAAE;YACzB,MAAM,CAAC,kBAAkB,CAAC,sBAAsB,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;SACrE;QACD,OAAO,IAAI,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;KAChD;IAED,OAAO,MAAM,CAAC,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;AACzE,CAAC;AA2BL,MAAM,CAAC,MAAM,eAAe,GAAa,IAAI,QAAQ,EAAE,CAAC"}
|
53
packages/abi/lib/coders/abstract-coder.d.ts
vendored
Normal file
53
packages/abi/lib/coders/abstract-coder.d.ts
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
import type { BytesLike } from "@ethersproject/bytes";
|
||||
import type { BigNumberish } from "@ethersproject/logger";
|
||||
export declare const WordSize = 32;
|
||||
export declare class Result extends Array<any> {
|
||||
#private;
|
||||
[K: string | number]: any;
|
||||
constructor(guard: any, items: Array<any>, keys?: Array<null | string>);
|
||||
slice(start?: number | undefined, end?: number | undefined): Array<any>;
|
||||
getValue(name: string): any;
|
||||
static fromItems(items: Array<any>, keys?: Array<null | string>): Result;
|
||||
}
|
||||
export declare function checkResultErrors(result: Result): Array<{
|
||||
path: Array<string | number>;
|
||||
error: Error;
|
||||
}>;
|
||||
export declare type CoerceFunc = (type: string, value: any) => any;
|
||||
export declare abstract class Coder {
|
||||
readonly name: string;
|
||||
readonly type: string;
|
||||
readonly localName: string;
|
||||
readonly dynamic: boolean;
|
||||
constructor(name: string, type: string, localName: string, dynamic: boolean);
|
||||
_throwError(message: string, value: any): never;
|
||||
abstract encode(writer: Writer, value: any): number;
|
||||
abstract decode(reader: Reader): any;
|
||||
abstract defaultValue(): any;
|
||||
}
|
||||
export declare class Writer {
|
||||
#private;
|
||||
constructor();
|
||||
get data(): string;
|
||||
get length(): number;
|
||||
appendWriter(writer: Writer): number;
|
||||
writeBytes(value: BytesLike): number;
|
||||
writeValue(value: BigNumberish): number;
|
||||
writeUpdatableValue(): (value: BigNumberish) => void;
|
||||
}
|
||||
export declare class Reader {
|
||||
#private;
|
||||
readonly allowLoose: boolean;
|
||||
constructor(data: BytesLike, coerceFunc?: null | CoerceFunc, allowLoose?: boolean);
|
||||
get data(): string;
|
||||
get dataLength(): number;
|
||||
get consumed(): number;
|
||||
get bytes(): Uint8Array;
|
||||
static coerce(type: string, value: any): any;
|
||||
coerce(type: string, value: any): any;
|
||||
subReader(offset: number): Reader;
|
||||
readBytes(length: number, loose?: boolean): Uint8Array;
|
||||
readValue(): bigint;
|
||||
readIndex(): number;
|
||||
}
|
||||
//# sourceMappingURL=abstract-coder.d.ts.map
|
1
packages/abi/lib/coders/abstract-coder.d.ts.map
Normal file
1
packages/abi/lib/coders/abstract-coder.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"abstract-coder.d.ts","sourceRoot":"","sources":["../../src.ts/coders/abstract-coder.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,eAAO,MAAM,QAAQ,KAAK,CAAC;AAS3B,qBAAa,MAAO,SAAQ,KAAK,CAAC,GAAG,C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M;IACnD,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;IAEpC,QAAQ,CAAC,YAAY,IAAI,GAAG;CAC/B;AAED,qBAAa,MAAM;;;IAUf,IAAI,IAAI,IAAI,MAAM,CAEjB;IACD,IAAI,MAAM,IAAI,MAAM,CAA6B;IAQjD,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAKpC,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM;IAUpC,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM;IAMvC,mBAAmB,IAAI,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI;CAQvD;AAED,qBAAa,MAAM;;IAKf,QAAQ,CAAC,UAAU,EAAG,OAAO,CAAC;gBAOlB,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,IAAI,GAAG,UAAU,EAAE,UAAU,CAAC,EAAE,OAAO;IASjF,IAAI,IAAI,IAAI,MAAM,CAAgC;IAClD,IAAI,UAAU,IAAI,MAAM,CAA8B;IACtD,IAAI,QAAQ,IAAI,MAAM,CAAyB;IAC/C,IAAI,KAAK,IAAI,UAAU,CAAuC;IAG9D,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG;IAM5C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG;IAqBrC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAKjC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,UAAU;IAQtD,SAAS,IAAI,MAAM;IAInB,SAAS,IAAI,MAAM;CAGtB"}
|
263
packages/abi/lib/coders/abstract-coder.js
Normal file
263
packages/abi/lib/coders/abstract-coder.js
Normal file
@ -0,0 +1,263 @@
|
||||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
};
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var _Result_instances, _Result_indices, _Result_throwError, _Writer_instances, _Writer_data, _Writer_dataLength, _Writer_writeData, _Reader_instances, _Reader_data, _Reader_offset, _Reader_coerceFunc, _Reader_peekBytes;
|
||||
import { toArray, toBigInt, toNumber } from "@ethersproject/math";
|
||||
import { arrayify, concat, hexlify } from "@ethersproject/bytes";
|
||||
import { defineProperties } from "@ethersproject/properties";
|
||||
import { logger } from "../logger.js";
|
||||
export const WordSize = 32;
|
||||
const Padding = new Uint8Array(WordSize);
|
||||
// Properties used to immediate pass through to the underlying object
|
||||
// - `then` is used to detect if an object is a Promise for await
|
||||
const passProperties = ["then"];
|
||||
const _guard = {};
|
||||
export class Result extends Array {
|
||||
constructor(guard, items, keys) {
|
||||
logger.assertPrivate(guard, _guard, "Result");
|
||||
super(...items);
|
||||
_Result_instances.add(this);
|
||||
_Result_indices.set(this, void 0);
|
||||
// Name lookup table
|
||||
__classPrivateFieldSet(this, _Result_indices, new Map(), "f");
|
||||
if (keys) {
|
||||
keys.forEach((key, index) => {
|
||||
if (key == null) {
|
||||
return;
|
||||
}
|
||||
if (__classPrivateFieldGet(this, _Result_indices, "f").has(key)) {
|
||||
(__classPrivateFieldGet(this, _Result_indices, "f").get(key)).push(index);
|
||||
}
|
||||
else {
|
||||
__classPrivateFieldGet(this, _Result_indices, "f").set(key, [index]);
|
||||
}
|
||||
});
|
||||
}
|
||||
Object.freeze(this);
|
||||
return new Proxy(this, {
|
||||
get: (target, prop, receiver) => {
|
||||
if (typeof (prop) === "string") {
|
||||
if (prop.match(/^[0-9]+$/)) {
|
||||
const index = logger.getNumber(prop, "%index");
|
||||
if (index < 0 || index >= this.length) {
|
||||
throw new RangeError("out of result range");
|
||||
}
|
||||
const item = target[index];
|
||||
if (item instanceof Error) {
|
||||
__classPrivateFieldGet(this, _Result_instances, "m", _Result_throwError).call(this, `index ${index}`, item);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
// Pass important checks (like `then` for Promise) through
|
||||
if (prop in target || passProperties.indexOf(prop) >= 0) {
|
||||
return Reflect.get(target, prop, receiver);
|
||||
}
|
||||
// Something that could be a result keyword value
|
||||
if (!(prop in target)) {
|
||||
return target.getValue(prop);
|
||||
}
|
||||
}
|
||||
return Reflect.get(target, prop, receiver);
|
||||
}
|
||||
});
|
||||
}
|
||||
slice(start, end) {
|
||||
if (start == null) {
|
||||
start = 0;
|
||||
}
|
||||
if (end == null) {
|
||||
end = this.length;
|
||||
}
|
||||
const result = [];
|
||||
for (let i = start; i < end; i++) {
|
||||
let value;
|
||||
try {
|
||||
value = this[i];
|
||||
}
|
||||
catch (error) {
|
||||
value = error.error;
|
||||
}
|
||||
result.push(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
getValue(name) {
|
||||
const index = __classPrivateFieldGet(this, _Result_indices, "f").get(name);
|
||||
if (index != null && index.length === 1) {
|
||||
const item = this[index[0]];
|
||||
if (item instanceof Error) {
|
||||
__classPrivateFieldGet(this, _Result_instances, "m", _Result_throwError).call(this, `property ${JSON.stringify(name)}`, item);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
throw new Error(`no named parameter: ${JSON.stringify(name)}`);
|
||||
}
|
||||
static fromItems(items, keys) {
|
||||
return new Result(_guard, items, keys);
|
||||
}
|
||||
}
|
||||
_Result_indices = new WeakMap(), _Result_instances = new WeakSet(), _Result_throwError = function _Result_throwError(name, error) {
|
||||
const wrapped = new Error(`deferred error during ABI decoding triggered accessing ${name}`);
|
||||
wrapped.error = error;
|
||||
throw wrapped;
|
||||
};
|
||||
export function checkResultErrors(result) {
|
||||
// Find the first error (if any)
|
||||
const errors = [];
|
||||
const checkErrors = function (path, object) {
|
||||
if (!Array.isArray(object)) {
|
||||
return;
|
||||
}
|
||||
for (let key in object) {
|
||||
const childPath = path.slice();
|
||||
childPath.push(key);
|
||||
try {
|
||||
checkErrors(childPath, object[key]);
|
||||
}
|
||||
catch (error) {
|
||||
errors.push({ path: childPath, error: error });
|
||||
}
|
||||
}
|
||||
};
|
||||
checkErrors([], result);
|
||||
return errors;
|
||||
}
|
||||
function getValue(value) {
|
||||
let bytes = toArray(value);
|
||||
if (bytes.length > WordSize) {
|
||||
logger.throwError("value out-of-bounds", "BUFFER_OVERRUN", {
|
||||
buffer: bytes,
|
||||
length: WordSize,
|
||||
offset: bytes.length
|
||||
});
|
||||
}
|
||||
if (bytes.length % WordSize) {
|
||||
bytes = arrayify(concat([Padding.slice(bytes.length % WordSize), bytes]));
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
export class Coder {
|
||||
constructor(name, type, localName, dynamic) {
|
||||
defineProperties(this, { name, type, localName, dynamic }, {
|
||||
name: "string", type: "string", localName: "string", dynamic: "boolean"
|
||||
});
|
||||
}
|
||||
_throwError(message, value) {
|
||||
return logger.throwArgumentError(message, this.localName, value);
|
||||
}
|
||||
}
|
||||
export class Writer {
|
||||
constructor() {
|
||||
_Writer_instances.add(this);
|
||||
// An array of WordSize lengthed objects to concatenation
|
||||
_Writer_data.set(this, void 0);
|
||||
_Writer_dataLength.set(this, void 0);
|
||||
__classPrivateFieldSet(this, _Writer_data, [], "f");
|
||||
__classPrivateFieldSet(this, _Writer_dataLength, 0, "f");
|
||||
}
|
||||
get data() {
|
||||
return concat(__classPrivateFieldGet(this, _Writer_data, "f"));
|
||||
}
|
||||
get length() { return __classPrivateFieldGet(this, _Writer_dataLength, "f"); }
|
||||
appendWriter(writer) {
|
||||
return __classPrivateFieldGet(this, _Writer_instances, "m", _Writer_writeData).call(this, arrayify(writer.data));
|
||||
}
|
||||
// Arrayish item; pad on the right to *nearest* WordSize
|
||||
writeBytes(value) {
|
||||
let bytes = arrayify(value);
|
||||
const paddingOffset = bytes.length % WordSize;
|
||||
if (paddingOffset) {
|
||||
bytes = arrayify(concat([bytes, Padding.slice(paddingOffset)]));
|
||||
}
|
||||
return __classPrivateFieldGet(this, _Writer_instances, "m", _Writer_writeData).call(this, bytes);
|
||||
}
|
||||
// Numeric item; pad on the left *to* WordSize
|
||||
writeValue(value) {
|
||||
return __classPrivateFieldGet(this, _Writer_instances, "m", _Writer_writeData).call(this, getValue(value));
|
||||
}
|
||||
// Inserts a numeric place-holder, returning a callback that can
|
||||
// be used to asjust the value later
|
||||
writeUpdatableValue() {
|
||||
const offset = __classPrivateFieldGet(this, _Writer_data, "f").length;
|
||||
__classPrivateFieldGet(this, _Writer_data, "f").push(Padding);
|
||||
__classPrivateFieldSet(this, _Writer_dataLength, __classPrivateFieldGet(this, _Writer_dataLength, "f") + WordSize, "f");
|
||||
return (value) => {
|
||||
__classPrivateFieldGet(this, _Writer_data, "f")[offset] = getValue(value);
|
||||
};
|
||||
}
|
||||
}
|
||||
_Writer_data = new WeakMap(), _Writer_dataLength = new WeakMap(), _Writer_instances = new WeakSet(), _Writer_writeData = function _Writer_writeData(data) {
|
||||
__classPrivateFieldGet(this, _Writer_data, "f").push(data);
|
||||
__classPrivateFieldSet(this, _Writer_dataLength, __classPrivateFieldGet(this, _Writer_dataLength, "f") + data.length, "f");
|
||||
return data.length;
|
||||
};
|
||||
export class Reader {
|
||||
constructor(data, coerceFunc, allowLoose) {
|
||||
_Reader_instances.add(this);
|
||||
_Reader_data.set(this, void 0);
|
||||
_Reader_offset.set(this, void 0);
|
||||
_Reader_coerceFunc.set(this, void 0);
|
||||
defineProperties(this, { allowLoose: !!allowLoose });
|
||||
__classPrivateFieldSet(this, _Reader_data, arrayify(data), "f");
|
||||
__classPrivateFieldSet(this, _Reader_coerceFunc, coerceFunc || Reader.coerce, "f");
|
||||
__classPrivateFieldSet(this, _Reader_offset, 0, "f");
|
||||
}
|
||||
get data() { return hexlify(__classPrivateFieldGet(this, _Reader_data, "f")); }
|
||||
get dataLength() { return __classPrivateFieldGet(this, _Reader_data, "f").length; }
|
||||
get consumed() { return __classPrivateFieldGet(this, _Reader_offset, "f"); }
|
||||
get bytes() { return new Uint8Array(__classPrivateFieldGet(this, _Reader_data, "f")); }
|
||||
// The default Coerce function
|
||||
static coerce(type, value) {
|
||||
let match = type.match("^u?int([0-9]+)$");
|
||||
if (match && parseInt(match[1]) <= 48) {
|
||||
value = value.toNumber();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
coerce(type, value) {
|
||||
return __classPrivateFieldGet(this, _Reader_coerceFunc, "f").call(this, type, value);
|
||||
}
|
||||
// Create a sub-reader with the same underlying data, but offset
|
||||
subReader(offset) {
|
||||
return new Reader(__classPrivateFieldGet(this, _Reader_data, "f").slice(__classPrivateFieldGet(this, _Reader_offset, "f") + offset), __classPrivateFieldGet(this, _Reader_coerceFunc, "f"), this.allowLoose);
|
||||
}
|
||||
// Read bytes
|
||||
readBytes(length, loose) {
|
||||
let bytes = __classPrivateFieldGet(this, _Reader_instances, "m", _Reader_peekBytes).call(this, 0, length, !!loose);
|
||||
__classPrivateFieldSet(this, _Reader_offset, __classPrivateFieldGet(this, _Reader_offset, "f") + bytes.length, "f");
|
||||
// @TODO: Make sure the length..end bytes are all 0?
|
||||
return bytes.slice(0, length);
|
||||
}
|
||||
// Read a numeric values
|
||||
readValue() {
|
||||
return toBigInt(this.readBytes(WordSize));
|
||||
}
|
||||
readIndex() {
|
||||
return toNumber(this.readBytes(WordSize));
|
||||
}
|
||||
}
|
||||
_Reader_data = new WeakMap(), _Reader_offset = new WeakMap(), _Reader_coerceFunc = new WeakMap(), _Reader_instances = new WeakSet(), _Reader_peekBytes = function _Reader_peekBytes(offset, length, loose) {
|
||||
let alignedLength = Math.ceil(length / WordSize) * WordSize;
|
||||
if (__classPrivateFieldGet(this, _Reader_offset, "f") + alignedLength > __classPrivateFieldGet(this, _Reader_data, "f").length) {
|
||||
if (this.allowLoose && loose && __classPrivateFieldGet(this, _Reader_offset, "f") + length <= __classPrivateFieldGet(this, _Reader_data, "f").length) {
|
||||
alignedLength = length;
|
||||
}
|
||||
else {
|
||||
logger.throwError("data out-of-bounds", "BUFFER_OVERRUN", {
|
||||
buffer: arrayify(__classPrivateFieldGet(this, _Reader_data, "f")),
|
||||
length: __classPrivateFieldGet(this, _Reader_data, "f").length,
|
||||
offset: __classPrivateFieldGet(this, _Reader_offset, "f") + alignedLength
|
||||
});
|
||||
}
|
||||
}
|
||||
return __classPrivateFieldGet(this, _Reader_data, "f").slice(__classPrivateFieldGet(this, _Reader_offset, "f"), __classPrivateFieldGet(this, _Reader_offset, "f") + alignedLength);
|
||||
};
|
||||
//# sourceMappingURL=abstract-coder.js.map
|
1
packages/abi/lib/coders/abstract-coder.js.map
Normal file
1
packages/abi/lib/coders/abstract-coder.js.map
Normal file
File diff suppressed because one or more lines are too long
10
packages/abi/lib/coders/address.d.ts
vendored
Normal file
10
packages/abi/lib/coders/address.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
import { Typed } from "../typed.js";
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
import type { Reader, Writer } from "./abstract-coder.js";
|
||||
export declare class AddressCoder extends Coder {
|
||||
constructor(localName: string);
|
||||
defaultValue(): string;
|
||||
encode(writer: Writer, _value: string | Typed): number;
|
||||
decode(reader: Reader): any;
|
||||
}
|
||||
//# sourceMappingURL=address.d.ts.map
|
1
packages/abi/lib/coders/address.d.ts.map
Normal file
1
packages/abi/lib/coders/address.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src.ts/coders/address.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG1D,qBAAa,YAAa,SAAQ,KAAK;gBAEvB,SAAS,EAAE,MAAM;IAI7B,YAAY,IAAI,MAAM;IAItB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM;IAUtD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"}
|
26
packages/abi/lib/coders/address.js
Normal file
26
packages/abi/lib/coders/address.js
Normal file
@ -0,0 +1,26 @@
|
||||
import { getAddress } from "@ethersproject/address";
|
||||
import { toHex } from "@ethersproject/math";
|
||||
import { Typed } from "../typed.js";
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
export class AddressCoder extends Coder {
|
||||
constructor(localName) {
|
||||
super("address", "address", localName, false);
|
||||
}
|
||||
defaultValue() {
|
||||
return "0x0000000000000000000000000000000000000000";
|
||||
}
|
||||
encode(writer, _value) {
|
||||
let value = Typed.dereference(_value, "string");
|
||||
try {
|
||||
value = getAddress(value);
|
||||
}
|
||||
catch (error) {
|
||||
return this._throwError(error.message, _value);
|
||||
}
|
||||
return writer.writeValue(value);
|
||||
}
|
||||
decode(reader) {
|
||||
return getAddress(toHex(reader.readValue(), 20));
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=address.js.map
|
1
packages/abi/lib/coders/address.js.map
Normal file
1
packages/abi/lib/coders/address.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src.ts/coders/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAK5C,MAAM,OAAO,YAAa,SAAQ,KAAK;IAEnC,YAAY,SAAiB;QACzB,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;IAED,YAAY;QACR,OAAO,4CAA4C,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAsB;QACzC,IAAI,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAChD,IAAI;YACA,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;SAC7B;QAAC,OAAO,KAAU,EAAE;YACjB,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;SAClD;QACD,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;CACJ"}
|
10
packages/abi/lib/coders/anonymous.d.ts
vendored
Normal file
10
packages/abi/lib/coders/anonymous.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
import type { Reader, Writer } from "./abstract-coder.js";
|
||||
export declare class AnonymousCoder extends Coder {
|
||||
private coder;
|
||||
constructor(coder: Coder);
|
||||
defaultValue(): any;
|
||||
encode(writer: Writer, value: any): number;
|
||||
decode(reader: Reader): any;
|
||||
}
|
||||
//# sourceMappingURL=anonymous.d.ts.map
|
1
packages/abi/lib/coders/anonymous.d.ts.map
Normal file
1
packages/abi/lib/coders/anonymous.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"anonymous.d.ts","sourceRoot":"","sources":["../../src.ts/coders/anonymous.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG1D,qBAAa,cAAe,SAAQ,KAAK;IACrC,OAAO,CAAC,KAAK,CAAQ;gBAET,KAAK,EAAE,KAAK;IAKxB,YAAY,IAAI,GAAG;IAInB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,MAAM;IAI1C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"}
|
18
packages/abi/lib/coders/anonymous.js
Normal file
18
packages/abi/lib/coders/anonymous.js
Normal file
@ -0,0 +1,18 @@
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
// Clones the functionality of an existing Coder, but without a localName
|
||||
export class AnonymousCoder extends Coder {
|
||||
constructor(coder) {
|
||||
super(coder.name, coder.type, "_", coder.dynamic);
|
||||
this.coder = coder;
|
||||
}
|
||||
defaultValue() {
|
||||
return this.coder.defaultValue();
|
||||
}
|
||||
encode(writer, value) {
|
||||
return this.coder.encode(writer, value);
|
||||
}
|
||||
decode(reader) {
|
||||
return this.coder.decode(reader);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=anonymous.js.map
|
1
packages/abi/lib/coders/anonymous.js.map
Normal file
1
packages/abi/lib/coders/anonymous.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"anonymous.js","sourceRoot":"","sources":["../../src.ts/coders/anonymous.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAI5C,yEAAyE;AACzE,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGrC,YAAY,KAAY;QACpB,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,YAAY;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,KAAU;QAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;CACJ"}
|
16
packages/abi/lib/coders/array.d.ts
vendored
Normal file
16
packages/abi/lib/coders/array.d.ts
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
import { Typed } from "../typed.js";
|
||||
import { Coder, Result, Writer } from "./abstract-coder.js";
|
||||
import type { Reader } from "./abstract-coder.js";
|
||||
export declare function pack(writer: Writer, coders: ReadonlyArray<Coder>, values: Array<any> | {
|
||||
[name: string]: any;
|
||||
}): number;
|
||||
export declare function unpack(reader: Reader, coders: ReadonlyArray<Coder>): Result;
|
||||
export declare class ArrayCoder extends Coder {
|
||||
readonly coder: Coder;
|
||||
readonly length: number;
|
||||
constructor(coder: Coder, length: number, localName: string);
|
||||
defaultValue(): Array<any>;
|
||||
encode(writer: Writer, _value: Array<any> | Typed): number;
|
||||
decode(reader: Reader): any;
|
||||
}
|
||||
//# sourceMappingURL=array.d.ts.map
|
1
packages/abi/lib/coders/array.d.ts.map
Normal file
1
packages/abi/lib/coders/array.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src.ts/coders/array.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAY,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGlD,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG;IAAE,CAAE,IAAI,EAAE,MAAM,GAAI,GAAG,CAAA;CAAE,GAAG,MAAM,CAuEzH;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG,MAAM,CAoD3E;AAGD,qBAAa,UAAW,SAAQ,KAAK;IACjC,QAAQ,CAAC,KAAK,EAAG,KAAK,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAG,MAAM,CAAC;gBAEb,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAO3D,YAAY,IAAI,KAAK,CAAC,GAAG,CAAC;IAW1B,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,MAAM;IAsB1D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAuB9B"}
|
170
packages/abi/lib/coders/array.js
Normal file
170
packages/abi/lib/coders/array.js
Normal file
@ -0,0 +1,170 @@
|
||||
import { defineProperties } from "@ethersproject/properties";
|
||||
import { isError } from "@ethersproject/logger";
|
||||
import { logger } from "../logger.js";
|
||||
import { Typed } from "../typed.js";
|
||||
import { Coder, Result, WordSize, Writer } from "./abstract-coder.js";
|
||||
import { AnonymousCoder } from "./anonymous.js";
|
||||
export function pack(writer, coders, values) {
|
||||
let arrayValues = [];
|
||||
if (Array.isArray(values)) {
|
||||
arrayValues = values;
|
||||
}
|
||||
else if (values && typeof (values) === "object") {
|
||||
let unique = {};
|
||||
arrayValues = coders.map((coder) => {
|
||||
const name = coder.localName;
|
||||
if (!name) {
|
||||
logger.throwError("cannot encode object for signature with missing names", "INVALID_ARGUMENT", {
|
||||
argument: "values",
|
||||
info: { coder },
|
||||
value: values
|
||||
});
|
||||
}
|
||||
if (unique[name]) {
|
||||
logger.throwError("cannot encode object for signature with duplicate names", "INVALID_ARGUMENT", {
|
||||
argument: "values",
|
||||
info: { coder },
|
||||
value: values
|
||||
});
|
||||
}
|
||||
unique[name] = true;
|
||||
return values[name];
|
||||
});
|
||||
}
|
||||
else {
|
||||
logger.throwArgumentError("invalid tuple value", "tuple", values);
|
||||
}
|
||||
if (coders.length !== arrayValues.length) {
|
||||
logger.throwArgumentError("types/value length mismatch", "tuple", values);
|
||||
}
|
||||
let staticWriter = new Writer();
|
||||
let dynamicWriter = new Writer();
|
||||
let updateFuncs = [];
|
||||
coders.forEach((coder, index) => {
|
||||
let value = arrayValues[index];
|
||||
if (coder.dynamic) {
|
||||
// Get current dynamic offset (for the future pointer)
|
||||
let dynamicOffset = dynamicWriter.length;
|
||||
// Encode the dynamic value into the dynamicWriter
|
||||
coder.encode(dynamicWriter, value);
|
||||
// Prepare to populate the correct offset once we are done
|
||||
let updateFunc = staticWriter.writeUpdatableValue();
|
||||
updateFuncs.push((baseOffset) => {
|
||||
updateFunc(baseOffset + dynamicOffset);
|
||||
});
|
||||
}
|
||||
else {
|
||||
coder.encode(staticWriter, value);
|
||||
}
|
||||
});
|
||||
// Backfill all the dynamic offsets, now that we know the static length
|
||||
updateFuncs.forEach((func) => { func(staticWriter.length); });
|
||||
let length = writer.appendWriter(staticWriter);
|
||||
length += writer.appendWriter(dynamicWriter);
|
||||
return length;
|
||||
}
|
||||
export function unpack(reader, coders) {
|
||||
let values = [];
|
||||
let keys = [];
|
||||
// A reader anchored to this base
|
||||
let baseReader = reader.subReader(0);
|
||||
coders.forEach((coder) => {
|
||||
let value = null;
|
||||
if (coder.dynamic) {
|
||||
let offset = reader.readIndex();
|
||||
let offsetReader = baseReader.subReader(offset);
|
||||
try {
|
||||
value = coder.decode(offsetReader);
|
||||
}
|
||||
catch (error) {
|
||||
// Cannot recover from this
|
||||
if (isError(error, "BUFFER_OVERRUN")) {
|
||||
throw error;
|
||||
}
|
||||
value = error;
|
||||
value.baseType = coder.name;
|
||||
value.name = coder.localName;
|
||||
value.type = coder.type;
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
value = coder.decode(reader);
|
||||
}
|
||||
catch (error) {
|
||||
// Cannot recover from this
|
||||
if (isError(error, "BUFFER_OVERRUN")) {
|
||||
throw error;
|
||||
}
|
||||
value = error;
|
||||
value.baseType = coder.name;
|
||||
value.name = coder.localName;
|
||||
value.type = coder.type;
|
||||
}
|
||||
}
|
||||
if (value == undefined) {
|
||||
throw new Error("investigate");
|
||||
}
|
||||
values.push(value);
|
||||
keys.push(coder.localName || null);
|
||||
});
|
||||
return Result.fromItems(values, keys);
|
||||
}
|
||||
export class ArrayCoder extends Coder {
|
||||
constructor(coder, length, localName) {
|
||||
const type = (coder.type + "[" + (length >= 0 ? length : "") + "]");
|
||||
const dynamic = (length === -1 || coder.dynamic);
|
||||
super("array", type, localName, dynamic);
|
||||
defineProperties(this, { coder, length });
|
||||
}
|
||||
defaultValue() {
|
||||
// Verifies the child coder is valid (even if the array is dynamic or 0-length)
|
||||
const defaultChild = this.coder.defaultValue();
|
||||
const result = [];
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
result.push(defaultChild);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
encode(writer, _value) {
|
||||
const value = Typed.dereference(_value, "array");
|
||||
if (!Array.isArray(value)) {
|
||||
this._throwError("expected array value", value);
|
||||
}
|
||||
let count = this.length;
|
||||
if (count === -1) {
|
||||
count = value.length;
|
||||
writer.writeValue(value.length);
|
||||
}
|
||||
logger.assertArgumentCount(value.length, count, "coder array" + (this.localName ? (" " + this.localName) : ""));
|
||||
let coders = [];
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
coders.push(this.coder);
|
||||
}
|
||||
return pack(writer, coders, value);
|
||||
}
|
||||
decode(reader) {
|
||||
let count = this.length;
|
||||
if (count === -1) {
|
||||
count = reader.readIndex();
|
||||
// Check that there is *roughly* enough data to ensure
|
||||
// stray random data is not being read as a length. Each
|
||||
// slot requires at least 32 bytes for their value (or 32
|
||||
// bytes as a link to the data). This could use a much
|
||||
// tighter bound, but we are erroring on the side of safety.
|
||||
if (count * WordSize > reader.dataLength) {
|
||||
logger.throwError("insufficient data length", "BUFFER_OVERRUN", {
|
||||
buffer: reader.bytes,
|
||||
offset: count * WordSize,
|
||||
length: reader.dataLength
|
||||
});
|
||||
}
|
||||
}
|
||||
let coders = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
coders.push(new AnonymousCoder(this.coder));
|
||||
}
|
||||
return reader.coerce(this.name, unpack(reader, coders));
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=array.js.map
|
1
packages/abi/lib/coders/array.js.map
Normal file
1
packages/abi/lib/coders/array.js.map
Normal file
File diff suppressed because one or more lines are too long
10
packages/abi/lib/coders/boolean.d.ts
vendored
Normal file
10
packages/abi/lib/coders/boolean.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
import { Typed } from "../typed.js";
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
import type { Reader, Writer } from "./abstract-coder.js";
|
||||
export declare class BooleanCoder extends Coder {
|
||||
constructor(localName: string);
|
||||
defaultValue(): boolean;
|
||||
encode(writer: Writer, _value: boolean | Typed): number;
|
||||
decode(reader: Reader): any;
|
||||
}
|
||||
//# sourceMappingURL=boolean.d.ts.map
|
1
packages/abi/lib/coders/boolean.d.ts.map
Normal file
1
packages/abi/lib/coders/boolean.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../src.ts/coders/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG1D,qBAAa,YAAa,SAAQ,KAAK;gBAEvB,SAAS,EAAE,MAAM;IAI7B,YAAY,IAAI,OAAO;IAIvB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM;IAKvD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"}
|
18
packages/abi/lib/coders/boolean.js
Normal file
18
packages/abi/lib/coders/boolean.js
Normal file
@ -0,0 +1,18 @@
|
||||
import { Typed } from "../typed.js";
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
export class BooleanCoder extends Coder {
|
||||
constructor(localName) {
|
||||
super("bool", "bool", localName, false);
|
||||
}
|
||||
defaultValue() {
|
||||
return false;
|
||||
}
|
||||
encode(writer, _value) {
|
||||
const value = Typed.dereference(_value, "bool");
|
||||
return writer.writeValue(value ? 1 : 0);
|
||||
}
|
||||
decode(reader) {
|
||||
return reader.coerce(this.type, !reader.readValue());
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=boolean.js.map
|
1
packages/abi/lib/coders/boolean.js.map
Normal file
1
packages/abi/lib/coders/boolean.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src.ts/coders/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAK5C,MAAM,OAAO,YAAa,SAAQ,KAAK;IAEnC,YAAY,SAAiB;QACzB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,YAAY;QACR,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAuB;QAC1C,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChD,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;IACzD,CAAC;CACJ"}
|
13
packages/abi/lib/coders/bytes.d.ts
vendored
Normal file
13
packages/abi/lib/coders/bytes.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
import type { Reader, Writer } from "./abstract-coder.js";
|
||||
export declare class DynamicBytesCoder extends Coder {
|
||||
constructor(type: string, localName: string);
|
||||
defaultValue(): string;
|
||||
encode(writer: Writer, value: any): number;
|
||||
decode(reader: Reader): any;
|
||||
}
|
||||
export declare class BytesCoder extends DynamicBytesCoder {
|
||||
constructor(localName: string);
|
||||
decode(reader: Reader): any;
|
||||
}
|
||||
//# sourceMappingURL=bytes.d.ts.map
|
1
packages/abi/lib/coders/bytes.d.ts.map
Normal file
1
packages/abi/lib/coders/bytes.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../src.ts/coders/bytes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG1D,qBAAa,iBAAkB,SAAQ,KAAK;gBAC5B,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAI3C,YAAY,IAAI,MAAM;IAItB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,MAAM;IAO1C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B;AAED,qBAAa,UAAW,SAAQ,iBAAiB;gBACjC,SAAS,EAAE,MAAM;IAI7B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"}
|
28
packages/abi/lib/coders/bytes.js
Normal file
28
packages/abi/lib/coders/bytes.js
Normal file
@ -0,0 +1,28 @@
|
||||
import { arrayify, hexlify } from "@ethersproject/bytes";
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
export class DynamicBytesCoder extends Coder {
|
||||
constructor(type, localName) {
|
||||
super(type, type, localName, true);
|
||||
}
|
||||
defaultValue() {
|
||||
return "0x";
|
||||
}
|
||||
encode(writer, value) {
|
||||
value = arrayify(value);
|
||||
let length = writer.writeValue(value.length);
|
||||
length += writer.writeBytes(value);
|
||||
return length;
|
||||
}
|
||||
decode(reader) {
|
||||
return reader.readBytes(reader.readIndex(), true);
|
||||
}
|
||||
}
|
||||
export class BytesCoder extends DynamicBytesCoder {
|
||||
constructor(localName) {
|
||||
super("bytes", localName);
|
||||
}
|
||||
decode(reader) {
|
||||
return reader.coerce(this.name, hexlify(super.decode(reader)));
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=bytes.js.map
|
1
packages/abi/lib/coders/bytes.js.map
Normal file
1
packages/abi/lib/coders/bytes.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src.ts/coders/bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAK5C,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACxC,YAAY,IAAY,EAAE,SAAiB;QACxC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,YAAY;QACR,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,KAAU;QAC7B,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QACxB,IAAI,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;CACJ;AAED,MAAM,OAAO,UAAW,SAAQ,iBAAiB;IAC7C,YAAY,SAAiB;QACzB,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACnE,CAAC;CACJ"}
|
12
packages/abi/lib/coders/fixed-bytes.d.ts
vendored
Normal file
12
packages/abi/lib/coders/fixed-bytes.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import { Typed } from "../typed.js";
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
import type { BytesLike } from "@ethersproject/bytes";
|
||||
import type { Reader, Writer } from "./abstract-coder.js";
|
||||
export declare class FixedBytesCoder extends Coder {
|
||||
readonly size: number;
|
||||
constructor(size: number, localName: string);
|
||||
defaultValue(): string;
|
||||
encode(writer: Writer, _value: BytesLike | Typed): number;
|
||||
decode(reader: Reader): any;
|
||||
}
|
||||
//# sourceMappingURL=fixed-bytes.d.ts.map
|
1
packages/abi/lib/coders/fixed-bytes.d.ts.map
Normal file
1
packages/abi/lib/coders/fixed-bytes.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"fixed-bytes.d.ts","sourceRoot":"","sources":["../../src.ts/coders/fixed-bytes.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG1D,qBAAa,eAAgB,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;gBAEX,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAM3C,YAAY,IAAI,MAAM;IAItB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,KAAK,GAAG,MAAM;IAMzD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"}
|
25
packages/abi/lib/coders/fixed-bytes.js
Normal file
25
packages/abi/lib/coders/fixed-bytes.js
Normal file
@ -0,0 +1,25 @@
|
||||
import { arrayify, hexlify } from "@ethersproject/bytes";
|
||||
import { defineProperties } from "@ethersproject/properties";
|
||||
import { Typed } from "../typed.js";
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
export class FixedBytesCoder extends Coder {
|
||||
constructor(size, localName) {
|
||||
let name = "bytes" + String(size);
|
||||
super(name, name, localName, false);
|
||||
defineProperties(this, { size }, { size: "number" });
|
||||
}
|
||||
defaultValue() {
|
||||
return ("0x0000000000000000000000000000000000000000000000000000000000000000").substring(0, 2 + this.size * 2);
|
||||
}
|
||||
encode(writer, _value) {
|
||||
let data = arrayify(Typed.dereference(_value, this.type));
|
||||
if (data.length !== this.size) {
|
||||
this._throwError("incorrect data length", _value);
|
||||
}
|
||||
return writer.writeBytes(data);
|
||||
}
|
||||
decode(reader) {
|
||||
return reader.coerce(this.name, hexlify(reader.readBytes(this.size)));
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=fixed-bytes.js.map
|
1
packages/abi/lib/coders/fixed-bytes.js.map
Normal file
1
packages/abi/lib/coders/fixed-bytes.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"fixed-bytes.js","sourceRoot":"","sources":["../../src.ts/coders/fixed-bytes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAO5C,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAGtC,YAAY,IAAY,EAAE,SAAiB;QACvC,IAAI,IAAI,GAAG,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAClC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QACpC,gBAAgB,CAAkB,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,YAAY;QACR,OAAO,CAAC,oEAAoE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IAClH,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAyB;QAC5C,IAAI,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1D,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE;YAAE,IAAI,CAAC,WAAW,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;SAAE;QACrF,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1E,CAAC;CACJ"}
|
9
packages/abi/lib/coders/null.d.ts
vendored
Normal file
9
packages/abi/lib/coders/null.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
import type { Reader, Writer } from "./abstract-coder.js";
|
||||
export declare class NullCoder extends Coder {
|
||||
constructor(localName: string);
|
||||
defaultValue(): null;
|
||||
encode(writer: Writer, value: any): number;
|
||||
decode(reader: Reader): any;
|
||||
}
|
||||
//# sourceMappingURL=null.d.ts.map
|
1
packages/abi/lib/coders/null.d.ts.map
Normal file
1
packages/abi/lib/coders/null.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"null.d.ts","sourceRoot":"","sources":["../../src.ts/coders/null.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAI1D,qBAAa,SAAU,SAAQ,KAAK;gBAEpB,SAAS,EAAE,MAAM;IAI7B,YAAY,IAAI,IAAI;IAIpB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,MAAM;IAK1C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAI9B"}
|
21
packages/abi/lib/coders/null.js
Normal file
21
packages/abi/lib/coders/null.js
Normal file
@ -0,0 +1,21 @@
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
const Empty = new Uint8Array([]);
|
||||
export class NullCoder extends Coder {
|
||||
constructor(localName) {
|
||||
super("null", "", localName, false);
|
||||
}
|
||||
defaultValue() {
|
||||
return null;
|
||||
}
|
||||
encode(writer, value) {
|
||||
if (value != null) {
|
||||
this._throwError("not null", value);
|
||||
}
|
||||
return writer.writeBytes(Empty);
|
||||
}
|
||||
decode(reader) {
|
||||
reader.readBytes(0);
|
||||
return reader.coerce(this.name, null);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=null.js.map
|
1
packages/abi/lib/coders/null.js.map
Normal file
1
packages/abi/lib/coders/null.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"null.js","sourceRoot":"","sources":["../../src.ts/coders/null.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG5C,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAG,CAAC,CAAC;AAElC,MAAM,OAAO,SAAU,SAAQ,KAAK;IAEhC,YAAY,SAAiB;QACzB,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,YAAY;QACR,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,KAAU;QAC7B,IAAI,KAAK,IAAI,IAAI,EAAE;YAAE,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;SAAE;QAC3D,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACpB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;CACJ"}
|
13
packages/abi/lib/coders/number.d.ts
vendored
Normal file
13
packages/abi/lib/coders/number.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import { Typed } from "../typed.js";
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
import type { BigNumberish } from "@ethersproject/logger";
|
||||
import type { Reader, Writer } from "./abstract-coder.js";
|
||||
export declare class NumberCoder extends Coder {
|
||||
readonly size: number;
|
||||
readonly signed: boolean;
|
||||
constructor(size: number, signed: boolean, localName: string);
|
||||
defaultValue(): number;
|
||||
encode(writer: Writer, _value: BigNumberish | Typed): number;
|
||||
decode(reader: Reader): any;
|
||||
}
|
||||
//# sourceMappingURL=number.d.ts.map
|
1
packages/abi/lib/coders/number.d.ts.map
Normal file
1
packages/abi/lib/coders/number.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src.ts/coders/number.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAY,MAAM,qBAAqB,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAO1D,qBAAa,WAAY,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAG,OAAO,CAAC;gBAEd,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM;IAO5D,YAAY,IAAI,MAAM;IAItB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,KAAK,GAAG,MAAM;IAuB5D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAS9B"}
|
45
packages/abi/lib/coders/number.js
Normal file
45
packages/abi/lib/coders/number.js
Normal file
@ -0,0 +1,45 @@
|
||||
import { fromTwos, mask, toTwos } from "@ethersproject/math";
|
||||
import { defineProperties } from "@ethersproject/properties";
|
||||
import { logger } from "../logger.js";
|
||||
import { Typed } from "../typed.js";
|
||||
import { Coder, WordSize } from "./abstract-coder.js";
|
||||
const BN_0 = BigInt(0);
|
||||
const BN_1 = BigInt(1);
|
||||
const BN_MAX_UINT256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
export class NumberCoder extends Coder {
|
||||
constructor(size, signed, localName) {
|
||||
const name = ((signed ? "int" : "uint") + (size * 8));
|
||||
super(name, name, localName, false);
|
||||
defineProperties(this, { size, signed }, { size: "number", signed: "boolean" });
|
||||
}
|
||||
defaultValue() {
|
||||
return 0;
|
||||
}
|
||||
encode(writer, _value) {
|
||||
let value = logger.getBigInt(Typed.dereference(_value, this.type));
|
||||
// Check bounds are safe for encoding
|
||||
let maxUintValue = mask(BN_MAX_UINT256, WordSize * 8);
|
||||
if (this.signed) {
|
||||
let bounds = mask(maxUintValue, (this.size * 8) - 1);
|
||||
if (value > bounds || value < -(bounds + BN_1)) {
|
||||
this._throwError("value out-of-bounds", _value);
|
||||
}
|
||||
}
|
||||
else if (value < BN_0 || value > mask(maxUintValue, this.size * 8)) {
|
||||
this._throwError("value out-of-bounds", _value);
|
||||
}
|
||||
value = mask(toTwos(value, this.size * 8), this.size * 8);
|
||||
if (this.signed) {
|
||||
value = toTwos(fromTwos(value, this.size * 8), 8 * WordSize);
|
||||
}
|
||||
return writer.writeValue(value);
|
||||
}
|
||||
decode(reader) {
|
||||
let value = mask(reader.readValue(), this.size * 8);
|
||||
if (this.signed) {
|
||||
value = fromTwos(value, this.size * 8);
|
||||
}
|
||||
return reader.coerce(this.name, value);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=number.js.map
|
1
packages/abi/lib/coders/number.js.map
Normal file
1
packages/abi/lib/coders/number.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../src.ts/coders/number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OA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,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;aACnD;SACJ;aAAM,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,EAAE;YAClE,IAAI,CAAC,WAAW,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;SACnD;QAED,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;QAE1D,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC;SAChE;QAED,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;QAEpD,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;SAC1C;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;CACJ"}
|
10
packages/abi/lib/coders/string.d.ts
vendored
Normal file
10
packages/abi/lib/coders/string.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
import { Typed } from "../typed.js";
|
||||
import { DynamicBytesCoder } from "./bytes.js";
|
||||
import type { Reader, Writer } from "./abstract-coder.js";
|
||||
export declare class StringCoder extends DynamicBytesCoder {
|
||||
constructor(localName: string);
|
||||
defaultValue(): string;
|
||||
encode(writer: Writer, _value: string | Typed): number;
|
||||
decode(reader: Reader): any;
|
||||
}
|
||||
//# sourceMappingURL=string.d.ts.map
|
1
packages/abi/lib/coders/string.d.ts.map
Normal file
1
packages/abi/lib/coders/string.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src.ts/coders/string.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG1D,qBAAa,WAAY,SAAQ,iBAAiB;gBAElC,SAAS,EAAE,MAAM;IAI7B,YAAY,IAAI,MAAM;IAItB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM;IAItD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"}
|
18
packages/abi/lib/coders/string.js
Normal file
18
packages/abi/lib/coders/string.js
Normal file
@ -0,0 +1,18 @@
|
||||
import { toUtf8Bytes, toUtf8String } from "@ethersproject/strings";
|
||||
import { Typed } from "../typed.js";
|
||||
import { DynamicBytesCoder } from "./bytes.js";
|
||||
export class StringCoder extends DynamicBytesCoder {
|
||||
constructor(localName) {
|
||||
super("string", localName);
|
||||
}
|
||||
defaultValue() {
|
||||
return "";
|
||||
}
|
||||
encode(writer, _value) {
|
||||
return super.encode(writer, toUtf8Bytes(Typed.dereference(_value, "string")));
|
||||
}
|
||||
decode(reader) {
|
||||
return toUtf8String(super.decode(reader));
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=string.js.map
|
1
packages/abi/lib/coders/string.js.map
Normal file
1
packages/abi/lib/coders/string.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../src.ts/coders/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEnE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAK/C,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IAE9C,YAAY,SAAiB;QACzB,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED,YAAY;QACR,OAAO,EAAE,CAAC;IACd,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAsB;QACzC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAClF,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,CAAC;CACJ"}
|
13
packages/abi/lib/coders/tuple.d.ts
vendored
Normal file
13
packages/abi/lib/coders/tuple.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import { Typed } from "../typed.js";
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
import type { Reader, Writer } from "./abstract-coder.js";
|
||||
export declare class TupleCoder extends Coder {
|
||||
readonly coders: ReadonlyArray<Coder>;
|
||||
constructor(coders: Array<Coder>, localName: string);
|
||||
defaultValue(): any;
|
||||
encode(writer: Writer, _value: Array<any> | {
|
||||
[name: string]: any;
|
||||
} | Typed): number;
|
||||
decode(reader: Reader): any;
|
||||
}
|
||||
//# sourceMappingURL=tuple.d.ts.map
|
1
packages/abi/lib/coders/tuple.d.ts.map
Normal file
1
packages/abi/lib/coders/tuple.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"tuple.d.ts","sourceRoot":"","sources":["../../src.ts/coders/tuple.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAI5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE1D,qBAAa,UAAW,SAAQ,KAAK;IACjC,QAAQ,CAAC,MAAM,EAAG,aAAa,CAAC,KAAK,CAAC,CAAC;gBAE3B,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,MAAM;IAanD,YAAY,IAAI,GAAG;IA+BnB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG;QAAE,CAAE,IAAI,EAAE,MAAM,GAAI,GAAG,CAAA;KAAE,GAAG,KAAK,GAAG,MAAM;IAKtF,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"}
|
59
packages/abi/lib/coders/tuple.js
Normal file
59
packages/abi/lib/coders/tuple.js
Normal file
@ -0,0 +1,59 @@
|
||||
import { defineProperties } from "@ethersproject/properties";
|
||||
import { Typed } from "../typed.js";
|
||||
import { Coder } from "./abstract-coder.js";
|
||||
import { pack, unpack } from "./array.js";
|
||||
export class TupleCoder extends Coder {
|
||||
constructor(coders, localName) {
|
||||
let dynamic = false;
|
||||
const types = [];
|
||||
coders.forEach((coder) => {
|
||||
if (coder.dynamic) {
|
||||
dynamic = true;
|
||||
}
|
||||
types.push(coder.type);
|
||||
});
|
||||
const type = ("tuple(" + types.join(",") + ")");
|
||||
super("tuple", type, localName, dynamic);
|
||||
defineProperties(this, { coders: Object.freeze(coders.slice()) });
|
||||
}
|
||||
defaultValue() {
|
||||
const values = [];
|
||||
this.coders.forEach((coder) => {
|
||||
values.push(coder.defaultValue());
|
||||
});
|
||||
// We only output named properties for uniquely named coders
|
||||
const uniqueNames = this.coders.reduce((accum, coder) => {
|
||||
const name = coder.localName;
|
||||
if (name) {
|
||||
if (!accum[name]) {
|
||||
accum[name] = 0;
|
||||
}
|
||||
accum[name]++;
|
||||
}
|
||||
return accum;
|
||||
}, {});
|
||||
// Add named values
|
||||
this.coders.forEach((coder, index) => {
|
||||
let name = coder.localName;
|
||||
if (!name || uniqueNames[name] !== 1) {
|
||||
return;
|
||||
}
|
||||
if (name === "length") {
|
||||
name = "_length";
|
||||
}
|
||||
if (values[name] != null) {
|
||||
return;
|
||||
}
|
||||
values[name] = values[index];
|
||||
});
|
||||
return Object.freeze(values);
|
||||
}
|
||||
encode(writer, _value) {
|
||||
const value = Typed.dereference(_value, "tuple");
|
||||
return pack(writer, this.coders, value);
|
||||
}
|
||||
decode(reader) {
|
||||
return reader.coerce(this.name, unpack(reader, this.coders));
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=tuple.js.map
|
1
packages/abi/lib/coders/tuple.js.map
Normal file
1
packages/abi/lib/coders/tuple.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../src.ts/coders/tuple.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAI1C,MAAM,OAAO,UAAW,SAAQ,KAAK;IAGjC,YAAY,MAAoB,EAAE,SAAiB;QAC/C,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,MAAM,KAAK,GAAkB,EAAE,CAAC;QAChC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACrB,IAAI,KAAK,CAAC,OAAO,EAAE;gBAAE,OAAO,GAAG,IAAI,CAAC;aAAE;YACtC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;QACH,MAAM,IA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AAC,IAAI,CAAC,IAAI,IAAI,EAAE;gBAAE,OAAO;aAAE;YAErC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAsD;QACzE,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACjE,CAAC;CACJ"}
|
153
packages/abi/lib/fragments.d.ts
vendored
Normal file
153
packages/abi/lib/fragments.d.ts
vendored
Normal file
@ -0,0 +1,153 @@
|
||||
export interface JsonFragmentType {
|
||||
readonly name?: string;
|
||||
readonly indexed?: boolean;
|
||||
readonly type?: string;
|
||||
readonly internalType?: string;
|
||||
readonly components?: ReadonlyArray<JsonFragmentType>;
|
||||
}
|
||||
export interface JsonFragment {
|
||||
readonly name?: string;
|
||||
readonly type?: string;
|
||||
readonly anonymous?: boolean;
|
||||
readonly payable?: boolean;
|
||||
readonly constant?: boolean;
|
||||
readonly stateMutability?: string;
|
||||
readonly inputs?: ReadonlyArray<JsonFragmentType>;
|
||||
readonly outputs?: ReadonlyArray<JsonFragmentType>;
|
||||
readonly gas?: string;
|
||||
}
|
||||
export declare enum FormatType {
|
||||
sighash = "sighash",
|
||||
minimal = "minimal",
|
||||
full = "full",
|
||||
json = "json"
|
||||
}
|
||||
export declare type Token = Readonly<{
|
||||
type: string;
|
||||
offset: number;
|
||||
text: string;
|
||||
depth: number;
|
||||
match: number;
|
||||
linkBack: number;
|
||||
linkNext: number;
|
||||
value: number;
|
||||
}>;
|
||||
export declare class TokenString {
|
||||
#private;
|
||||
get offset(): number;
|
||||
get length(): number;
|
||||
constructor(tokens: ReadonlyArray<Token>);
|
||||
clone(): TokenString;
|
||||
reset(): void;
|
||||
popKeyword(allowed: ReadonlySet<string>): string;
|
||||
popType(type: string): string;
|
||||
popParen(): TokenString;
|
||||
popParams(): Array<TokenString>;
|
||||
peek(): Token;
|
||||
peekKeyword(allowed: ReadonlySet<string>): null | string;
|
||||
peekType(type: string): null | string;
|
||||
pop(): Token;
|
||||
toString(): string;
|
||||
}
|
||||
export declare function lex(text: string): TokenString;
|
||||
export interface ArrayParamType {
|
||||
readonly arrayLength: number;
|
||||
readonly arrayChildren: ParamType;
|
||||
}
|
||||
export interface TupleParamType extends ParamType {
|
||||
readonly components: ReadonlyArray<ParamType>;
|
||||
}
|
||||
export interface IndexableParamType extends ParamType {
|
||||
readonly indexed: boolean;
|
||||
}
|
||||
export declare type FragmentWalkFunc = (type: string, value: any) => any;
|
||||
export declare type FragmentWalkAsyncFunc = (type: string, value: any) => any | Promise<any>;
|
||||
export declare class ParamType {
|
||||
#private;
|
||||
readonly name: string;
|
||||
readonly type: string;
|
||||
readonly baseType: string;
|
||||
readonly indexed: null | boolean;
|
||||
readonly components: null | ReadonlyArray<ParamType>;
|
||||
readonly arrayLength: null | number;
|
||||
readonly arrayChildren: null | ParamType;
|
||||
constructor(guard: any, name: string, type: string, baseType: string, indexed: null | boolean, components: null | ReadonlyArray<ParamType>, arrayLength: null | number, arrayChildren: null | ParamType);
|
||||
format(format?: FormatType): string;
|
||||
static isArray(value: any): value is {
|
||||
arrayChildren: ParamType;
|
||||
};
|
||||
isArray(): this is (ParamType & ArrayParamType);
|
||||
isTuple(): this is TupleParamType;
|
||||
isIndexable(): this is IndexableParamType;
|
||||
walk(value: any, process: FragmentWalkFunc): any;
|
||||
walkAsync(value: any, process: (type: string, value: any) => any | Promise<any>): Promise<any>;
|
||||
static from(obj: any, allowIndexed?: boolean): ParamType;
|
||||
static fromObject(obj: any, allowIndexed?: boolean): ParamType;
|
||||
static fromTokens(tokens: TokenString, allowIndexed?: boolean): ParamType;
|
||||
static isParamType(value: any): value is ParamType;
|
||||
}
|
||||
export declare enum FragmentType {
|
||||
"constructor" = "constructor",
|
||||
"error" = "error",
|
||||
"event" = "event",
|
||||
"function" = "function",
|
||||
"struct" = "struct"
|
||||
}
|
||||
export declare abstract class Fragment {
|
||||
readonly type: FragmentType;
|
||||
readonly inputs: ReadonlyArray<ParamType>;
|
||||
constructor(guard: any, type: FragmentType, inputs: ReadonlyArray<ParamType>);
|
||||
abstract format(format?: FormatType): string;
|
||||
static from(obj: any): Fragment;
|
||||
static fromObject(obj: any): Fragment;
|
||||
static fromString(text: string): Fragment;
|
||||
static fromTokens(tokens: TokenString): Fragment;
|
||||
static isConstructor(value: any): value is ConstructorFragment;
|
||||
static isError(value: any): value is ErrorFragment;
|
||||
static isEvent(value: any): value is EventFragment;
|
||||
static isFunction(value: any): value is FunctionFragment;
|
||||
static isStruct(value: any): value is StructFragment;
|
||||
}
|
||||
export declare abstract class NamedFragment extends Fragment {
|
||||
readonly name: string;
|
||||
constructor(guard: any, type: FragmentType, name: string, inputs: ReadonlyArray<ParamType>);
|
||||
}
|
||||
export declare class ErrorFragment extends NamedFragment {
|
||||
constructor(guard: any, name: string, inputs: ReadonlyArray<ParamType>);
|
||||
format(format?: FormatType): string;
|
||||
static fromString(text: string): ErrorFragment;
|
||||
static fromTokens(tokens: TokenString): ErrorFragment;
|
||||
}
|
||||
export declare class EventFragment extends NamedFragment {
|
||||
readonly anonymous: boolean;
|
||||
constructor(guard: any, name: string, inputs: ReadonlyArray<ParamType>, anonymous: boolean);
|
||||
format(format?: FormatType): string;
|
||||
static fromString(text: string): EventFragment;
|
||||
static fromTokens(tokens: TokenString): EventFragment;
|
||||
}
|
||||
export declare class ConstructorFragment extends Fragment {
|
||||
readonly payable: boolean;
|
||||
readonly gas: null | bigint;
|
||||
constructor(guard: any, type: FragmentType, inputs: ReadonlyArray<ParamType>, payable: boolean, gas: null | bigint);
|
||||
format(format?: FormatType): string;
|
||||
static fromString(text: string): ConstructorFragment;
|
||||
static fromObject(obj: any): ConstructorFragment;
|
||||
static fromTokens(tokens: TokenString): ConstructorFragment;
|
||||
}
|
||||
export declare class FunctionFragment extends NamedFragment {
|
||||
readonly constant: boolean;
|
||||
readonly outputs: ReadonlyArray<ParamType>;
|
||||
readonly stateMutability: string;
|
||||
readonly payable: boolean;
|
||||
readonly gas: null | bigint;
|
||||
constructor(guard: any, name: string, stateMutability: string, inputs: ReadonlyArray<ParamType>, outputs: ReadonlyArray<ParamType>, gas: null | bigint);
|
||||
format(format?: FormatType): string;
|
||||
static fromString(text: string): FunctionFragment;
|
||||
static fromTokens(tokens: TokenString): FunctionFragment;
|
||||
}
|
||||
export declare class StructFragment extends NamedFragment {
|
||||
format(): string;
|
||||
static fromString(text: string): StructFragment;
|
||||
static fromTokens(tokens: TokenString): StructFragment;
|
||||
}
|
||||
//# sourceMappingURL=fragments.d.ts.map
|
1
packages/abi/lib/fragments.d.ts.map
Normal file
1
packages/abi/lib/fragments.d.ts.map
Normal file
File diff suppressed because one or more lines are too long
909
packages/abi/lib/fragments.js
Normal file
909
packages/abi/lib/fragments.js
Normal file
@ -0,0 +1,909 @@
|
||||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
};
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var _TokenString_instances, _TokenString_offset, _TokenString_tokens, _TokenString_subTokenString, _ParamType_instances, _ParamType_walkAsync;
|
||||
import { defineProperties } from "@ethersproject/properties";
|
||||
import { logger } from "./logger.js";
|
||||
;
|
||||
export var FormatType;
|
||||
(function (FormatType) {
|
||||
// Bare formatting, as is needed for computing a sighash of an event or function
|
||||
FormatType["sighash"] = "sighash";
|
||||
// Human-Readable with Minimal spacing and without names (compact human-readable)
|
||||
FormatType["minimal"] = "minimal";
|
||||
// Human-Readable with nice spacing, including all names
|
||||
FormatType["full"] = "full";
|
||||
// JSON-format a la Solidity
|
||||
FormatType["json"] = "json";
|
||||
})(FormatType || (FormatType = {}));
|
||||
;
|
||||
// [ "a", "b" ] => { "a": 1, "b": 1 }
|
||||
function setify(items) {
|
||||
const result = new Set();
|
||||
items.forEach((k) => result.add(k));
|
||||
return Object.freeze(result);
|
||||
}
|
||||
// Visibility Keywords
|
||||
const _kwVisib = "constant external internal payable private public pure view";
|
||||
const KwVisib = setify(_kwVisib.split(" "));
|
||||
const _kwTypes = "constructor error event function struct";
|
||||
const KwTypes = setify(_kwTypes.split(" "));
|
||||
const _kwModifiers = "calldata memory storage payable indexed";
|
||||
const KwModifiers = setify(_kwModifiers.split(" "));
|
||||
const _kwOther = "tuple returns";
|
||||
// All Keywords
|
||||
const _keywords = [_kwTypes, _kwModifiers, _kwOther, _kwVisib].join(" ");
|
||||
const Keywords = setify(_keywords.split(" "));
|
||||
// Single character tokens
|
||||
const SimpleTokens = {
|
||||
"(": "OPEN_PAREN", ")": "CLOSE_PAREN",
|
||||
"[": "OPEN_BRACKET", "]": "CLOSE_BRACKET",
|
||||
",": "COMMA", "@": "AT"
|
||||
};
|
||||
// Parser regexes to consume the next token
|
||||
const regexWhitespace = new RegExp("^(\\s*)");
|
||||
const regexNumber = new RegExp("^([0-9]+)");
|
||||
const regexIdentifier = new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)");
|
||||
const regexType = new RegExp("^(address|bool|bytes(0-9*)|string|u?int([0-9]*))");
|
||||
export class TokenString {
|
||||
constructor(tokens) {
|
||||
_TokenString_instances.add(this);
|
||||
_TokenString_offset.set(this, void 0);
|
||||
_TokenString_tokens.set(this, void 0);
|
||||
__classPrivateFieldSet(this, _TokenString_offset, 0, "f");
|
||||
__classPrivateFieldSet(this, _TokenString_tokens, tokens.slice(), "f");
|
||||
}
|
||||
get offset() { return __classPrivateFieldGet(this, _TokenString_offset, "f"); }
|
||||
get length() { return __classPrivateFieldGet(this, _TokenString_tokens, "f").length - __classPrivateFieldGet(this, _TokenString_offset, "f"); }
|
||||
clone() { return new TokenString(__classPrivateFieldGet(this, _TokenString_tokens, "f")); }
|
||||
reset() { __classPrivateFieldSet(this, _TokenString_offset, 0, "f"); }
|
||||
// Pops and returns the value of the next token, if it is a keyword in allowed; throws if out of tokens
|
||||
popKeyword(allowed) {
|
||||
const top = this.peek();
|
||||
if (top.type !== "KEYWORD" || !allowed.has(top.text)) {
|
||||
throw new Error(`expected keyword ${top.text}`);
|
||||
}
|
||||
return this.pop().text;
|
||||
}
|
||||
// Pops and returns the value of the next token if it is `type`; throws if out of tokens
|
||||
popType(type) {
|
||||
if (this.peek().type !== type) {
|
||||
throw new Error(`expected ${type}; got ${JSON.stringify(this.peek())}`);
|
||||
}
|
||||
return this.pop().text;
|
||||
}
|
||||
// Pops and returns a "(" TOKENS ")"
|
||||
popParen() {
|
||||
const top = this.peek();
|
||||
if (top.type !== "OPEN_PAREN") {
|
||||
throw new Error("bad start");
|
||||
}
|
||||
const result = __classPrivateFieldGet(this, _TokenString_instances, "m", _TokenString_subTokenString).call(this, __classPrivateFieldGet(this, _TokenString_offset, "f") + 1, top.match + 1);
|
||||
__classPrivateFieldSet(this, _TokenString_offset, top.match + 1, "f");
|
||||
return result;
|
||||
}
|
||||
// Pops and returns the items within "(" ITEM1 "," ITEM2 "," ... ")"
|
||||
popParams() {
|
||||
const top = this.peek();
|
||||
if (top.type !== "OPEN_PAREN") {
|
||||
throw new Error("bad start");
|
||||
}
|
||||
const result = [];
|
||||
while (__classPrivateFieldGet(this, _TokenString_offset, "f") < top.match - 1) {
|
||||
const link = this.peek().linkNext;
|
||||
result.push(__classPrivateFieldGet(this, _TokenString_instances, "m", _TokenString_subTokenString).call(this, __classPrivateFieldGet(this, _TokenString_offset, "f") + 1, link));
|
||||
__classPrivateFieldSet(this, _TokenString_offset, link, "f");
|
||||
}
|
||||
__classPrivateFieldSet(this, _TokenString_offset, top.match + 1, "f");
|
||||
return result;
|
||||
}
|
||||
// Returns the top Token, throwing if out of tokens
|
||||
peek() {
|
||||
if (__classPrivateFieldGet(this, _TokenString_offset, "f") >= __classPrivateFieldGet(this, _TokenString_tokens, "f").length) {
|
||||
throw new Error("out-of-bounds");
|
||||
}
|
||||
return __classPrivateFieldGet(this, _TokenString_tokens, "f")[__classPrivateFieldGet(this, _TokenString_offset, "f")];
|
||||
}
|
||||
// Returns the next value, if it is a keyword in `allowed`
|
||||
peekKeyword(allowed) {
|
||||
const top = this.peekType("KEYWORD");
|
||||
return (top != null && allowed.has(top)) ? top : null;
|
||||
}
|
||||
// Returns the value of the next token if it is `type`
|
||||
peekType(type) {
|
||||
if (this.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const top = this.peek();
|
||||
return (top.type === type) ? top.text : null;
|
||||
}
|
||||
// Returns the next token; throws if out of tokens
|
||||
pop() {
|
||||
var _a;
|
||||
const result = this.peek();
|
||||
__classPrivateFieldSet(this, _TokenString_offset, (_a = __classPrivateFieldGet(this, _TokenString_offset, "f"), _a++, _a), "f");
|
||||
return result;
|
||||
}
|
||||
toString() {
|
||||
const tokens = [];
|
||||
for (let i = __classPrivateFieldGet(this, _TokenString_offset, "f"); i < __classPrivateFieldGet(this, _TokenString_tokens, "f").length; i++) {
|
||||
const token = __classPrivateFieldGet(this, _TokenString_tokens, "f")[i];
|
||||
tokens.push(`${token.type}:${token.text}`);
|
||||
}
|
||||
return `<TokenString ${tokens.join(" ")}>`;
|
||||
}
|
||||
}
|
||||
_TokenString_offset = new WeakMap(), _TokenString_tokens = new WeakMap(), _TokenString_instances = new WeakSet(), _TokenString_subTokenString = function _TokenString_subTokenString(from = 0, to = 0) {
|
||||
return new TokenString(__classPrivateFieldGet(this, _TokenString_tokens, "f").slice(from, to).map((t) => {
|
||||
return Object.freeze(Object.assign({}, t, {
|
||||
match: (t.match - from),
|
||||
linkBack: (t.linkBack - from),
|
||||
linkNext: (t.linkNext - from),
|
||||
}));
|
||||
return t;
|
||||
}));
|
||||
};
|
||||
export function lex(text) {
|
||||
const tokens = [];
|
||||
const throwError = (message) => {
|
||||
const token = (offset < text.length) ? JSON.stringify(text[offset]) : "$EOI";
|
||||
throw new Error(`invalid token ${token} at ${offset}: ${message}`);
|
||||
};
|
||||
let brackets = [];
|
||||
let commas = [];
|
||||
let offset = 0;
|
||||
while (offset < text.length) {
|
||||
// Strip off any leading whitespace
|
||||
let cur = text.substring(offset);
|
||||
let match = cur.match(regexWhitespace);
|
||||
if (match) {
|
||||
offset += match[1].length;
|
||||
cur = text.substring(offset);
|
||||
}
|
||||
const token = { depth: brackets.length, linkBack: -1, linkNext: -1, match: -1, type: "", text: "", offset, value: -1 };
|
||||
tokens.push(token);
|
||||
let type = (SimpleTokens[cur[0]] || "");
|
||||
if (type) {
|
||||
token.type = type;
|
||||
token.text = cur[0];
|
||||
offset++;
|
||||
if (type === "OPEN_PAREN") {
|
||||
brackets.push(tokens.length - 1);
|
||||
commas.push(tokens.length - 1);
|
||||
}
|
||||
else if (type == "CLOSE_PAREN") {
|
||||
if (brackets.length === 0) {
|
||||
throwError("no matching open bracket");
|
||||
}
|
||||
token.match = brackets.pop();
|
||||
(tokens[token.match]).match = tokens.length - 1;
|
||||
token.depth--;
|
||||
token.linkBack = commas.pop();
|
||||
(tokens[token.linkBack]).linkNext = tokens.length - 1;
|
||||
}
|
||||
else if (type === "COMMA") {
|
||||
token.linkBack = commas.pop();
|
||||
(tokens[token.linkBack]).linkNext = tokens.length - 1;
|
||||
commas.push(tokens.length - 1);
|
||||
}
|
||||
else if (type === "OPEN_BRACKET") {
|
||||
token.type = "BRACKET";
|
||||
}
|
||||
else if (type === "CLOSE_BRACKET") {
|
||||
// Remove the CLOSE_BRACKET
|
||||
let suffix = tokens.pop().text;
|
||||
if (tokens.length > 0 && tokens[tokens.length - 1].type === "NUMBER") {
|
||||
const value = tokens.pop().text;
|
||||
suffix = value + suffix;
|
||||
(tokens[tokens.length - 1]).value = logger.getNumber(value);
|
||||
}
|
||||
if (tokens.length === 0 || tokens[tokens.length - 1].type !== "BRACKET") {
|
||||
throw new Error("missing opening bracket");
|
||||
}
|
||||
(tokens[tokens.length - 1]).text += suffix;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
match = cur.match(regexIdentifier);
|
||||
if (match) {
|
||||
token.text = match[1];
|
||||
offset += token.text.length;
|
||||
if (Keywords.has(token.text)) {
|
||||
token.type = "KEYWORD";
|
||||
continue;
|
||||
}
|
||||
if (token.text.match(regexType)) {
|
||||
token.type = "TYPE";
|
||||
continue;
|
||||
}
|
||||
token.type = "ID";
|
||||
continue;
|
||||
}
|
||||
match = cur.match(regexNumber);
|
||||
if (match) {
|
||||
token.text = match[1];
|
||||
token.type = "NUMBER";
|
||||
offset += token.text.length;
|
||||
continue;
|
||||
}
|
||||
throw new Error(`unexpected token ${JSON.stringify(cur[0])} at position ${offset}`);
|
||||
}
|
||||
return new TokenString(tokens.map((t) => Object.freeze(t)));
|
||||
}
|
||||
// Check only one of `allowed` is in `set`
|
||||
function allowSingle(set, allowed) {
|
||||
let included = [];
|
||||
for (const key in allowed.keys()) {
|
||||
if (set.has(key)) {
|
||||
included.push(key);
|
||||
}
|
||||
}
|
||||
if (included.length > 1) {
|
||||
throw new Error(`conflicting types: ${included.join(", ")}`);
|
||||
}
|
||||
}
|
||||
// Functions to process a Solidity Signature TokenString from left-to-right for...
|
||||
// ...the name with an optional type, returning the name
|
||||
function consumeName(type, tokens) {
|
||||
if (tokens.peekKeyword(KwTypes)) {
|
||||
const keyword = tokens.pop().text;
|
||||
if (keyword !== type) {
|
||||
throw new Error(`expected ${type}, got ${keyword}`);
|
||||
}
|
||||
}
|
||||
return tokens.popType("ID");
|
||||
}
|
||||
// ...all keywords matching allowed, returning the keywords
|
||||
function consumeKeywords(tokens, allowed) {
|
||||
const keywords = new Set();
|
||||
while (true) {
|
||||
const keyword = tokens.peekType("KEYWORD");
|
||||
if (keyword == null || (allowed && !allowed.has(keyword))) {
|
||||
break;
|
||||
}
|
||||
tokens.pop();
|
||||
if (keywords.has(keyword)) {
|
||||
throw new Error(`duplicate keywords: ${JSON.stringify(keyword)}`);
|
||||
}
|
||||
keywords.add(keyword);
|
||||
}
|
||||
return Object.freeze(keywords);
|
||||
}
|
||||
// ...all visibility keywords, returning the coalesced mutability
|
||||
function consumeMutability(tokens) {
|
||||
let modifiers = consumeKeywords(tokens, KwVisib);
|
||||
// Detect conflicting modifiers
|
||||
allowSingle(modifiers, setify("constant payable nonpayable".split(" ")));
|
||||
allowSingle(modifiers, setify("pure view payable nonpayable".split(" ")));
|
||||
// Process mutability states
|
||||
if (modifiers.has("view")) {
|
||||
return "view";
|
||||
}
|
||||
if (modifiers.has("pure")) {
|
||||
return "pure";
|
||||
}
|
||||
if (modifiers.has("payable")) {
|
||||
return "payable";
|
||||
}
|
||||
if (modifiers.has("nonpayable")) {
|
||||
return "nonpayable";
|
||||
}
|
||||
// Process legacy `constant` last
|
||||
if (modifiers.has("constant")) {
|
||||
return "view";
|
||||
}
|
||||
return "nonpayable";
|
||||
}
|
||||
// ...a parameter list, returning the ParamType list
|
||||
function consumeParams(tokens, allowIndexed) {
|
||||
return tokens.popParams().map((t) => ParamType.fromTokens(t, allowIndexed));
|
||||
}
|
||||
// ...a gas limit, returning a BigNumber or null if none
|
||||
function consumeGas(tokens) {
|
||||
if (tokens.peekType("AT")) {
|
||||
tokens.pop();
|
||||
if (tokens.peekType("NUMBER")) {
|
||||
return logger.getBigInt(tokens.pop().text);
|
||||
}
|
||||
throw new Error("invalid gas");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function consumeEoi(tokens) {
|
||||
if (tokens.length) {
|
||||
throw new Error(`unexpected tokens: ${tokens.toString()}`);
|
||||
}
|
||||
}
|
||||
const regexArrayType = new RegExp(/^(.*)\[([0-9]*)\]$/);
|
||||
function verifyBasicType(type) {
|
||||
const match = type.match(regexType);
|
||||
if (!match) {
|
||||
return logger.throwArgumentError("invalid type", "type", type);
|
||||
}
|
||||
if (type === "uint") {
|
||||
return "uint256";
|
||||
}
|
||||
if (type === "int") {
|
||||
return "int256";
|
||||
}
|
||||
if (match[2]) {
|
||||
// bytesXX
|
||||
const length = parseInt(match[2]);
|
||||
if (length === 0 || length > 32) {
|
||||
logger.throwArgumentError("invalid bytes length", "type", type);
|
||||
}
|
||||
}
|
||||
else if (match[3]) {
|
||||
// intXX or uintXX
|
||||
const size = parseInt(match[3]);
|
||||
if (size === 0 || size > 256 || size % 8) {
|
||||
logger.throwArgumentError("invalid numeric width", "type", type);
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
// Make the Fragment constructors effectively private
|
||||
const _guard = {};
|
||||
const internal = Symbol.for("_ethers_internal");
|
||||
const ParamTypeInternal = "_ParamTypeInternal";
|
||||
export class ParamType {
|
||||
constructor(guard, name, type, baseType, indexed, components, arrayLength, arrayChildren) {
|
||||
_ParamType_instances.add(this);
|
||||
logger.assertPrivate(guard, _guard, "ParamType");
|
||||
Object.defineProperty(this, internal, { value: ParamTypeInternal });
|
||||
if (components) {
|
||||
components = Object.freeze(components.slice());
|
||||
}
|
||||
if (baseType === "array") {
|
||||
if (arrayLength == null || arrayChildren == null) {
|
||||
throw new Error("");
|
||||
}
|
||||
}
|
||||
else if (arrayLength != null || arrayChildren != null) {
|
||||
throw new Error("");
|
||||
}
|
||||
if (baseType === "tuple") {
|
||||
if (components == null) {
|
||||
throw new Error("");
|
||||
}
|
||||
}
|
||||
else if (components != null) {
|
||||
throw new Error("");
|
||||
}
|
||||
defineProperties(this, {
|
||||
name, type, baseType, indexed, components, arrayLength, arrayChildren
|
||||
});
|
||||
}
|
||||
// Format the parameter fragment
|
||||
// - sighash: "(uint256,address)"
|
||||
// - minimal: "tuple(uint256,address) indexed"
|
||||
// - full: "tuple(uint256 foo, address bar) indexed baz"
|
||||
format(format = FormatType.sighash) {
|
||||
if (!FormatType[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatType.json) {
|
||||
let result = {
|
||||
type: ((this.baseType === "tuple") ? "tuple" : this.type),
|
||||
name: (this.name || undefined)
|
||||
};
|
||||
if (typeof (this.indexed) === "boolean") {
|
||||
result.indexed = this.indexed;
|
||||
}
|
||||
if (this.isTuple()) {
|
||||
result.components = this.components.map((c) => JSON.parse(c.format(format)));
|
||||
}
|
||||
return JSON.stringify(result);
|
||||
}
|
||||
let result = "";
|
||||
// Array
|
||||
if (this.isArray()) {
|
||||
result += this.arrayChildren.format(format);
|
||||
result += `[${(this.arrayLength < 0 ? "" : String(this.arrayLength))}]`;
|
||||
}
|
||||
else {
|
||||
if (this.isTuple()) {
|
||||
if (format !== FormatType.sighash) {
|
||||
result += this.type;
|
||||
}
|
||||
result += "(" + this.components.map((comp) => comp.format(format)).join((format === FormatType.full) ? ", " : ",") + ")";
|
||||
}
|
||||
else {
|
||||
result += this.type;
|
||||
}
|
||||
}
|
||||
if (format !== FormatType.sighash) {
|
||||
if (this.indexed === true) {
|
||||
result += " indexed";
|
||||
}
|
||||
if (format === FormatType.full && this.name) {
|
||||
result += " " + this.name;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static isArray(value) {
|
||||
return value && (value.baseType === "array");
|
||||
}
|
||||
isArray() {
|
||||
return (this.baseType === "array");
|
||||
}
|
||||
isTuple() {
|
||||
return (this.baseType === "tuple");
|
||||
}
|
||||
isIndexable() {
|
||||
return (this.indexed != null);
|
||||
}
|
||||
walk(value, process) {
|
||||
if (this.isArray()) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error("invlaid array value");
|
||||
}
|
||||
if (this.arrayLength !== -1 && value.length !== this.arrayLength) {
|
||||
throw new Error("array is wrong length");
|
||||
}
|
||||
return value.map((v) => (this.arrayChildren.walk(v, process)));
|
||||
}
|
||||
if (this.isTuple()) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error("invlaid tuple value");
|
||||
}
|
||||
if (value.length !== this.components.length) {
|
||||
throw new Error("array is wrong length");
|
||||
}
|
||||
return value.map((v, i) => (this.components[i].walk(v, process)));
|
||||
}
|
||||
return process(this.type, value);
|
||||
}
|
||||
async walkAsync(value, process) {
|
||||
const promises = [];
|
||||
const result = [value];
|
||||
__classPrivateFieldGet(this, _ParamType_instances, "m", _ParamType_walkAsync).call(this, promises, value, process, (value) => {
|
||||
result[0] = value;
|
||||
});
|
||||
if (promises.length) {
|
||||
await Promise.all(promises);
|
||||
}
|
||||
return result[0];
|
||||
}
|
||||
static from(obj, allowIndexed) {
|
||||
if (ParamType.isParamType(obj)) {
|
||||
return obj;
|
||||
}
|
||||
if (typeof (obj) === "string") {
|
||||
return ParamType.fromTokens(lex(obj), allowIndexed);
|
||||
}
|
||||
if (obj instanceof TokenString) {
|
||||
return ParamType.fromTokens(obj, allowIndexed);
|
||||
}
|
||||
const name = obj.name;
|
||||
if (name && (typeof (name) !== "string" || !name.match(regexIdentifier))) {
|
||||
logger.throwArgumentError("invalid name", "obj.name", name);
|
||||
}
|
||||
let indexed = obj.indexed;
|
||||
if (indexed != null) {
|
||||
if (!allowIndexed) {
|
||||
logger.throwArgumentError("parameter cannot be indexed", "obj.indexed", obj.indexed);
|
||||
}
|
||||
indexed = !!indexed;
|
||||
}
|
||||
let type = obj.type;
|
||||
let arrayMatch = type.match(regexArrayType);
|
||||
if (arrayMatch) {
|
||||
const arrayLength = arrayMatch[2];
|
||||
const arrayChildren = ParamType.from({
|
||||
type: arrayMatch[1],
|
||||
components: obj.components
|
||||
});
|
||||
return new ParamType(_guard, name, type, "array", indexed, null, arrayLength, arrayChildren);
|
||||
}
|
||||
if (type.substring(0, 5) === "tuple(" || type[0] === "(") {
|
||||
const comps = (obj.components != null) ? obj.components.map((c) => ParamType.from(c)) : null;
|
||||
const tuple = new ParamType(_guard, name, type, "tuple", indexed, comps, null, null);
|
||||
// @TODO: use lexer to validate and normalize type
|
||||
return tuple;
|
||||
}
|
||||
type = verifyBasicType(obj.type);
|
||||
return new ParamType(_guard, name, type, type, indexed, null, null, null);
|
||||
}
|
||||
static fromObject(obj, allowIndexed) {
|
||||
throw new Error("@TODO");
|
||||
}
|
||||
static fromTokens(tokens, allowIndexed) {
|
||||
let type = "", baseType = "";
|
||||
let comps = null;
|
||||
if (consumeKeywords(tokens, setify(["tuple"])).has("tuple") || tokens.peekType("OPEN_PAREN")) {
|
||||
// Tuple
|
||||
baseType = "tuple";
|
||||
comps = tokens.popParams().map((t) => ParamType.from(t));
|
||||
type = `tuple(${comps.map((c) => c.format()).join(",")})`;
|
||||
}
|
||||
else {
|
||||
// Normal
|
||||
type = verifyBasicType(tokens.popType("TYPE"));
|
||||
baseType = type;
|
||||
}
|
||||
// Check for Array
|
||||
let arrayChildren = null;
|
||||
let arrayLength = null;
|
||||
while (tokens.length && tokens.peekType("BRACKET")) {
|
||||
const bracket = tokens.pop(); //arrays[i];
|
||||
arrayChildren = new ParamType(_guard, "", type, baseType, null, comps, arrayLength, arrayChildren);
|
||||
arrayLength = bracket.value;
|
||||
type += bracket.text;
|
||||
baseType = "array";
|
||||
comps = null;
|
||||
}
|
||||
let indexed = null;
|
||||
const keywords = consumeKeywords(tokens, KwModifiers);
|
||||
if (keywords.has("indexed")) {
|
||||
if (!allowIndexed) {
|
||||
throw new Error("");
|
||||
}
|
||||
indexed = true;
|
||||
}
|
||||
const name = (tokens.peekType("ID") ? tokens.pop().text : "");
|
||||
if (tokens.length) {
|
||||
throw new Error("leftover tokens");
|
||||
}
|
||||
return new ParamType(_guard, name, type, baseType, indexed, comps, arrayLength, arrayChildren);
|
||||
}
|
||||
static isParamType(value) {
|
||||
return (value && value[internal] === ParamTypeInternal);
|
||||
}
|
||||
}
|
||||
_ParamType_instances = new WeakSet(), _ParamType_walkAsync = function _ParamType_walkAsync(promises, value, process, setValue) {
|
||||
if (this.isArray()) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error("invlaid array value");
|
||||
}
|
||||
if (this.arrayLength !== -1 && value.length !== this.arrayLength) {
|
||||
throw new Error("array is wrong length");
|
||||
}
|
||||
const childType = this.arrayChildren;
|
||||
const result = value.slice();
|
||||
result.forEach((value, index) => {
|
||||
__classPrivateFieldGet(childType, _ParamType_instances, "m", _ParamType_walkAsync).call(childType, promises, value, process, (value) => {
|
||||
result[index] = value;
|
||||
});
|
||||
});
|
||||
setValue(result);
|
||||
return;
|
||||
}
|
||||
if (this.isTuple()) {
|
||||
const components = this.components;
|
||||
// Convert the object into an array
|
||||
let result;
|
||||
if (Array.isArray(value)) {
|
||||
result = value.slice();
|
||||
}
|
||||
else {
|
||||
if (value == null || typeof (value) !== "object") {
|
||||
throw new Error("invlaid tuple value");
|
||||
}
|
||||
result = components.map((param) => {
|
||||
if (!param.name) {
|
||||
throw new Error("cannot use object value with unnamed components");
|
||||
}
|
||||
if (!(param.name in value)) {
|
||||
throw new Error(`missing value for component ${param.name}`);
|
||||
}
|
||||
return value[param.name];
|
||||
});
|
||||
}
|
||||
if (value.length !== this.components.length) {
|
||||
throw new Error("array is wrong length");
|
||||
}
|
||||
result.forEach((value, index) => {
|
||||
var _a;
|
||||
__classPrivateFieldGet((_a = components[index]), _ParamType_instances, "m", _ParamType_walkAsync).call(_a, promises, value, process, (value) => {
|
||||
result[index] = value;
|
||||
});
|
||||
});
|
||||
setValue(result);
|
||||
return;
|
||||
}
|
||||
const result = process(this.type, value);
|
||||
if (result.then) {
|
||||
promises.push((async function () { setValue(await result); })());
|
||||
}
|
||||
else {
|
||||
setValue(result);
|
||||
}
|
||||
};
|
||||
export var FragmentType;
|
||||
(function (FragmentType) {
|
||||
FragmentType["constructor"] = "constructor";
|
||||
FragmentType["error"] = "error";
|
||||
FragmentType["event"] = "event";
|
||||
FragmentType["function"] = "function";
|
||||
FragmentType["struct"] = "struct";
|
||||
})(FragmentType || (FragmentType = {}));
|
||||
;
|
||||
export class Fragment {
|
||||
constructor(guard, type, inputs) {
|
||||
logger.assertPrivate(guard, _guard, "Fragment");
|
||||
inputs = Object.freeze(inputs.slice());
|
||||
defineProperties(this, { type, inputs });
|
||||
}
|
||||
static from(obj) {
|
||||
if (typeof (obj) === "string") {
|
||||
return this.fromString(obj);
|
||||
}
|
||||
if (obj instanceof TokenString) {
|
||||
return this.fromTokens(obj);
|
||||
}
|
||||
if (typeof (obj) === "object") {
|
||||
return this.fromObject(obj);
|
||||
}
|
||||
throw new Error(`unsupported type: ${obj}`);
|
||||
}
|
||||
static fromObject(obj) {
|
||||
switch (obj.type) {
|
||||
case "constructor": return ConstructorFragment.fromObject(obj);
|
||||
case "error": return ErrorFragment.fromObject(obj);
|
||||
case "event": return EventFragment.fromObject(obj);
|
||||
case "function": return FunctionFragment.fromObject(obj);
|
||||
case "struct": return StructFragment.fromObject(obj);
|
||||
}
|
||||
throw new Error("not implemented yet");
|
||||
}
|
||||
static fromString(text) {
|
||||
try {
|
||||
Fragment.from(JSON.parse(text));
|
||||
}
|
||||
catch (e) { }
|
||||
return Fragment.fromTokens(lex(text));
|
||||
}
|
||||
static fromTokens(tokens) {
|
||||
const type = tokens.popKeyword(KwTypes);
|
||||
switch (type) {
|
||||
case "constructor": return ConstructorFragment.fromTokens(tokens);
|
||||
case "error": return ErrorFragment.fromTokens(tokens);
|
||||
case "event": return EventFragment.fromTokens(tokens);
|
||||
case "function": return FunctionFragment.fromTokens(tokens);
|
||||
case "struct": return StructFragment.fromTokens(tokens);
|
||||
}
|
||||
throw new Error(`unsupported type: ${type}`);
|
||||
}
|
||||
/*
|
||||
static fromTokens(tokens: TokenString): Fragment {
|
||||
const assertDone = () => {
|
||||
if (tokens.length) { throw new Error(`unexpected tokens: ${ tokens.toString() }`); }
|
||||
});
|
||||
|
||||
const type = (tokens.length && tokens.peek().type === "KEYWORD") ? tokens.peek().text: "unknown";
|
||||
|
||||
const name = consumeName("error", tokens);
|
||||
const inputs = consumeParams(tokens, type === "event");
|
||||
|
||||
switch (type) {
|
||||
case "event": case "struct":
|
||||
assertDone();
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
static isConstructor(value) {
|
||||
return (value && value.type === "constructor");
|
||||
}
|
||||
static isError(value) {
|
||||
return (value && value.type === "error");
|
||||
}
|
||||
static isEvent(value) {
|
||||
return (value && value.type === "event");
|
||||
}
|
||||
static isFunction(value) {
|
||||
return (value && value.type === "function");
|
||||
}
|
||||
static isStruct(value) {
|
||||
return (value && value.type === "struct");
|
||||
}
|
||||
}
|
||||
export class NamedFragment extends Fragment {
|
||||
constructor(guard, type, name, inputs) {
|
||||
super(guard, type, inputs);
|
||||
inputs = Object.freeze(inputs.slice());
|
||||
defineProperties(this, { name });
|
||||
}
|
||||
}
|
||||
function joinParams(format, params) {
|
||||
return "(" + params.map((p) => p.format(format)).join((format === FormatType.full) ? ", " : ",") + ")";
|
||||
}
|
||||
export class ErrorFragment extends NamedFragment {
|
||||
constructor(guard, name, inputs) {
|
||||
super(guard, FragmentType.error, name, inputs);
|
||||
}
|
||||
format(format = FormatType.sighash) {
|
||||
if (!FormatType[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatType.json) {
|
||||
return JSON.stringify({
|
||||
type: "error",
|
||||
name: this.name,
|
||||
inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
|
||||
});
|
||||
}
|
||||
const result = [];
|
||||
if (format !== FormatType.sighash) {
|
||||
result.push("error");
|
||||
}
|
||||
result.push(this.name + joinParams(format, this.inputs));
|
||||
return result.join(" ");
|
||||
}
|
||||
static fromString(text) {
|
||||
return ErrorFragment.fromTokens(lex(text));
|
||||
}
|
||||
static fromTokens(tokens) {
|
||||
const name = consumeName("error", tokens);
|
||||
const inputs = consumeParams(tokens);
|
||||
consumeEoi(tokens);
|
||||
return new ErrorFragment(_guard, name, inputs);
|
||||
}
|
||||
}
|
||||
export class EventFragment extends NamedFragment {
|
||||
constructor(guard, name, inputs, anonymous) {
|
||||
super(guard, FragmentType.event, name, inputs);
|
||||
defineProperties(this, { anonymous });
|
||||
}
|
||||
format(format = FormatType.sighash) {
|
||||
if (!FormatType[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatType.json) {
|
||||
return JSON.stringify({
|
||||
type: "event",
|
||||
anonymous: this.anonymous,
|
||||
name: this.name,
|
||||
inputs: this.inputs.map((i) => JSON.parse(i.format(format)))
|
||||
});
|
||||
}
|
||||
const result = [];
|
||||
if (format !== FormatType.sighash) {
|
||||
result.push("event");
|
||||
}
|
||||
result.push(this.name + joinParams(format, this.inputs));
|
||||
if (format !== FormatType.sighash && this.anonymous) {
|
||||
result.push("anonymous");
|
||||
}
|
||||
return result.join(" ");
|
||||
}
|
||||
static fromString(text) {
|
||||
return EventFragment.fromTokens(lex(text));
|
||||
}
|
||||
static fromTokens(tokens) {
|
||||
const name = consumeName("event", tokens);
|
||||
const inputs = consumeParams(tokens, true);
|
||||
const anonymous = !!consumeKeywords(tokens, setify(["anonymous"])).has("anonymous");
|
||||
consumeEoi(tokens);
|
||||
return new EventFragment(_guard, name, inputs, anonymous);
|
||||
}
|
||||
}
|
||||
export class ConstructorFragment extends Fragment {
|
||||
constructor(guard, type, inputs, payable, gas) {
|
||||
super(guard, type, inputs);
|
||||
defineProperties(this, { payable, gas });
|
||||
}
|
||||
format(format = FormatType.sighash) {
|
||||
if (!FormatType[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatType.sighash) {
|
||||
logger.throwError("cannot format a constructor for sighash", "UNSUPPORTED_OPERATION", {
|
||||
operation: "format(sighash)"
|
||||
});
|
||||
}
|
||||
if (format === FormatType.json) {
|
||||
return JSON.stringify({
|
||||
type: "constructor",
|
||||
stateMutability: (this.payable ? "payable" : "undefined"),
|
||||
payable: this.payable,
|
||||
gas: ((this.gas != null) ? this.gas : undefined),
|
||||
inputs: this.inputs.map((i) => JSON.parse(i.format(format)))
|
||||
});
|
||||
}
|
||||
const result = [`constructor${joinParams(format, this.inputs)}`];
|
||||
result.push((this.payable) ? "payable" : "nonpayable");
|
||||
if (this.gas != null) {
|
||||
result.push(`@${this.gas.toString()}`);
|
||||
}
|
||||
return result.join(" ");
|
||||
}
|
||||
static fromString(text) {
|
||||
return ConstructorFragment.fromTokens(lex(text));
|
||||
}
|
||||
static fromObject(obj) {
|
||||
throw new Error("TODO");
|
||||
}
|
||||
static fromTokens(tokens) {
|
||||
consumeKeywords(tokens, setify(["constructor"]));
|
||||
const inputs = consumeParams(tokens);
|
||||
const payable = !!consumeKeywords(tokens, setify(["payable"])).has("payable");
|
||||
const gas = consumeGas(tokens);
|
||||
consumeEoi(tokens);
|
||||
return new ConstructorFragment(_guard, FragmentType.constructor, inputs, payable, gas);
|
||||
}
|
||||
}
|
||||
export class FunctionFragment extends NamedFragment {
|
||||
constructor(guard, name, stateMutability, inputs, outputs, gas) {
|
||||
super(guard, FragmentType.function, name, inputs);
|
||||
outputs = Object.freeze(outputs.slice());
|
||||
const constant = (stateMutability === "view" || stateMutability === "pure");
|
||||
const payable = (stateMutability === "payable");
|
||||
defineProperties(this, { constant, gas, outputs, payable, stateMutability });
|
||||
}
|
||||
format(format = FormatType.sighash) {
|
||||
if (!FormatType[format]) {
|
||||
logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatType.json) {
|
||||
return JSON.stringify({
|
||||
type: "function",
|
||||
name: this.name,
|
||||
constant: this.constant,
|
||||
stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
|
||||
payable: this.payable,
|
||||
gas: ((this.gas != null) ? this.gas : undefined),
|
||||
inputs: this.inputs.map((i) => JSON.parse(i.format(format))),
|
||||
outputs: this.outputs.map((o) => JSON.parse(o.format(format))),
|
||||
});
|
||||
}
|
||||
const result = [];
|
||||
if (format !== FormatType.sighash) {
|
||||
result.push("function");
|
||||
}
|
||||
result.push(this.name + joinParams(format, this.inputs));
|
||||
if (format !== FormatType.sighash) {
|
||||
if (this.stateMutability !== "nonpayable") {
|
||||
result.push(this.stateMutability);
|
||||
}
|
||||
if (this.outputs && this.outputs.length) {
|
||||
result.push("returns");
|
||||
result.push(joinParams(format, this.outputs));
|
||||
}
|
||||
if (this.gas != null) {
|
||||
result.push(`@${this.gas.toString()}`);
|
||||
}
|
||||
}
|
||||
return result.join(" ");
|
||||
}
|
||||
static fromString(text) {
|
||||
return FunctionFragment.fromTokens(lex(text));
|
||||
}
|
||||
static fromTokens(tokens) {
|
||||
const name = consumeName("function", tokens);
|
||||
const inputs = consumeParams(tokens);
|
||||
const mutability = consumeMutability(tokens);
|
||||
let outputs = [];
|
||||
if (consumeKeywords(tokens, setify(["returns"])).has("returns")) {
|
||||
outputs = consumeParams(tokens);
|
||||
}
|
||||
const gas = consumeGas(tokens);
|
||||
consumeEoi(tokens);
|
||||
return new FunctionFragment(_guard, name, mutability, inputs, outputs, gas);
|
||||
}
|
||||
}
|
||||
export class StructFragment extends NamedFragment {
|
||||
format() {
|
||||
throw new Error("@TODO");
|
||||
}
|
||||
static fromString(text) {
|
||||
return StructFragment.fromTokens(lex(text));
|
||||
}
|
||||
static fromTokens(tokens) {
|
||||
const name = consumeName("struct", tokens);
|
||||
const inputs = consumeParams(tokens);
|
||||
consumeEoi(tokens);
|
||||
return new StructFragment(_guard, FragmentType.struct, name, inputs);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=fragments.js.map
|
1
packages/abi/lib/fragments.js.map
Normal file
1
packages/abi/lib/fragments.js.map
Normal file
File diff suppressed because one or more lines are too long
7
packages/abi/lib/index.d.ts
vendored
Normal file
7
packages/abi/lib/index.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import { ConstructorFragment, ErrorFragment, EventFragment, Fragment, FunctionFragment, JsonFragment, JsonFragmentType, ParamType } from "./fragments.js";
|
||||
import { AbiCoder, CoerceFunc, defaultAbiCoder } from "./abi-coder.js";
|
||||
import { checkResultErrors, Indexed, Interface, InterfaceAbi, LogDescription, Result, TransactionDescription } from "./interface.js";
|
||||
export { Typed } from "./typed.js";
|
||||
export { ConstructorFragment, ErrorFragment, EventFragment, Fragment, FunctionFragment, ParamType, AbiCoder, defaultAbiCoder, Interface, Indexed, };
|
||||
export type { CoerceFunc, JsonFragment, JsonFragmentType, InterfaceAbi, Result, checkResultErrors, LogDescription, TransactionDescription };
|
||||
//# sourceMappingURL=index.d.ts.map
|
1
packages/abi/lib/index.d.ts.map
Normal file
1
packages/abi/lib/index.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1J,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACrI,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EACH,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,SAAS,EAET,QAAQ,EACR,eAAe,EAEf,SAAS,EACT,OAAO,GAEV,CAAC;AAEF,YAAY,EACR,UAAU,EACV,YAAY,EACZ,gBAAgB,EAEhB,YAAY,EAEZ,MAAM,EACN,iBAAiB,EAEjB,cAAc,EACd,sBAAsB,EACzB,CAAC"}
|
7
packages/abi/lib/index.js
Normal file
7
packages/abi/lib/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
// @TODO: export from
|
||||
import { ConstructorFragment, ErrorFragment, EventFragment, Fragment, FunctionFragment, ParamType } from "./fragments.js";
|
||||
import { AbiCoder, defaultAbiCoder } from "./abi-coder.js";
|
||||
import { checkResultErrors, Indexed, Interface, LogDescription, Result, TransactionDescription } from "./interface.js";
|
||||
export { Typed } from "./typed.js";
|
||||
export { ConstructorFragment, ErrorFragment, EventFragment, Fragment, FunctionFragment, ParamType, AbiCoder, defaultAbiCoder, Interface, Indexed, };
|
||||
//# sourceMappingURL=index.js.map
|
1
packages/abi/lib/index.js.map
Normal file
1
packages/abi/lib/index.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AAAA,qBAAqB;AAErB,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,gBAAgB,EAAkC,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1J,OAAO,EAAE,QAAQ,EAAc,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,SAAS,EAAgB,cAAc,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACrI,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EACH,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,SAAS,EAET,QAAQ,EACR,eAAe,EAEf,SAAS,EACT,OAAO,GAEV,CAAC"}
|
84
packages/abi/lib/interface.d.ts
vendored
Normal file
84
packages/abi/lib/interface.d.ts
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
import { AbiCoder } from "./abi-coder.js";
|
||||
import { checkResultErrors, Result } from "./coders/abstract-coder.js";
|
||||
import { ConstructorFragment, ErrorFragment, EventFragment, FormatType, Fragment, FunctionFragment, ParamType } from "./fragments.js";
|
||||
import { Typed } from "./typed.js";
|
||||
import type { BytesLike } from "@ethersproject/bytes";
|
||||
import type { BigNumberish } from "@ethersproject/logger";
|
||||
import type { JsonFragment } from "./fragments.js";
|
||||
export { checkResultErrors, Result };
|
||||
export declare class LogDescription {
|
||||
readonly fragment: EventFragment;
|
||||
readonly name: string;
|
||||
readonly signature: string;
|
||||
readonly topic: string;
|
||||
readonly args: Result;
|
||||
constructor(fragment: EventFragment, topic: string, args: Result);
|
||||
}
|
||||
export declare class TransactionDescription {
|
||||
readonly fragment: FunctionFragment;
|
||||
readonly name: string;
|
||||
readonly args: Result;
|
||||
readonly signature: string;
|
||||
readonly selector: string;
|
||||
readonly value: bigint;
|
||||
constructor(fragment: FunctionFragment, selector: string, args: Result, value: bigint);
|
||||
}
|
||||
export declare class ErrorDescription {
|
||||
readonly fragment: ErrorFragment;
|
||||
readonly name: string;
|
||||
readonly args: Result;
|
||||
readonly signature: string;
|
||||
readonly selector: string;
|
||||
constructor(fragment: ErrorFragment, selector: string, args: Result);
|
||||
}
|
||||
export declare class Indexed {
|
||||
readonly hash: null | string;
|
||||
readonly _isIndexed: boolean;
|
||||
static isIndexed(value: any): value is Indexed;
|
||||
constructor(hash: null | string);
|
||||
}
|
||||
export declare type InterfaceAbi = string | ReadonlyArray<Fragment | JsonFragment | string>;
|
||||
export declare class Interface {
|
||||
#private;
|
||||
readonly fragments: ReadonlyArray<Fragment>;
|
||||
readonly deploy: ConstructorFragment;
|
||||
constructor(fragments: InterfaceAbi);
|
||||
format(format?: FormatType): string | Array<string>;
|
||||
getAbiCoder(): AbiCoder;
|
||||
getFunctionName(key: string): string;
|
||||
getFunction(key: string, values?: Array<any | Typed>): FunctionFragment;
|
||||
getEventName(key: string): string;
|
||||
getEvent(key: string, values?: Array<any | Typed>): EventFragment;
|
||||
getError(key: string, values?: Array<any | Typed>): ErrorFragment;
|
||||
getSelector(fragment: ErrorFragment | FunctionFragment): string;
|
||||
getEventTopic(fragment: EventFragment): string;
|
||||
_decodeParams(params: ReadonlyArray<ParamType>, data: BytesLike): Result;
|
||||
_encodeParams(params: ReadonlyArray<ParamType>, values: ReadonlyArray<any>): string;
|
||||
encodeDeploy(values?: ReadonlyArray<any>): string;
|
||||
decodeErrorResult(fragment: ErrorFragment | string, data: BytesLike): Result;
|
||||
encodeErrorResult(fragment: ErrorFragment | string, values?: ReadonlyArray<any>): string;
|
||||
decodeFunctionData(fragment: FunctionFragment | string, data: BytesLike): Result;
|
||||
encodeFunctionData(fragment: FunctionFragment | string, values?: ReadonlyArray<any>): string;
|
||||
decodeFunctionResult(fragment: FunctionFragment | string, data: BytesLike): Result;
|
||||
makeError(fragment: FunctionFragment | string, _data: BytesLike, tx?: {
|
||||
data: string;
|
||||
}): Error;
|
||||
encodeFunctionResult(functionFragment: FunctionFragment | string, values?: ReadonlyArray<any>): string;
|
||||
encodeFilterTopics(eventFragment: EventFragment, values: ReadonlyArray<any>): Array<null | string | Array<string>>;
|
||||
encodeEventLog(eventFragment: EventFragment, values: ReadonlyArray<any>): {
|
||||
data: string;
|
||||
topics: Array<string>;
|
||||
};
|
||||
decodeEventLog(eventFragment: EventFragment | string, data: BytesLike, topics?: ReadonlyArray<string>): Result;
|
||||
parseTransaction(tx: {
|
||||
data: string;
|
||||
value?: BigNumberish;
|
||||
}): null | TransactionDescription;
|
||||
parseLog(log: {
|
||||
topics: Array<string>;
|
||||
data: string;
|
||||
}): null | LogDescription;
|
||||
parseError(data: BytesLike): null | ErrorDescription;
|
||||
static from(value: ReadonlyArray<Fragment | string | JsonFragment> | string | Interface): Interface;
|
||||
}
|
||||
//# sourceMappingURL=interface.d.ts.map
|
1
packages/abi/lib/interface.d.ts.map
Normal file
1
packages/abi/lib/interface.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src.ts/interface.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAmB,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEtI,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,CAAC;AAErC,qBAAa,cAAc;IACvB,QAAQ,CAAC,QAAQ,EAAG,aAAa,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAG,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAG,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAA;gBAEV,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAMnE;AAED,qBAAa,sBAAsB;IAC/B,QAAQ,CAAC,QAAQ,EAAG,gBAAgB,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAG,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAG,MAAM,CAA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(this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
};
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var _Interface_instances, _Interface_errors, _Interface_events, _Interface_functions, _Interface_abiCoder, _Interface_getFunction, _Interface_getEvent;
|
||||
import { arrayify, concat, dataSlice, hexlify, zeroPadLeft, isHexString } from "@ethersproject/bytes";
|
||||
import { keccak256 } from "@ethersproject/crypto";
|
||||
import { id } from "@ethersproject/hash";
|
||||
import { defineProperties } from "@ethersproject/properties";
|
||||
import { defaultAbiCoder } from "./abi-coder.js";
|
||||
import { checkResultErrors, Result } from "./coders/abstract-coder.js";
|
||||
import { ConstructorFragment, ErrorFragment, EventFragment, FormatType, Fragment, FunctionFragment, ParamType } from "./fragments.js";
|
||||
import { logger } from "./logger.js";
|
||||
import { Typed } from "./typed.js";
|
||||
export { checkResultErrors, Result };
|
||||
export class LogDescription {
|
||||
constructor(fragment, topic, args) {
|
||||
const name = fragment.name, signature = fragment.format();
|
||||
defineProperties(this, {
|
||||
fragment, name, signature, topic, args
|
||||
});
|
||||
}
|
||||
}
|
||||
export class TransactionDescription {
|
||||
constructor(fragment, selector, args, value) {
|
||||
const name = fragment.name, signature = fragment.format();
|
||||
defineProperties(this, {
|
||||
fragment, name, args, signature, selector, value
|
||||
});
|
||||
}
|
||||
}
|
||||
export class ErrorDescription {
|
||||
constructor(fragment, selector, args) {
|
||||
const name = fragment.name, signature = fragment.format();
|
||||
defineProperties(this, {
|
||||
fragment, name, args, signature, selector
|
||||
});
|
||||
}
|
||||
}
|
||||
export class Indexed {
|
||||
constructor(hash) {
|
||||
defineProperties(this, { hash, _isIndexed: true });
|
||||
}
|
||||
static isIndexed(value) {
|
||||
return !!(value && value._isIndexed);
|
||||
}
|
||||
}
|
||||
// https://docs.soliditylang.org/en/v0.8.13/control-structures.html?highlight=panic#panic-via-assert-and-error-via-require
|
||||
const PanicReasons = {
|
||||
"0": "generic panic",
|
||||
"1": "assert(false)",
|
||||
"17": "arithmetic overflow",
|
||||
"18": "division or modulo by zero",
|
||||
"33": "enum overflow",
|
||||
"34": "invalid encoded storage byte array accessed",
|
||||
"49": "out-of-bounds array access; popping on an empty array",
|
||||
"50": "out-of-bounds access of an array or bytesN",
|
||||
"65": "out of memory",
|
||||
"81": "uninitialized function",
|
||||
};
|
||||
const BuiltinErrors = {
|
||||
"0x08c379a0": {
|
||||
signature: "Error(string)",
|
||||
name: "Error",
|
||||
inputs: ["string"],
|
||||
reason: (message) => {
|
||||
return `reverted with reason string ${JSON.stringify(message)}`;
|
||||
}
|
||||
},
|
||||
"0x4e487b71": {
|
||||
signature: "Panic(uint256)",
|
||||
name: "Panic",
|
||||
inputs: ["uint256"],
|
||||
reason: (code) => {
|
||||
let reason = "unknown panic code";
|
||||
if (code >= 0 && code <= 0xff && PanicReasons[code.toString()]) {
|
||||
reason = PanicReasons[code.toString()];
|
||||
}
|
||||
return `reverted with panic code 0x${code.toString(16)} (${reason})`;
|
||||
}
|
||||
}
|
||||
};
|
||||
export class Interface {
|
||||
constructor(fragments) {
|
||||
_Interface_instances.add(this);
|
||||
_Interface_errors.set(this, void 0);
|
||||
_Interface_events.set(this, void 0);
|
||||
_Interface_functions.set(this, void 0);
|
||||
// #structs: Map<string, StructFragment>;
|
||||
_Interface_abiCoder.set(this, void 0);
|
||||
let abi = [];
|
||||
if (typeof (fragments) === "string") {
|
||||
abi = JSON.parse(fragments);
|
||||
}
|
||||
else {
|
||||
abi = fragments;
|
||||
}
|
||||
__classPrivateFieldSet(this, _Interface_functions, new Map(), "f");
|
||||
__classPrivateFieldSet(this, _Interface_errors, new Map(), "f");
|
||||
__classPrivateFieldSet(this, _Interface_events, new Map(), "f");
|
||||
// this.#structs = new Map();
|
||||
defineProperties(this, {
|
||||
fragments: Object.freeze(abi.map((f) => Fragment.from(f)).filter((f) => (f != null))),
|
||||
});
|
||||
__classPrivateFieldSet(this, _Interface_abiCoder, this.getAbiCoder(), "f");
|
||||
// Add all fragments by their signature
|
||||
this.fragments.forEach((fragment) => {
|
||||
let bucket;
|
||||
switch (fragment.type) {
|
||||
case "constructor":
|
||||
if (this.deploy) {
|
||||
logger.warn("duplicate definition - constructor");
|
||||
return;
|
||||
}
|
||||
//checkNames(fragment, "input", fragment.inputs);
|
||||
defineProperties(this, { deploy: fragment });
|
||||
return;
|
||||
case "function":
|
||||
//checkNames(fragment, "input", fragment.inputs);
|
||||
//checkNames(fragment, "output", (<FunctionFragment>fragment).outputs);
|
||||
bucket = __classPrivateFieldGet(this, _Interface_functions, "f");
|
||||
break;
|
||||
case "event":
|
||||
//checkNames(fragment, "input", fragment.inputs);
|
||||
bucket = __classPrivateFieldGet(this, _Interface_events, "f");
|
||||
break;
|
||||
case "error":
|
||||
bucket = __classPrivateFieldGet(this, _Interface_errors, "f");
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
const signature = fragment.format();
|
||||
if (bucket.has(signature)) {
|
||||
logger.warn("duplicate definition - " + signature);
|
||||
return;
|
||||
}
|
||||
bucket.set(signature, fragment);
|
||||
});
|
||||
// If we do not have a constructor add a default
|
||||
if (!this.deploy) {
|
||||
defineProperties(this, {
|
||||
deploy: ConstructorFragment.fromString("constructor()")
|
||||
});
|
||||
}
|
||||
}
|
||||
// @TODO: multi sig?
|
||||
format(format) {
|
||||
if (!format) {
|
||||
format = FormatType.full;
|
||||
}
|
||||
if (format === FormatType.sighash) {
|
||||
logger.throwArgumentError("interface does not support formatting sighash", "format", format);
|
||||
}
|
||||
const abi = this.fragments.map((f) => f.format(format));
|
||||
// We need to re-bundle the JSON fragments a bit
|
||||
if (format === FormatType.json) {
|
||||
return JSON.stringify(abi.map((j) => JSON.parse(j)));
|
||||
}
|
||||
return abi;
|
||||
}
|
||||
getAbiCoder() {
|
||||
return defaultAbiCoder;
|
||||
}
|
||||
getFunctionName(key) {
|
||||
return (__classPrivateFieldGet(this, _Interface_instances, "m", _Interface_getFunction).call(this, key, null, false)).name;
|
||||
}
|
||||
getFunction(key, values) {
|
||||
return __classPrivateFieldGet(this, _Interface_instances, "m", _Interface_getFunction).call(this, key, values || null, true);
|
||||
}
|
||||
getEventName(key) {
|
||||
return (__classPrivateFieldGet(this, _Interface_instances, "m", _Interface_getEvent).call(this, key, null, false)).name;
|
||||
}
|
||||
getEvent(key, values) {
|
||||
return __classPrivateFieldGet(this, _Interface_instances, "m", _Interface_getEvent).call(this, key, values || null, true);
|
||||
}
|
||||
// Find a function definition by any means necessary (unless it is ambiguous)
|
||||
getError(key, values) {
|
||||
if (isHexString(key)) {
|
||||
const selector = key.toLowerCase();
|
||||
for (const fragment of __classPrivateFieldGet(this, _Interface_errors, "f").values()) {
|
||||
if (selector === this.getSelector(fragment)) {
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
logger.throwArgumentError("no matching error", "selector", key);
|
||||
}
|
||||
// It is a bare name, look up the function (will return null if ambiguous)
|
||||
if (key.indexOf("(") === -1) {
|
||||
const matching = [];
|
||||
for (const [name, fragment] of __classPrivateFieldGet(this, _Interface_errors, "f")) {
|
||||
if (name.split("(" /* fix:) */)[0] === key) {
|
||||
matching.push(fragment);
|
||||
}
|
||||
}
|
||||
if (matching.length === 0) {
|
||||
logger.throwArgumentError("no matching error", "name", key);
|
||||
}
|
||||
else if (matching.length > 1) {
|
||||
// @TODO: refine by Typed
|
||||
logger.throwArgumentError("multiple matching errors", "name", key);
|
||||
}
|
||||
return matching[0];
|
||||
}
|
||||
// Normalize the signature and lookup the function
|
||||
const result = __classPrivateFieldGet(this, _Interface_errors, "f").get(ErrorFragment.fromString(key).format());
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
return logger.throwArgumentError("no matching error", "signature", key);
|
||||
}
|
||||
// Get the 4-byte selector used by Solidity to identify a function
|
||||
getSelector(fragment) {
|
||||
/*
|
||||
if (typeof(fragment) === "string") {
|
||||
const matches: Array<Fragment> = [ ];
|
||||
|
||||
try { matches.push(this.getFunction(fragment)); } catch (error) { }
|
||||
try { matches.push(this.getError(<string>fragment)); } catch (_) { }
|
||||
|
||||
if (matches.length === 0) {
|
||||
logger.throwArgumentError("unknown fragment", "key", fragment);
|
||||
} else if (matches.length > 1) {
|
||||
logger.throwArgumentError("ambiguous fragment matches function and error", "key", fragment);
|
||||
}
|
||||
|
||||
fragment = matches[0];
|
||||
}
|
||||
*/
|
||||
return dataSlice(id(fragment.format()), 0, 4);
|
||||
}
|
||||
// Get the 32-byte topic hash used by Solidity to identify an event
|
||||
getEventTopic(fragment) {
|
||||
//if (typeof(fragment) === "string") { fragment = this.getEvent(eventFragment); }
|
||||
return id(fragment.format());
|
||||
}
|
||||
_decodeParams(params, data) {
|
||||
return __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(params, data);
|
||||
}
|
||||
_encodeParams(params, values) {
|
||||
return __classPrivateFieldGet(this, _Interface_abiCoder, "f").encode(params, values);
|
||||
}
|
||||
encodeDeploy(values) {
|
||||
return this._encodeParams(this.deploy.inputs, values || []);
|
||||
}
|
||||
decodeErrorResult(fragment, data) {
|
||||
if (typeof (fragment) === "string") {
|
||||
fragment = this.getError(fragment);
|
||||
}
|
||||
if (dataSlice(data, 0, 4) !== this.getSelector(fragment)) {
|
||||
logger.throwArgumentError(`data signature does not match error ${fragment.name}.`, "data", data);
|
||||
}
|
||||
return this._decodeParams(fragment.inputs, dataSlice(data, 4));
|
||||
}
|
||||
encodeErrorResult(fragment, values) {
|
||||
if (typeof (fragment) === "string") {
|
||||
fragment = this.getError(fragment);
|
||||
}
|
||||
return concat([
|
||||
this.getSelector(fragment),
|
||||
this._encodeParams(fragment.inputs, values || [])
|
||||
]);
|
||||
}
|
||||
// Decode the data for a function call (e.g. tx.data)
|
||||
decodeFunctionData(fragment, data) {
|
||||
if (typeof (fragment) === "string") {
|
||||
fragment = this.getFunction(fragment);
|
||||
}
|
||||
if (dataSlice(data, 0, 4) !== this.getSelector(fragment)) {
|
||||
logger.throwArgumentError(`data signature does not match function ${fragment.name}.`, "data", data);
|
||||
}
|
||||
return this._decodeParams(fragment.inputs, dataSlice(data, 4));
|
||||
}
|
||||
// Encode the data for a function call (e.g. tx.data)
|
||||
encodeFunctionData(fragment, values) {
|
||||
if (typeof (fragment) === "string") {
|
||||
fragment = this.getFunction(fragment);
|
||||
}
|
||||
return concat([
|
||||
this.getSelector(fragment),
|
||||
this._encodeParams(fragment.inputs, values || [])
|
||||
]);
|
||||
}
|
||||
// Decode the result from a function call (e.g. from eth_call)
|
||||
decodeFunctionResult(fragment, data) {
|
||||
if (typeof (fragment) === "string") {
|
||||
fragment = this.getFunction(fragment);
|
||||
}
|
||||
let message = "invalid length for result data";
|
||||
const bytes = arrayify(data);
|
||||
if ((bytes.length % 32) === 0) {
|
||||
try {
|
||||
return __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(fragment.outputs, bytes);
|
||||
}
|
||||
catch (error) {
|
||||
message = "could not decode result data";
|
||||
}
|
||||
}
|
||||
// Call returned data with no error, but the data is junk
|
||||
return logger.throwError(message, "BAD_DATA", {
|
||||
value: hexlify(bytes),
|
||||
info: { method: fragment.name, signature: fragment.format() }
|
||||
});
|
||||
}
|
||||
makeError(fragment, _data, tx) {
|
||||
if (typeof (fragment) === "string") {
|
||||
fragment = this.getFunction(fragment);
|
||||
}
|
||||
const data = logger.getBytes(_data);
|
||||
let args = undefined;
|
||||
if (tx) {
|
||||
try {
|
||||
args = __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(fragment.inputs, tx.data || "0x");
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
let errorArgs = undefined;
|
||||
let errorName = undefined;
|
||||
let errorSignature = undefined;
|
||||
let reason = "unknown reason";
|
||||
if (data.length === 0) {
|
||||
reason = "missing error reason";
|
||||
}
|
||||
else if ((data.length % 32) === 4) {
|
||||
const selector = hexlify(data.slice(0, 4));
|
||||
const builtin = BuiltinErrors[selector];
|
||||
if (builtin) {
|
||||
try {
|
||||
errorName = builtin.name;
|
||||
errorSignature = builtin.signature;
|
||||
errorArgs = __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(builtin.inputs, data.slice(4));
|
||||
reason = builtin.reason(...errorArgs);
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error); // @TODO: remove
|
||||
}
|
||||
}
|
||||
else {
|
||||
reason = "unknown custom error";
|
||||
try {
|
||||
const error = this.getError(selector);
|
||||
errorName = error.name;
|
||||
errorSignature = error.format();
|
||||
reason = `custom error: ${errorSignature}`;
|
||||
try {
|
||||
errorArgs = __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(error.inputs, data.slice(4));
|
||||
}
|
||||
catch (error) {
|
||||
reason = `custom error: ${errorSignature} (coult not decode error data)`;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error); // @TODO: remove
|
||||
}
|
||||
}
|
||||
}
|
||||
return logger.makeError("call revert exception", "CALL_EXCEPTION", {
|
||||
data: hexlify(data), transaction: null,
|
||||
method: fragment.name, signature: fragment.format(), args,
|
||||
errorArgs, errorName, errorSignature, reason
|
||||
});
|
||||
}
|
||||
// Encode the result for a function call (e.g. for eth_call)
|
||||
encodeFunctionResult(functionFragment, values) {
|
||||
if (typeof (functionFragment) === "string") {
|
||||
functionFragment = this.getFunction(functionFragment);
|
||||
}
|
||||
return hexlify(__classPrivateFieldGet(this, _Interface_abiCoder, "f").encode(functionFragment.outputs, values || []));
|
||||
}
|
||||
/*
|
||||
spelunk(inputs: Array<ParamType>, values: ReadonlyArray<any>, processfunc: (type: string, value: any) => Promise<any>): Promise<Array<any>> {
|
||||
const promises: Array<Promise<>> = [ ];
|
||||
const process = function(type: ParamType, value: any): any {
|
||||
if (type.baseType === "array") {
|
||||
return descend(type.child
|
||||
}
|
||||
if (type. === "address") {
|
||||
}
|
||||
};
|
||||
|
||||
const descend = function (inputs: Array<ParamType>, values: ReadonlyArray<any>) {
|
||||
if (inputs.length !== values.length) { throw new Error("length mismatch"); }
|
||||
|
||||
};
|
||||
|
||||
const result: Array<any> = [ ];
|
||||
values.forEach((value, index) => {
|
||||
if (value == null) {
|
||||
topics.push(null);
|
||||
} else if (param.baseType === "array" || param.baseType === "tuple") {
|
||||
logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
|
||||
} else if (Array.isArray(value)) {
|
||||
topics.push(value.map((value) => encodeTopic(param, value)));
|
||||
} else {
|
||||
topics.push(encodeTopic(param, value));
|
||||
}
|
||||
});
|
||||
}
|
||||
*/
|
||||
// Create the filter for the event with search criteria (e.g. for eth_filterLog)
|
||||
encodeFilterTopics(eventFragment, values) {
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
if (values.length > eventFragment.inputs.length) {
|
||||
logger.throwError("too many arguments for " + eventFragment.format(), "UNEXPECTED_ARGUMENT", {
|
||||
count: values.length,
|
||||
expectedCount: eventFragment.inputs.length
|
||||
});
|
||||
}
|
||||
const topics = [];
|
||||
if (!eventFragment.anonymous) {
|
||||
topics.push(this.getEventTopic(eventFragment));
|
||||
}
|
||||
const encodeTopic = (param, value) => {
|
||||
if (param.type === "string") {
|
||||
return id(value);
|
||||
}
|
||||
else if (param.type === "bytes") {
|
||||
return keccak256(hexlify(value));
|
||||
}
|
||||
// Check addresses are valid
|
||||
if (param.type === "address") {
|
||||
__classPrivateFieldGet(this, _Interface_abiCoder, "f").encode(["address"], [value]);
|
||||
}
|
||||
return zeroPadLeft(hexlify(value), 32);
|
||||
//@TOOD should probably be return toHex(value, 32)
|
||||
};
|
||||
values.forEach((value, index) => {
|
||||
const 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.baseType === "array" || param.baseType === "tuple") {
|
||||
logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
topics.push(value.map((value) => encodeTopic(param, value)));
|
||||
}
|
||||
else {
|
||||
topics.push(encodeTopic(param, value));
|
||||
}
|
||||
});
|
||||
// Trim off trailing nulls
|
||||
while (topics.length && topics[topics.length - 1] === null) {
|
||||
topics.pop();
|
||||
}
|
||||
return topics;
|
||||
}
|
||||
encodeEventLog(eventFragment, values) {
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
const topics = [];
|
||||
const dataTypes = [];
|
||||
const dataValues = [];
|
||||
if (!eventFragment.anonymous) {
|
||||
topics.push(this.getEventTopic(eventFragment));
|
||||
}
|
||||
if (values.length !== eventFragment.inputs.length) {
|
||||
logger.throwArgumentError("event arguments/values mismatch", "values", values);
|
||||
}
|
||||
eventFragment.inputs.forEach((param, index) => {
|
||||
const value = values[index];
|
||||
if (param.indexed) {
|
||||
if (param.type === "string") {
|
||||
topics.push(id(value));
|
||||
}
|
||||
else if (param.type === "bytes") {
|
||||
topics.push(keccak256(value));
|
||||
}
|
||||
else if (param.baseType === "tuple" || param.baseType === "array") {
|
||||
// @TODO
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
else {
|
||||
topics.push(__classPrivateFieldGet(this, _Interface_abiCoder, "f").encode([param.type], [value]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
dataTypes.push(param);
|
||||
dataValues.push(value);
|
||||
}
|
||||
});
|
||||
return {
|
||||
data: __classPrivateFieldGet(this, _Interface_abiCoder, "f").encode(dataTypes, dataValues),
|
||||
topics: topics
|
||||
};
|
||||
}
|
||||
// Decode a filter for the event and the search criteria
|
||||
decodeEventLog(eventFragment, data, topics) {
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
if (topics != null && !eventFragment.anonymous) {
|
||||
const eventTopic = this.getEventTopic(eventFragment);
|
||||
if (!isHexString(topics[0], 32) || topics[0].toLowerCase() !== eventTopic) {
|
||||
logger.throwArgumentError("fragment/topic mismatch", "topics[0]", topics[0]);
|
||||
}
|
||||
topics = topics.slice(1);
|
||||
}
|
||||
const indexed = [];
|
||||
const nonIndexed = [];
|
||||
const dynamic = [];
|
||||
eventFragment.inputs.forEach((param, index) => {
|
||||
if (param.indexed) {
|
||||
if (param.type === "string" || param.type === "bytes" || param.baseType === "tuple" || param.baseType === "array") {
|
||||
indexed.push(ParamType.fromObject({ type: "bytes32", name: param.name }));
|
||||
dynamic.push(true);
|
||||
}
|
||||
else {
|
||||
indexed.push(param);
|
||||
dynamic.push(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
nonIndexed.push(param);
|
||||
dynamic.push(false);
|
||||
}
|
||||
});
|
||||
const resultIndexed = (topics != null) ? __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(indexed, concat(topics)) : null;
|
||||
const resultNonIndexed = __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(nonIndexed, data, true);
|
||||
//const result: (Array<any> & { [ key: string ]: any }) = [ ];
|
||||
const values = [];
|
||||
const keys = [];
|
||||
let nonIndexedIndex = 0, indexedIndex = 0;
|
||||
eventFragment.inputs.forEach((param, index) => {
|
||||
let value = null;
|
||||
if (param.indexed) {
|
||||
if (resultIndexed == null) {
|
||||
value = new Indexed(null);
|
||||
}
|
||||
else if (dynamic[index]) {
|
||||
value = new Indexed(resultIndexed[indexedIndex++]);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
value = resultIndexed[indexedIndex++];
|
||||
}
|
||||
catch (error) {
|
||||
value = error;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
value = resultNonIndexed[nonIndexedIndex++];
|
||||
}
|
||||
catch (error) {
|
||||
value = error;
|
||||
}
|
||||
}
|
||||
values.push(value);
|
||||
keys.push(param.name || null);
|
||||
});
|
||||
return Result.fromItems(values, keys);
|
||||
}
|
||||
// Given a transaction, find the matching function fragment (if any) and
|
||||
// determine all its properties and call parameters
|
||||
parseTransaction(tx) {
|
||||
const data = logger.getBytes(tx.data, "tx.data");
|
||||
const value = logger.getBigInt((tx.value != null) ? tx.value : 0, "tx.value");
|
||||
const fragment = this.getFunction(hexlify(data.slice(0, 4)));
|
||||
if (!fragment) {
|
||||
return null;
|
||||
}
|
||||
const args = __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(fragment.inputs, data.slice(4));
|
||||
return new TransactionDescription(fragment, this.getSelector(fragment), args, value);
|
||||
}
|
||||
// @TODO
|
||||
//parseCallResult(data: BytesLike): ??
|
||||
// Given an event log, find the matching event fragment (if any) and
|
||||
// determine all its properties and values
|
||||
parseLog(log) {
|
||||
const fragment = this.getEvent(log.topics[0]);
|
||||
if (!fragment || fragment.anonymous) {
|
||||
return null;
|
||||
}
|
||||
// @TODO: If anonymous, and the only method, and the input count matches, should we parse?
|
||||
// Probably not, because just because it is the only event in the ABI does
|
||||
// not mean we have the full ABI; maybe just a fragment?
|
||||
return new LogDescription(fragment, this.getEventTopic(fragment), this.decodeEventLog(fragment, log.data, log.topics));
|
||||
}
|
||||
parseError(data) {
|
||||
const hexData = hexlify(data);
|
||||
const fragment = this.getError(dataSlice(hexData, 0, 4));
|
||||
if (!fragment) {
|
||||
return null;
|
||||
}
|
||||
const args = __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(fragment.inputs, dataSlice(hexData, 4));
|
||||
return new ErrorDescription(fragment, this.getSelector(fragment), args);
|
||||
}
|
||||
static from(value) {
|
||||
// Already an Interface, which is immutable
|
||||
if (value instanceof Interface) {
|
||||
return value;
|
||||
}
|
||||
// JSON
|
||||
if (typeof (value) === "string") {
|
||||
return new Interface(JSON.parse(value));
|
||||
}
|
||||
// Maybe an interface from an older version, or from a symlinked copy
|
||||
if (typeof (value.format) === "function") {
|
||||
return new Interface(value.format(FormatType.json));
|
||||
}
|
||||
// Array of fragments
|
||||
return new Interface(value);
|
||||
}
|
||||
}
|
||||
_Interface_errors = new WeakMap(), _Interface_events = new WeakMap(), _Interface_functions = new WeakMap(), _Interface_abiCoder = new WeakMap(), _Interface_instances = new WeakSet(), _Interface_getFunction = function _Interface_getFunction(key, values, forceUnique) {
|
||||
// Selector
|
||||
if (isHexString(key)) {
|
||||
const selector = key.toLowerCase();
|
||||
for (const fragment of __classPrivateFieldGet(this, _Interface_functions, "f").values()) {
|
||||
if (selector === this.getSelector(fragment)) {
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
logger.throwArgumentError("no matching function", "selector", key);
|
||||
}
|
||||
// It is a bare name, look up the function (will return null if ambiguous)
|
||||
if (key.indexOf("(") === -1) {
|
||||
const matching = [];
|
||||
for (const [name, fragment] of __classPrivateFieldGet(this, _Interface_functions, "f")) {
|
||||
if (name.split("(" /* fix:) */)[0] === key) {
|
||||
matching.push(fragment);
|
||||
}
|
||||
}
|
||||
if (values) {
|
||||
const lastValue = (values.length > 0) ? values[values.length - 1] : null;
|
||||
let valueLength = values.length;
|
||||
let allowOptions = true;
|
||||
if (Typed.isTyped(lastValue) && lastValue.type === "overrides") {
|
||||
allowOptions = false;
|
||||
valueLength--;
|
||||
}
|
||||
// Remove all matches that don't have a compatible length. The args
|
||||
// may contain an overrides, so the match may have n or n - 1 parameters
|
||||
for (let i = matching.length - 1; i >= 0; i--) {
|
||||
const inputs = matching[i].inputs.length;
|
||||
if (inputs !== valueLength && (!allowOptions || inputs !== valueLength - 1)) {
|
||||
matching.splice(i, 1);
|
||||
}
|
||||
}
|
||||
// Remove all matches that don't match the Typed signature
|
||||
for (let i = matching.length - 1; i >= 0; i--) {
|
||||
const inputs = matching[i].inputs;
|
||||
for (let j = 0; j < values.length; j++) {
|
||||
// Not a typed value
|
||||
if (!Typed.isTyped(values[j])) {
|
||||
continue;
|
||||
}
|
||||
// We are past the inputs
|
||||
if (j >= inputs.length) {
|
||||
if (values[j].type === "overrides") {
|
||||
continue;
|
||||
}
|
||||
matching.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
// Make sure the value type matches the input type
|
||||
if (values[j].type !== inputs[j].baseType) {
|
||||
matching.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// We found a single matching signature with an overrides, but the
|
||||
// last value is something that cannot possibly be an options
|
||||
if (matching.length === 1 && values && values.length !== matching[0].inputs.length) {
|
||||
const lastArg = values[values.length - 1];
|
||||
if (lastArg == null || Array.isArray(lastArg) || typeof (lastArg) !== "object") {
|
||||
matching.splice(0, 1);
|
||||
}
|
||||
}
|
||||
if (matching.length === 0) {
|
||||
logger.throwArgumentError("no matching function", "name", key);
|
||||
}
|
||||
else if (matching.length > 1 && forceUnique) {
|
||||
const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", ");
|
||||
logger.throwArgumentError(`multiple matching functions (i.e. ${matchStr})`, "name", key);
|
||||
}
|
||||
return matching[0];
|
||||
}
|
||||
// Normalize the signature and lookup the function
|
||||
const result = __classPrivateFieldGet(this, _Interface_functions, "f").get(FunctionFragment.fromString(key).format());
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
return logger.throwArgumentError("no matching function", "signature", key);
|
||||
}, _Interface_getEvent = function _Interface_getEvent(key, values, forceUnique) {
|
||||
// EventTopic
|
||||
if (isHexString(key)) {
|
||||
const eventTopic = key.toLowerCase();
|
||||
for (const fragment of __classPrivateFieldGet(this, _Interface_events, "f").values()) {
|
||||
if (eventTopic === this.getEventTopic(fragment)) {
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
logger.throwArgumentError("no matching event", "eventTopic", key);
|
||||
}
|
||||
// It is a bare name, look up the function (will return null if ambiguous)
|
||||
if (key.indexOf("(") === -1) {
|
||||
const matching = [];
|
||||
for (const [name, fragment] of __classPrivateFieldGet(this, _Interface_events, "f")) {
|
||||
if (name.split("(" /* fix:) */)[0] === key) {
|
||||
matching.push(fragment);
|
||||
}
|
||||
}
|
||||
if (values) {
|
||||
// Remove all matches that don't have a compatible length.
|
||||
for (let i = matching.length - 1; i >= 0; i--) {
|
||||
if (matching[i].inputs.length < values.length) {
|
||||
matching.splice(i, 1);
|
||||
}
|
||||
}
|
||||
// Remove all matches that don't match the Typed signature
|
||||
for (let i = matching.length - 1; i >= 0; i--) {
|
||||
const inputs = matching[i].inputs;
|
||||
for (let j = 0; j < values.length; j++) {
|
||||
// Not a typed value
|
||||
if (!Typed.isTyped(values[j])) {
|
||||
continue;
|
||||
}
|
||||
// Make sure the value type matches the input type
|
||||
if (values[j].type !== inputs[j].baseType) {
|
||||
matching.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matching.length === 0) {
|
||||
logger.throwArgumentError("no matching event", "name", key);
|
||||
}
|
||||
else if (matching.length > 1 && forceUnique) {
|
||||
// @TODO: refine by Typed
|
||||
logger.throwArgumentError("multiple matching events", "name", key);
|
||||
}
|
||||
return matching[0];
|
||||
}
|
||||
// Normalize the signature and lookup the function
|
||||
const result = __classPrivateFieldGet(this, _Interface_events, "f").get(EventFragment.fromString(key).format());
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
return logger.throwArgumentError("no matching event", "signature", key);
|
||||
};
|
||||
//# sourceMappingURL=interface.js.map
|
1
packages/abi/lib/interface.js.map
Normal file
1
packages/abi/lib/interface.js.map
Normal file
File diff suppressed because one or more lines are too long
3
packages/abi/lib/logger.d.ts
vendored
Normal file
3
packages/abi/lib/logger.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
export declare const logger: Logger;
|
||||
//# sourceMappingURL=logger.d.ts.map
|
1
packages/abi/lib/logger.d.ts.map
Normal file
1
packages/abi/lib/logger.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src.ts/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,eAAO,MAAM,MAAM,QAAsB,CAAC"}
|
4
packages/abi/lib/logger.js
Normal file
4
packages/abi/lib/logger.js
Normal file
@ -0,0 +1,4 @@
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "./_version.js";
|
||||
export const logger = new Logger(version);
|
||||
//# sourceMappingURL=logger.js.map
|
1
packages/abi/lib/logger.js.map
Normal file
1
packages/abi/lib/logger.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src.ts/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC"}
|
144
packages/abi/lib/typed.d.ts
vendored
Normal file
144
packages/abi/lib/typed.d.ts
vendored
Normal file
@ -0,0 +1,144 @@
|
||||
import type { Addressable } from "@ethersproject/address";
|
||||
import type { BigNumberish, BytesLike } from "@ethersproject/logger";
|
||||
import type { Result } from "./coders/abstract-coder.js";
|
||||
export interface TypedNumber extends Typed {
|
||||
defaultValue(): number;
|
||||
minValue(): number;
|
||||
maxValue(): number;
|
||||
}
|
||||
export interface TypedBigInt extends Typed {
|
||||
defaultValue(): bigint;
|
||||
minValue(): bigint;
|
||||
maxValue(): bigint;
|
||||
}
|
||||
export interface TypedData extends Typed {
|
||||
defaultValue(): string;
|
||||
}
|
||||
export interface TypedString extends Typed {
|
||||
defaultValue(): string;
|
||||
}
|
||||
export declare class Typed {
|
||||
#private;
|
||||
readonly type: string;
|
||||
readonly value: any;
|
||||
readonly _typedSymbol: Symbol;
|
||||
constructor(gaurd: any, type: string, value: any, options?: any);
|
||||
format(): string;
|
||||
defaultValue(): string | number | bigint | Result;
|
||||
minValue(): string | number | bigint;
|
||||
maxValue(): string | number | bigint;
|
||||
isBigInt(): this is TypedBigInt;
|
||||
isData(): this is TypedData;
|
||||
isString(): this is TypedString;
|
||||
get tupleName(): null | string;
|
||||
get arrayLength(): null | number;
|
||||
static from(type: string, value: any): Typed;
|
||||
static uint8(v: BigNumberish): Typed;
|
||||
static uint16(v: BigNumberish): Typed;
|
||||
static uint24(v: BigNumberish): Typed;
|
||||
static uint32(v: BigNumberish): Typed;
|
||||
static uint40(v: BigNumberish): Typed;
|
||||
static uint48(v: BigNumberish): Typed;
|
||||
static uint56(v: BigNumberish): Typed;
|
||||
static uint64(v: BigNumberish): Typed;
|
||||
static uint72(v: BigNumberish): Typed;
|
||||
static uint80(v: BigNumberish): Typed;
|
||||
static uint88(v: BigNumberish): Typed;
|
||||
static uint96(v: BigNumberish): Typed;
|
||||
static uint104(v: BigNumberish): Typed;
|
||||
static uint112(v: BigNumberish): Typed;
|
||||
static uint120(v: BigNumberish): Typed;
|
||||
static uint128(v: BigNumberish): Typed;
|
||||
static uint136(v: BigNumberish): Typed;
|
||||
static uint144(v: BigNumberish): Typed;
|
||||
static uint152(v: BigNumberish): Typed;
|
||||
static uint160(v: BigNumberish): Typed;
|
||||
static uint168(v: BigNumberish): Typed;
|
||||
static uint176(v: BigNumberish): Typed;
|
||||
static uint184(v: BigNumberish): Typed;
|
||||
static uint192(v: BigNumberish): Typed;
|
||||
static uint200(v: BigNumberish): Typed;
|
||||
static uint208(v: BigNumberish): Typed;
|
||||
static uint216(v: BigNumberish): Typed;
|
||||
static uint224(v: BigNumberish): Typed;
|
||||
static uint232(v: BigNumberish): Typed;
|
||||
static uint240(v: BigNumberish): Typed;
|
||||
static uint248(v: BigNumberish): Typed;
|
||||
static uint256(v: BigNumberish): Typed;
|
||||
static uint(v: BigNumberish): Typed;
|
||||
static int8(v: BigNumberish): Typed;
|
||||
static int16(v: BigNumberish): Typed;
|
||||
static int24(v: BigNumberish): Typed;
|
||||
static int32(v: BigNumberish): Typed;
|
||||
static int40(v: BigNumberish): Typed;
|
||||
static int48(v: BigNumberish): Typed;
|
||||
static int56(v: BigNumberish): Typed;
|
||||
static int64(v: BigNumberish): Typed;
|
||||
static int72(v: BigNumberish): Typed;
|
||||
static int80(v: BigNumberish): Typed;
|
||||
static int88(v: BigNumberish): Typed;
|
||||
static int96(v: BigNumberish): Typed;
|
||||
static int104(v: BigNumberish): Typed;
|
||||
static int112(v: BigNumberish): Typed;
|
||||
static int120(v: BigNumberish): Typed;
|
||||
static int128(v: BigNumberish): Typed;
|
||||
static int136(v: BigNumberish): Typed;
|
||||
static int144(v: BigNumberish): Typed;
|
||||
static int152(v: BigNumberish): Typed;
|
||||
static int160(v: BigNumberish): Typed;
|
||||
static int168(v: BigNumberish): Typed;
|
||||
static int176(v: BigNumberish): Typed;
|
||||
static int184(v: BigNumberish): Typed;
|
||||
static int192(v: BigNumberish): Typed;
|
||||
static int200(v: BigNumberish): Typed;
|
||||
static int208(v: BigNumberish): Typed;
|
||||
static int216(v: BigNumberish): Typed;
|
||||
static int224(v: BigNumberish): Typed;
|
||||
static int232(v: BigNumberish): Typed;
|
||||
static int240(v: BigNumberish): Typed;
|
||||
static int248(v: BigNumberish): Typed;
|
||||
static int256(v: BigNumberish): Typed;
|
||||
static int(v: BigNumberish): Typed;
|
||||
static bytes(v: BytesLike): Typed;
|
||||
static bytes1(v: BytesLike): Typed;
|
||||
static bytes2(v: BytesLike): Typed;
|
||||
static bytes3(v: BytesLike): Typed;
|
||||
static bytes4(v: BytesLike): Typed;
|
||||
static bytes5(v: BytesLike): Typed;
|
||||
static bytes6(v: BytesLike): Typed;
|
||||
static bytes7(v: BytesLike): Typed;
|
||||
static bytes8(v: BytesLike): Typed;
|
||||
static bytes9(v: BytesLike): Typed;
|
||||
static bytes10(v: BytesLike): Typed;
|
||||
static bytes11(v: BytesLike): Typed;
|
||||
static bytes12(v: BytesLike): Typed;
|
||||
static bytes13(v: BytesLike): Typed;
|
||||
static bytes14(v: BytesLike): Typed;
|
||||
static bytes15(v: BytesLike): Typed;
|
||||
static bytes16(v: BytesLike): Typed;
|
||||
static bytes17(v: BytesLike): Typed;
|
||||
static bytes18(v: BytesLike): Typed;
|
||||
static bytes19(v: BytesLike): Typed;
|
||||
static bytes20(v: BytesLike): Typed;
|
||||
static bytes21(v: BytesLike): Typed;
|
||||
static bytes22(v: BytesLike): Typed;
|
||||
static bytes23(v: BytesLike): Typed;
|
||||
static bytes24(v: BytesLike): Typed;
|
||||
static bytes25(v: BytesLike): Typed;
|
||||
static bytes26(v: BytesLike): Typed;
|
||||
static bytes27(v: BytesLike): Typed;
|
||||
static bytes28(v: BytesLike): Typed;
|
||||
static bytes29(v: BytesLike): Typed;
|
||||
static bytes30(v: BytesLike): Typed;
|
||||
static bytes31(v: BytesLike): Typed;
|
||||
static bytes32(v: BytesLike): Typed;
|
||||
static address(v: string | Addressable): Typed;
|
||||
static bool(v: any): Typed;
|
||||
static string(v: string): Typed;
|
||||
static array(v: Array<any | Typed>, dynamic?: null | boolean): Typed;
|
||||
static tuple(v: Array<any | Typed> | Record<string, any | Typed>, name?: string): Typed;
|
||||
static overrides(v: Record<string, any>): Typed;
|
||||
static isTyped(value: any): value is Typed;
|
||||
static dereference<T>(value: Typed | T, type: string): T;
|
||||
}
|
||||
//# sourceMappingURL=typed.d.ts.map
|
1
packages/abi/lib/typed.d.ts.map
Normal file
1
packages/abi/lib/typed.d.ts.map
Normal file
File diff suppressed because one or more lines are too long
222
packages/abi/lib/typed.js
Normal file
222
packages/abi/lib/typed.js
Normal file
@ -0,0 +1,222 @@
|
||||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
};
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var _Typed_options;
|
||||
import { defineProperties } from "@ethersproject/properties";
|
||||
const _gaurd = {};
|
||||
function n(value, width) {
|
||||
let signed = false;
|
||||
if (width < 0) {
|
||||
signed = true;
|
||||
width *= -1;
|
||||
}
|
||||
// @TODO: Check range is valid for value
|
||||
return new Typed(_gaurd, `${signed ? "" : "u"}int${width}`, value, { signed, width });
|
||||
}
|
||||
function b(value, size) {
|
||||
// @TODO: Check range is valid for value
|
||||
return new Typed(_gaurd, `bytes${(size) ? size : ""}`, value, { size });
|
||||
}
|
||||
const _typedSymbol = Symbol.for("_ethers_typed");
|
||||
export class Typed {
|
||||
constructor(gaurd, type, value, options = null) {
|
||||
_Typed_options.set(this, void 0);
|
||||
if (gaurd !== _gaurd) {
|
||||
throw new Error("private constructor");
|
||||
}
|
||||
defineProperties(this, { _typedSymbol, type, value });
|
||||
__classPrivateFieldSet(this, _Typed_options, options, "f");
|
||||
// Check the value is valid
|
||||
this.format();
|
||||
}
|
||||
format() {
|
||||
if (this.type === "array") {
|
||||
throw new Error("");
|
||||
}
|
||||
else if (this.type === "dynamicArray") {
|
||||
throw new Error("");
|
||||
}
|
||||
else if (this.type === "tuple") {
|
||||
return `tuple(${this.value.map((v) => v.format()).join(",")})`;
|
||||
}
|
||||
return this.type;
|
||||
}
|
||||
defaultValue() {
|
||||
return 0;
|
||||
}
|
||||
minValue() {
|
||||
return 0;
|
||||
}
|
||||
maxValue() {
|
||||
return 0;
|
||||
}
|
||||
isBigInt() {
|
||||
return !!(this.type.match(/^u?int[0-9]+$/));
|
||||
}
|
||||
isData() {
|
||||
return (this.type.substring(0, 5) === "bytes");
|
||||
}
|
||||
isString() {
|
||||
return (this.type === "string");
|
||||
}
|
||||
get tupleName() {
|
||||
if (this.type !== "tuple") {
|
||||
throw TypeError("not a tuple");
|
||||
}
|
||||
return __classPrivateFieldGet(this, _Typed_options, "f");
|
||||
}
|
||||
// Returns the length of this type as an array
|
||||
// - `null` indicates the length is unforced, it could be dynamic
|
||||
// - `-1` indicates the length is dynamic
|
||||
// - any other value indicates it is a static array and is its length
|
||||
get arrayLength() {
|
||||
if (this.type !== "array") {
|
||||
throw TypeError("not an array");
|
||||
}
|
||||
if (__classPrivateFieldGet(this, _Typed_options, "f") === true) {
|
||||
return -1;
|
||||
}
|
||||
if (__classPrivateFieldGet(this, _Typed_options, "f") === false) {
|
||||
return (this.value).length;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
static from(type, value) {
|
||||
return new Typed(_gaurd, type, value);
|
||||
}
|
||||
static uint8(v) { return n(v, 8); }
|
||||
static uint16(v) { return n(v, 16); }
|
||||
static uint24(v) { return n(v, 24); }
|
||||
static uint32(v) { return n(v, 32); }
|
||||
static uint40(v) { return n(v, 40); }
|
||||
static uint48(v) { return n(v, 46); }
|
||||
static uint56(v) { return n(v, 56); }
|
||||
static uint64(v) { return n(v, 64); }
|
||||
static uint72(v) { return n(v, 72); }
|
||||
static uint80(v) { return n(v, 80); }
|
||||
static uint88(v) { return n(v, 88); }
|
||||
static uint96(v) { return n(v, 96); }
|
||||
static uint104(v) { return n(v, 104); }
|
||||
static uint112(v) { return n(v, 112); }
|
||||
static uint120(v) { return n(v, 120); }
|
||||
static uint128(v) { return n(v, 128); }
|
||||
static uint136(v) { return n(v, 136); }
|
||||
static uint144(v) { return n(v, 144); }
|
||||
static uint152(v) { return n(v, 152); }
|
||||
static uint160(v) { return n(v, 160); }
|
||||
static uint168(v) { return n(v, 168); }
|
||||
static uint176(v) { return n(v, 176); }
|
||||
static uint184(v) { return n(v, 184); }
|
||||
static uint192(v) { return n(v, 192); }
|
||||
static uint200(v) { return n(v, 200); }
|
||||
static uint208(v) { return n(v, 208); }
|
||||
static uint216(v) { return n(v, 216); }
|
||||
static uint224(v) { return n(v, 224); }
|
||||
static uint232(v) { return n(v, 232); }
|
||||
static uint240(v) { return n(v, 240); }
|
||||
static uint248(v) { return n(v, 248); }
|
||||
static uint256(v) { return n(v, 256); }
|
||||
static uint(v) { return n(v, 256); }
|
||||
static int8(v) { return n(v, -8); }
|
||||
static int16(v) { return n(v, -16); }
|
||||
static int24(v) { return n(v, -24); }
|
||||
static int32(v) { return n(v, -32); }
|
||||
static int40(v) { return n(v, -40); }
|
||||
static int48(v) { return n(v, -46); }
|
||||
static int56(v) { return n(v, -56); }
|
||||
static int64(v) { return n(v, -64); }
|
||||
static int72(v) { return n(v, -72); }
|
||||
static int80(v) { return n(v, -80); }
|
||||
static int88(v) { return n(v, -88); }
|
||||
static int96(v) { return n(v, -96); }
|
||||
static int104(v) { return n(v, -104); }
|
||||
static int112(v) { return n(v, -112); }
|
||||
static int120(v) { return n(v, -120); }
|
||||
static int128(v) { return n(v, -128); }
|
||||
static int136(v) { return n(v, -136); }
|
||||
static int144(v) { return n(v, -144); }
|
||||
static int152(v) { return n(v, -152); }
|
||||
static int160(v) { return n(v, -160); }
|
||||
static int168(v) { return n(v, -168); }
|
||||
static int176(v) { return n(v, -176); }
|
||||
static int184(v) { return n(v, -184); }
|
||||
static int192(v) { return n(v, -192); }
|
||||
static int200(v) { return n(v, -200); }
|
||||
static int208(v) { return n(v, -208); }
|
||||
static int216(v) { return n(v, -216); }
|
||||
static int224(v) { return n(v, -224); }
|
||||
static int232(v) { return n(v, -232); }
|
||||
static int240(v) { return n(v, -240); }
|
||||
static int248(v) { return n(v, -248); }
|
||||
static int256(v) { return n(v, -256); }
|
||||
static int(v) { return n(v, -256); }
|
||||
static bytes(v) { return b(v); }
|
||||
static bytes1(v) { return b(v, 1); }
|
||||
static bytes2(v) { return b(v, 2); }
|
||||
static bytes3(v) { return b(v, 3); }
|
||||
static bytes4(v) { return b(v, 4); }
|
||||
static bytes5(v) { return b(v, 5); }
|
||||
static bytes6(v) { return b(v, 6); }
|
||||
static bytes7(v) { return b(v, 7); }
|
||||
static bytes8(v) { return b(v, 8); }
|
||||
static bytes9(v) { return b(v, 9); }
|
||||
static bytes10(v) { return b(v, 10); }
|
||||
static bytes11(v) { return b(v, 11); }
|
||||
static bytes12(v) { return b(v, 12); }
|
||||
static bytes13(v) { return b(v, 13); }
|
||||
static bytes14(v) { return b(v, 14); }
|
||||
static bytes15(v) { return b(v, 15); }
|
||||
static bytes16(v) { return b(v, 16); }
|
||||
static bytes17(v) { return b(v, 17); }
|
||||
static bytes18(v) { return b(v, 18); }
|
||||
static bytes19(v) { return b(v, 19); }
|
||||
static bytes20(v) { return b(v, 20); }
|
||||
static bytes21(v) { return b(v, 21); }
|
||||
static bytes22(v) { return b(v, 22); }
|
||||
static bytes23(v) { return b(v, 23); }
|
||||
static bytes24(v) { return b(v, 24); }
|
||||
static bytes25(v) { return b(v, 25); }
|
||||
static bytes26(v) { return b(v, 26); }
|
||||
static bytes27(v) { return b(v, 27); }
|
||||
static bytes28(v) { return b(v, 28); }
|
||||
static bytes29(v) { return b(v, 29); }
|
||||
static bytes30(v) { return b(v, 30); }
|
||||
static bytes31(v) { return b(v, 31); }
|
||||
static bytes32(v) { return b(v, 32); }
|
||||
static address(v) { return new Typed(_gaurd, "address", v); }
|
||||
static bool(v) { return new Typed(_gaurd, "bool", !!v); }
|
||||
static string(v) { return new Typed(_gaurd, "string", v); }
|
||||
static array(v, dynamic) {
|
||||
throw new Error("not implemented yet");
|
||||
return new Typed(_gaurd, "array", v, dynamic);
|
||||
}
|
||||
static tuple(v, name) {
|
||||
throw new Error("not implemented yet");
|
||||
return new Typed(_gaurd, "tuple", v, name);
|
||||
}
|
||||
static overrides(v) {
|
||||
return new Typed(_gaurd, "overrides", Object.assign({}, v));
|
||||
}
|
||||
static isTyped(value) {
|
||||
return (value && value._typedSymbol === _typedSymbol);
|
||||
}
|
||||
static dereference(value, type) {
|
||||
if (Typed.isTyped(value)) {
|
||||
if (value.type !== type) {
|
||||
throw new Error(`invalid type: expecetd ${type}, got ${value.type}`);
|
||||
}
|
||||
return value.value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
_Typed_options = new WeakMap();
|
||||
//# sourceMappingURL=typed.js.map
|
1
packages/abi/lib/typed.js.map
Normal file
1
packages/abi/lib/typed.js.map
Normal file
File diff suppressed because one or more lines are too long
2
packages/address/lib/_version.d.ts
vendored
Normal file
2
packages/address/lib/_version.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export declare const version = "@ethersproject/address@6.0.0-beta.1";
|
||||
//# sourceMappingURL=_version.d.ts.map
|
1
packages/address/lib/_version.d.ts.map
Normal file
1
packages/address/lib/_version.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"_version.d.ts","sourceRoot":"","sources":["../src.ts/_version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,wCAAwC,CAAC"}
|
2
packages/address/lib/_version.js
Normal file
2
packages/address/lib/_version.js
Normal file
@ -0,0 +1,2 @@
|
||||
export const version = "@ethersproject/address@6.0.0-beta.1";
|
||||
//# sourceMappingURL=_version.js.map
|
1
packages/address/lib/_version.js.map
Normal file
1
packages/address/lib/_version.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"_version.js","sourceRoot":"","sources":["../src.ts/_version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,qCAAqC,CAAC"}
|
3
packages/address/lib/address.d.ts
vendored
Normal file
3
packages/address/lib/address.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export declare function getAddress(address: string): string;
|
||||
export declare function getIcapAddress(address: string): string;
|
||||
//# sourceMappingURL=address.d.ts.map
|
1
packages/address/lib/address.d.ts.map
Normal file
1
packages/address/lib/address.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src.ts/address.ts"],"names":[],"mappings":"AAsFA,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAkClD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAKtD"}
|
110
packages/address/lib/address.js
Normal file
110
packages/address/lib/address.js
Normal file
@ -0,0 +1,110 @@
|
||||
import { arrayify } from "@ethersproject/bytes";
|
||||
import { keccak256 } from "@ethersproject/crypto";
|
||||
import { logger } from "./logger.js";
|
||||
const BN_0 = BigInt(0);
|
||||
const BN_36 = BigInt(36);
|
||||
function getChecksumAddress(address) {
|
||||
// if (!isHexString(address, 20)) {
|
||||
// logger.throwArgumentError("invalid address", "address", address);
|
||||
// }
|
||||
address = address.toLowerCase();
|
||||
const chars = address.substring(2).split("");
|
||||
const expanded = new Uint8Array(40);
|
||||
for (let i = 0; i < 40; i++) {
|
||||
expanded[i] = chars[i].charCodeAt(0);
|
||||
}
|
||||
const hashed = arrayify(keccak256(expanded));
|
||||
for (let i = 0; i < 40; i += 2) {
|
||||
if ((hashed[i >> 1] >> 4) >= 8) {
|
||||
chars[i] = chars[i].toUpperCase();
|
||||
}
|
||||
if ((hashed[i >> 1] & 0x0f) >= 8) {
|
||||
chars[i + 1] = chars[i + 1].toUpperCase();
|
||||
}
|
||||
}
|
||||
return "0x" + chars.join("");
|
||||
}
|
||||
// See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
|
||||
// Create lookup table
|
||||
const ibanLookup = {};
|
||||
for (let i = 0; i < 10; i++) {
|
||||
ibanLookup[String(i)] = String(i);
|
||||
}
|
||||
for (let i = 0; i < 26; i++) {
|
||||
ibanLookup[String.fromCharCode(65 + i)] = String(10 + i);
|
||||
}
|
||||
// How many decimal digits can we process? (for 64-bit float, this is 15)
|
||||
// i.e. Math.floor(Math.log10(Number.MAX_SAFE_INTEGER));
|
||||
const safeDigits = 15;
|
||||
function ibanChecksum(address) {
|
||||
address = address.toUpperCase();
|
||||
address = address.substring(4) + address.substring(0, 2) + "00";
|
||||
let expanded = address.split("").map((c) => { return ibanLookup[c]; }).join("");
|
||||
// Javascript can handle integers safely up to 15 (decimal) digits
|
||||
while (expanded.length >= safeDigits) {
|
||||
let block = expanded.substring(0, safeDigits);
|
||||
expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
|
||||
}
|
||||
let checksum = String(98 - (parseInt(expanded, 10) % 97));
|
||||
while (checksum.length < 2) {
|
||||
checksum = "0" + checksum;
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
;
|
||||
const Base36 = (function () {
|
||||
;
|
||||
const result = {};
|
||||
for (let i = 0; i < 36; i++) {
|
||||
const key = "0123456789abcdefghijklmnopqrstuvwxyz"[i];
|
||||
result[key] = BigInt(i);
|
||||
}
|
||||
return result;
|
||||
})();
|
||||
function fromBase36(value) {
|
||||
value = value.toLowerCase();
|
||||
let result = BN_0;
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
result = result * BN_36 + Base36[value[i]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export function getAddress(address) {
|
||||
if (typeof (address) !== "string") {
|
||||
logger.throwArgumentError("invalid address", "address", address);
|
||||
}
|
||||
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
|
||||
// Missing the 0x prefix
|
||||
if (address.substring(0, 2) !== "0x") {
|
||||
address = "0x" + address;
|
||||
}
|
||||
const result = getChecksumAddress(address);
|
||||
// It is a checksummed address with a bad checksum
|
||||
if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) {
|
||||
logger.throwArgumentError("bad address checksum", "address", address);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Maybe ICAP? (we only support direct mode)
|
||||
if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
|
||||
// It is an ICAP address with a bad checksum
|
||||
if (address.substring(2, 4) !== ibanChecksum(address)) {
|
||||
logger.throwArgumentError("bad icap checksum", "address", address);
|
||||
}
|
||||
let result = fromBase36(address.substring(4)).toString(16);
|
||||
while (result.length < 40) {
|
||||
result = "0" + result;
|
||||
}
|
||||
return getChecksumAddress("0x" + result);
|
||||
}
|
||||
return logger.throwArgumentError("invalid address", "address", address);
|
||||
}
|
||||
export function getIcapAddress(address) {
|
||||
//let base36 = _base16To36(getAddress(address).substring(2)).toUpperCase();
|
||||
let base36 = BigInt(getAddress(address)).toString(36).toUpperCase();
|
||||
while (base36.length < 30) {
|
||||
base36 = "0" + base36;
|
||||
}
|
||||
return "XE" + ibanChecksum("XE00" + base36) + base36;
|
||||
}
|
||||
//# sourceMappingURL=address.js.map
|
1
packages/address/lib/address.js.map
Normal file
1
packages/address/lib/address.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"address.js","sourceRoot":"","sources":["../src.ts/address.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACvB,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AAEzB,SAAS,kBAAkB,CAAC,OAAe;IAC3C,sCAAsC;IACtC,2EAA2E;IAC3E,OAAO;IAEH,OAAO,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAEhC,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kBAAkB,CAAC,sBAAsB,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;SACzE;QAED,OAAO,MAAM,CAAC;KACjB;IAED,4CAA4C;IAC5C,IAAI,OAAO,CAAC,KAAK,CAAC,gCAAgC,CAAC,EAAE;QACjD,4CAA4C;QAC5C,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,YAAY,CAAC,OAAO,CAAC,EAAE;YACnD,MAAM,CAAC,kBAAkB,CAAC,mBAAmB,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;SACtE;QAED,IAAI,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC3D,OAAO,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE;YAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC;SAAE;QACrD,OAAQ,kBAAkB,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC;KAC7C;IAED,OAAO,MAAM,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAe;IAC1C,2EAA2E;IAC3E,IAAI,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACpE,OAAO,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE;QAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC;KAAE;IACrD,OAAO,IAAI,GAAG,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;AACzD,CAAC"}
|
5
packages/address/lib/checks.d.ts
vendored
Normal file
5
packages/address/lib/checks.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import type { Addressable, NameResolver } from "./types.js";
|
||||
export declare function isAddressable(value: any): value is Addressable;
|
||||
export declare function isAddress(value: any): boolean;
|
||||
export declare function resolveAddress(target: string | Addressable, resolver?: null | NameResolver): Promise<string>;
|
||||
//# sourceMappingURL=checks.d.ts.map
|
1
packages/address/lib/checks.d.ts.map
Normal file
1
packages/address/lib/checks.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"checks.d.ts","sourceRoot":"","sources":["../src.ts/checks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE5D,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,WAAW,CAE9D;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAM7C;AAOD,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,YAAY,mBA2BhG"}
|
45
packages/address/lib/checks.js
Normal file
45
packages/address/lib/checks.js
Normal file
@ -0,0 +1,45 @@
|
||||
import { getAddress } from "./address.js";
|
||||
import { logger } from "./logger.js";
|
||||
export function isAddressable(value) {
|
||||
return (value && typeof (value.getAddress) === "function");
|
||||
}
|
||||
export function isAddress(value) {
|
||||
try {
|
||||
getAddress(value);
|
||||
return true;
|
||||
}
|
||||
catch (error) { }
|
||||
return false;
|
||||
}
|
||||
// Resolves an Ethereum address, ENS name or Addressable object,
|
||||
// throwing if the result is null; an explicit null returns null
|
||||
//export async function resolveAddress(target?: null, resolver?: null | NameResolver): Promise<null>;
|
||||
//export async function resolveAddress(target: string | Addressable, resolver?: null | NameResolver): Promise<string>;
|
||||
//export async function resolveAddress(target: null | undefined | string | Addressable, resolver?: null | NameResolver) {
|
||||
export async function resolveAddress(target, resolver) {
|
||||
//if (target == null) { return null; }
|
||||
if (typeof (target) === "string") {
|
||||
if (target.match(/^0x[0-9a-f]{40}$/i)) {
|
||||
return getAddress(target);
|
||||
}
|
||||
if (resolver == null) {
|
||||
return logger.throwError("ENS resolution requires a provider", "UNSUPPORTED_OPERATION", {
|
||||
operation: "resolveName",
|
||||
});
|
||||
}
|
||||
const result = await resolver.resolveName(target);
|
||||
if (result == null || result === "0x0000000000000000000000000000000000000000") {
|
||||
return logger.throwError("unconfigured name", "UNCONFIGURED_NAME", { value: target });
|
||||
}
|
||||
return getAddress(result);
|
||||
}
|
||||
else if (isAddressable(target)) {
|
||||
const result = await target.getAddress();
|
||||
if (result == null) {
|
||||
logger.throwArgumentError("addressable resolved to null", "target", target);
|
||||
}
|
||||
return getAddress(result);
|
||||
}
|
||||
return logger.throwArgumentError("unsupported addressable value", "target", target);
|
||||
}
|
||||
//# sourceMappingURL=checks.js.map
|
1
packages/address/lib/checks.js.map
Normal file
1
packages/address/lib/checks.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"checks.js","sourceRoot":"","sources":["../src.ts/checks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,MAAM,UAAU,aAAa,CAAC,KAAU;IACpC,OAAO,CAAC,KAAK,IAAI,OAAM,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,UAAU,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAU;IAChC,IAAI;QACA,UAAU,CAAC,KAAK,CAAC,CAAC;QAClB,OAAO,IAAI,CAAC;KACf;IAAC,OAAO,KAAK,EAAE,GAAG;IACnB,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,gEAAgE;AAChE,gEAAgE;AAChE,qGAAqG;AACrG,sHAAsH;AACtH,yHAAyH;AACzH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAA4B,EAAE,QAA8B;IAC7F,sCAAsC;IAEtC,IAAI,OAAM,CAAC,MAAM,CAAC,KAAK,QAAQ,EAAE;QAC7B,IAAI,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE;YAAE,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;SAAE;QAErE,IAAI,QAAQ,IAAI,IAAI,EAAE;YAClB,OAAO,MAAM,CAAC,UAAU,CAAC,oCAAoC,EAAE,uBAAuB,EAAE;gBACpF,SAAS,EAAE,aAAa;aAC3B,CAAC,CAAC;SACN;QAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAClD,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,KAAK,4CAA4C,EAAE;YAC3E,OAAO,MAAM,CAAC,UAAU,CAAC,mBAAmB,EAAE,mBAAmB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;SACzF;QACD,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;KAE7B;SAAM,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE;QAC9B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;QACzC,IAAI,MAAM,IAAI,IAAI,EAAE;YAChB,MAAM,CAAC,kBAAkB,CAAC,8BAA8B,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;SAC/E;QACD,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;KAC7B;IAED,OAAO,MAAM,CAAC,kBAAkB,CAAC,+BAA+B,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AACxF,CAAC"}
|
7
packages/address/lib/contract-address.d.ts
vendored
Normal file
7
packages/address/lib/contract-address.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import type { BigNumberish, BytesLike } from "@ethersproject/logger";
|
||||
export declare function getCreateAddress(tx: {
|
||||
from: string;
|
||||
nonce: BigNumberish;
|
||||
}): string;
|
||||
export declare function getCreate2Address(_from: string, _salt: BytesLike, _initCodeHash: BytesLike): string;
|
||||
//# sourceMappingURL=contract-address.d.ts.map
|
1
packages/address/lib/contract-address.d.ts.map
Normal file
1
packages/address/lib/contract-address.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"contract-address.d.ts","sourceRoot":"","sources":["../src.ts/contract-address.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAOrE,wBAAgB,gBAAgB,CAAC,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,GAAG,MAAM,CAclF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,GAAG,MAAM,CAcnG"}
|
34
packages/address/lib/contract-address.js
Normal file
34
packages/address/lib/contract-address.js
Normal file
@ -0,0 +1,34 @@
|
||||
import { concat, dataSlice } from "@ethersproject/bytes";
|
||||
import { keccak256 } from "@ethersproject/crypto";
|
||||
import { encodeRlp } from "@ethersproject/rlp";
|
||||
import { getAddress } from "./address.js";
|
||||
import { logger } from "./logger.js";
|
||||
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
|
||||
export function getCreateAddress(tx) {
|
||||
const from = getAddress(tx.from);
|
||||
const nonce = logger.getBigInt(tx.nonce, "tx.nonce");
|
||||
let nonceHex = nonce.toString(16);
|
||||
if (nonceHex === "0") {
|
||||
nonceHex = "0x";
|
||||
}
|
||||
else if (nonceHex.length % 2) {
|
||||
nonceHex = "0x0" + nonceHex;
|
||||
}
|
||||
else {
|
||||
nonceHex = "0x" + nonceHex;
|
||||
}
|
||||
return getAddress(dataSlice(keccak256(encodeRlp([from, nonceHex])), 12));
|
||||
}
|
||||
export function getCreate2Address(_from, _salt, _initCodeHash) {
|
||||
const from = getAddress(_from);
|
||||
const salt = logger.getBytes(_salt, "salt");
|
||||
const initCodeHash = logger.getBytes(_initCodeHash, "initCodeHash");
|
||||
if (salt.length !== 32) {
|
||||
logger.throwArgumentError("salt must be 32 bytes", "salt", _salt);
|
||||
}
|
||||
if (initCodeHash.length !== 32) {
|
||||
logger.throwArgumentError("initCodeHash must be 32 bytes", "initCodeHash", _initCodeHash);
|
||||
}
|
||||
return getAddress(dataSlice(keccak256(concat(["0xff", from, salt, initCodeHash])), 12));
|
||||
}
|
||||
//# sourceMappingURL=contract-address.js.map
|
1
packages/address/lib/contract-address.js.map
Normal file
1
packages/address/lib/contract-address.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"contract-address.js","sourceRoot":"","sources":["../src.ts/contract-address.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,sGAAsG;AACtG,MAAM,UAAU,gBAAgB,CAAC,EAAyC;IACtE,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAErD,IAAI,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAClC,IAAI,QAAQ,KAAK,GAAG,EAAE;QAClB,QAAQ,GAAG,IAAI,CAAC;KACnB;SAAM,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;QAC5B,QAAQ,GAAG,KAAK,GAAG,QAAQ,CAAC;KAC/B;SAAM;QACH,QAAQ,GAAG,IAAI,GAAG,QAAQ,CAAC;KAC9B;IAED,OAAO,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,CAAE,IAAI,EAAE,QAAQ,CAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAa,EAAE,KAAgB,EAAE,aAAwB;IACvF,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC5C,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IAEpE,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,EAAE;QACpB,MAAM,CAAC,kBAAkB,CAAC,uBAAuB,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;KACrE;IAED,IAAI,YAAY,CAAC,MAAM,KAAK,EAAE,EAAE;QAC5B,MAAM,CAAC,kBAAkB,CAAC,+BAA+B,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;KAC7F;IAED,OAAO,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,CAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAC7F,CAAC"}
|
5
packages/address/lib/index.d.ts
vendored
Normal file
5
packages/address/lib/index.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
export { getAddress, getIcapAddress } from "./address.js";
|
||||
export { getCreateAddress, getCreate2Address } from "./contract-address.js";
|
||||
export { isAddressable, isAddress, resolveAddress } from "./checks.js";
|
||||
export type { Addressable, NameResolver } from "./types.js";
|
||||
//# sourceMappingURL=index.d.ts.map
|
1
packages/address/lib/index.d.ts.map
Normal file
1
packages/address/lib/index.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEvE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA"}
|
4
packages/address/lib/index.js
Normal file
4
packages/address/lib/index.js
Normal file
@ -0,0 +1,4 @@
|
||||
export { getAddress, getIcapAddress } from "./address.js";
|
||||
export { getCreateAddress, getCreate2Address } from "./contract-address.js";
|
||||
export { isAddressable, isAddress, resolveAddress } from "./checks.js";
|
||||
//# sourceMappingURL=index.js.map
|
1
packages/address/lib/index.js.map
Normal file
1
packages/address/lib/index.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
3
packages/address/lib/logger.d.ts
vendored
Normal file
3
packages/address/lib/logger.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
export declare const logger: Logger;
|
||||
//# sourceMappingURL=logger.d.ts.map
|
1
packages/address/lib/logger.d.ts.map
Normal file
1
packages/address/lib/logger.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src.ts/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAK/C,eAAO,MAAM,MAAM,QAAsB,CAAC"}
|
4
packages/address/lib/logger.js
Normal file
4
packages/address/lib/logger.js
Normal file
@ -0,0 +1,4 @@
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "./_version.js";
|
||||
export const logger = new Logger(version);
|
||||
//# sourceMappingURL=logger.js.map
|
1
packages/address/lib/logger.js.map
Normal file
1
packages/address/lib/logger.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src.ts/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC"}
|
2
packages/address/lib/tests/test-address.d.ts
vendored
Normal file
2
packages/address/lib/tests/test-address.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=test-address.d.ts.map
|
1
packages/address/lib/tests/test-address.d.ts.map
Normal file
1
packages/address/lib/tests/test-address.d.ts.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-address.d.ts","sourceRoot":"","sources":["../../src.ts/tests/test-address.ts"],"names":[],"mappings":""}
|
110
packages/address/lib/tests/test-address.js
Normal file
110
packages/address/lib/tests/test-address.js
Normal file
@ -0,0 +1,110 @@
|
||||
import assert from "assert";
|
||||
import { loadTests } from "./utils.js";
|
||||
import { getAddress, getIcapAddress, getCreateAddress, getCreate2Address } from "../index.js";
|
||||
describe("computes checksum address", function () {
|
||||
const tests = loadTests("accounts");
|
||||
for (const test of tests) {
|
||||
it(`computes the checksum address for ${test.name}`, function () {
|
||||
assert.equal(getAddress(test.address), test.address);
|
||||
assert.equal(getAddress(test.icap), test.address);
|
||||
assert.equal(getAddress(test.address.substring(2)), test.address);
|
||||
assert.equal(getAddress(test.address.toLowerCase()), test.address);
|
||||
assert.equal(getAddress("0x" + test.address.substring(2).toUpperCase()), test.address);
|
||||
});
|
||||
}
|
||||
const invalidAddresses = [
|
||||
{ name: "null", value: null },
|
||||
{ name: "number", value: 1234 },
|
||||
{ name: "emtpy bytes", value: "0x" },
|
||||
{ name: "too short", value: "0x8ba1f109551bd432803012645ac136ddd64dba" },
|
||||
{ name: "too long", value: "0x8ba1f109551bd432803012645ac136ddd64dba7200" },
|
||||
];
|
||||
invalidAddresses.forEach(({ name, value }) => {
|
||||
it(`fails on invalid address: ${name}`, function () {
|
||||
assert.throws(function () {
|
||||
getAddress(value);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^invalid address/) &&
|
||||
error.argument === "address" &&
|
||||
error.value === value);
|
||||
});
|
||||
});
|
||||
});
|
||||
it("fails on invalid checksum", function () {
|
||||
const value = "0x8ba1f109551bD432803012645Ac136ddd64DBa72";
|
||||
assert.throws(function () {
|
||||
getAddress(value);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^bad address checksum/) &&
|
||||
error.argument === "address" &&
|
||||
error.value === value);
|
||||
});
|
||||
});
|
||||
it("fails on invalid IBAN checksum", function () {
|
||||
const value = "XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK37";
|
||||
assert.throws(function () {
|
||||
getAddress(value);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^bad icap checksum/) &&
|
||||
error.argument === "address" &&
|
||||
error.value === value);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("computes ICAP address", function () {
|
||||
const tests = loadTests("accounts");
|
||||
for (const test of tests) {
|
||||
it(`computes the ICAP address for ${test.name}`, function () {
|
||||
assert.equal(getIcapAddress(test.address), test.icap);
|
||||
assert.equal(getAddress(test.address.toLowerCase()), test.address);
|
||||
assert.equal(getAddress("0x" + test.address.substring(2).toUpperCase()), test.address);
|
||||
});
|
||||
}
|
||||
});
|
||||
describe("computes create address", function () {
|
||||
const tests = loadTests("create");
|
||||
for (const { sender, creates } of tests) {
|
||||
for (const { name, nonce, address } of creates) {
|
||||
it(`computes the create address for ${name}`, function () {
|
||||
assert.equal(getCreateAddress({ from: sender, nonce }), address);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
describe("computes create2 address", function () {
|
||||
const tests = loadTests("create2");
|
||||
for (const { sender, creates } of tests) {
|
||||
for (const { name, salt, initCodeHash, address } of creates) {
|
||||
it(`computes the create2 address for ${name}`, function () {
|
||||
assert.equal(getCreate2Address(sender, salt, initCodeHash), address);
|
||||
});
|
||||
}
|
||||
}
|
||||
const sender = "0x8ba1f109551bD432803012645Ac136ddd64DBA72";
|
||||
const salt = "0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8";
|
||||
const initCodeHash = "0x8452c9b9140222b08593a26daa782707297be9f7b3e8281d7b4974769f19afd0";
|
||||
it("fails on invalid salt", function () {
|
||||
const badSalt = "0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36dea";
|
||||
assert.throws(function () {
|
||||
getCreate2Address(sender, badSalt, initCodeHash);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.argument === "salt" &&
|
||||
error.value === badSalt);
|
||||
});
|
||||
});
|
||||
it("fails on invalid initCodeHash", function () {
|
||||
const badInitCodeHash = "0x8452c9b9140222b08593a26daa782707297be9f7b3e8281d7b4974769f19af";
|
||||
assert.throws(function () {
|
||||
getCreate2Address(sender, salt, badInitCodeHash);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.argument === "initCodeHash" &&
|
||||
error.value === badInitCodeHash);
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=test-address.js.map
|
1
packages/address/lib/tests/test-address.js.map
Normal file
1
packages/address/lib/tests/test-address.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-address.js","sourceRoot":"","sources":["../../src.ts/tests/test-address.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAA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gBACrC,KAAK,CAAC,QAAQ,KAAK,cAAc;gBACjC,KAAK,CAAC,KAAK,KAAK,eAAe,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user