From 71dc5c9ed7d0ee28e3f9df410ec8088bf43b2d61 Mon Sep 17 00:00:00 2001 From: ebadiere Date: Mon, 21 Oct 2024 10:38:19 -0600 Subject: [PATCH 1/3] feat: Added spending plans for testing on testnet. Signed-off-by: ebadiere feat: Moved create aliases script to the sctrips directory. Signed-off-by: ebadiere feat: Moved create alias accounts script to root ./scripts directory. Signed-off-by: ebadiere --- package.json | 6 +- .../server/tests/testnetSpendingPlans.json | 28 ++++++++ scripts/createAliasAccounts.js | 71 +++++++++++++++++++ 3 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 packages/server/tests/testnetSpendingPlans.json create mode 100644 scripts/createAliasAccounts.js diff --git a/package.json b/package.json index 5aed51725b..e3ed5b33e3 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "axios-mock-adapter": "^1.20.0", "chai-as-promised": "^7.1.1", "chai-exclude": "^2.1.1", + "env-cmd": "^10.1.0", "eslint": "^8.48.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-prettier": "^8.3.0", @@ -79,7 +80,8 @@ "test": "npx lerna run test", "openrpctest": "ts-mocha packages/relay/tests/lib/openrpc.spec.ts --exit", "bump-version": "SEM_VER=${npm_config_semver} SNAPSHOT=${npm_config_snapshot} node scripts/.bump-version.js", - "prepare": "husky install" + "prepare": "husky install", + "create-alias-accounts": "env-cmd node ./scripts/createAliasAccounts.js" }, "dependencies": { "@ethereumjs/rlp": "^5.0.2", @@ -91,8 +93,8 @@ "lerna": "^8.1.8", "pino": "^7.11.0", "pino-pretty": "^7.6.1", - "prom-client": "^14.0.1", "pnpm": "^8.7.1", + "prom-client": "^14.0.1", "redis": "^4.7.0" }, "overrides": { diff --git a/packages/server/tests/testnetSpendingPlans.json b/packages/server/tests/testnetSpendingPlans.json new file mode 100644 index 0000000000..99c4f35b57 --- /dev/null +++ b/packages/server/tests/testnetSpendingPlans.json @@ -0,0 +1,28 @@ +[ + { + "id": "c758c095-342c-4607-9db5-867d7e90ab9d", + "name": "partner name", + "ethAddresses": ["0x7d102fe71af42790fe31b126c1f49766376ca2b5", "0x4ad27ba9330cb336b0ee38bfb5b86da015500342"], + "ipAddresses": ["127.0.0.1", "128.0.0.1"], + "subscriptionTier": "PRIVILEGED" + }, + { + "id": "a68488b0-6f7d-44a0-87c1-774ad64615f2", + "name": "some other partner that has given us only eth addresses", + "ethAddresses": ["0x40183ec818c1826114767391989ff2eaebc2b91e", "0x1fd56166627bee3fc51c0918451e3391f463219c"], + "subscriptionTier": "PRIVILEGED" + }, + { + "id": "af13d6ed-d676-4d33-8b9d-cf05d1ad7134", + "name": "supported project name", + "ethAddresses": ["0x421e224dfe6717d94a03ce23741c2d7c6009f2dc", "0x149294f355f62827748988071de70ab195d0eb23"], + "ipAddresses": ["129.0.0.1", "130.0.0.1"], + "subscriptionTier": "EXTENDED" + }, + { + "id": "7f665aa3-6b73-41d7-bf9b-92d04cdab96b", + "name": "some other supported project that has given us only ip addresses", + "ipAddresses": ["131.0.0.1", "132.0.0.1"], + "subscriptionTier": "EXTENDED" + } + ] diff --git a/scripts/createAliasAccounts.js b/scripts/createAliasAccounts.js new file mode 100644 index 0000000000..013e8da84d --- /dev/null +++ b/scripts/createAliasAccounts.js @@ -0,0 +1,71 @@ +/*- + * + * Hedera JSON RPC Relay + * + * Copyright (C) 2022-2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +const { Client, PrivateKey, TransferTransaction, AccountId, Hbar } = require('@hashgraph/sdk'); +const { exit } = require('process'); + +const operatorAccountId = process.env.OPERATOR_ID_MAIN; +const operatorPrivateKey = process.env.OPERATOR_KEY_MAIN; + + +if (!operatorAccountId || !operatorPrivateKey) { + throw new Error('Operator ID and Private Key must be set.'); +} + +const client = Client.forTestnet(); +client.setOperator(operatorAccountId, operatorPrivateKey); + +const numberOfAccounts = 4; + +// Initial balance for each new account (in tinybars) +const initialBalanceTinybar = Hbar.fromTinybars(1000000000); // Equivalent to 10 HBAR + +async function main() { + + for (let i = 1; i <= numberOfAccounts; i++) { + console.log(`\n=== Creating Alias Account ${i} ===`); + + const privateKey = PrivateKey.generateECDSA(); + const publicKey = privateKey.publicKey; + + console.log(`Generated ECDSA Private Key: ${privateKey.toStringRaw()}`); + console.log(`Generated ECDSA Public Key: ${publicKey.toStringRaw()}`); + + const ethereumAddress = publicKey.toEthereumAddress(); + + console.log(`Ethereum Address: 0x${ethereumAddress.toString()}`); + + const aliasAccountId = AccountId.fromEvmAddress(0, 0, ethereumAddress); + + const transferTx = await new TransferTransaction() + .addHbarTransfer(operatorAccountId, initialBalanceTinybar.negated()) + .addHbarTransfer(aliasAccountId, initialBalanceTinybar) + .execute(client); + + const receipt = await transferTx.getReceipt(client); + console.log(`Transfer Transaction Status: ${receipt.status.toString()}`); + + } + + exit(); +} + +main().catch((error) => { + console.error('Error creating alias accounts:', error); +}); From 2a1dadeac7916cd63b521675f9029af4fcec024c Mon Sep 17 00:00:00 2001 From: ebadiere Date: Mon, 21 Oct 2024 13:07:00 -0600 Subject: [PATCH 2/3] feat: Added condition for either previewnet or testnet. Signed-off-by: ebadiere --- scripts/createAliasAccounts.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/createAliasAccounts.js b/scripts/createAliasAccounts.js index 013e8da84d..f09a198787 100644 --- a/scripts/createAliasAccounts.js +++ b/scripts/createAliasAccounts.js @@ -28,7 +28,13 @@ if (!operatorAccountId || !operatorPrivateKey) { throw new Error('Operator ID and Private Key must be set.'); } -const client = Client.forTestnet(); +let client; +if(process.env.HEDERA_NETWORK === 'testnet') { + client = Client.forTestnet(); +} else { + client = Client.forPreviewnet(); +} + client.setOperator(operatorAccountId, operatorPrivateKey); const numberOfAccounts = 4; From 1fadbabff30180cb3be16f6b58ea7b98fa4267b2 Mon Sep 17 00:00:00 2001 From: ebadiere Date: Tue, 22 Oct 2024 07:36:50 -0600 Subject: [PATCH 3/3] fix: Updated package-lock.json Signed-off-by: ebadiere --- package-lock.json | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/package-lock.json b/package-lock.json index ef4096b281..0eee672b73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,6 +35,7 @@ "axios-mock-adapter": "^1.20.0", "chai-as-promised": "^7.1.1", "chai-exclude": "^2.1.1", + "env-cmd": "^10.1.0", "eslint": "^8.48.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-prettier": "^8.3.0", @@ -8438,6 +8439,31 @@ "node": ">=8.6" } }, + "node_modules/env-cmd": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/env-cmd/-/env-cmd-10.1.0.tgz", + "integrity": "sha512-mMdWTT9XKN7yNth/6N6g2GuKuJTsKMDHlQFUDacb/heQRRWOTIZ42t1rMHnQu4jYxU1ajdTeJM+9eEETlqToMA==", + "dev": true, + "dependencies": { + "commander": "^4.0.0", + "cross-spawn": "^7.0.0" + }, + "bin": { + "env-cmd": "bin/env-cmd.js" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/env-cmd/node_modules/commander": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", + "integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==", + "dev": true, + "engines": { + "node": ">= 6" + } + }, "node_modules/env-paths": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz", @@ -28696,6 +28722,24 @@ "ansi-colors": "^4.1.1" } }, + "env-cmd": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/env-cmd/-/env-cmd-10.1.0.tgz", + "integrity": "sha512-mMdWTT9XKN7yNth/6N6g2GuKuJTsKMDHlQFUDacb/heQRRWOTIZ42t1rMHnQu4jYxU1ajdTeJM+9eEETlqToMA==", + "dev": true, + "requires": { + "commander": "^4.0.0", + "cross-spawn": "^7.0.0" + }, + "dependencies": { + "commander": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", + "integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==", + "dev": true + } + } + }, "env-paths": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz",