diff --git a/lib/controller/transaction/index.js b/lib/controller/transaction/index.js index 29c9969c49..957cc20791 100644 --- a/lib/controller/transaction/index.js +++ b/lib/controller/transaction/index.js @@ -85,12 +85,12 @@ async function broadcastTransaction(networkId, senderAddress, url, signedTx) { .then(assertOk) // check if tx is successful when executed vs when broadcasted - pollTransactionSuccess(networkId, senderAddress, url, res.txhash) + pollTransactionSuccess(networkId, senderAddress, url, res.txhash, res) return res.txhash } -function createBroadcastBody(signedTx, returnType = `block`) { +function createBroadcastBody(signedTx, returnType = `sync`) { return JSON.stringify({ tx: signedTx, mode: returnType @@ -131,6 +131,7 @@ async function pollTransactionSuccess( senderAddress, url, hash, + broadcastResponse, iteration = 0 ) { let res @@ -153,6 +154,7 @@ async function pollTransactionSuccess( senderAddress, url, hash, + broadcastResponse, iteration + 1 ) return @@ -161,7 +163,7 @@ async function pollTransactionSuccess( res = { hash, success: false, - height: null + height: -1 } throw new Error( 'Timed out waiting for the transaction to be included in a block' @@ -171,13 +173,24 @@ async function pollTransactionSuccess( assertOk(res) } catch (error) { console.error('TX failed:', hash, error) - const transaction = reducers.transactionReducer(res, reducers) + let transaction + if (res.tx) { + transaction = reducers.transactionReducer(res, reducers) + } else { + // on timeout we don't get a transaction back + transaction = { + hash, + success: false, + log: error.message + } + } publishUserTransactionAdded(networkId, senderAddress, transaction) Sentry.withScope(scope => { scope.setExtra('api_url', url) scope.setExtra('hash', hash) scope.setExtra('address', senderAddress) scope.setExtra('transaction', res) + scope.setExtra('broadcast_response', broadcastResponse) Sentry.captureException(error) }) } diff --git a/lib/schema.js b/lib/schema.js index 26c58beccd..71f3854297 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -126,7 +126,7 @@ const typeDefs = gql` type Transaction { type: String! - hash: String # may be null if the transaction is not successful + hash: String! height: Int! group: String! timestamp: String!