Skip to content

Commit

Permalink
fixup! feat: initial projection implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mkazlauskas committed Nov 14, 2022
1 parent 03cfe94 commit b548aec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Expand Up @@ -4,7 +4,7 @@ import { WithRolledBackEvents } from '../withRolledBackEvents';
import { projectorOperator } from '../utils';

export interface CertificatePointer {
blockHeight: Cardano.BlockNo;
slot: Cardano.Slot;
txIndex: number;
certIndex: number;
}
Expand All @@ -23,16 +23,16 @@ export interface WithCertificates {

const blockCertificates = ({
block: {
header: { blockNo },
header: { slot },
body
}
}: RollForwardEvent) =>
body.flatMap(({ body: { certificates = [] } }, txIndex) =>
certificates.map((certificate, certIndex) => ({
certificate,
pointer: {
blockHeight: blockNo,
certIndex,
slot,
txIndex
}
}))
Expand Down
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../../src';
import { createTestScheduler } from '@cardano-sdk/util-dev';

const rollForwardEvent = (blockNo: Cardano.BlockNo, txs: Cardano.Certificate[][]) =>
const rollForwardEvent = (slot: Cardano.Slot, txs: Cardano.Certificate[][]) =>
({
block: {
body: txs.map(
Expand All @@ -18,20 +18,20 @@ const rollForwardEvent = (blockNo: Cardano.BlockNo, txs: Cardano.Certificate[][]
body: { certificates }
} as Cardano.TxAlonzo)
),
header: { blockNo }
header: { slot }
},
eventType: ChainSyncEventType.RollForward
} as RollForwardEvent);

const rollBackwardEvent = (blocks: Cardano.Certificate[][][]) =>
({
eventType: ChainSyncEventType.RollBackward,
rolledBackEvents: blocks.map((txs, blockNo) => ({
rolledBackEvents: blocks.map((txs, slot) => ({
block: {
body: txs.map((certificates) => ({
body: { certificates }
})),
header: { blockNo }
header: { slot }
}
}))
} as RollBackwardEvent<WithRolledBackEvents>);
Expand All @@ -58,24 +58,24 @@ describe('withCertificates', () => {
{
certificate: certificates[0][0],
pointer: {
blockHeight: 1,
certIndex: 0,
slot: 1,
txIndex: 0
}
},
{
certificate: certificates[1][0],
pointer: {
blockHeight: 1,
certIndex: 0,
slot: 1,
txIndex: 1
}
},
{
certificate: certificates[1][1],
pointer: {
blockHeight: 1,
certIndex: 1,
slot: 1,
txIndex: 1
}
}
Expand All @@ -102,24 +102,24 @@ describe('withCertificates', () => {
{
certificate: certificates[1][1],
pointer: {
blockHeight: 0,
certIndex: 1,
slot: 0,
txIndex: 1
}
},
{
certificate: certificates[1][0],
pointer: {
blockHeight: 0,
certIndex: 0,
slot: 0,
txIndex: 1
}
},
{
certificate: certificates[0][0],
pointer: {
blockHeight: 0,
certIndex: 0,
slot: 0,
txIndex: 0
}
}
Expand Down
Expand Up @@ -48,7 +48,7 @@ describe('withStakePools', () => {
} else {
// delete all updates and retirements <= current tip
const belowOrAtTip = ({ source }: WithCertificateSource) =>
evt.tip !== 'origin' && source.blockHeight <= evt.tip.blockNo;
evt.tip !== 'origin' && source.slot <= evt.tip.slot;
for (const [_, stakePool] of stakePools) {
stakePool.updates = stakePool.updates.filter(belowOrAtTip);
stakePool.retirements = stakePool.retirements.filter(belowOrAtTip);
Expand Down

0 comments on commit b548aec

Please sign in to comment.