diff --git a/src/core/block.js b/src/core/block.js index 422f307..177f4ca 100644 --- a/src/core/block.js +++ b/src/core/block.js @@ -62,9 +62,9 @@ class Block { balances[transaction.sender] = senderBalance - transaction.amount - transaction.gas - (transaction.additionalData.contractGas || 0); } else { - balances[transaction.sender] -= transaction.amount + transaction.gas; + balances[transaction.sender] -= transaction.amount + transaction.gas + (transaction.additionalData.contractGas || 0); } - gas += transaction.gas += (transaction.additionalData.contractGas || 0); + gas += transaction.gas + (transaction.additionalData.contractGas || 0); } else { reward = transaction.amount; } diff --git a/src/core/txPool.js b/src/core/txPool.js index a078ad8..808b199 100644 --- a/src/core/txPool.js +++ b/src/core/txPool.js @@ -14,11 +14,11 @@ async function addTransaction(transaction, txPool, stateDB) { // Fetch sender's state object const dataFromSender = await stateDB.get(transaction.sender); // Get sender's balance - let balance = dataFromSender.balance - transaction.amount - transaction.gas; + let balance = dataFromSender.balance - transaction.amount - transaction.gas - (transaction.additionalData.contractGas || 0); txPool.forEach(tx => { if (tx.sender === transaction.sender) { - balance -= tx.amount + tx.gas; + balance -= tx.amount + tx.gas + (tx.additionalData.contractGas || 0); } }); @@ -29,6 +29,8 @@ async function addTransaction(transaction, txPool, stateDB) { ) { txPool.push(transaction); } + + console.log("LOG :: Sent one transaction, added transaction to pool."); } module.exports = addTransaction; diff --git a/src/node/server.js b/src/node/server.js index 146b127..4e48c2b 100644 --- a/src/node/server.js +++ b/src/node/server.js @@ -191,7 +191,7 @@ async function startServer(options) { chainInfo.transactionPool.push(transaction); // Broadcast the transaction - sendTransaction(transaction); + sendMessage(produceMessage("TYPE_CREATE_TRANSACTION", transaction), opened); } break; @@ -419,8 +419,6 @@ async function sendTransaction(transaction) { sendMessage(produceMessage("TYPE_CREATE_TRANSACTION", transaction), opened); await addTransaction(transaction, chainInfo.transactionPool, stateDB); - - console.log("LOG :: Sent one transaction, added transaction to pool."); } function mine(publicKey, ENABLE_LOGGING) {