Skip to content

Commit

Permalink
Add type def (#20)
Browse files Browse the repository at this point in the history
* Add type storage

* Add attest to type

* Remove unused import
  • Loading branch information
corydickson authored Apr 29, 2024
1 parent 16a1030 commit 1f27b19
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::env::log_str;
use near_sdk::serde::{Serialize, Deserialize};
use near_sdk::collections::LookupMap;
use near_sdk::collections::{LookupMap, UnorderedMap};
use near_sdk::near_bindgen;
use near_sdk::{
AccountId, BorshStorageKey, PublicKey, require
Expand Down Expand Up @@ -52,7 +52,7 @@ pub struct Contract {
// A signer can submit an attestation for a particular package already in the registry
pub attestations: LookupMap<AccountId, LookupMap<Namespace, Attestations>>,
pub compiled_types: LookupMap<Namespace, Types>,
pub type_list: LookupMap<String, u8>,
pub type_list: UnorderedMap<String, u8>,
}

impl Default for Contract {
Expand All @@ -61,7 +61,7 @@ impl Default for Contract {
packages: LookupMap::new(PrefixKeys::Package),
attestations: LookupMap::new(PrefixKeys::Attestation),
compiled_types: LookupMap::new(PrefixKeys::Types),
type_list: LookupMap::new(PrefixKeys::TypeList)
type_list: UnorderedMap::new(PrefixKeys::TypeList)
}
}
}
Expand Down Expand Up @@ -319,6 +319,23 @@ impl Contract {

return at[index].clone();
}

pub fn attest_to_type(
&mut self,
// An account ID of the author who published the manifest
author: AccountId,
// Name of a type in a package
type_name: String,
) {
if self.attestations.contains_key(&author) {
let count: u8 = match self.type_list.get(&type_name) {
Some(v) => v + 1u8,
None => 1u8,
};

self.type_list.insert(&type_name, &count);
}
}
}

#[cfg(all(test, not(target_arch = "wasm32")))]
Expand Down

0 comments on commit 1f27b19

Please sign in to comment.