Skip to content

Commit

Permalink
Merge pull request #274 from Web3-API/prealpha-dev
Browse files Browse the repository at this point in the history
Prep 0.0.1-prealpha.14
  • Loading branch information
dOrgJelli authored Apr 12, 2021
2 parents c43fbd8 + 0f28683 commit 0be151d
Show file tree
Hide file tree
Showing 60 changed files with 797 additions and 299 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Web3API 0.0.1-prealpha.14
## Features
* Network Specific ENS Lookup
* `@web3api/ethereum-plugin-js`: The EthereumPlugin can now be constructed with multiple network connections (mainnet, rinkeby, testnet, etc).
* All Query & Mutation methods now accept an optional `connection` property which can be used to configure a specific network to be used for the action.
* `@web3api/ens-plugin-js`: The EnsPlugin can now handle URIs that address specific networks. For example: `w3://ens/testnet/myweb3api.eth`. It will request the `testnet` connection to be used when querying the Ethereum Web3API.

# Web3API 0.0.1-prealpha.13
## Features
* Improved template projects that are used with the `w3 create ...` CLI command.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1-prealpha.13
0.0.1-prealpha.14
8 changes: 6 additions & 2 deletions packages/cli/src/__tests__/e2e/query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ ${HELP}`);
cwd: projectRoot
}, "../../../bin/w3");

expect(buildCode).toEqual(0);
expect(buildErr).toBe("");
expect(buildCode).toEqual(0);

const { exitCode: code, stdout: output, stderr: queryErr } = await runCLI({
args: ["query", "./recipes/e2e.json", "--test-ens"],
Expand All @@ -72,6 +72,9 @@ mutation {
address: $address
value: $value
}
connection: {
networkNameOrChainId: $network
}
) {
value
txReceipt
Expand All @@ -80,7 +83,8 @@ mutation {
{
"address": "${constants.SimpleStorageAddr}",
"value": 569
"value": 569,
"network": "testnet"
}
-----------------------------------
-----------------------------------
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/__tests__/project/deploy-contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ async function main() {
const contractAbi = require(`${__dirname}/src/contracts/SimpleStorage.json`);

const eth = new EthereumPlugin({
provider: "http://localhost:8545"
testnet: {
provider: "http://localhost:8545"
}
});

const address = await eth.deployContract(
contractAbi.abi, `0x${contractAbi.bytecode.object}`
contractAbi.abi, `0x${contractAbi.bytecode.object}`, [], {
networkNameOrChainId: "testnet"
}
);

console.log(`✔️ SimpleStorage live at: ${address}`)
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/__tests__/project/recipes/e2e.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[
{
"api": "ens/simplestorage.eth",
"api": "ens/testnet/simplestorage.eth",
"constants": "./constants.json"
},
{
"query": "./set.graphql",
"variables": {
"address": "$SimpleStorageAddr",
"value": 569
"value": 569,
"network": "testnet"
}
}
]
3 changes: 3 additions & 0 deletions packages/cli/src/__tests__/project/recipes/get.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
query {
getData(
address: $address
connection: {
networkNameOrChainId: $network
}
)
}
3 changes: 3 additions & 0 deletions packages/cli/src/__tests__/project/recipes/set.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ mutation {
address: $address
value: $value
}
connection: {
networkNameOrChainId: $network
}
) {
value
txReceipt
Expand Down
67 changes: 57 additions & 10 deletions packages/cli/src/__tests__/project/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export const composedSchema = {
"\n" +
"type Query @imports(\n" +
" types: [\n" +
' "Ethereum_Query"\n' +
' "Ethereum_Query",\n' +
' "Ethereum_Connection"\n' +
" ]\n" +
") {\n" +
" getData(\n" +
" address: String!\n" +
" connection: Ethereum_Connection\n" +
" ): UInt32!\n" +
"}\n" +
"\n" +
Expand All @@ -44,14 +46,24 @@ export const composedSchema = {
" callView(\n" +
" address: String!\n" +
" method: String!\n" +
" args: [String!]!\n" +
" args: [String!]\n" +
" connection: Ethereum_Connection\n" +
" ): String!\n" +
"}\n" +
"\n" +
"### Imported Queries END ###\n" +
"\n" +
"### Imported Objects START ###\n" +
"\n" +
"type Ethereum_Connection @imported(\n" +
" uri: \"w3://ens/ethereum.web3api.eth\",\n" +
" namespace: \"Ethereum\",\n" +
" nativeType: \"Connection\"\n" +
") {\n" +
" node: String\n" +
" networkNameOrChainId: String\n" +
"}\n" +
"\n" +
"### Imported Objects END ###\n",
mutation:
"### Web3API Header START ###\n" +
Expand Down Expand Up @@ -80,14 +92,18 @@ export const composedSchema = {
"\n" +
"type Mutation @imports(\n" +
" types: [\n" +
' "Ethereum_Mutation"\n' +
' "Ethereum_Mutation",\n' +
' "Ethereum_Connection"\n' +
" ]\n" +
") {\n" +
" setData(\n" +
" options: SetDataOptions!\n" +
" connection: Ethereum_Connection\n" +
" ): SetDataResult!\n" +
"\n" +
" deployContract: String!\n" +
" deployContract(\n" +
" connection: Ethereum_Connection\n" +
" ): String!\n" +
"}\n" +
"\n" +
"type SetDataOptions {\n" +
Expand All @@ -110,19 +126,31 @@ export const composedSchema = {
" sendTransaction(\n" +
" address: String!\n" +
" method: String!\n" +
" args: [String!]!\n" +
" args: [String!]\n" +
" connection: Ethereum_Connection\n" +
" ): String!\n" +
"\n" +
" deployContract(\n" +
" abi: String!\n" +
" bytecode: String!\n" +
" args: [String!]\n" +
" connection: Ethereum_Connection\n" +
" ): String!\n" +
"}\n" +
"\n" +
"### Imported Queries END ###\n" +
"\n" +
"### Imported Objects START ###\n" +
"\n" +
"type Ethereum_Connection @imported(\n" +
" uri: \"w3://ens/ethereum.web3api.eth\",\n" +
" namespace: \"Ethereum\",\n" +
" nativeType: \"Connection\"\n" +
") {\n" +
" node: String\n" +
" networkNameOrChainId: String\n" +
"}\n" +
"\n" +
"### Imported Objects END ###\n",
combined:
"### Web3API Header START ###\n" +
Expand Down Expand Up @@ -151,24 +179,30 @@ export const composedSchema = {
"\n" +
"type Query @imports(\n" +
" types: [\n" +
' "Ethereum_Query"\n' +
' "Ethereum_Query",\n' +
' "Ethereum_Connection"\n' +
" ]\n" +
") {\n" +
" getData(\n" +
" address: String!\n" +
" connection: Ethereum_Connection\n" +
" ): UInt32!\n" +
"}\n" +
"\n" +
"type Mutation @imports(\n" +
" types: [\n" +
' "Ethereum_Mutation"\n' +
' "Ethereum_Mutation",\n' +
' "Ethereum_Connection"\n' +
" ]\n" +
") {\n" +
" setData(\n" +
" options: SetDataOptions!\n" +
" connection: Ethereum_Connection\n" +
" ): SetDataResult!\n" +
"\n" +
" deployContract: String!\n" +
" deployContract(\n" +
" connection: Ethereum_Connection\n" +
" ): String!\n" +
"}\n" +
"\n" +
"type SetDataOptions {\n" +
Expand All @@ -191,7 +225,8 @@ export const composedSchema = {
" callView(\n" +
" address: String!\n" +
" method: String!\n" +
" args: [String!]!\n" +
" args: [String!]\n" +
" connection: Ethereum_Connection\n" +
" ): String!\n" +
"}\n" +
"\n" +
Expand All @@ -203,18 +238,30 @@ export const composedSchema = {
" sendTransaction(\n" +
" address: String!\n" +
" method: String!\n" +
" args: [String!]!\n" +
" args: [String!]\n" +
" connection: Ethereum_Connection\n" +
" ): String!\n" +
"\n" +
" deployContract(\n" +
" abi: String!\n" +
" bytecode: String!\n" +
" args: [String!]\n" +
" connection: Ethereum_Connection\n" +
" ): String!\n" +
"}\n" +
"\n" +
"### Imported Queries END ###\n" +
"\n" +
"### Imported Objects START ###\n" +
"\n" +
"type Ethereum_Connection @imported(\n" +
" uri: \"w3://ens/ethereum.web3api.eth\",\n" +
" namespace: \"Ethereum\",\n" +
" nativeType: \"Connection\"\n" +
") {\n" +
" node: String\n" +
" networkNameOrChainId: String\n" +
"}\n" +
"\n" +
"### Imported Objects END ###\n",
};
11 changes: 7 additions & 4 deletions packages/cli/src/__tests__/project/src/mutation/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Ethereum_Mutation } from "./w3/imported";
import { Input_setData, SetDataResult } from "./w3";
import { Input_setData, Input_deployContract, SetDataResult } from "./w3";

export function setData(input: Input_setData): SetDataResult {
const hash = Ethereum_Mutation.sendTransaction({
address: input.options.address,
method: "function set(uint256 value)",
args: [input.options.value.toString()]
args: [input.options.value.toString()],
connection: input.connection
});

return {
Expand All @@ -14,9 +15,11 @@ export function setData(input: Input_setData): SetDataResult {
};
}

export function deployContract(): string {
export function deployContract(input: Input_deployContract): string {
return Ethereum_Mutation.deployContract({
abi: `[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"from","type":"address"}],"name":"DataSet","type":"event"},{"inputs":[],"name":"get","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"set","outputs":[],"stateMutability":"nonpayable","type":"function"}]`,
bytecode: "0x608060405234801561001057600080fd5b5061012a806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806360fe47b11460375780636d4ce63c146062575b600080fd5b606060048036036020811015604b57600080fd5b8101908080359060200190929190505050607e565b005b606860eb565b6040518082815260200191505060405180910390f35b806000819055507f3d38713ec8fb49acced894a52df2f06a371a15960550da9ba0f017cb7d07a8ec33604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a150565b6000805490509056fea2646970667358221220f312fe8d32f77c74cc4eb4a1f5c805d8bb124755ca4e8a1db2cce10cbb133dc564736f6c63430006060033"
bytecode: "0x608060405234801561001057600080fd5b5061012a806100206000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806360fe47b11460375780636d4ce63c146062575b600080fd5b606060048036036020811015604b57600080fd5b8101908080359060200190929190505050607e565b005b606860eb565b6040518082815260200191505060405180910390f35b806000819055507f3d38713ec8fb49acced894a52df2f06a371a15960550da9ba0f017cb7d07a8ec33604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a150565b6000805490509056fea2646970667358221220f312fe8d32f77c74cc4eb4a1f5c805d8bb124755ca4e8a1db2cce10cbb133dc564736f6c63430006060033",
args: null,
connection: input.connection
});
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#import { Mutation } into Ethereum from "w3://ens/ethereum.web3api.eth"
#import { Mutation, Connection } into Ethereum from "w3://ens/ethereum.web3api.eth"

type Mutation {
setData(
options: SetDataOptions!
connection: Ethereum_Connection
): SetDataResult!

deployContract: String!
deployContract(
connection: Ethereum_Connection
): String!
}

type SetDataOptions {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/__tests__/project/src/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export function getData(input: Input_getData): u32 {
const res = Ethereum_Query.callView({
address: input.address,
method: "function get() view returns (uint256)",
args: []
args: null,
connection: input.connection
});

return U32.parseInt(res);
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/__tests__/project/src/query/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#import { Query } into Ethereum from "w3://ens/ethereum.web3api.eth"
#import { Query, Connection } into Ethereum from "w3://ens/ethereum.web3api.eth"

type Query {
getData(
address: String!
connection: Ethereum_Connection
): UInt32!
}
Loading

0 comments on commit 0be151d

Please sign in to comment.