Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
fix: api server no longer crashes on empty transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Apr 9, 2019
1 parent 1eae14a commit 7b692d7
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions api/inbound-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class BridgeFn {
});

tx.fee = txn.fee;
tx.last_id = txn.lastId;
tx.recent_blockhash = txn.recentBlockhash;

return tx;
});
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down

0 comments on commit 7b692d7

Please sign in to comment.