From 8d84802fd63797e1cb814c30f1731d96367e4654 Mon Sep 17 00:00:00 2001 From: Cory Dickson Date: Tue, 27 Feb 2024 12:59:45 -0500 Subject: [PATCH] Use predecessor account for manifests --- src/lib.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 86cff27..02af50f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,7 +88,8 @@ impl Contract { package_name: String, version: String, content_type: String, - cid: String + cid: String, + is_contract: bool, ) { let manifest = Manifest { version, @@ -96,19 +97,25 @@ impl Contract { 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(); @@ -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()), @@ -290,7 +298,8 @@ mod tests { name.clone(), version.clone(), content_type.clone(), - cid.clone() + cid.clone(), + false ); let new_cid = "QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n".to_string(); @@ -323,7 +332,8 @@ mod tests { name.clone(), version.clone(), content_type.clone(), - cid.clone() + cid.clone(), + false );