From f243dd1dee4d4340dc1d365d7e7714359fe08324 Mon Sep 17 00:00:00 2001 From: Neil Campbell Date: Fri, 12 Jul 2024 18:09:30 +0800 Subject: [PATCH] chore: prevent participationUpdates and upgradeVote being an empty object (#92) * chore: prevent participationUpdates and upgradeVote being an empty object --- src/transform.ts | 26 ++++++++++++------- tests/scenarios/transform-complex-txn.spec.ts | 9 ------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/transform.ts b/src/transform.ts index a00ae9f..2c3368a 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -635,15 +635,23 @@ export function blockDataToBlockMetadata(blockData: BlockData): BlockMetadata { txnCounter: block.tc, transactionsRoot: block.txn ? Buffer.from(block.txn).toString('base64') : 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=', transactionsRootSha256: block.txn256, - upgradeVote: { - upgradeApprove: block.upgradeyes, - upgradeDelay: block.upgradedelay, - upgradePropose: block.upgradeprop, - }, - participationUpdates: { - absentParticipationAccounts: block.partupdabs?.map((addr) => algosdk.encodeAddress(addr)), - expiredParticipationAccounts: block.partupdrmv?.map((addr) => algosdk.encodeAddress(addr)), - }, + ...(block.upgradeyes !== undefined || block.upgradedelay !== undefined || block.upgradeprop !== undefined + ? { + upgradeVote: { + upgradeApprove: block.upgradeyes, + upgradeDelay: block.upgradedelay, + upgradePropose: block.upgradeprop, + }, + } + : undefined), + ...(block.partupdabs !== undefined || block.partupdrmv !== undefined + ? { + participationUpdates: { + absentParticipationAccounts: block.partupdabs?.map((addr) => algosdk.encodeAddress(addr)), + expiredParticipationAccounts: block.partupdrmv?.map((addr) => algosdk.encodeAddress(addr)), + }, + } + : undefined), stateProofTracking: block.spt ? Object.entries(block.spt).map(([key, value]) => ({ nextRound: value.n, diff --git a/tests/scenarios/transform-complex-txn.spec.ts b/tests/scenarios/transform-complex-txn.spec.ts index db27cf7..f71b536 100644 --- a/tests/scenarios/transform-complex-txn.spec.ts +++ b/tests/scenarios/transform-complex-txn.spec.ts @@ -301,10 +301,6 @@ describe('Complex transaction with many nested inner transactions', () => { "genesisId": "mainnet-v1.0", "hash": "EOq+HX242/G/ADonU6q5lfimxX7twuFKEwtG4rDt+kI=", "parentTransactionCount": 55, - "participationUpdates": { - "absentParticipationAccounts": undefined, - "expiredParticipationAccounts": undefined, - }, "previousBlockHash": "8ReLxqOPxmuKuBfACtllRRr13n2E2r01f8wXt3vFYW0=", "rewards": { "feeSink": "Y76M3MSY6DKBRHBL7C3NNDXGS5IIMQVQVUAB6MP4XEMMGVF2QWNPL226CA", @@ -335,11 +331,6 @@ describe('Complex transaction with many nested inner transactions', () => { "nextProtocolSwitchOn": 35275315, "nextProtocolVoteBefore": 35125315, }, - "upgradeVote": { - "upgradeApprove": undefined, - "upgradeDelay": undefined, - "upgradePropose": undefined, - }, }, ] `)