@@ -100,29 +100,58 @@ export const contractTx = async (
100
100
// Call actual query/tx & wrap it in a promise
101
101
const gasLimit = dryResult . gasRequired
102
102
return new Promise ( async ( resolve , reject ) => {
103
- const tx = contract . tx [ stringCamelCase ( method ) ] (
104
- { ...options , gasLimit } ,
105
- ...args ,
106
- )
107
103
try {
108
- const unsub = await tx . signAndSend ( account , ( result ) => {
104
+ const isDevelopment =
105
+ ( api . runtimeChain || '' ) . toLowerCase ( ) === 'development'
106
+ ? 'isInBlock'
107
+ : 'isFinalized'
108
+ const finalStatus = isDevelopment ? 'isInBlock' : 'isFinalized'
109
+ const asFinalStatus = isDevelopment ? 'asInBlock' : 'asFinalized'
110
+
111
+ const tx = contract . tx [ stringCamelCase ( method ) ] (
112
+ { ...options , gasLimit } ,
113
+ ...args ,
114
+ )
115
+
116
+ const unsub = await tx . signAndSend ( account , async ( result ) => {
109
117
statusCb ?.( result )
110
- const isInBlock = result ?. status ?. isInBlock
111
- if ( ! isInBlock ) return
112
- const errorEvent = result ?. events . find (
113
- ( { event : { method } } : any ) => method === 'ExtrinsicFailed' ,
118
+
119
+ const isFinalized = result ?. status ?. [ finalStatus ]
120
+ if ( ! isFinalized ) return
121
+
122
+ // Determine extrinsic and block info
123
+ const extrinsicHash = result . txHash . toHex ( )
124
+ const extrinsicIndex = result . txIndex
125
+ const blockHash = result . status [ asFinalStatus ] . toHex ( )
126
+
127
+ const errorEvent = result ?. events . find ( ( { event } ) =>
128
+ api . events . system . ExtrinsicFailed . is ( event ) ,
114
129
)
115
- if ( isInBlock && errorEvent ) {
130
+ if ( errorEvent ) {
116
131
// Reject if `ExtrinsicFailed` event was found
117
132
reject ( {
118
133
dryResult,
119
134
errorMessage : decodeOutput || 'ExtrinsicFailed' ,
120
135
errorEvent,
136
+ extrinsicHash,
137
+ extrinsicIndex,
138
+ blockHash,
121
139
} )
122
140
unsub ?.( )
123
- } else if ( isInBlock ) {
124
- // Otherwise resolve succesfully if transaction is in block
125
- resolve ( { dryResult, result } )
141
+ } else {
142
+ // Resolve succesfully otherwise
143
+ const successEvent = result ?. events . find ( ( { event } ) =>
144
+ api . events . system . ExtrinsicSuccess . is ( event ) ,
145
+ )
146
+
147
+ resolve ( {
148
+ dryResult,
149
+ result,
150
+ successEvent,
151
+ extrinsicHash,
152
+ extrinsicIndex,
153
+ blockHash,
154
+ } )
126
155
unsub ?.( )
127
156
}
128
157
} )
0 commit comments