Search code examples
rustnearprotocol

near-bindgen macro: unsupported argument type


I am writing a smart contract promise interface for NEAR blockchain.

I have the following interface:

#[ext_contract(token_receiver)]
pub trait ExtTokenReceiver {

    fn process_token_received(&self, sender_id: AccountId, amount: Balance, message: [u8]) -> Option<String>;
}

However this fails with the following error:

error: Unsupported argument type.
  --> src/token.rs:32:1
   |
32 | #[ext_contract(token_receiver)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
  • How can I debug near-bindgen macro
  • What is the Unsupported argument type in this case
  • How to fix my interface

Solution

  • I believe the unsupported arguments is [u8]. I have changed the code to use Vec and it works:

    use near_sdk::ext_contract;
    
    #[ext_contract(token_receiver)]
    pub trait ExtTokenReceiver {
        fn process_token_received(
            &self,
            sender_id: AccountId,
            amount: Balance,
            message: Vec<u8>,
        ) -> Option<String>;
    }
    
        Finished release [optimized] target(s) in 0.05s
    

    What I believe is the issue that the compiler doesn't know the size of the static array at compile time and complains, and Vec as it is a dynamic container that is fine.