Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

fix: add new Ethereum types namespace to fix types #2527

Merged
merged 43 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9a979e2
type stuff
davidmurdoch Feb 3, 2022
58f56c1
type and typo fixes
davidmurdoch Feb 4, 2022
bb167ad
WIP types test
davidmurdoch Feb 12, 2022
2b728e1
update types tests
davidmurdoch Mar 4, 2022
45b4004
fix tye
davidmurdoch Mar 4, 2022
5ef99fb
fix type
davidmurdoch Mar 4, 2022
5730274
fix up types
davidmurdoch Mar 4, 2022
c6713e5
add type tests for db_putString, db_getString, db_putHex, and eth_get…
davidmurdoch Mar 9, 2022
1fe3b40
ugh
davidmurdoch Mar 9, 2022
48bede0
add namespace
davidmurdoch Apr 6, 2022
0eea2d2
doing some clean up
davidmurdoch Apr 8, 2022
0253d70
tweaks for rollup
davidmurdoch Apr 8, 2022
bdd0ff3
add block types
davidmurdoch Apr 14, 2022
884f000
add note about polymorphic types
davidmurdoch Apr 15, 2022
958bf92
remove experiemental generic
davidmurdoch Apr 15, 2022
f72305a
make type look better
davidmurdoch Apr 15, 2022
7efdea4
add intersection type to interactive docs
davidmurdoch Apr 18, 2022
5bb8f85
update docs
davidmurdoch Apr 19, 2022
2d1a050
fix type
davidmurdoch Apr 20, 2022
7a4066a
boolean
davidmurdoch Apr 20, 2022
a47ec5b
eth_signTransaction
davidmurdoch Apr 20, 2022
6c3ff98
prettier changes
davidmurdoch Apr 20, 2022
abb4d59
update defaults of some type generics
davidmurdoch Apr 20, 2022
4399cb1
fix typo
davidmurdoch Apr 21, 2022
b45eb11
reame exported transactions
davidmurdoch Apr 21, 2022
47d6128
document what `Externalize` does
davidmurdoch Apr 21, 2022
26a6170
clarify comment for evm_mine type
davidmurdoch Apr 21, 2022
802834e
remove some GitHub Copilot shenanigans :-)
davidmurdoch Apr 21, 2022
212c501
Update src/chains/ethereum/ethereum/src/api.ts
davidmurdoch Apr 21, 2022
5f54818
Update src/packages/cli/src/cli.ts
davidmurdoch Apr 21, 2022
7b23c7b
use more concise type
davidmurdoch Apr 21, 2022
711a404
Update src/packages/ganache/tests/types.test.ts
davidmurdoch Apr 21, 2022
bc39d5e
add more namespaces
davidmurdoch May 5, 2022
a1bec6c
update docs
davidmurdoch May 5, 2022
66dc0b2
Clean up types
davidmurdoch May 6, 2022
6a2883c
some docs improvements
davidmurdoch May 6, 2022
aec9643
Merge branch 'develop' into fix-types
davidmurdoch May 20, 2022
88a0730
use typescript 4.6.4
davidmurdoch May 20, 2022
bd809ce
remove unused imports
davidmurdoch May 25, 2022
6da12e8
remove weird comment
davidmurdoch May 25, 2022
d58d1eb
fix TuplifyUnion jsdoc comment
davidmurdoch May 25, 2022
67eedcd
re-order Call type for readability
davidmurdoch May 25, 2022
8a743c7
Merge branch 'develop' into fix-types
davidmurdoch May 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/assets/js/ganache/ganache.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/js/ganache/ganache.min.js.map

Large diffs are not rendered by default.

352 changes: 187 additions & 165 deletions docs/index.html

Large diffs are not rendered by default.

4,845 changes: 1,896 additions & 2,949 deletions docs/typedoc/api.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/typedoc/assets/search.js

Large diffs are not rendered by default.

318 changes: 170 additions & 148 deletions docs/typedoc/classes/default.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"semver": "7.3.5",
"shx": "0.3.3",
"ts-node": "10.4.0",
"typescript": "4.5.4",
"typescript": "4.6.4",
"validate-npm-package-name": "3.0.0",
"yargs": "16.2.0"
},
Expand Down
23 changes: 15 additions & 8 deletions scripts/build-docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Type = {
elements: Type[];
elementType: Type;
value?: any;
declaration?: Child;
};

