|
| 1 | +use near_sdk::{ |
| 2 | + assert_one_yocto, |
| 3 | + borsh::{self, BorshDeserialize, BorshSerialize}, |
| 4 | + collections::{LookupMap, TreeMap, UnorderedMap, Vector}, |
| 5 | + env, |
| 6 | + json_types::{Base64VecU8, ValidAccountId, U128, U64}, |
| 7 | + log, near_bindgen, |
| 8 | + serde::{Deserialize, Serialize}, |
| 9 | + serde_json::json, |
| 10 | + AccountId, Balance, BorshStorageKey, Gas, PanicOnDefault, Promise, StorageUsage, |
| 11 | +}; |
| 12 | + |
| 13 | +mod owner; |
| 14 | +mod storage_impl; |
| 15 | +mod utils; |
| 16 | +mod views; |
| 17 | + |
| 18 | +near_sdk::setup_alloc!(); |
| 19 | + |
| 20 | +// Balance & Fee Definitions |
| 21 | +pub const ONE_NEAR: u128 = 1_000_000_000_000_000_000_000_000; |
| 22 | +pub const GAS_BASE_PRICE: Balance = 100_000_000; |
| 23 | +pub const GAS_BASE_FEE: Gas = 3_000_000_000_000; |
| 24 | +pub const STAKE_BALANCE_MIN: u128 = 10 * ONE_NEAR; |
| 25 | + |
| 26 | + |
| 27 | +// #[derive(BorshStorageKey, BorshSerialize)] |
| 28 | +// pub enum StorageKeys { |
| 29 | +// Tasks, |
| 30 | +// Agents, |
| 31 | +// Slots, |
| 32 | +// AgentsActive, |
| 33 | +// AgentsPending, |
| 34 | +// } |
| 35 | + |
| 36 | +#[near_bindgen] |
| 37 | +#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)] |
| 38 | +pub struct Contract { |
| 39 | + // Runtime |
| 40 | + paused: bool, |
| 41 | + owner_id: AccountId, |
| 42 | + |
| 43 | + // Storage |
| 44 | + // agent_storage_usage: StorageUsage, |
| 45 | +} |
| 46 | + |
| 47 | +#[near_bindgen] |
| 48 | +impl Contract { |
| 49 | + /// ```bash |
| 50 | + /// near call cron.testnet new --accountId cron.testnet |
| 51 | + /// ``` |
| 52 | + #[init] |
| 53 | + pub fn new() -> Self { |
| 54 | + let mut this = Contract { |
| 55 | + paused: false, |
| 56 | + owner_id: env::signer_account_id(), |
| 57 | + }; |
| 58 | + // this.measure_account_storage_usage(); |
| 59 | + this |
| 60 | + } |
| 61 | + |
| 62 | + // /// Measure the storage an agent will take and need to provide |
| 63 | + // fn measure_account_storage_usage(&mut self) { |
| 64 | + // let initial_storage_usage = env::storage_usage(); |
| 65 | + // // Create a temporary, dummy entry and measure the storage used. |
| 66 | + // let tmp_account_id = "a".repeat(64); |
| 67 | + // let tmp_agent = Agent { |
| 68 | + // status: agent::AgentStatus::Pending, |
| 69 | + // payable_account_id: tmp_account_id.clone(), |
| 70 | + // balance: U128::from(0), |
| 71 | + // total_tasks_executed: U128::from(0), |
| 72 | + // last_missed_slot: 0, |
| 73 | + // }; |
| 74 | + // self.agents.insert(&tmp_account_id, &tmp_agent); |
| 75 | + // self.agent_storage_usage = env::storage_usage() - initial_storage_usage; |
| 76 | + // // Remove the temporary entry. |
| 77 | + // self.agents.remove(&tmp_account_id); |
| 78 | + // } |
| 79 | +} |
| 80 | + |
| 81 | +// #[cfg(test)] |
| 82 | +// mod tests { |
| 83 | +// use super::*; |
| 84 | +// use near_sdk::json_types::ValidAccountId; |
| 85 | +// use near_sdk::test_utils::{accounts, VMContextBuilder}; |
| 86 | +// use near_sdk::{testing_env, MockedBlockchain}; |
| 87 | + |
| 88 | +// const BLOCK_START_BLOCK: u64 = 52_201_040; |
| 89 | +// const BLOCK_START_TS: u64 = 1_624_151_503_447_000_000; |
| 90 | + |
| 91 | +// fn get_context(predecessor_account_id: ValidAccountId) -> VMContextBuilder { |
| 92 | +// let mut builder = VMContextBuilder::new(); |
| 93 | +// builder |
| 94 | +// .current_account_id(accounts(0)) |
| 95 | +// .signer_account_id(predecessor_account_id.clone()) |
| 96 | +// .signer_account_pk(b"ed25519:4ZhGmuKTfQn9ZpHCQVRwEr4JnutL8Uu3kArfxEqksfVM".to_vec()) |
| 97 | +// .predecessor_account_id(predecessor_account_id) |
| 98 | +// .block_index(BLOCK_START_BLOCK) |
| 99 | +// .block_timestamp(BLOCK_START_TS); |
| 100 | +// builder |
| 101 | +// } |
| 102 | + |
| 103 | +// #[test] |
| 104 | +// fn test_contract_new() { |
| 105 | +// let mut context = get_context(accounts(1)); |
| 106 | +// testing_env!(context.build()); |
| 107 | +// let contract = Contract::new(); |
| 108 | +// testing_env!(context.is_view(true).build()); |
| 109 | +// assert!(contract.get_tasks(None, None, None).is_empty()); |
| 110 | +// } |
| 111 | +// } |
0 commit comments