Skip to content

Commit

Permalink
Merge pull request #13 from archetype-org/accounts
Browse files Browse the repository at this point in the history
Use predecessor account for manifests
  • Loading branch information
corydickson authored Feb 27, 2024
2 parents a7345df + 8d84802 commit 4590d87
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,34 @@ impl Contract {
package_name: String,
version: String,
content_type: String,
cid: String
cid: String,
is_contract: bool,
) {
let manifest = Manifest {
version,
content_type,
cid
};

if !self.packages.contains_key(&near_sdk::env::signer_account_id()) {
let mut author = near_sdk::env::signer_account_id();

if is_contract {
author = near_sdk::env::predecessor_account_id();
}

if !self.packages.contains_key(&author) {
self.packages.insert(
&near_sdk::env::signer_account_id(),
&author,
&LookupMap::new(PrefixKeys::Manifest)
);

log_str(&format!("Creating storage..."));
let mut manifests = self.packages.get(&near_sdk::env::signer_account_id()).unwrap();
let mut manifests = self.packages.get(&author).unwrap();
manifests.insert(&package_name, &mut Vec::new());
}

log_str(&format!("Writing manifest for {package_name}..."));
let mut manifests = self.packages.get(&near_sdk::env::signer_account_id()).unwrap();
let mut manifests = self.packages.get(&author).unwrap();
let mut versions = manifests.get(&package_name)
.unwrap();

Expand Down Expand Up @@ -268,7 +275,8 @@ mod tests {
name.clone(),
version.clone(),
content_type.clone(),
cid.clone()
cid.clone(),
false
);
assert_eq!(
contract.get_manifest(context.signer_account_id.clone(), name.clone(), version.clone()),
Expand All @@ -290,7 +298,8 @@ mod tests {
name.clone(),
version.clone(),
content_type.clone(),
cid.clone()
cid.clone(),
false
);

let new_cid = "QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n".to_string();
Expand Down Expand Up @@ -323,7 +332,8 @@ mod tests {
name.clone(),
version.clone(),
content_type.clone(),
cid.clone()
cid.clone(),
false
);


Expand Down

0 comments on commit 4590d87

Please sign in to comment.