#Need help with an error

8 messages · Page 1 of 1 (latest)

unborn stirrup
#

I tried creating a staking canister and got this error message.

error[E0432]: unresolved import self::matrix::BandMatrix
--> /home/elari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/storage-0.5.0/src/matrix.rs:5:9
|
5 | pub use self::matrix::BandMatrix;
| ^^^^^^^^^^^^^^^^^^^^^^^^ no BandMatrix in the root

error[E0432]: unresolved imports self::matrix::CompressedMatrix, self::matrix::CompressedFormat
--> /home/elari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/storage-0.5.0/src/matrix.rs:6:24
|
6 | pub use self::matrix::{CompressedMatrix, CompressedFormat};
| ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ no CompressedFormat in the root
| |
| no CompressedMatrix in the root

error[E0432]: unresolved imports self::matrix::PackedMatrix, self::matrix::PackedFormat
--> /home/elari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/storage-0.5.0/src/matrix.rs:8:24
|
8 | pub use self::matrix::{PackedMatrix, PackedFormat};
| ^^^^^^^^^^^^ ^^^^^^^^^^^^ no PackedFormat in the root
| |
| no PackedMatrix in the root

I can send the code if that makes it easier to help . Storage0.5.0 is installed andplaced in my dependencies already.

obsidian agate
#

You can put ``` on a line by itself before and after your error message. Also, changing the top ``` to ```rust will give syntax highlighting for Rust code.

#

Try an earlier version.

unborn stirrup
#

hi Chai T, still battling with this task. So am trying to create a staking canister with rust. Am trying to create tokens that can be staked for a specific period of time say 30days, 60 days, 90days and 180days. When staker withdraws, a penalty will be issued based on the amount of days left for the stake to end. I used another logic for the code. The error i am getting now is that i can not borrow *self as mutable more than once at a time . Here is the code. please help explain how i can resolve this or point me to materials where i get read or watch to get better understanding

#

use std::collections::HashMap;
use ic_cdk::api;
use ic_cdk::export::Principal;

// Define a struct for the staking token
#[derive(Clone, Debug, PartialEq, Eq, Default)]
struct Token {
name: String,
symbol: String,
total_supply: u64,
}

// Define a struct for the staking details
#[derive(Clone, Debug, PartialEq, Eq)]
struct StakingDetails {
amount: u64,
start_timestamp: u64,
end_timestamp: u64,
}

// Define a struct for the staking account
#[derive(Clone, Debug, PartialEq, Eq, Default)]
struct StakingAccount {
balance: u64,
staking_details: HashMap<Principal, StakingDetails>,
}

// Define the staking canister
#[derive(Default)]
struct StakingCanister {
// Define the token
token: Token,
// Define the staking accounts
accounts: HashMap<Principal, StakingAccount>,
}

impl StakingCanister {
fn get_account(&mut self, caller: Principal) -> &mut StakingAccount {
self.accounts.entry(caller).or_default()
}

#

fn stake( &mut self, amount: u64, duration: u64) {
// Get the caller's principal ID
let caller: Principal = api::caller();

    // Get the staking account for the caller
    let account = self.get_account(caller);

    // Check if the caller has enough balance to stake the requested amount
    if account.balance < amount {
        ic_cdk::trap("Insufficient balance");
    }

    // Calculate the start and end timestamps for the staking period
    let current_timestamp = api::time();

    let start_timestamp = current_timestamp;
    let end_timestamp = start_timestamp + duration;

    // Add the staking details to the account
    let staking_details = StakingDetails { amount, start_timestamp, end_timestamp };
    account.staking_details.insert(caller, staking_details);

    // Update the balance of the staking account
    account.balance -= amount;
}


fn withdraw(&mut self) {
    // Get the caller's principal ID
    let caller = api::caller();

    // Get the staking account for the caller
    let account = self.get_account(caller);

    // Calculate the current timestamp
    let current_timestamp = api::time();

    // Calculate the penalty for early withdrawal
    let mut penalty = 0;

    for (_, staking_details) in account.staking_details.iter() {
        if current_timestamp < staking_details.end_timestamp {
            let days_left = (staking_details.end_timestamp - current_timestamp) / 86400;
            penalty += staking_details.amount * days_left / 100;
        }
    }

    // Calculate the total amount to be returned
    let total_amount = account.balance + penalty;

    // Clear the staking details from the account
    account.staking_details.clear();

    // Update the balance of the staking account
    account.balance = total_amount;
}