UNPKG

@mysten/sui

Version:

Sui TypeScript API(Work in Progress)

94 lines (93 loc) 2.69 kB
var __accessCheck = (obj, member, msg) => { if (!member.has(obj)) throw TypeError("Cannot " + msg); }; var __privateGet = (obj, member, getter) => { __accessCheck(obj, member, "read from private field"); return getter ? getter.call(obj) : member.get(obj); }; var __privateAdd = (obj, member, value) => { if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); member instanceof WeakSet ? member.add(obj) : member.set(obj, value); }; var __privateSet = (obj, member, value, setter) => { __accessCheck(obj, member, "write to private field"); setter ? setter.call(obj, value) : member.set(obj, value); return value; }; var _client; import { bcs } from "../../bcs/index.js"; import { ObjectCache } from "../ObjectCache.js"; import { isTransaction } from "../Transaction.js"; class CachingTransactionExecutor { constructor({ client, ...options }) { __privateAdd(this, _client, void 0); __privateSet(this, _client, client); this.cache = new ObjectCache(options); } /** * Clears all Owned objects * Immutable objects, Shared objects, and Move function definitions will be preserved */ async reset() { await this.cache.clearOwnedObjects(); await this.cache.clearCustom(); } async buildTransaction({ transaction, ...options }) { transaction.addBuildPlugin(this.cache.asPlugin()); return transaction.build({ client: __privateGet(this, _client), ...options }); } async executeTransaction({ transaction, options, ...input }) { const bytes = isTransaction(transaction) ? await this.buildTransaction({ transaction }) : transaction; const results = await __privateGet(this, _client).executeTransactionBlock({ ...input, transactionBlock: bytes, options: { ...options, showRawEffects: true } }); if (results.rawEffects) { const effects = bcs.TransactionEffects.parse(Uint8Array.from(results.rawEffects)); await this.applyEffects(effects); } return results; } async signAndExecuteTransaction({ options, transaction, ...input }) { transaction.setSenderIfNotSet(input.signer.toSuiAddress()); const bytes = await this.buildTransaction({ transaction }); const { signature } = await input.signer.signTransaction(bytes); const results = await this.executeTransaction({ transaction: bytes, signature, options }); return results; } async applyEffects(effects) { await this.cache.applyEffects(effects); } } _client = new WeakMap(); export { CachingTransactionExecutor }; //# sourceMappingURL=caching.js.map