Skip to content

Commit

Permalink
Merge pull request #1143 from polywrap/eth-plugin-connections-store
Browse files Browse the repository at this point in the history
Modify Ethereum plugin config to use Connections store
  • Loading branch information
dOrgJelli authored Aug 24, 2022
2 parents 67b7f0b + 71d7061 commit c6fbcfc
Show file tree
Hide file tree
Showing 24 changed files with 646 additions and 333 deletions.
18 changes: 10 additions & 8 deletions packages/cli/src/__tests__/e2e/deploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@polywrap/test-env-js";
import { GetPathToCliTestFiles } from "@polywrap/test-cases";
import { PolywrapClient } from "@polywrap/client-js";
import { ethereumPlugin } from "@polywrap/ethereum-plugin-js";
import { ethereumPlugin, Connections, Connection } from "@polywrap/ethereum-plugin-js";
import { Wallet } from "@ethersproject/wallet";
import path from "path";
import fs from "fs";
Expand Down Expand Up @@ -60,13 +60,15 @@ const setup = async (domainNames: string[]) => {
{
uri: ethereumPluginUri,
plugin: ethereumPlugin({
networks: {
testnet: {
provider: providers.ethereum,
signer
}
},
defaultNetwork: "testnet"
connections: new Connections({
networks: {
testnet: new Connection({
provider: providers.ethereum,
signer,
}),
},
defaultNetwork: "testnet",
}),
}),
}
],
Expand Down
20 changes: 13 additions & 7 deletions packages/cli/src/lib/defaults/deploy-modules/ens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { JsonRpcProvider } from "@ethersproject/providers";
import { Uri } from "@polywrap/core-js";
import { PolywrapClient } from "@polywrap/client-js";
import path from "path";
import { ethereumPlugin } from "@polywrap/ethereum-plugin-js";
import {
ethereumPlugin,
Connections,
Connection,
} from "@polywrap/ethereum-plugin-js";

const contentHash = require("content-hash");

