-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major overhaul in compilation to enable ES6 module generation.
- Loading branch information
Showing
686 changed files
with
58,756 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"use strict"; | ||
|
||
const { setupBuild } = require("../build"); | ||
|
||
setupBuild(false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const version = "abi/5.0.0-beta.136"; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
"use strict"; | ||
// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI | ||
import { arrayify } from "@ethersproject/bytes"; | ||
import { defineReadOnly } from "@ethersproject/properties"; | ||
import { Logger } from "@ethersproject/logger"; | ||
import { version } from "./_version"; | ||
const logger = new Logger(version); | ||
import { Reader, Writer } from "./coders/abstract-coder"; | ||
import { AddressCoder } from "./coders/address"; | ||
import { ArrayCoder } from "./coders/array"; | ||
import { BooleanCoder } from "./coders/boolean"; | ||
import { BytesCoder } from "./coders/bytes"; | ||
import { FixedBytesCoder } from "./coders/fixed-bytes"; | ||
import { NullCoder } from "./coders/null"; | ||
import { NumberCoder } from "./coders/number"; | ||
import { StringCoder } from "./coders/string"; | ||
import { TupleCoder } from "./coders/tuple"; | ||
import { ParamType } from "./fragments"; | ||
const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/); | ||
const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/); | ||
export class AbiCoder { | ||
constructor(coerceFunc) { | ||
logger.checkNew(new.target, AbiCoder); | ||
defineReadOnly(this, "coerceFunc", coerceFunc || null); | ||
} | ||
_getCoder(param) { | ||
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 "array": | ||
return new ArrayCoder(this._getCoder(param.arrayChildren), param.arrayLength, param.name); | ||
case "tuple": | ||
return new TupleCoder((param.components || []).map((component) => { | ||
return this._getCoder(component); | ||
}), 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.throwError("invalid type", "type", param.type); | ||
} | ||
_getWordSize() { return 32; } | ||
_getReader(data) { | ||
return new Reader(data, this._getWordSize(), this.coerceFunc); | ||
} | ||
_getWriter() { | ||
return new Writer(this._getWordSize()); | ||
} | ||
encode(types, values) { | ||
if (types.length !== values.length) { | ||
logger.throwError("types/values length mismatch", Logger.errors.INVALID_ARGUMENT, { | ||
count: { types: types.length, values: values.length }, | ||
value: { types: types, values: values } | ||
}); | ||
} | ||
let coders = types.map((type) => this._getCoder(ParamType.from(type))); | ||
let coder = (new TupleCoder(coders, "_")); | ||
let writer = this._getWriter(); | ||
coder.encode(writer, values); | ||
return writer.data; | ||
} | ||
decode(types, data) { | ||
let coders = types.map((type) => this._getCoder(ParamType.from(type))); | ||
let coder = new TupleCoder(coders, "_"); | ||
return coder.decode(this._getReader(arrayify(data))); | ||
} | ||
} | ||
export const defaultAbiCoder = new AbiCoder(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { BytesLike } from "@ethersproject/bytes"; | ||
import { BigNumber, BigNumberish } from "@ethersproject/bignumber"; | ||
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): void; | ||
abstract encode(writer: Writer, value: any): number; | ||
abstract decode(reader: Reader): any; | ||
} | ||
export declare class Writer { | ||
readonly wordSize: number; | ||
_data: Uint8Array; | ||
_padding: Uint8Array; | ||
constructor(wordSize?: number); | ||
readonly data: string; | ||
readonly length: number; | ||
_writeData(data: Uint8Array): number; | ||
writeBytes(value: BytesLike): number; | ||
_getValue(value: BigNumberish): Uint8Array; | ||
writeValue(value: BigNumberish): number; | ||
writeUpdatableValue(): (value: BigNumberish) => void; | ||
} | ||
export declare class Reader { | ||
readonly wordSize: number; | ||
readonly _data: Uint8Array; | ||
readonly _coerceFunc: CoerceFunc; | ||
_offset: number; | ||
constructor(data: BytesLike, wordSize?: number, coerceFunc?: CoerceFunc); | ||
readonly data: string; | ||
readonly consumed: number; | ||
static coerce(name: string, value: any): any; | ||
coerce(name: string, value: any): any; | ||
_peekBytes(offset: number, length: number): Uint8Array; | ||
subReader(offset: number): Reader; | ||
readBytes(length: number): Uint8Array; | ||
readValue(): BigNumber; | ||
} |
Oops, something went wrong.