Skip to content

Commit

Permalink
feat(core): add cslToOgmios.txIn
Browse files Browse the repository at this point in the history
  • Loading branch information
mkazlauskas committed Oct 12, 2021
1 parent 80bd495 commit 5bb937e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/core/src/Ogmios/cslToOgmios.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TxIn } from '@cardano-ogmios/schema';
import { Asset } from '..';
import { CSL } from '../CSL';
import { OgmiosValue } from './util';
Expand Down Expand Up @@ -30,3 +31,8 @@ export const value = (cslValue: CSL.Value): OgmiosValue => {
}
return result;
};

export const txIn = (input: CSL.TransactionInput): TxIn => ({
txId: Buffer.from(input.transaction_id().to_bytes()).toString('hex'),
index: input.index()
});
11 changes: 9 additions & 2 deletions packages/core/test/Ogmios/cslToOgmios.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CardanoSerializationLib, loadCardanoSerializationLib } from '@cardano-sdk/core';
import { AssetId } from '@cardano-sdk/util-dev';
import { AssetId, CslTestUtil } from '@cardano-sdk/util-dev';
import { cslToOgmios, ogmiosToCsl } from '../../src/Ogmios';

describe('util', () => {
Expand All @@ -8,7 +8,7 @@ describe('util', () => {
csl = await loadCardanoSerializationLib();
});

describe('valueToValueQuantities', () => {
describe('value', () => {
it('coin only', () => {
const coins = 100_000n;
const value = csl.Value.new(csl.BigNum.from_str(coins.toString()));
Expand All @@ -25,4 +25,11 @@ describe('util', () => {
expect(quantities.assets).toEqual(assets);
});
});

it('txIn', () => {
const cslInput = CslTestUtil.createTxInput(csl);
const txIn = cslToOgmios.txIn(cslInput);
expect(typeof txIn.index).toBe('number');
expect(typeof txIn.txId).toBe('string');
});
});

0 comments on commit 5bb937e

Please sign in to comment.