Skip to content

Commit

Permalink
Merge pull request #7 from vechainfoundation/v0.0.2
Browse files Browse the repository at this point in the history
V0.0.2
  • Loading branch information
andreas-papageorgiou authored May 8, 2023
2 parents a9cb94b + e4e4cff commit af96959
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 24 deletions.
6 changes: 3 additions & 3 deletions packages/ethers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vechain/hardhat-ethers",
"version": "0.0.1",
"version": "0.0.2",
"license": "MIT",
"description": "Hardhat Vechain Ethers Plugin",
"repository": "github:vechainfoundation/hardhat-plugins",
Expand All @@ -18,13 +18,13 @@
"ethers": "^5.0.0",
"hardhat": "^2.12.7",
"@nomiclabs/hardhat-ethers": "^2.2.2",
"@vechain/hardhat-vechain": "^0.0.1"
"@vechain/hardhat-vechain": "^0.0.2"
},
"peerDependencies": {
"ethers": "^5.0.0",
"hardhat": "^2.12.7",
"@nomiclabs/hardhat-ethers": "^2.2.2",
"@vechain/hardhat-vechain": "^0.0.1"
"@vechain/hardhat-vechain": "^0.0.2"
}
}

12 changes: 7 additions & 5 deletions packages/vechain/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vechain/hardhat-vechain",
"version": "0.0.1",
"version": "0.0.2",
"description": "Hardhat plugin for a VeChain provider",
"homepage": "https://github.com/vechainfoundation/hardhat-plugins",
"repository": "github:vechainfoundation/hardhat-plugins",
Expand All @@ -15,16 +15,18 @@
"build": "tsc --build"
},
"dependencies": {
"ethers": "^5.7.2",
"thor-devkit": "^2.0.6",
"@vechain/connex-driver": "^2.0.12",
"@vechain/connex-framework": "^2.0.12",
"@vechain/web3-providers-connex": "^1.0.0"
"@vechain/web3-providers-connex": "^1.0.0",
"debug": "^4.3.4",
"ethers": "^5.7.2",
"thor-devkit": "^2.0.6"
},
"devDependencies": {
"@types/debug": "^4.1.7",
"hardhat": "^2.12.7"
},
"peerDependencies": {
"hardhat": "^2.12.7"
}
}
}
44 changes: 37 additions & 7 deletions packages/vechain/src/ConnexProviderWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import debug from "debug";
import { EventEmitter } from "events";
import {
NetworkConfig,
Expand All @@ -12,9 +13,13 @@ import { DelegateOpt } from "@vechain/web3-providers-connex/dist/types";

export default class ConnexProviderWrapper extends EventEmitter implements EthereumProvider {
private _provider: Promise<Provider>;
private _verbose: boolean;
private _log: debug.Debugger;

constructor(networkConfig: NetworkConfig) {
constructor(networkConfig: NetworkConfig, verbose: boolean) {
super();
this._log = debug("hardhat:vechain:provider");
this._verbose = verbose;
this._provider = createProvider(networkConfig);
this._provider
.then(provider => {
Expand Down Expand Up @@ -54,6 +59,13 @@ export default class ConnexProviderWrapper extends EventEmitter implements Ether
sendAsync(payload: JsonRpcRequest, callback: (error: any, response: JsonRpcResponse) => void): void {
this._provider
.then(provider => provider.request(payload))
.then(result => {
if (this._verbose) {
this._log(`Request:\n${JSON.stringify(payload)}`);
this._log(`Response:\n${JSON.stringify(result)}`);
}
return result;
})
.then(result => callback(
null,
{
Expand All @@ -62,17 +74,35 @@ export default class ConnexProviderWrapper extends EventEmitter implements Ether
result
}
))
.catch(error => callback(
error,
{
.catch(error => {
if (this._verbose) {
console.debug(`Request:\n${JSON.stringify(payload)}`);
console.error(`Error:\n${JSON.stringify(error)}`);
}
callback(error, {
id: payload.id,
jsonrpc: '2.0',
error
}
));
})
});
}

async request(args: RequestArguments): Promise<unknown> {
return this._provider.then(provider => provider.request(args as any));
return this._provider
.then(provider => provider.request(args as any))
.then(result => {
if (this._verbose) {
this._log(`Request:\n${JSON.stringify(args)}`);
this._log(`Response:\n${JSON.stringify(result)}`);
}
return result;
})
.catch(error => {
if (this._verbose) {
console.debug(`Request:\n${JSON.stringify(args)}`);
console.error(`Error:\n${JSON.stringify(error)}`);
}
throw error;
});
}
}
7 changes: 3 additions & 4 deletions packages/vechain/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export const VECHAIN_HARDHAT_PLUGIN_NAME = "vechain";

export const VECHAIN_DEFAULT_MNEMONIC = "denial kitchen pet squirrel other broom bar gas better priority spoil cross";
export const VECHAIN_URL_SOLO = "http://127.0.0.1:8669";
export const VECHAIN_DEFAULT_MNEMONIC = "denial kitchen pet squirrel other broom bar gas better priority spoil cross";

// TODO: set and expose correctly:
// export const VECHAIN_URL_TESTNET = "http://127.0.0.1:8669";
// export const VECHAIN_URL_MAINNET = "http://127.0.0.1:8669";
export const VECHAIN_URL_TESTNET = "https://vethor-node-test.vechaindev.com";
export const VECHAIN_URL_MAINNET = "https://vethor-node.vechain.com";
8 changes: 7 additions & 1 deletion packages/vechain/src/helpers/createProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import { createWallet } from "./createWallet";
export async function createProvider(networkConfig: NetworkConfig): Promise<Provider> {
const config = networkConfig as HttpNetworkConfig;

if (config.restful === undefined) {
config.restful = true;
}

const net = createNetwork(config);
const wallet = createWallet(config);

const driver = await Driver
.connect(net, wallet);
return new Provider({
connex: new Framework(driver),
wallet
wallet,
net: config.restful === true ? net : undefined,
delegate: config.delegate
});
}
3 changes: 2 additions & 1 deletion packages/vechain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ extendEnvironment(hre => {
if (hre.network.name !== "vechain") {
return;
}
hre.vechain = lazyObject(() => new ConnexProviderWrapper(hre.network.config));
hre.vechain = lazyObject(() => new ConnexProviderWrapper(hre.network.config, hre.hardhatArguments.verbose));
hre.network.provider = hre.vechain;
});

export * from "./constants";
6 changes: 3 additions & 3 deletions packages/web3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vechain/hardhat-web3",
"version": "0.0.1",
"version": "0.0.2",
"description": "Hardhat Vechain Web3 Plugin",
"repository": "github:vechainfoundation/hardhat-plugins",
"author": "Electi Consulting LTD",
Expand All @@ -23,12 +23,12 @@
"web3": "^1.0.0-beta.36",
"hardhat": "^2.12.7",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@vechain/hardhat-vechain": "^0.0.1"
"@vechain/hardhat-vechain": "^0.0.2"
},
"peerDependencies": {
"web3": "^1.0.0-beta.36",
"hardhat": "^2.12.7",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@vechain/hardhat-vechain": "^0.0.1"
"@vechain/hardhat-vechain": "^0.0.2"
}
}

0 comments on commit af96959

Please sign in to comment.