Skip to content

Commit cc2523d

Browse files
TinyChain --> address error added into validateContent.
1 parent 1ff8706 commit cc2523d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/TinyChain/Block.mjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ class TinyChainBlock {
342342
if (firstValidation) this.validateSig();
343343
}
344344

345+
/** @type {Record<string, string>} */
346+
invalidAddress = {
347+
0: 'NULL',
348+
1: 'UNKNOWN',
349+
};
350+
345351
/**
346352
* Validates the integrity of each transaction inside the block by verifying
347353
* its ECDSA signature using the associated address.
@@ -359,8 +365,11 @@ class TinyChainBlock {
359365
for (const index in dc) {
360366
const data = dc[index];
361367
const sig = sigs[index];
362-
if (data.address === '0')
363-
throw new Error(`Transaction at index "${index}" has an invalid address "0".`);
368+
const invalidValue = this.invalidAddress[data.address];
369+
if (typeof invalidValue === 'string')
370+
throw new Error(
371+
`Transaction at index "${index}" has an invalid address "${data.address}" (${invalidValue}).`,
372+
);
364373
if (
365374
!this.#signer.verifyECDSA(
366375
this.#parser.serializeDeep(data),

src/TinyChain/Instance.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,12 @@ class TinyChainInstance {
839839
return reward > 0n ? reward : 0n;
840840
}
841841

842+
/** @type {Object<string, string>} */
843+
invalidAddress = {
844+
0: 'NULL',
845+
1: 'UNKNOWN',
846+
};
847+
842848
/**
843849
* Validates the transaction content before inclusion in a block.
844850
* This method checks payload format, transfer structure, gas-related constraints,
@@ -888,6 +894,9 @@ class TinyChainInstance {
888894
if (typeof address !== 'string') throw new Error('Address value must be string');
889895
if (typeof addressType !== 'string' || addressType.length === 0)
890896
throw new Error('Invalid address type');
897+
const invalidValue = this.invalidAddress[address];
898+
if (typeof invalidValue === 'string')
899+
throw new Error(`Transaction has an invalid address "${address}" (${invalidValue}).`);
891900

892901
const totalGas = gasUsed + this.getBaseFeePerGas();
893902
if (totalGas > gasLimit)

0 commit comments

Comments
 (0)