wowok
Version:
Wowok Blockchain TypeScript API
1 lines • 1.55 kB
JavaScript
import{bcs}from'../../bcs/index.js';import{ObjectCache}from'../ObjectCache.js';import{isTransaction}from'../Transaction.js';export class CachingTransactionExecutor{#client;#lastDigest=null;['cache'];constructor({client:a,...b}){this.#client=a,this['cache']=new ObjectCache(b);}async['reset'](){await Promise['all']([this['cache']['clearOwnedObjects'](),this['cache']['clearCustom'](),this['waitForLastTransaction']()]);}async['buildTransaction']({transaction:a,...b}){return a['addBuildPlugin'](this['cache']['asPlugin']()),a['build']({'client':this.#client,...b});}async['executeTransaction']({transaction:a,options:b,...c}){const d=isTransaction(a)?await this['buildTransaction']({'transaction':a}):a,e=await this.#client['executeTransactionBlock']({...c,'transactionBlock':d,'options':{...b,'showRawEffects':!![]}});if(e['rawEffects']){const f=bcs['TransactionEffects']['parse'](Uint8Array['from'](e['rawEffects']));await this['applyEffects'](f);}return e;}async['signAndExecuteTransaction']({options:a,transaction:b,...c}){b['setSenderIfNotSet'](c['signer']['toWAddress']());const d=await this['buildTransaction']({'transaction':b}),{signature:e}=await c['signer']['signTransaction'](d),f=await this['executeTransaction']({'transaction':d,'signature':e,'options':a});return f;}async['applyEffects'](a){this.#lastDigest=a['V2']?.['transactionDigest']??null,await this['cache']['applyEffects'](a);}async['waitForLastTransaction'](){this.#lastDigest&&(await this.#client['waitForTransaction']({'digest':this.#lastDigest}),this.#lastDigest=null);}}