Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type def #20

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading