diff --git a/assets/keys/miner.json b/assets/keys/miner.json index 51d62e9..692d3fc 100644 --- a/assets/keys/miner.json +++ b/assets/keys/miner.json @@ -1,4 +1,4 @@ { - "publicKey": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEARZFWSXfMHfZ5WWZeqhznPwKV09wq8Cmg9wkLO+dHDoc=\n-----END PUBLIC KEY-----\n", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIA7c9FpfySYc+gvaORHZ43oFuacwzayoK5qCRvBAl7kB\n-----END PRIVATE KEY-----\n" + "publicKey": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAQuJ8hp9ntC2z/q+i9TA60NzxLf5JGbSax76JWr+vp8A=\n-----END PUBLIC KEY-----\n", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIG1YwIi76G+K6C0HKg+lH+Q69k03Kp/D8bKXcX6OYuq1\n-----END PRIVATE KEY-----\n" } \ No newline at end of file diff --git a/assets/keys/user.json b/assets/keys/user.json index ce61135..27bd11f 100644 --- a/assets/keys/user.json +++ b/assets/keys/user.json @@ -1,4 +1,4 @@ { - "publicKey": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEABMxC5bHBMsrZbx2G2mr2Jz+YDJor2JOBIkHoVV/0Wfg=\n-----END PUBLIC KEY-----\n", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIERQntg1KdePgNTwvk6smrg2WJtcRCpNvCPsuxqCPFkn\n-----END PRIVATE KEY-----\n" + "publicKey": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEABYuR9ZVr8WRemSZX6RaTlXFmzMZ8Erx3OKsxGi3alXk=\n-----END PUBLIC KEY-----\n", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIMYnQt+xnEA8Iy8BYdxkBSahcWZ7mc0bb9HIZkdXCnWQ\n-----END PRIVATE KEY-----\n" } \ No newline at end of file diff --git a/readme.md b/readme.md index d10967c..7ad034a 100755 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # GoodChain -Welcome to **GoodChain**, a blockchain platform designed for both beginners and experienced users, seeking simplicity and flexibility. Built with `TypeScript` and `LevelDB (soon)`, **GoodChain** offers a customizable environment for experimenting with consensus algorithms, including a default Simple **Proof-of-Work (PoW)** option. +Welcome to **GoodChain**, a blockchain platform designed for both beginners and experienced users, seeking simplicity and flexibility. Built with `TypeScript` and `LevelDB`, **GoodChain** offers a customizable environment for experimenting with consensus algorithms, including a default Simple **Proof-of-Work (PoW)** option. **GoodChain** is a distributed ledger that enables secure and irreversible transactions across a peer-to-peer distributed network of nodes, ensuring the integrity of data. @@ -139,13 +139,13 @@ This project is licensed under the GNU General Public License. The first version of `GoodChain` was a simple blockchain implementation used to learn about blockchain technology. It used `json` files to store the blockchain data. Check out the [releases](https://github.com/mlibre/GoodChain/releases/tag/1.0.5) to see the code. -### Version 2 (latest version) +### Version 2 -The second version of `GoodChain` built using `Node.js` and `Express.js`, and uses `git` to store the blockchain data. +The second version of `GoodChain` built using `Node.js` and `Express.js`, and uses `git` to store the blockchain data. Check out the [releases](https://github.com/mlibre/GoodChain/releases/tag/2.0.2) to see the code. -### Version 3 (in progress) +### Version 3 (latest version) -The third version of `GoodChain` is built using `TypeScript`, `Express.js`, and `TypeORM`. +The third version of `GoodChain` is built using `TypeScript`, `Express.js`, and `LevelDB`. ## Donate 💖 diff --git a/src/library/chain.ts b/src/library/chain.ts index 8d12614..9d23eb1 100644 --- a/src/library/chain.ts +++ b/src/library/chain.ts @@ -5,11 +5,9 @@ export default class ChainStore { // eslint-disable-next-line @typescript-eslint/no-explicit-any public db: any; - sublevel: string; constructor ( leveldb: Level ) { - this.sublevel = "chain"; - this.db = leveldb.sublevel( this.sublevel, { valueEncoding: "json" }); + this.db = leveldb.sublevel( "chain", { valueEncoding: "json" }); } async length (): Promise @@ -43,7 +41,7 @@ export default class ChainStore async get ( blockNumber: number | string ): Promise { const blockIndex = parseInt( blockNumber.toString() ); - if ( blockIndex >= await this.length() || blockIndex < 0 ) + if ( blockIndex > await this.length() || blockIndex < 0 ) { throw new Error( "Invalid block number" ); } @@ -82,7 +80,7 @@ export default class ChainStore { const action: PutAction = { type: "put", - sublevel: this.sublevel, + sublevel: this.db, key: block.index.toString(), value: block }; diff --git a/src/library/wallet.ts b/src/library/wallet.ts index 1a8167f..8640676 100644 --- a/src/library/wallet.ts +++ b/src/library/wallet.ts @@ -8,11 +8,9 @@ class Wallet { // eslint-disable-next-line @typescript-eslint/no-explicit-any public db: any; - sublevel: string; constructor ( leveldb: Level ) { - this.sublevel = "wallet"; - this.db = leveldb.sublevel( this.sublevel, { valueEncoding: "json" }); + this.db = leveldb.sublevel( "wallet", { valueEncoding: "json" }); } async allWallets (): Promise @@ -121,7 +119,7 @@ class Wallet wallet.balance += amount; const action: PutAction = { type: "put", - sublevel: this.sublevel, + sublevel: this.db, key: address, value: wallet }; @@ -140,7 +138,7 @@ class Wallet wallet.transaction_number++; const action: PutAction = { type: "put", - sublevel: this.sublevel, + sublevel: this.db, key: address, value: wallet }; diff --git a/src/test/a.ts b/src/test/a.ts deleted file mode 100644 index 681bc72..0000000 --- a/src/test/a.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { Level } from "level"; - -// Specify types of keys and values (any, in the case of json). -// The generic type parameters default to Level. -const db = new Level( "./db", { valueEncoding: "json" }); - -// All relevant methods then use those types -await db.put( 0, { x: 1234 }); -await db.put( 3, { x: 1234 }); -await db.put( 6, { x: 1234 }); -await db.put( 9, { x: 1234 }); -await db.put( 1, { x: 1234 }); -await db.put( 12, { x: 1234 }); -await db.put( -1, { x: 1234 }); - -// const keys = await db.keys; -const entries = await db.iterator().all(); - -console.log( entries ); - - -// await revert( "b" ); -// Specify different types when overriding encoding per operation -// await db.get( "a", { valueEncoding: "utf8" }); - -// Though in some cases TypeScript can infer them -// const res = await db.get( "a", { valueEncoding: db.valueEncoding( "utf8" ) }); -// console.log( res ); - - - - -// // It works the same for sublevels -// const abc = db.sublevel( "abc" ); -// await db.clear(); -const xyz = db.sublevel( "xyz", { valueEncoding: "json" }); - -// await xyz.put( "aa", { sublevel: 7777 }); -const res2 = await xyz.get( "aa", { valueEncoding: db.valueEncoding( "utf8" ) }); -console.log( res2 ); - - -