Skip to content

Commit 083a766

Browse files
committed
fixup! fix(core): proposal procedure now correctly deserializes info action procedures
1 parent b1a7f4d commit 083a766

File tree

6 files changed

+57
-41
lines changed

6 files changed

+57
-41
lines changed

packages/tx-construction/src/createTransactionInternals.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export const createPreInputSelectionTxBody = ({
2727
requiredExtraSignatures,
2828
outputs
2929
}: Omit<CreateTxInternalsProps, 'inputSelection'> & { outputs?: Cardano.TxOut[] }): {
30-
body: TxBodyPreInputSelection;
30+
txBody: TxBodyPreInputSelection;
3131
auxiliaryData?: Cardano.AuxiliaryData;
3232
} => ({
3333
auxiliaryData,
34-
body: {
34+
txBody: {
3535
auxiliaryDataHash: auxiliaryData ? Cardano.computeAuxiliaryDataHash(auxiliaryData) : undefined,
3636
certificates,
3737
mint,
@@ -68,6 +68,6 @@ export const includeChangeAndInputs = ({
6868
};
6969

7070
export const createTransactionInternals = (props: CreateTxInternalsProps): Cardano.TxBodyWithHash => {
71-
const { body } = createPreInputSelectionTxBody({ ...props });
72-
return includeChangeAndInputs({ bodyPreInputSelection: body, inputSelection: props.inputSelection });
71+
const { txBody } = createPreInputSelectionTxBody({ ...props });
72+
return includeChangeAndInputs({ bodyPreInputSelection: txBody, inputSelection: props.inputSelection });
7373
};

packages/tx-construction/src/tx-builder/TxBuilder.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import {
88
util
99
} from '@cardano-sdk/key-management';
1010
import { Cardano, HandleProvider, HandleResolution, metadatum } from '@cardano-sdk/core';
11-
import { GreedyInputSelector, SelectionSkeleton } from '@cardano-sdk/input-selection';
12-
import { InitializeTxProps, RewardAccountWithPoolId } from '../types';
1311
import {
12+
CustomizeCb,
1413
InsufficientRewardAccounts,
1514
OutOfSyncRewardAccounts,
1615
OutputBuilderTxOut,
@@ -24,8 +23,10 @@ import {
2423
TxOutValidationError,
2524
UnsignedTx
2625
} from './types';
26+
import { GreedyInputSelector, SelectionSkeleton } from '@cardano-sdk/input-selection';
2727
import { Logger } from 'ts-log';
2828
import { OutputBuilderValidator, TxOutputBuilder } from './OutputBuilder';
29+
import { RewardAccountWithPoolId } from '../types';
2930
import { coldObservableProvider } from '@cardano-sdk/util-rxjs';
3031
import { contextLogger, deepEquals } from '@cardano-sdk/util';
3132
import { createOutputValidator } from '../output-validation';
@@ -102,7 +103,7 @@ export class GenericTxBuilder implements TxBuilder {
102103
#logger: Logger;
103104
#handleProvider?: HandleProvider;
104105
#handleResolutions: HandleResolution[];
105-
#customizeCb: InitializeTxProps['customizeCb'];
106+
#customizeCb: CustomizeCb;
106107

107108
constructor(dependencies: TxBuilderDependencies) {
108109
this.#outputValidator =
@@ -195,8 +196,9 @@ export class GenericTxBuilder implements TxBuilder {
195196
return this;
196197
}
197198

198-
customize(cb: InitializeTxProps['customizeCb']): void {
199+
customize(cb: CustomizeCb): TxBuilder {
199200
this.#customizeCb = cb;
201+
return this;
200202
}
201203

202204
build(): UnsignedTx {

packages/tx-construction/src/tx-builder/initializeTx.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const initializeTx = async (
3636
});
3737

3838
// Create transaction body that can be customized by the user via the customizeCb
39-
const { body: b, auxiliaryData } = createPreInputSelectionTxBody({
39+
const { txBody, auxiliaryData } = createPreInputSelectionTxBody({
4040
auxiliaryData: props.auxiliaryData,
4141
certificates: props.certificates,
4242
collaterals: props.collaterals,
@@ -53,7 +53,7 @@ export const initializeTx = async (
5353
.filter(({ quantity }) => !!quantity)
5454
});
5555

56-
const bodyPreInputSelection = props.customizeCb ? props.customizeCb(b) : b;
56+
const bodyPreInputSelection = props.customizeCb ? props.customizeCb({ txBody }) : txBody;
5757

5858
const constraints = defaultSelectionConstraints({
5959
buildTx: async (inputSelection) => {

packages/tx-construction/src/tx-builder/types.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { Cardano, Handle, HandleProvider, HandleResolution, TxCBOR } from '@cardano-sdk/core';
1010
import { CustomError } from 'ts-custom-error';
1111
import { Hash32ByteBase16 } from '@cardano-sdk/crypto';
12-
import { InitializeTxProps, InitializeTxWitness, TxBuilderProviders } from '../types';
12+
import { InitializeTxWitness, TxBodyPreInputSelection, TxBuilderProviders } from '../types';
1313
import { InputSelectionError, InputSelector, SelectionSkeleton } from '@cardano-sdk/input-selection';
1414
import { Logger } from 'ts-log';
1515
import { OutputBuilderValidator } from './OutputBuilder';
@@ -181,6 +181,10 @@ export interface PartialTx {
181181
extraSigners?: TransactionSigner[];
182182
signingOptions?: SignTransactionOptions;
183183
}
184+
185+
type CustomizeCbProps = { txBody: Readonly<TxBodyPreInputSelection> };
186+
export type CustomizeCb = (props: CustomizeCbProps) => TxBodyPreInputSelection;
187+
184188
export interface TxBuilder {
185189
/**
186190
* @returns a partial transaction that has properties set by calling other TxBuilder methods. Does not validate the transaction.
@@ -243,7 +247,7 @@ export interface TxBuilder {
243247
* the `delegatePortfolio` method.
244248
* This method is not available when using web extension remote apis.
245249
*/
246-
customize(cb: InitializeTxProps['customizeCb']): void;
250+
customize(cb: CustomizeCb): TxBuilder;
247251

248252
/**
249253
* Create a snapshot of current transaction properties.

packages/tx-construction/src/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Cardano, HandleResolution } from '@cardano-sdk/core';
33
import { GroupedAddress, SignTransactionOptions, TransactionSigner } from '@cardano-sdk/key-management';
44
import { SelectionSkeleton } from '@cardano-sdk/input-selection';
55

6+
import { CustomizeCb } from './tx-builder';
67
import { MinimumCoinQuantityPerOutput } from './output-validation';
78

89
export type InitializeTxResult = Cardano.TxBodyWithHash & { inputSelection: SelectionSkeleton };
@@ -48,7 +49,7 @@ export interface InitializeTxProps {
4849
signingOptions?: Pick<SignTransactionOptions, 'additionalKeyPaths'>;
4950
handleResolutions?: HandleResolution[];
5051
/** callback function that allows updating the transaction before input selection */
51-
customizeCb?: (txBody: Readonly<TxBodyPreInputSelection>) => TxBodyPreInputSelection;
52+
customizeCb?: CustomizeCb;
5253
}
5354

5455
export interface InitializeTxPropsValidationResult {

packages/tx-construction/test/tx-builder/TxBuilder.test.ts

+37-28
Original file line numberDiff line numberDiff line change
@@ -498,16 +498,18 @@ describe('GenericTxBuilder', () => {
498498
});
499499

500500
it('can add a custom fields which are accounted for by input selector', async () => {
501-
txBuilder.addOutput(mocks.utxo[0][1]);
502-
txBuilder.customize((txBody) => {
503-
const outputs = [...txBody.outputs, { ...mocks.utxo[1][1], value: { coins: 100n } }];
504-
return {
505-
...txBody,
506-
outputs,
507-
withdrawals: [...(txBody.withdrawals || []), { quantity: 13n, stakeAddress: mocks.rewardAccount }]
508-
};
509-
});
510-
const txProps = await txBuilder.build().inspect();
501+
const txProps = await txBuilder
502+
.addOutput(mocks.utxo[0][1])
503+
.customize(({ txBody }) => {
504+
const outputs = [...txBody.outputs, { ...mocks.utxo[1][1], value: { coins: 100n } }];
505+
return {
506+
...txBody,
507+
outputs,
508+
withdrawals: [...(txBody.withdrawals || []), { quantity: 13n, stakeAddress: mocks.rewardAccount }]
509+
};
510+
})
511+
.build()
512+
.inspect();
511513

512514
// Check if the custom fields were included the built transaction
513515
expect(txProps.body.outputs.filter(({ value: { coins } }) => coins === 100n).length).toBe(1);
@@ -536,11 +538,14 @@ describe('GenericTxBuilder', () => {
536538
type: Cardano.CredentialType.KeyHash
537539
}
538540
};
539-
txBuilder.customize((txBody) => {
540-
const certificates = [...(txBody.certificates || []), stakeVoteRegDelegCert];
541-
return { ...txBody, certificates };
542-
});
543-
const txProps = await txBuilder.build().inspect();
541+
const txProps = await txBuilder
542+
.customize(({ txBody }) => {
543+
const certificates = [...(txBody.certificates || []), stakeVoteRegDelegCert];
544+
return { ...txBody, certificates };
545+
})
546+
.build()
547+
.inspect();
548+
544549
expect(txProps.body.certificates?.length).toEqual(1);
545550
expect(txProps.body.certificates![0]).toEqual(stakeVoteRegDelegCert);
546551
});
@@ -556,12 +561,14 @@ describe('GenericTxBuilder', () => {
556561
}
557562
};
558563

559-
txBuilder.customize((txBody) => {
560-
const certificates = [...(txBody.certificates || []), stakeRegDelegCert];
561-
return { ...txBody, certificates };
562-
});
564+
const txProps = await txBuilder
565+
.customize(({ txBody }) => {
566+
const certificates = [...(txBody.certificates || []), stakeRegDelegCert];
567+
return { ...txBody, certificates };
568+
})
569+
.build()
570+
.inspect();
563571

564-
const txProps = await txBuilder.build().inspect();
565572
expect(txProps.body.certificates?.length).toEqual(1);
566573
expect(txProps.body.certificates![0]).toEqual(stakeRegDelegCert);
567574

@@ -596,15 +603,17 @@ describe('GenericTxBuilder', () => {
596603
]
597604
};
598605

599-
txBuilder.customize((txBody) => {
600-
const votingProcedures: Cardano.TxBody['votingProcedures'] = [
601-
...(txBody.votingProcedures || []),
602-
votingProcedure
603-
];
604-
return { ...txBody, votingProcedures };
605-
});
606+
const txProps = await txBuilder
607+
.customize(({ txBody }) => {
608+
const votingProcedures: Cardano.TxBody['votingProcedures'] = [
609+
...(txBody.votingProcedures || []),
610+
votingProcedure
611+
];
612+
return { ...txBody, votingProcedures };
613+
})
614+
.build()
615+
.inspect();
606616

607-
const txProps = await txBuilder.build().inspect();
608617
expect(txProps.body.votingProcedures?.length).toBe(1);
609618
expect(txProps.body.votingProcedures![0]).toEqual(votingProcedure);
610619
});

0 commit comments

Comments
 (0)