chainx-org / chainx-common

Collection of crates used in ChainX projects. (Will be deprecated after upgrading ChainX to v2.0)
GNU General Public License v3.0
2 stars 1 forks source link

ERROR: generate-metadata #19

Open Luca-Poggi opened 4 years ago

Luca-Poggi commented 4 years ago

Hi, I'm coding and testing smartcontracts. I want to test a smartcontract using U256. lib.rs file is:

#![feature(proc_macro_hygiene)]
#![cfg_attr(not(feature = "std"), no_std)]

use ink_core::storage;
use ink_lang2 as ink;
use primitive_types::U256;

#[ink::contract(version = "0.1.0")]
mod big_number {
    #[ink(storage)]
    struct BigNumber {
        // Storage Declaration
    }

    impl BigNumber {
        #[ink(constructor)]
        fn new(&mut self, init_value: i32) {
            // Contract Constructor
        }

        #[ink(message)]
        fn get(&self) {
            // Contract Message
        }

        #[ink(message)]
        fn insert_number(&self, number: U256) {

        }
    }

    #[cfg(test)]
    mod tests {
        use super::*;

        #[test]
        fn default_works() {
            // Test Your Contract
        }
    }
}

Cargo.toml file is:

[package]
name = "big_number"
version = "0.1.0"
authors = ["[your_name] <[your_email]>"]
edition = "2018"

[dependencies]
ink_abi = { git = "https://github.com/chainx-org/ink", branch = "ink2.0", package = "ink_abi", default-features = false, features = ["derive"], optional = true }
ink_core = { git = "https://github.com/chainx-org/ink", branch = "ink2.0", package = "ink_core", default-features = false, features = ["old-codec"] }
ink_lang2 = { git = "https://github.com/chainx-org/ink", branch = "ink2.0", package = "ink_lang2", default-features = false, features = ["old-codec"] }

scale = { package = "parity-codec", version = "3.5", default-features = false, features = ["derive"] }
type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true }
primitive-types = { git = "https://github.com/chainx-org/chainx-common", default-features = false, features = ["codec"] }

[lib]
name = "big_number"
path = "lib.rs"
crate-type = [
    # Used for normal contract Wasm blobs.
    "cdylib",
    # Used for ABI generation.
    "rlib",
]

[features]
default = ["test-env"]
std = [
    "ink_abi/std",
    "ink_core/std",
    "scale/std",
    "type-metadata/std",
]
test-env = [
    "std",
    "ink_core/test-env",
    "ink_lang2/test-env",
]
ink-generate-abi = [
    "std",
    "ink_abi",
    "type-metadata",
    "ink_core/ink-generate-abi",
    "ink_lang2/ink-generate-abi",
]
ink-as-dependency = []

[profile.release]
panic = "abort"
lto = true
opt-level = "z"
overflow-checks = true

[workspace]
members = [
    ".ink/abi_gen"
]
exclude = [
    ".ink"
]
error[E0277]: the trait bound primitive_types::U256: type_metadata::type_def::HasTypeDef is not satisfied --> lib.rs:8:1 8 #[ink::contract(version = "0.1.0")] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait type_metadata::type_def::HasTypeDef is not implemented for primitive_types::U256
::: /home/luca/.cargo/git/checkouts/ink-9c358e34fc403586/024347d/abi/src/specs.rs:625:12 625 T: Metadata, -------- required by this bound in ink_abi::specs::TypeSpec::with_name_segs
= note: required because of the requirements on the impl of `type_metadata::Metadata` for `primitive_types::U256`

error: aborting due to 2 previous errors

For more information about this error, try rustc --explain E0277. error: could not compile big_number.



Are there some suggestions to solve this ERROR?
koushiro commented 4 years ago

As the error message shows, the U256 type does not implement the Metadata trait. (Here are all types that implement the Metadata trait)

If you want to use U256 type in smart contract written with ink!, please implement the U256 type and implement the Metadata trait for it by yourself.