From 975d6ee145966f260f41ce55e470cc6db11307fd Mon Sep 17 00:00:00 2001 From: Andreas Papageorgiou Date: Thu, 27 Apr 2023 17:11:45 +0300 Subject: [PATCH 1/6] use restful and wallet on construction --- packages/vechain/src/helpers/createProvider.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/vechain/src/helpers/createProvider.ts b/packages/vechain/src/helpers/createProvider.ts index 4b15dba..d3618a3 100644 --- a/packages/vechain/src/helpers/createProvider.ts +++ b/packages/vechain/src/helpers/createProvider.ts @@ -9,6 +9,10 @@ import { createWallet } from "./createWallet"; export async function createProvider(networkConfig: NetworkConfig): Promise { const config = networkConfig as HttpNetworkConfig; + if (config.restful === undefined) { + config.restful = true; + } + const net = createNetwork(config); const wallet = createWallet(config); @@ -16,6 +20,8 @@ export async function createProvider(networkConfig: NetworkConfig): Promise Date: Thu, 27 Apr 2023 17:12:28 +0300 Subject: [PATCH 2/6] make hre.network.provider = hre.vechain --- packages/vechain/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vechain/src/index.ts b/packages/vechain/src/index.ts index dc2614b..a47a12f 100644 --- a/packages/vechain/src/index.ts +++ b/packages/vechain/src/index.ts @@ -7,6 +7,7 @@ extendEnvironment(hre => { return; } hre.vechain = lazyObject(() => new ConnexProviderWrapper(hre.network.config)); + hre.network.provider = hre.vechain; }); export * from "./constants"; \ No newline at end of file From babef66f0a2d45d8dcaeb74bef8c31b0f1470565 Mon Sep 17 00:00:00 2001 From: Andreas Papageorgiou Date: Thu, 27 Apr 2023 17:13:03 +0300 Subject: [PATCH 3/6] add testnet and mainnet urls --- packages/vechain/src/constants.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/vechain/src/constants.ts b/packages/vechain/src/constants.ts index a6b708a..f1445b2 100644 --- a/packages/vechain/src/constants.ts +++ b/packages/vechain/src/constants.ts @@ -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"; \ No newline at end of file +export const VECHAIN_URL_TESTNET = "https://vethor-node-test.vechaindev.com"; +export const VECHAIN_URL_MAINNET = "https://vethor-node.vechain.com"; \ No newline at end of file From 987f0dde89ed289275d1fd6eb23965361b1325e3 Mon Sep 17 00:00:00 2001 From: Andreas Papageorgiou Date: Wed, 3 May 2023 10:18:36 +0300 Subject: [PATCH 4/6] add verbose option --- packages/vechain/src/ConnexProviderWrapper.ts | 41 +++++++++++++++---- packages/vechain/src/index.ts | 2 +- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/packages/vechain/src/ConnexProviderWrapper.ts b/packages/vechain/src/ConnexProviderWrapper.ts index 6c62d76..06d44bb 100644 --- a/packages/vechain/src/ConnexProviderWrapper.ts +++ b/packages/vechain/src/ConnexProviderWrapper.ts @@ -12,9 +12,11 @@ import { DelegateOpt } from "@vechain/web3-providers-connex/dist/types"; export default class ConnexProviderWrapper extends EventEmitter implements EthereumProvider { private _provider: Promise; + private _verbose: boolean; - constructor(networkConfig: NetworkConfig) { + constructor(networkConfig: NetworkConfig, verbose: boolean) { super(); + this._verbose = verbose; this._provider = createProvider(networkConfig); this._provider .then(provider => { @@ -54,6 +56,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) { + console.debug(`Request:\n${payload}`); + console.debug(`Response:\n${result}`); + } + return result; + }) .then(result => callback( null, { @@ -62,17 +71,35 @@ export default class ConnexProviderWrapper extends EventEmitter implements Ether result } )) - .catch(error => callback( - error, - { + .catch(error => { + if (this._verbose) { + console.debug(`Request:\n${payload}`); + console.error(`Error:\n${error}`); + } + callback(error, { id: payload.id, jsonrpc: '2.0', error - } - )); + }) + }); } async request(args: RequestArguments): Promise { - 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) { + console.debug(`Request:\n${args}`); + console.debug(`Response:\n${result}`); + } + return result; + }) + .catch(error => { + if (this._verbose) { + console.debug(`Request:\n${args}`); + console.error(`Error:\n${error}`); + } + throw error; + }); } } \ No newline at end of file diff --git a/packages/vechain/src/index.ts b/packages/vechain/src/index.ts index a47a12f..2380c23 100644 --- a/packages/vechain/src/index.ts +++ b/packages/vechain/src/index.ts @@ -6,7 +6,7 @@ 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; }); From 04f886b13b3dcff1439eb0f32f9dbde37490b78d Mon Sep 17 00:00:00 2001 From: Andreas Papageorgiou Date: Mon, 8 May 2023 16:25:04 +0300 Subject: [PATCH 5/6] update versions --- packages/ethers/package.json | 6 +++--- packages/vechain/package.json | 2 +- packages/web3/package.json | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/ethers/package.json b/packages/ethers/package.json index 1227685..dc394d1 100644 --- a/packages/ethers/package.json +++ b/packages/ethers/package.json @@ -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", @@ -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" } } \ No newline at end of file diff --git a/packages/vechain/package.json b/packages/vechain/package.json index b2f0ccc..0b964b7 100644 --- a/packages/vechain/package.json +++ b/packages/vechain/package.json @@ -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", diff --git a/packages/web3/package.json b/packages/web3/package.json index 0d8bfcf..f2e2a21 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -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", @@ -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" } } \ No newline at end of file From e4e4cff34ce9c27b90d108877881c4ea15bb175f Mon Sep 17 00:00:00 2001 From: Andreas Papageorgiou Date: Mon, 8 May 2023 16:56:31 +0300 Subject: [PATCH 6/6] use debug package --- packages/vechain/package.json | 10 ++++++---- packages/vechain/src/ConnexProviderWrapper.ts | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/vechain/package.json b/packages/vechain/package.json index 0b964b7..198b86e 100644 --- a/packages/vechain/package.json +++ b/packages/vechain/package.json @@ -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" } -} \ No newline at end of file +} diff --git a/packages/vechain/src/ConnexProviderWrapper.ts b/packages/vechain/src/ConnexProviderWrapper.ts index 06d44bb..3f6caba 100644 --- a/packages/vechain/src/ConnexProviderWrapper.ts +++ b/packages/vechain/src/ConnexProviderWrapper.ts @@ -1,3 +1,4 @@ +import debug from "debug"; import { EventEmitter } from "events"; import { NetworkConfig, @@ -13,9 +14,11 @@ import { DelegateOpt } from "@vechain/web3-providers-connex/dist/types"; export default class ConnexProviderWrapper extends EventEmitter implements EthereumProvider { private _provider: Promise; private _verbose: boolean; + private _log: debug.Debugger; constructor(networkConfig: NetworkConfig, verbose: boolean) { super(); + this._log = debug("hardhat:vechain:provider"); this._verbose = verbose; this._provider = createProvider(networkConfig); this._provider @@ -58,8 +61,8 @@ export default class ConnexProviderWrapper extends EventEmitter implements Ether .then(provider => provider.request(payload)) .then(result => { if (this._verbose) { - console.debug(`Request:\n${payload}`); - console.debug(`Response:\n${result}`); + this._log(`Request:\n${JSON.stringify(payload)}`); + this._log(`Response:\n${JSON.stringify(result)}`); } return result; }) @@ -73,8 +76,8 @@ export default class ConnexProviderWrapper extends EventEmitter implements Ether )) .catch(error => { if (this._verbose) { - console.debug(`Request:\n${payload}`); - console.error(`Error:\n${error}`); + console.debug(`Request:\n${JSON.stringify(payload)}`); + console.error(`Error:\n${JSON.stringify(error)}`); } callback(error, { id: payload.id, @@ -89,15 +92,15 @@ export default class ConnexProviderWrapper extends EventEmitter implements Ether .then(provider => provider.request(args as any)) .then(result => { if (this._verbose) { - console.debug(`Request:\n${args}`); - console.debug(`Response:\n${result}`); + 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${args}`); - console.error(`Error:\n${error}`); + console.debug(`Request:\n${JSON.stringify(args)}`); + console.error(`Error:\n${JSON.stringify(error)}`); } throw error; });