forked from Qortal/qortal
Allow zero fee transactions if the fee is zero in blockchain.json
Until now it wasn't possible to set up a chain with zero transaction fees due to a hardcoded zero check in Payment.isValid(), and a divide by zero error in Transaction.hasMinimumFeePerByte()
This commit is contained in:
parent
4b1de108d1
commit
49eddc9da5
@ -40,8 +40,9 @@ public class Payment {
|
|||||||
public ValidationResult isValid(byte[] senderPublicKey, List<PaymentData> payments, long fee, boolean isZeroAmountValid) throws DataException {
|
public ValidationResult isValid(byte[] senderPublicKey, List<PaymentData> payments, long fee, boolean isZeroAmountValid) throws DataException {
|
||||||
AssetRepository assetRepository = this.repository.getAssetRepository();
|
AssetRepository assetRepository = this.repository.getAssetRepository();
|
||||||
|
|
||||||
// Check fee is positive
|
// Check fee is positive or zero
|
||||||
if (fee <= 0)
|
// We have already checked that the fee is correct in the Transaction superclass
|
||||||
|
if (fee < 0)
|
||||||
return ValidationResult.NEGATIVE_FEE;
|
return ValidationResult.NEGATIVE_FEE;
|
||||||
|
|
||||||
// Total up payment amounts by assetId
|
// Total up payment amounts by assetId
|
||||||
|
@ -348,6 +348,10 @@ public abstract class Transaction {
|
|||||||
long unitFee = BlockChain.getInstance().getUnitFee();
|
long unitFee = BlockChain.getInstance().getUnitFee();
|
||||||
int maxBytePerUnitFee = BlockChain.getInstance().getMaxBytesPerUnitFee();
|
int maxBytePerUnitFee = BlockChain.getInstance().getMaxBytesPerUnitFee();
|
||||||
|
|
||||||
|
// If the unit fee is zero, any fee is enough to cover the byte-length of the transaction
|
||||||
|
if (unitFee == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return this.feePerByte() >= maxBytePerUnitFee / unitFee;
|
return this.feePerByte() >= maxBytePerUnitFee / unitFee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user