|
#![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(); |
|
} |
|
|
|
} |
|
} |
|
|