Skip to content

Commit

Permalink
chore: recover previous version
Browse files Browse the repository at this point in the history
  • Loading branch information
palozano committed Jul 2, 2024
1 parent 908a83c commit b7fcb3d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 90 deletions.
58 changes: 26 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 34 additions & 57 deletions contracts/blob-registry/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{Maintainer, Namespace};
use near_sdk::{
env::log_str,
serde::{Deserialize, Serialize},
serde_json,
serde_json::to_string,
};

const CONTRACT_STANDARD_NAME: &str = "nepXXX";
Expand All @@ -16,7 +16,7 @@ const CONTRACT_STANDARD_VERSION: &str = "1.0.0";
/// * `event`: associate event data
#[derive(Serialize, Deserialize, Debug)]
#[serde(crate = "near_sdk::serde")]
pub struct EventLog {
pub(crate) struct EventLog {
pub standard: String,
pub version: String,
#[serde(flatten)]
Expand All @@ -29,42 +29,9 @@ pub struct EventLog {
#[serde(rename_all = "snake_case")]
#[serde(crate = "near_sdk::serde")]
#[non_exhaustive]
pub enum EventLogVariant {
pub(crate) enum EventLogVariant {
AddMaintainer(AddMaintainerLog),
OwnerTransfer(OwnerEvent),
}

/// An event to log the submission of a blob.
///
/// Arguments
/// * `namespace`: "namespace.near"
/// * `blob_id`: "blob.near"
/// * `memo`: optional message
#[derive(Serialize, Deserialize, Debug)]
#[serde(crate = "near_sdk::serde")]
pub struct BlobSubmissionLog {
pub who: AccountId,
pub namespace: u32,
pub blob: Vec<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
pub memo: Option<String>,
}

/// Log the submission of a blob by `log_str`ing an [`EventLogVariant::BlobSubmissionLog`].
pub(crate) fn log_blob_submission(namespace: u32, blob: Vec<u8>) {
let log = EventLog {
standard: CONTRACT_STANDARD_NAME.to_string(),
version: CONTRACT_STANDARD_VERSION.to_string(),
event: EventLogVariant::BlobSubmission(BlobSubmissionLog {
who: predecessor_account_id(),
namespace,
blob,
memo: None,
}),
};
log_str(&log.to_string());
}

NamespaceRegistration(NamespaceRegistrationLog),
}

/// An event log to capture a maintainer inclusion.
Expand All @@ -74,39 +41,49 @@ pub(crate) fn log_blob_submission(namespace: u32, blob: Vec<u8>) {
/// * `memo`: optional message
#[derive(Serialize, Deserialize, Debug)]
#[serde(crate = "near_sdk::serde")]
pub struct AddMaintainerLog {
pub(crate) struct AddMaintainerLog {
pub maintainer: Maintainer,
#[serde(skip_serializing_if = "Option::is_none")]
pub memo: Option<String>,
}

/// An event log to capture an ownership transfer.
///
/// Arguments
/// * `authorized_id`: approved account to transfer
/// * `old_owner_id`: "owner.near"
/// * `new_owner_id`: "receiver.near"
/// * `memo`: optional message
#[derive(Serialize, Deserialize, Debug)]
#[serde(crate = "near_sdk::serde")]
pub struct OwnershipTransferLog {
#[serde(skip_serializing_if = "Option::is_none")]
pub authorized_id: Option<String>,
pub old_owner_id: String,
pub new_owner_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub memo: Option<String>,
}

/// An event log to capture a new namespace registration.
///
/// Arguments
/// * `namespace`: u32 that has been registered
/// * `memo`: optional message
#[derive(Serialize, Deserialize, Debug)]
#[serde(crate = "near_sdk::serde")]
pub struct NamespaceRegistrationLog {
pub(crate) struct NamespaceRegistrationLog {
pub namespace: Namespace,
#[serde(skip_serializing_if = "Option::is_none")]
pub memo: Option<String>,
}

impl EventLog {
fn new(event: EventLogVariant) -> Self {
Self {
standard: CONTRACT_STANDARD_NAME.to_string(),
version: CONTRACT_STANDARD_VERSION.to_string(),
event,
}
}

pub(crate) fn maintainer(maintainer: Maintainer) {
let log = EventLog::new(EventLogVariant::AddMaintainer(AddMaintainerLog {
maintainer,
memo: None,
}));
log_str(&to_string(&log).unwrap());
}

pub(crate) fn namespace(namespace: Namespace) {
let log = EventLog::new(EventLogVariant::NamespaceRegistration(
NamespaceRegistrationLog {
namespace,
memo: None,
},
));
log_str(&to_string(&log).unwrap());
}
}
2 changes: 1 addition & 1 deletion contracts/blob-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Contract {
}

/// Submit the blob and the namespace.
pub fn submit(&self, namespace: Namespace, transaction_ids: Vec<TransactionId>) {
pub fn submit(&self, namespace: Namespace, _transaction_ids: Vec<TransactionId>) {
// check the namespace exists and the caller is in the maintainers list
match self.check_authorized(namespace) {
Some(_) => {
Expand Down

0 comments on commit b7fcb3d

Please sign in to comment.