snjax / near-sdk-pure-rs

MIT License
0 stars 1 forks source link

possible borsh bug #2

Closed thor314 closed 3 years ago

thor314 commented 3 years ago

Running into a possible pure_near_sdk borsh bug. I have a type that wraps a HashMap.

#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, Clone)]
#[serde(crate = "near_sdk::serde")]
pub struct Royalty {
  pub split_between: HashMap<AccountId, Fraction>,
}

HashMap is being pulled from std, but I don't think this is causing the problem.

After swapping

use near_sdk::{
  borsh::{self, BorshDeserialize, BorshSerialize},
  env,
  serde::{Deserialize, Serialize},
  AccountId, Balance, Gas,
};

for

use near_sdk_pure::{
  borsh::{self, BorshDeserialize, BorshSerialize},
  env,
  serde::{Deserialize, Serialize},
  AccountId, Balance, Gas,
};

compilation returns the error:

error[E0277]: the trait bound `std::collections::HashMap<std::string::String, Fraction>: BorshSerialize` is not satisfied
   --> pure_utils/src/lib.rs:215:10
    |
215 | #[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
    |          ^^^^^^^^^^^^^^ the trait `BorshSerialize` is not implemented for `std::collections::HashMap<std::string::String, Fraction>`
    |
    = help: see issue #48214
    = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
snjax commented 3 years ago

@thor314, for no_std environment we use hashbrown::hash_map::HashMap. It is available from borsh::maybestd::collections::HashMap.

thor314 commented 3 years ago

got a giggle out of maybe_std. Thanks.