From 2cac0fb425aa9896d4b00c36302022b6d6902217 Mon Sep 17 00:00:00 2001 From: Rhys Bartels-Waller Date: Thu, 23 Sep 2021 17:37:44 +1000 Subject: [PATCH] refactor: rename Tx to WithHash, and export under namespace --- packages/blockfrost/src/BlockfrostToOgmios.ts | 4 ++-- packages/blockfrost/test/blockfrostProvider.test.ts | 6 +++--- .../cardano-graphql-db-sync/src/CardanoGraphqlToOgmios.ts | 4 ++-- .../test/cardanoGraphqlDbSyncProvider.test.ts | 6 +++--- packages/core/src/Provider/CardanoProvider.ts | 6 +++--- packages/core/src/Transaction/Tx.ts | 3 --- packages/core/src/Transaction/WithHash.ts | 3 +++ packages/core/src/Transaction/index.ts | 2 +- packages/core/src/index.ts | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 packages/core/src/Transaction/Tx.ts create mode 100644 packages/core/src/Transaction/WithHash.ts diff --git a/packages/blockfrost/src/BlockfrostToOgmios.ts b/packages/blockfrost/src/BlockfrostToOgmios.ts index b4a5d649225..ce98d6ae713 100644 --- a/packages/blockfrost/src/BlockfrostToOgmios.ts +++ b/packages/blockfrost/src/BlockfrostToOgmios.ts @@ -1,6 +1,6 @@ import { Responses } from '@blockfrost/blockfrost-js'; import * as OgmiosSchema from '@cardano-ogmios/schema'; -import { ProtocolParametersRequiredByWallet, Tx } from '@cardano-sdk/core'; +import { ProtocolParametersRequiredByWallet, Transaction } from '@cardano-sdk/core'; type Unpacked = T extends (infer U)[] ? U : T; type BlockfrostAddressUtxoContent = Responses['address_utxo_content']; @@ -41,7 +41,7 @@ export const BlockfrostToOgmios = { outputs: (outputs: BlockfrostOutputs): OgmiosSchema.TxOut[] => outputs.map((output) => BlockfrostToOgmios.txOut(output)), - txContentUtxo: (blockfrost: Responses['tx_content_utxo']): Tx => ({ + txContentUtxo: (blockfrost: Responses['tx_content_utxo']): Transaction.WithHash => ({ hash: blockfrost.hash, inputs: BlockfrostToOgmios.inputs(blockfrost.inputs), outputs: BlockfrostToOgmios.outputs(blockfrost.outputs) diff --git a/packages/blockfrost/test/blockfrostProvider.test.ts b/packages/blockfrost/test/blockfrostProvider.test.ts index af9d6f32030..cf3e16dfc99 100644 --- a/packages/blockfrost/test/blockfrostProvider.test.ts +++ b/packages/blockfrost/test/blockfrostProvider.test.ts @@ -3,7 +3,7 @@ import { BlockFrostAPI, Responses } from '@blockfrost/blockfrost-js'; import { blockfrostProvider } from '../src'; import { Schema as Cardano } from '@cardano-ogmios/client'; -import { Tx } from '@cardano-sdk/core'; +import { Transaction } from '@cardano-sdk/core'; jest.mock('@blockfrost/blockfrost-js'); describe('blockfrostProvider', () => { @@ -165,7 +165,7 @@ describe('blockfrostProvider', () => { ]); expect(response).toHaveLength(1); - expect(response[0]).toMatchObject({ + expect(response[0]).toMatchObject({ hash: '4123d70f66414cc921f6ffc29a899aafc7137a99a0fd453d6b200863ef5702d6', inputs: [ { @@ -253,7 +253,7 @@ describe('blockfrostProvider', () => { ]); expect(response).toHaveLength(1); - expect(response[0]).toMatchObject({ + expect(response[0]).toMatchObject({ hash: '4123d70f66414cc921f6ffc29a899aafc7137a99a0fd453d6b200863ef5702d6', inputs: [ { diff --git a/packages/cardano-graphql-db-sync/src/CardanoGraphqlToOgmios.ts b/packages/cardano-graphql-db-sync/src/CardanoGraphqlToOgmios.ts index c5edf9aa2d5..c3fc11c93bf 100644 --- a/packages/cardano-graphql-db-sync/src/CardanoGraphqlToOgmios.ts +++ b/packages/cardano-graphql-db-sync/src/CardanoGraphqlToOgmios.ts @@ -1,5 +1,5 @@ import { Schema as Cardano } from '@cardano-ogmios/client'; -import { ProtocolParametersRequiredByWallet, Tx } from '@cardano-sdk/core'; +import { ProtocolParametersRequiredByWallet, Transaction } from '@cardano-sdk/core'; import { Block } from '@cardano-graphql/client-ts'; type GraphqlTransaction = { @@ -31,7 +31,7 @@ export type GraphqlCurrentWalletProtocolParameters = { export type CardanoGraphQlTip = Pick; export const CardanoGraphqlToOgmios = { - graphqlTransactionsToCardanoTxs: (transactions: GraphqlTransaction[]): Tx[] => + graphqlTransactionsToCardanoTxs: (transactions: GraphqlTransaction[]): Transaction.WithHash[] => transactions.map((tx) => ({ hash: tx.hash, inputs: tx.inputs.map((index) => ({ txId: index.txHash, index: index.sourceTxIndex })), diff --git a/packages/cardano-graphql-db-sync/test/cardanoGraphqlDbSyncProvider.test.ts b/packages/cardano-graphql-db-sync/test/cardanoGraphqlDbSyncProvider.test.ts index 7bae9eee2a0..0b993e0c30f 100644 --- a/packages/cardano-graphql-db-sync/test/cardanoGraphqlDbSyncProvider.test.ts +++ b/packages/cardano-graphql-db-sync/test/cardanoGraphqlDbSyncProvider.test.ts @@ -1,7 +1,7 @@ /* eslint-disable max-len */ import { GraphQLClient } from 'graphql-request'; -import { ProtocolParametersRequiredByWallet, Tx } from '@cardano-sdk/core'; +import { ProtocolParametersRequiredByWallet, Transaction } from '@cardano-sdk/core'; import { cardanoGraphqlDbSyncProvider } from '../src'; import { Schema as Cardano } from '@cardano-ogmios/client'; jest.mock('graphql-request'); @@ -75,7 +75,7 @@ describe('cardanoGraphqlDbSyncProvider', () => { expect(response).toHaveLength(2); - expect(response[0]).toMatchObject({ + expect(response[0]).toMatchObject({ hash: '886206542d63b23a047864021fbfccf291d78e47c1e59bd4c75fbc67b248c5e8', inputs: [ { @@ -147,7 +147,7 @@ describe('cardanoGraphqlDbSyncProvider', () => { ]); expect(response).toHaveLength(1); - expect(response[0]).toMatchObject({ + expect(response[0]).toMatchObject({ hash: '886206542d63b23a047864021fbfccf291d78e47c1e59bd4c75fbc67b248c5e8', inputs: [ { diff --git a/packages/core/src/Provider/CardanoProvider.ts b/packages/core/src/Provider/CardanoProvider.ts index 9314ef7720a..3e9441cc28a 100644 --- a/packages/core/src/Provider/CardanoProvider.ts +++ b/packages/core/src/Provider/CardanoProvider.ts @@ -1,7 +1,7 @@ // Importing types from cardano-serialization-lib-browser will cause TypeScript errors. import CardanoSerializationLib from '@emurgo/cardano-serialization-lib-nodejs'; import Cardano, { ProtocolParametersAlonzo } from '@cardano-ogmios/schema'; -import { Tx } from '../Transaction'; +import { Transaction } from '../'; export type ProtocolParametersRequiredByWallet = Pick< ProtocolParametersAlonzo, @@ -25,7 +25,7 @@ export interface CardanoProvider { addresses: Cardano.Address[], stakeKeyHash: Cardano.Hash16 ) => Promise<{ utxo: Cardano.Utxo; delegationAndRewards: Cardano.DelegationsAndRewards }>; - queryTransactionsByAddresses: (addresses: Cardano.Address[]) => Promise; - queryTransactionsByHashes: (hashes: Cardano.Hash16[]) => Promise; + queryTransactionsByAddresses: (addresses: Cardano.Address[]) => Promise; + queryTransactionsByHashes: (hashes: Cardano.Hash16[]) => Promise; currentWalletProtocolParameters: () => Promise; } diff --git a/packages/core/src/Transaction/Tx.ts b/packages/core/src/Transaction/Tx.ts deleted file mode 100644 index 05b2f622156..00000000000 --- a/packages/core/src/Transaction/Tx.ts +++ /dev/null @@ -1,3 +0,0 @@ -import OgmiosSchema from '@cardano-ogmios/schema'; - -export type Tx = { hash: OgmiosSchema.Hash16 } & OgmiosSchema.Tx; diff --git a/packages/core/src/Transaction/WithHash.ts b/packages/core/src/Transaction/WithHash.ts new file mode 100644 index 00000000000..bbef9db26cb --- /dev/null +++ b/packages/core/src/Transaction/WithHash.ts @@ -0,0 +1,3 @@ +import OgmiosSchema from '@cardano-ogmios/schema'; + +export type WithHash = { hash: OgmiosSchema.Hash16 } & OgmiosSchema.Tx; diff --git a/packages/core/src/Transaction/index.ts b/packages/core/src/Transaction/index.ts index dafe1ba1802..4fe3eeb26b9 100644 --- a/packages/core/src/Transaction/index.ts +++ b/packages/core/src/Transaction/index.ts @@ -1 +1 @@ -export * from './Tx'; +export * from './WithHash'; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index abc2c048924..75fcb770fb0 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -3,5 +3,5 @@ export * as Cardano from './Cardano'; export * as Ogmios from './Ogmios'; export * from './Genesis'; export * from './Provider'; -export * from './Transaction'; +export * as Transaction from './Transaction'; export * from './util';