Skip to content

Instantly share code, notes, and snippets.

@morkeltry
Created January 22, 2021 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morkeltry/3fabbe630b325698ef3456cd8b762a27 to your computer and use it in GitHub Desktop.
Save morkeltry/3fabbe630b325698ef3456cd8b762a27 to your computer and use it in GitHub Desktop.

Expected behaviour:

scale-info is imported if possible, and the declaration use scale_info::{TypeInfo}; works to import scale_info::TypeInfo to be asccessible as TypeInfo throughout the mod registrations scope

Actual behaviour:

$ cargo contract build

 [1/5] Building cargo project
    Updating crates.io index
   Compiling registrations v0.1.0 (/tmp/cargo-contract_2tPvAR)
error[E0432]: unresolved import `scale_info`
  --> /home/dips/rust/registrations/lib.rs:14:9
   |
14 |     use scale_info::{TypeInfo};
   |         ^^^^^^^^^^ use of undeclared crate or module `scale_info`

error: cannot determine resolution for the derive macro `TypeInfo`
  --> /home/dips/rust/registrations/lib.rs:83:14
   |
83 |     #[derive(TypeInfo)]
   |              ^^^^^^^^
   |
   = note: import resolution is stuck, try simplifying macro imports
[package]
name = "registrations"
version = "0.1.0"
authors = ["[your_name] <[your_email]>"]
edition = "2018"
[dependencies]
ink_primitives = { version = "3.0.0-rc2", default-features = false }
ink_metadata = { version = "3.0.0-rc2", default-features = false, features = ["derive"], optional = true }
ink_env = { version = "3.0.0-rc2", default-features = false }
ink_storage = { version = "3.0.0-rc2", default-features = false }
ink_storage_derive = { version = "3.0.0-rc2", default-features = false }
ink_lang = { version = "3.0.0-rc2", default-features = false }
ink_prelude = { version = "3.0.0-rc2", default-features = false }
ink_core = { version = "0.0.0", default-features = false }
scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] }
scale-info = { package = "scale-info", version = "0.4.1", default-features = false, features = ["derive"], optional = true }
[lib]
name = "registrations"
path = "lib.rs"
crate-type = [
# Used for normal contract Wasm blobs.
"cdylib",
]
[features]
default = ["std"]
std = [
"ink_metadata/std",
"ink_env/std",
"ink_storage/std",
"ink_primitives/std",
"scale/std",
"scale-info/std",
]
ink-as-dependency = []
#![cfg_attr(not(feature = "std"), no_std)]
use ink_lang as ink;
#[ink::contract]
#[macro_use]
mod registrations {
use ink_storage::collections::HashMap;
// use ink_storage::alloc::Box;
use ink_storage_derive::{ PackedLayout, SpreadLayout };
use ink_prelude::vec::Vec;
use scale::{Encode, Decode};
use scale_info::{TypeInfo};
#[ink(event)]
pub struct OfferRegistered {
#[ink(topic)]
id: u32,
#[ink(topic)]
to: Option<AccountId>,
#[ink(topic)]
value: Balance,
}
#[derive(Encode, Decode )]
#[derive(PackedLayout, SpreadLayout)]
struct Bytes32([u8; 4]);
struct TimeBlockCurve {
a: i32,
b: i32,
c: i32,
cliff_start: i32,
}
struct FungibleAsset {
asset_id: u32,
amount: u32,
}
struct NonfungibleAsset {
asset_id: Bytes32,
amount: u32,
}
enum PaymentAsset {
FungibleAsset,
NonfungibleAsset
}
struct ParamsSet<'a> {
params: &'a str,
// params: Vec<Box<&'a str>>,
}
// // TODO:
// struct TimeBlockCurve<'a> {
// node_job_id: JobSpec,
// params: ParamsSet<'a>,
// threshold: f32,
// price: PaymentAsset,
// deposit_curve: Option<TimeBlockCurve>,
// opp_cost_rent_curve: Option<TimeBlockCurve>,
// payment_release_curve: Option<TimeBlockCurve>,
// }
struct Deposit((PaymentAsset, Option<TimeBlockCurve>));
struct EncryptedOffer(Vec<u8>);
struct HashedOffer(Bytes32);
/// Defines the storage of your contract.
/// Add new fields to the below struct in order
/// to add new static storage fields to your contract.
#[ink(storage)]
#[derive(TypeInfo)]
pub struct Registrations {
owner: Option<AccountId>,
offers: HashMap<u32, (Bytes32, Option<(u32, Option<u32>)>)>
// offers: HashMap<u32, (HashedOffer, Option<Deposit>)>
// https://github.com/paritytech/substrate/blob/dd97b1478b31a4715df7e88a5ebc6664425fb6c6/frame/support/src/storage/generator/map.rs#L28
// https://substrate.dev/rustdocs/v2.0.0/frame_support/storage/trait.StorageMap.html
}
impl Registrations {
/// Constructor
#[ink(constructor)]
pub fn new(sudo: bool) -> Self {
Self {
owner: if sudo { Some(Self::env().caller()) } else { None },
offers: HashMap::new()
}
}
/// Constructor that initializes sudo to `true`.
#[ink(constructor)]
pub fn default() -> Self {
Self::new(true)
}
/// Returns contents of storage without index.
#[ink(message)]
pub fn get(&self, key: u32) -> Option<(u32, Option<u32>)> {
match self.offers.get(&key) {
Some(val) => val.1,
None => None
}
}
/// ...
#[ink(message)]
pub fn register(&mut self, enc_offer: Vec<u8>) {
let reg_time= self.env().block_timestamp();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment