From 23868e74b1123296bbc6726dbeaf1da7c17cacf7 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Thu, 15 Sep 2022 22:31:00 -0400 Subject: [PATCH] Refactor imports. --- src.ts/address/address.ts | 2 +- src.ts/address/contract-address.ts | 2 +- src.ts/ethers.ts | 24 +++++++++++++++++++----- src.ts/hash/id.ts | 2 +- src.ts/hash/message.ts | 2 +- src.ts/hash/namehash.ts | 2 +- src.ts/hash/solidity.ts | 8 -------- src.ts/providers/abstract-signer.ts | 17 +++++++++++++++-- src.ts/providers/index.ts | 26 +++++++++++++++++++++----- src.ts/providers/provider.ts | 8 ++++++++ src.ts/providers/subscriber-polling.ts | 3 +-- src.ts/utils/fetch.ts | 2 +- src.ts/utils/index.ts | 10 ++++++---- src.ts/wallet/hdwallet.ts | 5 ----- src.ts/wallet/index.ts | 6 ++++++ src.ts/wallet/json-crowdsale.ts | 2 +- src.ts/wordlists/lang-ja.ts | 2 +- src.ts/wordlists/lang-ko.ts | 2 +- src.ts/wordlists/wordlist-owl.ts | 2 +- 19 files changed, 86 insertions(+), 41 deletions(-) diff --git a/src.ts/address/address.ts b/src.ts/address/address.ts index 3e9d6f1f3..e29c46946 100644 --- a/src.ts/address/address.ts +++ b/src.ts/address/address.ts @@ -1,4 +1,4 @@ -import { keccak256 } from "../crypto/keccak.js"; +import { keccak256 } from "../crypto/index.js"; import { getBytes, throwArgumentError } from "../utils/index.js"; diff --git a/src.ts/address/contract-address.ts b/src.ts/address/contract-address.ts index 4c517816d..1c84ee453 100644 --- a/src.ts/address/contract-address.ts +++ b/src.ts/address/contract-address.ts @@ -1,4 +1,4 @@ -import { keccak256 } from "../crypto/keccak.js"; +import { keccak256 } from "../crypto/index.js"; import { concat, dataSlice, getBigInt, getBytes, encodeRlp, throwArgumentError } from "../utils/index.js"; diff --git a/src.ts/ethers.ts b/src.ts/ethers.ts index b1e6ee49b..cf4c6128e 100644 --- a/src.ts/ethers.ts +++ b/src.ts/ethers.ts @@ -62,11 +62,16 @@ export { export { decodeBase58, encodeBase58, + decodeBase64, encodeBase64, + concat, dataLength, dataSlice, getBytes, getBytesCopy, hexlify, + isHexString, isBytesLike, stripZerosLeft, zeroPadBytes, zeroPadValue, + assertArgument, assertArgumentCount, assertNormalize, assertPrivate, + makeError, throwArgumentError, throwError, isCallException, isError, - FetchRequest, FetchResponse, + getIpfsGatewayFunc, FetchRequest, FetchResponse, FetchCancelSignal, FixedFormat, FixedNumber, formatFixed, parseFixed, - assertArgument, - fromTwos, toTwos, mask, toArray, toBigInt, toHex, toNumber, + getBigInt, getNumber, toArray, toBigInt, toHex, toNumber, toQuantity, + fromTwos, toTwos, mask, formatEther, parseEther, formatUnits, parseUnits, _toEscapedUtf8String, toUtf8Bytes, toUtf8CodePoints, toUtf8String, Utf8ErrorFuncs, @@ -111,6 +116,8 @@ export type { ProgressCallback, SignatureLike } from "./crypto/index.js"; export type { TypedDataDomain, TypedDataField } from "./hash/index.js"; export { + AbstractProvider, + FallbackProvider, JsonRpcApiProvider, JsonRpcProvider, JsonRpcSigner, @@ -135,9 +142,16 @@ export type { RlpStructuredData, GetUrlResponse, - FetchRequestWithBody, FetchResponseWithBody, FetchPreflightFunc, FetchProcessFunc, FetchRetryFunc, - FetchGatewayFunc, FetchGetUrlFunc + FetchGatewayFunc, FetchGetUrlFunc, + + EthersError, UnknownError, NotImplementedError, UnsupportedOperationError, NetworkError, + ServerError, TimeoutError, BadDataError, CancelledError, BufferOverrunError, + NumericFaultError, InvalidArgumentError, MissingArgumentError, UnexpectedArgumentError, + CallExceptionError, InsufficientFundsError, NonceExpiredError, OffchainFaultError, + ReplacementUnderpricedError, TransactionReplacedError, UnconfiguredNameError, + UnpredictableGasLimitError, ActionRejectedError, + CodedEthersError, } from "./utils/index.js"; export type { diff --git a/src.ts/hash/id.ts b/src.ts/hash/id.ts index 8b0f08185..2c3eeb4ec 100644 --- a/src.ts/hash/id.ts +++ b/src.ts/hash/id.ts @@ -1,4 +1,4 @@ -import { keccak256 } from "../crypto/keccak.js"; +import { keccak256 } from "../crypto/index.js"; import { toUtf8Bytes } from "../utils/index.js"; export function id(value: string): string { diff --git a/src.ts/hash/message.ts b/src.ts/hash/message.ts index f2c959738..b97fbc9c9 100644 --- a/src.ts/hash/message.ts +++ b/src.ts/hash/message.ts @@ -1,4 +1,4 @@ -import { keccak256 } from "../crypto/keccak.js"; +import { keccak256 } from "../crypto/index.js"; import { MessagePrefix } from "../constants/index.js"; import { concat, toUtf8Bytes } from "../utils/index.js"; diff --git a/src.ts/hash/namehash.ts b/src.ts/hash/namehash.ts index 89ee901ac..687779291 100644 --- a/src.ts/hash/namehash.ts +++ b/src.ts/hash/namehash.ts @@ -1,5 +1,5 @@ -import { keccak256 } from "../crypto/keccak.js"; +import { keccak256 } from "../crypto/index.js"; import { concat, hexlify, throwArgumentError, toUtf8Bytes, toUtf8String } from "../utils/index.js"; diff --git a/src.ts/hash/solidity.ts b/src.ts/hash/solidity.ts index 98674f325..9841dfba0 100644 --- a/src.ts/hash/solidity.ts +++ b/src.ts/hash/solidity.ts @@ -104,14 +104,6 @@ export function solidityPackedKeccak256(types: ReadonlyArray, values: Re return _keccak256(solidityPacked(types, values)); } -/** - * Test Function, for fun - * - * @param foo - something fun - */ -export function test(foo: number | string): void { -} - export function solidityPackedSha256(types: ReadonlyArray, values: ReadonlyArray): string { return _sha256(solidityPacked(types, values)); } diff --git a/src.ts/providers/abstract-signer.ts b/src.ts/providers/abstract-signer.ts index cfb65faed..54127d6d4 100644 --- a/src.ts/providers/abstract-signer.ts +++ b/src.ts/providers/abstract-signer.ts @@ -1,6 +1,6 @@ import { Transaction } from "../transaction/index.js"; import { - defineProperties, resolveProperties, + defineProperties, getBigInt, resolveProperties, throwArgumentError, throwError } from "../utils/index.js"; @@ -80,8 +80,21 @@ export abstract class AbstractSigner

(this.provider)).getNetwork(); + if (pop.chainId != null) { + const chainId = getBigInt(pop.chainId); + if (chainId !== network.chainId) { + throwArgumentError("transaction chainId mismatch", "tx.chainId", tx.chainId); + } + } else { + pop.chainId = network.chainId; + } +//@TOOD: Don't await all over the place; save them up for +// the end for better batching + //@TODO: Copy type logic from AbstractSigner in v5 +// Test how many batches is actually sent for sending a tx; compare before/after return await resolveProperties(pop); } diff --git a/src.ts/providers/index.ts b/src.ts/providers/index.ts index 5fe28b49b..33b7f6e00 100644 --- a/src.ts/providers/index.ts +++ b/src.ts/providers/index.ts @@ -1,8 +1,11 @@ -/* + + + +///// + export { AbstractProvider, UnmanagedSubscriber } from "./abstract-provider.js"; -*/ export { AbstractSigner, @@ -60,12 +63,16 @@ export { IpcSocketProvider }; export { SocketProvider } from "./provider-socket.js"; export { WebSocketProvider } from "./provider-websocket.js"; +export { + SocketSubscriber, SocketBlockSubscriber, SocketPendingSubscriber, + SocketEventSubscriber +} from "./provider-socket.js"; -/* export type { - ProviderPlugin, Subscriber, Subscription + Subscription, Subscriber, + ProviderPlugin, + PerformActionFilter, PerformActionTransaction, PerformActionRequest } from "./abstract-provider.js" -*/ export type { ContractRunner } from "./contracts.js"; /* export type { @@ -89,4 +96,13 @@ export type { Provider, } from "./provider.js"; +export type { + JsonRpcPayload, JsonRpcResult, JsonRpcError, + JsonRpcApiProviderOptions, + JsonRpcTransactionRequest, +} from "./provider-jsonrpc.js"; + +export type { WebSocketLike } from "./provider-websocket.js"; + export type { Signer } from "./signer.js"; + diff --git a/src.ts/providers/provider.ts b/src.ts/providers/provider.ts index 4cda9219d..9adb6e01f 100644 --- a/src.ts/providers/provider.ts +++ b/src.ts/providers/provider.ts @@ -574,6 +574,10 @@ export class TransactionReceipt implements TransactionReceiptParams, Iterable { + return (await this.provider.getTransactionResult(this.hash)); + } + async confirmations(): Promise { return (await this.provider.getBlockNumber()) - this.blockNumber + 1; } @@ -971,6 +975,7 @@ export interface Provider extends ContractRunner, EventEmitterable> getTransaction(hash: string): Promise; getTransactionReceipt(hash: string): Promise; + getTransactionResult(hash: string): Promise; //////////////////// @@ -1039,6 +1044,9 @@ class DummyProvider implements Provider { async getTransactionReceipt(hash: string): Promise { return fail(); } + async getTransactionResult(hash: string): Promise { + return fail(); + } // Bloom-filter Queries async getLogs(filter: Filter | FilterByBlockHash): Promise> { diff --git a/src.ts/providers/subscriber-polling.ts b/src.ts/providers/subscriber-polling.ts index c0d78ac17..0b0d29523 100644 --- a/src.ts/providers/subscriber-polling.ts +++ b/src.ts/providers/subscriber-polling.ts @@ -1,8 +1,7 @@ -import { isHexString } from "../utils/data.js"; +import { isHexString, throwError } from "../utils/index.js"; import type { AbstractProvider, Subscriber } from "./abstract-provider.js"; import type { EventFilter, OrphanFilter, ProviderEvent } from "./provider.js"; -import { throwError } from "../utils/index.js"; function copy(obj: any): any { return JSON.parse(JSON.stringify(obj)); diff --git a/src.ts/utils/fetch.ts b/src.ts/utils/fetch.ts index f6a5cd87c..92084564e 100644 --- a/src.ts/utils/fetch.ts +++ b/src.ts/utils/fetch.ts @@ -62,7 +62,7 @@ async function gatewayData(url: string, signal?: FetchCancelSignal): Promise>(node: T, path: string): T { return result; } - -export interface HDNodeWithPath { - path: string; -} - export class HDNodeWallet extends BaseWallet { readonly publicKey!: string; diff --git a/src.ts/wallet/index.ts b/src.ts/wallet/index.ts index 842a5e6db..f081d2f81 100644 --- a/src.ts/wallet/index.ts +++ b/src.ts/wallet/index.ts @@ -7,15 +7,21 @@ export { HDNodeVoidWallet, HDNodeWalletManager, } from "./hdwallet.js"; + export { isCrowdsaleJson, decryptCrowdsaleJson } from "./json-crowdsale.js"; + export { isKeystoreJson, decryptKeystoreJsonSync, decryptKeystoreJson, encryptKeystoreJson } from "./json-keystore.js"; + export { Mnemonic } from "./mnemonic.js"; + export { Wallet } from "./wallet.js"; + +export type { CrowdsaleAccount } from "./json-crowdsale.js"; export type { KeystoreAccountParams, KeystoreAccount, EncryptOptions diff --git a/src.ts/wallet/json-crowdsale.ts b/src.ts/wallet/json-crowdsale.ts index 98958096e..ef14647f1 100644 --- a/src.ts/wallet/json-crowdsale.ts +++ b/src.ts/wallet/json-crowdsale.ts @@ -2,7 +2,7 @@ import { CBC, pkcs7Strip } from "aes-js"; import { getAddress } from "../address/index.js"; import { pbkdf2 } from "../crypto/index.js"; -import { id } from "../hash/id.js"; +import { id } from "../hash/index.js"; import { getBytes, throwArgumentError } from "../utils/index.js"; import { getPassword, looseArrayify, spelunk } from "./utils.js"; diff --git a/src.ts/wordlists/lang-ja.ts b/src.ts/wordlists/lang-ja.ts index 1fc7d085f..4f328bf04 100644 --- a/src.ts/wordlists/lang-ja.ts +++ b/src.ts/wordlists/lang-ja.ts @@ -1,4 +1,4 @@ -import { id } from "../hash/id.js"; +import { id } from "../hash/index.js"; import { hexlify, throwArgumentError, toUtf8Bytes, toUtf8String } from "../utils/index.js"; diff --git a/src.ts/wordlists/lang-ko.ts b/src.ts/wordlists/lang-ko.ts index 653415be1..77c20f926 100644 --- a/src.ts/wordlists/lang-ko.ts +++ b/src.ts/wordlists/lang-ko.ts @@ -1,4 +1,4 @@ -import { id } from "../hash/id.js"; +import { id } from "../hash/index.js"; import { throwArgumentError, toUtf8String } from "../utils/index.js"; import { Wordlist } from "./wordlist.js"; diff --git a/src.ts/wordlists/wordlist-owl.ts b/src.ts/wordlists/wordlist-owl.ts index 884fd0934..ac2dac611 100644 --- a/src.ts/wordlists/wordlist-owl.ts +++ b/src.ts/wordlists/wordlist-owl.ts @@ -2,7 +2,7 @@ // Use the encode-latin.js script to create the necessary // data files to be consumed by this class -import { id } from "../hash/id.js"; +import { id } from "../hash/index.js"; import { throwArgumentError } from "../utils/index.js"; import { decodeOwl } from "./decode-owl.js";