Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
fix: do not panic when there is an empty data field in MessageOut r…
Browse files Browse the repository at this point in the history
…eceipt (#705)

* Do not panic when there is an empty data field in MessageOut receipt

* Address feedback; format quoted code
  • Loading branch information
deekerno authored Mar 24, 2023
1 parent ade8040 commit 1a88172
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions packages/fuel-indexer-macros/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ fn process_fn_items(
}
}
})
.chain(
vec![quote! {
u64::MAX => {
{}
}
}]
.into_iter(),
)
.collect::<Vec<proc_macro2::TokenStream>>();

let abi_type_decoders = abi_types
Expand Down Expand Up @@ -463,10 +471,25 @@ fn process_fn_items(
}
}
Receipt::MessageOut { message_id, sender, recipient, amount, nonce, len, digest, data } => {
let mut buf = [0u8; 8];
buf.copy_from_slice(&data[0..8]);
let type_id = u64::from_be_bytes(buf);
let receipt = abi::MessageOut{ message_id, sender, recipient, amount, nonce, len, digest, data: data[8..].to_vec() };
// It's possible that the data field was generated from an empty Sway `Bytes` array
// in the send_message() instruction in which case the data field in the receipt will
// have no type information or data to decode, so we decode an empty vector to a unit struct
let type_id = data
.get(..8)
.map(|buffer| {
u64::from_be_bytes(
<[u8; 8]>::try_from(&buffer[..])
.expect("Could not get type ID for data in MessageOut receipt"),
)
})
.unwrap_or(u64::MAX);

let data = data
.get(8..)
.map(|buffer| buffer.to_vec())
.unwrap_or(Vec::<u8>::new());

let receipt = abi::MessageOut{ message_id, sender, recipient, amount, nonce, len, digest, data };
decoder.decode_messageout(type_id, receipt);
}
Receipt::ScriptResult { result, gas_used } => {
Expand Down

0 comments on commit 1a88172

Please sign in to comment.