From ad4e09f8e516bf2b2902a5c4a0b1b6d0a73b5bcb Mon Sep 17 00:00:00 2001 From: 0xaptosj <129789810+0xaptosj@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:49:18 -0700 Subject: [PATCH] remove node scripts --- .../node-scripts/.example.env | 1 - .../indexer-template/node-scripts/.gitignore | 37 --------- .../indexer-template/node-scripts/README.MD | 5 -- .../node-scripts/package.json | 22 ----- .../src/lib/abi/message_board_abi.ts | 80 ------------------- .../node-scripts/src/lib/utils.ts | 51 ------------ .../node-scripts/src/script/create_message.ts | 13 --- .../src/script/get_last_message_from_db.ts | 18 ----- .../node-scripts/src/script/get_message.ts | 14 ---- .../node-scripts/src/script/update_message.ts | 16 ---- .../node-scripts/tsconfig.json | 17 ---- 11 files changed, 274 deletions(-) delete mode 100644 templates/indexer-template/node-scripts/.example.env delete mode 100644 templates/indexer-template/node-scripts/.gitignore delete mode 100644 templates/indexer-template/node-scripts/README.MD delete mode 100644 templates/indexer-template/node-scripts/package.json delete mode 100644 templates/indexer-template/node-scripts/src/lib/abi/message_board_abi.ts delete mode 100644 templates/indexer-template/node-scripts/src/lib/utils.ts delete mode 100644 templates/indexer-template/node-scripts/src/script/create_message.ts delete mode 100644 templates/indexer-template/node-scripts/src/script/get_last_message_from_db.ts delete mode 100644 templates/indexer-template/node-scripts/src/script/get_message.ts delete mode 100644 templates/indexer-template/node-scripts/src/script/update_message.ts delete mode 100644 templates/indexer-template/node-scripts/tsconfig.json diff --git a/templates/indexer-template/node-scripts/.example.env b/templates/indexer-template/node-scripts/.example.env deleted file mode 100644 index b4280b1b..00000000 --- a/templates/indexer-template/node-scripts/.example.env +++ /dev/null @@ -1 +0,0 @@ -PRIVATE_KEY="to_fill" \ No newline at end of file diff --git a/templates/indexer-template/node-scripts/.gitignore b/templates/indexer-template/node-scripts/.gitignore deleted file mode 100644 index 00bba9bb..00000000 --- a/templates/indexer-template/node-scripts/.gitignore +++ /dev/null @@ -1,37 +0,0 @@ -# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. - -# dependencies -/node_modules -/.pnp -.pnp.js -.yarn/install-state.gz - -# testing -/coverage - -# next.js -/.next/ -/out/ - -# production -/build - -# misc -.DS_Store -*.pem - -# debug -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# local env files -.env*.local -.env - -# vercel -.vercel - -# typescript -*.tsbuildinfo -next-env.d.ts diff --git a/templates/indexer-template/node-scripts/README.MD b/templates/indexer-template/node-scripts/README.MD deleted file mode 100644 index 6cc17b92..00000000 --- a/templates/indexer-template/node-scripts/README.MD +++ /dev/null @@ -1,5 +0,0 @@ -# Node scripts for testing - -We prepared some node scripts for you to test reading and writing to the contract and DB. This makes it easier to test the contract without having to use the frontend. - -See `scripts` in `package.json` for the available scripts. diff --git a/templates/indexer-template/node-scripts/package.json b/templates/indexer-template/node-scripts/package.json deleted file mode 100644 index 7068dae1..00000000 --- a/templates/indexer-template/node-scripts/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "node-scripts", - "version": "0.0.1", - "private": true, - "scripts": { - "create-message": "ts-node src/script/create_message.ts", - "update-message": "ts-node src/script/update_message.ts", - "get-message": "ts-node src/script/get_message.ts", - "get-last-message-from-db": "ts-node src/script/get_last_message_from_db.ts" - }, - "dependencies": { - "@aptos-labs/ts-sdk": "^1.26.0", - "@thalalabs/surf": "^1.7.3", - "dotenv": "^16.3.1", - "pg": "^8.12.0" - }, - "devDependencies": { - "@types/pg": "^8.11.8", - "ts-node": "^10.9.2", - "typescript": "^5.3.3" - } -} diff --git a/templates/indexer-template/node-scripts/src/lib/abi/message_board_abi.ts b/templates/indexer-template/node-scripts/src/lib/abi/message_board_abi.ts deleted file mode 100644 index b2b56319..00000000 --- a/templates/indexer-template/node-scripts/src/lib/abi/message_board_abi.ts +++ /dev/null @@ -1,80 +0,0 @@ -export const ABI = { - address: "0xda6c2a8c4eae7b4fb7ef1b3319cc201492cc04e49d17b57dd75456e9b85e84b4", - name: "message_board", - friends: [], - exposed_functions: [ - { - name: "create_message", - visibility: "public", - is_entry: true, - is_view: false, - generic_type_params: [], - params: ["&signer", "0x1::string::String"], - return: [], - }, - { - name: "get_message_content", - visibility: "public", - is_entry: false, - is_view: true, - generic_type_params: [], - params: [ - "0x1::object::Object<0xda6c2a8c4eae7b4fb7ef1b3319cc201492cc04e49d17b57dd75456e9b85e84b4::message_board::Message>", - ], - return: ["0x1::string::String", "address", "u64", "u64"], - }, - { - name: "update_message", - visibility: "public", - is_entry: true, - is_view: false, - generic_type_params: [], - params: [ - "&signer", - "0x1::object::Object<0xda6c2a8c4eae7b4fb7ef1b3319cc201492cc04e49d17b57dd75456e9b85e84b4::message_board::Message>", - "0x1::string::String", - ], - return: [], - }, - ], - structs: [ - { - name: "CreateMessageEvent", - is_native: false, - abilities: ["drop", "store"], - generic_type_params: [], - fields: [ - { name: "message_obj_addr", type: "address" }, - { - name: "message", - type: "0xda6c2a8c4eae7b4fb7ef1b3319cc201492cc04e49d17b57dd75456e9b85e84b4::message_board::Message", - }, - ], - }, - { - name: "Message", - is_native: false, - abilities: ["copy", "drop", "store", "key"], - generic_type_params: [], - fields: [ - { name: "creator", type: "address" }, - { name: "content", type: "0x1::string::String" }, - { name: "creation_timestamp", type: "u64" }, - { name: "last_update_timestamp", type: "u64" }, - ], - }, - { - name: "UpdateMessageEvent", - is_native: false, - abilities: ["drop", "store"], - generic_type_params: [], - fields: [ - { name: "message_obj_addr", type: "address" }, - { - name: "message", - type: "0xda6c2a8c4eae7b4fb7ef1b3319cc201492cc04e49d17b57dd75456e9b85e84b4::message_board::Message", - }, - ], - }, - ], -} as const; diff --git a/templates/indexer-template/node-scripts/src/lib/utils.ts b/templates/indexer-template/node-scripts/src/lib/utils.ts deleted file mode 100644 index 120ec3b4..00000000 --- a/templates/indexer-template/node-scripts/src/lib/utils.ts +++ /dev/null @@ -1,51 +0,0 @@ -import "dotenv/config"; -import { env } from "process"; -import { - Account, - Aptos, - AptosConfig, - Ed25519PrivateKey, - Network, -} from "@aptos-labs/ts-sdk"; -import { createSurfClient } from "@thalalabs/surf"; -import { Client } from "pg"; - -import { ABI } from "./abi/message_board_abi"; - -const APTOS_CLIENT = new Aptos( - new AptosConfig({ - network: Network.TESTNET, - }) -); - -const SURF_CLIENT = createSurfClient(APTOS_CLIENT).useABI(ABI); - -const POSTGRES_CLIENT = new Client({ - // user: "your_username", - // host: "localhost", - database: "example-indexer", - // password: "your_password", - // port: 5432, -}); - -export const getAptosClient = () => APTOS_CLIENT; - -export const getSurfClient = () => SURF_CLIENT; - -export const getAccount = () => { - if (!env.PRIVATE_KEY && env.PRIVATE_KEY === "to_fill") { - throw new Error("Please fill in your private key"); - } - - return Account.fromPrivateKey({ - privateKey: new Ed25519PrivateKey(env.PRIVATE_KEY!), - }); -}; - -export const getPostgresClient = async () => { - await POSTGRES_CLIENT.connect() - .then(() => console.log("Connected to PostgreSQL")) - .catch((err) => console.error("Connection error", err.stack)); - - return POSTGRES_CLIENT; -}; diff --git a/templates/indexer-template/node-scripts/src/script/create_message.ts b/templates/indexer-template/node-scripts/src/script/create_message.ts deleted file mode 100644 index 0684e8ca..00000000 --- a/templates/indexer-template/node-scripts/src/script/create_message.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { getSurfClient, getAccount } from "../lib/utils"; - -const run = async () => { - getSurfClient() - .entry.create_message({ - typeArguments: [], - functionArguments: ["hahahahaah indexer is working ooooooo"], - account: getAccount(), - }) - .then(console.log); -}; - -run(); diff --git a/templates/indexer-template/node-scripts/src/script/get_last_message_from_db.ts b/templates/indexer-template/node-scripts/src/script/get_last_message_from_db.ts deleted file mode 100644 index d7aa7487..00000000 --- a/templates/indexer-template/node-scripts/src/script/get_last_message_from_db.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { getPostgresClient } from "../lib/utils"; - -const run = async () => { - const client = await getPostgresClient(); - client.query( - "SELECT * FROM messages ORDER BY id DESC LIMIT 1", - (err, res) => { - if (err) { - console.error(err.stack); - } else { - console.log(res.rows[0]); - } - client.end(); - } - ); -}; - -run(); diff --git a/templates/indexer-template/node-scripts/src/script/get_message.ts b/templates/indexer-template/node-scripts/src/script/get_message.ts deleted file mode 100644 index 68093679..00000000 --- a/templates/indexer-template/node-scripts/src/script/get_message.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { getSurfClient } from "../lib/utils"; - -const run = async () => { - getSurfClient() - .view.get_message_content({ - typeArguments: [], - functionArguments: [ - "0x5830e5ee9c9ce1dcbc7a3ff6e8d23f556a99eb21e913ecbdae4c623c314850d1", - ], - }) - .then(console.log); -}; - -run(); diff --git a/templates/indexer-template/node-scripts/src/script/update_message.ts b/templates/indexer-template/node-scripts/src/script/update_message.ts deleted file mode 100644 index 5a0ee605..00000000 --- a/templates/indexer-template/node-scripts/src/script/update_message.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { getSurfClient, getAccount } from "../lib/utils"; - -const run = async () => { - getSurfClient() - .entry.update_message({ - typeArguments: [], - functionArguments: [ - "0x7f37bcfed49904375b012ceae8fdcca58d8c43dc224cbf78a1a0db0f3a32e9cb", - "this is an updated message", - ], - account: getAccount(), - }) - .then(console.log); -}; - -run(); diff --git a/templates/indexer-template/node-scripts/tsconfig.json b/templates/indexer-template/node-scripts/tsconfig.json deleted file mode 100644 index b079044c..00000000 --- a/templates/indexer-template/node-scripts/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "display": "Node", - "compilerOptions": { - "target": "es6", - "moduleResolution": "node", - "noImplicitAny": false, - "removeComments": true, - "preserveConstEnums": true, - "sourceMap": true, - "forceConsistentCasingInFileNames": true, - "outDir": "dist", - "declaration": true, - "allowSyntheticDefaultImports": true, - "strict": true - } -}