Disable post tokenization feature

This commit is contained in:
silverpill 2023-03-08 23:16:42 +00:00
parent b5365099a4
commit 268707a78a
8 changed files with 58 additions and 26 deletions

View file

@ -6,9 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Changed
### Removed
- Store NFT monitor state in database.
- Disabled post tokenization (can be re-enabled with `ethereum-extras` feature).
## [1.16.0] - 2023-03-08

View file

@ -92,7 +92,10 @@ web3 = { version = "0.18.0", default-features = false, features = ["http", "http
[dev-dependencies]
mitra-config = { path = "mitra-config", features = ["test-utils"] }
mitra-utils = { path = "mitra-utils", features = ["test-utils"] }
serial_test = "0.7.0"
[features]
ethereum-extras = []
production = ["mitra-config/production"]

View file

@ -133,7 +133,9 @@ pub async fn get_contracts(
};
let minter_abi = load_abi(&config.contract_dir, MINTER)?;
if is_interface_supported(&erc165, &minter_abi).await? {
if cfg!(feature = "ethereum-extras") &&
is_interface_supported(&erc165, &minter_abi).await?
{
let minter = Contract::new(
web3.eth(),
adapter_address,

View file

@ -4,8 +4,10 @@ pub mod eip4361;
mod errors;
pub mod gate;
pub mod identity;
pub mod nft;
pub mod signatures;
pub mod subscriptions;
pub mod sync;
pub mod utils;
#[cfg(feature = "ethereum-extras")]
pub mod nft;

View file

@ -8,6 +8,7 @@ pub fn get_ipfs_url(cid: &str) -> String {
#[error("parse error")]
pub struct ParseError;
#[allow(dead_code)]
pub fn parse_ipfs_url(url: &str) -> Result<String, ParseError> {
let regexp = Regex::new(r"ipfs://(?P<cid>\w+)").unwrap();
let caps = regexp.captures(url).ok_or(ParseError)?;

View file

@ -12,7 +12,6 @@ use crate::activitypub::queues::{
use crate::database::{get_database_client, DbPool};
use crate::ethereum::{
contracts::Blockchain,
nft::process_nft_events,
subscriptions::{
check_ethereum_subscriptions,
update_expired_subscriptions,
@ -28,6 +27,10 @@ use crate::models::{
},
};
#[cfg(feature = "ethereum-extras")]
use crate::ethereum::nft::process_nft_events;
#[cfg(feature = "ethereum-extras")]
pub async fn nft_monitor(
maybe_blockchain: Option<&mut Blockchain>,
db_pool: &DbPool,

View file

@ -11,7 +11,6 @@ use super::periodic_tasks::*;
#[derive(Debug, Eq, Hash, PartialEq)]
enum PeriodicTask {
NftMonitor,
EthereumSubscriptionMonitor,
SubscriptionExpirationMonitor,
MoneroPaymentMonitor,
@ -19,13 +18,15 @@ enum PeriodicTask {
OutgoingActivityQueueExecutor,
DeleteExtraneousPosts,
DeleteEmptyProfiles,
#[cfg(feature = "ethereum-extras")]
NftMonitor,
}
impl PeriodicTask {
/// Returns task period (in seconds)
fn period(&self) -> i64 {
match self {
Self::NftMonitor => 30,
Self::EthereumSubscriptionMonitor => 300,
Self::SubscriptionExpirationMonitor => 300,
Self::MoneroPaymentMonitor => 30,
@ -33,6 +34,9 @@ impl PeriodicTask {
Self::OutgoingActivityQueueExecutor => 5,
Self::DeleteExtraneousPosts => 3600,
Self::DeleteEmptyProfiles => 3600,
#[cfg(feature = "ethereum-extras")]
Self::NftMonitor => 30,
}
}
@ -54,12 +58,14 @@ pub fn run(
) -> () {
tokio::spawn(async move {
let mut scheduler_state = HashMap::from([
(PeriodicTask::NftMonitor, None),
(PeriodicTask::EthereumSubscriptionMonitor, None),
(PeriodicTask::SubscriptionExpirationMonitor, None),
(PeriodicTask::MoneroPaymentMonitor, None),
(PeriodicTask::IncomingActivityQueueExecutor, None),
(PeriodicTask::OutgoingActivityQueueExecutor, None),
#[cfg(feature = "ethereum-extras")]
(PeriodicTask::NftMonitor, None),
]);
if config.retention.extraneous_posts.is_some() {
scheduler_state.insert(PeriodicTask::DeleteExtraneousPosts, None);
@ -77,12 +83,6 @@ pub fn run(
continue;
};
let task_result = match task {
PeriodicTask::NftMonitor => {
nft_monitor(
maybe_blockchain.as_mut(),
&db_pool,
).await
},
PeriodicTask::EthereumSubscriptionMonitor => {
ethereum_subscription_monitor(
&config,
@ -108,6 +108,13 @@ pub fn run(
PeriodicTask::DeleteEmptyProfiles => {
delete_empty_profiles(&config, &db_pool).await
},
#[cfg(feature = "ethereum-extras")]
PeriodicTask::NftMonitor => {
nft_monitor(
maybe_blockchain.as_mut(),
&db_pool,
).await
},
};
task_result.unwrap_or_else(|err| {
log::error!("{:?}: {}", task, err);

View file

@ -13,10 +13,7 @@ use chrono::Utc;
use uuid::Uuid;
use mitra_config::Config;
use mitra_utils::{
currencies::Currency,
markdown::markdown_lite_to_html,
};
use mitra_utils::markdown::markdown_lite_to_html;
use crate::activitypub::builders::{
announce::prepare_announce,
@ -28,12 +25,10 @@ use crate::activitypub::builders::{
};
use crate::database::{get_database_client, DatabaseError, DbPool};
use crate::errors::ValidationError;
use crate::ethereum::nft::create_mint_signature;
use crate::http::{get_request_base_url, FormOrJson};
use crate::ipfs::{
store as ipfs_store,
posts::PostMetadata,
utils::get_ipfs_url,
};
use crate::mastodon_api::{
errors::MastodonError,
@ -47,7 +42,6 @@ use crate::models::{
get_thread,
find_reposts_by_user,
set_post_ipfs_cid,
set_post_token_tx_id,
delete_post,
},
posts::types::{PostCreateData, Visibility},
@ -74,7 +68,6 @@ use super::types::{
StatusData,
StatusPreview,
StatusPreviewData,
TransactionData,
};
#[post("")]
@ -600,6 +593,16 @@ async fn make_permanent(
Ok(HttpResponse::Ok().json(status))
}
#[cfg(feature = "ethereum-extras")]
use {
mitra_utils::currencies::Currency,
crate::ethereum::nft::create_mint_signature,
crate::ipfs::utils::get_ipfs_url,
crate::models::posts::queries::set_post_token_tx_id,
super::types::TransactionData,
};
#[cfg(feature = "ethereum-extras")]
#[get("/{status_id}/signature")]
async fn get_signature(
auth: BearerAuth,
@ -634,6 +637,7 @@ async fn get_signature(
Ok(HttpResponse::Ok().json(signature))
}
#[cfg(feature = "ethereum-extras")]
#[post("/{status_id}/token_minted")]
async fn token_minted(
auth: BearerAuth,
@ -666,8 +670,19 @@ async fn token_minted(
Ok(HttpResponse::Ok().json(status))
}
#[cfg(feature = "ethereum-extras")]
fn with_ethereum_extras(scope: Scope) -> Scope {
scope
.service(get_signature)
.service(token_minted)
}
#[cfg(not(feature = "ethereum-extras"))]
fn with_ethereum_extras(scope: Scope) -> Scope {
scope
}
pub fn status_api_scope() -> Scope {
web::scope("/api/v1/statuses")
let scope = web::scope("/api/v1/statuses")
// Routes without status ID
.service(create_status)
.service(preview_status)
@ -680,7 +695,6 @@ pub fn status_api_scope() -> Scope {
.service(unfavourite)
.service(reblog)
.service(unreblog)
.service(make_permanent)
.service(get_signature)
.service(token_minted)
.service(make_permanent);
with_ethereum_extras(scope)
}