@@ -31,6 +31,7 @@ import {ABICache, ABICacheInterface} from '@wharfkit/abicache'
3131import {
3232 AbstractTransactPlugin ,
3333 BaseTransactPlugin ,
34+ BroadcastOptions ,
3435 TransactABIDef ,
3536 TransactArgs ,
3637 TransactContext ,
@@ -44,6 +45,7 @@ import {
4445import { SessionStorage } from './storage'
4546import {
4647 actionMatchesPermission ,
48+ buildSendTransaction2Options ,
4749 extractActions ,
4850 getFetch ,
4951 getPluginTranslations ,
@@ -87,6 +89,8 @@ export interface SessionOptions {
8789 transactPlugins ?: AbstractTransactPlugin [ ]
8890 transactPluginsOptions ?: TransactPluginsOptions
8991 ui ?: UserInterface
92+ awaitIrreversible ?: boolean
93+ broadcastOptions ?: BroadcastOptions
9094 sessionKeyManager ?: SessionKeyManager
9195 onPersist ?: ( session : Session ) => Promise < void >
9296}
@@ -108,7 +112,9 @@ export class Session {
108112 readonly abis : TransactABIDef [ ] = [ ]
109113 readonly abiCache : ABICacheInterface
110114 readonly allowModify : boolean = true
115+ readonly awaitIrreversible : boolean = false
111116 readonly broadcast : boolean = true
117+ readonly broadcastOptions ?: BroadcastOptions
112118 readonly chain : ChainDefinition
113119 readonly expireSeconds : number = 120
114120 readonly fetch : Fetch
@@ -201,6 +207,12 @@ export class Session {
201207 if ( options . broadcast !== undefined ) {
202208 this . broadcast = options . broadcast
203209 }
210+ if ( options . awaitIrreversible !== undefined ) {
211+ this . awaitIrreversible = options . awaitIrreversible
212+ }
213+ if ( options . broadcastOptions !== undefined ) {
214+ this . broadcastOptions = options . broadcastOptions
215+ }
204216 if ( options . expireSeconds ) {
205217 this . expireSeconds = options . expireSeconds
206218 }
@@ -448,6 +460,16 @@ export class Session {
448460 ? options . broadcast
449461 : this . broadcast
450462
463+ const awaitIrreversible =
464+ options && options . awaitIrreversible !== undefined
465+ ? options . awaitIrreversible
466+ : this . awaitIrreversible
467+
468+ const broadcastOptions =
469+ options && options . broadcastOptions !== undefined
470+ ? options . broadcastOptions
471+ : this . broadcastOptions
472+
451473 // The abi provider to use for this transaction, falling back to the session instance
452474 const abiCache = this . getMergedAbiCache ( args , options )
453475
@@ -596,8 +618,19 @@ export class Session {
596618 signatures : result . signatures ,
597619 } )
598620
599- // Broadcast the SignedTransaction and save the API response to the TransactResult
600- result . response = await context . client . v1 . chain . send_transaction ( signed )
621+ const tx2Options = buildSendTransaction2Options ( awaitIrreversible , broadcastOptions )
622+ try {
623+ result . response = await context . client . v1 . chain . send_transaction2 (
624+ signed ,
625+ tx2Options
626+ )
627+ } catch ( error : any ) {
628+ if ( error ?. response ?. status === 404 ) {
629+ result . response = await context . client . v1 . chain . send_transaction ( signed )
630+ } else {
631+ throw error
632+ }
633+ }
601634
602635 // Find and process any return values from the transaction
603636 if ( result . response . processed && result . response . processed . action_traces ) {
0 commit comments