Skip to content

Commit

Permalink
refactor!: renamed field handle to handleResolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
iadmytro authored and mkazlauskas committed Jul 28, 2023
1 parent 2dd4f64 commit cb6bc4e
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/cardano-services/src/TxSubmit/openApi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0.0"
"version": "2.0.0"
},
"paths": {
"/tx-submit/submit": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('Service dependency abstractions', () => {
await provider.initialize();
await provider.start();
const res = await provider.submitTx({
context: { handles: [handleProviderMocks.getAliceHandleProviderResponse] },
context: { handleResolutions: [handleProviderMocks.getAliceHandleProviderResponse] },
signedTransaction: bufferToHexString(Buffer.from(new Uint8Array([])))
});
expect(res).toBeUndefined();
Expand All @@ -313,7 +313,7 @@ describe('Service dependency abstractions', () => {

await expect(
provider.submitTx({
context: { handles: [handleProviderMocks.getWrongHandleProviderResponse] },
context: { handleResolutions: [handleProviderMocks.getWrongHandleProviderResponse] },
signedTransaction: bufferToHexString(Buffer.from(new Uint8Array([])))
})
).rejects.toBeInstanceOf(ProviderError);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Provider/TxSubmitProvider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type SerializedTransaction = Cardano.util.HexBlob;

export interface SubmitTxArgs {
signedTransaction: SerializedTransaction;
context?: { handles: HandleResolution[] };
context?: { handleResolutions: HandleResolution[] };
}

export interface TxSubmitProvider extends Provider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class OgmiosTxSubmitProvider extends RunnableModule implements TxSubmitPr
}

private async throwIfHandleResolutionConflict(context: SubmitTxArgs['context']): Promise<void> {
if (context?.handles && context.handles.length > 0) {
if (context?.handleResolutions && context.handleResolutions.length > 0) {
if (!this.#handleProvider) {
throw new ProviderError(
ProviderFailure.NotImplemented,
Expand All @@ -103,14 +103,14 @@ export class OgmiosTxSubmitProvider extends RunnableModule implements TxSubmitPr
}

const handleInfoList = await this.#handleProvider.resolveHandles({
handles: context.handles.map((handle) => handle.handle)
handles: context.handleResolutions.map((hndRes) => hndRes.handle)
});

for (const [index, handleInfo] of handleInfoList.entries()) {
if (!handleInfo || handleInfo.cardanoAddress !== context.handles[index].cardanoAddress) {
if (!handleInfo || handleInfo.cardanoAddress !== context.handleResolutions[index].cardanoAddress) {
const handleOwnerChangeError = new HandleOwnerChangeError(
context.handles[index].handle,
context.handles[index].cardanoAddress,
context.handleResolutions[index].handle,
context.handleResolutions[index].cardanoAddress,
handleInfo ? handleInfo.cardanoAddress : null
);
throw new ProviderError(ProviderFailure.Conflict, handleOwnerChangeError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('OgmiosTxSubmitProvider', () => {
await expect(
provider.submitTx({
context: {
handles: [mockHandleResolution]
handleResolutions: [mockHandleResolution]
},
signedTransaction: emptyUintArrayAsHexString
})
Expand All @@ -172,7 +172,7 @@ describe('OgmiosTxSubmitProvider', () => {

const res = await provider.submitTx({
context: {
handles: [mockHandleResolution]
handleResolutions: [mockHandleResolution]
},
signedTransaction: emptyUintArrayAsHexString
});
Expand All @@ -199,7 +199,7 @@ describe('OgmiosTxSubmitProvider', () => {
await expect(
provider.submitTx({
context: {
handles: [mockHandleResolution]
handleResolutions: [mockHandleResolution]
},
signedTransaction: emptyUintArrayAsHexString
})
Expand Down
2 changes: 1 addition & 1 deletion packages/tx-construction/src/tx-builder/OutputBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class TxOutputBuilder implements OutputBuilder {
const resolution = await this.#handleProvider.resolveHandles({ handles: [this.#partialOutput.handle] });

if (resolution[0] !== null) {
txOut.handle = resolution[0];
txOut.handleResolution = resolution[0];
txOut.address = resolution[0].cardanoAddress;
} else {
// Throw an error because the handle resolved to null so we don't have
Expand Down
20 changes: 10 additions & 10 deletions packages/tx-construction/src/tx-builder/TxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class LazyTxSigner implements UnsignedTx {
async inspect(): Promise<TxInspection> {
const {
tx,
ctx: { ownAddresses, auxiliaryData, handles },
ctx: { ownAddresses, auxiliaryData, handleResolutions },
inputSelection
} = await this.#build();
return { ...tx, auxiliaryData, handles, inputSelection, ownAddresses };
return { ...tx, auxiliaryData, handleResolutions, inputSelection, ownAddresses };
}

async sign(): Promise<SignedTx> {
Expand All @@ -89,7 +89,7 @@ export class GenericTxBuilder implements TxBuilder {
#requestedPortfolio?: TxBuilderStakePool[];
#logger: Logger;
#handleProvider?: HandleProvider;
#handles: HandleResolution[];
#handleResolutions: HandleResolution[];

constructor(dependencies: TxBuilderDependencies) {
this.#outputValidator =
Expand All @@ -105,7 +105,7 @@ export class GenericTxBuilder implements TxBuilder {
};
this.#logger = dependencies.logger;
this.#handleProvider = dependencies.handleProvider;
this.#handles = [];
this.#handleResolutions = [];
}

async inspect(): Promise<PartialTx> {
Expand All @@ -118,16 +118,16 @@ export class GenericTxBuilder implements TxBuilder {
}

addOutput(txOut: OutputBuilderTxOut): TxBuilder {
if (txOut.handle) {
this.#handles = [...this.#handles, txOut.handle];
if (txOut.handleResolution) {
this.#handleResolutions = [...this.#handleResolutions, txOut.handleResolution];
}
const txOutNoHandle = omit(txOut, 'handle');
const txOutNoHandle = omit(txOut, ['handle', 'handleResolution']);
this.partialTxBody = { ...this.partialTxBody, outputs: [...(this.partialTxBody.outputs || []), txOutNoHandle] };
return this;
}

removeOutput(txOut: OutputBuilderTxOut): TxBuilder {
this.#handles = this.#handles.filter((handle) => handle !== txOut.handle);
this.#handleResolutions = this.#handleResolutions.filter((hndRes) => hndRes.handle !== txOut.handle);
this.partialTxBody = {
...this.partialTxBody,
outputs: this.partialTxBody.outputs?.filter((output) => !deepEquals(output, txOut))
Expand Down Expand Up @@ -204,7 +204,7 @@ export class GenericTxBuilder implements TxBuilder {
{
auxiliaryData,
certificates: this.partialTxBody.certificates,
handles: this.#handles,
handleResolutions: this.#handleResolutions,
outputs: new Set(this.partialTxBody.outputs || []),
signingOptions,
witness: { extraSigners }
Expand All @@ -214,7 +214,7 @@ export class GenericTxBuilder implements TxBuilder {
return {
ctx: {
auxiliaryData,
handles: this.#handles,
handleResolutions: this.#handleResolutions,
ownAddresses,
signingOptions,
witness: { extraSigners }
Expand Down
4 changes: 2 additions & 2 deletions packages/tx-construction/src/tx-builder/finalizeTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const getSignatures = async (

export const finalizeTx = async (
tx: Cardano.TxBodyWithHash,
{ ownAddresses, witness, signingOptions, auxiliaryData, isValid, handles }: TxContext,
{ ownAddresses, witness, signingOptions, auxiliaryData, isValid, handleResolutions }: TxContext,
{ inputResolver, keyAgent }: FinalizeTxDependencies,
stubSign = false
): Promise<SignedTx> => {
Expand Down Expand Up @@ -58,7 +58,7 @@ export const finalizeTx = async (
return {
cbor: TxCBOR.serialize(transaction),
context: {
handles: handles ?? []
handleResolutions: handleResolutions ?? []
},
tx: transaction
};
Expand Down
2 changes: 1 addition & 1 deletion packages/tx-construction/src/tx-builder/initializeTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const initializeTx = async (
unsignedTx,
{
auxiliaryData: props.auxiliaryData,
handles: props.handles ?? [],
handleResolutions: props.handleResolutions ?? [],
ownAddresses: addresses,
signingOptions: props.signingOptions,
witness: props.witness
Expand Down
8 changes: 4 additions & 4 deletions packages/tx-construction/src/tx-builder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export type TxBodyValidationError = TxOutValidationError | InputSelectionError;
* appear in the final TxOut type since it's extracted before then and passed
* as `ctx`.
*/
export type OutputBuilderTxOut = Cardano.TxOut & { handle?: HandleResolution };
export type OutputBuilderTxOut = Cardano.TxOut & { handle?: Handle; handleResolution?: HandleResolution };

/**
* Helps build transaction outputs from its constituent parts.
Expand Down Expand Up @@ -129,19 +129,19 @@ export interface TxContext {
auxiliaryData?: Cardano.AuxiliaryData;
witness?: InitializeTxWitness;
isValid?: boolean;
handles?: HandleResolution[];
handleResolutions?: HandleResolution[];
}

export type TxInspection = Cardano.TxBodyWithHash &
Pick<TxContext, 'ownAddresses' | 'auxiliaryData' | 'handles'> & {
Pick<TxContext, 'ownAddresses' | 'auxiliaryData' | 'handleResolutions'> & {
inputSelection: SelectionSkeleton;
};

export interface SignedTx {
cbor: TxCBOR;
tx: Cardano.Tx;
context: {
handles: HandleResolution[];
handleResolutions: HandleResolution[];
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/tx-construction/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface InitializeTxProps {
auxiliaryData?: Cardano.AuxiliaryData;
witness?: InitializeTxWitness;
signingOptions?: SignTransactionOptions;
handles?: HandleResolution[];
handleResolutions?: HandleResolution[];
}

export interface InitializeTxPropsValidationResult {
Expand Down
10 changes: 5 additions & 5 deletions packages/tx-construction/test/tx-builder/TxBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ describe('GenericTxBuilder', () => {
it('resolves handle to address', async () => {
const txOut = await txBuilder.buildOutput().handle('alice').coin(output1Coin).build();

expect(txOut.handle).toBe(resolvedHandle);
expect(txOut.handle).toBe(resolvedHandle.handle);
expect(txOut.address).toBe(resolvedHandle.cardanoAddress);
});

Expand Down Expand Up @@ -480,13 +480,13 @@ describe('GenericTxBuilder', () => {
const tx = txBuilder
.addOutput({
...mocks.utxo[0][1],
handle: resolvedHandle
handleResolution: resolvedHandle
})
.build();
const { handles } = await tx.inspect();
expect(handles).toEqual([resolvedHandle]);
const { handleResolutions } = await tx.inspect();
expect(handleResolutions).toEqual([resolvedHandle]);
const { context } = await tx.sign();
expect(context.handles).toEqual([resolvedHandle]);
expect(context.handleResolutions).toEqual([resolvedHandle]);
});

it('can build transactions that are not modified by subsequent builder changes', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/test/PersonalWallet/methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ describe('PersonalWallet methods', () => {

const txOut = await txBuilder.addOutput(txOutput).build().sign();
const submitTxArgsMock = {
context: { handles: [mocks.resolvedHandle] },
context: { handleResolutions: [mocks.resolvedHandle] },
signedTransaction: txOut.cbor
};
const txPending = firstValueFrom(wallet.transactions.outgoing.pending$);
Expand Down

0 comments on commit cb6bc4e

Please sign in to comment.