From 9aa9fc989b324011295cdd4b5b4bba5ead5b199b Mon Sep 17 00:00:00 2001 From: kriii Date: Mon, 24 Apr 2023 11:02:44 +0900 Subject: [PATCH 01/41] Fix dockerfile node version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6cda1ec55..23bdbf611 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16.14 +FROM node:18.16 WORKDIR /app/ain-blockchain COPY . /app/ain-blockchain RUN yarn install From ddd50a073d74065c33c3104c848a52aa4cc1ceb8 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 24 Apr 2023 17:55:24 +0900 Subject: [PATCH 02/41] Set chain id properly in blockchain node param config scripts --- config_client_api_ip_whitelist.sh | 9 ++++++++- config_node_param.sh | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/config_client_api_ip_whitelist.sh b/config_client_api_ip_whitelist.sh index 450a4b8d3..1e0773737 100644 --- a/config_client_api_ip_whitelist.sh +++ b/config_client_api_ip_whitelist.sh @@ -72,10 +72,13 @@ printf "Enter password: " read -s PASSWORD printf "\n\n" if [[ $SEASON = "mainnet" ]]; then + CHAIN_ID="1" KEYSTORE_DIR="mainnet_prod_keys" elif [[ $SEASON = "spring" ]] || [[ $SEASON = "summer" ]]; then + CHAIN_ID="0" KEYSTORE_DIR="testnet_prod_keys" else + CHAIN_ID="0" KEYSTORE_DIR="testnet_dev_staging_keys" fi @@ -87,6 +90,10 @@ else COMMAND_NODE_JS_FILE="getDevClientApiIpWhitelist.js" fi +printf "CHAIN_ID=$CHAIN_ID\n" +printf "KEYSTORE_DIR=$KEYSTORE_DIR\n" +printf "COMMAND_NODE_JS_FILE=$COMMAND_NODE_JS_FILE\n" + function config_node() { local node_index="$1" local node_ip_addr=${IP_ADDR_LIST[${node_index}]} @@ -94,7 +101,7 @@ function config_node() { printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_ip_addr) >>>\n\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" - CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_ip_addr 0 keystore $KEYSTORE_FILE_PATH" + CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_ip_addr $CHAIN_ID keystore $KEYSTORE_FILE_PATH" if [[ ! $COMMAND = "get" ]]; then CONFIG_NODE_CMD="$CONFIG_NODE_CMD '$IP_ADDR'" fi diff --git a/config_node_param.sh b/config_node_param.sh index e2c318bbd..698423e79 100644 --- a/config_node_param.sh +++ b/config_node_param.sh @@ -8,6 +8,7 @@ function usage() { printf "Example: bash config_node_param.sh dev add DEV_CLIENT_API_IP_WHITELIST '*'\n" printf "Example: bash config_node_param.sh dev remove DEV_CLIENT_API_IP_WHITELIST 32.190.239.181\n" printf "Example: bash config_node_param.sh dev set DEV_CLIENT_API_IP_WHITELIST '*'\n" + printf "Example: bash config_node_param.sh dev get CORS_WHITELIST\n" printf "\n" exit } @@ -80,10 +81,13 @@ printf "Enter password: " read -s PASSWORD printf "\n\n" if [[ $SEASON = "mainnet" ]]; then + CHAIN_ID="1" KEYSTORE_DIR="mainnet_prod_keys" elif [[ $SEASON = "spring" ]] || [[ $SEASON = "summer" ]]; then + CHAIN_ID="0" KEYSTORE_DIR="testnet_prod_keys" else + CHAIN_ID="0" KEYSTORE_DIR="testnet_dev_staging_keys" fi @@ -97,6 +101,10 @@ else COMMAND_NODE_JS_FILE="getNodeParam.js" fi +printf "CHAIN_ID=$CHAIN_ID\n" +printf "KEYSTORE_DIR=$KEYSTORE_DIR\n" +printf "COMMAND_NODE_JS_FILE=$COMMAND_NODE_JS_FILE\n" + function config_node() { local node_index="$1" local node_ip_addr=${IP_ADDR_LIST[${node_index}]} @@ -104,7 +112,7 @@ function config_node() { printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_ip_addr) >>>\n\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" - CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_ip_addr 0 keystore $KEYSTORE_FILE_PATH $PARAM" + CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_ip_addr $CHAIN_ID keystore $KEYSTORE_FILE_PATH $PARAM" if [[ ! $COMMAND = "get" ]]; then CONFIG_NODE_CMD="$CONFIG_NODE_CMD '$VALUE'" fi From ac8106418d6c93e75dcf8957446253b4f59b340a Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Tue, 25 Apr 2023 20:13:54 +0900 Subject: [PATCH 03/41] Fix chatbot-related code --- tools/chatbot/sendCreateAppAndConfigTx.js | 10 +- tools/chatbot/sendMessageTx.js | 5 +- tools/simple-chatbot-server/index.js | 32 +- tools/simple-chatbot-server/package.json | 3 +- tools/simple-chatbot-server/yarn.lock | 938 ++++++++++++++++++++++ 5 files changed, 970 insertions(+), 18 deletions(-) create mode 100644 tools/simple-chatbot-server/yarn.lock diff --git a/tools/chatbot/sendCreateAppAndConfigTx.js b/tools/chatbot/sendCreateAppAndConfigTx.js index 8bc66c32b..def4173de 100644 --- a/tools/chatbot/sendCreateAppAndConfigTx.js +++ b/tools/chatbot/sendCreateAppAndConfigTx.js @@ -1,3 +1,5 @@ +// A tool to create and configure a blockchain app for chatbots. +// This can be used with the server code under tools/simple-chatbot-server. const path = require('path'); const { signAndSendTx, confirmTransaction } = require('../util'); @@ -25,7 +27,7 @@ function buildChatbotConfigTxBody(timestamp) { op_list: [ { type: "SET_OWNER", - ref: "/apps/chatbots/common/message", + ref: "/apps/chatbots/common/messages", value: { ".owner": { owners: { @@ -41,7 +43,7 @@ function buildChatbotConfigTxBody(timestamp) { }, { type: "SET_RULE", - ref: "/apps/chatbots/common/message/$key", + ref: "/apps/chatbots/common/messages/$key", value: { ".rule": { "write": true @@ -50,12 +52,12 @@ function buildChatbotConfigTxBody(timestamp) { }, { type: "SET_FUNCTION", - ref: "/apps/chatbots/common/message/$key", + ref: "/apps/chatbots/common/messages/$key/user", value: { ".function": { "liayoo-ainjs": { function_type: "REST", - function_url: "https://events.ainetwork.ai/trigger", + function_url: "http://localhost:3000/trigger", function_id: "liayoo-ainjs" } } diff --git a/tools/chatbot/sendMessageTx.js b/tools/chatbot/sendMessageTx.js index da1f5e3a5..942e682f9 100644 --- a/tools/chatbot/sendMessageTx.js +++ b/tools/chatbot/sendMessageTx.js @@ -1,3 +1,5 @@ +// A tool to send chatting messages to chatbots. +// This can be used with the server code under tools/simple-chatbot-server. const path = require('path'); const { signAndSendTx, confirmTransaction } = require('../util'); let config = {}; @@ -6,9 +8,10 @@ function buildMessageTxBody(timestamp, message) { return { operation: { type: 'SET_VALUE', - ref: `/apps/chatbots/common/message/${timestamp}`, + ref: `/apps/chatbots/common/messages/${timestamp}/user`, value: message, }, + gas_price: 500, timestamp, nonce: -1 }; diff --git a/tools/simple-chatbot-server/index.js b/tools/simple-chatbot-server/index.js index 1fa05e81b..4ecf23c88 100644 --- a/tools/simple-chatbot-server/index.js +++ b/tools/simple-chatbot-server/index.js @@ -1,10 +1,13 @@ +// A simple chatbot server based on blockchain REST function calls. +// This can be used with the tool scripts under tools/chatbot. const express = require('express'); +const _ = require('lodash'); const AinJs = require('@ainblockchain/ain-js').default; const CommonUtil = require('../../common/common-util'); const app = express(); -const port = 80; -const blockchainEndpoint = 'https://dev-api.ainetwork.ai/'; -const ain = new AinJs(blockchainEndpoint, 0); +const PORT = 3000; +const BLOCKCHAIN_ENDPOINT = 'http://localhost:8081/'; +const ain = new AinJs(BLOCKCHAIN_ENDPOINT, 0); const BOT_NAME = 'echo-bot'; const BOT_PK = 'ee0b1315d446e5318eb6eb4e9d071cd12ef42d2956d546f9acbdc3b75c469640'; const BOT_ADDRESS = AinJs.utils.toChecksumAddress(ain.wallet.add(BOT_PK)); // 0x09A0d53FDf1c36A131938eb379b98910e55EEfe1 @@ -23,34 +26,39 @@ app.get('/', (req, res, next) => { app.post('/trigger', async (req, res) => { res.send('Triggered!'); - const tx = req.body.transaction; + const body = _.get(req, 'body', null); + console.log(`\n[][][] >> body: ${JSON.stringify(body, null, 2)}`); + const tx = _.get(body, 'transaction', null); if (!tx || !tx.tx_body || !tx.tx_body.operation) { console.log(`Invalid tx: ${JSON.stringify(tx)}`); return; } - if (tx.tx_body.operation.type !== 'SET_VALUE') { + if (_.get(tx, 'tx_body.operation.type') !== 'SET_VALUE') { console.log(`Not supported tx type: ${tx.tx_body.operation.type}`) return; } - const ref = tx.tx_body.operation.ref; + const ref = _.get(tx, 'tx_body.operation.ref'); const parsedRef = CommonUtil.parsePath(ref); - const userVal = tx.tx_body.operation.value; - if (parsedRef.length !== 6 || parsedRef[0] !== 'apps' || parsedRef[2] !== 'messages' || - parsedRef[5] !== 'user') { + const userVal = _.get(tx, 'tx_body.operation.value'); + if (parsedRef.length !== 6 || parsedRef[0] !== 'apps' || parsedRef[1] !== 'chatbots' || + parsedRef[3] !== 'messages' || parsedRef[5] !== 'user') { console.log(`Not supported path pattern: ${ref}`); return; } const answerRef = CommonUtil.formatPath([...parsedRef.slice(0, parsedRef.length - 1), BOT_NAME]); + const timestamp = Date.now(); const result = await ain.db.ref(answerRef).setValue({ value: `Did you mean ${JSON.stringify(userVal)}?`, + gas_price: 500, + timestamp, nonce: -1, }) .catch((e) => { console.error(`setValue failure:`, e); }); - console.log('result:', result); + console.log('\n[][][] << result:', JSON.stringify(result, null, 2)); }); -app.listen(port, () => { - console.log(`App listening at http://localhost:${port}`); +app.listen(PORT, () => { + console.log(`App listening at http://localhost:${PORT}`); }); diff --git a/tools/simple-chatbot-server/package.json b/tools/simple-chatbot-server/package.json index f59047193..81b3310c4 100644 --- a/tools/simple-chatbot-server/package.json +++ b/tools/simple-chatbot-server/package.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "@ainblockchain/ain-js": "^1.1.8", - "express": "^4.18.2" + "express": "^4.18.2", + "lodash": "^4.17.21" } } diff --git a/tools/simple-chatbot-server/yarn.lock b/tools/simple-chatbot-server/yarn.lock new file mode 100644 index 000000000..b48576791 --- /dev/null +++ b/tools/simple-chatbot-server/yarn.lock @@ -0,0 +1,938 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@ainblockchain/ain-js@^1.1.8": + version "1.3.7" + resolved "https://registry.yarnpkg.com/@ainblockchain/ain-js/-/ain-js-1.3.7.tgz#870220e950913e74094726e48350a3de26119386" + integrity sha512-lj8qVTja3u3WGCZklS36nLlQuhEL5m22jOUOai2GUaL2+qyrKxndgrT4op0rBm+5CnUVSzI/Ktk7lDHcnYUDWA== + dependencies: + "@ainblockchain/ain-util" "^1.1.9" + "@types/node" "^12.7.3" + "@types/randombytes" "^2.0.0" + "@types/semver" "^7.3.4" + axios "^0.21.4" + bip39 "^3.0.2" + browserify-cipher "^1.0.1" + eventemitter3 "^4.0.0" + hdkey "^1.1.1" + lodash "^4.17.20" + node-seal "^4.5.7" + pbkdf2 "^3.0.17" + randombytes "^2.1.0" + scryptsy "^2.1.0" + semver "^6.3.0" + url-parse "^1.4.7" + uuid "^3.3.3" + ws "^8.2.3" + +"@ainblockchain/ain-util@^1.1.9": + version "1.1.9" + resolved "https://registry.yarnpkg.com/@ainblockchain/ain-util/-/ain-util-1.1.9.tgz#4369547af354d84229c5b0f1fd4e93e8497d6227" + integrity sha512-u3q0h0zwWk+vzZ6VpBZiagVKJbNw/Dw4LVjBAhOvgPCx/E3jHHQCufIMDGqD4wjeBuHVtTAQyMTv7LRPSZFBGg== + dependencies: + bip39 "^3.0.4" + bn.js "^4.11.8" + browserify-cipher "^1.0.1" + eccrypto "^1.1.6" + fast-json-stable-stringify "^2.0.0" + hdkey "^2.0.1" + keccak "^2.0.0" + pbkdf2 "^3.0.17" + randombytes "^2.1.0" + rlp "^2.2.2" + safe-buffer "^5.1.2" + scryptsy "^2.1.0" + secp256k1 "^3.6.2" + uuid "^3.3.3" + varuint-bitcoin "^1.1.0" + +"@noble/hashes@^1.2.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.0.tgz#085fd70f6d7d9d109671090ccae1d3bec62554a1" + integrity sha512-ilHEACi9DwqJB0pw7kv+Apvh50jiiSyR/cQ3y4W7lOR5mhvn/50FLUfsnfJz0BDZtl/RR16kXvptiv6q1msYZg== + +"@types/node@*": + version "18.16.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.16.0.tgz#4668bc392bb6938637b47e98b1f2ed5426f33316" + integrity sha512-BsAaKhB+7X+H4GnSjGhJG9Qi8Tw+inU9nJDwmD5CgOmBLEI6ArdhikpLX7DjbjDRDTbqZzU2LSQNZg8WGPiSZQ== + +"@types/node@^12.7.3": + version "12.20.55" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" + integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ== + +"@types/randombytes@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@types/randombytes/-/randombytes-2.0.0.tgz#0087ff5e60ae68023b9bc4398b406fea7ad18304" + integrity sha512-bz8PhAVlwN72vqefzxa14DKNT8jK/mV66CSjwdVQM/k3Th3EPKfUtdMniwZgMedQTFuywAsfjnZsg+pEnltaMA== + dependencies: + "@types/node" "*" + +"@types/semver@^7.3.4": + version "7.3.13" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91" + integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw== + +accepts@~1.3.8: + version "1.3.8" + resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e" + integrity sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw== + dependencies: + mime-types "~2.1.34" + negotiator "0.6.3" + +acorn@7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.1.tgz#e35668de0b402f359de515c5482a1ab9f89a69bf" + integrity sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg== + +array-flatten@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2" + integrity sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg== + +axios@^0.21.4: + version "0.21.4" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575" + integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg== + dependencies: + follow-redirects "^1.14.0" + +base-x@^3.0.2: + version "3.0.9" + resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.9.tgz#6349aaabb58526332de9f60995e548a53fe21320" + integrity sha512-H7JU6iBHTal1gp56aKoaa//YUxEaAOUiydvrV/pILqIHXTtqxSkATOnDA2u+jZ/61sD+L/412+7kzXRtWukhpQ== + dependencies: + safe-buffer "^5.0.1" + +bindings@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df" + integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ== + dependencies: + file-uri-to-path "1.0.0" + +bip39@^3.0.2, bip39@^3.0.4: + version "3.1.0" + resolved "https://registry.yarnpkg.com/bip39/-/bip39-3.1.0.tgz#c55a418deaf48826a6ceb34ac55b3ee1577e18a3" + integrity sha512-c9kiwdk45Do5GL0vJMe7tS95VjCii65mYAH7DfWl3uW8AVzXKQVUm64i3hzVybBDMp9r7j9iNxR85+ul8MdN/A== + dependencies: + "@noble/hashes" "^1.2.0" + +bip66@^1.1.5: + version "1.1.5" + resolved "https://registry.yarnpkg.com/bip66/-/bip66-1.1.5.tgz#01fa8748785ca70955d5011217d1b3139969ca22" + integrity sha512-nemMHz95EmS38a26XbbdxIYj5csHd3RMP3H5bwQknX0WYHF01qhpufP42mLOwVICuH2JmhIhXiWs89MfUGL7Xw== + dependencies: + safe-buffer "^5.0.1" + +bn.js@^4.11.8, bn.js@^4.11.9: + version "4.12.0" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" + integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA== + +bn.js@^5.2.0: + version "5.2.1" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70" + integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ== + +body-parser@1.20.1: + version "1.20.1" + resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.1.tgz#b1812a8912c195cd371a3ee5e66faa2338a5c668" + integrity sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw== + dependencies: + bytes "3.1.2" + content-type "~1.0.4" + debug "2.6.9" + depd "2.0.0" + destroy "1.2.0" + http-errors "2.0.0" + iconv-lite "0.4.24" + on-finished "2.4.1" + qs "6.11.0" + raw-body "2.5.1" + type-is "~1.6.18" + unpipe "1.0.0" + +brorand@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f" + integrity sha512-cKV8tMCEpQs4hK/ik71d6LrPOnpkpGBR0wzxqr68g2m/LB2GxVYQroAjMJZRVM1Y4BCjCKc3vAamxSzOY2RP+w== + +browserify-aes@^1.0.4, browserify-aes@^1.0.6: + version "1.2.0" + resolved "https://registry.yarnpkg.com/browserify-aes/-/browserify-aes-1.2.0.tgz#326734642f403dabc3003209853bb70ad428ef48" + integrity sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA== + dependencies: + buffer-xor "^1.0.3" + cipher-base "^1.0.0" + create-hash "^1.1.0" + evp_bytestokey "^1.0.3" + inherits "^2.0.1" + safe-buffer "^5.0.1" + +browserify-cipher@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/browserify-cipher/-/browserify-cipher-1.0.1.tgz#8d6474c1b870bfdabcd3bcfcc1934a10e94f15f0" + integrity sha512-sPhkz0ARKbf4rRQt2hTpAHqn47X3llLkUGn+xEJzLjwY8LRs2p0v7ljvI5EyoRO/mexrNunNECisZs+gw2zz1w== + dependencies: + browserify-aes "^1.0.4" + browserify-des "^1.0.0" + evp_bytestokey "^1.0.0" + +browserify-des@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/browserify-des/-/browserify-des-1.0.2.tgz#3af4f1f59839403572f1c66204375f7a7f703e9c" + integrity sha512-BioO1xf3hFwz4kc6iBhI3ieDFompMhrMlnDFC4/0/vd5MokpuAc3R+LYbwTA9A5Yc9pq9UYPqffKpW2ObuwX5A== + dependencies: + cipher-base "^1.0.1" + des.js "^1.0.0" + inherits "^2.0.1" + safe-buffer "^5.1.2" + +bs58@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/bs58/-/bs58-4.0.1.tgz#be161e76c354f6f788ae4071f63f34e8c4f0a42a" + integrity sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw== + dependencies: + base-x "^3.0.2" + +bs58check@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/bs58check/-/bs58check-2.1.2.tgz#53b018291228d82a5aa08e7d796fdafda54aebfc" + integrity sha512-0TS1jicxdU09dwJMNZtVAfzPi6Q6QeN0pM1Fkzrjn+XYHvzMKPU3pHVpva+769iNVSfIYWf7LJ6WR+BuuMf8cA== + dependencies: + bs58 "^4.0.0" + create-hash "^1.1.0" + safe-buffer "^5.1.2" + +buffer-xor@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9" + integrity sha512-571s0T7nZWK6vB67HI5dyUF7wXiNcfaPPPTl6zYCNApANjIvYJTg7hlud/+cJpdAhS7dVzqMLmfhfHR3rAcOjQ== + +bytes@3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.2.tgz#8b0beeb98605adf1b128fa4386403c009e0221a5" + integrity sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg== + +call-bind@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c" + integrity sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA== + dependencies: + function-bind "^1.1.1" + get-intrinsic "^1.0.2" + +cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/cipher-base/-/cipher-base-1.0.4.tgz#8760e4ecc272f4c363532f926d874aae2c1397de" + integrity sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q== + dependencies: + inherits "^2.0.1" + safe-buffer "^5.0.1" + +content-disposition@0.5.4: + version "0.5.4" + resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.4.tgz#8b82b4efac82512a02bb0b1dcec9d2c5e8eb5bfe" + integrity sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ== + dependencies: + safe-buffer "5.2.1" + +content-type@~1.0.4: + version "1.0.5" + resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.5.tgz#8b773162656d1d1086784c8f23a54ce6d73d7918" + integrity sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA== + +cookie-signature@1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" + integrity sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ== + +cookie@0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b" + integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw== + +create-hash@^1.1.0, create-hash@^1.1.2, create-hash@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/create-hash/-/create-hash-1.2.0.tgz#889078af11a63756bcfb59bd221996be3a9ef196" + integrity sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg== + dependencies: + cipher-base "^1.0.1" + inherits "^2.0.1" + md5.js "^1.3.4" + ripemd160 "^2.0.1" + sha.js "^2.4.0" + +create-hmac@^1.1.4: + version "1.1.7" + resolved "https://registry.yarnpkg.com/create-hmac/-/create-hmac-1.1.7.tgz#69170c78b3ab957147b2b8b04572e47ead2243ff" + integrity sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg== + dependencies: + cipher-base "^1.0.3" + create-hash "^1.1.0" + inherits "^2.0.1" + ripemd160 "^2.0.0" + safe-buffer "^5.0.1" + sha.js "^2.4.8" + +debug@2.6.9: + version "2.6.9" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA== + dependencies: + ms "2.0.0" + +depd@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df" + integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw== + +des.js@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.1.tgz#5382142e1bdc53f85d86d53e5f4aa7deb91e0843" + integrity sha512-Q0I4pfFrv2VPd34/vfLrFOoRmlYj3OV50i7fskps1jZWK1kApMWWT9G6RRUeYedLcBDIhnSDaUvJMb3AhUlaEA== + dependencies: + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + +destroy@1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.2.0.tgz#4803735509ad8be552934c67df614f94e66fa015" + integrity sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg== + +drbg.js@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/drbg.js/-/drbg.js-1.0.1.tgz#3e36b6c42b37043823cdbc332d58f31e2445480b" + integrity sha512-F4wZ06PvqxYLFEZKkFxTDcns9oFNk34hvmJSEwdzsxVQ8YI5YaxtACgQatkYgv2VI2CFkUd2Y+xosPQnHv809g== + dependencies: + browserify-aes "^1.0.6" + create-hash "^1.1.2" + create-hmac "^1.1.4" + +eccrypto@^1.1.6: + version "1.1.6" + resolved "https://registry.yarnpkg.com/eccrypto/-/eccrypto-1.1.6.tgz#846bd1222323036f7a3515613704386399702bd3" + integrity sha512-d78ivVEzu7Tn0ZphUUaL43+jVPKTMPFGtmgtz1D0LrFn7cY3K8CdrvibuLz2AAkHBLKZtR8DMbB2ukRYFk987A== + dependencies: + acorn "7.1.1" + elliptic "6.5.4" + es6-promise "4.2.8" + nan "2.14.0" + optionalDependencies: + secp256k1 "3.7.1" + +ee-first@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" + integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow== + +elliptic@6.5.4, elliptic@^6.4.1, elliptic@^6.5.2, elliptic@^6.5.4: + version "6.5.4" + resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb" + integrity sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ== + dependencies: + bn.js "^4.11.9" + brorand "^1.1.0" + hash.js "^1.0.0" + hmac-drbg "^1.0.1" + inherits "^2.0.4" + minimalistic-assert "^1.0.1" + minimalistic-crypto-utils "^1.0.1" + +encodeurl@~1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" + integrity sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w== + +es6-promise@4.2.8: + version "4.2.8" + resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a" + integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w== + +escape-html@~1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" + integrity sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow== + +etag@~1.8.1: + version "1.8.1" + resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887" + integrity sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg== + +eventemitter3@^4.0.0: + version "4.0.7" + resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f" + integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw== + +evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz#7fcbdb198dc71959432efe13842684e0525acb02" + integrity sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA== + dependencies: + md5.js "^1.3.4" + safe-buffer "^5.1.1" + +express@^4.18.2: + version "4.18.2" + resolved "https://registry.yarnpkg.com/express/-/express-4.18.2.tgz#3fabe08296e930c796c19e3c516979386ba9fd59" + integrity sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ== + dependencies: + accepts "~1.3.8" + array-flatten "1.1.1" + body-parser "1.20.1" + content-disposition "0.5.4" + content-type "~1.0.4" + cookie "0.5.0" + cookie-signature "1.0.6" + debug "2.6.9" + depd "2.0.0" + encodeurl "~1.0.2" + escape-html "~1.0.3" + etag "~1.8.1" + finalhandler "1.2.0" + fresh "0.5.2" + http-errors "2.0.0" + merge-descriptors "1.0.1" + methods "~1.1.2" + on-finished "2.4.1" + parseurl "~1.3.3" + path-to-regexp "0.1.7" + proxy-addr "~2.0.7" + qs "6.11.0" + range-parser "~1.2.1" + safe-buffer "5.2.1" + send "0.18.0" + serve-static "1.15.0" + setprototypeof "1.2.0" + statuses "2.0.1" + type-is "~1.6.18" + utils-merge "1.0.1" + vary "~1.1.2" + +fast-json-stable-stringify@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" + integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw== + +file-uri-to-path@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" + integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw== + +finalhandler@1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.2.0.tgz#7d23fe5731b207b4640e4fcd00aec1f9207a7b32" + integrity sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg== + dependencies: + debug "2.6.9" + encodeurl "~1.0.2" + escape-html "~1.0.3" + on-finished "2.4.1" + parseurl "~1.3.3" + statuses "2.0.1" + unpipe "~1.0.0" + +follow-redirects@^1.14.0: + version "1.15.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" + integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== + +forwarded@0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811" + integrity sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow== + +fresh@0.5.2: + version "0.5.2" + resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7" + integrity sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q== + +function-bind@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" + integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== + +get-intrinsic@^1.0.2: + version "1.2.0" + resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.2.0.tgz#7ad1dc0535f3a2904bba075772763e5051f6d05f" + integrity sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q== + dependencies: + function-bind "^1.1.1" + has "^1.0.3" + has-symbols "^1.0.3" + +has-symbols@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.3.tgz#bb7b2c4349251dce87b125f7bdf874aa7c8b39f8" + integrity sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A== + +has@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" + integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== + dependencies: + function-bind "^1.1.1" + +hash-base@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/hash-base/-/hash-base-3.1.0.tgz#55c381d9e06e1d2997a883b4a3fddfe7f0d3af33" + integrity sha512-1nmYp/rhMDiE7AYkDw+lLwlAzz0AntGIe51F3RfFfEqyQ3feY2eI/NcwC6umIQVOASPMsWJLJScWKSSvzL9IVA== + dependencies: + inherits "^2.0.4" + readable-stream "^3.6.0" + safe-buffer "^5.2.0" + +hash.js@^1.0.0, hash.js@^1.0.3: + version "1.1.7" + resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.7.tgz#0babca538e8d4ee4a0f8988d68866537a003cf42" + integrity sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA== + dependencies: + inherits "^2.0.3" + minimalistic-assert "^1.0.1" + +hdkey@^1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/hdkey/-/hdkey-1.1.2.tgz#c60f9cf6f90fbf24a8a52ea06893f36a0108cd3e" + integrity sha512-PTQ4VKu0oRnCrYfLp04iQZ7T2Cxz0UsEXYauk2j8eh6PJXCpbXuCFhOmtIFtbET0i3PMWmHN9J11gU8LEgUljQ== + dependencies: + bs58check "^2.1.2" + safe-buffer "^5.1.1" + secp256k1 "^3.0.1" + +hdkey@^2.0.1: + version "2.1.0" + resolved "https://registry.yarnpkg.com/hdkey/-/hdkey-2.1.0.tgz#755b30b73f54e93c31919c1b2f19205a8e57cb92" + integrity sha512-i9Wzi0Dy49bNS4tXXeGeu0vIcn86xXdPQUpEYg+SO1YiO8HtomjmmRMaRyqL0r59QfcD4PfVbSF3qmsWFwAemA== + dependencies: + bs58check "^2.1.2" + ripemd160 "^2.0.2" + safe-buffer "^5.1.1" + secp256k1 "^4.0.0" + +hmac-drbg@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" + integrity sha512-Tti3gMqLdZfhOQY1Mzf/AanLiqh1WTiJgEj26ZuYQ9fbkLomzGchCws4FyrSd4VkpBfiNhaE1On+lOz894jvXg== + dependencies: + hash.js "^1.0.3" + minimalistic-assert "^1.0.0" + minimalistic-crypto-utils "^1.0.1" + +http-errors@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-2.0.0.tgz#b7774a1486ef73cf7667ac9ae0858c012c57b9d3" + integrity sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ== + dependencies: + depd "2.0.0" + inherits "2.0.4" + setprototypeof "1.2.0" + statuses "2.0.1" + toidentifier "1.0.1" + +iconv-lite@0.4.24: + version "0.4.24" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" + integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== + dependencies: + safer-buffer ">= 2.1.2 < 3" + +inherits@2.0.4, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +ipaddr.js@1.9.1: + version "1.9.1" + resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz#bff38543eeb8984825079ff3a2a8e6cbd46781b3" + integrity sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g== + +keccak@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/keccak/-/keccak-2.1.0.tgz#734ea53f2edcfd0f42cdb8d5f4c358fef052752b" + integrity sha512-m1wbJRTo+gWbctZWay9i26v5fFnYkOn7D5PCxJ3fZUGUEb49dE1Pm4BREUYCt/aoO6di7jeoGmhvqN9Nzylm3Q== + dependencies: + bindings "^1.5.0" + inherits "^2.0.4" + nan "^2.14.0" + safe-buffer "^5.2.0" + +lodash@^4.17.20, lodash@^4.17.21: + version "4.17.21" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" + integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== + +md5.js@^1.3.4: + version "1.3.5" + resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f" + integrity sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg== + dependencies: + hash-base "^3.0.0" + inherits "^2.0.1" + safe-buffer "^5.1.2" + +media-typer@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" + integrity sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ== + +merge-descriptors@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" + integrity sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w== + +methods@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" + integrity sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w== + +mime-db@1.52.0: + version "1.52.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" + integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== + +mime-types@~2.1.24, mime-types@~2.1.34: + version "2.1.35" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a" + integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== + dependencies: + mime-db "1.52.0" + +mime@1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" + integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== + +minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7" + integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A== + +minimalistic-crypto-utils@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a" + integrity sha512-JIYlbt6g8i5jKfJ3xz7rF0LXmv2TkDxBLUkiBeZ7bAx4GnnNMr8xFpGnOxn6GhTEHx3SjRrZEoU+j04prX1ktg== + +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + integrity sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A== + +ms@2.1.3: + version "2.1.3" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== + +nan@2.14.0: + version "2.14.0" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c" + integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg== + +nan@^2.14.0: + version "2.17.0" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.17.0.tgz#c0150a2368a182f033e9aa5195ec76ea41a199cb" + integrity sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ== + +negotiator@0.6.3: + version "0.6.3" + resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.3.tgz#58e323a72fedc0d6f9cd4d31fe49f51479590ccd" + integrity sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg== + +node-addon-api@^2.0.0: + version "2.0.2" + resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32" + integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA== + +node-gyp-build@^4.2.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.6.0.tgz#0c52e4cbf54bbd28b709820ef7b6a3c2d6209055" + integrity sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ== + +node-seal@^4.5.7: + version "4.6.4" + resolved "https://registry.yarnpkg.com/node-seal/-/node-seal-4.6.4.tgz#155f9ee6e23b16a1ba38bdff97c9c6fe333ed774" + integrity sha512-ZQU63Ikt9/n9CXueEltszdAxUPHWpfbExcoux6Ktn2W3lxWc7jG2yx3p0ok34LzOgKOfytUSwHCxYmabAm3VPQ== + +object-inspect@^1.9.0: + version "1.12.3" + resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.3.tgz#ba62dffd67ee256c8c086dfae69e016cd1f198b9" + integrity sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g== + +on-finished@2.4.1: + version "2.4.1" + resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.4.1.tgz#58c8c44116e54845ad57f14ab10b03533184ac3f" + integrity sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg== + dependencies: + ee-first "1.1.1" + +parseurl@~1.3.3: + version "1.3.3" + resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4" + integrity sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ== + +path-to-regexp@0.1.7: + version "0.1.7" + resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" + integrity sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ== + +pbkdf2@^3.0.17: + version "3.1.2" + resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.1.2.tgz#dd822aa0887580e52f1a039dc3eda108efae3075" + integrity sha512-iuh7L6jA7JEGu2WxDwtQP1ddOpaJNC4KlDEFfdQajSGgGPNi4OyDc2R7QnbY2bR9QjBVGwgvTdNJZoE7RaxUMA== + dependencies: + create-hash "^1.1.2" + create-hmac "^1.1.4" + ripemd160 "^2.0.1" + safe-buffer "^5.0.1" + sha.js "^2.4.8" + +proxy-addr@~2.0.7: + version "2.0.7" + resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.7.tgz#f19fe69ceab311eeb94b42e70e8c2070f9ba1025" + integrity sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg== + dependencies: + forwarded "0.2.0" + ipaddr.js "1.9.1" + +qs@6.11.0: + version "6.11.0" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.0.tgz#fd0d963446f7a65e1367e01abd85429453f0c37a" + integrity sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q== + dependencies: + side-channel "^1.0.4" + +querystringify@^2.1.1: + version "2.2.0" + resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6" + integrity sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ== + +randombytes@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a" + integrity sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ== + dependencies: + safe-buffer "^5.1.0" + +range-parser@~1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031" + integrity sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg== + +raw-body@2.5.1: + version "2.5.1" + resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.5.1.tgz#fe1b1628b181b700215e5fd42389f98b71392857" + integrity sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig== + dependencies: + bytes "3.1.2" + http-errors "2.0.0" + iconv-lite "0.4.24" + unpipe "1.0.0" + +readable-stream@^3.6.0: + version "3.6.2" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967" + integrity sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA== + dependencies: + inherits "^2.0.3" + string_decoder "^1.1.1" + util-deprecate "^1.0.1" + +requires-port@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" + integrity sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ== + +ripemd160@^2.0.0, ripemd160@^2.0.1, ripemd160@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.2.tgz#a1c1a6f624751577ba5d07914cbc92850585890c" + integrity sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA== + dependencies: + hash-base "^3.0.0" + inherits "^2.0.1" + +rlp@^2.2.2: + version "2.2.7" + resolved "https://registry.yarnpkg.com/rlp/-/rlp-2.2.7.tgz#33f31c4afac81124ac4b283e2bd4d9720b30beaf" + integrity sha512-d5gdPmgQ0Z+AklL2NVXr/IoSjNZFfTVvQWzL/AM2AOcSzYP2xjlb0AC8YyCLc41MSNf6P6QVtjgPdmVtzb+4lQ== + dependencies: + bn.js "^5.2.0" + +safe-buffer@5.2.1, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0: + version "5.2.1" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" + integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== + +"safer-buffer@>= 2.1.2 < 3": + version "2.1.2" + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== + +scryptsy@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/scryptsy/-/scryptsy-2.1.0.tgz#8d1e8d0c025b58fdd25b6fa9a0dc905ee8faa790" + integrity sha512-1CdSqHQowJBnMAFyPEBRfqag/YP9OF394FV+4YREIJX4ljD7OxvQRDayyoyyCk+senRjSkP6VnUNQmVQqB6g7w== + +secp256k1@3.7.1: + version "3.7.1" + resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-3.7.1.tgz#12e473e0e9a7c2f2d4d4818e722ad0e14cc1e2f1" + integrity sha512-1cf8sbnRreXrQFdH6qsg2H71Xw91fCCS9Yp021GnUNJzWJS/py96fS4lHbnTnouLp08Xj6jBoBB6V78Tdbdu5g== + dependencies: + bindings "^1.5.0" + bip66 "^1.1.5" + bn.js "^4.11.8" + create-hash "^1.2.0" + drbg.js "^1.0.1" + elliptic "^6.4.1" + nan "^2.14.0" + safe-buffer "^5.1.2" + +secp256k1@^3.0.1, secp256k1@^3.6.2: + version "3.8.0" + resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-3.8.0.tgz#28f59f4b01dbee9575f56a47034b7d2e3b3b352d" + integrity sha512-k5ke5avRZbtl9Tqx/SA7CbY3NF6Ro+Sj9cZxezFzuBlLDmyqPiL8hJJ+EmzD8Ig4LUDByHJ3/iPOVoRixs/hmw== + dependencies: + bindings "^1.5.0" + bip66 "^1.1.5" + bn.js "^4.11.8" + create-hash "^1.2.0" + drbg.js "^1.0.1" + elliptic "^6.5.2" + nan "^2.14.0" + safe-buffer "^5.1.2" + +secp256k1@^4.0.0: + version "4.0.3" + resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-4.0.3.tgz#c4559ecd1b8d3c1827ed2d1b94190d69ce267303" + integrity sha512-NLZVf+ROMxwtEj3Xa562qgv2BK5e2WNmXPiOdVIPLgs6lyTzMvBq0aWTYMI5XCP9jZMVKOcqZLw/Wc4vDkuxhA== + dependencies: + elliptic "^6.5.4" + node-addon-api "^2.0.0" + node-gyp-build "^4.2.0" + +semver@^6.3.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" + integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== + +send@0.18.0: + version "0.18.0" + resolved "https://registry.yarnpkg.com/send/-/send-0.18.0.tgz#670167cc654b05f5aa4a767f9113bb371bc706be" + integrity sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg== + dependencies: + debug "2.6.9" + depd "2.0.0" + destroy "1.2.0" + encodeurl "~1.0.2" + escape-html "~1.0.3" + etag "~1.8.1" + fresh "0.5.2" + http-errors "2.0.0" + mime "1.6.0" + ms "2.1.3" + on-finished "2.4.1" + range-parser "~1.2.1" + statuses "2.0.1" + +serve-static@1.15.0: + version "1.15.0" + resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.15.0.tgz#faaef08cffe0a1a62f60cad0c4e513cff0ac9540" + integrity sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g== + dependencies: + encodeurl "~1.0.2" + escape-html "~1.0.3" + parseurl "~1.3.3" + send "0.18.0" + +setprototypeof@1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424" + integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw== + +sha.js@^2.4.0, sha.js@^2.4.8: + version "2.4.11" + resolved "https://registry.yarnpkg.com/sha.js/-/sha.js-2.4.11.tgz#37a5cf0b81ecbc6943de109ba2960d1b26584ae7" + integrity sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ== + dependencies: + inherits "^2.0.1" + safe-buffer "^5.0.1" + +side-channel@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" + integrity sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw== + dependencies: + call-bind "^1.0.0" + get-intrinsic "^1.0.2" + object-inspect "^1.9.0" + +statuses@2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63" + integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ== + +string_decoder@^1.1.1: + version "1.3.0" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" + integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== + dependencies: + safe-buffer "~5.2.0" + +toidentifier@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35" + integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA== + +type-is@~1.6.18: + version "1.6.18" + resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131" + integrity sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g== + dependencies: + media-typer "0.3.0" + mime-types "~2.1.24" + +unpipe@1.0.0, unpipe@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" + integrity sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ== + +url-parse@^1.4.7: + version "1.5.10" + resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1" + integrity sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ== + dependencies: + querystringify "^2.1.1" + requires-port "^1.0.0" + +util-deprecate@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" + integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw== + +utils-merge@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" + integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA== + +uuid@^3.3.3: + version "3.4.0" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" + integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== + +varuint-bitcoin@^1.1.0: + version "1.1.2" + resolved "https://registry.yarnpkg.com/varuint-bitcoin/-/varuint-bitcoin-1.1.2.tgz#e76c138249d06138b480d4c5b40ef53693e24e92" + integrity sha512-4EVb+w4rx+YfVM32HQX42AbbT7/1f5zwAYhIujKXKk8NQK+JfRVl3pqT3hjNn/L+RstigmGGKVwHA/P0wgITZw== + dependencies: + safe-buffer "^5.1.1" + +vary@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" + integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg== + +ws@^8.2.3: + version "8.13.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" + integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== From 4f1c576a095ae58fecf92e830f6a12a3a2129e50 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Wed, 26 Apr 2023 14:54:57 +0900 Subject: [PATCH 04/41] Parameterize app name in chatbot tools --- tools/chatbot/config_gcp.js | 3 ++- tools/chatbot/config_local.js | 3 ++- tools/chatbot/sendCreateAppAndConfigTx.js | 8 ++++---- tools/chatbot/sendMessageTx.js | 2 +- tools/simple-chatbot-server/index.js | 3 ++- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/chatbot/config_gcp.js b/tools/chatbot/config_gcp.js index 3f86f7b16..a96790326 100644 --- a/tools/chatbot/config_gcp.js +++ b/tools/chatbot/config_gcp.js @@ -2,5 +2,6 @@ module.exports = { endpointUrl: "https://dev-api.ainetwork.ai", userAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", serviceOwnerAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", - serviceOwnerPrivateKey: "9fad756c0bd0d3a42643973f36e61d4d76e01cbb41371fa3046bcced6926e1b2" + serviceOwnerPrivateKey: "9fad756c0bd0d3a42643973f36e61d4d76e01cbb41371fa3046bcced6926e1b2", + appName: "chatbots" }; \ No newline at end of file diff --git a/tools/chatbot/config_local.js b/tools/chatbot/config_local.js index ed11f04cd..4dcee4a95 100644 --- a/tools/chatbot/config_local.js +++ b/tools/chatbot/config_local.js @@ -2,5 +2,6 @@ module.exports = { endpointUrl: "http://localhost:8081", userAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", serviceOwnerAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", - serviceOwnerPrivateKey: "9fad756c0bd0d3a42643973f36e61d4d76e01cbb41371fa3046bcced6926e1b2" + serviceOwnerPrivateKey: "9fad756c0bd0d3a42643973f36e61d4d76e01cbb41371fa3046bcced6926e1b2", + appName: "chatbots" }; \ No newline at end of file diff --git a/tools/chatbot/sendCreateAppAndConfigTx.js b/tools/chatbot/sendCreateAppAndConfigTx.js index def4173de..5635c1869 100644 --- a/tools/chatbot/sendCreateAppAndConfigTx.js +++ b/tools/chatbot/sendCreateAppAndConfigTx.js @@ -9,7 +9,7 @@ function buildCreateAppTxBody(address, timestamp) { return { operation: { type: 'SET_VALUE', - ref: `/manage_app/chatbots/create/${timestamp}`, + ref: `/manage_app/${config.appName}/create/${timestamp}`, value: { admin: { [address]: true }, } @@ -27,7 +27,7 @@ function buildChatbotConfigTxBody(timestamp) { op_list: [ { type: "SET_OWNER", - ref: "/apps/chatbots/common/messages", + ref: `/apps/${config.appName}/common/messages`, value: { ".owner": { owners: { @@ -43,7 +43,7 @@ function buildChatbotConfigTxBody(timestamp) { }, { type: "SET_RULE", - ref: "/apps/chatbots/common/messages/$key", + ref: `/apps/${config.appName}/common/messages/$key`, value: { ".rule": { "write": true @@ -52,7 +52,7 @@ function buildChatbotConfigTxBody(timestamp) { }, { type: "SET_FUNCTION", - ref: "/apps/chatbots/common/messages/$key/user", + ref: `/apps/${config.appName}/common/messages/$key/user`, value: { ".function": { "liayoo-ainjs": { diff --git a/tools/chatbot/sendMessageTx.js b/tools/chatbot/sendMessageTx.js index 942e682f9..40c1f4343 100644 --- a/tools/chatbot/sendMessageTx.js +++ b/tools/chatbot/sendMessageTx.js @@ -8,7 +8,7 @@ function buildMessageTxBody(timestamp, message) { return { operation: { type: 'SET_VALUE', - ref: `/apps/chatbots/common/messages/${timestamp}/user`, + ref: `/apps/${config.appName}/common/messages/${timestamp}/user`, value: message, }, gas_price: 500, diff --git a/tools/simple-chatbot-server/index.js b/tools/simple-chatbot-server/index.js index 4ecf23c88..41aac7d51 100644 --- a/tools/simple-chatbot-server/index.js +++ b/tools/simple-chatbot-server/index.js @@ -8,6 +8,7 @@ const app = express(); const PORT = 3000; const BLOCKCHAIN_ENDPOINT = 'http://localhost:8081/'; const ain = new AinJs(BLOCKCHAIN_ENDPOINT, 0); +const APP_NAME = 'chatbots'; const BOT_NAME = 'echo-bot'; const BOT_PK = 'ee0b1315d446e5318eb6eb4e9d071cd12ef42d2956d546f9acbdc3b75c469640'; const BOT_ADDRESS = AinJs.utils.toChecksumAddress(ain.wallet.add(BOT_PK)); // 0x09A0d53FDf1c36A131938eb379b98910e55EEfe1 @@ -40,7 +41,7 @@ app.post('/trigger', async (req, res) => { const ref = _.get(tx, 'tx_body.operation.ref'); const parsedRef = CommonUtil.parsePath(ref); const userVal = _.get(tx, 'tx_body.operation.value'); - if (parsedRef.length !== 6 || parsedRef[0] !== 'apps' || parsedRef[1] !== 'chatbots' || + if (parsedRef.length !== 6 || parsedRef[0] !== 'apps' || parsedRef[1] !== APP_NAME || parsedRef[3] !== 'messages' || parsedRef[5] !== 'user') { console.log(`Not supported path pattern: ${ref}`); return; From db6b8db28cada243c016dd13e038d8705dcb650c Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Wed, 26 Apr 2023 18:17:05 +0900 Subject: [PATCH 05/41] Move event emission skipping logic to db side --- db/index.js | 3 ++- event-handler/index.js | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/db/index.js b/db/index.js index 087a2cd3e..16f0dbdf7 100644 --- a/db/index.js +++ b/db/index.js @@ -1073,7 +1073,8 @@ class DB { logger.debug( `[${LOG_HEADER}] applyStateGcRuleRes: deleted ${applyStateGcRuleRes} child nodes`); } - if (this.eh) { + // NOTE: Skipped when the event source is null. + if (this.eh && eventSource !== null) { this.eh.emitValueChanged(auth, transaction, localPath, prevValueCopy, valueCopy, eventSource); } diff --git a/event-handler/index.js b/event-handler/index.js index af39f196f..aa0077ef4 100644 --- a/event-handler/index.js +++ b/event-handler/index.js @@ -81,9 +81,6 @@ class EventHandler { // TODO(cshcomcom): Add tests. emitValueChanged(auth, transaction, parsedValuePath, beforeValue, afterValue, eventSource) { const LOG_HEADER = 'emitValueChanged'; - if (!eventSource) { // NOTE: If the event source is null, propagation isn't required. - return; - } const valuePath = CommonUtil.formatPath(parsedValuePath); const matchedEventFilterIdList = this.stateEventTreeManager.matchEventFilterPath(parsedValuePath); for (const eventFilterId of matchedEventFilterIdList) { From 80fdea13f46164e76e3b135bbeec66c812d8f876 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Wed, 26 Apr 2023 18:17:54 +0900 Subject: [PATCH 06/41] Skip REST function call for null eventSource cases --- db/functions.js | 97 +++++++++++++++----------- test/unit/functions.test.js | 135 +++++++++++++++++++++++++++++++++++- 2 files changed, 189 insertions(+), 43 deletions(-) diff --git a/db/functions.js b/db/functions.js index e1dbd410b..7f2fde8cb 100644 --- a/db/functions.js +++ b/db/functions.js @@ -154,6 +154,7 @@ class Functions { const timestamp = _.get(options, 'timestamp', null); const blockNumber = _.get(options, 'blockNumber', null); const blockTime = _.get(options, 'blockTime', null); + const eventSource = _.get(options, 'eventSource', null); let triggerCount = 0; let failCount = 0; const promises = []; @@ -190,7 +191,6 @@ class Functions { const newAuth = Object.assign( {}, auth, { fid: functionEntry.function_id, fids: this.getFids() }); let result = null; - const eventSource = _.get(options, 'eventSource', null); try { result = nativeFunction.func( value, @@ -208,11 +208,11 @@ class Functions { blockNumber, blockTime, options, + eventSource, auth: newAuth, opResultList: [], otherGasAmount: 0, ...blockchainParams, - eventSource, }); funcResults[functionEntry.function_id] = result; if (DevFlags.enableRichFunctionLogging) { @@ -236,51 +236,64 @@ class Functions { } } } else if (functionEntry.function_type === FunctionTypes.REST) { - if (NodeConfigs.ENABLE_REST_FUNCTION_CALL && functionEntry.function_url && - CommonUtil.isWhitelistedUrl(functionEntry.function_url, this.db.getRestFunctionsUrlWhitelist())) { - if (DevFlags.enableRichFunctionLogging) { + // NOTE: Skipped when the event source is null. + if (NodeConfigs.ENABLE_REST_FUNCTION_CALL && + eventSource !== null && + functionEntry.function_url) { + const restFunctionUrlWhitelist = this.db.getRestFunctionsUrlWhitelist(); + if (!CommonUtil.isWhitelistedUrl(functionEntry.function_url, restFunctionUrlWhitelist)) { + // NOTE: Skipped when the function url is not in the whitelist. logger.info( - ` ==> Triggering REST function [[ ${functionEntry.function_id} ]] of ` + - `function_url '${functionEntry.function_url}' with:\n` + + `Skipped triggering REST function [[ ${functionEntry.function_id} ]] of ` + + `function_url '${functionEntry.function_url}' which is NOT in the whitelist: \n` + + `${JSON.stringify(restFunctionUrlWhitelist)}` + formattedParams); - } - const newAuth = Object.assign( - {}, auth, { fid: functionEntry.function_id, fids: this.getFids() }); - promises.push(axios.post(functionEntry.function_url, { - fid: functionEntry.function_id, - function: functionEntry, - valuePath, - functionPath, - value, - prevValue, - params, - timestamp, - executedAt, - transaction, - blockNumber, - blockTime, - options, - auth: newAuth, - chainId: blockchainParams.chainId, - networkId: blockchainParams.networkId, - }, { - timeout: NodeConfigs.REST_FUNCTION_CALL_TIMEOUT_MS - }).catch((error) => { + } else { if (DevFlags.enableRichFunctionLogging) { - logger.error( - `Failed to trigger REST function [[ ${functionEntry.function_id} ]] of ` + - `function_url '${functionEntry.function_url}' with error: \n` + - `${JSON.stringify(error)}` + + logger.info( + ` ==> Triggering REST function [[ ${functionEntry.function_id} ]] of ` + + `function_url '${functionEntry.function_url}' with:\n` + formattedParams); } - failCount++; - return true; - })); - funcResults[functionEntry.function_id] = { - code: FunctionResultCode.SUCCESS, - bandwidth_gas_amount: blockchainParams.restFunctionCallGasAmount, - }; - triggerCount++; + const newAuth = Object.assign( + {}, auth, { fid: functionEntry.function_id, fids: this.getFids() }); + promises.push(axios.post(functionEntry.function_url, { + fid: functionEntry.function_id, + function: functionEntry, + valuePath, + functionPath, + value, + prevValue, + params, + timestamp, + executedAt, + transaction, + blockNumber, + blockTime, + options, + eventSource, + auth: newAuth, + chainId: blockchainParams.chainId, + networkId: blockchainParams.networkId, + }, { + timeout: NodeConfigs.REST_FUNCTION_CALL_TIMEOUT_MS + }).catch((error) => { + if (DevFlags.enableRichFunctionLogging) { + logger.error( + `Failed to trigger REST function [[ ${functionEntry.function_id} ]] of ` + + `function_url '${functionEntry.function_url}' with error: \n` + + `${JSON.stringify(error)}` + + formattedParams); + } + failCount++; + return true; + })); + funcResults[functionEntry.function_id] = { + code: FunctionResultCode.SUCCESS, + bandwidth_gas_amount: blockchainParams.restFunctionCallGasAmount, + }; + triggerCount++; + } } } } diff --git a/test/unit/functions.test.js b/test/unit/functions.test.js index 3622325a2..70518f9a2 100644 --- a/test/unit/functions.test.js +++ b/test/unit/functions.test.js @@ -300,6 +300,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); assert.deepEqual(triggerRes.func_results, { "0x00001": { @@ -342,7 +343,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": {}, "prevValue": "prev value", "timestamp": 1234567890000, @@ -400,6 +403,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); assert.deepEqual(triggerRes.func_results, { "0x10001": { @@ -442,7 +446,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "arbitrary" }, @@ -502,6 +508,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); assert.deepEqual(triggerRes.func_results, { "0x20001": { @@ -548,7 +555,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": {}, "prevValue": "prev value", "timestamp": 1234567890000, @@ -607,7 +616,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": {}, "prevValue": "prev value", "timestamp": 1234567890000, @@ -680,6 +691,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); assert.deepEqual(triggerRes.func_results, { "0x30001": { @@ -771,7 +783,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": {}, "prevValue": null, "timestamp": 1234567890000, @@ -858,7 +872,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": {}, "prevValue": null, "timestamp": 1234567890000, @@ -947,7 +963,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": {}, "prevValue": null, "timestamp": 1234567890000, @@ -1026,7 +1044,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": {}, "prevValue": null, "timestamp": 1234567890000, @@ -1105,7 +1125,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "path" }, @@ -1184,7 +1206,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "other_path" }, @@ -1265,7 +1289,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "path" }, @@ -1344,7 +1370,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "other_path" }, @@ -1454,6 +1482,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); assert.deepEqual(triggerRes.func_results, { "0x30001": { @@ -1572,7 +1601,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": {}, "prevValue": { // non-null prevValue case only! "deep": { @@ -1672,7 +1703,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": {}, "prevValue": { // non-null prevValue case only! "deep": { @@ -1774,7 +1807,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": {}, "prevValue": { // non-null prevValue case only! "to": "PREVIOUS: deep path to value" @@ -1855,7 +1890,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": {}, "prevValue": { // non-null prevValue case only! "to": "PREVIOUS: deep path to value" @@ -1936,7 +1973,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "existing_path" }, @@ -2019,7 +2058,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "path" }, @@ -2100,7 +2141,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "other_path" }, @@ -2181,7 +2224,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "existing_path" }, @@ -2264,7 +2309,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "path" }, @@ -2345,7 +2392,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "other_path" }, @@ -2428,7 +2477,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "existing_path", "var_path2": "existing_path2", @@ -2514,7 +2565,9 @@ describe("Functions", () => { "timestamp": 1234567890000, "blockNumber": 1000, "blockTime": 1234567890999, + "eventSource": "USER", }, + "eventSource": "USER", "params": { "var_path": "existing_path", "var_path2": "existing_path2", @@ -2595,6 +2648,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); return triggerRes.func_promises.then((resp) => { assert.deepEqual(resp, { @@ -2605,6 +2659,76 @@ describe("Functions", () => { }); }) + it("REST function with 'BLOCK' eventSource", () => { + const value = 'value'; + const tx = { + "tx_body": { + "operation": { + "ref": refPathRest, + "type": "SET_VALUE", + "value": value, + }, + "nonce": 123, + "timestamp": 1566736760322, + "gas_price": 1, + }, + "extra": { + "created_at": 1566736760323, + "executed_at": 1566736760324, + } + } + const triggerRes = functions.matchAndTriggerFunctions( + CommonUtil.parsePath(refPathRest), value, "prev value", { addr: 'abcd' }, + tx, blockchainParams, { + timestamp: 1234567890000, + blockNumber: 1000, + blockTime: 1234567890999, + eventSource: 'BLOCK', + }); + return triggerRes.func_promises.then((resp) => { + assert.deepEqual(resp, { + func_count: 1, + trigger_count: 1, + fail_count: 0, + }); + }); + }) + + it("REST function with null eventSource", () => { + const value = 'value'; + const tx = { + "tx_body": { + "operation": { + "ref": refPathRest, + "type": "SET_VALUE", + "value": value, + }, + "nonce": 123, + "timestamp": 1566736760322, + "gas_price": 1, + }, + "extra": { + "created_at": 1566736760323, + "executed_at": 1566736760324, + } + } + const triggerRes = functions.matchAndTriggerFunctions( + CommonUtil.parsePath(refPathRest), value, "prev value", { addr: 'abcd' }, + tx, blockchainParams, { + timestamp: 1234567890000, + blockNumber: 1000, + blockTime: 1234567890999, + eventSource: null, + }); + return triggerRes.func_promises.then((resp) => { + assert.deepEqual(resp, { + func_count: 1, + trigger_count: 0, + fail_count: 0, + }); + }); + }) + it("REST function NOT whitelisted", () => { const value = 'value'; const tx = { @@ -2612,7 +2736,7 @@ describe("Functions", () => { "operation": { "ref": refPathRestNotWhitelisted, "type": "SET_VALUE", - "value": 1000 + "value": value, }, "nonce": 123, "timestamp": 1566736760322, @@ -2629,6 +2753,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); return triggerRes.func_promises.then((resp) => { assert.deepEqual(resp, { @@ -2674,6 +2799,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); return triggerRes.func_promises.then((resp) => { assert.deepEqual(resp, { @@ -2711,6 +2837,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); return triggerRes.func_promises.then((resp) => { assert.deepEqual(resp, { @@ -2745,6 +2872,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); return triggerRes.func_promises.then((resp) => { assert.deepEqual(resp, { @@ -2809,6 +2937,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); assert.deepEqual(triggerRes.func_results, { "_transfer": { @@ -2862,6 +2991,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); assert.deepEqual(triggerRes.func_results, { "_transfer": { @@ -2915,6 +3045,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); assert.deepEqual(triggerRes.func_results, { "_transfer": { @@ -2968,6 +3099,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); assert.deepEqual(triggerRes.func_results, { "_transfer": { @@ -3025,6 +3157,7 @@ describe("Functions", () => { timestamp: 1234567890000, blockNumber: 1000, blockTime: 1234567890999, + eventSource: 'USER', }); assert.deepEqual(triggerRes.func_results, { "0x90001": { From 7662a209c39b6dfeab9671f317daed5c5dd6c4f8 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 27 Apr 2023 15:09:02 +0900 Subject: [PATCH 07/41] Use staging-api.ainetwork.ai in tool scripts instead. --- tools/chatbot/config_gcp.js | 2 +- tools/checkin/config_gcp.js | 2 +- tools/checkout/config_gcp.js | 2 +- tools/escrow/config_gcp.js | 2 +- tools/payments/config_gcp.js | 2 +- tools/staking/config_gcp.js | 2 +- tools/transfer/config_gcp.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/chatbot/config_gcp.js b/tools/chatbot/config_gcp.js index a96790326..c81c21314 100644 --- a/tools/chatbot/config_gcp.js +++ b/tools/chatbot/config_gcp.js @@ -1,5 +1,5 @@ module.exports = { - endpointUrl: "https://dev-api.ainetwork.ai", + endpointUrl: "https://staging-api.ainetwork.ai", userAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", serviceOwnerAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", serviceOwnerPrivateKey: "9fad756c0bd0d3a42643973f36e61d4d76e01cbb41371fa3046bcced6926e1b2", diff --git a/tools/checkin/config_gcp.js b/tools/checkin/config_gcp.js index 11fb5af07..092d83daf 100644 --- a/tools/checkin/config_gcp.js +++ b/tools/checkin/config_gcp.js @@ -1,5 +1,5 @@ module.exports = { - endpointUrl: "https://dev-api.ainetwork.ai", + endpointUrl: "https://staging-api.ainetwork.ai", ainErc20Address: "0xB16c0C80a81f73204d454426fC413CAe455525A7", userAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", userPrivateKey: "ee0b1315d446e5318eb6eb4e9d071cd12ef42d2956d546f9acbdc3b75c469640", diff --git a/tools/checkout/config_gcp.js b/tools/checkout/config_gcp.js index 30ff9a29a..bad833c8b 100644 --- a/tools/checkout/config_gcp.js +++ b/tools/checkout/config_gcp.js @@ -1,5 +1,5 @@ module.exports = { - endpointUrl: "https://dev-api.ainetwork.ai", + endpointUrl: "https://staging-api.ainetwork.ai", ainErc20Address: "0xB16c0C80a81f73204d454426fC413CAe455525A7", userAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", userPrivateKey: "ee0b1315d446e5318eb6eb4e9d071cd12ef42d2956d546f9acbdc3b75c469640", diff --git a/tools/escrow/config_gcp.js b/tools/escrow/config_gcp.js index 84d6453ae..84586a15c 100644 --- a/tools/escrow/config_gcp.js +++ b/tools/escrow/config_gcp.js @@ -1,5 +1,5 @@ module.exports = { - endpointUrl: "https://dev-api.ainetwork.ai", + endpointUrl: "https://staging-api.ainetwork.ai", sourceAddr: "0x07A43138CC760C85A5B1F115aa60eADEaa0bf417", sourcePrivateKey: "0e9876c7e7966fb0237892eb2e890b4738d0e50adfcfe089ef31f5a1579d65cd", targetAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", diff --git a/tools/payments/config_gcp.js b/tools/payments/config_gcp.js index 3f86f7b16..7666de689 100644 --- a/tools/payments/config_gcp.js +++ b/tools/payments/config_gcp.js @@ -1,5 +1,5 @@ module.exports = { - endpointUrl: "https://dev-api.ainetwork.ai", + endpointUrl: "https://staging-api.ainetwork.ai", userAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", serviceOwnerAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", serviceOwnerPrivateKey: "9fad756c0bd0d3a42643973f36e61d4d76e01cbb41371fa3046bcced6926e1b2" diff --git a/tools/staking/config_gcp.js b/tools/staking/config_gcp.js index 2421ef9fa..e13295d7f 100644 --- a/tools/staking/config_gcp.js +++ b/tools/staking/config_gcp.js @@ -1,5 +1,5 @@ module.exports = { - endpointUrl: "https://dev-api.ainetwork.ai", + endpointUrl: "https://staging-api.ainetwork.ai", userAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", userPrivateKey: "ee0b1315d446e5318eb6eb4e9d071cd12ef42d2956d546f9acbdc3b75c469640", serviceOwnerAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", diff --git a/tools/transfer/config_gcp.js b/tools/transfer/config_gcp.js index e2ca31740..022e558ff 100644 --- a/tools/transfer/config_gcp.js +++ b/tools/transfer/config_gcp.js @@ -1,5 +1,5 @@ module.exports = { - endpointUrl: "https://dev-api.ainetwork.ai", + endpointUrl: "https://staging-api.ainetwork.ai", fromAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", fromPrivateKey: "ee0b1315d446e5318eb6eb4e9d071cd12ef42d2956d546f9acbdc3b75c469640", toAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", From 2ea4d5664306f72c2ca5d7dcf19102fe7cc5d270 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 27 Apr 2023 15:21:44 +0900 Subject: [PATCH 08/41] Add sendAddToDevelopersUserWhitelistTx.js developers tool --- tools/chatbot/sendMessageTx.js | 3 +- tools/developers/config_gcp.js | 6 ++ tools/developers/config_local.js | 6 ++ .../sendAddToDevelopersUserWhitelistTx.js | 56 +++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tools/developers/config_gcp.js create mode 100644 tools/developers/config_local.js create mode 100644 tools/developers/sendAddToDevelopersUserWhitelistTx.js diff --git a/tools/chatbot/sendMessageTx.js b/tools/chatbot/sendMessageTx.js index 40c1f4343..6ece23452 100644 --- a/tools/chatbot/sendMessageTx.js +++ b/tools/chatbot/sendMessageTx.js @@ -27,7 +27,7 @@ async function sendTransaction(message) { const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { - console.log(`Message transaction failed.`); + console.log(`Transaction failed.`); process.exit(0); } await confirmTransaction(config.endpointUrl, timestamp, txInfo.txHash); @@ -46,6 +46,7 @@ async function processArguments() { } function usage() { + console.log("\nExample commandlines:\n node sendMessageTx.js config_local.js") console.log("\nExample commandlines:\n node sendMessageTx.js config_local.js 'Hello'") process.exit(0) } diff --git a/tools/developers/config_gcp.js b/tools/developers/config_gcp.js new file mode 100644 index 000000000..b953e36d9 --- /dev/null +++ b/tools/developers/config_gcp.js @@ -0,0 +1,6 @@ +module.exports = { + endpointUrl: "https://staging-api.ainetwork.ai", + developerAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", + serviceOwnerAddr: "0xAAAf6f50A0304F12119D218b94bea8082642515B", + serviceOwnerPrivateKey: "a2b5848760d81afe205884284716f90356ad82be5ab77b8130980bdb0b7ba2ba", +}; \ No newline at end of file diff --git a/tools/developers/config_local.js b/tools/developers/config_local.js new file mode 100644 index 000000000..a01d21d9e --- /dev/null +++ b/tools/developers/config_local.js @@ -0,0 +1,6 @@ +module.exports = { + endpointUrl: "http://localhost:8081", + developerAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", + serviceOwnerAddr: "0xAAAf6f50A0304F12119D218b94bea8082642515B", + serviceOwnerPrivateKey: "a2b5848760d81afe205884284716f90356ad82be5ab77b8130980bdb0b7ba2ba", +}; \ No newline at end of file diff --git a/tools/developers/sendAddToDevelopersUserWhitelistTx.js b/tools/developers/sendAddToDevelopersUserWhitelistTx.js new file mode 100644 index 000000000..e1d5b1112 --- /dev/null +++ b/tools/developers/sendAddToDevelopersUserWhitelistTx.js @@ -0,0 +1,56 @@ +// A tool to register an address to the developers user whitelist. +// This can be tested with the tool scripts under tools/chatbot. +const path = require('path'); +const CommonUtil = require('../../common/common-util'); +const PathUtil = require('../../common/path-util'); +const { signAndSendTx, confirmTransaction } = require('../util'); +let config = {}; + +function buildMessageTxBody(timestamp, address) { + const userPath = PathUtil.getDevelopersRestFunctionsUserWhitelistUserPath(address); + return { + operation: { + type: 'SET_VALUE', + ref: userPath, + value: true, + }, + gas_price: 500, + timestamp, + nonce: -1 + }; +} + +async function sendTransaction() { + console.log('\n*** sendTransaction():'); + const timestamp = Date.now(); + + if (!CommonUtil.isCksumAddr(config.developerAddr)) { + console.log(`The developer address is NOT a checksum address: ${config.developerAddr}`); + process.exit(0); + } + const txBody = buildMessageTxBody(timestamp, config.developerAddr); + console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); + + const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey); + console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); + if (!txInfo.success) { + console.log(`Transaction failed.`); + process.exit(0); + } + await confirmTransaction(config.endpointUrl, timestamp, txInfo.txHash); +} + +async function processArguments() { + if (process.argv.length !== 3) { + usage(); + } + config = require(path.resolve(__dirname, process.argv[2])); + await sendTransaction(); +} + +function usage() { + console.log("\nExample commandlines:\n node sendAddToDevelopersUserWhitelistTx.js config_local.js") + process.exit(0) +} + +processArguments(); \ No newline at end of file From 42474fe2e51e287e0d637a46cd58451fd2303274 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 27 Apr 2023 15:33:48 +0900 Subject: [PATCH 09/41] Add sendRemoveFromDevelopersUserWhitelistTx.js developer tool --- .../sendAddToDevelopersUserWhitelistTx.js | 4 +- ...sendRemoveFromDevelopersUserWhitelistTx.js | 56 +++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js diff --git a/tools/developers/sendAddToDevelopersUserWhitelistTx.js b/tools/developers/sendAddToDevelopersUserWhitelistTx.js index e1d5b1112..e9d7b04f0 100644 --- a/tools/developers/sendAddToDevelopersUserWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUserWhitelistTx.js @@ -6,7 +6,7 @@ const PathUtil = require('../../common/path-util'); const { signAndSendTx, confirmTransaction } = require('../util'); let config = {}; -function buildMessageTxBody(timestamp, address) { +function buildTxBody(timestamp, address) { const userPath = PathUtil.getDevelopersRestFunctionsUserWhitelistUserPath(address); return { operation: { @@ -28,7 +28,7 @@ async function sendTransaction() { console.log(`The developer address is NOT a checksum address: ${config.developerAddr}`); process.exit(0); } - const txBody = buildMessageTxBody(timestamp, config.developerAddr); + const txBody = buildTxBody(timestamp, config.developerAddr); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey); diff --git a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js new file mode 100644 index 000000000..ce30e37ef --- /dev/null +++ b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js @@ -0,0 +1,56 @@ +// A tool to deregister an address from the developers user whitelist. +// This can be tested with the tool scripts under tools/chatbot. +const path = require('path'); +const CommonUtil = require('../../common/common-util'); +const PathUtil = require('../../common/path-util'); +const { signAndSendTx, confirmTransaction } = require('../util'); +let config = {}; + +function buildTxBody(timestamp, address) { + const userPath = PathUtil.getDevelopersRestFunctionsUserWhitelistUserPath(address); + return { + operation: { + type: 'SET_VALUE', + ref: userPath, + value: null, + }, + gas_price: 500, + timestamp, + nonce: -1 + }; +} + +async function sendTransaction() { + console.log('\n*** sendTransaction():'); + const timestamp = Date.now(); + + if (!CommonUtil.isCksumAddr(config.developerAddr)) { + console.log(`The developer address is NOT a checksum address: ${config.developerAddr}`); + process.exit(0); + } + const txBody = buildTxBody(timestamp, config.developerAddr); + console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); + + const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey); + console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); + if (!txInfo.success) { + console.log(`Transaction failed.`); + process.exit(0); + } + await confirmTransaction(config.endpointUrl, timestamp, txInfo.txHash); +} + +async function processArguments() { + if (process.argv.length !== 3) { + usage(); + } + config = require(path.resolve(__dirname, process.argv[2])); + await sendTransaction(); +} + +function usage() { + console.log("\nExample commandlines:\n node sendRemoveFromDevelopersUserWhitelistTx.js config_local.js") + process.exit(0) +} + +processArguments(); \ No newline at end of file From 1f754fc3abd3dfd407f6d9ce352c5dd3ad9d59de Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 27 Apr 2023 16:24:13 +0900 Subject: [PATCH 10/41] Add sendAddToDevelopersUrlWhitelistTx.js developer tool --- common/common-util.js | 4 ++ .../sendAddToDevelopersUrlWhitelistTx.js | 68 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 tools/developers/sendAddToDevelopersUrlWhitelistTx.js diff --git a/common/common-util.js b/common/common-util.js index 4fc9a670a..27b874fd2 100644 --- a/common/common-util.js +++ b/common/common-util.js @@ -146,6 +146,10 @@ class CommonUtil { return ruleUtil.isValidatorOffenseType(type); } + static isValidUrlWhitelistItem(url) { + return ruleUtil.isValidUrlWhitelistItem(url); + } + static isValidUrl(url) { return ruleUtil.isValidUrl(url); } diff --git a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js new file mode 100644 index 000000000..ac5d90bc3 --- /dev/null +++ b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js @@ -0,0 +1,68 @@ +// A tool to register a URL to the developers URL whitelist. +// This can be tested with the tool scripts under tools/chatbot. +const path = require('path'); +const CommonUtil = require('../../common/common-util'); +const PathUtil = require('../../common/path-util'); +const { signAndSendTx, confirmTransaction } = require('../util'); +let config = {}; + +function buildTxBody(timestamp, address, urlKey, urlValue) { + const urlPath = CommonUtil.appendPath( + PathUtil.getDevelopersRestFunctionsUrlWhitelistUserPath(address), urlKey); + return { + operation: { + type: 'SET_VALUE', + ref: urlPath, + value: urlValue, + }, + gas_price: 500, + timestamp, + nonce: -1 + }; +} + +async function sendTransaction(urlKey, urlValue) { + console.log('\n*** sendTransaction():'); + const timestamp = Date.now(); + + if (!CommonUtil.isCksumAddr(config.developerAddr)) { + console.log(`The developer address is NOT a checksum address: ${config.developerAddr}`); + process.exit(0); + } + const txBody = buildTxBody(timestamp, config.developerAddr, urlKey, urlValue); + console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); + + const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey); + console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); + if (!txInfo.success) { + console.log(`Transaction failed.`); + process.exit(0); + } + await confirmTransaction(config.endpointUrl, timestamp, txInfo.txHash); +} + +async function processArguments() { + if (process.argv.length !== 5) { + usage(); + } + const urlKey = process.argv[3]; + if (!CommonUtil.isString(urlKey) || urlKey.length == 0) { + console.log(`The URL key is NOT a valid one: ${urlKey}`); + process.exit(0); + } + const urlValue = process.argv[4]; + if (!CommonUtil.isValidUrlWhitelistItem(urlValue)) { + console.log(`The URL value is NOT a valid whitelist item: ${urlValue}`); + process.exit(0); + } + config = require(path.resolve(__dirname, process.argv[2])); + await sendTransaction(urlKey, urlValue); +} + +function usage() { + console.log("\nExample commandlines:\n node sendAddToDevelopersUrlWhitelistTx.js config_local.js ") + console.log("\nExample commandlines:\n node sendAddToDevelopersUrlWhitelistTx.js config_local.js 0 http://localhost:8000") + process.exit(0) +} + +processArguments(); \ No newline at end of file From 3b99ed95cb6b97ef1e12109dfc9a9fdeace6a0da Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 27 Apr 2023 16:33:05 +0900 Subject: [PATCH 11/41] Add sendRemoveFromDevelopersUrlWhitelistTx.js developer tool --- .../sendRemoveFromDevelopersUrlWhitelistTx.js | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js diff --git a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js new file mode 100644 index 000000000..9fff43216 --- /dev/null +++ b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js @@ -0,0 +1,63 @@ +// A tool to deregister a URL from the developers URL whitelist. +// This can be tested with the tool scripts under tools/chatbot. +const path = require('path'); +const CommonUtil = require('../../common/common-util'); +const PathUtil = require('../../common/path-util'); +const { signAndSendTx, confirmTransaction } = require('../util'); +let config = {}; + +function buildTxBody(timestamp, address, urlKey) { + const urlPath = CommonUtil.appendPath( + PathUtil.getDevelopersRestFunctionsUrlWhitelistUserPath(address), urlKey); + return { + operation: { + type: 'SET_VALUE', + ref: urlPath, + value: null, + }, + gas_price: 500, + timestamp, + nonce: -1 + }; +} + +async function sendTransaction(urlKey) { + console.log('\n*** sendTransaction():'); + const timestamp = Date.now(); + + if (!CommonUtil.isCksumAddr(config.developerAddr)) { + console.log(`The developer address is NOT a checksum address: ${config.developerAddr}`); + process.exit(0); + } + const txBody = buildTxBody(timestamp, config.developerAddr, urlKey); + console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); + + const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey); + console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); + if (!txInfo.success) { + console.log(`Transaction failed.`); + process.exit(0); + } + await confirmTransaction(config.endpointUrl, timestamp, txInfo.txHash); +} + +async function processArguments() { + if (process.argv.length !== 4) { + usage(); + } + const urlKey = process.argv[3]; + if (!CommonUtil.isString(urlKey) || urlKey.length == 0) { + console.log(`The URL key is NOT a valid one: ${urlKey}`); + process.exit(0); + } + config = require(path.resolve(__dirname, process.argv[2])); + await sendTransaction(urlKey); +} + +function usage() { + console.log("\nExample commandlines:\n node sendRemoveFromDevelopersUrlWhitelistTx.js config_local.js ") + console.log("\nExample commandlines:\n node sendRemoveFromDevelopersUrlWhitelistTx.js config_local.js 0") + process.exit(0) +} + +processArguments(); \ No newline at end of file From 814e18bc1d4b363cf8a7e766170c6dc77e569e47 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 27 Apr 2023 19:53:49 +0900 Subject: [PATCH 12/41] Use keystore file instead of private key --- tools/account/keystoreToAccount.js | 23 +++------------- tools/developers/config_gcp.js | 3 --- tools/developers/config_local.js | 3 --- .../sendAddToDevelopersUrlWhitelistTx.js | 24 +++++++++-------- .../sendAddToDevelopersUserWhitelistTx.js | 26 +++++++++++-------- .../sendRemoveFromDevelopersUrlWhitelistTx.js | 24 +++++++++-------- ...sendRemoveFromDevelopersUserWhitelistTx.js | 26 +++++++++++-------- tools/util.js | 21 +++++++++++++++ 8 files changed, 80 insertions(+), 70 deletions(-) diff --git a/tools/account/keystoreToAccount.js b/tools/account/keystoreToAccount.js index 68a9e91f0..c76b1dc22 100644 --- a/tools/account/keystoreToAccount.js +++ b/tools/account/keystoreToAccount.js @@ -1,28 +1,11 @@ -const fs = require('fs'); -const ainUtil = require('@ainblockchain/ain-util'); -const prompt = require('prompt'); - -async function keystoreToAccount(filePath) { - prompt.message = ''; - prompt.delimiter = ''; - prompt.colors = false; - prompt.start(); - const input = await prompt.get([{ - name: 'password', - description: 'Enter password:', - hidden: true, - }]); - const keystore = JSON.parse(fs.readFileSync(filePath)); - console.log(keystore, input) - const account = ainUtil.privateToAccount(ainUtil.v3KeystoreToPrivate(keystore, input.password)); - console.log('\nAccount:', account, '\n'); -} +const { keystoreToAccount } = require('../util'); async function processArguments() { if (process.argv.length !== 3) { usage(); } - await keystoreToAccount(process.argv[2]); + const account = await keystoreToAccount(process.argv[2]); + console.log(`\nAccount: ${JSON.stringify(account, null, 2)}\n`); } function usage() { diff --git a/tools/developers/config_gcp.js b/tools/developers/config_gcp.js index b953e36d9..260b07ef2 100644 --- a/tools/developers/config_gcp.js +++ b/tools/developers/config_gcp.js @@ -1,6 +1,3 @@ module.exports = { endpointUrl: "https://staging-api.ainetwork.ai", - developerAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", - serviceOwnerAddr: "0xAAAf6f50A0304F12119D218b94bea8082642515B", - serviceOwnerPrivateKey: "a2b5848760d81afe205884284716f90356ad82be5ab77b8130980bdb0b7ba2ba", }; \ No newline at end of file diff --git a/tools/developers/config_local.js b/tools/developers/config_local.js index a01d21d9e..bf0f8a1ca 100644 --- a/tools/developers/config_local.js +++ b/tools/developers/config_local.js @@ -1,6 +1,3 @@ module.exports = { endpointUrl: "http://localhost:8081", - developerAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", - serviceOwnerAddr: "0xAAAf6f50A0304F12119D218b94bea8082642515B", - serviceOwnerPrivateKey: "a2b5848760d81afe205884284716f90356ad82be5ab77b8130980bdb0b7ba2ba", }; \ No newline at end of file diff --git a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js index ac5d90bc3..c944aba8c 100644 --- a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js @@ -3,7 +3,7 @@ const path = require('path'); const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); -const { signAndSendTx, confirmTransaction } = require('../util'); +const { keystoreToAccount, signAndSendTx, confirmTransaction } = require('../util'); let config = {}; function buildTxBody(timestamp, address, urlKey, urlValue) { @@ -21,18 +21,18 @@ function buildTxBody(timestamp, address, urlKey, urlValue) { }; } -async function sendTransaction(urlKey, urlValue) { +async function sendTransaction(urlKey, urlValue, keystoreAccount) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - if (!CommonUtil.isCksumAddr(config.developerAddr)) { - console.log(`The developer address is NOT a checksum address: ${config.developerAddr}`); + if (!CommonUtil.isCksumAddr(keystoreAccount.address)) { + console.log(`The developer address is NOT a checksum address: ${keystoreAccount.address}`); process.exit(0); } - const txBody = buildTxBody(timestamp, config.developerAddr, urlKey, urlValue); + const txBody = buildTxBody(timestamp, keystoreAccount.address, urlKey, urlValue); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey); + const txInfo = await signAndSendTx(config.endpointUrl, txBody, keystoreAccount.private_key); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); @@ -42,9 +42,10 @@ async function sendTransaction(urlKey, urlValue) { } async function processArguments() { - if (process.argv.length !== 5) { + if (process.argv.length !== 6) { usage(); } + config = require(path.resolve(__dirname, process.argv[2])); const urlKey = process.argv[3]; if (!CommonUtil.isString(urlKey) || urlKey.length == 0) { console.log(`The URL key is NOT a valid one: ${urlKey}`); @@ -55,13 +56,14 @@ async function processArguments() { console.log(`The URL value is NOT a valid whitelist item: ${urlValue}`); process.exit(0); } - config = require(path.resolve(__dirname, process.argv[2])); - await sendTransaction(urlKey, urlValue); + const keystoreAccount = await keystoreToAccount(process.argv[5]); + console.log(`\nKeystore account address: ${keystoreAccount.address}\n`); + await sendTransaction(urlKey, urlValue, keystoreAccount); } function usage() { - console.log("\nExample commandlines:\n node sendAddToDevelopersUrlWhitelistTx.js config_local.js ") - console.log("\nExample commandlines:\n node sendAddToDevelopersUrlWhitelistTx.js config_local.js 0 http://localhost:8000") + console.log('\nUsage: node sendAddToDevelopersUrlWhitelistTx.js \n'); + console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js config_local.js 0 http://localhost:8000 keystore.json\n'); process.exit(0) } diff --git a/tools/developers/sendAddToDevelopersUserWhitelistTx.js b/tools/developers/sendAddToDevelopersUserWhitelistTx.js index e9d7b04f0..b752a413c 100644 --- a/tools/developers/sendAddToDevelopersUserWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUserWhitelistTx.js @@ -3,7 +3,7 @@ const path = require('path'); const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); -const { signAndSendTx, confirmTransaction } = require('../util'); +const { keystoreToAccount, signAndSendTx, confirmTransaction } = require('../util'); let config = {}; function buildTxBody(timestamp, address) { @@ -20,18 +20,14 @@ function buildTxBody(timestamp, address) { }; } -async function sendTransaction() { +async function sendTransaction(developerAddr, keystoreAccount) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - if (!CommonUtil.isCksumAddr(config.developerAddr)) { - console.log(`The developer address is NOT a checksum address: ${config.developerAddr}`); - process.exit(0); - } - const txBody = buildTxBody(timestamp, config.developerAddr); + const txBody = buildTxBody(timestamp, developerAddr); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey); + const txInfo = await signAndSendTx(config.endpointUrl, txBody, keystoreAccount.private_key); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); @@ -41,15 +37,23 @@ async function sendTransaction() { } async function processArguments() { - if (process.argv.length !== 3) { + if (process.argv.length !== 5) { usage(); } config = require(path.resolve(__dirname, process.argv[2])); - await sendTransaction(); + const developerAddr = process.argv[3]; + if (!CommonUtil.isCksumAddr(developerAddr)) { + console.log(`The developer address is NOT a checksum address: ${developerAddr}`); + process.exit(0); + } + const keystoreAccount = await keystoreToAccount(process.argv[4]); + console.log(`\nKeystore account address: ${keystoreAccount.address}\n`); + await sendTransaction(developerAddr, keystoreAccount); } function usage() { - console.log("\nExample commandlines:\n node sendAddToDevelopersUserWhitelistTx.js config_local.js") + console.log('\nUsage: node sendAddToDevelopersUserWhitelistTx.js \n'); + console.log('Example: node sendAddToDevelopersUserWhitelistTx.js config_local.js 0x09A0d53FDf1c36A131938eb379b98910e55EEfe1 keystore.json\n'); process.exit(0) } diff --git a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js index 9fff43216..634dfe242 100644 --- a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js @@ -3,7 +3,7 @@ const path = require('path'); const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); -const { signAndSendTx, confirmTransaction } = require('../util'); +const { keystoreToAccount, signAndSendTx, confirmTransaction } = require('../util'); let config = {}; function buildTxBody(timestamp, address, urlKey) { @@ -21,18 +21,18 @@ function buildTxBody(timestamp, address, urlKey) { }; } -async function sendTransaction(urlKey) { +async function sendTransaction(urlKey, keystoreAccount) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - if (!CommonUtil.isCksumAddr(config.developerAddr)) { - console.log(`The developer address is NOT a checksum address: ${config.developerAddr}`); + if (!CommonUtil.isCksumAddr(keystoreAccount.address)) { + console.log(`The developer address is NOT a checksum address: ${keystoreAccount.address}`); process.exit(0); } - const txBody = buildTxBody(timestamp, config.developerAddr, urlKey); + const txBody = buildTxBody(timestamp, keystoreAccount.address, urlKey); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey); + const txInfo = await signAndSendTx(config.endpointUrl, txBody, keystoreAccount.private_key); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); @@ -42,21 +42,23 @@ async function sendTransaction(urlKey) { } async function processArguments() { - if (process.argv.length !== 4) { + if (process.argv.length !== 5) { usage(); } + config = require(path.resolve(__dirname, process.argv[2])); const urlKey = process.argv[3]; if (!CommonUtil.isString(urlKey) || urlKey.length == 0) { console.log(`The URL key is NOT a valid one: ${urlKey}`); process.exit(0); } - config = require(path.resolve(__dirname, process.argv[2])); - await sendTransaction(urlKey); + const keystoreAccount = await keystoreToAccount(process.argv[4]); + console.log(`\nKeystore account address: ${keystoreAccount.address}\n`); + await sendTransaction(urlKey, keystoreAccount); } function usage() { - console.log("\nExample commandlines:\n node sendRemoveFromDevelopersUrlWhitelistTx.js config_local.js ") - console.log("\nExample commandlines:\n node sendRemoveFromDevelopersUrlWhitelistTx.js config_local.js 0") + console.log('\nUsage: node sendRemoveFromDevelopersUrlWhitelistTx.js \n'); + console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js config_local.js 0 keystore.json\n'); process.exit(0) } diff --git a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js index ce30e37ef..fc791a11b 100644 --- a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js @@ -3,7 +3,7 @@ const path = require('path'); const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); -const { signAndSendTx, confirmTransaction } = require('../util'); +const { keystoreToAccount, signAndSendTx, confirmTransaction } = require('../util'); let config = {}; function buildTxBody(timestamp, address) { @@ -20,18 +20,14 @@ function buildTxBody(timestamp, address) { }; } -async function sendTransaction() { +async function sendTransaction(developerAddr, keystoreAccount) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - if (!CommonUtil.isCksumAddr(config.developerAddr)) { - console.log(`The developer address is NOT a checksum address: ${config.developerAddr}`); - process.exit(0); - } - const txBody = buildTxBody(timestamp, config.developerAddr); + const txBody = buildTxBody(timestamp, developerAddr); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey); + const txInfo = await signAndSendTx(config.endpointUrl, txBody, keystoreAccount.private_key); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); @@ -41,15 +37,23 @@ async function sendTransaction() { } async function processArguments() { - if (process.argv.length !== 3) { + if (process.argv.length !== 5) { usage(); } config = require(path.resolve(__dirname, process.argv[2])); - await sendTransaction(); + const developerAddr = process.argv[3]; + if (!CommonUtil.isCksumAddr(developerAddr)) { + console.log(`The developer address is NOT a checksum address: ${developerAddr}`); + process.exit(0); + } + const keystoreAccount = await keystoreToAccount(process.argv[4]); + console.log(`\nKeystore account address: ${keystoreAccount.address}\n`); + await sendTransaction(developerAddr, keystoreAccount); } function usage() { - console.log("\nExample commandlines:\n node sendRemoveFromDevelopersUserWhitelistTx.js config_local.js") + console.log('\nUsage: node sendRemoveFromDevelopersUserWhitelistTx.js \n'); + console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js config_local.js 0x09A0d53FDf1c36A131938eb379b98910e55EEfe1 keystore.json\n'); process.exit(0) } diff --git a/tools/util.js b/tools/util.js index 33a977fe1..ba17bb77f 100644 --- a/tools/util.js +++ b/tools/util.js @@ -1,9 +1,29 @@ const _ = require('lodash'); +const fs = require('fs'); +const prompt = require('prompt'); const axios = require('axios'); +const ainUtil = require('@ainblockchain/ain-util'); const { BlockchainConsts } = require('../common/constants'); const CommonUtil = require('../common/common-util'); const { JSON_RPC_METHODS } = require('../json_rpc/constants'); +async function keystoreToAccount(filePath) { + const keystore = JSON.parse(fs.readFileSync(filePath)); + console.log(`\nKeystore: ${JSON.stringify(keystore, null, 2)}\n`) + + prompt.message = ''; + prompt.delimiter = ''; + prompt.colors = false; + prompt.start(); + const input = await prompt.get([{ + name: 'password', + description: 'Enter password:', + hidden: true, + }]); + + return ainUtil.privateToAccount(ainUtil.v3KeystoreToPrivate(keystore, input.password)); +} + // FIXME(minsulee2): this is duplicated function see: ./common/network-util.js function signAndSendTx(endpointUrl, txBody, privateKey, chainId) { console.log('\n*** signAndSendTx():'); @@ -67,6 +87,7 @@ async function confirmTransaction(endpointUrl, timestamp, txHash) { } module.exports = { + keystoreToAccount, signAndSendTx, sendGetTxByHashRequest, confirmTransaction, From eecb9867b3f95e0157d22144d4bfe86efa722804 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 27 Apr 2023 20:01:51 +0900 Subject: [PATCH 13/41] Tweak usage --- tools/chatbot/sendCreateAppAndConfigTx.js | 3 ++- tools/chatbot/sendMessageTx.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/chatbot/sendCreateAppAndConfigTx.js b/tools/chatbot/sendCreateAppAndConfigTx.js index 5635c1869..2210139d5 100644 --- a/tools/chatbot/sendCreateAppAndConfigTx.js +++ b/tools/chatbot/sendCreateAppAndConfigTx.js @@ -107,7 +107,8 @@ async function processArguments() { } function usage() { - console.log('\nExample commandlines:\n node sendCreateAppAndConfigTx.js config_local.js\n') + console.log("\nUsage: node sendCreateAppAndConfigTx.js \n") + console.log("Example: node sendCreateAppAndConfigTx.js config_local.js 'Hello'\n") process.exit(0) } diff --git a/tools/chatbot/sendMessageTx.js b/tools/chatbot/sendMessageTx.js index 6ece23452..81a56012b 100644 --- a/tools/chatbot/sendMessageTx.js +++ b/tools/chatbot/sendMessageTx.js @@ -46,8 +46,8 @@ async function processArguments() { } function usage() { - console.log("\nExample commandlines:\n node sendMessageTx.js config_local.js") - console.log("\nExample commandlines:\n node sendMessageTx.js config_local.js 'Hello'") + console.log("\nUsage: node sendMessageTx.js \n") + console.log("Example: node sendMessageTx.js config_local.js 'Hello'\n") process.exit(0) } From e19fca455813e1986389640821012aa7add2503c Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 27 Apr 2023 20:11:27 +0900 Subject: [PATCH 14/41] Add more comments. --- tools/developers/sendAddToDevelopersUrlWhitelistTx.js | 1 + tools/developers/sendAddToDevelopersUserWhitelistTx.js | 1 + tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js | 1 + tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js | 1 + 4 files changed, 4 insertions(+) diff --git a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js index c944aba8c..c38bb1741 100644 --- a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js @@ -1,4 +1,5 @@ // A tool to register a URL to the developers URL whitelist. +// This should be executed with developer's keystore files. // This can be tested with the tool scripts under tools/chatbot. const path = require('path'); const CommonUtil = require('../../common/common-util'); diff --git a/tools/developers/sendAddToDevelopersUserWhitelistTx.js b/tools/developers/sendAddToDevelopersUserWhitelistTx.js index b752a413c..72e8dd424 100644 --- a/tools/developers/sendAddToDevelopersUserWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUserWhitelistTx.js @@ -1,4 +1,5 @@ // A tool to register an address to the developers user whitelist. +// This should be executed with blockchain owner's keystore files. // This can be tested with the tool scripts under tools/chatbot. const path = require('path'); const CommonUtil = require('../../common/common-util'); diff --git a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js index 634dfe242..f0a6dc760 100644 --- a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js @@ -1,4 +1,5 @@ // A tool to deregister a URL from the developers URL whitelist. +// This should be executed with developer's keystore files. // This can be tested with the tool scripts under tools/chatbot. const path = require('path'); const CommonUtil = require('../../common/common-util'); diff --git a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js index fc791a11b..0d381f905 100644 --- a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js @@ -1,4 +1,5 @@ // A tool to deregister an address from the developers user whitelist. +// This should be executed with blockchain owner's keystore files. // This can be tested with the tool scripts under tools/chatbot. const path = require('path'); const CommonUtil = require('../../common/common-util'); From de53dc4d5d774696d889a6f16b40fb0adbd4ae79 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Tue, 2 May 2023 18:07:49 +0900 Subject: [PATCH 15/41] Tweak usage --- tools/chatbot/sendMessageTx.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/chatbot/sendMessageTx.js b/tools/chatbot/sendMessageTx.js index 81a56012b..5c11f89d5 100644 --- a/tools/chatbot/sendMessageTx.js +++ b/tools/chatbot/sendMessageTx.js @@ -46,7 +46,8 @@ async function processArguments() { } function usage() { - console.log("\nUsage: node sendMessageTx.js \n") + console.log("\nUsage: node sendMessageTx.js []\n") + console.log("Example: node sendMessageTx.js config_local.js\n") console.log("Example: node sendMessageTx.js config_local.js 'Hello'\n") process.exit(0) } From ed1ed54f04d3d8f21a22a6ff8899ac06b13a88b2 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Tue, 2 May 2023 18:16:52 +0900 Subject: [PATCH 16/41] Tweak comments --- tools/developers/sendAddToDevelopersUrlWhitelistTx.js | 2 +- tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js index c38bb1741..746fbed11 100644 --- a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js @@ -1,4 +1,4 @@ -// A tool to register a URL to the developers URL whitelist. +// A tool to register a URL to the developers URL whitelist (i.e., REST function URL whitelist). // This should be executed with developer's keystore files. // This can be tested with the tool scripts under tools/chatbot. const path = require('path'); diff --git a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js index f0a6dc760..df4dd0de5 100644 --- a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js @@ -1,4 +1,4 @@ -// A tool to deregister a URL from the developers URL whitelist. +// A tool to deregister a URL from the developers URL whitelist (i.e., REST function URL whitelist). // This should be executed with developer's keystore files. // This can be tested with the tool scripts under tools/chatbot. const path = require('path'); From 6327cf2bfb0974ef0d9b3358d1aa1cd46e4070d0 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Tue, 2 May 2023 18:27:45 +0900 Subject: [PATCH 17/41] Add sample keystore files --- tools/developers/keystore_developer_dev_staging.json | 1 + tools/developers/keystore_owner_dev_staging.json | 1 + tools/developers/sendAddToDevelopersUserWhitelistTx.js | 2 +- tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 tools/developers/keystore_developer_dev_staging.json create mode 100644 tools/developers/keystore_owner_dev_staging.json diff --git a/tools/developers/keystore_developer_dev_staging.json b/tools/developers/keystore_developer_dev_staging.json new file mode 100644 index 000000000..df2a7cff0 --- /dev/null +++ b/tools/developers/keystore_developer_dev_staging.json @@ -0,0 +1 @@ +{"version":3,"id":"0ca3c829-4b9b-403c-9a8f-a87c823c50b2","address":"08aed7af9354435c38d52143ee50ac839d20696b","crypto":{"ciphertext":"3e543fff76cf4e23c5d29db0ff8d437da1e35654e3861c4ef690d0135599e6df","cipherparams":{"iv":"7146b9d7c0068e2b741d8774b526d2ae"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"fd8b94e9e6c72c89ea6fb37f84b6c63de026769f9656aa8fd6166959ec27aa68","n":262144,"r":8,"p":1},"mac":"b71aed58015c67a0b0a9edc7b727a8affda2091c185964eb9c41af47ebc5d97e"}} \ No newline at end of file diff --git a/tools/developers/keystore_owner_dev_staging.json b/tools/developers/keystore_owner_dev_staging.json new file mode 100644 index 000000000..f7edc0767 --- /dev/null +++ b/tools/developers/keystore_owner_dev_staging.json @@ -0,0 +1 @@ +{"version":3,"id":"7825b108-83c5-4343-b61c-7e8d4d1c1593","address":"aaaf6f50a0304f12119d218b94bea8082642515b","crypto":{"ciphertext":"88a398a54e454ec85b0b12563d585d45f422041914b0d7d934154523c064ab33","cipherparams":{"iv":"f9362201b57e1ee4cfc35590ad0a660e"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"517d302da151cb9ba33acc1c35df9a1aa44938ab941a39e85ebb19f75d2d5196","n":262144,"r":8,"p":1},"mac":"bcf14e22783477bcd3ff7da6df73c273d7bfc63e60b7368f8238b037483cbd27"}} diff --git a/tools/developers/sendAddToDevelopersUserWhitelistTx.js b/tools/developers/sendAddToDevelopersUserWhitelistTx.js index 72e8dd424..55b8da4b3 100644 --- a/tools/developers/sendAddToDevelopersUserWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUserWhitelistTx.js @@ -54,7 +54,7 @@ async function processArguments() { function usage() { console.log('\nUsage: node sendAddToDevelopersUserWhitelistTx.js \n'); - console.log('Example: node sendAddToDevelopersUserWhitelistTx.js config_local.js 0x09A0d53FDf1c36A131938eb379b98910e55EEfe1 keystore.json\n'); + console.log('Example: node sendAddToDevelopersUserWhitelistTx.js config_local.js 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore.json\n'); process.exit(0) } diff --git a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js index 0d381f905..e9351e851 100644 --- a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js @@ -54,7 +54,7 @@ async function processArguments() { function usage() { console.log('\nUsage: node sendRemoveFromDevelopersUserWhitelistTx.js \n'); - console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js config_local.js 0x09A0d53FDf1c36A131938eb379b98910e55EEfe1 keystore.json\n'); + console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js config_local.js 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore.json\n'); process.exit(0) } From 91f5be6d8eb75614764447720e523e66b988c693 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Tue, 2 May 2023 18:53:04 +0900 Subject: [PATCH 18/41] Tweak filenames and usages --- ...taging.json => keystore_blockchain_owner_dev_staging.json} | 0 tools/developers/sendAddToDevelopersUrlWhitelistTx.js | 4 ++-- tools/developers/sendAddToDevelopersUserWhitelistTx.js | 4 ++-- tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js | 4 ++-- tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) rename tools/developers/{keystore_owner_dev_staging.json => keystore_blockchain_owner_dev_staging.json} (100%) diff --git a/tools/developers/keystore_owner_dev_staging.json b/tools/developers/keystore_blockchain_owner_dev_staging.json similarity index 100% rename from tools/developers/keystore_owner_dev_staging.json rename to tools/developers/keystore_blockchain_owner_dev_staging.json diff --git a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js index 746fbed11..2b14b7352 100644 --- a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js @@ -63,8 +63,8 @@ async function processArguments() { } function usage() { - console.log('\nUsage: node sendAddToDevelopersUrlWhitelistTx.js \n'); - console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js config_local.js 0 http://localhost:8000 keystore.json\n'); + console.log('\nUsage: node sendAddToDevelopersUrlWhitelistTx.js \n'); + console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js config_local.js 0 http://localhost:8000 keystore_developer.json\n'); process.exit(0) } diff --git a/tools/developers/sendAddToDevelopersUserWhitelistTx.js b/tools/developers/sendAddToDevelopersUserWhitelistTx.js index 55b8da4b3..76b24345c 100644 --- a/tools/developers/sendAddToDevelopersUserWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUserWhitelistTx.js @@ -53,8 +53,8 @@ async function processArguments() { } function usage() { - console.log('\nUsage: node sendAddToDevelopersUserWhitelistTx.js \n'); - console.log('Example: node sendAddToDevelopersUserWhitelistTx.js config_local.js 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore.json\n'); + console.log('\nUsage: node sendAddToDevelopersUserWhitelistTx.js \n'); + console.log('Example: node sendAddToDevelopersUserWhitelistTx.js config_local.js 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json\n'); process.exit(0) } diff --git a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js index df4dd0de5..4223d3e3b 100644 --- a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js @@ -58,8 +58,8 @@ async function processArguments() { } function usage() { - console.log('\nUsage: node sendRemoveFromDevelopersUrlWhitelistTx.js \n'); - console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js config_local.js 0 keystore.json\n'); + console.log('\nUsage: node sendRemoveFromDevelopersUrlWhitelistTx.js \n'); + console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js config_local.js 0 keystore_developer.json\n'); process.exit(0) } diff --git a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js index e9351e851..453f64b3f 100644 --- a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js @@ -53,8 +53,8 @@ async function processArguments() { } function usage() { - console.log('\nUsage: node sendRemoveFromDevelopersUserWhitelistTx.js \n'); - console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js config_local.js 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore.json\n'); + console.log('\nUsage: node sendRemoveFromDevelopersUserWhitelistTx.js \n'); + console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js config_local.js 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json\n'); process.exit(0) } From 2a4181e94a45d7c04064441ffc6453d91194f248 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sat, 6 May 2023 01:03:57 +0900 Subject: [PATCH 19/41] Support HOSTING_ENV === 'aws' option --- common/network-util.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/common/network-util.js b/common/network-util.js index c6b7e0db2..0abc2f867 100644 --- a/common/network-util.js +++ b/common/network-util.js @@ -8,10 +8,10 @@ const extIp = require('ext-ip')(); const CommonUtil = require('../common/common-util'); const DB = require('../db'); const { JSON_RPC_METHODS } = require('../json_rpc/constants'); -const GCP_EXTERNAL_IP_URL = 'http://metadata.google.internal/computeMetadata/v1/instance' + - '/network-interfaces/0/access-configs/0/external-ip'; -const GCP_INTERNAL_IP_URL = 'http://metadata.google.internal/computeMetadata/v1/instance' + - '/network-interfaces/0/ip'; +const GCP_EXTERNAL_IP_URL = 'http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip'; +const GCP_INTERNAL_IP_URL = 'http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip'; +const AWS_EXTERNAL_IP_URL = 'http://169.254.169.254/latest/meta-data/public-ipv4'; +const AWS_INTERNAL_IP_URL = 'http://169.254.169.254/latest/meta-data/local-ipv4'; axios.defaults.timeout = NodeConfigs.DEFAULT_AXIOS_REQUEST_TIMEOUT; @@ -108,6 +108,17 @@ function getIpAddress(internal = false) { CommonUtil.finishWithStackTrace( logger, `Failed to get ip address: ${JSON.stringify(err, null, 2)}`); }); + } else if (NodeConfigs.HOSTING_ENV === 'aws') { + return axios.get(internal ? AWS_INTERNAL_IP_URL : AWS_EXTERNAL_IP_URL, { + timeout: 3000 + }) + .then((res) => { + return res.data; + }) + .catch((err) => { + CommonUtil.finishWithStackTrace( + logger, `Failed to get ip address: ${JSON.stringify(err, null, 2)}`); + }); } else { if (internal) { return ip.address(); From 54a13a157e528ed6bc1365a77a2a4fe43a9b8c7d Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 8 May 2023 12:16:18 +0900 Subject: [PATCH 20/41] Add HostingEnvs enum definition --- common/constants.js | 13 +++++++++++++ common/network-util.js | 6 +++--- consensus/index.js | 3 ++- event-handler/event-channel-manager.js | 3 ++- logger/bunyan-util.js | 4 ++-- logger/winston-util.js | 4 ++-- p2p/p2p-util.js | 5 +++-- p2p/server.js | 7 ++++--- 8 files changed, 31 insertions(+), 14 deletions(-) diff --git a/common/constants.js b/common/constants.js index 3913d375a..163e47571 100644 --- a/common/constants.js +++ b/common/constants.js @@ -131,6 +131,18 @@ function setNodeConfigs() { setNodeConfigs(); // ** Enums ** +/** + * Hosting Environments. + * + * @enum {string} + */ +const HostingEnvs = { + AWS: 'aws', // Amazon AWS + COMCOM: 'comcom', // ComCom On-Premise + LOCAL: 'local', // Local + GCP: 'gcp', // Google Cloud Platform +}; + /** * Types of P2P network messages. * @@ -821,6 +833,7 @@ module.exports = { TimerFlagEnabledBandageMap, BlockchainParams, NodeConfigs, + HostingEnvs, P2pMessageTypes, BlockchainNodeStates, P2pNetworkStates, diff --git a/common/network-util.js b/common/network-util.js index 0abc2f867..bd7688344 100644 --- a/common/network-util.js +++ b/common/network-util.js @@ -2,7 +2,7 @@ const logger = new (require('../logger'))('NETWORK-UTIL'); const _ = require('lodash'); const axios = require('axios'); -const { BlockchainConsts, NodeConfigs } = require('../common/constants'); +const { BlockchainConsts, NodeConfigs, HostingEnvs } = require('../common/constants'); const ip = require('ip'); const extIp = require('ext-ip')(); const CommonUtil = require('../common/common-util'); @@ -96,7 +96,7 @@ function sendGetRequest(endpoint, method, params) { function getIpAddress(internal = false) { return Promise.resolve() .then(() => { - if (NodeConfigs.HOSTING_ENV === 'gcp') { + if (NodeConfigs.HOSTING_ENV === HostingEnvs.GCP) { return axios.get(internal ? GCP_INTERNAL_IP_URL : GCP_EXTERNAL_IP_URL, { headers: {'Metadata-Flavor': 'Google'}, timeout: 3000 @@ -108,7 +108,7 @@ function getIpAddress(internal = false) { CommonUtil.finishWithStackTrace( logger, `Failed to get ip address: ${JSON.stringify(err, null, 2)}`); }); - } else if (NodeConfigs.HOSTING_ENV === 'aws') { + } else if (NodeConfigs.HOSTING_ENV === HostingEnvs.AWS) { return axios.get(internal ? AWS_INTERNAL_IP_URL : AWS_EXTERNAL_IP_URL, { timeout: 3000 }) diff --git a/consensus/index.js b/consensus/index.js index 8a3df866c..0eefae8ae 100644 --- a/consensus/index.js +++ b/consensus/index.js @@ -12,6 +12,7 @@ const PushId = require('../db/push-id'); const { BlockchainConsts, NodeConfigs, + HostingEnvs, WriteDbOperations, PredefinedDbPaths, StateVersions, @@ -155,7 +156,7 @@ class Consensus { this.isInEpochTransition = true; this.node.tryFinalizeChain(); let currentTime = Date.now(); - if (NodeConfigs.HOSTING_ENV !== 'local' && + if (NodeConfigs.HOSTING_ENV !== HostingEnvs.LOCAL && (this.epoch % 10 === 0 || CommonUtil.timestampExceedsThreshold( this.ntpData.syncedAt, healthThresholdEpoch * epochMs))) { // adjust time diff --git a/event-handler/event-channel-manager.js b/event-handler/event-channel-manager.js index aea851ded..11535fe6d 100644 --- a/event-handler/event-channel-manager.js +++ b/event-handler/event-channel-manager.js @@ -5,6 +5,7 @@ const { getIpAddress } = require('../common/network-util'); const { BlockchainEventMessageTypes, NodeConfigs, + HostingEnvs, BlockchainEventTypes, FilterDeletionReasons, } = require('../common/constants'); @@ -23,7 +24,7 @@ class EventChannelManager { } async getNetworkInfo() { - const ipAddr = await getIpAddress(NodeConfigs.HOSTING_ENV === 'comcom' || NodeConfigs.HOSTING_ENV === 'local'); + const ipAddr = await getIpAddress(NodeConfigs.HOSTING_ENV === HostingEnvs.COMCOM || NodeConfigs.HOSTING_ENV === HostingEnvs.LOCAL); const eventHandlerUrl = new URL(`ws://${ipAddr}:${NodeConfigs.EVENT_HANDLER_PORT}`); return { url: eventHandlerUrl.toString(), diff --git a/logger/bunyan-util.js b/logger/bunyan-util.js index e714810f6..0d710e540 100644 --- a/logger/bunyan-util.js +++ b/logger/bunyan-util.js @@ -4,7 +4,7 @@ const RotatingFileStream = require('bunyan-rotating-file-stream'); const bunyanFormat = require('bunyan-format'); const path = require('path'); const fs = require('fs'); -const { NodeConfigs } = require('../common/constants'); +const { NodeConfigs, HostingEnvs } = require('../common/constants'); const logDir = path.join(NodeConfigs.LOGS_DIR, String(NodeConfigs.PORT)); if (!fs.existsSync(logDir)) { fs.mkdirSync(logDir, { recursive: true }); @@ -60,7 +60,7 @@ const getBunyanTransports = () => { if (NodeConfigs.CONSOLE_LOG) { transports.push(getBunyanConsoleTransport()); } - if (NodeConfigs.HOSTING_ENV === 'gcp') { + if (NodeConfigs.HOSTING_ENV === HostingEnvs.GCP) { transports.push(gcloudLoggingBunyan()); } return transports; diff --git a/logger/winston-util.js b/logger/winston-util.js index b43f91678..14fdfb7ab 100644 --- a/logger/winston-util.js +++ b/logger/winston-util.js @@ -5,7 +5,7 @@ const winston = require('winston'); const { LoggingWinston } = require('@google-cloud/logging-winston'); const winstonDaily = require('winston-daily-rotate-file'); const path = require('path'); -const { NodeConfigs } = require('../common/constants'); +const { NodeConfigs, HostingEnvs } = require('../common/constants'); const { combine, timestamp, label, printf, colorize } = winston.format; @@ -102,7 +102,7 @@ const getWinstonTransports = () => { if (NodeConfigs.CONSOLE_LOG) { transports.push(getWinstonConsoleTransport()); } - if (NodeConfigs.HOSTING_ENV === 'gcp') { + if (NodeConfigs.HOSTING_ENV === HostingEnvs.GCP) { transports.push(new LoggingWinston); } return transports; diff --git a/p2p/p2p-util.js b/p2p/p2p-util.js index d7b5e23ac..c11749118 100644 --- a/p2p/p2p-util.js +++ b/p2p/p2p-util.js @@ -12,7 +12,8 @@ const ip = require('ip'); const ainUtil = require('@ainblockchain/ain-util'); const { BlockchainConsts, - NodeConfigs + NodeConfigs, + HostingEnvs } = require('../common/constants'); const CommonUtil = require('../common/common-util'); const DB = require('../db'); @@ -147,7 +148,7 @@ class P2pUtil { } static areIdenticalUrls(url1, url2) { - if (NodeConfigs.HOSTING_ENV === 'local') { + if (NodeConfigs.HOSTING_ENV === HostingEnvs.LOCAL) { const comparingUrl1 = new URL(url1); const comapringUrl2 = new URL(url2); return CommonUtil.isValidPrivateUrl(comparingUrl1.hostname) && diff --git a/p2p/server.js b/p2p/server.js index e65c1987a..1d3d99c23 100644 --- a/p2p/server.js +++ b/p2p/server.js @@ -29,6 +29,7 @@ const { StateLabelProperties, TrafficEventTypes, trafficStatsManager, + HostingEnvs, } = require('../common/constants'); const CommonUtil = require('../common/common-util'); const { ConsensusStates } = require('../consensus/constants'); @@ -325,11 +326,11 @@ class P2pServer { const extIp = this.getExternalIp(); let urls; switch (NodeConfigs.HOSTING_ENV) { - case 'local': + case HostingEnvs.LOCAL: urls = this.buildUrls(intIp); break; - case 'comcom': - case 'gcp': + case HostingEnvs.COMCOM: + case HostingEnvs.GCP: urls = this.buildUrls(extIp); break; } From 0afc7eab2a0077fb189aaeadb064006ffb476b6c Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Tue, 2 May 2023 20:44:57 +0900 Subject: [PATCH 21/41] Fix tool script usage --- tools/chatbot/sendCreateAppAndConfigTx.js | 2 +- tools/chatbot/sendMessageTx.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/chatbot/sendCreateAppAndConfigTx.js b/tools/chatbot/sendCreateAppAndConfigTx.js index 2210139d5..54e632cfd 100644 --- a/tools/chatbot/sendCreateAppAndConfigTx.js +++ b/tools/chatbot/sendCreateAppAndConfigTx.js @@ -108,7 +108,7 @@ async function processArguments() { function usage() { console.log("\nUsage: node sendCreateAppAndConfigTx.js \n") - console.log("Example: node sendCreateAppAndConfigTx.js config_local.js 'Hello'\n") + console.log("Example: node sendCreateAppAndConfigTx.js config_local.js\n") process.exit(0) } diff --git a/tools/chatbot/sendMessageTx.js b/tools/chatbot/sendMessageTx.js index 5c11f89d5..db33dce40 100644 --- a/tools/chatbot/sendMessageTx.js +++ b/tools/chatbot/sendMessageTx.js @@ -47,7 +47,7 @@ async function processArguments() { function usage() { console.log("\nUsage: node sendMessageTx.js []\n") - console.log("Example: node sendMessageTx.js config_local.js\n") + console.log("Example: node sendMessageTx.js config_local.js") console.log("Example: node sendMessageTx.js config_local.js 'Hello'\n") process.exit(0) } From 6ed1989e6916fb81c4ed0fb6666d1bd17bdc18bf Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Tue, 2 May 2023 21:13:28 +0900 Subject: [PATCH 22/41] Add chain id option to developer tools --- tools/developers/config_gcp.js | 3 --- tools/developers/config_local.js | 3 --- .../sendAddToDevelopersUrlWhitelistTx.js | 27 ++++++++++--------- .../sendAddToDevelopersUserWhitelistTx.js | 25 ++++++++--------- .../sendRemoveFromDevelopersUrlWhitelistTx.js | 25 ++++++++--------- ...sendRemoveFromDevelopersUserWhitelistTx.js | 25 ++++++++--------- 6 files changed, 53 insertions(+), 55 deletions(-) delete mode 100644 tools/developers/config_gcp.js delete mode 100644 tools/developers/config_local.js diff --git a/tools/developers/config_gcp.js b/tools/developers/config_gcp.js deleted file mode 100644 index 260b07ef2..000000000 --- a/tools/developers/config_gcp.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - endpointUrl: "https://staging-api.ainetwork.ai", -}; \ No newline at end of file diff --git a/tools/developers/config_local.js b/tools/developers/config_local.js deleted file mode 100644 index bf0f8a1ca..000000000 --- a/tools/developers/config_local.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - endpointUrl: "http://localhost:8081", -}; \ No newline at end of file diff --git a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js index 2b14b7352..4d1ee1475 100644 --- a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js @@ -1,11 +1,9 @@ // A tool to register a URL to the developers URL whitelist (i.e., REST function URL whitelist). // This should be executed with developer's keystore files. // This can be tested with the tool scripts under tools/chatbot. -const path = require('path'); const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); const { keystoreToAccount, signAndSendTx, confirmTransaction } = require('../util'); -let config = {}; function buildTxBody(timestamp, address, urlKey, urlValue) { const urlPath = CommonUtil.appendPath( @@ -22,7 +20,7 @@ function buildTxBody(timestamp, address, urlKey, urlValue) { }; } -async function sendTransaction(urlKey, urlValue, keystoreAccount) { +async function sendTransaction(endpointUrl, chainId, urlKey, urlValue, keystoreAccount) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); @@ -33,38 +31,41 @@ async function sendTransaction(urlKey, urlValue, keystoreAccount) { const txBody = buildTxBody(timestamp, keystoreAccount.address, urlKey, urlValue); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(config.endpointUrl, txBody, keystoreAccount.private_key); + const txInfo = await signAndSendTx(endpointUrl, txBody, keystoreAccount.private_key, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); process.exit(0); } - await confirmTransaction(config.endpointUrl, timestamp, txInfo.txHash); + await confirmTransaction(endpointUrl, timestamp, txInfo.txHash); } async function processArguments() { - if (process.argv.length !== 6) { + if (process.argv.length !== 7) { usage(); } - config = require(path.resolve(__dirname, process.argv[2])); - const urlKey = process.argv[3]; + const endpointUrl = process.argv[2]; + const chainId = Number(process.argv[3]); + const urlKey = process.argv[4]; if (!CommonUtil.isString(urlKey) || urlKey.length == 0) { console.log(`The URL key is NOT a valid one: ${urlKey}`); process.exit(0); } - const urlValue = process.argv[4]; + const urlValue = process.argv[5]; if (!CommonUtil.isValidUrlWhitelistItem(urlValue)) { console.log(`The URL value is NOT a valid whitelist item: ${urlValue}`); process.exit(0); } - const keystoreAccount = await keystoreToAccount(process.argv[5]); + const keystoreAccount = await keystoreToAccount(process.argv[6]); console.log(`\nKeystore account address: ${keystoreAccount.address}\n`); - await sendTransaction(urlKey, urlValue, keystoreAccount); + await sendTransaction(endpointUrl, chainId, urlKey, urlValue, keystoreAccount); } function usage() { - console.log('\nUsage: node sendAddToDevelopersUrlWhitelistTx.js \n'); - console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js config_local.js 0 http://localhost:8000 keystore_developer.json\n'); + console.log('\nUsage: node sendAddToDevelopersUrlWhitelistTx.js \n'); + console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js http://localhost:8081 0 0 http://localhost:8000 keystore_developer.json'); + console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js https://staging-api.ainetwork.ai 0 0 https://mydomain.com keystore_developer.json'); + console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js https://mainnet-api.ainetwork.ai 1 0 https://mydomain.com keystore_developer.json\n'); process.exit(0) } diff --git a/tools/developers/sendAddToDevelopersUserWhitelistTx.js b/tools/developers/sendAddToDevelopersUserWhitelistTx.js index 76b24345c..ff323f4ef 100644 --- a/tools/developers/sendAddToDevelopersUserWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUserWhitelistTx.js @@ -1,11 +1,9 @@ // A tool to register an address to the developers user whitelist. // This should be executed with blockchain owner's keystore files. // This can be tested with the tool scripts under tools/chatbot. -const path = require('path'); const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); const { keystoreToAccount, signAndSendTx, confirmTransaction } = require('../util'); -let config = {}; function buildTxBody(timestamp, address) { const userPath = PathUtil.getDevelopersRestFunctionsUserWhitelistUserPath(address); @@ -21,40 +19,43 @@ function buildTxBody(timestamp, address) { }; } -async function sendTransaction(developerAddr, keystoreAccount) { +async function sendTransaction(endpointUrl, chainId, developerAddr, keystoreAccount) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); const txBody = buildTxBody(timestamp, developerAddr); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(config.endpointUrl, txBody, keystoreAccount.private_key); + const txInfo = await signAndSendTx(endpointUrl, txBody, keystoreAccount.private_key, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); process.exit(0); } - await confirmTransaction(config.endpointUrl, timestamp, txInfo.txHash); + await confirmTransaction(endpointUrl, timestamp, txInfo.txHash); } async function processArguments() { - if (process.argv.length !== 5) { + if (process.argv.length !== 6) { usage(); } - config = require(path.resolve(__dirname, process.argv[2])); - const developerAddr = process.argv[3]; + const endpointUrl = process.argv[2]; + const chainId = Number(process.argv[3]); + const developerAddr = process.argv[4]; if (!CommonUtil.isCksumAddr(developerAddr)) { console.log(`The developer address is NOT a checksum address: ${developerAddr}`); process.exit(0); } - const keystoreAccount = await keystoreToAccount(process.argv[4]); + const keystoreAccount = await keystoreToAccount(process.argv[5]); console.log(`\nKeystore account address: ${keystoreAccount.address}\n`); - await sendTransaction(developerAddr, keystoreAccount); + await sendTransaction(endpointUrl, chainId, developerAddr, keystoreAccount); } function usage() { - console.log('\nUsage: node sendAddToDevelopersUserWhitelistTx.js \n'); - console.log('Example: node sendAddToDevelopersUserWhitelistTx.js config_local.js 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json\n'); + console.log('\nUsage: node sendAddToDevelopersUserWhitelistTx.js \n'); + console.log('Example: node sendAddToDevelopersUserWhitelistTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json'); + console.log('Example: node sendAddToDevelopersUserWhitelistTx.js https://staging-api.ainetwork.ai 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json'); + console.log('Example: node sendAddToDevelopersUserWhitelistTx.js https://mainnet-api.ainetwork.ai 1 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json\n'); process.exit(0) } diff --git a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js index 4223d3e3b..79b93f8cd 100644 --- a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js @@ -1,11 +1,9 @@ // A tool to deregister a URL from the developers URL whitelist (i.e., REST function URL whitelist). // This should be executed with developer's keystore files. // This can be tested with the tool scripts under tools/chatbot. -const path = require('path'); const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); const { keystoreToAccount, signAndSendTx, confirmTransaction } = require('../util'); -let config = {}; function buildTxBody(timestamp, address, urlKey) { const urlPath = CommonUtil.appendPath( @@ -22,7 +20,7 @@ function buildTxBody(timestamp, address, urlKey) { }; } -async function sendTransaction(urlKey, keystoreAccount) { +async function sendTransaction(endpointUrl, chainId, urlKey, keystoreAccount) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); @@ -33,33 +31,36 @@ async function sendTransaction(urlKey, keystoreAccount) { const txBody = buildTxBody(timestamp, keystoreAccount.address, urlKey); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(config.endpointUrl, txBody, keystoreAccount.private_key); + const txInfo = await signAndSendTx(endpointUrl, txBody, keystoreAccount.private_key, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); process.exit(0); } - await confirmTransaction(config.endpointUrl, timestamp, txInfo.txHash); + await confirmTransaction(endpointUrl, timestamp, txInfo.txHash); } async function processArguments() { - if (process.argv.length !== 5) { + if (process.argv.length !== 6) { usage(); } - config = require(path.resolve(__dirname, process.argv[2])); - const urlKey = process.argv[3]; + const endpointUrl = process.argv[2]; + const chainId = Number(process.argv[3]); + const urlKey = process.argv[4]; if (!CommonUtil.isString(urlKey) || urlKey.length == 0) { console.log(`The URL key is NOT a valid one: ${urlKey}`); process.exit(0); } - const keystoreAccount = await keystoreToAccount(process.argv[4]); + const keystoreAccount = await keystoreToAccount(process.argv[5]); console.log(`\nKeystore account address: ${keystoreAccount.address}\n`); - await sendTransaction(urlKey, keystoreAccount); + await sendTransaction(endpointUrl, chainId, urlKey, keystoreAccount); } function usage() { - console.log('\nUsage: node sendRemoveFromDevelopersUrlWhitelistTx.js \n'); - console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js config_local.js 0 keystore_developer.json\n'); + console.log('\nUsage: node sendRemoveFromDevelopersUrlWhitelistTx.js \n'); + console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js http://localhost:8081 0 0 keystore_developer.json'); + console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js https://staging-api.ainetwork.ai 0 0 keystore_developer.json'); + console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js https://mainnet-api.ainetwork.ai 1 0 keystore_developer.json\n'); process.exit(0) } diff --git a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js index 453f64b3f..1afabd769 100644 --- a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js @@ -1,11 +1,9 @@ // A tool to deregister an address from the developers user whitelist. // This should be executed with blockchain owner's keystore files. // This can be tested with the tool scripts under tools/chatbot. -const path = require('path'); const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); const { keystoreToAccount, signAndSendTx, confirmTransaction } = require('../util'); -let config = {}; function buildTxBody(timestamp, address) { const userPath = PathUtil.getDevelopersRestFunctionsUserWhitelistUserPath(address); @@ -21,40 +19,43 @@ function buildTxBody(timestamp, address) { }; } -async function sendTransaction(developerAddr, keystoreAccount) { +async function sendTransaction(endpointUrl, chainId, developerAddr, keystoreAccount) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); const txBody = buildTxBody(timestamp, developerAddr); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(config.endpointUrl, txBody, keystoreAccount.private_key); + const txInfo = await signAndSendTx(endpointUrl, txBody, keystoreAccount.private_key, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); process.exit(0); } - await confirmTransaction(config.endpointUrl, timestamp, txInfo.txHash); + await confirmTransaction(endpointUrl, timestamp, txInfo.txHash); } async function processArguments() { - if (process.argv.length !== 5) { + if (process.argv.length !== 6) { usage(); } - config = require(path.resolve(__dirname, process.argv[2])); - const developerAddr = process.argv[3]; + const endpointUrl = process.argv[2]; + const chainId = Number(process.argv[3]); + const developerAddr = process.argv[4]; if (!CommonUtil.isCksumAddr(developerAddr)) { console.log(`The developer address is NOT a checksum address: ${developerAddr}`); process.exit(0); } - const keystoreAccount = await keystoreToAccount(process.argv[4]); + const keystoreAccount = await keystoreToAccount(process.argv[5]); console.log(`\nKeystore account address: ${keystoreAccount.address}\n`); - await sendTransaction(developerAddr, keystoreAccount); + await sendTransaction(endpointUrl, chainId, developerAddr, keystoreAccount); } function usage() { - console.log('\nUsage: node sendRemoveFromDevelopersUserWhitelistTx.js \n'); - console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js config_local.js 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json\n'); + console.log('\nUsage: node sendRemoveFromDevelopersUserWhitelistTx.js \n'); + console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json'); + console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js https://staging-api.ainetwork.ai 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json'); + console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js https://mainnet-api.ainetwork.ai 1 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json\n'); process.exit(0) } From e24e6fafe0de6cadf6bdbb9caefbf4347c2caac3 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Tue, 2 May 2023 21:19:52 +0900 Subject: [PATCH 23/41] Add chain id option to chatbot tools --- tools/chatbot/config_gcp.js | 1 + tools/chatbot/config_local.js | 1 + tools/chatbot/sendCreateAppAndConfigTx.js | 2 +- tools/chatbot/sendMessageTx.js | 2 +- tools/simple-chatbot-server/index.js | 3 ++- 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/chatbot/config_gcp.js b/tools/chatbot/config_gcp.js index c81c21314..ebfe6e64b 100644 --- a/tools/chatbot/config_gcp.js +++ b/tools/chatbot/config_gcp.js @@ -1,5 +1,6 @@ module.exports = { endpointUrl: "https://staging-api.ainetwork.ai", + chainId: 0, userAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", serviceOwnerAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", serviceOwnerPrivateKey: "9fad756c0bd0d3a42643973f36e61d4d76e01cbb41371fa3046bcced6926e1b2", diff --git a/tools/chatbot/config_local.js b/tools/chatbot/config_local.js index 4dcee4a95..6821dda37 100644 --- a/tools/chatbot/config_local.js +++ b/tools/chatbot/config_local.js @@ -1,5 +1,6 @@ module.exports = { endpointUrl: "http://localhost:8081", + chainId: 0, userAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", serviceOwnerAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", serviceOwnerPrivateKey: "9fad756c0bd0d3a42643973f36e61d4d76e01cbb41371fa3046bcced6926e1b2", diff --git a/tools/chatbot/sendCreateAppAndConfigTx.js b/tools/chatbot/sendCreateAppAndConfigTx.js index 54e632cfd..20c297003 100644 --- a/tools/chatbot/sendCreateAppAndConfigTx.js +++ b/tools/chatbot/sendCreateAppAndConfigTx.js @@ -78,7 +78,7 @@ async function sendTransaction() { const createAppTxBody = buildCreateAppTxBody(config.serviceOwnerAddr, timestamp); console.log(`createAppTxBody: ${JSON.stringify(createAppTxBody, null, 2)}`); - const createAppTxInfo = await signAndSendTx(config.endpointUrl, createAppTxBody, config.serviceOwnerPrivateKey); + const createAppTxInfo = await signAndSendTx(config.endpointUrl, createAppTxBody, config.serviceOwnerPrivateKey, config.chainId); console.log(`createAppTxInfo: ${JSON.stringify(createAppTxInfo, null, 2)}`); if (!createAppTxInfo.success) { console.log(`Create app transaction failed.`); diff --git a/tools/chatbot/sendMessageTx.js b/tools/chatbot/sendMessageTx.js index db33dce40..a5059e5d1 100644 --- a/tools/chatbot/sendMessageTx.js +++ b/tools/chatbot/sendMessageTx.js @@ -24,7 +24,7 @@ async function sendTransaction(message) { const txBody = buildMessageTxBody(timestamp, message); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey); + const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey, config.chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); diff --git a/tools/simple-chatbot-server/index.js b/tools/simple-chatbot-server/index.js index 41aac7d51..c18749277 100644 --- a/tools/simple-chatbot-server/index.js +++ b/tools/simple-chatbot-server/index.js @@ -7,7 +7,8 @@ const CommonUtil = require('../../common/common-util'); const app = express(); const PORT = 3000; const BLOCKCHAIN_ENDPOINT = 'http://localhost:8081/'; -const ain = new AinJs(BLOCKCHAIN_ENDPOINT, 0); +const CHAIN_ID = 0; +const ain = new AinJs(BLOCKCHAIN_ENDPOINT, CHAIN_ID); const APP_NAME = 'chatbots'; const BOT_NAME = 'echo-bot'; const BOT_PK = 'ee0b1315d446e5318eb6eb4e9d071cd12ef42d2956d546f9acbdc3b75c469640'; From c5db918321b7e523976cd34bd9c75a1ceba9a598 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Wed, 3 May 2023 11:24:27 +0900 Subject: [PATCH 24/41] Add chain id option to transfer tool script --- tools/transfer/sendTransferTx.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tools/transfer/sendTransferTx.js b/tools/transfer/sendTransferTx.js index 7ba8e42ca..2f378840f 100644 --- a/tools/transfer/sendTransferTx.js +++ b/tools/transfer/sendTransferTx.js @@ -15,7 +15,7 @@ function buildTransferTxBody(fromAddr, toAddr, key, amount, timestamp) { } } -async function sendTransaction(endpointUrl) { +async function sendTransaction(endpointUrl, chainId) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); if (!endpointUrl) { @@ -26,7 +26,7 @@ async function sendTransaction(endpointUrl) { buildTransferTxBody(config.fromAddr, config.toAddr, timestamp, config.amount, timestamp); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(endpointUrl, txBody, config.fromPrivateKey); + const txInfo = await signAndSendTx(endpointUrl, txBody, config.fromPrivateKey, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transfer transaction failed.`); @@ -37,18 +37,20 @@ async function sendTransaction(endpointUrl) { async function processArguments() { const len = process.argv.length; - if (len !== 3 && len !== 4) { + if (len !== 4 && len !== 5) { usage(); } - const endpointUrl = len === 4 ? process.argv[3] : null; config = require(path.resolve(__dirname, process.argv[2])); - await sendTransaction(endpointUrl); + const chainId = Number(process.argv[3]); + const endpointUrl = len === 5 ? process.argv[4] : null; + await sendTransaction(endpointUrl, chainId); } function usage() { - console.log('\nUsage: node sendTransferTx.js []\n'); - console.log('Example: node sendTransferTx.js config_local.js '); - console.log('Example: node sendTransferTx.js config_local.js http://111.222.333.44:1234\n'); + console.log('\nUsage: node sendTransferTx.js []\n'); + console.log('Example: node sendTransferTx.js config_local.js 0'); + console.log('Example: node sendTransferTx.js config_local.js 0 http://111.222.333.44:1234'); + console.log('Example: node sendTransferTx.js config_local.js 1 https://mainnet-api.ainetwork.ai\n'); process.exit(0) } From 66592b6c0ac7d3f310b099a68967a126bd61e54c Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 4 May 2023 18:57:55 +0900 Subject: [PATCH 25/41] Tweak api-access tool options --- .../addToDevClientApiIpWhitelist.js | 37 +++++----- tools/api-access/addToWhitelistNodeParam.js | 46 ++++++------- .../api-access/getDevClientApiIpWhitelist.js | 26 ++++--- tools/api-access/getNodeParam.js | 36 +++++----- .../removeFromDevClientApiIpWhitelist.js | 37 +++++----- .../removeFromWhitelistNodeParam.js | 46 ++++++------- tools/api-access/setNodeParam.js | 42 +++++------ tools/api-access/util.js | 69 ------------------- tools/util.js | 64 +++++++++++++++++ 9 files changed, 194 insertions(+), 209 deletions(-) delete mode 100644 tools/api-access/util.js diff --git a/tools/api-access/addToDevClientApiIpWhitelist.js b/tools/api-access/addToDevClientApiIpWhitelist.js index dd4263713..2e8b4e08c 100644 --- a/tools/api-access/addToDevClientApiIpWhitelist.js +++ b/tools/api-access/addToDevClientApiIpWhitelist.js @@ -3,7 +3,7 @@ const _ = require('lodash'); const ainUtil = require('@ainblockchain/ain-util'); const stringify = require('fast-json-stable-stringify'); const { BlockchainConsts } = require('../../common/constants'); -const { getAccountPrivateKey } = require('./util'); +const { getAccountPrivateKey } = require('../util'); const { JSON_RPC_METHODS } = require('../../json_rpc/constants'); async function sendAddToDevClientApiIpWhitelistRequest(endpointUrl, privateKey, chainId, ip) { @@ -32,8 +32,8 @@ async function sendAddToDevClientApiIpWhitelistRequest(endpointUrl, privateKey, }); } -async function addToDevClientApiIpWhitelist(endpointUrl, chainId, type, keystoreFilePath, ip) { - const privateKey = await getAccountPrivateKey(type, keystoreFilePath); +async function addToDevClientApiIpWhitelist(endpointUrl, chainId, ip, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); const res = await sendAddToDevClientApiIpWhitelistRequest(endpointUrl, privateKey, chainId, ip); console.log('Result:', res); } @@ -44,28 +44,25 @@ async function processArguments() { } const endpointUrl = process.argv[2]; const chainId = Number(process.argv[3]); - const accountType = process.argv[4]; - let keystoreFilePath = null; - let ip = null; - if (accountType === 'keystore') { - keystoreFilePath = process.argv[5]; - ip = process.argv[6]; - } else { - ip = process.argv[5]; - } - if (!ip) { - console.error('Please specify an IP'); + const ip = process.argv[4]; + const accountType = process.argv[5]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[6] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); usage(); } - await addToDevClientApiIpWhitelist(endpointUrl, chainId, accountType, keystoreFilePath, ip); + await addToDevClientApiIpWhitelist(endpointUrl, chainId, ip, accountType, keystoreFilepath); } function usage() { - console.log('\nUsage:\n node addToDevClientApiIpWhitelist.js [] \n'); - console.log('\nExamples:'); - console.log('node tools/api-access/addToDevClientApiIpWhitelist.js http://localhost:8081 0 private_key 127.0.0.1'); - console.log('node tools/api-access/addToDevClientApiIpWhitelist.js http://localhost:8081 0 mnemonic 127.0.0.1'); - console.log('node tools/api-access/addToDevClientApiIpWhitelist.js http://localhost:8081 0 keystore /path/to/keystore/file "*"'); + console.log('\nUsage: node addToDevClientApiIpWhitelist.js []\n'); + console.log('Example: node tools/api-access/addToDevClientApiIpWhitelist.js http://localhost:8081 0 127.0.0.1 private_key'); + console.log('Example: node tools/api-access/addToDevClientApiIpWhitelist.js http://localhost:8081 0 127.0.0.1 mnemonic'); + console.log('Example: node tools/api-access/addToDevClientApiIpWhitelist.js http://localhost:8081 0 127.0.0.1 keystore keystore_blockchain_node.json'); + console.log("Example: node tools/api-access/addToDevClientApiIpWhitelist.js http://localhost:8081 0 '*' keystore keystore_blockchain_node.json"); + console.log('Example: node tools/api-access/addToDevClientApiIpWhitelist.js https://staging-api.ainetwork.ai 0 127.0.0.1 keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/addToDevClientApiIpWhitelist.js https://testnet-api.ainetwork.ai 0 127.0.0.1 keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/addToDevClientApiIpWhitelist.js https://mainnet-api.ainetwork.ai 1 127.0.0.1 keystore keystore_blockchain_node.json\n'); process.exit(0); } diff --git a/tools/api-access/addToWhitelistNodeParam.js b/tools/api-access/addToWhitelistNodeParam.js index 569e2f42a..e81ae75e9 100644 --- a/tools/api-access/addToWhitelistNodeParam.js +++ b/tools/api-access/addToWhitelistNodeParam.js @@ -3,10 +3,10 @@ const _ = require('lodash'); const ainUtil = require('@ainblockchain/ain-util'); const stringify = require('fast-json-stable-stringify'); const { BlockchainConsts } = require('../../common/constants'); -const { getAccountPrivateKey } = require('./util'); +const { getAccountPrivateKey } = require('../util'); const { JSON_RPC_METHODS } = require('../../json_rpc/constants'); -async function sendAddToWhiteListNodeParamRequest(endpointUrl, privateKey, chainId, param, value) { +async function sendAddToWhitelistNodeParamRequest(endpointUrl, privateKey, chainId, param, value) { const message = { timestamp: Date.now(), method: JSON_RPC_METHODS.AIN_ADD_TO_WHITELIST_NODE_PARAM, @@ -32,9 +32,9 @@ async function sendAddToWhiteListNodeParamRequest(endpointUrl, privateKey, chain }); } -async function addToWhiteListNodeParam(endpointUrl, chainId, type, keystoreFilePath, param, value) { - const privateKey = await getAccountPrivateKey(type, keystoreFilePath); - const res = await sendAddToWhiteListNodeParamRequest(endpointUrl, privateKey, chainId, param, value); +async function addToWhitelistNodeParam(endpointUrl, chainId, param, value, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); + const res = await sendAddToWhitelistNodeParamRequest(endpointUrl, privateKey, chainId, param, value); console.log('Result:', res); } @@ -44,31 +44,27 @@ async function processArguments() { } const endpointUrl = process.argv[2]; const chainId = Number(process.argv[3]); - const accountType = process.argv[4]; - let keystoreFilePath = null; - let param = null; - let value = null; - if (accountType === 'keystore') { - keystoreFilePath = process.argv[5]; - param = process.argv[6]; - value = process.argv[7]; - } else { - param = process.argv[5]; - value = process.argv[6]; - } - if (!value) { - console.error('Please specify a value'); + const param = process.argv[4]; + const value = process.argv[5]; + const accountType = process.argv[6]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[7] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); usage(); } - await addToWhiteListNodeParam(endpointUrl, chainId, accountType, keystoreFilePath, param, value); + await addToWhitelistNodeParam(endpointUrl, chainId, param, value, accountType, keystoreFilepath); } function usage() { - console.log('\nUsage:\n node addToWhiteListNodeParam.js [] \n'); - console.log('\nExamples:'); - console.log('node tools/api-access/addToWhiteListNodeParam.js http://localhost:8081 0 private_key DEV_CLIENT_API_IP_WHITELIST 127.0.0.1'); - console.log('node tools/api-access/addToWhiteListNodeParam.js http://localhost:8081 0 mnemonic DEV_CLIENT_API_IP_WHITELIST "*"'); - console.log('node tools/api-access/addToWhiteListNodeParam.js http://localhost:8081 0 keystore /path/to/kezystore/file CORS_WHITELIST "https://ainetwork\\.ai"'); + console.log('\nUsage: node addToWhitelistNodeParam.js []\n'); + console.log('Example: node tools/api-access/addToWhitelistNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 private_key'); + console.log('Example: node tools/api-access/addToWhitelistNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 mnemonic'); + console.log('Example: node tools/api-access/addToWhitelistNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 keystore keystore keystore_blockchain_node.json'); + console.log("Example: node tools/api-access/addToWhitelistNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST '*' keystore keystore keystore_blockchain_node.json"); + console.log('Example: node tools/api-access/addToWhitelistNodeParam.js http://localhost:8081 0 CORS_WHITELIST https://ainetwork.ai keystore keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/addToWhitelistNodeParam.js https://staging-api.ainetwork.ai 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 keystore keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/addToWhitelistNodeParam.js https://testnet-api.ainetwork.ai 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 keystore keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/addToWhitelistNodeParam.js https://mainnet-api.ainetwork.ai 1 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 keystore keystore keystore_blockchain_node.json\n'); process.exit(0); } diff --git a/tools/api-access/getDevClientApiIpWhitelist.js b/tools/api-access/getDevClientApiIpWhitelist.js index b8150b039..ec4da4dd6 100644 --- a/tools/api-access/getDevClientApiIpWhitelist.js +++ b/tools/api-access/getDevClientApiIpWhitelist.js @@ -3,7 +3,7 @@ const _ = require('lodash'); const ainUtil = require('@ainblockchain/ain-util'); const stringify = require('fast-json-stable-stringify'); const { BlockchainConsts } = require('../../common/constants'); -const { getAccountPrivateKey } = require('./util'); +const { getAccountPrivateKey } = require('../util'); const { JSON_RPC_METHODS } = require('../../json_rpc/constants'); async function sendGetDevClientApiIpWhitelistRequest(endpointUrl, privateKey, chainId) { @@ -31,8 +31,8 @@ async function sendGetDevClientApiIpWhitelistRequest(endpointUrl, privateKey, ch }); } -async function getDevClientApiIpWhitelist(endpointUrl, chainId, type, keystoreFilePath) { - const privateKey = await getAccountPrivateKey(type, keystoreFilePath); +async function getDevClientApiIpWhitelist(endpointUrl, chainId, type, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(type, keystoreFilepath); const res = await sendGetDevClientApiIpWhitelistRequest(endpointUrl, privateKey, chainId); console.log('Result:', res); } @@ -44,16 +44,22 @@ async function processArguments() { const endpointUrl = process.argv[2]; const chainId = Number(process.argv[3]); const accountType = process.argv[4]; - const keystoreFilePath = process.argv[5]; - await getDevClientApiIpWhitelist(endpointUrl, chainId, accountType, keystoreFilePath); + const keystoreFilepath = (accountType === 'keystore') ? process.argv[5] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); + usage(); + } + await getDevClientApiIpWhitelist(endpointUrl, chainId, accountType, keystoreFilepath); } function usage() { - console.log('\nUsage:\n node getDevClientApiIpWhitelist.js []\n'); - console.log('\nExamples:'); - console.log('node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 private_key'); - console.log('node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 mnemonic'); - console.log('node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 keystore /path/to/keystore/file'); + console.log('\nUsage: node getDevClientApiIpWhitelist.js []\n'); + console.log('Example: node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 private_key'); + console.log('Example: node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 mnemonic'); + console.log('Example: node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/getDevClientApiIpWhitelist.js https://staging-api.ainetwork.ai 0 keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/getDevClientApiIpWhitelist.js https://testnet-api.ainetwork.ai 0 keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/getDevClientApiIpWhitelist.js https://mainnet-api.ainetwork.ai 1 keystore keystore_blockchain_node.json\n'); process.exit(0); } diff --git a/tools/api-access/getNodeParam.js b/tools/api-access/getNodeParam.js index 63d9fd495..ab292a971 100644 --- a/tools/api-access/getNodeParam.js +++ b/tools/api-access/getNodeParam.js @@ -3,7 +3,7 @@ const _ = require('lodash'); const ainUtil = require('@ainblockchain/ain-util'); const stringify = require('fast-json-stable-stringify'); const { BlockchainConsts } = require('../../common/constants'); -const { getAccountPrivateKey } = require('./util'); +const { getAccountPrivateKey } = require('../util'); const { JSON_RPC_METHODS } = require('../../json_rpc/constants'); async function sendGetNodeParamRequest(endpointUrl, privateKey, chainId, param) { @@ -31,8 +31,8 @@ async function sendGetNodeParamRequest(endpointUrl, privateKey, chainId, param) }); } -async function getNodeParam(endpointUrl, chainId, type, keystoreFilePath, param) { - const privateKey = await getAccountPrivateKey(type, keystoreFilePath); +async function getNodeParam(endpointUrl, chainId, param, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); const res = await sendGetNodeParamRequest(endpointUrl, privateKey, chainId, param); console.log('Result:', res); } @@ -43,24 +43,26 @@ async function processArguments() { } const endpointUrl = process.argv[2]; const chainId = Number(process.argv[3]); - const accountType = process.argv[4]; - let keystoreFilePath = null; - let param = null; - if (accountType === 'keystore') { - keystoreFilePath = process.argv[5]; - param = process.argv[6]; - } else { - param = process.argv[5]; + const param = process.argv[4]; + const accountType = process.argv[5]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[6] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); + usage(); } - await getNodeParam(endpointUrl, chainId, accountType, keystoreFilePath, param); + await getNodeParam(endpointUrl, chainId, param, accountType, keystoreFilepath); } function usage() { - console.log('\nUsage:\n node getNodeParam.js [] \n'); - console.log('\nExamples:'); - console.log('node tools/api-access/getNodeParam.js http://localhost:8081 0 private_key DEV_CLIENT_API_IP_WHITELIST'); - console.log('node tools/api-access/getNodeParam.js http://localhost:8081 0 mnemonic P2P_MESSAGE_TIMEOUT_MS'); - console.log('node tools/api-access/getNodeParam.js http://localhost:8081 0 keystore /path/to/keystore/file SYNC_MODE'); + console.log('\nUsage: node getNodeParam.js []\n'); + console.log('Example: node tools/api-access/getNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST private_key'); + console.log('Example: node tools/api-access/getNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST mnemonic'); + console.log('Example: node tools/api-access/getNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/getNodeParam.js http://localhost:8081 0 P2P_MESSAGE_TIMEOUT_MS keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/getNodeParam.js http://localhost:8081 0 SYNC_MODE keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/getNodeParam.js https://staging-api.ainetwork.ai 0 DEV_CLIENT_API_IP_WHITELIST keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/getNodeParam.js https://testnet-api.ainetwork.ai 0 DEV_CLIENT_API_IP_WHITELIST keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/getNodeParam.js https://mainnet-api.ainetwork.ai 1 DEV_CLIENT_API_IP_WHITELIST keystore keystore_blockchain_node.json\n'); process.exit(0); } diff --git a/tools/api-access/removeFromDevClientApiIpWhitelist.js b/tools/api-access/removeFromDevClientApiIpWhitelist.js index fe5ace2e7..d065de40c 100644 --- a/tools/api-access/removeFromDevClientApiIpWhitelist.js +++ b/tools/api-access/removeFromDevClientApiIpWhitelist.js @@ -3,7 +3,7 @@ const _ = require('lodash'); const ainUtil = require('@ainblockchain/ain-util'); const stringify = require('fast-json-stable-stringify'); const { BlockchainConsts } = require('../../common/constants'); -const { getAccountPrivateKey } = require('./util'); +const { getAccountPrivateKey } = require('../util'); const { JSON_RPC_METHODS } = require('../../json_rpc/constants'); async function sendRemoveFromToDevClientApiIpWhitelistRequest(endpointUrl, privateKey, chainId, ip) { @@ -32,8 +32,8 @@ async function sendRemoveFromToDevClientApiIpWhitelistRequest(endpointUrl, priva }); } -async function removeFromDevClientApiIpWhitelist(endpointUrl, chainId, type, keystoreFilePath, ip) { - const privateKey = await getAccountPrivateKey(type, keystoreFilePath); +async function removeFromDevClientApiIpWhitelist(endpointUrl, chainId, ip, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); const res = await sendRemoveFromToDevClientApiIpWhitelistRequest(endpointUrl, privateKey, chainId, ip); console.log('Result:', res); } @@ -44,28 +44,25 @@ async function processArguments() { } const endpointUrl = process.argv[2]; const chainId = Number(process.argv[3]); - const accountType = process.argv[4]; - let keystoreFilePath = null; - let ip = null; - if (accountType === 'keystore') { - keystoreFilePath = process.argv[5]; - ip = process.argv[6]; - } else { - ip = process.argv[5]; - } - if (!ip) { - console.error('Please specify an IP'); + const ip = process.argv[4]; + const accountType = process.argv[5]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[6] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); usage(); } - await removeFromDevClientApiIpWhitelist(endpointUrl, chainId, accountType, keystoreFilePath, ip); + await removeFromDevClientApiIpWhitelist(endpointUrl, chainId, ip, accountType, keystoreFilepath); } function usage() { - console.log('\nUsage:\n node removeFromDevClientApiIpWhitelist.js [] \n'); - console.log('\nExamples:'); - console.log('node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 private_key 127.0.0.1'); - console.log('node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 mnemonic 127.0.0.1'); - console.log('node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 keystore /path/to/keystore/file "*"'); + console.log('\nUsage: node removeFromDevClientApiIpWhitelist.js []\n'); + console.log('Example: node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 127.0.0.1 private_key'); + console.log('Example: node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 127.0.0.1 mnemonic'); + console.log('Example: node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 127.0.0.1 keystore keystore_blockchain_node.json'); + console.log("Example: node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 '*' keystore keystore_blockchain_node.json"); + console.log('Example: node tools/api-access/removeFromDevClientApiIpWhitelist.js https://staging-api.ainetwork.ai 0 127.0.0.1 keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/removeFromDevClientApiIpWhitelist.js https://testnet-api.ainetwork.ai 0 127.0.0.1 keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/removeFromDevClientApiIpWhitelist.js https://mainnet-api.ainetwork.ai 1 127.0.0.1 keystore keystore_blockchain_node.json\n'); process.exit(0); } diff --git a/tools/api-access/removeFromWhitelistNodeParam.js b/tools/api-access/removeFromWhitelistNodeParam.js index cbf077e5c..2ae5e55e7 100644 --- a/tools/api-access/removeFromWhitelistNodeParam.js +++ b/tools/api-access/removeFromWhitelistNodeParam.js @@ -3,10 +3,10 @@ const _ = require('lodash'); const ainUtil = require('@ainblockchain/ain-util'); const stringify = require('fast-json-stable-stringify'); const { BlockchainConsts } = require('../../common/constants'); -const { getAccountPrivateKey } = require('./util'); +const { getAccountPrivateKey } = require('../util'); const { JSON_RPC_METHODS } = require('../../json_rpc/constants'); -async function sendRemoveFromWhiteListNodeParamRequest(endpointUrl, privateKey, chainId, param, value) { +async function sendRemoveFromWhitelistNodeParamRequest(endpointUrl, privateKey, chainId, param, value) { const message = { timestamp: Date.now(), method: JSON_RPC_METHODS.AIN_REMOVE_FROM_WHITELIST_NODE_PARAM, @@ -32,9 +32,9 @@ async function sendRemoveFromWhiteListNodeParamRequest(endpointUrl, privateKey, }); } -async function removeFromWhiteListNodeParam(endpointUrl, chainId, type, keystoreFilePath, param, value) { - const privateKey = await getAccountPrivateKey(type, keystoreFilePath); - const res = await sendRemoveFromWhiteListNodeParamRequest(endpointUrl, privateKey, chainId, param, value); +async function removeFromWhitelistNodeParam(endpointUrl, chainId, param, value, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); + const res = await sendRemoveFromWhitelistNodeParamRequest(endpointUrl, privateKey, chainId, param, value); console.log('Result:', res); } @@ -44,31 +44,27 @@ async function processArguments() { } const endpointUrl = process.argv[2]; const chainId = Number(process.argv[3]); - const accountType = process.argv[4]; - let keystoreFilePath = null; - let param = null; - let value = null; - if (accountType === 'keystore') { - keystoreFilePath = process.argv[5]; - param = process.argv[6]; - value = process.argv[7]; - } else { - param = process.argv[5]; - value = process.argv[6]; - } - if (!value) { - console.error('Please specify a value'); + const param = process.argv[4]; + const value = process.argv[5]; + const accountType = process.argv[6]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[7] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); usage(); } - await removeFromWhiteListNodeParam(endpointUrl, chainId, accountType, keystoreFilePath, param, value); + await removeFromWhitelistNodeParam(endpointUrl, chainId, param, value, accountType, keystoreFilepath); } function usage() { - console.log('\nUsage:\n node removeFromWhiteListNodeParam.js [] \n'); - console.log('\nExamples:'); - console.log('node tools/api-access/removeFromWhiteListNodeParam.js http://localhost:8081 0 private_key DEV_CLIENT_API_IP_WHITELIST 127.0.0.1'); - console.log('node tools/api-access/removeFromWhiteListNodeParam.js http://localhost:8081 0 mnemonic DEV_CLIENT_API_IP_WHITELIST "*"'); - console.log('node tools/api-access/removeFromWhiteListNodeParam.js http://localhost:8081 0 keystore /path/to/kezystore/file CORS_WHITELIST "https://ainetwork\\.ai"'); + console.log('\nUsage: node removeFromWhitelistNodeParam.js []\n'); + console.log('Example: node tools/api-access/removeFromWhitelistNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 private_key'); + console.log('Example: node tools/api-access/removeFromWhitelistNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 mnemonic'); + console.log('Example: node tools/api-access/removeFromWhitelistNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 keystore keystore_blockchain_node.json'); + console.log("Example: node tools/api-access/removeFromWhitelistNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST '*' keystore keystore_blockchain_node.json"); + console.log('Example: node tools/api-access/removeFromWhitelistNodeParam.js http://localhost:8081 0 CORS_WHITELIST https://ainetwork.ai keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/removeFromWhitelistNodeParam.js https://staging-api.ainetwork.ai 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/removeFromWhitelistNodeParam.js https://testnet-api.ainetwork.ai 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/removeFromWhitelistNodeParam.js https://mainnet-api.ainetwork.ai 1 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 keystore keystore_blockchain_node.json\n'); process.exit(0); } diff --git a/tools/api-access/setNodeParam.js b/tools/api-access/setNodeParam.js index 847476c9d..d4775e021 100644 --- a/tools/api-access/setNodeParam.js +++ b/tools/api-access/setNodeParam.js @@ -3,7 +3,7 @@ const _ = require('lodash'); const ainUtil = require('@ainblockchain/ain-util'); const stringify = require('fast-json-stable-stringify'); const { BlockchainConsts } = require('../../common/constants'); -const { getAccountPrivateKey } = require('./util'); +const { getAccountPrivateKey } = require('../util'); const { JSON_RPC_METHODS } = require('../../json_rpc/constants'); async function sendSetNodeParamRequest(endpointUrl, privateKey, chainId, param, value) { @@ -32,8 +32,8 @@ async function sendSetNodeParamRequest(endpointUrl, privateKey, chainId, param, }); } -async function setNodeParam(endpointUrl, chainId, type, keystoreFilePath, param, value) { - const privateKey = await getAccountPrivateKey(type, keystoreFilePath); +async function setNodeParam(endpointUrl, chainId, param, value, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); const res = await sendSetNodeParamRequest(endpointUrl, privateKey, chainId, param, value); console.log('Result:', res); } @@ -44,31 +44,27 @@ async function processArguments() { } const endpointUrl = process.argv[2]; const chainId = Number(process.argv[3]); - const accountType = process.argv[4]; - let keystoreFilePath = null; - let param = null; - let value = null; - if (accountType === 'keystore') { - keystoreFilePath = process.argv[5]; - param = process.argv[6]; - value = process.argv[7]; - } else { - param = process.argv[5]; - value = process.argv[6]; - } - if (!value) { - console.error('Please specify a value'); + const param = process.argv[4]; + const value = process.argv[5]; + const accountType = process.argv[6]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[7] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); usage(); } - await setNodeParam(endpointUrl, chainId, accountType, keystoreFilePath, param, value); + await setNodeParam(endpointUrl, chainId, param, value, accountType, keystoreFilepath); } function usage() { - console.log('\nUsage:\n node setNodeParam.js [] \n'); - console.log('\nExamples:'); - console.log('node tools/api-access/setNodeParam.js http://localhost:8081 0 private_key DEV_CLIENT_API_IP_WHITELIST "*"'); - console.log('node tools/api-access/setNodeParam.js http://localhost:8081 0 mnemonic P2P_MESSAGE_TIMEOUT_MS 200000'); - console.log('node tools/api-access/setNodeParam.js http://localhost:8081 0 keystore /path/to/kezystore/file SYNC_MODE peer'); + console.log('\nUsage: node setNodeParam.js []\n'); + console.log('Example: node tools/api-access/setNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 private_key'); + console.log('Example: node tools/api-access/setNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 mnemonic'); + console.log('Example: node tools/api-access/setNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 keystore keystore_blockchain_node.json'); + console.log("Example: node tools/api-access/setNodeParam.js http://localhost:8081 0 DEV_CLIENT_API_IP_WHITELIST '*' keystore keystore_blockchain_node.json"); + console.log("Example: node tools/api-access/setNodeParam.js http://localhost:8081 0 P2P_MESSAGE_TIMEOUT_MS 200000 keystore keystore_blockchain_node.json"); + console.log('Example: node tools/api-access/setNodeParam.js https://staging-api.ainetwork.ai 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/setNodeParam.js https://testnet-api.ainetwork.ai 0 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 keystore keystore_blockchain_node.json'); + console.log('Example: node tools/api-access/setNodeParam.js https://mainnet-api.ainetwork.ai 1 DEV_CLIENT_API_IP_WHITELIST 127.0.0.1 keystore keystore_blockchain_node.json\n'); process.exit(0); } diff --git a/tools/api-access/util.js b/tools/api-access/util.js deleted file mode 100644 index d6c5b32f2..000000000 --- a/tools/api-access/util.js +++ /dev/null @@ -1,69 +0,0 @@ -const fs = require('fs'); -const readline = require('readline'); -const ainUtil = require('@ainblockchain/ain-util'); -const FileUtil = require('../../common/file-util'); - -async function getAccountPrivateKey(type, keystoreFilePath) { - let privateKey = ''; - let hide = false; - let secret = true; - const readlineInterface = readline.createInterface({ - input: process.stdin, - output: process.stdout - }); - // NOTE(liayoo): Show the prompt & hide the password - readlineInterface._writeToOutput = (val) => { - if (!hide && secret) { - readlineInterface.output.write(val); - hide = true; - } else if (!hide && !secret) { - readlineInterface.output.write(val); - } - }; - switch (type) { - case 'private_key': - privateKey = await new Promise((resolve) => { - readlineInterface.question(`Enter private key: `, (privateKey) => { - readlineInterface.output.write('\n\r'); - readlineInterface.close(); - resolve(privateKey); - }); - }); - break; - case 'keystore': - if (!keystoreFilePath || !fs.existsSync(keystoreFilePath)) { - throw Error(`Invalid keystore file path: ${keystoreFilePath}`); - } - const password = await new Promise((resolve) => { - readlineInterface.question(`Enter keystore file password: `, (password) => { - readlineInterface.output.write('\n\r'); - readlineInterface.close(); - resolve(password); - }); - }); - const accountFromKeystore = FileUtil.getAccountFromKeystoreFile(keystoreFilePath, password); - privateKey = accountFromKeystore.private_key; - break; - case 'mnemonic': - const [mnemonic, mnemonicAccountIndex] = await new Promise((resolve) => { - readlineInterface.question(`Enter mnemonic: `, (mnemonic) => { - readlineInterface.output.write('\n\r'); - hide = false; - secret = false; - readlineInterface.question(`Enter account index (default: 0): `, (index) => { - readlineInterface.output.write('\n\r'); - readlineInterface.close(); - resolve([mnemonic, index]); - }); - }); - }); - const accountFromHDWallet = ainUtil.mnemonicToAccount(mnemonic, mnemonicAccountIndex || 0); - privateKey = accountFromHDWallet.private_key; - break; - } - return privateKey; -} - -module.exports = { - getAccountPrivateKey, -}; diff --git a/tools/util.js b/tools/util.js index ba17bb77f..975c11f27 100644 --- a/tools/util.js +++ b/tools/util.js @@ -1,12 +1,75 @@ const _ = require('lodash'); const fs = require('fs'); +const readline = require('readline'); const prompt = require('prompt'); const axios = require('axios'); const ainUtil = require('@ainblockchain/ain-util'); +const FileUtil = require('../common/file-util'); const { BlockchainConsts } = require('../common/constants'); const CommonUtil = require('../common/common-util'); const { JSON_RPC_METHODS } = require('../json_rpc/constants'); +async function getAccountPrivateKey(type, keystoreFilePath) { + let privateKey = ''; + let hide = false; + let secret = true; + const readlineInterface = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + // NOTE(liayoo): Show the prompt & hide the password + readlineInterface._writeToOutput = (val) => { + if (!hide && secret) { + readlineInterface.output.write(val); + hide = true; + } else if (!hide && !secret) { + readlineInterface.output.write(val); + } + }; + switch (type) { + case 'private_key': + privateKey = await new Promise((resolve) => { + readlineInterface.question(`Enter private key: `, (privateKey) => { + readlineInterface.output.write('\n\r'); + readlineInterface.close(); + resolve(privateKey); + }); + }); + break; + case 'keystore': + if (!keystoreFilePath || !fs.existsSync(keystoreFilePath)) { + throw Error(`Invalid keystore file path: ${keystoreFilePath}`); + } + const password = await new Promise((resolve) => { + readlineInterface.question(`Enter keystore file password: `, (password) => { + readlineInterface.output.write('\n\r'); + readlineInterface.close(); + resolve(password); + }); + }); + const accountFromKeystore = FileUtil.getAccountFromKeystoreFile(keystoreFilePath, password); + privateKey = accountFromKeystore.private_key; + break; + case 'mnemonic': + const [mnemonic, mnemonicAccountIndex] = await new Promise((resolve) => { + readlineInterface.question(`Enter mnemonic: `, (mnemonic) => { + readlineInterface.output.write('\n\r'); + hide = false; + secret = false; + readlineInterface.question(`Enter account index (default: 0): `, (index) => { + readlineInterface.output.write('\n\r'); + readlineInterface.close(); + resolve([mnemonic, index]); + }); + }); + }); + const accountFromHDWallet = ainUtil.mnemonicToAccount(mnemonic, mnemonicAccountIndex || 0); + privateKey = accountFromHDWallet.private_key; + break; + } + return privateKey; +} + async function keystoreToAccount(filePath) { const keystore = JSON.parse(fs.readFileSync(filePath)); console.log(`\nKeystore: ${JSON.stringify(keystore, null, 2)}\n`) @@ -87,6 +150,7 @@ async function confirmTransaction(endpointUrl, timestamp, txHash) { } module.exports = { + getAccountPrivateKey, keystoreToAccount, signAndSendTx, sendGetTxByHashRequest, From 249b03d177d4dc69fd9c3ecfae9707c1fa246420 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 4 May 2023 21:30:59 +0900 Subject: [PATCH 26/41] Add other key options to developers tools --- .../sendAddToDevelopersUrlWhitelistTx.js | 43 ++++++++++++------- .../sendAddToDevelopersUserWhitelistTx.js | 34 ++++++++++----- .../sendRemoveFromDevelopersUrlWhitelistTx.js | 43 ++++++++++++------- ...sendRemoveFromDevelopersUserWhitelistTx.js | 34 ++++++++++----- 4 files changed, 100 insertions(+), 54 deletions(-) diff --git a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js index 4d1ee1475..a50912baa 100644 --- a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js @@ -1,9 +1,10 @@ // A tool to register a URL to the developers URL whitelist (i.e., REST function URL whitelist). // This should be executed with developer's keystore files. // This can be tested with the tool scripts under tools/chatbot. +const ainUtil = require('@ainblockchain/ain-util'); const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); -const { keystoreToAccount, signAndSendTx, confirmTransaction } = require('../util'); +const { getAccountPrivateKey, signAndSendTx, confirmTransaction } = require('../util'); function buildTxBody(timestamp, address, urlKey, urlValue) { const urlPath = CommonUtil.appendPath( @@ -20,18 +21,14 @@ function buildTxBody(timestamp, address, urlKey, urlValue) { }; } -async function sendTransaction(endpointUrl, chainId, urlKey, urlValue, keystoreAccount) { +async function sendTransaction(endpointUrl, chainId, urlKey, urlValue, address, privateKey) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - if (!CommonUtil.isCksumAddr(keystoreAccount.address)) { - console.log(`The developer address is NOT a checksum address: ${keystoreAccount.address}`); - process.exit(0); - } - const txBody = buildTxBody(timestamp, keystoreAccount.address, urlKey, urlValue); + const txBody = buildTxBody(timestamp, address, urlKey, urlValue); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(endpointUrl, txBody, keystoreAccount.private_key, chainId); + const txInfo = await signAndSendTx(endpointUrl, txBody, privateKey, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); @@ -40,8 +37,15 @@ async function sendTransaction(endpointUrl, chainId, urlKey, urlValue, keystoreA await confirmTransaction(endpointUrl, timestamp, txInfo.txHash); } +async function sendAddToDevelopersUrlWhitelistTx(endpointUrl, chainId, urlKey, urlValue, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); + const account = ainUtil.privateToAccount('0x' + privateKey); + console.log(`\nAccount address: ${account.address}\n`); + await sendTransaction(endpointUrl, chainId, urlKey, urlValue, account.address, privateKey); +} + async function processArguments() { - if (process.argv.length !== 7) { + if (process.argv.length !== 7 && process.argv.length !== 8) { usage(); } const endpointUrl = process.argv[2]; @@ -56,16 +60,23 @@ async function processArguments() { console.log(`The URL value is NOT a valid whitelist item: ${urlValue}`); process.exit(0); } - const keystoreAccount = await keystoreToAccount(process.argv[6]); - console.log(`\nKeystore account address: ${keystoreAccount.address}\n`); - await sendTransaction(endpointUrl, chainId, urlKey, urlValue, keystoreAccount); + const accountType = process.argv[6]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[7] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); + usage(); + } + await sendAddToDevelopersUrlWhitelistTx(endpointUrl, chainId, urlKey, urlValue, accountType, keystoreFilepath); } function usage() { - console.log('\nUsage: node sendAddToDevelopersUrlWhitelistTx.js \n'); - console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js http://localhost:8081 0 0 http://localhost:8000 keystore_developer.json'); - console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js https://staging-api.ainetwork.ai 0 0 https://mydomain.com keystore_developer.json'); - console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js https://mainnet-api.ainetwork.ai 1 0 https://mydomain.com keystore_developer.json\n'); + console.log('\nUsage: node sendAddToDevelopersUrlWhitelistTx.js []\n'); + console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js http://localhost:8081 0 0 http://localhost:8000 private_key'); + console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js http://localhost:8081 0 0 http://localhost:8000 mnemonic'); + console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js http://localhost:8081 0 0 http://localhost:8000 keystore keystore_developer.json'); + console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js https://staging-api.ainetwork.ai 0 0 https://mydomain.com keystore keystore_developer.json'); + console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js https://testnet-api.ainetwork.ai 0 0 https://mydomain.com keystore keystore_developer.json'); + console.log('Example: node sendAddToDevelopersUrlWhitelistTx.js https://mainnet-api.ainetwork.ai 1 0 https://mydomain.com keystore keystore_developer.json\n'); process.exit(0) } diff --git a/tools/developers/sendAddToDevelopersUserWhitelistTx.js b/tools/developers/sendAddToDevelopersUserWhitelistTx.js index ff323f4ef..b79fb0c88 100644 --- a/tools/developers/sendAddToDevelopersUserWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUserWhitelistTx.js @@ -3,7 +3,7 @@ // This can be tested with the tool scripts under tools/chatbot. const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); -const { keystoreToAccount, signAndSendTx, confirmTransaction } = require('../util'); +const { getAccountPrivateKey, signAndSendTx, confirmTransaction } = require('../util'); function buildTxBody(timestamp, address) { const userPath = PathUtil.getDevelopersRestFunctionsUserWhitelistUserPath(address); @@ -19,14 +19,14 @@ function buildTxBody(timestamp, address) { }; } -async function sendTransaction(endpointUrl, chainId, developerAddr, keystoreAccount) { +async function sendTransaction(endpointUrl, chainId, developerAddr, privateKey) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); const txBody = buildTxBody(timestamp, developerAddr); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(endpointUrl, txBody, keystoreAccount.private_key, chainId); + const txInfo = await signAndSendTx(endpointUrl, txBody, privateKey, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); @@ -35,8 +35,13 @@ async function sendTransaction(endpointUrl, chainId, developerAddr, keystoreAcco await confirmTransaction(endpointUrl, timestamp, txInfo.txHash); } +async function sendAddToDevelopersUserWhitelistTx(endpointUrl, chainId, developerAddr, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); + await sendTransaction(endpointUrl, chainId, developerAddr, privateKey); +} + async function processArguments() { - if (process.argv.length !== 6) { + if (process.argv.length !== 6 && process.argv.length !== 7) { usage(); } const endpointUrl = process.argv[2]; @@ -46,16 +51,23 @@ async function processArguments() { console.log(`The developer address is NOT a checksum address: ${developerAddr}`); process.exit(0); } - const keystoreAccount = await keystoreToAccount(process.argv[5]); - console.log(`\nKeystore account address: ${keystoreAccount.address}\n`); - await sendTransaction(endpointUrl, chainId, developerAddr, keystoreAccount); + const accountType = process.argv[5]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[6] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); + usage(); + } + await sendAddToDevelopersUserWhitelistTx(endpointUrl, chainId, developerAddr, accountType, keystoreFilepath); } function usage() { - console.log('\nUsage: node sendAddToDevelopersUserWhitelistTx.js \n'); - console.log('Example: node sendAddToDevelopersUserWhitelistTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json'); - console.log('Example: node sendAddToDevelopersUserWhitelistTx.js https://staging-api.ainetwork.ai 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json'); - console.log('Example: node sendAddToDevelopersUserWhitelistTx.js https://mainnet-api.ainetwork.ai 1 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json\n'); + console.log('\nUsage: node sendAddToDevelopersUserWhitelistTx.js []\n'); + console.log('Example: node sendAddToDevelopersUserWhitelistTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b private_key'); + console.log('Example: node sendAddToDevelopersUserWhitelistTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b mnemonic'); + console.log('Example: node sendAddToDevelopersUserWhitelistTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore keystore_blockchain_owner.json'); + console.log('Example: node sendAddToDevelopersUserWhitelistTx.js https://staging-api.ainetwork.ai 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore keystore_blockchain_owner.json'); + console.log('Example: node sendAddToDevelopersUserWhitelistTx.js https://testnet-api.ainetwork.ai 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore keystore_blockchain_owner.json'); + console.log('Example: node sendAddToDevelopersUserWhitelistTx.js https://mainnet-api.ainetwork.ai 1 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore keystore_blockchain_owner.json\n'); process.exit(0) } diff --git a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js index 79b93f8cd..aedae0ea9 100644 --- a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js @@ -1,9 +1,10 @@ // A tool to deregister a URL from the developers URL whitelist (i.e., REST function URL whitelist). // This should be executed with developer's keystore files. // This can be tested with the tool scripts under tools/chatbot. +const ainUtil = require('@ainblockchain/ain-util'); const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); -const { keystoreToAccount, signAndSendTx, confirmTransaction } = require('../util'); +const { getAccountPrivateKey, signAndSendTx, confirmTransaction } = require('../util'); function buildTxBody(timestamp, address, urlKey) { const urlPath = CommonUtil.appendPath( @@ -20,18 +21,14 @@ function buildTxBody(timestamp, address, urlKey) { }; } -async function sendTransaction(endpointUrl, chainId, urlKey, keystoreAccount) { +async function sendTransaction(endpointUrl, chainId, urlKey, address, privateKey) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - if (!CommonUtil.isCksumAddr(keystoreAccount.address)) { - console.log(`The developer address is NOT a checksum address: ${keystoreAccount.address}`); - process.exit(0); - } - const txBody = buildTxBody(timestamp, keystoreAccount.address, urlKey); + const txBody = buildTxBody(timestamp, address, urlKey); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(endpointUrl, txBody, keystoreAccount.private_key, chainId); + const txInfo = await signAndSendTx(endpointUrl, txBody, privateKey, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); @@ -40,8 +37,15 @@ async function sendTransaction(endpointUrl, chainId, urlKey, keystoreAccount) { await confirmTransaction(endpointUrl, timestamp, txInfo.txHash); } +async function sendRemoveFromDevelopersUrlWhitelistTx(endpointUrl, chainId, urlKey, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); + const account = ainUtil.privateToAccount('0x' + privateKey); + console.log(`\nAccount address: ${account.address}\n`); + await sendTransaction(endpointUrl, chainId, urlKey, account.address, privateKey); +} + async function processArguments() { - if (process.argv.length !== 6) { + if (process.argv.length !== 6 && process.argv.length !== 7) { usage(); } const endpointUrl = process.argv[2]; @@ -51,16 +55,23 @@ async function processArguments() { console.log(`The URL key is NOT a valid one: ${urlKey}`); process.exit(0); } - const keystoreAccount = await keystoreToAccount(process.argv[5]); - console.log(`\nKeystore account address: ${keystoreAccount.address}\n`); - await sendTransaction(endpointUrl, chainId, urlKey, keystoreAccount); + const accountType = process.argv[5]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[6] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); + usage(); + } + await sendRemoveFromDevelopersUrlWhitelistTx(endpointUrl, chainId, urlKey, accountType, keystoreFilepath); } function usage() { - console.log('\nUsage: node sendRemoveFromDevelopersUrlWhitelistTx.js \n'); - console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js http://localhost:8081 0 0 keystore_developer.json'); - console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js https://staging-api.ainetwork.ai 0 0 keystore_developer.json'); - console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js https://mainnet-api.ainetwork.ai 1 0 keystore_developer.json\n'); + console.log('\nUsage: node sendRemoveFromDevelopersUrlWhitelistTx.js []\n'); + console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js http://localhost:8081 0 0 private_key'); + console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js http://localhost:8081 0 0 mnemonic'); + console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js http://localhost:8081 0 0 keystore keystore_developer.json'); + console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js https://staging-api.ainetwork.ai 0 0 keystore keystore_developer.json'); + console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js https://testnet-api.ainetwork.ai 0 0 keystore keystore_developer.json'); + console.log('Example: node sendRemoveFromDevelopersUrlWhitelistTx.js https://mainnet-api.ainetwork.ai 1 0 keystore keystore_developer.json\n'); process.exit(0) } diff --git a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js index 1afabd769..639be6223 100644 --- a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js @@ -3,7 +3,7 @@ // This can be tested with the tool scripts under tools/chatbot. const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); -const { keystoreToAccount, signAndSendTx, confirmTransaction } = require('../util'); +const { getAccountPrivateKey, signAndSendTx, confirmTransaction } = require('../util'); function buildTxBody(timestamp, address) { const userPath = PathUtil.getDevelopersRestFunctionsUserWhitelistUserPath(address); @@ -19,14 +19,14 @@ function buildTxBody(timestamp, address) { }; } -async function sendTransaction(endpointUrl, chainId, developerAddr, keystoreAccount) { +async function sendTransaction(endpointUrl, chainId, developerAddr, privateKey) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); const txBody = buildTxBody(timestamp, developerAddr); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(endpointUrl, txBody, keystoreAccount.private_key, chainId); + const txInfo = await signAndSendTx(endpointUrl, txBody, privateKey, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); @@ -35,8 +35,13 @@ async function sendTransaction(endpointUrl, chainId, developerAddr, keystoreAcco await confirmTransaction(endpointUrl, timestamp, txInfo.txHash); } +async function sendRemoveFromDevelopersUserWhitelistTx(endpointUrl, chainId, developerAddr, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); + await sendTransaction(endpointUrl, chainId, developerAddr, privateKey); +} + async function processArguments() { - if (process.argv.length !== 6) { + if (process.argv.length !== 6 && process.argv.length !== 7) { usage(); } const endpointUrl = process.argv[2]; @@ -46,16 +51,23 @@ async function processArguments() { console.log(`The developer address is NOT a checksum address: ${developerAddr}`); process.exit(0); } - const keystoreAccount = await keystoreToAccount(process.argv[5]); - console.log(`\nKeystore account address: ${keystoreAccount.address}\n`); - await sendTransaction(endpointUrl, chainId, developerAddr, keystoreAccount); + const accountType = process.argv[5]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[6] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); + usage(); + } + await sendRemoveFromDevelopersUserWhitelistTx(endpointUrl, chainId, developerAddr, accountType, keystoreFilepath); } function usage() { - console.log('\nUsage: node sendRemoveFromDevelopersUserWhitelistTx.js \n'); - console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json'); - console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js https://staging-api.ainetwork.ai 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json'); - console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js https://mainnet-api.ainetwork.ai 1 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore_blockchain_owner.json\n'); + console.log('\nUsage: node sendRemoveFromDevelopersUserWhitelistTx.js []\n'); + console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b private_key'); + console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b mnemonic'); + console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore keystore_blockchain_owner.json'); + console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js https://staging-api.ainetwork.ai 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore keystore_blockchain_owner.json'); + console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js https://testnet-api.ainetwork.ai 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore keystore_blockchain_owner.json'); + console.log('Example: node sendRemoveFromDevelopersUserWhitelistTx.js https://mainnet-api.ainetwork.ai 1 0x08Aed7AF9354435c38d52143EE50ac839D20696b keystore keystore_blockchain_owner.json\n'); process.exit(0) } From 9640ffa83f882c0702e9da6b263294487318f125 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 4 May 2023 21:49:04 +0900 Subject: [PATCH 27/41] Fix privateKeyToAccount.js account tool --- tools/account/privateKeyToAccount.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/account/privateKeyToAccount.js b/tools/account/privateKeyToAccount.js index 3a02330f9..42f797b82 100644 --- a/tools/account/privateKeyToAccount.js +++ b/tools/account/privateKeyToAccount.js @@ -11,7 +11,7 @@ async function privateKeyToAccount() { description: 'Enter private key:', hidden: true, }]); - const account = ainUtil.privateToAccount('0x' + input.privateKey); + const account = ainUtil.privateToAccount(Buffer.from(input.privateKey, 'hex')); console.log('\nAccount:', account, '\n'); } From 5b1fa66d720dd31864dcf6ce9d01ef99f5307fa9 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 4 May 2023 21:54:01 +0900 Subject: [PATCH 28/41] Fix ainUtil.privateToAccount() usecases --- tools/developers/sendAddToDevelopersUrlWhitelistTx.js | 10 +++++----- tools/developers/sendAddToDevelopersUserWhitelistTx.js | 9 ++++++--- .../sendRemoveFromDevelopersUrlWhitelistTx.js | 10 +++++----- .../sendRemoveFromDevelopersUserWhitelistTx.js | 9 ++++++--- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js index a50912baa..f3694bc09 100644 --- a/tools/developers/sendAddToDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUrlWhitelistTx.js @@ -21,14 +21,14 @@ function buildTxBody(timestamp, address, urlKey, urlValue) { }; } -async function sendTransaction(endpointUrl, chainId, urlKey, urlValue, address, privateKey) { +async function sendTransaction(endpointUrl, chainId, urlKey, urlValue, account) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - const txBody = buildTxBody(timestamp, address, urlKey, urlValue); + const txBody = buildTxBody(timestamp, account.address, urlKey, urlValue); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(endpointUrl, txBody, privateKey, chainId); + const txInfo = await signAndSendTx(endpointUrl, txBody, account.private_key, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); @@ -39,9 +39,9 @@ async function sendTransaction(endpointUrl, chainId, urlKey, urlValue, address, async function sendAddToDevelopersUrlWhitelistTx(endpointUrl, chainId, urlKey, urlValue, accountType, keystoreFilepath) { const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); - const account = ainUtil.privateToAccount('0x' + privateKey); + const account = ainUtil.privateToAccount(Buffer.from(privateKey, 'hex')); console.log(`\nAccount address: ${account.address}\n`); - await sendTransaction(endpointUrl, chainId, urlKey, urlValue, account.address, privateKey); + await sendTransaction(endpointUrl, chainId, urlKey, urlValue, account); } async function processArguments() { diff --git a/tools/developers/sendAddToDevelopersUserWhitelistTx.js b/tools/developers/sendAddToDevelopersUserWhitelistTx.js index b79fb0c88..c2a55aabe 100644 --- a/tools/developers/sendAddToDevelopersUserWhitelistTx.js +++ b/tools/developers/sendAddToDevelopersUserWhitelistTx.js @@ -1,6 +1,7 @@ // A tool to register an address to the developers user whitelist. // This should be executed with blockchain owner's keystore files. // This can be tested with the tool scripts under tools/chatbot. +const ainUtil = require('@ainblockchain/ain-util'); const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); const { getAccountPrivateKey, signAndSendTx, confirmTransaction } = require('../util'); @@ -19,14 +20,14 @@ function buildTxBody(timestamp, address) { }; } -async function sendTransaction(endpointUrl, chainId, developerAddr, privateKey) { +async function sendTransaction(endpointUrl, chainId, developerAddr, account) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); const txBody = buildTxBody(timestamp, developerAddr); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(endpointUrl, txBody, privateKey, chainId); + const txInfo = await signAndSendTx(endpointUrl, txBody, account.private_key, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); @@ -37,7 +38,9 @@ async function sendTransaction(endpointUrl, chainId, developerAddr, privateKey) async function sendAddToDevelopersUserWhitelistTx(endpointUrl, chainId, developerAddr, accountType, keystoreFilepath) { const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); - await sendTransaction(endpointUrl, chainId, developerAddr, privateKey); + const account = ainUtil.privateToAccount(Buffer.from(privateKey, 'hex')); + console.log(`\nAccount address: ${account.address}\n`); + await sendTransaction(endpointUrl, chainId, developerAddr, account); } async function processArguments() { diff --git a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js index aedae0ea9..12162d3c7 100644 --- a/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUrlWhitelistTx.js @@ -21,14 +21,14 @@ function buildTxBody(timestamp, address, urlKey) { }; } -async function sendTransaction(endpointUrl, chainId, urlKey, address, privateKey) { +async function sendTransaction(endpointUrl, chainId, urlKey, account) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - const txBody = buildTxBody(timestamp, address, urlKey); + const txBody = buildTxBody(timestamp, account.address, urlKey); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(endpointUrl, txBody, privateKey, chainId); + const txInfo = await signAndSendTx(endpointUrl, txBody, account.private_key, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); @@ -39,9 +39,9 @@ async function sendTransaction(endpointUrl, chainId, urlKey, address, privateKey async function sendRemoveFromDevelopersUrlWhitelistTx(endpointUrl, chainId, urlKey, accountType, keystoreFilepath) { const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); - const account = ainUtil.privateToAccount('0x' + privateKey); + const account = ainUtil.privateToAccount(Buffer.from(privateKey, 'hex')); console.log(`\nAccount address: ${account.address}\n`); - await sendTransaction(endpointUrl, chainId, urlKey, account.address, privateKey); + await sendTransaction(endpointUrl, chainId, urlKey, account); } async function processArguments() { diff --git a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js index 639be6223..80b9e63bb 100644 --- a/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js +++ b/tools/developers/sendRemoveFromDevelopersUserWhitelistTx.js @@ -1,6 +1,7 @@ // A tool to deregister an address from the developers user whitelist. // This should be executed with blockchain owner's keystore files. // This can be tested with the tool scripts under tools/chatbot. +const ainUtil = require('@ainblockchain/ain-util'); const CommonUtil = require('../../common/common-util'); const PathUtil = require('../../common/path-util'); const { getAccountPrivateKey, signAndSendTx, confirmTransaction } = require('../util'); @@ -19,14 +20,14 @@ function buildTxBody(timestamp, address) { }; } -async function sendTransaction(endpointUrl, chainId, developerAddr, privateKey) { +async function sendTransaction(endpointUrl, chainId, developerAddr, account) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); const txBody = buildTxBody(timestamp, developerAddr); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(endpointUrl, txBody, privateKey, chainId); + const txInfo = await signAndSendTx(endpointUrl, txBody, account.private_key, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transaction failed.`); @@ -37,7 +38,9 @@ async function sendTransaction(endpointUrl, chainId, developerAddr, privateKey) async function sendRemoveFromDevelopersUserWhitelistTx(endpointUrl, chainId, developerAddr, accountType, keystoreFilepath) { const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); - await sendTransaction(endpointUrl, chainId, developerAddr, privateKey); + const account = ainUtil.privateToAccount(Buffer.from(privateKey, 'hex')); + console.log(`\nAccount address: ${account.address}\n`); + await sendTransaction(endpointUrl, chainId, developerAddr, account); } async function processArguments() { From 4aacbb6bb8f3ce0b11c2f74904bf9bcaba70dfd3 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 4 May 2023 22:23:51 +0900 Subject: [PATCH 29/41] Tweak options of token transfer tool --- tools/transfer/config_gcp.js | 7 --- tools/transfer/config_local.js | 7 --- tools/transfer/config_token_bridge_local.js | 8 --- tools/transfer/sendTransferTx.js | 58 ++++++++++++++------- 4 files changed, 40 insertions(+), 40 deletions(-) delete mode 100644 tools/transfer/config_gcp.js delete mode 100644 tools/transfer/config_local.js delete mode 100644 tools/transfer/config_token_bridge_local.js diff --git a/tools/transfer/config_gcp.js b/tools/transfer/config_gcp.js deleted file mode 100644 index 022e558ff..000000000 --- a/tools/transfer/config_gcp.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - endpointUrl: "https://staging-api.ainetwork.ai", - fromAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", - fromPrivateKey: "ee0b1315d446e5318eb6eb4e9d071cd12ef42d2956d546f9acbdc3b75c469640", - toAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", - amount: 10 -}; \ No newline at end of file diff --git a/tools/transfer/config_local.js b/tools/transfer/config_local.js deleted file mode 100644 index c49d1e59f..000000000 --- a/tools/transfer/config_local.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - endpointUrl: "http://localhost:8081", - fromAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", - fromPrivateKey: "ee0b1315d446e5318eb6eb4e9d071cd12ef42d2956d546f9acbdc3b75c469640", - toAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", - amount: 10, -}; \ No newline at end of file diff --git a/tools/transfer/config_token_bridge_local.js b/tools/transfer/config_token_bridge_local.js deleted file mode 100644 index f144405e4..000000000 --- a/tools/transfer/config_token_bridge_local.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - endpointUrl: "http://localhost:8081", - fromAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", - fromPrivateKey: "ee0b1315d446e5318eb6eb4e9d071cd12ef42d2956d546f9acbdc3b75c469640", - // AIN Native token pool (Local) - toAddr: '0x20ADd3d38405ebA6338CB9e57a0510DEB8f8e000', - amount: 100000, -}; \ No newline at end of file diff --git a/tools/transfer/sendTransferTx.js b/tools/transfer/sendTransferTx.js index 2f378840f..483d5d2ad 100644 --- a/tools/transfer/sendTransferTx.js +++ b/tools/transfer/sendTransferTx.js @@ -1,6 +1,7 @@ -const path = require('path'); -const { signAndSendTx, confirmTransaction } = require('../util'); -let config = {}; +// A tool to transfer native AIN tokens between accounts. +const ainUtil = require('@ainblockchain/ain-util'); +const CommonUtil = require('../../common/common-util'); +const { getAccountPrivateKey, signAndSendTx, confirmTransaction } = require('../util'); function buildTransferTxBody(fromAddr, toAddr, key, amount, timestamp) { return { @@ -15,18 +16,15 @@ function buildTransferTxBody(fromAddr, toAddr, key, amount, timestamp) { } } -async function sendTransaction(endpointUrl, chainId) { +async function sendTransaction(endpointUrl, chainId, toAddr, ainAmount, account) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - if (!endpointUrl) { - endpointUrl = config.endpointUrl; - } const txBody = - buildTransferTxBody(config.fromAddr, config.toAddr, timestamp, config.amount, timestamp); + buildTransferTxBody(account.address, toAddr, timestamp, ainAmount, timestamp); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(endpointUrl, txBody, config.fromPrivateKey, chainId); + const txInfo = await signAndSendTx(endpointUrl, txBody, account.private_key, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Transfer transaction failed.`); @@ -35,22 +33,46 @@ async function sendTransaction(endpointUrl, chainId) { await confirmTransaction(endpointUrl, timestamp, txInfo.txHash); } +async function sendTransferTx(endpointUrl, chainId, toAddr, ainAmount, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); + const account = ainUtil.privateToAccount(Buffer.from(privateKey, 'hex')); + console.log(`\nFrom-address: ${account.address}\n`); + await sendTransaction(endpointUrl, chainId, toAddr, ainAmount, account); +} + async function processArguments() { - const len = process.argv.length; - if (len !== 4 && len !== 5) { + if (process.argv.length !== 7 && process.argv.length !== 8) { usage(); } - config = require(path.resolve(__dirname, process.argv[2])); + const endpointUrl = process.argv[2]; const chainId = Number(process.argv[3]); - const endpointUrl = len === 5 ? process.argv[4] : null; - await sendTransaction(endpointUrl, chainId); + const toAddr = process.argv[4]; + if (!CommonUtil.isCksumAddr(toAddr)) { + console.log(`The to-address is NOT a checksum address: ${toAddr}`); + process.exit(0); + } + const ainAmount = Number(process.argv[5]); + if (!CommonUtil.isNumber(ainAmount) || ainAmount <= 0) { + console.log(`The AIN amount is NOT a valid one: ${ainAmount}`); + process.exit(0); + } + const accountType = process.argv[6]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[7] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); + usage(); + } + await sendTransferTx(endpointUrl, chainId, toAddr, ainAmount, accountType, keystoreFilepath); } function usage() { - console.log('\nUsage: node sendTransferTx.js []\n'); - console.log('Example: node sendTransferTx.js config_local.js 0'); - console.log('Example: node sendTransferTx.js config_local.js 0 http://111.222.333.44:1234'); - console.log('Example: node sendTransferTx.js config_local.js 1 https://mainnet-api.ainetwork.ai\n'); + console.log('\nUsage: node sendTransferTx.js []\n'); + console.log('Example: node sendTransferTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b 10 private_key'); + console.log('Example: node sendTransferTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b 10 mnemonic'); + console.log('Example: node sendTransferTx.js http://localhost:8081 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b 10 keystore keystore_from_account.json'); + console.log('Example: node sendTransferTx.js https://staging-api.ainetwork.ai 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b 10 keystore keystore_from_account.json'); + console.log('Example: node sendTransferTx.js https://testnet-api.ainetwork.ai 0 0x08Aed7AF9354435c38d52143EE50ac839D20696b 10 keystore keystore_from_account.json'); + console.log('Example: node sendTransferTx.js https://mainnet-api.ainetwork.ai 1 0x08Aed7AF9354435c38d52143EE50ac839D20696b 10 keystore keystore_from_account.json\n'); process.exit(0) } From 80016b513ace223c55732fd1ed965102e3ee565d Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 4 May 2023 23:27:34 +0900 Subject: [PATCH 30/41] Add chain id option to staking tools --- tools/staking/config_gcp.js | 7 --- tools/staking/config_local.js | 7 --- .../keystore_app_admin_dev_staging.json | 1 + tools/staking/keystore_user_dev_staging.json | 1 + tools/staking/sendCreateAppTx.js | 53 ++++++++++++---- tools/staking/sendStakeTx.js | 60 ++++++++++++++----- tools/staking/sendUnstakeTx.js | 60 ++++++++++++++----- 7 files changed, 134 insertions(+), 55 deletions(-) delete mode 100644 tools/staking/config_gcp.js delete mode 100644 tools/staking/config_local.js create mode 100644 tools/staking/keystore_app_admin_dev_staging.json create mode 100644 tools/staking/keystore_user_dev_staging.json diff --git a/tools/staking/config_gcp.js b/tools/staking/config_gcp.js deleted file mode 100644 index e13295d7f..000000000 --- a/tools/staking/config_gcp.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - endpointUrl: "https://staging-api.ainetwork.ai", - userAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", - userPrivateKey: "ee0b1315d446e5318eb6eb4e9d071cd12ef42d2956d546f9acbdc3b75c469640", - serviceOwnerAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", - serviceOwnerPrivateKey: "9fad756c0bd0d3a42643973f36e61d4d76e01cbb41371fa3046bcced6926e1b2" -}; diff --git a/tools/staking/config_local.js b/tools/staking/config_local.js deleted file mode 100644 index cd979804d..000000000 --- a/tools/staking/config_local.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - endpointUrl: "http://localhost:8081", - userAddr: "0x09A0d53FDf1c36A131938eb379b98910e55EEfe1", - userPrivateKey: "ee0b1315d446e5318eb6eb4e9d071cd12ef42d2956d546f9acbdc3b75c469640", - serviceOwnerAddr: "0x08Aed7AF9354435c38d52143EE50ac839D20696b", - serviceOwnerPrivateKey: "9fad756c0bd0d3a42643973f36e61d4d76e01cbb41371fa3046bcced6926e1b2" -}; \ No newline at end of file diff --git a/tools/staking/keystore_app_admin_dev_staging.json b/tools/staking/keystore_app_admin_dev_staging.json new file mode 100644 index 000000000..df2a7cff0 --- /dev/null +++ b/tools/staking/keystore_app_admin_dev_staging.json @@ -0,0 +1 @@ +{"version":3,"id":"0ca3c829-4b9b-403c-9a8f-a87c823c50b2","address":"08aed7af9354435c38d52143ee50ac839d20696b","crypto":{"ciphertext":"3e543fff76cf4e23c5d29db0ff8d437da1e35654e3861c4ef690d0135599e6df","cipherparams":{"iv":"7146b9d7c0068e2b741d8774b526d2ae"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"fd8b94e9e6c72c89ea6fb37f84b6c63de026769f9656aa8fd6166959ec27aa68","n":262144,"r":8,"p":1},"mac":"b71aed58015c67a0b0a9edc7b727a8affda2091c185964eb9c41af47ebc5d97e"}} \ No newline at end of file diff --git a/tools/staking/keystore_user_dev_staging.json b/tools/staking/keystore_user_dev_staging.json new file mode 100644 index 000000000..3b8c057fd --- /dev/null +++ b/tools/staking/keystore_user_dev_staging.json @@ -0,0 +1 @@ +{"version":3,"id":"8cd7d0a1-4ef4-4217-9118-9b3e3f929ea0","address":"09a0d53fdf1c36a131938eb379b98910e55eefe1","crypto":{"ciphertext":"99f00fe56585a99321c698d5b1114bf23358f40c4a2bcac353b59c160730566d","cipherparams":{"iv":"103d8779982a74c6374fa095893aa2ea"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"28ff7f42bd95b206d8dcb524e9f6d74e9e32765c433bf6505a90c87bbd7858b9","n":262144,"r":8,"p":1},"mac":"3959b7c613826de47e835615992f0dbd5a9ccb346cb0c50507ac773b640568e0"}} \ No newline at end of file diff --git a/tools/staking/sendCreateAppTx.js b/tools/staking/sendCreateAppTx.js index 1fb7cc247..743333962 100644 --- a/tools/staking/sendCreateAppTx.js +++ b/tools/staking/sendCreateAppTx.js @@ -1,16 +1,18 @@ -const path = require('path'); +// A tool to create a blockchain app. const moment = require('moment'); -const { signAndSendTx, confirmTransaction } = require('../util'); +const ainUtil = require('@ainblockchain/ain-util'); +const CommonUtil = require('../../common/common-util'); +const { getAccountPrivateKey, signAndSendTx, confirmTransaction } = require('../util'); -function buildCreateAppTxBody(address, timestamp) { +function buildCreateAppTxBody(address, appName, timestamp) { return { operation: { type: 'SET_VALUE', - ref: `/manage_app/test_service/create/${timestamp}`, + ref: `/manage_app/${appName}/create/${timestamp}`, value: { admin: { [address]: true }, service: { - staking: { lockup_duration: moment.duration(5, 'minute').as('milliseconds') } + staking: { lockup_duration: moment.duration(1, 'minute').as('milliseconds') } } } }, @@ -20,30 +22,55 @@ function buildCreateAppTxBody(address, timestamp) { } } -async function sendTransaction() { +async function sendTransaction(endpointUrl, chainId, appName, account) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - const txBody = buildCreateAppTxBody(config.serviceOwnerAddr, timestamp); + const txBody = buildCreateAppTxBody(account.address, appName, timestamp); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.serviceOwnerPrivateKey); + const txInfo = await signAndSendTx(endpointUrl, txBody, account.private_key, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Create app transaction failed.`); process.exit(0); } - await confirmTransaction(config.endpointUrl, timestamp, txInfo.txHash); + await confirmTransaction(endpointUrl, timestamp, txInfo.txHash); +} + +async function sendCreateAppTx(endpointUrl, chainId, appName, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); + const account = ainUtil.privateToAccount(Buffer.from(privateKey, 'hex')); + console.log(`\nApp admin address: ${account.address}\n`); + await sendTransaction(endpointUrl, chainId, appName, account); } async function processArguments() { - if (process.argv.length !== 3) { + if (process.argv.length !== 6 && process.argv.length !== 7) { + usage(); + } + const endpointUrl = process.argv[2]; + const chainId = Number(process.argv[3]); + const appName = process.argv[4]; + if (!CommonUtil.isString(appName) || appName.length == 0) { + console.log(`The app name is NOT a valid one: ${appName}`); + process.exit(0); + } + const accountType = process.argv[5]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[6] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); usage(); } - config = require(path.resolve(__dirname, process.argv[2])); - await sendTransaction(); + await sendCreateAppTx(endpointUrl, chainId, appName, accountType, keystoreFilepath); } function usage() { - console.log('\nExample commandlines:\n node sendCreateAppTx.js config_local.js\n') + console.log('\nUsage: node sendCreateAppTx.js []\n'); + console.log('Example: node sendCreateAppTx.js http://localhost:8081 0 test_app private_key'); + console.log('Example: node sendCreateAppTx.js http://localhost:8081 0 test_app mnemonic'); + console.log('Example: node sendCreateAppTx.js http://localhost:8081 0 test_app keystore keystore_app_admin.json'); + console.log('Example: node sendCreateAppTx.js https://staging-api.ainetwork.ai 0 test_app keystore keystore_app_admin.json'); + console.log('Example: node sendCreateAppTx.js https://testnet-api.ainetwork.ai 0 test_app keystore keystore_app_admin.json'); + console.log('Example: node sendCreateAppTx.js https://mainnet-api.ainetwork.ai 1 test_app keystore keystore_app_admin.json\n'); process.exit(0) } diff --git a/tools/staking/sendStakeTx.js b/tools/staking/sendStakeTx.js index daa7d1822..49c2c147d 100644 --- a/tools/staking/sendStakeTx.js +++ b/tools/staking/sendStakeTx.js @@ -1,12 +1,14 @@ -const path = require('path'); -const { signAndSendTx, confirmTransaction } = require('../util'); +// A tool to stake AIN tokens for a blockchain app. +const ainUtil = require('@ainblockchain/ain-util'); +const CommonUtil = require('../../common/common-util'); +const { getAccountPrivateKey, signAndSendTx, confirmTransaction } = require('../util'); -function buildStakeTxBody(address, timestamp) { +function buildStakeTxBody(address, appName, ainAmount, timestamp) { return { operation: { type: 'SET_VALUE', - ref: `/staking/test_service/${address}/0/stake/${timestamp}/value`, - value: 100 + ref: `/staking/${appName}/${address}/0/stake/${timestamp}/value`, + value: ainAmount }, gas_price: 500, timestamp, @@ -14,31 +16,61 @@ function buildStakeTxBody(address, timestamp) { } } -async function sendTransaction() { +async function sendTransaction(endpointUrl, chainId, appName, ainAmount, account) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - const txBody = buildStakeTxBody(config.userAddr, timestamp); + const txBody = buildStakeTxBody(account.address, appName, ainAmount, timestamp); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.userPrivateKey); + const txInfo = await signAndSendTx(endpointUrl, txBody, account.private_key, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Stake transaction failed.`); process.exit(0); } - await confirmTransaction(config.endpointUrl, timestamp, txInfo.txHash); + await confirmTransaction(endpointUrl, timestamp, txInfo.txHash); +} + +async function sendStakeTx(endpointUrl, chainId, appName, ainAmount, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); + const account = ainUtil.privateToAccount(Buffer.from(privateKey, 'hex')); + console.log(`\nStaking address: ${account.address}\n`); + await sendTransaction(endpointUrl, chainId, appName, ainAmount, account); } async function processArguments() { - if (process.argv.length !== 3) { + if (process.argv.length !== 7 && process.argv.length !== 8) { + usage(); + } + const endpointUrl = process.argv[2]; + const chainId = Number(process.argv[3]); + const appName = process.argv[4]; + if (!CommonUtil.isString(appName) || appName.length == 0) { + console.log(`The app name is NOT a valid one: ${appName}`); + process.exit(0); + } + const ainAmount = Number(process.argv[5]); + if (!CommonUtil.isNumber(ainAmount) || ainAmount <= 0) { + console.log(`The AIN amount is NOT a valid one: ${ainAmount}`); + process.exit(0); + } + const accountType = process.argv[6]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[7] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); usage(); } - config = require(path.resolve(__dirname, process.argv[2])); - await sendTransaction(); + await sendStakeTx(endpointUrl, chainId, appName, ainAmount, accountType, keystoreFilepath); } function usage() { - console.log('\nExample commandlines:\n node sendStakeTx.js config_local.js\n') - process.exit(0) + console.log('\nUsage: node sendStakeTx.js []\n'); + console.log('Example: node sendStakeTx.js http://localhost:8081 0 test_app 100 private_key'); + console.log('Example: node sendStakeTx.js http://localhost:8081 0 test_app 100 mnemonic'); + console.log('Example: node sendStakeTx.js http://localhost:8081 0 test_app 100 keystore keystore_user.json'); + console.log('Example: node sendStakeTx.js https://staging-api.ainetwork.ai 0 test_app 100 keystore keystore_user.json'); + console.log('Example: node sendStakeTx.js https://testnet-api.ainetwork.ai 0 test_app 100 keystore keystore_user.json'); + console.log('Example: node sendStakeTx.js https://mainnet-api.ainetwork.ai 1 test_app 100 keystore keystore_user.json\n'); + process.exit(0); } processArguments(); diff --git a/tools/staking/sendUnstakeTx.js b/tools/staking/sendUnstakeTx.js index 2808914b9..f84b90f54 100644 --- a/tools/staking/sendUnstakeTx.js +++ b/tools/staking/sendUnstakeTx.js @@ -1,12 +1,14 @@ -const path = require('path'); -const { signAndSendTx, confirmTransaction } = require('../util'); +// A tool to unstake AIN tokens for a blockchain app. +const ainUtil = require('@ainblockchain/ain-util'); +const CommonUtil = require('../../common/common-util'); +const { getAccountPrivateKey, signAndSendTx, confirmTransaction } = require('../util'); -function buildUnstakeTxBody(address, timestamp) { +function buildUnstakeTxBody(address, appName, ainAmount, timestamp) { return { operation: { type: 'SET_VALUE', - ref: `/staking/test_service/${address}/0/unstake/${timestamp}/value`, - value: 100 + ref: `/staking/${appName}/${address}/0/unstake/${timestamp}/value`, + value: ainAmount }, gas_price: 500, timestamp, @@ -14,31 +16,61 @@ function buildUnstakeTxBody(address, timestamp) { } } -async function sendTransaction() { +async function sendTransaction(endpointUrl, chainId, appName, ainAmount, account) { console.log('\n*** sendTransaction():'); const timestamp = Date.now(); - const txBody = buildUnstakeTxBody(config.userAddr, timestamp); + const txBody = buildUnstakeTxBody(account.address, appName, ainAmount, timestamp); console.log(`txBody: ${JSON.stringify(txBody, null, 2)}`); - const txInfo = await signAndSendTx(config.endpointUrl, txBody, config.userPrivateKey); + const txInfo = await signAndSendTx(endpointUrl, txBody, account.private_key, chainId); console.log(`txInfo: ${JSON.stringify(txInfo, null, 2)}`); if (!txInfo.success) { console.log(`Unstake transaction failed.`); process.exit(0); } - await confirmTransaction(config.endpointUrl, timestamp, txInfo.txHash); + await confirmTransaction(endpointUrl, timestamp, txInfo.txHash); +} + +async function sendUnstakeTx(endpointUrl, chainId, appName, ainAmount, accountType, keystoreFilepath) { + const privateKey = await getAccountPrivateKey(accountType, keystoreFilepath); + const account = ainUtil.privateToAccount(Buffer.from(privateKey, 'hex')); + console.log(`\nUnstaking address: ${account.address}\n`); + await sendTransaction(endpointUrl, chainId, appName, ainAmount, account); } async function processArguments() { - if (process.argv.length !== 3) { + if (process.argv.length !== 7 && process.argv.length !== 8) { + usage(); + } + const endpointUrl = process.argv[2]; + const chainId = Number(process.argv[3]); + const appName = process.argv[4]; + if (!CommonUtil.isString(appName) || appName.length == 0) { + console.log(`The app name is NOT a valid one: ${appName}`); + process.exit(0); + } + const ainAmount = Number(process.argv[5]); + if (!CommonUtil.isNumber(ainAmount) || ainAmount <= 0) { + console.log(`The AIN amount is NOT a valid one: ${ainAmount}`); + process.exit(0); + } + const accountType = process.argv[6]; + const keystoreFilepath = (accountType === 'keystore') ? process.argv[7] : null; + if (accountType === 'keystore' && !keystoreFilepath) { + console.error('Please specify keystore filepath.'); usage(); } - config = require(path.resolve(__dirname, process.argv[2])); - await sendTransaction(); + await sendUnstakeTx(endpointUrl, chainId, appName, ainAmount, accountType, keystoreFilepath); } function usage() { - console.log('\nExample commandlines:\n node sendUnstakeTx.js config_local.js\n') - process.exit(0) + console.log('\nUsage: node sendUnstakeTx.js []\n'); + console.log('Example: node sendUnstakeTx.js http://localhost:8081 0 test_app 100 private_key'); + console.log('Example: node sendUnstakeTx.js http://localhost:8081 0 test_app 100 mnemonic'); + console.log('Example: node sendUnstakeTx.js http://localhost:8081 0 test_app 100 keystore keystore_user.json'); + console.log('Example: node sendUnstakeTx.js https://staging-api.ainetwork.ai 0 test_app 100 keystore keystore_user.json'); + console.log('Example: node sendUnstakeTx.js https://testnet-api.ainetwork.ai 0 test_app 100 keystore keystore_user.json'); + console.log('Example: node sendUnstakeTx.js https://mainnet-api.ainetwork.ai 1 test_app 100 keystore keystore_user.json\n'); + process.exit(0); } processArguments(); From d6faa0af4d8533de4fe1ff58f1ba5d3646253cf2 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 8 May 2023 11:24:48 +0900 Subject: [PATCH 31/41] Fix typo, tweak usage --- tools/account/createAccounts.js | 2 +- tools/account/keystoreToAccount.js | 3 +-- tools/account/seedPhraseToAccounts.js | 4 ++-- tools/api-access/removeFromDevClientApiIpWhitelist.js | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/account/createAccounts.js b/tools/account/createAccounts.js index 26bf0c5fb..3f99254b5 100644 --- a/tools/account/createAccounts.js +++ b/tools/account/createAccounts.js @@ -55,7 +55,7 @@ async function processArguments() { function usage() { console.log('\nUsage: node createAccounts.js \n') console.log('Example: node createAccounts.js 1'); - console.log('Example: node createAccounts.js 10 AA'); + console.log('Example: node createAccounts.js 10 AA\n'); process.exit(0) } diff --git a/tools/account/keystoreToAccount.js b/tools/account/keystoreToAccount.js index c76b1dc22..8a3fd2439 100644 --- a/tools/account/keystoreToAccount.js +++ b/tools/account/keystoreToAccount.js @@ -10,8 +10,7 @@ async function processArguments() { function usage() { console.log('\nUsage: node keystoreToAccount.js \n'); - console.log('Example: node keystoreToAccount.js /path/to/keystore'); - console.log('Example: node keystoreToAccount.js ../../testnet_dev_staging_keys/keystore_node_0.json'); + console.log('Example: node keystoreToAccount.js keystore_my_account.json\n'); process.exit(0); } diff --git a/tools/account/seedPhraseToAccounts.js b/tools/account/seedPhraseToAccounts.js index db704a3a1..c56c9028a 100644 --- a/tools/account/seedPhraseToAccounts.js +++ b/tools/account/seedPhraseToAccounts.js @@ -32,8 +32,8 @@ async function processArguments() { function usage() { console.log('\nUsage: node seedPhraseToAccount.js []\n'); - console.log('Example: node seedPhraseToAccount.js'); - console.log('Example: node seedPhraseToAccount.js 1'); + console.log('Example: node seedPhraseToAccount.js'); + console.log('Example: node seedPhraseToAccount.js 1\n'); process.exit(0); } diff --git a/tools/api-access/removeFromDevClientApiIpWhitelist.js b/tools/api-access/removeFromDevClientApiIpWhitelist.js index d065de40c..2f9236a26 100644 --- a/tools/api-access/removeFromDevClientApiIpWhitelist.js +++ b/tools/api-access/removeFromDevClientApiIpWhitelist.js @@ -55,7 +55,7 @@ async function processArguments() { } function usage() { - console.log('\nUsage: node removeFromDevClientApiIpWhitelist.js []\n'); + console.log('\nUsage: node removeFromDevClientApiIpWhitelist.js []\n'); console.log('Example: node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 127.0.0.1 private_key'); console.log('Example: node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 127.0.0.1 mnemonic'); console.log('Example: node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 127.0.0.1 keystore keystore_blockchain_node.json'); From 366f8992b58faa195708f4d624dcd86e535146eb Mon Sep 17 00:00:00 2001 From: kriii Date: Tue, 9 May 2023 11:29:01 +0900 Subject: [PATCH 32/41] Add json rpc urls to start_node_docker.sh --- start_node_docker.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/start_node_docker.sh b/start_node_docker.sh index 7c83ce8f1..39c79baff 100644 --- a/start_node_docker.sh +++ b/start_node_docker.sh @@ -1,15 +1,23 @@ if [[ $SEASON = 'mainnet' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/mainnet-prod + export TRACKER_UPDATE_JSON_RPC_URL=http://34.81.167.141:8080/json-rpc + export PEER_CANDIDATE_JSON_RPC_URL="http://104.199.237.250:8080/json-rpc" elif [[ $SEASON = 'summer' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-prod + export TRACKER_UPDATE_JSON_RPC_URL=http://35.194.172.106:8080/json-rpc + export PEER_CANDIDATE_JSON_RPC_URL="http://35.194.169.78:8080/json-rpc" elif [[ $SEASON = 'spring' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-prod + export TRACKER_UPDATE_JSON_RPC_URL=http://35.221.137.80:8080/json-rpc + export PEER_CANDIDATE_JSON_RPC_URL="http://35.221.184.48:8080/json-rpc" elif [[ $SEASON = 'sandbox' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-sandbox elif [[ $SEASON = 'staging' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-staging + export PEER_CANDIDATE_JSON_RPC_URL="http://35.194.139.219:8080/json-rpc" elif [[ $SEASON = 'exp' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-exp + export PEER_CANDIDATE_JSON_RPC_URL="http://34.81.178.195:8080/json-rpc" elif [[ $SEASON = 'dev' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-dev fi From 690457b3695d7e45de1106ce5e6b703885368b3f Mon Sep 17 00:00:00 2001 From: kriii Date: Tue, 9 May 2023 11:29:23 +0900 Subject: [PATCH 33/41] Add mount a volume readme --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5250bd86f..021e59fa4 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,12 @@ You can use some environment variables, and these have the following options. -e SYNC_MODE={fast|full|peer} -e STAKE= ``` +You can mount a volume when you meet some wants. +1. Want to preserve blockchain data in the docker container when changing the docker image due to an update. +2. Want to save your keystore file in the docker container when injecting your account into the blockchain automatically. +``` +-v :/home +``` After the node is executed, you should inject your account into the node. ``` node inject_node_account.js --private-key @@ -180,7 +186,7 @@ node inject_node_account.js --mnemonic If you want to inject your account automatically, add one of these environment variables before running the node. ``` -e ACCOUNT_INJECTION_OPTION=private_key -e PRIVATE_KEY= --e ACCOUNT_INJECTION_OPTION=keystore -e KEYSTORE_FILE_PATH="/path/to/keystore" -e PASSWORD= +-e ACCOUNT_INJECTION_OPTION=keystore -e KEYSTORE_FILE_PATH="/home/" -e PASSWORD= -e ACCOUNT_INJECTION_OPTION=mnemonic -e MNEMONIC="your mnemonic" ``` From 7e433a14aaba910bb2861a98d98e5a9b4589e3f6 Mon Sep 17 00:00:00 2001 From: kriii Date: Tue, 9 May 2023 11:40:58 +0900 Subject: [PATCH 34/41] Add HOSTRING_ENV readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 021e59fa4..b74b88e86 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,7 @@ You can use some environment variables, and these have the following options. -e ACCOUNT_INJECTION_OPTION={private_key|keystore|mnemonic} -e SYNC_MODE={fast|full|peer} -e STAKE= +-e HOSTING_ENV={gcp|aws} ``` You can mount a volume when you meet some wants. 1. Want to preserve blockchain data in the docker container when changing the docker image due to an update. From 1cce2efa310cfe9b4b29d0deccb8e8c8ffc96d77 Mon Sep 17 00:00:00 2001 From: kriii Date: Tue, 9 May 2023 11:55:06 +0900 Subject: [PATCH 35/41] Add local HOSTRING_ENV --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b74b88e86..943778e53 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ You can use some environment variables, and these have the following options. -e ACCOUNT_INJECTION_OPTION={private_key|keystore|mnemonic} -e SYNC_MODE={fast|full|peer} -e STAKE= --e HOSTING_ENV={gcp|aws} +-e HOSTING_ENV={local|gcp|aws} ``` You can mount a volume when you meet some wants. 1. Want to preserve blockchain data in the docker container when changing the docker image due to an update. From a26246b4b5eb79ae53cf11957d80269f2d23bf45 Mon Sep 17 00:00:00 2001 From: kriii Date: Tue, 9 May 2023 11:56:09 +0900 Subject: [PATCH 36/41] Add comcom HOSTRING_ENV --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 943778e53..27c39bfaf 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ You can use some environment variables, and these have the following options. -e ACCOUNT_INJECTION_OPTION={private_key|keystore|mnemonic} -e SYNC_MODE={fast|full|peer} -e STAKE= --e HOSTING_ENV={local|gcp|aws} +-e HOSTING_ENV={local|comcom|gcp|aws} ``` You can mount a volume when you meet some wants. 1. Want to preserve blockchain data in the docker container when changing the docker image due to an update. From c82d9801db079026c018ca0ec1018c8ce23a049e Mon Sep 17 00:00:00 2001 From: kriii Date: Tue, 9 May 2023 17:02:24 +0900 Subject: [PATCH 37/41] Fix initUrls --- p2p/server.js | 1 + 1 file changed, 1 insertion(+) diff --git a/p2p/server.js b/p2p/server.js index 1d3d99c23..8eaad1f0e 100644 --- a/p2p/server.js +++ b/p2p/server.js @@ -331,6 +331,7 @@ class P2pServer { break; case HostingEnvs.COMCOM: case HostingEnvs.GCP: + case HostingEnvs.AWS: urls = this.buildUrls(extIp); break; } From e3f3f25b3456b8e2aac86420abefb8a1ddb031c9 Mon Sep 17 00:00:00 2001 From: kriii Date: Tue, 9 May 2023 17:59:23 +0900 Subject: [PATCH 38/41] Fix getIpAddress --- common/network-util.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common/network-util.js b/common/network-util.js index bd7688344..cfca678ec 100644 --- a/common/network-util.js +++ b/common/network-util.js @@ -10,6 +10,7 @@ const DB = require('../db'); const { JSON_RPC_METHODS } = require('../json_rpc/constants'); const GCP_EXTERNAL_IP_URL = 'http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip'; const GCP_INTERNAL_IP_URL = 'http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip'; +const AWS_TOKEN_URL = 'http://169.254.169.254/latest/api/token'; const AWS_EXTERNAL_IP_URL = 'http://169.254.169.254/latest/meta-data/public-ipv4'; const AWS_INTERNAL_IP_URL = 'http://169.254.169.254/latest/meta-data/local-ipv4'; @@ -109,7 +110,18 @@ function getIpAddress(internal = false) { logger, `Failed to get ip address: ${JSON.stringify(err, null, 2)}`); }); } else if (NodeConfigs.HOSTING_ENV === HostingEnvs.AWS) { + const token = axios.put(AWS_TOKEN_URL, { }, { + headers: {'X-aws-ec2-metadata-token-ttl-seconds': 21600} + }) + .then((res) => { + return res.data; + }) + .catch((err) => { + CommonUtil.finishWithStackTrace( + logger, `Failed to get aws token: ${JSON.stringify(err, null, 2)}`); + }); return axios.get(internal ? AWS_INTERNAL_IP_URL : AWS_EXTERNAL_IP_URL, { + headers: {'X-aws-ec2-metadata-token': token}, timeout: 3000 }) .then((res) => { From f9e53753089ccc25cad48472d64d93c118fd1e78 Mon Sep 17 00:00:00 2001 From: kriii Date: Wed, 10 May 2023 09:57:29 +0900 Subject: [PATCH 39/41] Change mount path --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 27c39bfaf..03b870346 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ You can mount a volume when you meet some wants. 1. Want to preserve blockchain data in the docker container when changing the docker image due to an update. 2. Want to save your keystore file in the docker container when injecting your account into the blockchain automatically. ``` --v :/home +-v :/home/ain_blockchain_data ``` After the node is executed, you should inject your account into the node. ``` @@ -187,7 +187,7 @@ node inject_node_account.js --mnemonic If you want to inject your account automatically, add one of these environment variables before running the node. ``` -e ACCOUNT_INJECTION_OPTION=private_key -e PRIVATE_KEY= --e ACCOUNT_INJECTION_OPTION=keystore -e KEYSTORE_FILE_PATH="/home/" -e PASSWORD= +-e ACCOUNT_INJECTION_OPTION=keystore -e KEYSTORE_FILE_PATH="/home/ain_blockchain_data/" -e PASSWORD= -e ACCOUNT_INJECTION_OPTION=mnemonic -e MNEMONIC="your mnemonic" ``` From c22cf1b5d2259a3444d8da128f4eaaccead86446 Mon Sep 17 00:00:00 2001 From: kriii Date: Thu, 11 May 2023 14:20:46 +0900 Subject: [PATCH 40/41] Fix JSON_PRC_URL setting --- start_node_docker.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/start_node_docker.sh b/start_node_docker.sh index 39c79baff..d79045eea 100644 --- a/start_node_docker.sh +++ b/start_node_docker.sh @@ -1,23 +1,17 @@ if [[ $SEASON = 'mainnet' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/mainnet-prod - export TRACKER_UPDATE_JSON_RPC_URL=http://34.81.167.141:8080/json-rpc - export PEER_CANDIDATE_JSON_RPC_URL="http://104.199.237.250:8080/json-rpc" elif [[ $SEASON = 'summer' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-prod - export TRACKER_UPDATE_JSON_RPC_URL=http://35.194.172.106:8080/json-rpc - export PEER_CANDIDATE_JSON_RPC_URL="http://35.194.169.78:8080/json-rpc" + export TRACKER_UPDATE_JSON_RPC_URL="http://35.194.172.106:8080/json-rpc" elif [[ $SEASON = 'spring' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-prod - export TRACKER_UPDATE_JSON_RPC_URL=http://35.221.137.80:8080/json-rpc - export PEER_CANDIDATE_JSON_RPC_URL="http://35.221.184.48:8080/json-rpc" + export TRACKER_UPDATE_JSON_RPC_URL="http://35.221.137.80:8080/json-rpc" elif [[ $SEASON = 'sandbox' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-sandbox elif [[ $SEASON = 'staging' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-staging - export PEER_CANDIDATE_JSON_RPC_URL="http://35.194.139.219:8080/json-rpc" elif [[ $SEASON = 'exp' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-exp - export PEER_CANDIDATE_JSON_RPC_URL="http://34.81.178.195:8080/json-rpc" elif [[ $SEASON = 'dev' ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-dev fi From ed5668f9a5427ef44681a9e4ababf9ee32efc9d4 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Fri, 12 May 2023 10:47:20 +0900 Subject: [PATCH 41/41] Upgrade ain blockchain version to 1.0.14 --- client/protocol_versions.json | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/protocol_versions.json b/client/protocol_versions.json index ca6224fee..2b8f68f4a 100644 --- a/client/protocol_versions.json +++ b/client/protocol_versions.json @@ -116,5 +116,8 @@ }, "1.0.13": { "min": "1.0.0" + }, + "1.0.14": { + "min": "1.0.0" } } \ No newline at end of file diff --git a/package.json b/package.json index c5ed41868..afed40b08 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ain-blockchain", "description": "AI Network Blockchain", - "version": "1.0.13", + "version": "1.0.14", "private": true, "license": "MIT", "author": "dev@ainetwork.ai",