Skip to content

Commit

Permalink
refactor: rename Tx to WithHash, and export under namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyslbw committed Sep 24, 2021
1 parent 34eb9af commit 229d243
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions 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> = T extends (infer U)[] ? U : T;
type BlockfrostAddressUtxoContent = Responses['address_utxo_content'];
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions packages/blockfrost/test/blockfrostProvider.test.ts
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('blockfrostProvider', () => {
]);

expect(response).toHaveLength(1);
expect(response[0]).toMatchObject<Tx>({
expect(response[0]).toMatchObject<Transaction.WithHash>({
hash: '4123d70f66414cc921f6ffc29a899aafc7137a99a0fd453d6b200863ef5702d6',
inputs: [
{
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('blockfrostProvider', () => {
]);

expect(response).toHaveLength(1);
expect(response[0]).toMatchObject<Tx>({
expect(response[0]).toMatchObject<Transaction.WithHash>({
hash: '4123d70f66414cc921f6ffc29a899aafc7137a99a0fd453d6b200863ef5702d6',
inputs: [
{
Expand Down
@@ -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 = {
Expand Down Expand Up @@ -31,7 +31,7 @@ export type GraphqlCurrentWalletProtocolParameters = {
export type CardanoGraphQlTip = Pick<Block, 'hash' | 'number' | 'slotNo'>;

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 })),
Expand Down
@@ -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');
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('cardanoGraphqlDbSyncProvider', () => {

expect(response).toHaveLength(2);

expect(response[0]).toMatchObject<Tx>({
expect(response[0]).toMatchObject<Transaction.WithHash>({
hash: '886206542d63b23a047864021fbfccf291d78e47c1e59bd4c75fbc67b248c5e8',
inputs: [
{
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('cardanoGraphqlDbSyncProvider', () => {
]);

expect(response).toHaveLength(1);
expect(response[0]).toMatchObject<Tx>({
expect(response[0]).toMatchObject<Transaction.WithHash>({
hash: '886206542d63b23a047864021fbfccf291d78e47c1e59bd4c75fbc67b248c5e8',
inputs: [
{
Expand Down
6 changes: 3 additions & 3 deletions 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,
Expand All @@ -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<Tx[]>;
queryTransactionsByHashes: (hashes: Cardano.Hash16[]) => Promise<Tx[]>;
queryTransactionsByAddresses: (addresses: Cardano.Address[]) => Promise<Transaction.WithHash[]>;
queryTransactionsByHashes: (hashes: Cardano.Hash16[]) => Promise<Transaction.WithHash[]>;
currentWalletProtocolParameters: () => Promise<ProtocolParametersRequiredByWallet>;
}
3 changes: 0 additions & 3 deletions packages/core/src/Transaction/Tx.ts

This file was deleted.

3 changes: 3 additions & 0 deletions packages/core/src/Transaction/WithHash.ts
@@ -0,0 +1,3 @@
import OgmiosSchema from '@cardano-ogmios/schema';

export type WithHash = { hash: OgmiosSchema.Hash16 } & OgmiosSchema.Tx;
2 changes: 1 addition & 1 deletion packages/core/src/Transaction/index.ts
@@ -1 +1 @@
export * from './Tx';
export * from './WithHash';
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Expand Up @@ -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';

0 comments on commit 229d243

Please sign in to comment.