I have a question about reading data in a chain extension. To be precise, I'm concerned about methods Environment<_,_,_,S: BufIn>::read*
. Do I understand correctly, that every such function doesn't move starting pointer and thus I can make only a single read?
If so, then I would like to ask whether there are any reasons for that. My use case where it is kinda onerous, is when my chain extension has such an API:
fn extension(a: SomeSizedType, b: Vec<u8>) {...}
The approach that would be natural for me would be to do parsing like:
let env = env.buf_in_buf_out();
let a = env.read_as<SomeSizedType>()?;
// The caller is expected to pass length hint
let b_len = env.read_as<u32>()?;
let b = env.read(b_len);
However, when I can invoke read*
only once, I have to handle decoding and byte array mess on my site. Please notice, that I cannot pack a
and b
into a single struct, and use read_as
, because Vec<_>
is not MaxEncodedLen
.