Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change chainId from Int/UInt to BigInt type Ethereum plugin #747

Merged
merged 5 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ type Ethereum_TxRequest @imported(
gasPrice: BigInt
data: String
value: BigInt
chainId: UInt32
chainId: BigInt
type: UInt32
}

Expand Down Expand Up @@ -343,7 +343,7 @@ type Ethereum_Network @imported(
nativeType: "Network"
) {
name: String!
chainId: Int!
chainId: BigInt!
ensAddress: String
}

Expand All @@ -360,7 +360,7 @@ type Ethereum_TxResponse @imported(
gasPrice: BigInt
data: String!
value: BigInt!
chainId: UInt32!
chainId: BigInt!
blockNumber: BigInt
blockHash: String
timestamp: UInt32
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/__tests__/plugin/expected-types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ type Ethereum_TxRequest @imported(
gasPrice: BigInt
data: String
value: BigInt
chainId: UInt32
chainId: BigInt
type: UInt32
}

Expand Down Expand Up @@ -343,7 +343,7 @@ type Ethereum_Network @imported(
nativeType: "Network"
) {
name: String!
chainId: Int!
chainId: BigInt!
ensAddress: String
}

Expand All @@ -360,7 +360,7 @@ type Ethereum_TxResponse @imported(
gasPrice: BigInt
data: String!
value: BigInt!
chainId: UInt32!
chainId: BigInt!
blockNumber: BigInt
blockHash: String
timestamp: UInt32
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/__tests__/plugin/expected-types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface Ethereum_TxRequest {
gasPrice?: BigInt | null;
data?: String | null;
value?: BigInt | null;
chainId?: UInt32 | null;
chainId?: BigInt | null;
type?: UInt32 | null;
}

Expand Down Expand Up @@ -104,7 +104,7 @@ export interface Ethereum_EventNotification {
/* URI: "ens/ethereum.web3api.eth" */
export interface Ethereum_Network {
name: String;
chainId: Int;
chainId: BigInt;
ensAddress?: String | null;
}

Expand All @@ -118,7 +118,7 @@ export interface Ethereum_TxResponse {
gasPrice?: BigInt | null;
data: String;
value: BigInt;
chainId: UInt32;
chainId: BigInt;
blockNumber?: BigInt | null;
blockHash?: String | null;
timestamp?: UInt32 | null;
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/src/__tests__/project/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ type Ethereum_TxRequest @imported(
gasPrice: BigInt
data: String
value: BigInt
chainId: UInt32
chainId: BigInt
type: UInt32
}

Expand Down Expand Up @@ -265,7 +265,7 @@ type Ethereum_Network @imported(
nativeType: "Network"
) {
name: String!
chainId: Int!
chainId: BigInt!
ensAddress: String
}

Expand Down Expand Up @@ -424,7 +424,7 @@ type Ethereum_TxResponse @imported(
gasPrice: BigInt
data: String!
value: BigInt!
chainId: UInt32!
chainId: BigInt!
blockNumber: BigInt
blockHash: String
timestamp: UInt32
Expand Down Expand Up @@ -498,7 +498,7 @@ type Ethereum_TxRequest @imported(
gasPrice: BigInt
data: String
value: BigInt
chainId: UInt32
chainId: BigInt
type: UInt32
}

Expand Down Expand Up @@ -792,7 +792,7 @@ type Ethereum_TxRequest @imported(
gasPrice: BigInt
data: String
value: BigInt
chainId: UInt32
chainId: BigInt
type: UInt32
}

Expand Down Expand Up @@ -852,7 +852,7 @@ type Ethereum_Network @imported(
nativeType: "Network"
) {
name: String!
chainId: Int!
chainId: BigInt!
ensAddress: String
}

Expand All @@ -869,7 +869,7 @@ type Ethereum_TxResponse @imported(
gasPrice: BigInt
data: String!
value: BigInt!
chainId: UInt32!
chainId: BigInt!
blockNumber: BigInt
blockHash: String
timestamp: UInt32
Expand Down
6 changes: 3 additions & 3 deletions packages/js/plugins/ethereum/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type TxResponse {
gasPrice: BigInt
data: String!
value: BigInt!
chainId: UInt32!
chainId: BigInt!
blockNumber: BigInt
blockHash: String
timestamp: UInt32
Expand All @@ -48,7 +48,7 @@ type TxRequest {
gasPrice: BigInt
data: String
value: BigInt
chainId: UInt32
chainId: BigInt
type: UInt32
}

Expand Down Expand Up @@ -93,7 +93,7 @@ type Connection {

type Network {
name: String!
chainId: Int!
chainId: BigInt!
ensAddress: String
}

Expand Down
4 changes: 2 additions & 2 deletions packages/js/plugins/ethereum/src/__tests__/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ describe("Ethereum Plugin", () => {

expect(mainnetNetwork.data).toBeTruthy();
expect(mainnetNetwork.errors).toBeFalsy();
expect(mainnetNetwork.data?.getNetwork.chainId).toBe(1);
expect(mainnetNetwork.data?.getNetwork.chainId).toBe("1");
expect(mainnetNetwork.data?.getNetwork.name).toBe("homestead");
expect(mainnetNetwork.data?.getNetwork.ensAddress).toBe("0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e");

Expand All @@ -646,7 +646,7 @@ describe("Ethereum Plugin", () => {

expect(polygonNetwork.data).toBeTruthy();
expect(polygonNetwork.errors).toBeFalsy();
expect(polygonNetwork.data?.getNetwork.chainId).toBe(137);
expect(polygonNetwork.data?.getNetwork.chainId).toBe("137");
expect(polygonNetwork.data?.getNetwork.name).toBe("matic");
expect(polygonNetwork.data?.getNetwork.ensAddress).toBeFalsy();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/js/plugins/ethereum/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class EthereumPlugin extends Plugin {
const network = await provider.getNetwork();
return {
name: network.name,
chainId: network.chainId,
chainId: network.chainId.toString(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we serializing this automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be true if this were a wrapper, but in plugins the BigInt type is an alias for string. Here I'm changing the type from number to string.

ensAddress: network.ensAddress,
};
}
Expand Down
6 changes: 3 additions & 3 deletions packages/js/plugins/ethereum/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const toTxResponse = (
gasPrice: response.gasPrice?.toString(),
data: response.data,
value: response.value.toString(),
chainId: response.chainId,
chainId: response.chainId.toString(),
blockNumber: response.blockNumber?.toString(),
blockHash: response.blockHash,
timestamp: response.timestamp,
Expand All @@ -80,7 +80,7 @@ export const toTxRequest = (
gasPrice: request.gasPrice?.toString(),
data: request.data?.toString(),
value: request.value?.toString(),
chainId: request.chainId,
chainId: request.chainId?.toString(),
type: request.type,
});

Expand All @@ -98,7 +98,7 @@ export const fromTxRequest = (
: undefined,
data: request.data || undefined,
value: request.value ? ethers.BigNumber.from(request.value) : undefined,
chainId: request.chainId || undefined,
chainId: request.chainId ? Number.parseInt(request.chainId) : undefined,
type: request.type || undefined,
});

Expand Down