forked from input-output-hk/cardano-js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tx-projection): add projection for transaction projected indexed…
… by credentials
- Loading branch information
1 parent
9d68d1b
commit e05dec9
Showing
16 changed files
with
534 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/projection-typeorm/src/entity/Credential.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Column, Entity, Index, ManyToMany, PrimaryColumn } from 'typeorm'; | ||
import { Hash28ByteBase16 } from '@cardano-sdk/crypto'; | ||
import { TransactionEntity } from './Transaction.entity'; | ||
|
||
export enum CredentialType { | ||
PaymentKey = 'payment_key', | ||
PaymentScript = 'payment_script', | ||
StakeKey = 'stake_key', | ||
StakeScript = 'stake_script' | ||
} | ||
|
||
@Entity() | ||
export class CredentialEntity { | ||
@Index() | ||
@PrimaryColumn('varchar') | ||
credentialHash?: Hash28ByteBase16; | ||
|
||
@Column('enum', { enum: CredentialType, nullable: false }) | ||
credentialType?: CredentialType; | ||
|
||
@ManyToMany(() => TransactionEntity, (transaction) => transaction.credentials, { onDelete: 'CASCADE' }) | ||
transactions?: TransactionEntity[]; | ||
} | ||
|
||
export const credentialEntityComparator = (c1: CredentialEntity, c2: CredentialEntity) => | ||
c1.credentialHash === c2.credentialHash && c1.credentialType === c2.credentialType; |
27 changes: 27 additions & 0 deletions
27
packages/projection-typeorm/src/entity/Transaction.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { BlockEntity } from './Block.entity'; | ||
import { Cardano, TxCBOR } from '@cardano-sdk/core'; | ||
import { Column, Entity, Index, JoinColumn, JoinTable, ManyToMany, ManyToOne, PrimaryColumn } from 'typeorm'; | ||
import { CredentialEntity } from './Credential.entity'; | ||
import { OnDeleteCascadeRelationOptions } from './util'; | ||
|
||
@Entity() | ||
export class TransactionEntity { | ||
@Index() | ||
@PrimaryColumn('varchar') | ||
txId?: Cardano.TransactionId; | ||
|
||
@Column('varchar', { nullable: false }) | ||
cbor?: TxCBOR; | ||
|
||
@ManyToOne(() => BlockEntity, OnDeleteCascadeRelationOptions) | ||
@JoinColumn({ name: 'block_id' }) | ||
block?: BlockEntity; | ||
|
||
@ManyToMany(() => CredentialEntity, (credential) => credential.transactions, { onDelete: 'CASCADE' }) | ||
@JoinTable({ | ||
inverseJoinColumn: { name: 'credential_id', referencedColumnName: 'credentialHash' }, | ||
joinColumn: { name: 'transaction_id', referencedColumnName: 'txId' }, | ||
name: 'transaction_credentials' | ||
}) | ||
credentials?: CredentialEntity[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.