Skip to content

Commit

Permalink
feat(tooling-sdk): Pair TS SDK after rename TransactionEffectsV2 to T…
Browse files Browse the repository at this point in the history
…ransactionEffectsV1 (#3805)

* feat(tooling-sdk): TS SDK remove transactionEffectsV1 and rename transactionEffectsV2 to V1 [WiP]

* tmp

* wip: no errors

* chore: cleanup code

* chore: rename remaining v2 effects to v1 in tests

* feat(tooling-sdk): Minor formatting fix

* feat(tooling-sdk): Fix dapp-kit test

* feat(tooling-sdk): Remove unneeded export

---------

Co-authored-by: Begoña Alvarez <[email protected]>
  • Loading branch information
msarcev and begonaalvarezd authored Oct 31, 2024
1 parent c13a8c0 commit 0123dba
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('useSignAndExecuteTransaction', () => {
]),
);
const effectsBcs = bcs.TransactionEffects.serialize({
V2: {
V1: {
status: {
Success: true,
},
Expand Down
386 changes: 187 additions & 199 deletions sdk/graphql-transport/src/mappers/transaction-block.ts

Large diffs are not rendered by default.

25 changes: 3 additions & 22 deletions sdk/typescript/src/bcs/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { bcs } from '@iota/bcs';

import { Address, ObjectDigest, IotaObjectRef } from './bcs.js';
import { Address, ObjectDigest } from './bcs.js';

const PackageUpgradeError = bcs.enum('PackageUpgradeError', {
UnableToFetchPackage: bcs.struct('UnableToFetchPackage', { packageId: Address }),
Expand Down Expand Up @@ -132,32 +132,14 @@ const Owner = bcs.enum('Owner', {
Immutable: null,
});

const TransactionEffectsV1 = bcs.struct('TransactionEffectsV1', {
status: ExecutionStatus,
executedEpoch: bcs.u64(),
gasUsed: GasCostSummary,
modifiedAtVersions: bcs.vector(bcs.tuple([Address, bcs.u64()])),
sharedObjects: bcs.vector(IotaObjectRef),
transactionDigest: ObjectDigest,
created: bcs.vector(bcs.tuple([IotaObjectRef, Owner])),
mutated: bcs.vector(bcs.tuple([IotaObjectRef, Owner])),
unwrapped: bcs.vector(bcs.tuple([IotaObjectRef, Owner])),
deleted: bcs.vector(IotaObjectRef),
unwrappedThenDeleted: bcs.vector(IotaObjectRef),
wrapped: bcs.vector(IotaObjectRef),
gasObject: bcs.tuple([IotaObjectRef, Owner]),
eventsDigest: bcs.option(ObjectDigest),
dependencies: bcs.vector(ObjectDigest),
});

const VersionDigest = bcs.tuple([bcs.u64(), ObjectDigest]);

const ObjectIn = bcs.enum('ObjectIn', {
NotExist: null,
Exist: bcs.tuple([VersionDigest, Owner]),
});

const ObjectOut = bcs.enum('ObjectOut', {
export const ObjectOut = bcs.enum('ObjectOut', {
NotExist: null,
ObjectWrite: bcs.tuple([ObjectDigest, Owner]),
PackageWrite: VersionDigest,
Expand All @@ -183,7 +165,7 @@ const UnchangedSharedKind = bcs.enum('UnchangedSharedKind', {
PerEpochConfig: null,
});

const TransactionEffectsV2 = bcs.struct('TransactionEffectsV2', {
const TransactionEffectsV1 = bcs.struct('TransactionEffectsV1', {
status: ExecutionStatus,
executedEpoch: bcs.u64(),
gasUsed: GasCostSummary,
Expand All @@ -199,5 +181,4 @@ const TransactionEffectsV2 = bcs.struct('TransactionEffectsV2', {

export const TransactionEffects = bcs.enum('TransactionEffects', {
V1: TransactionEffectsV1,
V2: TransactionEffectsV2,
});
4 changes: 2 additions & 2 deletions sdk/typescript/src/transactions/ObjectCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ export class ObjectCache {
}

async applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {
if (!effects.V2) {
if (!effects.V1) {
throw new Error(`Unsupported transaction effects version ${effects.$kind}`);
}

const { lamportVersion, changedObjects } = effects.V2;
const { lamportVersion, changedObjects } = effects.V1;

const deletedIds: string[] = [];
const addedObjects: ObjectCacheEntry[] = [];
Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/src/transactions/executor/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class CachingTransactionExecutor {
}

async applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {
this.#lastDigest = effects.V2?.transactionDigest ?? null;
this.#lastDigest = effects.V1?.transactionDigest ?? null;
await this.cache.applyEffects(effects);
}

Expand Down
8 changes: 4 additions & 4 deletions sdk/typescript/src/transactions/executor/parallel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class ParallelTransactionExecutor {
const effects = bcs.TransactionEffects.parse(effectsBytes);

const gasResult = getGasCoinFromEffects(effects);
const gasUsed = effects.V2?.gasUsed;
const gasUsed = effects.V1?.gasUsed;

if (gasCoin && gasUsed && gasResult.owner === this.#signer.toIotaAddress()) {
const totalUsed =
Expand Down Expand Up @@ -428,14 +428,14 @@ export class ParallelTransactionExecutor {
});

const effects = bcs.TransactionEffects.parse(Uint8Array.from(result.rawEffects!));
effects.V2?.changedObjects.forEach(([id, { outputState }], i) => {
if (i === effects.V2?.gasObjectIndex || !outputState.ObjectWrite) {
effects.V1?.changedObjects.forEach(([id, { outputState }], i) => {
if (i === effects.V1?.gasObjectIndex || !outputState.ObjectWrite) {
return;
}

this.#coinPool.push({
id,
version: effects.V2!.lamportVersion,
version: effects.V1!.lamportVersion,
digest: outputState.ObjectWrite[0],
balance: BigInt(this.#initialCoinBalance),
});
Expand Down
8 changes: 4 additions & 4 deletions sdk/typescript/src/transactions/executor/serial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class SerialTransactionExecutor {
}

#cacheGasCoin = async (effects: typeof bcs.TransactionEffects.$inferType) => {
if (!effects.V2) {
if (!effects.V1) {
return;
}

Expand Down Expand Up @@ -117,11 +117,11 @@ export class SerialTransactionExecutor {
}

export function getGasCoinFromEffects(effects: typeof bcs.TransactionEffects.$inferType) {
if (!effects.V2) {
if (!effects.V1) {
throw new Error('Unexpected effects version');
}

const gasObjectChange = effects.V2.changedObjects[effects.V2.gasObjectIndex!];
const gasObjectChange = effects.V1.changedObjects[effects.V1.gasObjectIndex!];

if (!gasObjectChange) {
throw new Error('Gas object not found in effects');
Expand All @@ -139,7 +139,7 @@ export function getGasCoinFromEffects(effects: typeof bcs.TransactionEffects.$in
ref: {
objectId,
digest,
version: effects.V2.lamportVersion,
version: effects.V1.lamportVersion,
},
owner: owner.AddressOwner || owner.ObjectOwner!,
};
Expand Down
4 changes: 2 additions & 2 deletions sdk/typescript/test/e2e/parallel-executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ describe('ParallelTransactionExecutor', { retry: 3 }, () => {
const result = await executor.executeTransaction(txb);

const effects = bcs.TransactionEffects.fromBase64(result.effects);
const newCoinId = effects.V2?.changedObjects.find(
const newCoinId = effects.V1?.changedObjects.find(
([_id, { outputState }], index) =>
index !== effects.V2.gasObjectIndex && outputState.ObjectWrite,
index !== effects.V1.gasObjectIndex && outputState.ObjectWrite,
)?.[0]!;

return newCoinId;
Expand Down
10 changes: 5 additions & 5 deletions sdk/typescript/test/e2e/serial-executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ describe('SerialExecutor', { retry: 3 }, () => {

const effects = bcs.TransactionEffects.fromBase64(result.effects);

const newCoinId = effects.V2?.changedObjects.find(
const newCoinId = effects.V1?.changedObjects.find(
([_id, { outputState }], index) =>
index !== effects.V2.gasObjectIndex && outputState.ObjectWrite,
index !== effects.V1.gasObjectIndex && outputState.ObjectWrite,
)?.[0]!;

expect(toolbox.client.getCoins).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -82,9 +82,9 @@ describe('SerialExecutor', { retry: 3 }, () => {

await toolbox.client.waitForTransaction({ digest: result.digest });

const newCoinId = effects.V2?.changedObjects.find(
const newCoinId = effects.V1?.changedObjects.find(
([_id, { outputState }], index) =>
index !== effects.V2.gasObjectIndex && outputState.ObjectWrite,
index !== effects.V1.gasObjectIndex && outputState.ObjectWrite,
)?.[0]!;

expect(toolbox.client.getCoins).toHaveBeenCalledTimes(1);
Expand All @@ -106,6 +106,6 @@ describe('SerialExecutor', { retry: 3 }, () => {
const result2 = await executor.executeTransaction(txb3);

expect(result2.digest).not.toEqual(result.digest);
expect(bcs.TransactionEffects.fromBase64(result2.effects).V2?.status.Success).toEqual(true);
expect(bcs.TransactionEffects.fromBase64(result2.effects).V1?.status.Success).toEqual(true);
});
});

0 comments on commit 0123dba

Please sign in to comment.