diff --git a/assets/keys/miner.json b/assets/keys/miner.json index 5c91c03..51d62e9 100644 --- a/assets/keys/miner.json +++ b/assets/keys/miner.json @@ -1,4 +1,4 @@ { - "publicKey": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEA3oMfVtEcH5TihTocSs9u2uW7YeFb9uXs8xQdw1PinII=\n-----END PUBLIC KEY-----\n", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIP60GusxCkG8MzmGLZWF3xNI4i7HuZL7Iejs+47Y6evh\n-----END PRIVATE KEY-----\n" + "publicKey": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEARZFWSXfMHfZ5WWZeqhznPwKV09wq8Cmg9wkLO+dHDoc=\n-----END PUBLIC KEY-----\n", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIA7c9FpfySYc+gvaORHZ43oFuacwzayoK5qCRvBAl7kB\n-----END PRIVATE KEY-----\n" } \ No newline at end of file diff --git a/assets/keys/user.json b/assets/keys/user.json index 2cdd65e..ce61135 100644 --- a/assets/keys/user.json +++ b/assets/keys/user.json @@ -1,4 +1,4 @@ { - "publicKey": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAyVFaVJ+h82QimWmFCy8a7bCuTxlICkCklsEptOl3lvI=\n-----END PUBLIC KEY-----\n", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIMmaCvp+nGVSVhpZfZkWHZoOabfm6YgZkSMYKvc0H1zt\n-----END PRIVATE KEY-----\n" + "publicKey": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEABMxC5bHBMsrZbx2G2mr2Jz+YDJor2JOBIkHoVV/0Wfg=\n-----END PUBLIC KEY-----\n", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIERQntg1KdePgNTwvk6smrg2WJtcRCpNvCPsuxqCPFkn\n-----END PRIVATE KEY-----\n" } \ No newline at end of file diff --git a/dist/API/routes/chain.js b/dist/API/routes/chain.js index 71dc869..7047d64 100644 --- a/dist/API/routes/chain.js +++ b/dist/API/routes/chain.js @@ -9,7 +9,7 @@ router.get("/", async function (req, res) { router.post("/update", async function (req, res) { let continueUpdate = true; while (continueUpdate) { - const currentIndex = blockchain.chain.latestBlock.index; + const currentIndex = (await blockchain.chain.latestBlock()).index; const nodesLatestBlocks = []; for (const node of blockchain.nodes.list) { try { @@ -36,12 +36,12 @@ router.post("/update", async function (req, res) { res.send(blockchain.chain.latestBlock); }); router.put("/sync", async function (req, res) { - const myLastestBlock = blockchain.chain.latestBlock; + const myLastestBlock = await blockchain.chain.latestBlock(); const otherNodesLastestBlocks = []; for (const node of blockchain.nodes.list) { try { const [firstBlock, lastBlock] = (await axios.get(`${node}/block`, { params: { firstAndLast: true } })).data; - if (isEqualBlock(firstBlock, blockchain.chain.genesisBlock) && + if (isEqualBlock(firstBlock, await blockchain.chain.genesisBlock()) && !isEqualBlock(myLastestBlock, lastBlock)) { otherNodesLastestBlocks.push({ block: lastBlock, node }); } diff --git a/dist/API/routes/chain.js.map b/dist/API/routes/chain.js.map index ca85dbb..177d3c3 100644 --- a/dist/API/routes/chain.js.map +++ b/dist/API/routes/chain.js.map @@ -1 +1 @@ -{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../../src/API/routes/chain.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;AAChC,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE/D,MAAM,CAAC,GAAG,CAAE,GAAG,EAAE,KAAK,WAAY,GAAG,EAAE,GAAG;IAEzC,GAAG,CAAC,IAAI,CAAE,MAAM,UAAU,CAAC,K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C;QAClE,CAAC;IACF,CAAC;IACD,MAAM,kBAAkB,GAAG;QAC1B,GAAG,uBAAuB;QAC1B,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE;KACvE,CAAC;IACF,MAAM,eAAe,GAAG,UAAU,CAAC,SAAS,CAAC,WAAW,CAAE,kBAAkB,CAAE,CAAC;IAC/E,IAAK,eAAe,EACpB,CAAC;QACA,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,GAAG,CAAE,GAAG,eAAe,CAAC,IAAI,QAAQ,CAAE,CAAC;QACvE,UAAU,CAAC,YAAY,CAAE,WAAW,CAAC,IAAI,CAAE,CAAC;IAC7C,CAAC;IACD,GAAG,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,eAAe,MAAM,CAAC"} \ No newline at end of file diff --git a/dist/API/routes/wallet.js b/dist/API/routes/wallet.js index 6e940a8..2d0b2fb 100644 --- a/dist/API/routes/wallet.js +++ b/dist/API/routes/wallet.js @@ -1,8 +1,8 @@ import express from "express"; const router = express.Router(); import blockchain from "../blockchain.js"; -router.get("/", function (req, res) { - res.send(blockchain.wallet.allData); +router.get("/", async function (req, res) { + res.send(await blockchain.wallet.allWallets()); }); export default router; //# sourceMappingURL=wallet.js.map \ No newline at end of file diff --git a/dist/API/routes/wallet.js.map b/dist/API/routes/wallet.js.map index 9afa175..f109d2a 100644 --- a/dist/API/routes/wallet.js.map +++ b/dist/API/routes/wallet.js.map @@ -1 +1 @@ -{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../src/API/routes/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;AAChC,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAE1C,MAAM,CAAC,GAAG,CAAE,GAAG,EAAE,UAAW,GAAG,EAAE,GAAG;IAEnC,GAAG,CAAC,IAAI,CAAE,UAAU,CAAC,MAAM,CAAC,OAAO,CAAE,CAAC;AACvC,CAAC,CAAC,CAAC;AAEH,eAAe,MAAM,CAAC"} \ No newline at end of file +{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../src/API/routes/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;AAChC,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAE1C,MAAM,CAAC,GAAG,CAAE,GAAG,EAAE,KAAK,WAAY,GAAG,EAAE,GAAG;IAEzC,GAAG,CAAC,IAAI,CAAE,MAAM,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAE,CAAC;AAClD,CAAC,CAAC,CAAC;AAEH,eAAe,MAAM,CAAC"} \ No newline at end of file diff --git a/dist/guards.js b/dist/guards.js index 430fa47..864581b 100644 --- a/dist/guards.js +++ b/dist/guards.js @@ -5,4 +5,11 @@ export function isErrorWithStds(error) { "stdout" in error && "status" in error); } +export function isLevelNotFoundError(error) { + return (typeof error === "object" && + error !== null && + "code" in error && + "notFound" in error && + "status" in error); +} //# sourceMappingURL=guards.js.map \ No newline at end of file diff --git a/dist/guards.js.map b/dist/guards.js.map index 0870bda..cc79e9f 100644 --- a/dist/guards.js.map +++ b/dist/guards.js.map @@ -1 +1 @@ -{"version":3,"file":"guards.js","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAAG,KAAc;IAE/C,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,QAAQ,IAAI,KAAK;QACjB,QAAQ,IAAI,KAAK;QAChB,QAAQ,IAAI,KAAK,CAClB,CAAC;AACH,CAAC"} \ No newline at end of file +{"version":3,"file":"guards.js","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAAG,KAAc;IAE/C,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,QAAQ,IAAI,KAAK;QACjB,QAAQ,IAAI,KAAK;QAChB,QAAQ,IAAI,KAAK,CAClB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAG,KAAc;IAEpD,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACvB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,UAAU,IAAI,KAAK;QACnB,QAAQ,IAAI,KAAK,CACnB,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/dist/library/chain.js b/dist/library/chain.js index ffb6be9..a7d6067 100644 --- a/dist/library/chain.js +++ b/dist/library/chain.js @@ -1,14 +1,14 @@ -import _ from "lodash"; import * as Block from "./block.js"; export default class ChainStore { // eslint-disable-next-line @typescript-eslint/no-explicit-any db; + sublevel; constructor(leveldb) { - this.db = leveldb.sublevel("chain", { valueEncoding: "json" }); + this.sublevel = "chain"; + this.db = leveldb.sublevel(this.sublevel, { valueEncoding: "json" }); } async length() { - const lastKey = await this.lastKey(); - return lastKey; + return await this.lastKey(); } async lastKey() { let lastKey; @@ -18,7 +18,7 @@ export default class ChainStore { break; } if (!lastKey) { - return 0; + throw new Error("No blocks found"); } return Number(lastKey); } @@ -36,7 +36,7 @@ export default class ChainStore { } async getRange(from, to) { const blocks = []; - to = to ?? await this.length() - 1; + to = to ?? await this.length(); for (let i = from; i <= to; i++) { blocks.push(await this.get(i)); } @@ -53,45 +53,22 @@ export default class ChainStore { } return lastBlock; } - async push(block) { - await this.db.put(block.index.toString(), block); - } - async replaceChain(blocks) { - await this.db.clear(); - for (const block of blocks) { - await this.push(block); - } + pushAction(block) { + const action = { + type: "put", + sublevel: this.sublevel, + key: block.index.toString(), + value: block + }; + return action; } async lastTwoBlocks() { const lastBlock = await this.latestBlock(); const secondLastBlock = await this.get(lastBlock.index - 1); return [lastBlock, secondLastBlock]; } - async checkFinalDBState(proposedBlock) { - if (proposedBlock.index === 0) { - const lastBlock = await this.latestBlock(); - Block.verifyGenesisBlock(lastBlock); - if (!_.isEqual(lastBlock, proposedBlock)) { - throw new Error("Invalid chain"); - } - return true; - } - const [lastBlock, secondLastBlock] = [await this.get(proposedBlock.index), await this.get(proposedBlock.index - 1)]; - Block.verifyBlock(lastBlock, secondLastBlock); - if (!_.isEqual(lastBlock, proposedBlock)) { - throw new Error("Invalid chain"); - } - const [lastBlockFile, secondLastBlockFile] = await this.lastTwoBlocks(); - if (!_.isEqual(lastBlockFile, lastBlock) || !_.isEqual(secondLastBlockFile, secondLastBlock)) { - throw new Error("Invalid chain"); - } - return true; - } async validateChain() { - if (await this.length() === 0) { - return true; - } - for (let i = 0; i < await this.length(); i++) { + for (let i = 0; i <= await this.length(); i++) { if (i === 0) { Block.verifyGenesisBlock(await this.get(i)); } @@ -101,5 +78,17 @@ export default class ChainStore { } return true; } + async isEmpty() { + try { + await this.lastKey(); + return false; + } + catch (error) { + if (error instanceof Error && error.message === "No blocks found") { + return true; + } + throw error; + } + } } //# sourceMappingURL=chain.js.map \ No newline at end of file diff --git a/dist/library/chain.js.map b/dist/library/chain.js.map index e3987c8..19f1f0a 100644 --- a/dist/library/chain.js.map +++ b/dist/library/chain.js.map @@ -1 +1 @@ -{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/library/chain.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAGpC,MAAM,CAAC,OAAO,OAAO,UAAU;IAE9B,8DAA8D;IACvD,EAAE,CAAM;IACf,YAAc,OAAiC;QAE9C,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAqB,OAAO,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,CAAC;IACpF,CAAC;IAED,KAAK,CAAC,MAAM;QAEX,MAA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QACd,CAAC;QACD,OAAQ,KAAc,EACtB,CAAC;YACA,IAAK,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,iBAAiB,EAClE,CAAC;gBACA,OAAO,IAAI,CAAC;YACb,CAAC;YACD,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC;CACD"} \ No newline at end of file diff --git a/dist/library/database.js b/dist/library/database.js index 42bc1c7..02cbc68 100644 --- a/dist/library/database.js +++ b/dist/library/database.js @@ -3,12 +3,9 @@ export default class levelDatabase { constructor(leveldb) { this.db = leveldb; } - async revert(key) { - const batch = []; - for await (const [k] of this.db.iterator({ reverse: true })) { - if (k > key) { - batch.push({ type: "del", key: k }); - } + async batch(batch) { + if (batch.length === 0) { + return; } await this.db.batch(batch); } diff --git a/dist/library/database.js.map b/dist/library/database.js.map index 59ed510..8eabfa0 100644 --- a/dist/library/database.js.map +++ b/dist/library/database.js.map @@ -1 +1 @@ -{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/library/database.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,OAAO,aAAa;IAE1B,EAAE,CAA2B;IAEpC,YAAc,OAAiC;QAE9C,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,MAAM,CAAG,GAAW;QAEzB,MAAM,KAAK,GAAoC,EAAE,CAAC;QAElD,IAAI,KAAK,EAAG,MAAM,CAAE,CAAC,CAAE,IAAI,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAC9D,CAAC;YACA,IAAK,CAAC,GAAG,GAAG,EACZ,CAAC;gBACA,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;YACrC,CAAC;QACF,CAAC;QACD,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,CAAE,KAAK,CAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,KAAK;QAEV,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO;IACR,CAAC;CAED"} \ No newline at end of file +{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/library/database.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,OAAO,aAAa;IAE1B,EAAE,CAA2B;IAEpC,YAAc,OAAiC;QAE9C,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,KAAK,CAAG,KAAkB;QAE/B,IAAK,KAAK,CAAC,MAAM,KAAK,CAAC,EACvB,CAAC;YACA,OAAO;QACR,CAAC;QACD,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,CAAE,KAAK,CAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,KAAK;QAEV,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO;IACR,CAAC;CAED"} \ No newline at end of file diff --git a/dist/library/main.js b/dist/library/main.js index 442b4b8..89b5397 100644 --- a/dist/library/main.js +++ b/dist/library/main.js @@ -1,8 +1,8 @@ -import _ from "lodash"; import { Level } from "level"; -import LevelDatabase from "./database.js"; -import { verifyBlock, verifyGenesisBlock, blockify } from "./block.js"; +import _ from "lodash"; +import { blockify, verifyBlock, verifyGenesisBlock } from "./block.js"; import ChainStore from "./chain.js"; +import LevelDatabase from "./database.js"; import Nodes from "./nodes.js"; import Transaction from "./transaction.js"; import { calculateMiningFee, computeHash, createFolder } from "./utils.js"; @@ -31,77 +31,64 @@ export default class Blockchain { this.transactionPoolSize = 100; } async init() { - if (await this.chain.length() === 0) { + if (await this.chain.isEmpty()) { await this.#mineGenesisBlock(); } this.consensus.setValues(await this.chain.latestBlock()); } async #mineGenesisBlock() { const self = this; - try { - await self.database.clear(); - const coinbaseTrx = self.genCoinbaseTransaction(); - self.addTransaction(coinbaseTrx); - const block = { - index: 0, - chainName: self.chainName, - timestamp: Date.now(), - transactions: self.transactionPool, - previousHash: "", - miner: self.minerPublicKey - }; - self.consensus.applyGenesis(block); - block.hash = computeHash(block); - return self.addBlock(block); - } - catch (error) { - await self.database.clear(); - throw error; - } + await self.database.clear(); + const coinbaseTrx = self.genCoinbaseTransaction(); + await self.addTransaction(coinbaseTrx); + const block = { + index: 0, + chainName: self.chainName, + timestamp: Date.now(), + transactions: self.transactionPool, + previousHash: "", + miner: self.minerPublicKey + }; + self.consensus.applyGenesis(block); + block.hash = computeHash(block); + return self.addBlock(block); } async mineNewBlock() { const self = this; const blockIndex = await self.chain.length(); - try { - self.transactionPool = self.wallet.cleanupTransactions(self.transactionPool); - const coinbaseTrx = self.genCoinbaseTransaction(); - self.addTransaction(coinbaseTrx); - const lastBlock = await self.chain.latestBlock(); - const block = { - index: blockIndex + 1, - chainName: self.chainName, - timestamp: Date.now(), - transactions: self.transactionPool, - previousHash: lastBlock?.hash || "", - miner: self.minerPublicKey - }; - self.consensus.apply(block, await self.chain.get(block.index - 1)); - block.hash = computeHash(block); - return self.addBlock(block); - } - catch (error) { - self.database.revert(blockIndex.toString()); - throw error; - } + self.transactionPool = await self.wallet.cleanupTransactions(self.transactionPool); + const coinbaseTrx = self.genCoinbaseTransaction(); + await self.addTransaction(coinbaseTrx); + const lastBlock = await self.chain.latestBlock(); + const block = { + index: blockIndex + 1, + chainName: self.chainName, + timestamp: Date.now(), + transactions: self.transactionPool, + previousHash: lastBlock?.hash || "", + miner: self.minerPublicKey + }; + self.consensus.apply(block, await self.chain.get(block.index - 1)); + block.hash = computeHash(block); + return self.addBlock(block); } - addBlock(block) { + async addBlock(block) { const newBlock = blockify(block); this.verifyCandidateBlock(newBlock); - this.wallet.performTransactions(newBlock.transactions); - this.wallet.checkFinalDBState(newBlock); - this.chain.push(newBlock); - this.chain.checkFinalDBState(newBlock); + const actions = await this.wallet.processTrxActionList(newBlock.transactions); + actions.push(this.chain.pushAction(newBlock)); + await this.database.batch(actions); this.transactionPool = []; return newBlock; } - addBlocks(blocks) { + async addBlocks(blocks) { for (const block of blocks) { - this.addBlock(block); + await this.addBlock(block); } return blocks; } - getBlocks(from, to) { - return this.chain.getRange(from, to); + async getBlocks(from, to) { + return await this.chain.getRange(from, to); } async verifyCandidateBlock(block) { if (block.index == 0) { @@ -114,29 +101,32 @@ export default class Blockchain { } return true; } - addTransaction(transaction) { + async addTransaction(transaction) { this.checkTransactionsPoolSize(); const trx = new Transaction(transaction); if (!trx.isCoinBase() && trx.from !== null) { - this.wallet.validateAddress(trx.from); - this.wallet.isTransactionNumberCorrect(trx.from, trx.transaction_number); + await this.wallet.validateAddress(trx.from); + await this.wallet.isTransactionNumberCorrect(trx.from, trx.transaction_number); } - this.wallet.validateAddress(trx.to); + await this.wallet.validateAddress(trx.to); trx.validate(); this.isTransactionDuplicate(trx.data.signature); this.transactionPool.push(trx.data); this.transactionPool.sort((a, b) => { return b.fee - a.fee; }); - return this.chain.length; + if (trx.isCoinBase()) { + return 0; + } + return await this.chain.length() + 1; } - addTransactions(transactions) { + async addTransactions(transactions) { const results = []; for (const transaction of transactions) { try { results.push({ id: transaction.id, - blockNumber: this.addTransaction(transaction) + blockNumber: await this.addTransaction(transaction) }); } catch (error) { @@ -169,19 +159,19 @@ export default class Blockchain { throw new Error("Duplicate transaction"); } } - addNode(url) { - return this.nodes.add(url); - } async replaceChain(newChain) { - try { - await this.chain.replaceChain(newChain); - this.wallet.reCalculateWallet(await this.chain.getAll()); - } - catch (error) { - this.database.clear(); - throw error; + await this.database.clear(); + const actions = []; + for (const block of newChain) { + const putAction = await this.chain.pushAction(block); + actions.push(putAction); + actions.push(...await this.wallet.processTrxActionList(block.transactions)); + this.database.batch(actions); } return this.chain.getAll(); } + addNode(url) { + return this.nodes.add(url); + } } //# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/dist/library/main.js.map b/dist/library/main.js.map index 362bdb4..914a674 100644 --- a/dist/library/main.js.map +++ b/dist/library/main.js.map @@ -1 +1 @@ -{"version":3,"file":"main.js","sourceR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end of file diff --git a/dist/library/utils.js b/dist/library/utils.js index e26b6e1..a83c7c8 100644 --- a/dist/library/utils.js +++ b/dist/library/utils.js @@ -14,9 +14,6 @@ export function computeHash(data) { .update(stringData) .digest("hex"); } -export function objectify(data) { - return JSON.parse(JSON.stringify(data)); -} export function initJsonFile(filePath, defaultData = {}) { const folderPath = path.dirname(filePath); if (!existsSync(folderPath)) { @@ -66,12 +63,6 @@ export function createFolder(folderPath) { export function generateUuid() { return uuidv4(); } -export function removePublicKeyHeaders(publicKey) { - const headerRegex = /^-----BEGIN PUBLIC KEY-----\r?\n/; - const footerRegex = /\n-----END PUBLIC KEY-----/; - const strippedPublicKey = publicKey.replace(headerRegex, ""); - return strippedPublicKey.replace(footerRegex, ""); -} export function generateFilePath(folderPath, ...params) { return path.join(folderPath, ...params); } diff --git a/dist/library/utils.js.map b/dist/library/utils.js.map index aa98eb2..489f3d1 100644 --- a/dist/library/utils.js.map +++ b/dist/library/utils.js.map @@ -1 +1 @@ -{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/library/utils.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC5F,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,MAAM,UAAU,kBAAkB,CAAG,eAAkC;IAEtE,OAAO,eAAe,CAAC,MAAM,CAAE,CAAE,QAAQ,EAAE,WAAW,EAAG,EAAE;QAE1D,OAAO,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC;IACnC,CAAC,EAAE,CAAC,CAAE,CAAC;AACR,CAAC;AAED,MAAM,UAAU,WAAW,CAAG,IAAY;IAEzC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAE,IAAI,CAAE,CAA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QACA,OAAO,CAAC,IAAI,CAAE,UAAU,UAAU,iBAAiB,CAAE,CAAC;QACtD,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED,MAAM,UAAU,YAAY;IAE3B,OAAO,MAAM,EAAE,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAG,UAAkB,EAAE,GAAG,MAAgB;IAEzE,OAAO,IAAI,CAAC,IAAI,CAAE,UAAU,EAAE,GAAG,MAAM,CAAE,CAAC;AAC3C,CAAC"} \ No newline at end of file diff --git a/dist/library/wallet.js b/dist/library/wallet.js index 89cff4a..ff8a5e9 100644 --- a/dist/library/wallet.js +++ b/dist/library/wallet.js @@ -1,34 +1,40 @@ import crypto from "crypto"; +import _ from "lodash"; import Transaction from "./transaction.js"; -import { initJsonFile, updateFile } from "./utils.js"; +import { isLevelNotFoundError } from "../guards.js"; class Wallet { // eslint-disable-next-line @typescript-eslint/no-explicit-any - wallet; + db; + sublevel; constructor(leveldb) { - this.wallet = leveldb.sublevel("wallet", { valueEncoding: "json" }); + this.sublevel = "wallet"; + this.db = leveldb.sublevel(this.sublevel, { valueEncoding: "json" }); } - get allData() { - return this.wallet; + async allWallets() { + const result = await this.db.iterator().all(); + return _.fromPairs(result); } - performTransactions(transactionList) { + async processTrxActionList(transactionList) { + const actionList = []; for (const tmpTrx of transactionList) { const trx = new Transaction(tmpTrx); if (trx.isCoinBase()) { - this.addBalance(trx.to, trx.amount); + const action = await this.addBalance(trx.to, trx.amount); + actionList.push(action); continue; } if (trx.from !== null) { - this.minusBalance(trx.from, trx.amount + trx.fee); - this.incrementTN(trx.from); + const action = await this.minusBalance(trx.from, trx.amount + trx.fee); + actionList.push(action); } - this.addBalance(trx.to, trx.amount); + const action = await this.addBalance(trx.to, trx.amount); + actionList.push(action); } - this.wallet.blockNumber++; - this.updateDB(); - return transactionList; + return actionList; } - cleanupTransactions(transactions) { + async cleanupTransactions(transactions) { const newTransactions = []; + const wallets = await this.allWallets(); for (const tmpTrx of transactions) { try { const trx = new Transaction(tmpTrx); @@ -37,75 +43,104 @@ class Wallet { continue; } if (trx.from !== null) { - if (trx.transaction_number <= this.transactionNumber(trx.from)) { + const userWallet = await this.getBalance(trx.from); + if (trx.transaction_number <= userWallet.transaction_number) { console.warn("Dropping transaction with transaction number less than wallet transaction number"); continue; } - this.minusBalance(trx.from, trx.amount + trx.fee); - this.incrementTN(trx.from); + minusBalance(trx.from, trx.amount + trx.fee); } - this.addBalance(trx.to, trx.amount); + await addBalance(trx.to, trx.amount); newTransactions.push(trx.data); } catch (error) { console.error(error); } } - this.reloadDB(); return newTransactions; + function minusBalance(address, amount) { + if (!wallets[address]) { + wallets[address] = { + balance: 0, + transaction_number: 0 + }; + } + if (wallets[address].balance < amount) { + throw new Error("Insufficient balance", { cause: { address, amount } }); + } + wallets[address].balance -= amount; + wallets[address].transaction_number++; + } + function addBalance(address, amount) { + if (!wallets[address]) { + wallets[address] = { + balance: 0, + transaction_number: 0 + }; + } + wallets[address].balance += amount; + } } - incrementTN(address) { - this.validateAddress(address); - return ++this.wallet.list[address].transaction_number; - } - getBalance(address) { - return this.wallet.list[address].balance; - } - addBalance(address, amount) { - this.validateAddress(address); - return this.wallet.list[address].balance += amount; - } - minusBalance(address, amount) { - this.validateAddress(address); - if (this.getBalance(address) < amount) { + async getBalance(address) { + const wallet = await this.db.get(address.toString()); + return wallet; + } + async addBalance(address, amount) { + await this.validateAddress(address); + const wallet = await this.getBalance(address); + wallet.balance += amount; + const action = { + type: "put", + sublevel: this.sublevel, + key: address, + value: wallet + }; + return action; + } + async minusBalance(address, amount) { + await this.validateAddress(address); + const wallet = await this.getBalance(address); + if (wallet.balance < amount) { throw new Error("Insufficient balance", { cause: { address, amount } }); } - return this.wallet.list[address].balance -= amount; - } - transactionNumber(address) { - return this.wallet.list[address].transaction_number; - } - validateAddress(address) { - if (!this.wallet.list[address]) { - this.wallet.list[address] = { balance: 0, transaction_number: 0 }; + wallet.balance -= amount; + wallet.transaction_number++; + const action = { + type: "put", + sublevel: this.sublevel, + key: address, + value: wallet + }; + return action; + } + async validateAddress(address) { + try { + await this.getBalance(address); } - } - isTransactionNumberCorrect(address, transaction_number) { - if (transaction_number <= this.transactionNumber(address)) { - throw new Error("Invalid transaction number", { cause: { address, transaction_number } }); + catch (error) { + if (isLevelNotFoundError(error) && error.code === "LEVEL_NOT_FOUND") { + await this.db.put(address, { balance: 0, transaction_number: 0 }); + } + else { + console.log(error); + throw error; + } } } - checkFinalDBState(proposedBlock) { - if (this.wallet.blockNumber !== proposedBlock.index) { - throw new Error("Block number mismatch", { cause: { proposedBlock, wallet: this.wallet } }); + async isTransactionNumberCorrect(address, transaction_number) { + const wallet = await this.getBalance(address); + if (transaction_number <= wallet.transaction_number) { + throw new Error("Invalid transaction number", { cause: { address, transaction_number } }); } - return true; } reCalculateWallet(chain) { this.wipe(); for (const block of chain) { - this.performTransactions(block.transactions); + this.processTrxActionList(block.transactions); } } - reloadDB() { - this.wallet = initJsonFile(this.filePath, { blockNumber: 0, list: {} }); - } - wipe() { - this.wallet = { blockNumber: -1, list: {} }; - this.updateDB(); - } - updateDB() { - updateFile(this.filePath, this.wallet); + async wipe() { + await this.db.clear(); } static generateKeyPair() { const keyPair = crypto.generateKeyPairSync("ed25519"); diff --git a/dist/library/wallet.js.map b/dist/library/wallet.js.map index 1d9d514..9e3b998 100644 --- a/dist/library/wallet.js.map +++ b/dist/library/wallet.js.map @@ -1 +1 @@ -{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/library/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,MAAM;IAEX,8DAA8D;IACvD,MAAM,CAAM;IACnB,YAAc,OAAiC;QAE9C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAqB,QAAQ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AK,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;IAED,KAAK,CAAC,0BAA0B,CAAG,OAAe,EAAE,kBAA0B;QAE7E,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAE,OAAO,CAAE,CAAC;QAChD,IAAK,kBAAkB,IAAI,MAAM,CAAC,kBAAkB,EACpD,CAAC;YACA,MAAM,IAAI,KAAK,CAAE,4BAA4B,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,kBAAkB,EAAE,EAAE,CAAC,CAAC;QAC5F,CAAC;IACF,CAAC;IAED,iBAAiB,CAAG,KAAkB;QAErC,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,KAAM,MAAM,KAAK,IAAI,KAAK,EAC1B,CAAC;YACA,IAAI,CAAC,oBAAoB,CAAE,KAAK,CAAC,YAAY,CAAE,CAAC;QACjD,CAAC;IACF,CAAC;IAED,KAAK,CAAC,IAAI;QAET,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,eAAe;QAErB,MAAM,OAAO,GAAG,MAAM,CAAC,mBAAmB,CAAE,SAAS,CAAE,CAAC;QACxD,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;QACvF,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC1F,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;IAClC,CAAC;CACD;AAED,eAAe,MAAM,CAAC"} \ No newline at end of file diff --git a/dist/test/a.js b/dist/test/a.js index a1ad51e..c211484 100644 --- a/dist/test/a.js +++ b/dist/test/a.js @@ -11,9 +11,9 @@ await db.put(9, { x: 1234 }); await db.put(1, { x: 1234 }); await db.put(12, { x: 1234 }); await db.put(-1, { x: 1234 }); -for await (const [k] of db.iterator({ reverse: true })) { - console.log(k); -} +// 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" }); @@ -22,7 +22,7 @@ for await (const [k] of db.iterator({ reverse: true })) { // console.log( res ); // // It works the same for sublevels // const abc = db.sublevel( "abc" ); -await db.clear(); +// 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") }); diff --git a/dist/test/a.js.map b/dist/test/a.js.map index cada92d..60302d4 100644 --- a/dist/test/a.js.map +++ b/dist/test/a.js.map @@ -1 +1 @@ -{"version":3,"file":"a.js","sourceRoot":"","sources":["../../src/test/a.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,+DAA+D;AAC/D,gEAAgE;AAChE,MAAM,EAAE,GAAG,IAAI,KAAK,CAAe,MAAM,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,CAAC;AAEtE,4CAA4C;AAC5C,MAAM,EAAE,CAAC,GAAG,CAAE,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9B,MAAM,EAAE,CAAC,GAAG,CAAE,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9B,MAAM,EAAE,CAAC,GAAG,CAAE,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9B,MAAM,EAAE,CAAC,GAAG,CAAE,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9B,MAAM,EAAE,CAAC,GAAG,CAAE,CAAC,EAAE,EAAE,CAAC,EA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ockchain.test.js +++ b/dist/test/blockchain.test.js @@ -20,12 +20,12 @@ describe("Blockchain Test Suite", () => { afterAll(() => { cleanTestDB(); }); - test("mining first block", () => { - const newBlock = blockchain.mineNewBlock(); // miner: 200 + test("mining first block", async () => { + const newBlock = await blockchain.mineNewBlock(); // miner: 200 expect(newBlock.index).toBe(1); expect(blockchain.chain.validateChain()).toBe(true); }); - test("Sending a transaction from miner to sender and mining a new block", () => { + test("Sending a transaction from miner to sender and mining a new block", async () => { const transaction1 = new Transaction({ from: minerKeys.publicKey, to: senderKeys.publicKey, @@ -35,12 +35,12 @@ describe("Blockchain Test Suite", () => { signature: null }); transaction1.sign(minerKeys.privateKey); - blockchain.addTransaction(transaction1.data); - const blockWithTransaction1 = blockchain.mineNewBlock(); // miner: 250, miner receives his own trx fee + await blockchain.addTransaction(transaction1.data); + const blockWithTransaction1 = await blockchain.mineNewBlock(); // miner: 250, miner receives his own trx fee expect(blockWithTransaction1.transactions.length).toBe(2); // including coinbase transaction expect(blockchain.chain.validateChain()).toBe(true); }); - test("Sending a transaction from sender to receiver and mining a new block", () => { + test("Sending a transaction from sender to receiver and mining a new block", async () => { const transaction2 = new Transaction({ from: senderKeys.publicKey, to: receiverKeys.publicKey, @@ -50,12 +50,10 @@ describe("Blockchain Test Suite", () => { signature: null }); transaction2.sign(senderKeys.privateKey); - blockchain.addTransaction(transaction2.data); - const blockWithTransaction2 = blockchain.mineNewBlock(); // miner: 351 + await blockchain.addTransaction(transaction2.data); + const blockWithTransaction2 = await blockchain.mineNewBlock(); // miner: 351 expect(blockWithTransaction2.transactions.length).toBe(2); // including coinbase transaction expect(blockchain.chain.validateChain()).toBe(true); - expect(blockchain.wallet.checkFinalDBState(blockWithTransaction2)).toBe(true); - expect(blockchain.chain.checkFinalDBState(blockWithTransaction2)).toBe(true); }); test("Validating the final state of the blockchain", () => { const finalStateValid = blockchain.chain.validateChain(); @@ -69,7 +67,7 @@ describe("Blockchain Test Suite", () => { expect(receiverWalletBalance).toBe(25); // received 25 expect(minerWalletBalance).toBe(351); // 100 + 100 + 50 + 1 + 100 }); - test("Handling transaction with insufficient funds", () => { + test("Handling transaction with insufficient funds", async () => { const transaction3 = new Transaction({ from: senderKeys.publicKey, to: receiverKeys.publicKey, @@ -80,7 +78,7 @@ describe("Blockchain Test Suite", () => { }); transaction3.sign(senderKeys.privateKey); try { - blockchain.addTransaction(transaction3.data); + await blockchain.addTransaction(transaction3.data); } catch (e) { if (e instanceof Error) { @@ -91,7 +89,7 @@ describe("Blockchain Test Suite", () => { } } }); - test("Handling duplicate transaction number", () => { + test("Handling duplicate transaction number", async () => { const transaction4 = new Transaction({ from: senderKeys.publicKey, to: receiverKeys.publicKey, @@ -102,7 +100,7 @@ describe("Blockchain Test Suite", () => { }); transaction4.sign(senderKeys.privateKey); try { - blockchain.addTransaction(transaction4.data); + await blockchain.addTransaction(transaction4.data); } catch (e) { if (e instanceof Error) { @@ -113,7 +111,7 @@ describe("Blockchain Test Suite", () => { } } }); - test("Handling invalid signature", () => { + test("Handling invalid signature", async () => { const transaction5 = new Transaction({ from: senderKeys.publicKey, to: receiverKeys.publicKey, @@ -123,7 +121,7 @@ describe("Blockchain Test Suite", () => { signature: "invalid-signature" }); try { - blockchain.addTransaction(transaction5.data); + await blockchain.addTransaction(transaction5.data); } catch (e) { if (e instanceof Error) { @@ -134,7 +132,7 @@ describe("Blockchain Test Suite", () => { } } }); - test("Handling transaction with zero amount", () => { + test("Handling transaction with zero amount", async () => { const transaction6 = new Transaction({ from: senderKeys.publicKey, to: receiverKeys.publicKey, @@ -145,7 +143,7 @@ describe("Blockchain Test Suite", () => { }); transaction6.sign(senderKeys.privateKey); try { - blockchain.addTransaction(transaction6.data); + await blockchain.addTransaction(transaction6.data); } catch (e) { if (e instanceof Error) { @@ -156,7 +154,7 @@ describe("Blockchain Test Suite", () => { } } }); - test("Handling transaction with negative amount", () => { + test("Handling transaction with negative amount", async () => { const transaction7 = new Transaction({ from: senderKeys.publicKey, to: receiverKeys.publicKey, @@ -167,7 +165,7 @@ describe("Blockchain Test Suite", () => { }); transaction7.sign(senderKeys.privateKey); try { - blockchain.addTransaction(transaction7.data); + await blockchain.addTransaction(transaction7.data); } catch (e) { if (e instanceof Error) { diff --git a/dist/test/blockchain.test.js.map b/dist/test/blockchain.test.js.map index d4ab187..3fd69a1 100644 --- a/dist/test/blockchain.test.js.map +++ b/dist/test/blockchain.test.js.map @@ -1 +1 @@ -{"version":3,"file":"blockchain.test.js","sourceRoot":"","sources":["../../src/test/blockchain.test.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAC1C,OAAO,WAAW,MAAM,2BAA2B,CAAC;AACpD,OAAO,YAAY,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAErE,MAAM,YAAY,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC;AAEtD,QAAQ,CAAE,uBAAuB,EAAE,GAAG,EAAE;IAEvC,IAAI,UAAsB,CAAC;IAC3B,IAAI,UAAmB,CAAC;IACxB,IAAI,YAAqB,CAAC;IAC1B,IAAI,SAAkB,CAAC;IAEvB,SAAS,CAAE,GAAG,EAAE;QAEf,WAAW,EAAE,CAAC;QACd,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;QACrC,UAAU,GAAG,oBAAoB,CAAE,SAAS,CAAC,SAAS,CAAE,CAAC,CAAC,aAAa;QACvE,UAAU,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;QACtC,YAAY,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAE,GAAG,EAAE;QAEd,WAAW,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;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MAAM,CAAE,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;AACF,CAAC;AAED,SAAS,oBAAoB,CAAG,kBAA0B;IAEzD,MAAM,SAAS,GAAG,IAAI,YAAY,EAAE,CAAC;IACrC,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC;QACjC,MAAM,EAAE,YAAY;QACpB,KAAK,EAAE;YACN,IAAI,EAAE,CAAE,uBAAuB,CAAE;YACjC,OAAO,EAAE,uBAAuB;SAChC;QACD,SAAS,EAAE,YAAY;QACvB,cAAc,EAAE,kBAAkB;QAClC,SAAS;KACT,CAAC,CAAC;IACH,UAAU,CAAC,IAAI,EAAE,CAAC;IAClB,OAAO,UAAU,CAAC;AACnB,CAAC"} \ No newline at end of file +{"version":3,"file":"blockchain.test.js","sourceRoot":"","sources":["../../src/test/blockchain.test.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAC1C,OAAO,WAAW,MAAM,2BAA2B,CAAC;AACpD,OAAO,YAAY,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAErE,MAAM,YAAY,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC;AAEtD,QAAQ,CAAE,uBAAuB,EAAE,GAAG,EAAE;IAEvC,IAAI,UAAsB,CAAC;IAC3B,IAAI,UAAmB,CAAC;IACxB,IAAI,YAAqB,CAAC;IAC1B,IAAI,SAAkB,CAAC;IAEvB,SAAS,CAAE,GAAG,EAAE;QAEf,WAAW,EAAE,CAAC;QACd,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;QACrC,UAAU,GAAG,oBAAoB,CAAE,SAAS,CAAC,SAAS,C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C,CAAC;AAEH,SAAS,WAAW;IAEnB,IAAK,EAAE,CAAC,UAAU,CAAE,YAAY,CAAE,EAClC,CAAC;QACA,EAAE,CAAC,MAAM,CAAE,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;AACF,CAAC;AAED,SAAS,oBAAoB,CAAG,kBAA0B;IAEzD,MAAM,SAAS,GAAG,IAAI,YAAY,EAAE,CAAC;IACrC,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC;QACjC,MAAM,EAAE,YAAY;QACpB,KAAK,EAAE;YACN,IAAI,EAAE,CAAE,uBAAuB,CAAE;YACjC,OAAO,EAAE,uBAAuB;SAChC;QACD,SAAS,EAAE,YAAY;QACvB,cAAc,EAAE,kBAAkB;QAClC,SAAS;KACT,CAAC,CAAC;IACH,UAAU,CAAC,IAAI,EAAE,CAAC;IAClB,OAAO,UAAU,CAAC;AACnB,CAAC"} \ No newline at end of file diff --git a/dist/test/init.js b/dist/test/init.js index d88053d..f39f0f7 100644 --- a/dist/test/init.js +++ b/dist/test/init.js @@ -18,8 +18,8 @@ const blockchain = new Blockchain({ minerPublicKey: minerKeys.publicKey, consensus: new Consensus() }); -blockchain.init(); -blockchain.mineNewBlock(); +await blockchain.init(); +await blockchain.mineNewBlock(); const trx = new Transaction({ from: minerKeys.publicKey, to: userKeys.publicKey, @@ -28,9 +28,9 @@ const trx = new Transaction({ transaction_number: 1 }); trx.sign(minerKeys.privateKey); -const blockNumber = blockchain.addTransaction(trx.data); -blockchain.mineNewBlock(); -console.log("Mined block :", blockNumber, blockchain.chain.latestBlock); +const blockNumber = await blockchain.addTransaction(trx.data); +await blockchain.mineNewBlock(); +console.log("Mined block :", blockNumber, await blockchain.chain.latestBlock()); const trx2 = new Transaction({ from: userKeys.publicKey, to: "user3", @@ -39,9 +39,9 @@ const trx2 = new Transaction({ transaction_number: 1 }); trx2.sign(userKeys.privateKey); -blockchain.addTransaction(trx2.data); -blockchain.mineNewBlock(); -console.log("Latest Block :", blockchain.chain.latestBlock); -console.log("Wallets : ", blockchain.wallet); -console.log("chain validation:", blockchain.chain.validateChain()); +await blockchain.addTransaction(trx2.data); +await blockchain.mineNewBlock(); +console.log("Latest Block :", await blockchain.chain.latestBlock()); +console.log("Wallets : ", await blockchain.wallet.allWallets()); +console.log("chain validation:", await blockchain.chain.validateChain()); //# sourceMappingURL=init.js.map \ No newline at end of file diff --git a/dist/test/init.js.map b/dist/test/init.js.map index 5a0aa51..95c35f4 100644 --- a/dist/test/init.js.map +++ b/dist/test/init.js.map @@ -1 +1 @@ -{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/test/init.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,OAAO,WAAW,MAAM,2BAA2B,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAE1C,YAAY,CAAE,YAAY,CAAE,CAAC;AAC7B,UAAU,CAAE,0BAA0B,CAAE,CAAC;AACzC,UAAU,CAAE,yBAAyB,CAAE,CAAC;AAExC,MAAM,QAAQ,GAAG,YAAY,CAAE,yBAAyB,EAAE,MAAM,CAAC,eAAe,EAAE,CAAE,CAAC;AACrF,MAAM,SAAS,GAAG,YAAY,CAAE,0BAA0B,EAAE,MAAM,CAAC,eAAe,EAAE,CAAE,CAAC;AACvF,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC;IACjC,MAAM,EAAE,cAAc;IACtB,KAAK,EAAE;QACN,IAAI,EAAE,CAAE,uBAAuB,CAAE;QACjC,OAAO,EAAE,uBAAuB;KAChC;IACD,SAAS,EAAE,WAAW;IACtB,cAAc,EAAE,SAAS,CAAC,SAAS;IACnC,SAAS,EAAE,IAAI,SAAS,EAAE;CAC1B,CAAC,CAAC;AACH,UAAU,CAAC,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C,YAAY,EAAE,CAAC;AAChC,OAAO,CAAC,GAAG,CAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC,KAAK,CAAC,WAAW,EAAE,CAAE,CAAC;AAElF,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC;IAC5B,IAAI,EAAE,QAAQ,CAAC,SAAS;IACxB,EAAE,EAAE,OAAO;IACX,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,GAAG;IACR,kBAAkB,EAAE,CAAC;CACrB,CAAC,CAAC;AACH,IAAI,CAAC,IAAI,CAAE,QAAQ,CAAC,UAAU,CAAE,CAAC;AAEjC,MAAM,UAAU,CAAC,cAAc,CAAE,IAAI,CAAC,IAAI,CAAE,CAAC;AAC7C,MAAM,UAAU,CAAC,YAAY,EAAE,CAAC;AAEhC,OAAO,CAAC,GAAG,CAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC,KAAK,CAAC,WAAW,EAAE,CAAE,CAAC;AACtE,OAAO,CAAC,GAAG,CAAE,YAAY,EAAE,MAAM,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAE,CAAC;AAClE,OAAO,CAAC,GAAG,CAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC,KAAK,CAAC,aAAa,EAAE,CAAE,CAAC"} \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js index 9ad5674..381dcf4 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -81,7 +81,6 @@ export default [ ], "@typescript-eslint/prefer-nullish-coalescing": "off", "curly": [ "error", "multi-line" ], - "no-unused-vars": "warn", "one-var": [ "error", "never" ], "arrow-body-style": [ "error", "always" ], "no-template-curly-in-string": [ "error" ], diff --git a/package.json b/package.json index 28f29df..86eca74 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "goodchain", - "version": "2.0.2", + "version": "3.0.0", "description": "GoodChain: Blockchain for Everyone", "main": "index.js", "type": "module", diff --git a/src/global.d.ts b/src/global.d.ts index a2b9c62..9db1cd5 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -76,4 +76,14 @@ interface SimpleError message?: string; stack?: string; [key: string]: SimpleError; -} \ No newline at end of file +} + +interface LevelNotFoundError +{ + code: string; + notFound: boolean; + status: number; + message: string; + stack: string; + [key: string]: SimpleError; +} diff --git a/src/guards.ts b/src/guards.ts index 8567a63..87117dc 100644 --- a/src/guards.ts +++ b/src/guards.ts @@ -8,3 +8,14 @@ export function isErrorWithStds ( error: unknown ): error is ErrorWithStdsOutErr "status" in error ); } + +export function isLevelNotFoundError ( error: unknown ): error is LevelNotFoundError +{ + return ( + typeof error === "object" && + error !== null && + "code" in error && + "notFound" in error && + "status" in error + ); +} \ No newline at end of file diff --git a/src/library/main.ts b/src/library/main.ts index 2f2747a..cf419c5 100644 --- a/src/library/main.ts +++ b/src/library/main.ts @@ -147,6 +147,10 @@ export default class Blockchain { return b.fee - a.fee; }); + if ( trx.isCoinBase() ) + { + return 0; + } return await this.chain.length() + 1; } diff --git a/src/library/wallet.ts b/src/library/wallet.ts index 4060556..1a8167f 100644 --- a/src/library/wallet.ts +++ b/src/library/wallet.ts @@ -2,6 +2,7 @@ import crypto from "crypto"; import { Level } from "level"; import _ from "lodash"; import Transaction from "./transaction.js"; +import { isLevelNotFoundError } from "../guards.js"; class Wallet { @@ -148,9 +149,21 @@ class Wallet async validateAddress ( address: string ): Promise { - if ( !await this.getBalance( address ) ) + try { - await this.db.put( address, { balance: 0, transaction_number: 0 }); + await this.getBalance( address ); + } + catch ( error: unknown ) + { + if ( isLevelNotFoundError( error ) && error.code === "LEVEL_NOT_FOUND" ) + { + await this.db.put( address, { balance: 0, transaction_number: 0 }); + } + else + { + console.log( error ); + throw error; + } } } diff --git a/src/test/a.ts b/src/test/a.ts new file mode 100644 index 0000000..681bc72 --- /dev/null +++ b/src/test/a.ts @@ -0,0 +1,44 @@ +/* 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 ); + + + diff --git a/src/test/blockchain.test.ts b/src/test/blockchain.test.ts index 3e3b663..c1ff37b 100644 --- a/src/test/blockchain.test.ts +++ b/src/test/blockchain.test.ts @@ -28,9 +28,9 @@ describe( "Blockchain Test Suite", () => cleanTestDB(); }); - test( "mining first block", () => + test( "mining first block", async () => { - const newBlock = blockchain.mineNewBlock(); // miner: 200 + const newBlock = await blockchain.mineNewBlock(); // miner: 200 expect( newBlock.index ).toBe( 1 ); expect( blockchain.chain.validateChain() ).toBe( true ); }); @@ -48,7 +48,7 @@ describe( "Blockchain Test Suite", () => transaction1.sign( minerKeys.privateKey ); await blockchain.addTransaction( transaction1.data ); - const blockWithTransaction1 = blockchain.mineNewBlock(); // miner: 250, miner receives his own trx fee + const blockWithTransaction1 = await blockchain.mineNewBlock(); // miner: 250, miner receives his own trx fee expect( blockWithTransaction1.transactions.length ).toBe( 2 ); // including coinbase transaction expect( blockchain.chain.validateChain() ).toBe( true ); }); @@ -66,7 +66,7 @@ describe( "Blockchain Test Suite", () => transaction2.sign( senderKeys.privateKey ); await blockchain.addTransaction( transaction2.data ); - const blockWithTransaction2 = blockchain.mineNewBlock(); // miner: 351 + const blockWithTransaction2 = await blockchain.mineNewBlock(); // miner: 351 expect( blockWithTransaction2.transactions.length ).toBe( 2 ); // including coinbase transaction expect( blockchain.chain.validateChain() ).toBe( true ); }); diff --git a/src/test/init.ts b/src/test/init.ts index 468dfe8..b4df2bc 100644 --- a/src/test/init.ts +++ b/src/test/init.ts @@ -21,8 +21,8 @@ const blockchain = new Blockchain({ minerPublicKey: minerKeys.publicKey, consensus: new Consensus() }); -blockchain.init(); -blockchain.mineNewBlock(); +await blockchain.init(); +await blockchain.mineNewBlock(); const trx = new Transaction({ from: minerKeys.publicKey, @@ -34,8 +34,8 @@ const trx = new Transaction({ trx.sign( minerKeys.privateKey ); const blockNumber = await blockchain.addTransaction( trx.data ); -blockchain.mineNewBlock(); -console.log( "Mined block :", blockNumber, blockchain.chain.latestBlock ); +await blockchain.mineNewBlock(); +console.log( "Mined block :", blockNumber, await blockchain.chain.latestBlock() ); const trx2 = new Transaction({ from: userKeys.publicKey,