From 57e966c0f4c90ffd6ce0f33aac48bd5264e55c08 Mon Sep 17 00:00:00 2001 From: lucanicoladebiasi Date: Wed, 23 Oct 2024 16:35:17 +0100 Subject: [PATCH 01/11] Account poking... --- package.json | 5 +++-- src/1.Hello_World/FinancialMath.md | 17 ++++++++++++++ src/1.Hello_World/FinancialMath.ts | 31 +++++++++++++++++++++++++ src/1.Hello_World/HelloWorld.md | 2 +- src/4.Accounts/Account.mts | 36 ++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 src/1.Hello_World/FinancialMath.md create mode 100644 src/1.Hello_World/FinancialMath.ts create mode 100644 src/4.Accounts/Account.mts diff --git a/package.json b/package.json index c0f8c2f..c99f162 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "license": "MIT", "description": "VeChain SDK Tutorial for NodeJS.", "dependencies": { - "@vechain/sdk-network": "1.0.0-beta.32" + "@vechain/sdk-network": "1.0.0-beta.32", + "bignumber.js": "^9.1.1" }, "devDependencies": { "@commitlint/config-conventional": "^19.5.0", @@ -26,7 +27,7 @@ "commitlint": "^19.5.0", "eslint": "^9.12.0", "eslint-config-prettier": "^9.1.0", - "eslint-config-standard-with-typescript": "^43.0.1", + "eslint-config-love": "^v87.0.0", "eslint-plugin-import": "^2.31.0", "eslint-plugin-n": "^17.11.1", "eslint-plugin-prettier": "^5.2.1", diff --git a/src/1.Hello_World/FinancialMath.md b/src/1.Hello_World/FinancialMath.md new file mode 100644 index 0000000..b101966 --- /dev/null +++ b/src/1.Hello_World/FinancialMath.md @@ -0,0 +1,17 @@ +## Lesson 1 - Part 2 + +# Financial Math + +JavaScript (JS) was designed as front-end language. + +The JS `number` type implements the 64 bits [Double Precision Floating Point](https://en.wikipedia.org/wiki/Double-precision_floating-point_format) +representation as the `double` type common in *C#*, *Java?Kotlin* and *Rust/Zig* programming languages. +This representation approximates the real value with less precision as the value moves to the edge of +the information can be represented in 8 bytes, + +String doesn't oblige to approximation. + + + +https://mikemcl.github.io/bignumber.js/ + diff --git a/src/1.Hello_World/FinancialMath.ts b/src/1.Hello_World/FinancialMath.ts new file mode 100644 index 0000000..aa11199 --- /dev/null +++ b/src/1.Hello_World/FinancialMath.ts @@ -0,0 +1,31 @@ +import {FixedPointNumber} from '@vechain/sdk-core'; +import { BigNumber } from 'bignumber.js'; + +let x = FixedPointNumber.of(123.456789); +let y = FixedPointNumber.of('123.456789'); +console.log(`FPN value ${x} from number is ${x.isEqual(y) ? '' : 'not'}equal to ${y} from string.`); +console.log(`Cast FPN value to number is ${x.n}.`); +console.log(`Cast FPN value to bigint is ${x.bi}.`); + +x = FixedPointNumber.of(1); +y = FixedPointNumber.of(3); +let r = x.div(y); +console.log(`FPN value = ${r}; JS value = ${x.n/y.n}; BigNumber value = ${BigNumber(x.n).div(y.n)}.`); +x = x.dp(80) // must be updated +r = x.div(y); +console.log(`${r}`); + +let dp = 20; +for(let n = 0; n <= 8; n ++) { + x = FixedPointNumber.of(n, BigInt(dp)); + r = x.sqrt(); + console.log(`${n}, ${r};\t${Math.sqrt(n)};\t${BigNumber(n).dp(dp).sqrt()}`); +} + +// let dp = 20; +// for(let n = 0; n <= 8; n ++) { +// x = FixedPointNumber.of(n, BigInt(dp)); +// r = x.sqrt(); +// console.log(`${n}, ${r};\t${Math.sqrt(n)};\t${BigNumber(n).dp(dp).sqrt()}`); +// } + diff --git a/src/1.Hello_World/HelloWorld.md b/src/1.Hello_World/HelloWorld.md index 152fb5f..da6e656 100644 --- a/src/1.Hello_World/HelloWorld.md +++ b/src/1.Hello_World/HelloWorld.md @@ -1,4 +1,4 @@ -## Lesson 1 +## Lesson 1 - Part 1 # Hello World! diff --git a/src/4.Accounts/Account.mts b/src/4.Accounts/Account.mts new file mode 100644 index 0000000..8cff99f --- /dev/null +++ b/src/4.Accounts/Account.mts @@ -0,0 +1,36 @@ +import {Address, Clause, Secp256k1, TransactionClause, VET, VTHO} from "@vechain/sdk-core"; +import {THOR_SOLO_URL, ThorClient} from "@vechain/sdk-network"; + +const privateKey = await Secp256k1.generatePrivateKey(); +const publicKey = Secp256k1.derivePublicKey(privateKey); +const address = Address.ofPublicKey(publicKey); + +const clauses: TransactionClause[] = [ + Clause.transferVET( + address, + VET.of(10000) + ) as TransactionClause +]; + +const transaction = { + clauses: clauses +}; + +const thorClient = ThorClient.fromUrl(THOR_SOLO_URL); + +const gasResult = await thorClient.gas.estimateGas( + transaction.clauses +); + +console.log(gasResult); + +const txBody = await thorClient.transactions.buildTransactionBody( + transaction.clauses, + gasResult.totalGas +); + +console.log(txBody); + + + +thorClient.destroy(); From 453a580c88e5116ca7dd4cc436ae2cb34c812bda Mon Sep 17 00:00:00 2001 From: lucanicoladebiasi Date: Wed, 30 Oct 2024 13:40:22 +0000 Subject: [PATCH 02/11] Financial math lesson. --- src/4.Accounts/ThorSolo.md | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/4.Accounts/ThorSolo.md diff --git a/src/4.Accounts/ThorSolo.md b/src/4.Accounts/ThorSolo.md new file mode 100644 index 0000000..8974065 --- /dev/null +++ b/src/4.Accounts/ThorSolo.md @@ -0,0 +1,69 @@ +VeChain develops and provides the **[Thor](https://docs.vechain.org/core-concepts/networks)** blockchain networks. + +The **[mainnet](https://docs.vechain.org/core-concepts/networks/mainnet)** +refers to the live, operational version of a blockchain network. +It is the real, functioning blockchain network that is open to the public +and used by participants to conduct actual transactions, store data, and execute smart contracts. + +The **[testnet](https://docs.vechain.org/core-concepts/networks/testnet)** +is a testing environment where developers and users can experiment prior +to deploying code to the blockchain production network, referred to as **mainnet**. +The **testnet** is essentially a separate blockchain networks that +mirrors the functionality of the **mainnet** but is isolated from it. + +The **Thor** **[solo](https://docs.vechain.org/core-concepts/networks/thor-solo-node)** is a local +instance of **Thor** operating a single node that independently maintains and validates the entire blockchain network. +In other words, a **solo** node does not rely on other nodes for validation and verification of transactions and blocks. +Instead, it performs all the necessary tasks on its own. +Therefore, running a Thor **solo** node is essentially running the VeChainThor node software but not connecting it +to other network participants in **mainnet** or **testnet**. + +The **solo** node network instance is very convenient to develop and test software for the VeChain Thor network +without the need to be connected to **testnet** for the development, everything can be done in local. + +The following of this tutorial uses **Thor solo** to show how to develop software for the VeChain networks. + + +[How to run a Thor solo node](https://docs.vechain.org/how-to-run-a-node/how-to-run-a-thor-solo-node) + +The most convenient way to run a **solo** node network is to run it in a +**[docker](https://docs.vechain.org/how-to-run-a-node/how-to-run-a-thor-solo-node#docker-containerized-convenience)** +container. + +The following guides shows how to install + - **[docker](https://docs.docker.com/get-started/get-docker/)** + and **[docker compose](https://docs.docker.com/compose/install/)**, or + - **[docker desktop](https://docs.docker.com/desktop/)** +in your computer. + +Once **docker** and **docker compose** or **docker desktop** - that includes **docker compose** - are installed, + +1. move to the directory of the SDK. +2. To start **solo** open the [CLI](https://en.wikipedia.org/wiki/Command-line_interface) shell and type + ```shell + docker compose -f docker-compose.thor.yml up -d --wait + ``` +3. To stop **solo**, type in shell + ```shell + docker compose -f docker-compose.thor.yml down + ``` + +Since you are reading this tutorial, there are excellent chances you read it to develop software with the help of the +SDK, hence you have already installed +- [Node.js](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs) +- [Yarn](https://classic.yarnpkg.com/en/docs/install) + +you can start **solo** typing in the shell + +```shell +yarn start start-thor-solo +``` + +and stop it later typing in the shell + +```shell +yarn stop-thor-solo +``` + + + From 6454910393c62e871e42842166b8b055d4af4669 Mon Sep 17 00:00:00 2001 From: lucanicoladebiasi Date: Wed, 30 Oct 2024 13:55:00 +0000 Subject: [PATCH 03/11] Financial math lesson. --- README.md | 7 +++++-- src/4.Accounts/{ThorSolo.md => Thor.md} | 12 +++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) rename src/4.Accounts/{ThorSolo.md => Thor.md} (91%) diff --git a/README.md b/README.md index 0c7ea6c..df63fb6 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,12 @@ The [src](src) directory provides a list of lessons with exercises and solutions * [User's keys and address.](src/3.Keys_Addresses_Wallets/Keys.md) * [User's keys and address from mnemonic words - BIP39.](src/3.Keys_Addresses_Wallets/BIP39.md) * [One key to rule them all: hierarchic deterministic keys and wallets - BIP32.](src/3.Keys_Addresses_Wallets/BIP32.md) +4. + * [Thor networks - 'mainnet', 'testnet' and 'solo'](src/4.Accounts/Thor) + The lessons show snippet of code beginning with the remarks starting with `// STEP : `, -those refer to the complete code in the file haning the same name of the file of the lesson with the suffix `.ts` or `.mts` +those refer to the complete code in the file naming the same name of the file of the lesson with the suffix `.ts` or `.mts` ## License @@ -27,4 +30,4 @@ This project is licensed under the [MIT license](LICENSE.md). ## Contact information - Discord https://discord.com/invite/vechain -- Support https://support.vechain.org \ No newline at end of file +- Support https://support.vechain.org diff --git a/src/4.Accounts/ThorSolo.md b/src/4.Accounts/Thor.md similarity index 91% rename from src/4.Accounts/ThorSolo.md rename to src/4.Accounts/Thor.md index 8974065..d246535 100644 --- a/src/4.Accounts/ThorSolo.md +++ b/src/4.Accounts/Thor.md @@ -1,7 +1,12 @@ +## Lesson 4 - Part 1 + +# Thor networks - 'mainnet', 'testnet' and 'solo' + VeChain develops and provides the **[Thor](https://docs.vechain.org/core-concepts/networks)** blockchain networks. The **[mainnet](https://docs.vechain.org/core-concepts/networks/mainnet)** refers to the live, operational version of a blockchain network. + It is the real, functioning blockchain network that is open to the public and used by participants to conduct actual transactions, store data, and execute smart contracts. @@ -23,8 +28,7 @@ without the need to be connected to **testnet** for the development, everything The following of this tutorial uses **Thor solo** to show how to develop software for the VeChain networks. - -[How to run a Thor solo node](https://docs.vechain.org/how-to-run-a-node/how-to-run-a-thor-solo-node) +## [How to run a Thor 'solo' node network](https://docs.vechain.org/how-to-run-a-node/how-to-run-a-thor-solo-node) The most convenient way to run a **solo** node network is to run it in a **[docker](https://docs.vechain.org/how-to-run-a-node/how-to-run-a-thor-solo-node#docker-containerized-convenience)** @@ -48,6 +52,8 @@ Once **docker** and **docker compose** or **docker desktop** - that includes **d docker compose -f docker-compose.thor.yml down ``` +## Start and stop Thor 'solo' with `yarn` + Since you are reading this tutorial, there are excellent chances you read it to develop software with the help of the SDK, hence you have already installed - [Node.js](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs) @@ -65,5 +71,5 @@ and stop it later typing in the shell yarn stop-thor-solo ``` - +This is the way suggested to follow the next lessons. From b84f08628ca9b1c1cc53a4403feeac9182e0d0fe Mon Sep 17 00:00:00 2001 From: lucanicoladebiasi Date: Wed, 30 Oct 2024 18:12:14 +0000 Subject: [PATCH 04/11] Financial math lesson. --- src/4.Accounts/Account.mts | 36 --------------------- src/4.Accounts/Thor.md | 65 ++++++++++++++++++++++++++++++++------ 2 files changed, 55 insertions(+), 46 deletions(-) delete mode 100644 src/4.Accounts/Account.mts diff --git a/src/4.Accounts/Account.mts b/src/4.Accounts/Account.mts deleted file mode 100644 index 8cff99f..0000000 --- a/src/4.Accounts/Account.mts +++ /dev/null @@ -1,36 +0,0 @@ -import {Address, Clause, Secp256k1, TransactionClause, VET, VTHO} from "@vechain/sdk-core"; -import {THOR_SOLO_URL, ThorClient} from "@vechain/sdk-network"; - -const privateKey = await Secp256k1.generatePrivateKey(); -const publicKey = Secp256k1.derivePublicKey(privateKey); -const address = Address.ofPublicKey(publicKey); - -const clauses: TransactionClause[] = [ - Clause.transferVET( - address, - VET.of(10000) - ) as TransactionClause -]; - -const transaction = { - clauses: clauses -}; - -const thorClient = ThorClient.fromUrl(THOR_SOLO_URL); - -const gasResult = await thorClient.gas.estimateGas( - transaction.clauses -); - -console.log(gasResult); - -const txBody = await thorClient.transactions.buildTransactionBody( - transaction.clauses, - gasResult.totalGas -); - -console.log(txBody); - - - -thorClient.destroy(); diff --git a/src/4.Accounts/Thor.md b/src/4.Accounts/Thor.md index d246535..d8ed436 100644 --- a/src/4.Accounts/Thor.md +++ b/src/4.Accounts/Thor.md @@ -6,7 +6,6 @@ VeChain develops and provides the **[Thor](https://docs.vechain.org/core-concept The **[mainnet](https://docs.vechain.org/core-concepts/networks/mainnet)** refers to the live, operational version of a blockchain network. - It is the real, functioning blockchain network that is open to the public and used by participants to conduct actual transactions, store data, and execute smart contracts. @@ -28,7 +27,10 @@ without the need to be connected to **testnet** for the development, everything The following of this tutorial uses **Thor solo** to show how to develop software for the VeChain networks. -## [How to run a Thor 'solo' node network](https://docs.vechain.org/how-to-run-a-node/how-to-run-a-thor-solo-node) +## Start and stop Thor 'solo' + +The link at [How to run a Thor 'solo' node network](https://docs.vechain.org/how-to-run-a-node/how-to-run-a-thor-solo-node) +explains how to install and configure a Thor **solo** network. The most convenient way to run a **solo** node network is to run it in a **[docker](https://docs.vechain.org/how-to-run-a-node/how-to-run-a-thor-solo-node#docker-containerized-convenience)** @@ -42,27 +44,28 @@ in your computer. Once **docker** and **docker compose** or **docker desktop** - that includes **docker compose** - are installed, -1. move to the directory of the SDK. -2. To start **solo** open the [CLI](https://en.wikipedia.org/wiki/Command-line_interface) shell and type +1. move to the directory of the SDK, conventionally referred as `` in this document; +2. to start **solo** open the [CLI](https://en.wikipedia.org/wiki/Command-line_interface) shell and type ```shell docker compose -f docker-compose.thor.yml up -d --wait ``` -3. To stop **solo**, type in shell +3. and to stop **solo**, type in shell ```shell docker compose -f docker-compose.thor.yml down ``` +. ## Start and stop Thor 'solo' with `yarn` Since you are reading this tutorial, there are excellent chances you read it to develop software with the help of the -SDK, hence you have already installed -- [Node.js](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs) -- [Yarn](https://classic.yarnpkg.com/en/docs/install) +SDK, hence you should have already installed both +- [Node.js](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs), and +- [Yarn](https://classic.yarnpkg.com/en/docs/install), hence you can start **solo** typing in the shell ```shell -yarn start start-thor-solo +yarn start-thor-solo ``` and stop it later typing in the shell @@ -70,6 +73,48 @@ and stop it later typing in the shell ```shell yarn stop-thor-solo ``` +. + +Supposing the SDK is installed in the `` directory, +the file at `` directory, +the file at `/docker-compose.rpc-proxy.yml` shows how **docker compose** bootstraps **solo** +with the `--gensis` option reading how to build the genesis block from the file at +`/docker/rpc-proxy/config/genesis.json`. + +The file at `/docker-compose.thor.yml` is what `yarn start-thor-solo` invokes, the launched +**solo** instance has ten full funded accounts. -This is the way suggested to follow the next lessons. +In the following lessons of this tutorial you will play with these primordial accounts and you will transfer **balance** +and **energy** funds from them to the accounts you will create. From f7ff461f06b457f4664c64661ba0c36ba3dc9ecf Mon Sep 17 00:00:00 2001 From: lucanicoladebiasi Date: Wed, 30 Oct 2024 18:17:25 +0000 Subject: [PATCH 05/11] Thor explained --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index df63fb6..88eed0b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ The [src](src) directory provides a list of lessons with exercises and solutions * [User's keys and address from mnemonic words - BIP39.](src/3.Keys_Addresses_Wallets/BIP39.md) * [One key to rule them all: hierarchic deterministic keys and wallets - BIP32.](src/3.Keys_Addresses_Wallets/BIP32.md) 4. - * [Thor networks - 'mainnet', 'testnet' and 'solo'](src/4.Accounts/Thor) + * [Thor networks - 'mainnet', 'testnet' and 'solo'](src/4.Accounts/Thor.md) The lessons show snippet of code beginning with the remarks starting with `// STEP : `, From 37ccb6bc917c87b4b808a75d49c2b16fe6eff07d Mon Sep 17 00:00:00 2001 From: lucanicoladebiasi Date: Wed, 30 Oct 2024 18:23:15 +0000 Subject: [PATCH 06/11] Thor explained --- src/4.Accounts/Thor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/4.Accounts/Thor.md b/src/4.Accounts/Thor.md index d8ed436..aba1eeb 100644 --- a/src/4.Accounts/Thor.md +++ b/src/4.Accounts/Thor.md @@ -81,7 +81,7 @@ two commands `start-thor-solo` and `stop-thor-solo` invoke. This is the way to start and stop **solo** suggested to follow the next lessons. -## What an 'account' is? +## What an 'account' is In Thor terminology, an external owned account is a relation between an address - created because a pair of keys owned by a user - and funds. From 1e3723c3d2e140d1544060b1ae1b12e0ddb7342b Mon Sep 17 00:00:00 2001 From: lucanicoladebiasi Date: Wed, 30 Oct 2024 18:53:35 +0000 Subject: [PATCH 07/11] Thor explained --- src/4.Accounts/Thor.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/4.Accounts/Thor.md b/src/4.Accounts/Thor.md index aba1eeb..1a7d1b1 100644 --- a/src/4.Accounts/Thor.md +++ b/src/4.Accounts/Thor.md @@ -118,3 +118,23 @@ The file at `/docker-compose.thor.yml` is what `yarn start-thor- In the following lessons of this tutorial you will play with these primordial accounts and you will transfer **balance** and **energy** funds from them to the accounts you will create. +```mermaid +flowchart TD + start((Start)) + is_to_synch{{Sync with peer nodes?}} + synchronize[[Synchronize with peers node.]] + has_genesis_block{{Has genesis block?}} + has_genesis_option{{Has --genesis option?}} + build_genesis[[Build the genesis block]] + run(((Run))) + start --> is_to_synch + is_to_synch -->|yes|synchronize + is_to_synch -->|no| has_genesis_block + synchronize --> has_genesis_block + has_genesis_block -->|no|has_genesis_option + has_genesis_block -->|yes|run + has_genesis_option -->|yes|build_genesis + has_genesis_option -->|no|run + build_genesis --> run +``` + From 85b91667da25d02d72710312bd934b6f2c8fa48a Mon Sep 17 00:00:00 2001 From: lucanicoladebiasi Date: Wed, 30 Oct 2024 18:55:45 +0000 Subject: [PATCH 08/11] Thor explained --- src/4.Accounts/Thor.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/4.Accounts/Thor.md b/src/4.Accounts/Thor.md index 1a7d1b1..a30d869 100644 --- a/src/4.Accounts/Thor.md +++ b/src/4.Accounts/Thor.md @@ -119,6 +119,9 @@ In the following lessons of this tutorial you will play with these primordial ac and **energy** funds from them to the accounts you will create. ```mermaid +--- +title: Thor bootstrap +--- flowchart TD start((Start)) is_to_synch{{Sync with peer nodes?}} From a68d83ee49161822b0c12f6c8866c8bf62a34a7f Mon Sep 17 00:00:00 2001 From: lucanicoladebiasi Date: Wed, 30 Oct 2024 18:58:09 +0000 Subject: [PATCH 09/11] Thor explained --- src/4.Accounts/Thor.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/4.Accounts/Thor.md b/src/4.Accounts/Thor.md index a30d869..67684c1 100644 --- a/src/4.Accounts/Thor.md +++ b/src/4.Accounts/Thor.md @@ -128,7 +128,8 @@ flowchart TD synchronize[[Synchronize with peers node.]] has_genesis_block{{Has genesis block?}} has_genesis_option{{Has --genesis option?}} - build_genesis[[Build the genesis block]] + read_genesis[[Read the genesis.json file.]] + build_genesis[[Build the genesis block.]] run(((Run))) start --> is_to_synch is_to_synch -->|yes|synchronize @@ -136,7 +137,8 @@ flowchart TD synchronize --> has_genesis_block has_genesis_block -->|no|has_genesis_option has_genesis_block -->|yes|run - has_genesis_option -->|yes|build_genesis + has_genesis_option -->|yes|read_genesis + read_genesis --> build_genesis has_genesis_option -->|no|run build_genesis --> run ``` From fc2dab1580b0d3ce376f5bafa33f8fdd1c43ce7e Mon Sep 17 00:00:00 2001 From: lucanicoladebiasi Date: Wed, 30 Oct 2024 19:44:58 +0000 Subject: [PATCH 10/11] Thor explained --- src/4.Accounts/Thor.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/4.Accounts/Thor.md b/src/4.Accounts/Thor.md index 67684c1..f4a04ff 100644 --- a/src/4.Accounts/Thor.md +++ b/src/4.Accounts/Thor.md @@ -115,6 +115,8 @@ with the `--gensis` option reading how to build the genesis block from the file The file at `/docker-compose.thor.yml` is what `yarn start-thor-solo` invokes, the launched **solo** instance has ten full funded accounts. +**_NOTE:_** it's worth to mention, if not evident, the code building the **genesis** block is part of Thor, not of the SDK. + In the following lessons of this tutorial you will play with these primordial accounts and you will transfer **balance** and **energy** funds from them to the accounts you will create. From 07dba86f877e15b8662e1b77659eaed349924db2 Mon Sep 17 00:00:00 2001 From: Fabio Rigamonti <73019897+fabiorigam@users.noreply.github.com> Date: Thu, 31 Oct 2024 16:02:22 +0100 Subject: [PATCH 11/11] fix: fix linter issue --- package.json | 3 ++- src/1.Hello_World/FinancialMath.ts | 17 ++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index c99f162..edccd58 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,9 @@ "@eslint/js": "^9.12.0", "commitlint": "^19.5.0", "eslint": "^9.12.0", - "eslint-config-prettier": "^9.1.0", "eslint-config-love": "^v87.0.0", + "eslint-config-prettier": "^9.1.0", + "eslint-config-standard-with-typescript": "^43.0.1", "eslint-plugin-import": "^2.31.0", "eslint-plugin-n": "^17.11.1", "eslint-plugin-prettier": "^5.2.1", diff --git a/src/1.Hello_World/FinancialMath.ts b/src/1.Hello_World/FinancialMath.ts index aa11199..74707bb 100644 --- a/src/1.Hello_World/FinancialMath.ts +++ b/src/1.Hello_World/FinancialMath.ts @@ -1,22 +1,26 @@ -import {FixedPointNumber} from '@vechain/sdk-core'; +import { FixedPointNumber } from '@vechain/sdk-core'; import { BigNumber } from 'bignumber.js'; let x = FixedPointNumber.of(123.456789); let y = FixedPointNumber.of('123.456789'); -console.log(`FPN value ${x} from number is ${x.isEqual(y) ? '' : 'not'}equal to ${y} from string.`); +console.log( + `FPN value ${x} from number is ${x.isEqual(y) ? '' : 'not'}equal to ${y} from string.` +); console.log(`Cast FPN value to number is ${x.n}.`); console.log(`Cast FPN value to bigint is ${x.bi}.`); x = FixedPointNumber.of(1); y = FixedPointNumber.of(3); let r = x.div(y); -console.log(`FPN value = ${r}; JS value = ${x.n/y.n}; BigNumber value = ${BigNumber(x.n).div(y.n)}.`); -x = x.dp(80) // must be updated +console.log( + `FPN value = ${r}; JS value = ${x.n / y.n}; BigNumber value = ${BigNumber(x.n).div(y.n)}.` +); +x = x.dp(80); // must be updated r = x.div(y); console.log(`${r}`); -let dp = 20; -for(let n = 0; n <= 8; n ++) { +const dp = 20; +for (let n = 0; n <= 8; n++) { x = FixedPointNumber.of(n, BigInt(dp)); r = x.sqrt(); console.log(`${n}, ${r};\t${Math.sqrt(n)};\t${BigNumber(n).dp(dp).sqrt()}`); @@ -28,4 +32,3 @@ for(let n = 0; n <= 8; n ++) { // r = x.sqrt(); // console.log(`${n}, ${r};\t${Math.sqrt(n)};\t${BigNumber(n).dp(dp).sqrt()}`); // } -