Expand Down Expand Up @@ -53,13 +57,15 @@ class ENSPublisher implements Deployer {
{
uri: ethereumPluginUri,
plugin: ethereumPlugin({
networks: {
[network]: {
provider: config.provider,
signer,
connections: new Connections({
networks: {
[network]: new Connection({
provider: config.provider,
signer,
}),
},
},
defaultNetwork: network,
defaultNetwork: network,
}),
}),
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { Uri } from "@polywrap/core-js";
import { ensAddresses } from "@polywrap/test-env-js";
import path from "path";
import { PolywrapClient } from "@polywrap/client-js";
import { ethereumPlugin } from "@polywrap/ethereum-plugin-js";
import {
ethereumPlugin,
Connections,
Connection,
} from "@polywrap/ethereum-plugin-js";

const contentHash = require("content-hash");

Expand Down Expand Up @@ -35,12 +39,14 @@ class LocalDevENSPublisher implements Deployer {
{
uri: ethereumPluginUri,
plugin: ethereumPlugin({
networks: {
testnet: {
provider: `http://localhost:${config.ports.ethereum}`,
connections: new Connections({
networks: {
testnet: new Connection({
provider: `http://localhost:${config.ports.ethereum}`,
}),
},
},
defaultNetwork: "testnet",
defaultNetwork: "testnet",
}),
}),
},
],
Expand Down
16 changes: 11 additions & 5 deletions packages/cli/src/lib/helpers/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { PluginRegistration } from "@polywrap/core-js";
import { ensResolverPlugin } from "@polywrap/ens-resolver-plugin-js";
import { ethereumPlugin } from "@polywrap/ethereum-plugin-js";
import {
ethereumPlugin,
Connection,
Connections,
} from "@polywrap/ethereum-plugin-js";
import { ipfsPlugin } from "@polywrap/ipfs-plugin-js";
import { PolywrapClient } from "@polywrap/client-js";
import { defaultIpfsProviders } from "@polywrap/client-config-builder-js";
Expand Down Expand Up @@ -28,11 +32,13 @@ export function getSimpleClient(config: SimpleClientConfig): PolywrapClient {
plugins.push({
uri: "wrap://ens/ethereum.polywrap.eth",
plugin: ethereumPlugin({
networks: {
testnet: {
provider: ethProvider,
connections: new Connections({
networks: {
testnet: new Connection({
provider: ethProvider,
}),
},
},
}),
}),
});
}
Expand Down
16 changes: 11 additions & 5 deletions packages/cli/src/lib/test-env/client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { getTestEnvProviders } from "./providers";
import { PluginRegistration, PolywrapClientConfig } from "@polywrap/client-js";
import { defaultIpfsProviders } from "@polywrap/client-config-builder-js";
import { ensResolverPlugin } from "@polywrap/ens-resolver-plugin-js";
import { ethereumPlugin } from "@polywrap/ethereum-plugin-js";
import {
ethereumPlugin,
Connections,
Connection,
} from "@polywrap/ethereum-plugin-js";
import { ipfsPlugin } from "@polywrap/ipfs-plugin-js";
import { ensAddresses } from "@polywrap/test-env-js";

Expand All @@ -26,11 +30,13 @@ export async function getTestEnvClientConfig(): Promise<
{
uri: "wrap://ens/ethereum.polywrap.eth",
plugin: ethereumPlugin({
networks: {
testnet: {
provider: ethProvider,
connections: new Connections({
networks: {
testnet: new Connection({
provider: ethProvider,
}),
},
},
}),
}),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
import { WrapManifest } from "@polywrap/wrap-manifest-types-js";
import { ipfsPlugin } from "@polywrap/ipfs-plugin-js";
import { ipfsResolverPlugin } from "@polywrap/ipfs-resolver-plugin-js";
import { ethereumPlugin } from "@polywrap/ethereum-plugin-js";
import {
ethereumPlugin,
Connection,
Connections,
} from "@polywrap/ethereum-plugin-js";
import { ensResolverPlugin } from "@polywrap/ens-resolver-plugin-js";
import { graphNodePlugin } from "@polywrap/graph-node-plugin-js";
import { httpPlugin } from "@polywrap/http-plugin-js";
Expand Down Expand Up @@ -44,12 +48,14 @@ export const getDefaultClientConfig = (): ClientConfig<Uri> => {
{
uri: new Uri("wrap://ens/ethereum.polywrap.eth"),
plugin: ethereumPlugin({
networks: {
mainnet: {
provider:
"https://mainnet.infura.io/v3/b00b2c2cc09c487685e9fb061256d6a6",
connections: new Connections({
networks: {
mainnet: new Connection({
provider:
"https://mainnet.infura.io/v3/b00b2c2cc09c487685e9fb061256d6a6",
}),
},
},
}),
}),
},
{
Expand Down
15 changes: 14 additions & 1 deletion packages/js/client/scripts/extractPluginConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,29 @@ const plugins: PluginConfigSource[] = [
},
{
name: "build/Connection.d.ts",
interfaces: ["ConnectionConfig", "ConnectionConfigs"],
interfaces: ["ConnectionConfig"],
types: [
"EthereumProvider",
"EthereumSigner",
"AccountIndex",
"Address",
],
},
{
name: "build/Connections.d.ts",
interfaces: ["ConnectionsConfig"],
types: ["Networks"],
},
],
externals: [
{
type: "Connection",
module: "@polywrap/ethereum-plugin-js"
},
{
type: "Connections",
module: "@polywrap/ethereum-plugin-js"
},
{
type: "Signer",
module: "ethers",
Expand Down
18 changes: 10 additions & 8 deletions packages/js/client/src/__tests__/utils/getClientWithEnsAndIpfs.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { createPolywrapClient, PolywrapClientConfig } from "../..";
import { ensAddresses, providers } from "@polywrap/test-env-js";
import { Connection, Connections } from "@polywrap/ethereum-plugin-js";

export const getClientWithEnsAndIpfs = async (
config?: Partial<PolywrapClientConfig>
) => {
const connections: Connections = new Connections({
networks: {
testnet: new Connection({
provider: providers.ethereum,
}),
},
defaultNetwork: "testnet",
});
return createPolywrapClient(
{
ethereum: {
networks: {
testnet: {
provider: providers.ethereum,
},
},
defaultNetwork: "testnet",
},
ethereum: { connections },
ipfs: { provider: providers.ipfs },
ens: {
addresses: {
Expand Down
24 changes: 17 additions & 7 deletions packages/js/client/src/pluginConfigs/Ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@
/* eslint-disable prettier/prettier */

/// Types generated from @polywrap/ethereum-plugin-js build files:
/// build/index.d.ts, build/Connection.d.ts
/// build/index.d.ts, build/Connection.d.ts, build/Connections.d.ts

export interface EthereumPluginConfig {
networks: ConnectionConfigs;
defaultNetwork?: string;
connections: Connections;
}

export interface ConnectionConfig {
provider: EthereumProvider;
signer?: EthereumSigner;
}

export interface ConnectionConfigs {
[network: string]: ConnectionConfig;
}

export type EthereumProvider = string | ExternalProvider | JsonRpcProvider;

export type EthereumSigner = Signer | Address | AccountIndex;
Expand All @@ -27,6 +22,21 @@ export type AccountIndex = number;

export type Address = string;

export interface ConnectionsConfig {
networks: Networks;
defaultNetwork?: string;
}

type Networks = {
[network: string]: Connection;
};

// import { Connection } from "@polywrap/ethereum-plugin-js"
export type Connection = any;

// import { Connections } from "@polywrap/ethereum-plugin-js"
export type Connections = any;

// import { Signer } from "ethers"
export type Signer = any;

Expand Down
30 changes: 13 additions & 17 deletions packages/js/plugins/ethereum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ensAddresses,
providers
} from "@polywrap/test-env-js";
import { ethereumPlugin } from "@polywrap/ethereum-plugin-js";
import { ethereumPlugin, Connections, Connection } from "@polywrap/ethereum-plugin-js";
import { ipfsPlugin } from "@polywrap/ipfs-plugin-js";
import { ensPlugin } from "@polywrap/ens-plugin-js";

Expand All @@ -24,19 +24,22 @@ export async function foo({

const ethereumPluginURI = "wrap://ens/ipfs.polywrap.eth"

// initialize Ethereum Connections store
const connections: Connections = new Connections({
networks: {
testnet: new Connection({
provider: providers.ethereum,
}),
},
defaultNetwork: "testnet",
});

// initialize the client with eth, ipfs, ens plugins
client = new PolywrapClient({
plugins: [
{
uri: ethereumPluginURI,
plugin: ethereumPlugin({
networks: {
testnet: {
provider: providers.ethereum,
},
},
defaultNetwork: "testnet",
}),
plugin: ethereumPlugin({ connections }),
},
{
uri: "wrap://ens/ipfs.polywrap.eth",
Expand Down Expand Up @@ -72,14 +75,7 @@ export async function foo({
});

// or instantiate the plugin
const plugin = ethereumPlugin({
networks: {
testnet: {
provider: providers.ethereum,
},
},
defaultNetwork: "testnet",
});
const plugin = ethereumPlugin({ connections });

// and send invocations to ethereum
const signerAddressQuery' = plugin.getSignerAddress(client)
Expand Down
Loading

0 comments on commit c6fbcfc

Please sign in to comment.