validating transaction data bug
I found that validTransactionData method of Blockchain class does not work properly.
Precisely I think that this part is problem
const trueBalance = Wallet.calculateBalance({
chain: this.chain,
address: transaction.input.address
});
if (transaction.input.amount !== trueBalance) {
console.error('Invalid input amount');
return false;
}
Here you are comparing for every transaction's input amount with true balance of its sender. True balance will always be same for one wallet on blockchain but transaction.input.amount can be different for every transaction. So here is the problem that I faced when i tried to broadcast my blockchain to other nodes in the network, they wouldn't accept it becouse they marked it as invalid. validTransactionData always outputs 'Invalid input amount' error. So my fix is - only calculate balance of the wallet from start of blockchain up to this block transaction - this.chain.slice(0,i)
const trueBalance = Wallet.calculateBalance({
chain: this.chain.slice(0,i),
address: transaction.input.address
});
if (transaction.input.amount !== trueBalance) {
console.error('Invalid input amount');
return false;
}
I've tested it and it works perfectly