2

In the near_primitives::views, the args field on the FunctionCall is represented as a String type. From the chain data model, which is transaction::Action::FunctionCall, its args field there is a `Vec.

The question is, does this args field will always content a valid JSON payload as the content? We assume the answer is probably a No since the underlying field contains pure bytes.

In which circumstances this would a valid JSON string and in which circumstances it would be a binary format?

Finally, if binary format is possible (likely), how is it possible to decode it? Is this in developers hand and could be any binary format?

See

Matt
  • 10,633
  • 3
  • 46
  • 49

2 Answers2

2

In most cases args will be base64 encoded JSON string.

Here's an example of how we decode them on NEAR Indexer for Explorer side.

ActionView::FunctionCall {
    method_name,
    args,
    gas,
    deposit,
} => {
    if let Ok(decoded_args) = base64::decode(args) {
        if let Ok(mut args_json) = serde_json::from_slice(&decoded_args) {
            escape_json(&mut args_json);
            arguments["args_json"] = args_json;
        }
    }

Is this in developers hand and could be any binary format?

Yes.

Rainbow Bridge-related transactions have borsh-serialized args which are not possible to decode into JSON.

ref: https://github.com/near/near-indexer-for-explorer/blob/master/src/models/serializers.rs#L94-L103

khorolets
  • 666
  • 3
  • 8
1

args are not limited to any format at all, they are just binary blob. What you see in the views.rs is partially serialized data where args are expected to be in base64 encoding thus it is a String (thus, it is always base64 data there; be it JSON, Borsh-serialized data, or just raw binary blob, e.g. PNG image)

Vlad Frolov
  • 7,445
  • 5
  • 33
  • 52