From 7b692d720a930a95d9137e0c1f4ba52fbafe3fb5 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Tue, 9 Apr 2019 15:32:59 -0700 Subject: [PATCH] fix: api server no longer crashes on empty transactions --- api/inbound-stream.js | 44 +++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/api/inbound-stream.js b/api/inbound-stream.js index 72dcc30f..08324e5b 100644 --- a/api/inbound-stream.js +++ b/api/inbound-stream.js @@ -59,7 +59,7 @@ class BridgeFn { }); tx.fee = txn.fee; - tx.last_id = txn.lastId; + tx.recent_blockhash = txn.recentBlockhash; return tx; }); @@ -199,7 +199,7 @@ class RedisHandler { tx.entry_id = message.hash; tx.instructions = txn.instructions; tx.fee = txn.fee; - tx.last_id = txn.last_id; + tx.recent_blockhash = txn.recent_blockhash; let txnJson = JSON.stringify(tx); @@ -226,22 +226,34 @@ class RedisHandler { message.s, message.dt, message.hash, - tx.instructions[0].program_id, - tx.instructions[0].keys.join(','), - tx.id, - ].join('#'); + ]; + if (tx.instructions.length > 0) { + txnMsg.push(tx.instructions[0].program_id); + txnMsg.push(tx.instructions[0].keys.join(',')); + } else { + // Transactions should always have at least one instruction. But if + // the Transaction was not deserialized correctly we could end up + // here. + txnMsg.push(''); + txnMsg.push(''); + } + txnMsg.push(tx.id); + txnMsg = txnMsg.join('#'); + commands.push(['sadd', `!ent-txn:${message.hash}`, tx.id]); commands.push(['lpush', '!txn-timeline', txnMsg]); - commands.push([ - 'lpush', - `!txns-by-prgid-timeline:${tx.instructions[0].program_id}`, - txnMsg, - ]); - commands.push([ - 'publish', - `@program_id:${tx.instructions[0].program_id}`, - txnMsg, - ]); + if (tx.instructions.length > 0) { + commands.push([ + 'lpush', + `!txns-by-prgid-timeline:${tx.instructions[0].program_id}`, + txnMsg, + ]); + commands.push([ + 'publish', + `@program_id:${tx.instructions[0].program_id}`, + txnMsg, + ]); + } }); if (txCount > 0) {