type Comment = {
Expand Down Expand Up @@ -271,7 +272,15 @@ function getTypeAsString(type: Type): string {
case "array":
return `${getTypeAsString(type.elementType)}[]`;
case "reflection":
return "object";
if (type.declaration) {
return `{ ${type.declaration.children
.map(child => {
return `${child.name}: ${getTypeAsString(child.type)}`;
})
.join(", ")} }`;
} else {
return "object";
}
case "intrinsic":
case "reference":
return x(type.name);
Expand All @@ -283,6 +292,10 @@ function getTypeAsString(type: Type): string {
// outputs a string literal like `He said, "hello, world"!` as
// the string `"He said, \"hello, world\"!"`
return `"${type.value.replace(/"/g, '\\"')}"`;
case "intersection":
return type.types.map(getTypeAsString).join(" & ");
davidmurdoch marked this conversation as resolved.
Show resolved Hide resolved
case "conditional":
return getTypeAsString((type as any).checkType);
default:
console.error(type);
throw new Error(`Unhandled type: ${type.type}`);
Expand All @@ -295,13 +308,7 @@ function renderReturnType(method: Method) {
if (signature.type.typeArguments.length) {
let typeArgs = signature.type.typeArguments.map(getTypeAsString);
typeArgs = typeArgs.map((arg: string) => {
if (arg.includes("Quantity")) {
return arg.replace("Quantity", "QUANTITY");
} else if (arg.includes("Data")) {
return arg.replace("Data", "DATA");
} else {
return arg;
}
return arg.replace(/Quantity/g, "QUANTITY").replace(/Data/g, "DATA");
});
returnType = `${returnType}<${typeArgs.join(", ")}>`;
}
Expand Down
6 changes: 3 additions & 3 deletions src/chains/ethereum/address/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/chains/ethereum/address/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"mocha": "9.1.3",
"nyc": "15.1.0",
"ts-node": "10.4.0",
"typescript": "4.5.2"
"typescript": "4.6.4"
},
"dependencies": {
"@ganache/utils": "0.3.0"
Expand Down
6 changes: 3 additions & 3 deletions src/chains/ethereum/block/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/chains/ethereum/block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"mocha": "9.1.3",
"nyc": "15.1.0",
"ts-node": "10.4.0",
"typescript": "4.5.2"
"typescript": "4.6.4"
},
"dependencies": {
"@ethereumjs/common": "2.6.4",
Expand Down
17 changes: 10 additions & 7 deletions src/chains/ethereum/block/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
GanacheRawExtraTx,
TransactionFactory,
TypedDatabaseTransaction,
TypedTransaction
TypedTransaction,
TypedTransactionJSON
} from "@ganache/ethereum-transaction";
import type Common from "@ethereumjs/common";
import { encode, decode } from "@ganache/rlp";
Expand Down Expand Up @@ -69,9 +70,11 @@ export class Block {
});
}

toJSON(includeFullTransactions = false) {
toJSON<IncludeTransactions extends boolean>(
includeFullTransactions: IncludeTransactions
) {
const hash = this.hash();
const txFn = this.getTxFn(includeFullTransactions);
const txFn = this.getTxFn<IncludeTransactions>(includeFullTransactions);
const hashBuffer = hash.toBuffer();
const header = this.header;
const number = header.number.toBuffer();
Expand All @@ -92,19 +95,19 @@ export class Block {
// leave it out of extra and update the effectiveGasPrice after like this
tx.updateEffectiveGasPrice(header.baseFeePerGas);
return txFn(tx);
});
}) as IncludeTransactions extends true ? TypedTransactionJSON[] : Data[];

return {
hash,
...header,
size: Quantity.from(this._size),
transactions: jsonTxs,
uncles: [] as string[] // this.value.uncleHeaders.map(function(uncleHash) {return to.hex(uncleHash)})
uncles: [] as Data[] // this.value.uncleHeaders.map(function(uncleHash) {return to.hex(uncleHash)})
};
}

