Skip to content

Commit

Permalink
address's Frol's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ailisp committed Dec 22, 2023
1 parent c64e59e commit f367ea5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
4 changes: 2 additions & 2 deletions community-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use near_sdk::{env, near_bindgen, require, AccountId, Gas, NearToken, Promise};
const CODE: &[u8] = include_bytes!("../../res/devhub_community.wasm");
const INITIAL_BALANCE: NearToken = NearToken::from_near(2);
const PUBKEY_STR: &str = "ed25519:4deBAvg1S4MF7qe9GBDJwDCGLyyXtJa73JnMXwyG9vsB";
const DEVHUB: &str = "devgovgigs.near";
const DEVHUB: &near_sdk::AccountIdRef = near_sdk::AccountIdRef::new_or_panic("devhub.near");

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, Default)]
Expand All @@ -14,7 +14,7 @@ pub struct Contract {}
impl Contract {
#[payable]
pub fn create_community_account(&mut self, community: String) -> Promise {
let devhub_account: AccountId = DEVHUB.parse().unwrap();
let devhub_account: AccountId = DEVHUB.into();
require!(
env::predecessor_account_id() == devhub_account,
"Can only be called from DevHub contract"
Expand Down
11 changes: 6 additions & 5 deletions community/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
mod social_db;

use crate::social_db::{ext_social_db, SOCIAL_DB};
use near_sdk::borsh;
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::{env, near_bindgen, require, AccountId, NearToken, Promise};

const DEVHUB: &str = "devgovgigs.near";
const DEVHUB: &near_sdk::AccountIdRef = near_sdk::AccountIdRef::new_or_panic("devhub.near");

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, Default)]
Expand All @@ -14,23 +15,23 @@ pub struct Contract {}
impl Contract {
#[init]
pub fn new() -> Self {
ext_social_db::ext(SOCIAL_DB.parse().unwrap())
ext_social_db::ext(SOCIAL_DB.into())
.with_unused_gas_weight(1)
.with_attached_deposit(NearToken::from_near(1))
.grant_write_permission(
Some(DEVHUB.parse().unwrap()),
Some(DEVHUB.into()),
None,
vec![env::current_account_id().to_string()],
);
Contract {}
}

pub fn destroy(&mut self) {
let devhub_account: AccountId = DEVHUB.parse().unwrap();
let devhub_account: AccountId = DEVHUB.into();
require!(
env::predecessor_account_id() == devhub_account,
"Can only destroy community account from DevHub contract"
);
Promise::new(env::current_account_id()).delete_account(DEVHUB.parse().unwrap());
Promise::new(env::current_account_id()).delete_account(devhub_account);
}
}
2 changes: 1 addition & 1 deletion community/src/social_db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use near_sdk::serde_json::Value;
use near_sdk::{ext_contract, AccountId, PublicKey};

pub const SOCIAL_DB: &str = "social.near";
pub const SOCIAL_DB: &near_sdk::AccountIdRef = near_sdk::AccountIdRef::new_or_panic("social.near");

#[ext_contract(ext_social_db)]
pub trait SocialDB {
Expand Down
12 changes: 3 additions & 9 deletions tests/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use near_workspaces::{Account, AccountId, Worker};

use serde_json::json;

const DEVHUB_CONTRACT_PREFIX: &str = "devgovgigs";
const DEVHUB_CONTRACT: &str = "devgovgigs.near";
const DEVHUB_CONTRACT_PREFIX: &str = "devhub";
const DEVHUB_CONTRACT: &str = "devgovgigs.near"; // current production contract
const NEW_DEVHUB_CONTRACT_PREFIX: &str = "devhub";
const COMMUNITY_FACTORY_PREFIX: &str = "community";
const NEAR_SOCIAL: &str = "social.near";
Expand Down Expand Up @@ -82,13 +82,7 @@ pub async fn init_contracts_from_res(
let contract = contract_account.deploy(&contract_wasm).await?.into_result()?;
let outcome = contract.call("new").args_json(json!({})).transact().await?;

let new_devhub_account = tla_near
.create_subaccount(NEW_DEVHUB_CONTRACT_PREFIX)
.initial_balance(parse_near!("100 N"))
.transact()
.await?
.into_result()?;
let community_factory_account = new_devhub_account
let community_factory_account = contract_account
.create_subaccount(COMMUNITY_FACTORY_PREFIX)
.initial_balance(parse_near!("10 N"))
.transact()
Expand Down

0 comments on commit f367ea5

Please sign in to comment.