diff --git a/.changeset/pretty-rules-sort.md b/.changeset/pretty-rules-sort.md new file mode 100644 index 0000000000000..df367f81a852f --- /dev/null +++ b/.changeset/pretty-rules-sort.md @@ -0,0 +1,5 @@ +--- +'@mysten/sui': patch +--- + +Remove duplicate applyEffects in serial transaction executor diff --git a/sdk/typescript/src/transactions/ObjectCache.ts b/sdk/typescript/src/transactions/ObjectCache.ts index bd6a61c5ccc1f..e5accd58d50ac 100644 --- a/sdk/typescript/src/transactions/ObjectCache.ts +++ b/sdk/typescript/src/transactions/ObjectCache.ts @@ -148,13 +148,16 @@ export class InMemoryCache extends AsyncCache { export interface ObjectCacheOptions { cache?: AsyncCache; + onEffects?: (effects: typeof bcs.TransactionEffects.$inferType) => Promise; } export class ObjectCache { #cache: AsyncCache; + #onEffects?: (effects: typeof bcs.TransactionEffects.$inferType) => Promise; - constructor({ cache = new InMemoryCache() }: ObjectCacheOptions) { + constructor({ cache = new InMemoryCache(), onEffects }: ObjectCacheOptions) { this.#cache = cache; + this.#onEffects = onEffects; } asPlugin(): TransactionPlugin { @@ -291,6 +294,7 @@ export class ObjectCache { await Promise.all([ this.#cache.addObjects(addedObjects), this.#cache.deleteObjects(deletedIds), + this.#onEffects?.(effects), ]); } } diff --git a/sdk/typescript/src/transactions/executor/serial.ts b/sdk/typescript/src/transactions/executor/serial.ts index 0e25ed95c0445..fc121277ee6dc 100644 --- a/sdk/typescript/src/transactions/executor/serial.ts +++ b/sdk/typescript/src/transactions/executor/serial.ts @@ -3,7 +3,7 @@ import { toBase64 } from '@mysten/bcs'; -import { bcs } from '../../bcs/index.js'; +import type { bcs } from '../../bcs/index.js'; import type { SuiClient, SuiTransactionBlockResponseOptions } from '../../client/index.js'; import type { Signer } from '../../cryptography/keypair.js'; import type { ObjectCacheOptions } from '../ObjectCache.js'; @@ -32,11 +32,12 @@ export class SerialTransactionExecutor { this.#cache = new CachingTransactionExecutor({ client: options.client, cache: options.cache, + onEffects: (effects) => this.#cacheGasCoin(effects), }); } async applyEffects(effects: typeof bcs.TransactionEffects.$inferType) { - return Promise.all([this.#cacheGasCoin(effects), this.#cache.cache.applyEffects(effects)]); + return this.#cache.applyEffects(effects); } #cacheGasCoin = async (effects: typeof bcs.TransactionEffects.$inferType) => { @@ -104,9 +105,6 @@ export class SerialTransactionExecutor { }); const effectsBytes = Uint8Array.from(results.rawEffects!); - const effects = bcs.TransactionEffects.parse(effectsBytes); - await this.applyEffects(effects); - return { digest: results.digest, effects: toBase64(effectsBytes),