getTxFn(
include = false
getTxFn<IncludeTransactions extends boolean>(
include: IncludeTransactions = <IncludeTransactions>false
): (tx: TypedTransaction) => ReturnType<TypedTransaction["toJSON"]> | Data {
if (include) {
return (tx: TypedTransaction) => tx.toJSON(this._common);
Expand Down
2 changes: 1 addition & 1 deletion src/chains/ethereum/block/src/runtime-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type BlockHeader = {

/**
* Returns the size of the serialized data as it would have been calculated had
* we stored things geth does, i.e., `totalDfficulty` is not usually stored in
* we stored things geth does, i.e., `totalDifficulty` is not usually stored in
* the block header.
*
* @param serialized -
Expand Down
7 changes: 2 additions & 5 deletions src/chains/ethereum/block/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { Address } from "@ganache/ethereum-address";
import { BUFFER_ZERO, Data, Quantity } from "@ganache/utils";
import Common from "@ethereumjs/common";
import Wallet from "../../ethereum/src/wallet";
import {
TypedRpcTransaction,
TransactionFactory
} from "@ganache/ethereum-transaction";
import { Transaction, TransactionFactory } from "@ganache/ethereum-transaction";
import Blockchain from "../../ethereum/src/blockchain";
import { EthereumOptionsConfig } from "../../options/src/index";

Expand Down Expand Up @@ -36,7 +33,7 @@ describe("@ganache/ethereum-block", async () => {
const wallet = new Wallet(options.wallet);
const [from, to] = wallet.addresses;
const fromAddress = new Address(from);
const tx: TypedRpcTransaction = {
const tx: Transaction = {
type: "0x2",
from: from,
to: to,
Expand Down
58 changes: 32 additions & 26 deletions src/chains/ethereum/ethereum/RPC-METHODS.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Attempts to replay the transaction as it was executed on the network and return

##### Returns

`Promise<StorageRangeResult>` : Returns a storage object with the keys being keccak-256 hashes of the storage keys, and the values being the raw, unhashed key and value for that specific storage slot. Also returns a next key which is the keccak-256 hash of the next key in storage for continuous downloading.
`Promise<Ethereum.StorageRangeResult>` : Returns a storage object with the keys being keccak-256 hashes of the storage keys, and the values being the raw, unhashed key and value for that specific storage slot. Also returns a next key which is the keccak-256 hash of the next key in storage for continuous downloading.

---

Expand All @@ -109,11 +109,11 @@ Attempt to run the transaction in the exact same manner as it was executed on th
##### Arguments

- `transactionHash: DATA` : Hash of the transaction to trace.
- `options?: TransactionTraceOptions` : See options in source.
- `options?: Ethereum.TransactionTraceOptions` : See options in source.

##### Returns

`Promise<TraceTransactionResult>` : Returns the `gas`, `structLogs`, and `returnValue` for the traced transaction. The `structLogs` are an array of logs, which contains the following fields:
`Promise<Ethereum.TraceTransactionResult>` : Returns the `gas`, `structLogs`, and `returnValue` for the traced transaction. The `structLogs` are an array of logs, which contains the following fields:

- `depth`: The execution depth.
- `error`: Information about an error, if one occurred.
Expand Down Expand Up @@ -156,15 +156,11 @@ Executes a new message call immediately without creating a transaction on the bl
- `transaction: any` : The transaction call object as seen in source.
- `blockNumber: QUANTITY | TAG` : Integer block number, or the string "latest", "earliest" or "pending".
- `overrides: CallOverrides`: State overrides to apply during the simulation.

- `CallOverrides` - An address-to-state mapping, where each entry specifies some
state to be ephemerally overridden prior to executing the call. Each address maps to an object containing:
- `balance: QUANTITY` (optional) - The balance to set for the account before executing the call.
- `nonce: QUANTITY` (optional) - The nonce to set for the account before executing the call.
- `code: DATA` (optional) - The EVM bytecode to set for the account before executing the call.
- `state: OBJECT` (optional\*) - Key-value mapping to override _all_ slots in the account storage before executing the call.
- `stateDiff: OBJECT` (optional\*) - Key-value mapping to override _individual_ slots in the account storage before executing the call.
state to be ephemerally overridden prior to executing the call. Each address maps to an object containing: - `balance: QUANTITY` (optional) - The balance to set for the account before executing the call. - `nonce: QUANTITY` (optional) - The nonce to set for the account before executing the call. - `code: DATA` (optional) - The EVM bytecode to set for the account before executing the call. - `state: OBJECT` (optional\*) - Key-value mapping to override _all_ slots in the account storage before executing the call. - `stateDiff: OBJECT` (optional\*) - Key-value mapping to override _individual_ slots in the account storage before executing the call.

_\*Note - `state` and `stateDiff` fields are mutually exclusive._
_\*Note - `state` and `stateDiff` fields are mutually exclusive._

##### Returns

Expand Down Expand Up @@ -198,7 +194,7 @@ Generates and returns an estimate of how much gas is necessary to allow the tran

##### Arguments

- `transaction: TypedRpcTransaction` : The transaction call object as seen in source.
- `transaction: Ethereum.Transaction` : The transaction call object as seen in source.
- `blockNumber: QUANTITY | TAG` : Integer block number, or the string "latest", "earliest" or "pending".

##### Returns
Expand Down Expand Up @@ -243,7 +239,7 @@ Returns information about a block by block hash.

##### Returns

`Promise<object>` : The block, `null` if the block doesn't exist.
`Promise<Ethereum.Block<IncludeTransactions>>` : The block, `null` if the block doesn't exist.

---

Expand All @@ -258,7 +254,7 @@ Returns information about a block by block number.

##### Returns

`Promise<object>` : The block, `null` if the block doesn't exist.
`Promise<Ethereum.Block<IncludeTransactions>>` : The block, `null` if the block doesn't exist.

---

Expand Down Expand Up @@ -359,7 +355,7 @@ Returns an array of all logs matching a given filter object.

##### Arguments

- `filter: FilterArgs` : The filter options as seen in source.
- `filter: Ethereum.LogsFilter` : The filter options as seen in source.

##### Returns

Expand Down Expand Up @@ -452,7 +448,7 @@ Returns the receipt of a transaction by transaction hash.

##### Returns

`Promise<TransactionReceiptJSON>` : Returns the receipt of a transaction by transaction hash.
`Promise<Ethereum.TransactionReceipt>` : Returns the receipt of a transaction by transaction hash.

---

Expand Down Expand Up @@ -578,7 +574,7 @@ Creates a filter object, based on filter options, to notify when the state chang

##### Arguments

- `filter?: RangeFilterArgs` : The filter options as seen in source.
- `filter?: Ethereum.Filter` : The filter options as seen in source.

##### Returns

Expand Down Expand Up @@ -626,7 +622,7 @@ Creates new message call transaction or a contract creation, if the data field c

##### Arguments

- `transaction: TypedRpcTransaction` : The transaction call object as seen in source.
- `transaction: Ethereum.Transaction` : The transaction call object as seen in source.

##### Returns

Expand Down Expand Up @@ -655,7 +651,7 @@ Signs a transaction that can be submitted to the network at a later time using `

##### Arguments

- `transaction: TypedRpcTransaction` : The transaction call object as seen in source.
- `transaction: Ethereum.Transaction` : The transaction call object as seen in source.

##### Returns

Expand All @@ -670,7 +666,7 @@ Identical to eth_signTypedData_v4.
##### Arguments

- `address: DATA` : Address of the account that will sign the messages.
- `typedData: TypedData` : Typed structured data to be signed.
- `typedData: Ethereum.TypedData` : Typed structured data to be signed.

##### Returns

Expand All @@ -683,7 +679,7 @@ Identical to eth_signTypedData_v4.
##### Arguments

- `address: DATA` : Address of the account that will sign the messages.
- `typedData: TypedData` : Typed structured data to be signed.
- `typedData: Ethereum.TypedData` : Typed structured data to be signed.

##### Returns

Expand Down Expand Up @@ -728,7 +724,7 @@ Starts a subscription to a particular event. For every event that matches the su

##### Arguments

- `subscriptionName: SubscriptionName` : Name for the subscription.
- `subscriptionName: Ethereum.SubscriptionName` : Name for the subscription.

##### Returns

Expand Down Expand Up @@ -766,7 +762,7 @@ Cancel a subscription to a particular event. Returns a boolean indicating if the

##### Arguments

- `subscriptionId: SubscriptionId` : The ID of the subscription to unsubscribe to.
- `subscriptionId: Ethereum.SubscriptionId` : The ID of the subscription to unsubscribe to.

##### Returns

Expand Down Expand Up @@ -1086,8 +1082,8 @@ Validate the given passphrase and submit transaction.

##### Arguments

- `transaction: TypedRpcTransaction`
- `passphrase: string` : The passphrase to decrpyt the private key belonging to `tx.from`.
- `transaction: Ethereum.Transaction`
- `passphrase: string` : The passphrase to decrypt the private key belonging to `tx.from`.

##### Returns

Expand All @@ -1101,7 +1097,7 @@ Validates the given passphrase and signs a transaction that can be submitted to

##### Arguments

- `transaction: TypedRpcTransaction` : The transaction call object as seen in source.
- `transaction: Ethereum.Transaction` : The transaction call object as seen in source.
- `passphrase: string`

##### Returns
Expand Down Expand Up @@ -1233,7 +1229,7 @@ Creates a whisper message and injects it into the network for distribution.

##### Arguments

- `postData: WhisperPostObject`
- `postData: Ethereum.WhisperPostObject`

##### Returns

Expand Down Expand Up @@ -1265,6 +1261,16 @@ Returns the current whisper protocol version.

---

#### txpool_content()

Returns the current content of the transaction pool.

##### Returns

`Promise<Ethereum.Pool.Content>` : The transactions currently pending or queued in the transaction pool.

---

#### web3_clientVersion

Returns the current client version.
Expand Down
1 change: 1 addition & 0 deletions src/chains/ethereum/ethereum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/

export * from "./src/connector";
export * from "./src/api-types";
Loading