1

I am trying to upgrade then compile a token contract (employing openbrush) from ink!3 to ink!4.

My understanding is that SpreadAllocate, StorageLayout, etc. have been removed from the ink!4 release.

The problem is that I have custom data structures that cargo still expects the StorageLayout trait to be implemented for.

How do I work around this?

Context:

  • this is built using cargo-contract version 2.0.0-beta
  • this project uses Openbrush 3 (Cargo.toml included below)

Here are the structs in question:

    #[derive(scale::Encode, scale::Decode, Clone)]
    #[cfg_attr(
    feature = "std",
    derive(scale_info::TypeInfo)
    )]
    #[derive(Debug)]
    pub struct StakeholderData {
        paid: Balance,
        share: Balance,
        pool: u8,
    }

    #[derive(scale::Encode, scale::Decode, Clone, Default)]
    #[cfg_attr(
    feature = "std",
    derive(scale_info::TypeInfo)
    )]
    pub struct Port {
        hash: Hash,
        tax: Balance,
        cap: Balance,
        locked: bool,
        paid: Balance,
        collected: Balance,
    }

    #[derive(scale::Encode, scale::Decode, Clone, Default)]
    #[cfg_attr(
    feature = "std",
    derive(scale_info::TypeInfo)
    )]
    pub struct Socket {
        address: AccountId,
        port: u16,
    }

Cargo.toml below:

[package]
name = "ilocktoken"
version = "0.1.0"
authors = ["Blair Munro <[email protected]>"]
edition = "2021"

# This is to enable unsigned integer division (floor division)
# ...safe-math functions are used for lib.rs arithmetic where overflow checks would otherwise be
#    (that is, in all cases except the few floor division operations)
[profile.release]
overflow-checks = false

[dependencies]
ink = { git = "https://github.com/paritytech/ink", commit = "4655a8b4413cb50cbc38d1b7c173ad426ab06cde", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }

openbrush = { tag = "3.0.0-beta", git = "https://github.com/727-Ventures/openbrush-contracts", default-features = false, features = ["psp22", "ownable"] }
[lib]
name = "ilocktoken"
path = "lib.rs"
crate-type = [
    # Used for normal contract Wasm blobs.
    "cdylib",
]

[features]
default = ["std"]
std = [
    "ink/std",
    "scale/std",
    "scale-info/std",

    "openbrush/std",
]

ink-as-dependency = []

And here is a screenshot of the cargo build log:

enter image description here

Thank you for the insight and understanding.

1 Answer 1

1

Easy fix. I was mistaken to assert that ink!4 does not have the StorageLayout trait.

Per ink multisig reference implementation, StorageLayout must be be derived as so:

    #[derive(scale::Encode, scale::Decode, Clone, Default)]
    #[cfg_attr(
    feature = "std",
    derive(
        Debug,
        PartialEq,
        Eq,
        scale_info::TypeInfo,
        ink::storage::traits::StorageLayout    // <----- ! derive as so
        )
    )]
    pub struct StakeholderData {
        paid: Balance,
        share: Balance,
        pool: u8,
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.