Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Fix crash in non enhanced json
Browse files Browse the repository at this point in the history
  • Loading branch information
madninja committed Jul 1, 2021
1 parent 65fa681 commit 332bc09
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/bn_txns.erl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ get_transaction_json(Hash, State = #state{db = DB, json = JsonCF}) ->
case get_transaction(Hash, State) of
{ok, {Height, Txn}} ->
Json = blockchain_txn:to_json(Txn, []),
Json#{block => Height};
{ok, Json#{block => Height}};
Error ->
Error
end;
Expand All @@ -152,10 +152,11 @@ save_transactions(Height, Transactions, Ledger, Chain, #state{
{ok, Batch} = rocksdb:batch(),
HeightBin = <<Height:64/integer-unsigned-little>>,
lists:foreach(
fun (Txn) ->
fun(Txn) ->
Hash = blockchain_txn:hash(Txn),
Json =
try blockchain_txn:to_json(Txn, [{ledger, Ledger}, {chain, Chain}])
try
blockchain_txn:to_json(Txn, [{ledger, Ledger}, {chain, Chain}])
catch
_:_ ->
blockchain_txn:to_json(Txn, [])
Expand All @@ -170,7 +171,7 @@ save_transactions(Height, Transactions, Ledger, Chain, #state{
Batch,
JsonCF,
Hash,
jsone:encode(Json, [undefined_as_null])
jsone:encode(Json#{block => Height}, [undefined_as_null])
),
ok = rocksdb:batch_put(Batch, HeightsCF, Hash, HeightBin)
end,
Expand Down

0 comments on commit 332bc09

Please sign in to comment.