Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 42x 42x 42x 42x 42x 42x 3x 3x 6x 6x 2x 6x 3x 2x 42x 1x 3x | import { Cardano, getCertificatesByType } from '@cardano-sdk/core';
import { Observable, combineLatest, distinctUntilChanged, map } from 'rxjs';
import { isNotNil } from '@cardano-sdk/util';
import { transactionsEquals } from '../util/equals';
import last from 'lodash/last.js';
export const lastStakeKeyCertOfType = <K extends Cardano.RegAndDeregCertificateTypes>(
transactionsCertificates: Cardano.Certificate[][],
certTypes: readonly K[],
rewardAccount?: Cardano.RewardAccount
) => {
const stakeKeyHash = rewardAccount ? Cardano.RewardAccount.toHash(rewardAccount) : null;
const lastRegOrDereg = last(
transactionsCertificates
.map((certificates) => {
const allStakeKeyCertificates = Cardano.stakeKeyCertificates(certificates);
const addressStakeKeyCertificates = stakeKeyHash
? allStakeKeyCertificates.filter(({ stakeCredential: certStakeCred }) => stakeKeyHash === certStakeCred.hash)
: allStakeKeyCertificates;
return last(addressStakeKeyCertificates);
})
.filter(isNotNil)
);
if (lastRegOrDereg && Cardano.isCertType(lastRegOrDereg, certTypes)) {
return lastRegOrDereg;
}
};
export const transactionsWithCertificates = (
transactions$: Observable<Cardano.HydratedTx[]>,
rewardAccounts$: Observable<Cardano.RewardAccount[]>,
certificateTypes: Cardano.CertificateType[]
) =>
combineLatest([transactions$, rewardAccounts$]).pipe(
map(([transactions, rewardAccounts]) =>
transactions.filter((tx) => getCertificatesByType(tx, rewardAccounts, certificateTypes).length > 0)
),
distinctUntilChanged(transactionsEquals)
);
|