Removed superfluous types for refining type properties.
This commit is contained in:
parent
5bdac36a99
commit
b617322ee8
@ -428,18 +428,6 @@ function verifyBasicType(type: string): string {
|
|||||||
// Make the Fragment constructors effectively private
|
// Make the Fragment constructors effectively private
|
||||||
const _guard = { };
|
const _guard = { };
|
||||||
|
|
||||||
export interface ArrayParamType { //extends ParamType {
|
|
||||||
readonly arrayLength: number;
|
|
||||||
readonly arrayChildren: ParamType;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TupleParamType extends ParamType {
|
|
||||||
readonly components: ReadonlyArray<ParamType>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IndexableParamType extends ParamType {
|
|
||||||
readonly indexed: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FragmentWalkFunc = (type: string, value: any) => any;
|
export type FragmentWalkFunc = (type: string, value: any) => any;
|
||||||
export type FragmentWalkAsyncFunc = (type: string, value: any) => any | Promise<any>;
|
export type FragmentWalkAsyncFunc = (type: string, value: any) => any | Promise<any>;
|
||||||
@ -545,15 +533,15 @@ export class ParamType {
|
|||||||
return value && (value.baseType === "array")
|
return value && (value.baseType === "array")
|
||||||
}
|
}
|
||||||
|
|
||||||
isArray(): this is (ParamType & ArrayParamType) {
|
isArray(): this is (ParamType & { arrayLength: number, arrayChildren: ParamType }) {
|
||||||
return (this.baseType === "array")
|
return (this.baseType === "array")
|
||||||
}
|
}
|
||||||
|
|
||||||
isTuple(): this is TupleParamType {
|
isTuple(): this is (ParamType & { components: ReadonlyArray<ParamType> }) {
|
||||||
return (this.baseType === "tuple");
|
return (this.baseType === "tuple");
|
||||||
}
|
}
|
||||||
|
|
||||||
isIndexable(): this is IndexableParamType {
|
isIndexable(): this is (ParamType & { indexed: boolean }) {
|
||||||
return (this.indexed != null);
|
return (this.indexed != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,7 +551,8 @@ export class ParamType {
|
|||||||
if (this.arrayLength !== -1 && value.length !== this.arrayLength) {
|
if (this.arrayLength !== -1 && value.length !== this.arrayLength) {
|
||||||
throw new Error("array is wrong length");
|
throw new Error("array is wrong length");
|
||||||
}
|
}
|
||||||
return value.map((v) => ((<ArrayParamType>this).arrayChildren.walk(v, process)));
|
const _this = this;
|
||||||
|
return value.map((v) => (_this.arrayChildren.walk(v, process)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isTuple()) {
|
if (this.isTuple()) {
|
||||||
@ -571,7 +560,8 @@ export class ParamType {
|
|||||||
if (value.length !== this.components.length) {
|
if (value.length !== this.components.length) {
|
||||||
throw new Error("array is wrong length");
|
throw new Error("array is wrong length");
|
||||||
}
|
}
|
||||||
return value.map((v, i) => ((<TupleParamType>this).components[i].walk(v, process)));
|
const _this = this;
|
||||||
|
return value.map((v, i) => (_this.components[i].walk(v, process)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return process(this.type, value);
|
return process(this.type, value);
|
||||||
@ -742,13 +732,7 @@ export class ParamType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum FragmentType {
|
export type FragmentType = "constructor" | "error" | "event" | "function" | "struct";
|
||||||
"constructor" = "constructor",
|
|
||||||
"error" = "error",
|
|
||||||
"event" = "event",
|
|
||||||
"function" = "function",
|
|
||||||
"struct" = "struct",
|
|
||||||
};
|
|
||||||
|
|
||||||
export abstract class Fragment {
|
export abstract class Fragment {
|
||||||
readonly type!: FragmentType;
|
readonly type!: FragmentType;
|
||||||
@ -858,7 +842,7 @@ function joinParams(format: FormatType, params: ReadonlyArray<ParamType>): strin
|
|||||||
|
|
||||||
export class ErrorFragment extends NamedFragment {
|
export class ErrorFragment extends NamedFragment {
|
||||||
constructor(guard: any, name: string, inputs: ReadonlyArray<ParamType>) {
|
constructor(guard: any, name: string, inputs: ReadonlyArray<ParamType>) {
|
||||||
super(guard, FragmentType.error, name, inputs);
|
super(guard, "error", name, inputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
format(format: FormatType = "sighash"): string {
|
format(format: FormatType = "sighash"): string {
|
||||||
@ -894,7 +878,7 @@ export class EventFragment extends NamedFragment {
|
|||||||
readonly anonymous!: boolean;
|
readonly anonymous!: boolean;
|
||||||
|
|
||||||
constructor(guard: any, name: string, inputs: ReadonlyArray<ParamType>, anonymous: boolean) {
|
constructor(guard: any, name: string, inputs: ReadonlyArray<ParamType>, anonymous: boolean) {
|
||||||
super(guard, FragmentType.event, name, inputs);
|
super(guard, "event", name, inputs);
|
||||||
defineProperties<EventFragment>(this, { anonymous });
|
defineProperties<EventFragment>(this, { anonymous });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -977,7 +961,7 @@ export class ConstructorFragment extends Fragment {
|
|||||||
const gas = consumeGas(tokens);
|
const gas = consumeGas(tokens);
|
||||||
consumeEoi(tokens);
|
consumeEoi(tokens);
|
||||||
|
|
||||||
return new ConstructorFragment(_guard, FragmentType.constructor, inputs, payable, gas);
|
return new ConstructorFragment(_guard, "constructor", inputs, payable, gas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -990,7 +974,7 @@ export class FunctionFragment extends NamedFragment {
|
|||||||
readonly gas!: null | bigint;
|
readonly gas!: null | bigint;
|
||||||
|
|
||||||
constructor(guard: any, name: string, stateMutability: string, inputs: ReadonlyArray<ParamType>, outputs: ReadonlyArray<ParamType>, gas: null | bigint) {
|
constructor(guard: any, name: string, stateMutability: string, inputs: ReadonlyArray<ParamType>, outputs: ReadonlyArray<ParamType>, gas: null | bigint) {
|
||||||
super(guard, FragmentType.function, name, inputs);
|
super(guard, "function", name, inputs);
|
||||||
outputs = Object.freeze(outputs.slice());
|
outputs = Object.freeze(outputs.slice());
|
||||||
const constant = (stateMutability === "view" || stateMutability === "pure");
|
const constant = (stateMutability === "view" || stateMutability === "pure");
|
||||||
const payable = (stateMutability === "payable");
|
const payable = (stateMutability === "payable");
|
||||||
@ -1068,7 +1052,7 @@ export class StructFragment extends NamedFragment {
|
|||||||
const inputs = consumeParams(tokens);
|
const inputs = consumeParams(tokens);
|
||||||
consumeEoi(tokens);
|
consumeEoi(tokens);
|
||||||
|
|
||||||
return new StructFragment(_guard, FragmentType.struct, name, inputs);
|
return new StructFragment(_guard, "struct", name, inputs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,7 +597,7 @@ export class AbstractProvider implements Provider {
|
|||||||
return network.formatter.transactionRequest(request);
|
return network.formatter.transactionRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
async estimateGas(_tx: TransactionRequest) {
|
async estimateGas(_tx: TransactionRequest): Promise<bigint> {
|
||||||
const transaction = await this._getTransaction(_tx);
|
const transaction = await this._getTransaction(_tx);
|
||||||
return getBigInt(await this.#perform({
|
return getBigInt(await this.#perform({
|
||||||
method: "estimateGas", transaction
|
method: "estimateGas", transaction
|
||||||
@ -665,7 +665,7 @@ export class AbstractProvider implements Provider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async call(_tx: CallRequest) {
|
async call(_tx: CallRequest): Promise<string> {
|
||||||
const [ tx, blockTag ] = await Promise.all([
|
const [ tx, blockTag ] = await Promise.all([
|
||||||
this._getTransaction(_tx), this._getBlockTag(_tx.blockTag)
|
this._getTransaction(_tx), this._getBlockTag(_tx.blockTag)
|
||||||
]);
|
]);
|
||||||
@ -684,25 +684,25 @@ export class AbstractProvider implements Provider {
|
|||||||
return await this.#perform(Object.assign(request, { address, blockTag }));
|
return await this.#perform(Object.assign(request, { address, blockTag }));
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBalance(address: AddressLike, blockTag?: BlockTag) {
|
async getBalance(address: AddressLike, blockTag?: BlockTag): Promise<bigint> {
|
||||||
return getBigInt(await this.#getAccountValue({ method: "getBalance" }, address, blockTag), "%response");
|
return getBigInt(await this.#getAccountValue({ method: "getBalance" }, address, blockTag), "%response");
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTransactionCount(address: AddressLike, blockTag?: BlockTag) {
|
async getTransactionCount(address: AddressLike, blockTag?: BlockTag): Promise<number> {
|
||||||
return getNumber(await this.#getAccountValue({ method: "getTransactionCount" }, address, blockTag), "%response");
|
return getNumber(await this.#getAccountValue({ method: "getTransactionCount" }, address, blockTag), "%response");
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCode(address: AddressLike, blockTag?: BlockTag) {
|
async getCode(address: AddressLike, blockTag?: BlockTag): Promise<string> {
|
||||||
return hexlify(await this.#getAccountValue({ method: "getCode" }, address, blockTag));
|
return hexlify(await this.#getAccountValue({ method: "getCode" }, address, blockTag));
|
||||||
}
|
}
|
||||||
|
|
||||||
async getStorageAt(address: AddressLike, _position: BigNumberish, blockTag?: BlockTag) {
|
async getStorageAt(address: AddressLike, _position: BigNumberish, blockTag?: BlockTag): Promise<string> {
|
||||||
const position = getBigInt(_position, "position");
|
const position = getBigInt(_position, "position");
|
||||||
return hexlify(await this.#getAccountValue({ method: "getStorageAt", position }, address, blockTag));
|
return hexlify(await this.#getAccountValue({ method: "getStorageAt", position }, address, blockTag));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write
|
// Write
|
||||||
async broadcastTransaction(signedTx: string) {
|
async broadcastTransaction(signedTx: string): Promise<TransactionResponse> {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
return <TransactionResponse><unknown>{ };
|
return <TransactionResponse><unknown>{ };
|
||||||
}
|
}
|
||||||
@ -869,6 +869,7 @@ export class AbstractProvider implements Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async resolveName(name: string): Promise<null | string>{
|
async resolveName(name: string): Promise<null | string>{
|
||||||
|
if (isHexString(name, 20)) { return name; }
|
||||||
//if (typeof(name) === "string") {
|
//if (typeof(name) === "string") {
|
||||||
const resolver = await this.getResolver(name);
|
const resolver = await this.getResolver(name);
|
||||||
if (resolver) { return await resolver.getAddress(); }
|
if (resolver) { return await resolver.getAddress(); }
|
||||||
@ -1230,7 +1231,7 @@ function bytesPad(value: Uint8Array): Uint8Array {
|
|||||||
const empty = new Uint8Array([ ]);
|
const empty = new Uint8Array([ ]);
|
||||||
|
|
||||||
// ABI Encodes a series of (bytes, bytes, ...)
|
// ABI Encodes a series of (bytes, bytes, ...)
|
||||||
function encodeBytes(datas: Array<BytesLike>) {
|
function encodeBytes(datas: Array<BytesLike>): string {
|
||||||
const result: Array<Uint8Array> = [ ];
|
const result: Array<Uint8Array> = [ ];
|
||||||
|
|
||||||
let byteCount = 0;
|
let byteCount = 0;
|
||||||
|
@ -206,10 +206,6 @@ export interface MinedBlock<T extends string | TransactionResponse = string> ext
|
|||||||
readonly miner: string;
|
readonly miner: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LondonBlock<T extends string | TransactionResponse> extends Block<T> {
|
|
||||||
readonly baseFeePerGas: bigint;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Block<T extends string | TransactionResponse> implements BlockParams<T>, Iterable<T> {
|
export class Block<T extends string | TransactionResponse> implements BlockParams<T>, Iterable<T> {
|
||||||
readonly provider!: Provider;
|
readonly provider!: Provider;
|
||||||
|
|
||||||
@ -320,7 +316,9 @@ export class Block<T extends string | TransactionResponse> implements BlockParam
|
|||||||
}
|
}
|
||||||
|
|
||||||
isMined(): this is MinedBlock<T> { return !!this.hash; }
|
isMined(): this is MinedBlock<T> { return !!this.hash; }
|
||||||
isLondon(): this is LondonBlock<T> { return !!this.baseFeePerGas; }
|
isLondon(): this is (Block<T> & { baseFeePerGas: bigint }) {
|
||||||
|
return !!this.baseFeePerGas;
|
||||||
|
}
|
||||||
|
|
||||||
orphanedEvent(): OrphanFilter {
|
orphanedEvent(): OrphanFilter {
|
||||||
if (!this.isMined()) { throw new Error(""); }
|
if (!this.isMined()) { throw new Error(""); }
|
||||||
@ -449,6 +447,7 @@ export interface TransactionReceiptParams {
|
|||||||
root: null | string;
|
root: null | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
export interface LegacyTransactionReceipt {
|
export interface LegacyTransactionReceipt {
|
||||||
byzantium: false;
|
byzantium: false;
|
||||||
status: null;
|
status: null;
|
||||||
@ -460,6 +459,7 @@ export interface ByzantiumTransactionReceipt {
|
|||||||
status: number;
|
status: number;
|
||||||
root: null;
|
root: null;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
export class TransactionReceipt implements TransactionReceiptParams, Iterable<Log> {
|
export class TransactionReceipt implements TransactionReceiptParams, Iterable<Log> {
|
||||||
readonly provider!: Provider;
|
readonly provider!: Provider;
|
||||||
@ -631,23 +631,7 @@ export interface MinedTransactionResponse extends TransactionResponse {
|
|||||||
date: Date;
|
date: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LegacyTransactionResponse extends TransactionResponse {
|
|
||||||
accessList: null;
|
|
||||||
maxFeePerGas: null;
|
|
||||||
maxPriorityFeePerGas: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BerlinTransactionResponse extends TransactionResponse {
|
|
||||||
accessList: AccessList;
|
|
||||||
maxFeePerGas: null;
|
|
||||||
maxPriorityFeePerGas: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LondonTransactionResponse extends TransactionResponse {
|
|
||||||
accessList: AccessList;
|
|
||||||
maxFeePerGas: bigint;
|
|
||||||
maxPriorityFeePerGas: bigint;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TransactionResponse implements TransactionLike<string>, TransactionResponseParams {
|
export class TransactionResponse implements TransactionLike<string>, TransactionResponseParams {
|
||||||
readonly provider: Provider;
|
readonly provider: Provider;
|
||||||
@ -760,15 +744,15 @@ export class TransactionResponse implements TransactionLike<string>, Transaction
|
|||||||
return (this.blockHash != null);
|
return (this.blockHash != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
isLegacy(): this is LegacyTransactionResponse {
|
isLegacy(): this is (TransactionResponse & { accessList: null, maxFeePerGas: null, maxPriorityFeePerGas: null }) {
|
||||||
return (this.type === 0)
|
return (this.type === 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
isBerlin(): this is BerlinTransactionResponse {
|
isBerlin(): this is (TransactionResponse & { accessList: AccessList, maxFeePerGas: null, maxPriorityFeePerGas: null }) {
|
||||||
return (this.type === 1);
|
return (this.type === 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
isLondon(): this is LondonTransactionResponse {
|
isLondon(): this is (TransactionResponse & { accessList: AccessList, maxFeePerGas: bigint, maxPriorityFeePerGas: bigint }){
|
||||||
return (this.type === 2);
|
return (this.type === 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,23 +328,6 @@ export interface SignedTransaction extends Transaction {
|
|||||||
signature: Signature;
|
signature: Signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LegacyTransaction extends Transaction {
|
|
||||||
type: 0;
|
|
||||||
gasPrice: bigint;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BerlinTransaction extends Transaction {
|
|
||||||
type: 1;
|
|
||||||
gasPrice: bigint;
|
|
||||||
accessList: AccessList;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LondonTransaction extends Transaction {
|
|
||||||
type: 2;
|
|
||||||
maxFeePerGas: bigint;
|
|
||||||
maxPriorityFeePerGas: bigint;
|
|
||||||
accessList: AccessList;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Transaction implements Freezable<Transaction>, TransactionLike<string> {
|
export class Transaction implements Freezable<Transaction>, TransactionLike<string> {
|
||||||
#props: {
|
#props: {
|
||||||
@ -595,9 +578,15 @@ export class Transaction implements Freezable<Transaction>, TransactionLike<stri
|
|||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
isLegacy(): this is LegacyTransaction { return (this.type === 0); }
|
isLegacy(): this is (Transaction & { type: 0, gasPrice: bigint }) {
|
||||||
isBerlin(): this is BerlinTransaction { return (this.type === 1); }
|
return (this.type === 0);
|
||||||
isLondon(): this is LondonTransaction { return (this.type === 2); }
|
}
|
||||||
|
isBerlin(): this is (Transaction & { type: 1, gasPrice: bigint, accessList: AccessList }) {
|
||||||
|
return (this.type === 1);
|
||||||
|
}
|
||||||
|
isLondon(): this is (Transaction & { type: 2, accessList: AccessList, maxFeePerGas: bigint, maxPriorityFeePerGas: bigint}) {
|
||||||
|
return (this.type === 2);
|
||||||
|
}
|
||||||
|
|
||||||
clone(): Transaction {
|
clone(): Transaction {
|
||||||
return Transaction.from(this);
|
return Transaction.from(this);
|
||||||
|
@ -14,10 +14,6 @@ export type GetUrlResponse = {
|
|||||||
body: null | Uint8Array
|
body: null | Uint8Array
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface FetchRequestWithBody extends FetchRequest {
|
|
||||||
body: Uint8Array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before any network request, allowing updated headers (e.g. Bearer tokens), etc.
|
* Called before any network request, allowing updated headers (e.g. Bearer tokens), etc.
|
||||||
*/
|
*/
|
||||||
@ -125,7 +121,7 @@ export class FetchCancelSignal {
|
|||||||
this.#listeners.push(listener);
|
this.#listeners.push(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
get cancelled(): boolean { return this.cancelled; }
|
get cancelled(): boolean { return this.#cancelled; }
|
||||||
|
|
||||||
checkSignal(): void {
|
checkSignal(): void {
|
||||||
if (!this.cancelled) { return; }
|
if (!this.cancelled) { return; }
|
||||||
@ -217,7 +213,7 @@ export class FetchRequest implements Iterable<[ key: string, value: string ]> {
|
|||||||
/**
|
/**
|
||||||
* Returns true if the request has a body.
|
* Returns true if the request has a body.
|
||||||
*/
|
*/
|
||||||
hasBody(): this is FetchRequestWithBody {
|
hasBody(): this is (FetchRequest & { body: Uint8Array }) {
|
||||||
return (this.#body != null);
|
return (this.#body != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,10 +613,6 @@ export class FetchRequest implements Iterable<[ key: string, value: string ]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export interface FetchResponseWithBody extends FetchResponse {
|
|
||||||
body: Readonly<Uint8Array>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ThrottleError extends Error {
|
interface ThrottleError extends Error {
|
||||||
stall: number;
|
stall: number;
|
||||||
throttle: true;
|
throttle: true;
|
||||||
@ -771,7 +763,7 @@ export class FetchResponse implements Iterable<[ key: string, value: string ]> {
|
|||||||
/**
|
/**
|
||||||
* Returns true of the response has a body.
|
* Returns true of the response has a body.
|
||||||
*/
|
*/
|
||||||
hasBody(): this is FetchResponseWithBody {
|
hasBody(): this is (FetchResponse & { body: Uint8Array }) {
|
||||||
return (this.#body != null);
|
return (this.#body != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user