Disable post tokenization feature
This commit is contained in:
parent
b5365099a4
commit
268707a78a
8 changed files with 58 additions and 26 deletions
|
@ -6,9 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
## [Unreleased]
|
## [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
|
## [1.16.0] - 2023-03-08
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,10 @@ web3 = { version = "0.18.0", default-features = false, features = ["http", "http
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
mitra-config = { path = "mitra-config", features = ["test-utils"] }
|
mitra-config = { path = "mitra-config", features = ["test-utils"] }
|
||||||
mitra-utils = { path = "mitra-utils", features = ["test-utils"] }
|
mitra-utils = { path = "mitra-utils", features = ["test-utils"] }
|
||||||
|
|
||||||
serial_test = "0.7.0"
|
serial_test = "0.7.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
ethereum-extras = []
|
||||||
|
|
||||||
production = ["mitra-config/production"]
|
production = ["mitra-config/production"]
|
||||||
|
|
|
@ -133,7 +133,9 @@ pub async fn get_contracts(
|
||||||
};
|
};
|
||||||
|
|
||||||
let minter_abi = load_abi(&config.contract_dir, MINTER)?;
|
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(
|
let minter = Contract::new(
|
||||||
web3.eth(),
|
web3.eth(),
|
||||||
adapter_address,
|
adapter_address,
|
||||||
|
|
|
@ -4,8 +4,10 @@ pub mod eip4361;
|
||||||
mod errors;
|
mod errors;
|
||||||
pub mod gate;
|
pub mod gate;
|
||||||
pub mod identity;
|
pub mod identity;
|
||||||
pub mod nft;
|
|
||||||
pub mod signatures;
|
pub mod signatures;
|
||||||
pub mod subscriptions;
|
pub mod subscriptions;
|
||||||
pub mod sync;
|
pub mod sync;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
|
#[cfg(feature = "ethereum-extras")]
|
||||||
|
pub mod nft;
|
||||||
|
|
|
@ -8,6 +8,7 @@ pub fn get_ipfs_url(cid: &str) -> String {
|
||||||
#[error("parse error")]
|
#[error("parse error")]
|
||||||
pub struct ParseError;
|
pub struct ParseError;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn parse_ipfs_url(url: &str) -> Result<String, ParseError> {
|
pub fn parse_ipfs_url(url: &str) -> Result<String, ParseError> {
|
||||||
let regexp = Regex::new(r"ipfs://(?P<cid>\w+)").unwrap();
|
let regexp = Regex::new(r"ipfs://(?P<cid>\w+)").unwrap();
|
||||||
let caps = regexp.captures(url).ok_or(ParseError)?;
|
let caps = regexp.captures(url).ok_or(ParseError)?;
|
||||||
|
|
|
@ -12,7 +12,6 @@ use crate::activitypub::queues::{
|
||||||
use crate::database::{get_database_client, DbPool};
|
use crate::database::{get_database_client, DbPool};
|
||||||
use crate::ethereum::{
|
use crate::ethereum::{
|
||||||
contracts::Blockchain,
|
contracts::Blockchain,
|
||||||
nft::process_nft_events,
|
|
||||||
subscriptions::{
|
subscriptions::{
|
||||||
check_ethereum_subscriptions,
|
check_ethereum_subscriptions,
|
||||||
update_expired_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(
|
pub async fn nft_monitor(
|
||||||
maybe_blockchain: Option<&mut Blockchain>,
|
maybe_blockchain: Option<&mut Blockchain>,
|
||||||
db_pool: &DbPool,
|
db_pool: &DbPool,
|
||||||
|
|
|
@ -11,7 +11,6 @@ use super::periodic_tasks::*;
|
||||||
|
|
||||||
#[derive(Debug, Eq, Hash, PartialEq)]
|
#[derive(Debug, Eq, Hash, PartialEq)]
|
||||||
enum PeriodicTask {
|
enum PeriodicTask {
|
||||||
NftMonitor,
|
|
||||||
EthereumSubscriptionMonitor,
|
EthereumSubscriptionMonitor,
|
||||||
SubscriptionExpirationMonitor,
|
SubscriptionExpirationMonitor,
|
||||||
MoneroPaymentMonitor,
|
MoneroPaymentMonitor,
|
||||||
|
@ -19,13 +18,15 @@ enum PeriodicTask {
|
||||||
OutgoingActivityQueueExecutor,
|
OutgoingActivityQueueExecutor,
|
||||||
DeleteExtraneousPosts,
|
DeleteExtraneousPosts,
|
||||||
DeleteEmptyProfiles,
|
DeleteEmptyProfiles,
|
||||||
|
|
||||||
|
#[cfg(feature = "ethereum-extras")]
|
||||||
|
NftMonitor,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PeriodicTask {
|
impl PeriodicTask {
|
||||||
/// Returns task period (in seconds)
|
/// Returns task period (in seconds)
|
||||||
fn period(&self) -> i64 {
|
fn period(&self) -> i64 {
|
||||||
match self {
|
match self {
|
||||||
Self::NftMonitor => 30,
|
|
||||||
Self::EthereumSubscriptionMonitor => 300,
|
Self::EthereumSubscriptionMonitor => 300,
|
||||||
Self::SubscriptionExpirationMonitor => 300,
|
Self::SubscriptionExpirationMonitor => 300,
|
||||||
Self::MoneroPaymentMonitor => 30,
|
Self::MoneroPaymentMonitor => 30,
|
||||||
|
@ -33,6 +34,9 @@ impl PeriodicTask {
|
||||||
Self::OutgoingActivityQueueExecutor => 5,
|
Self::OutgoingActivityQueueExecutor => 5,
|
||||||
Self::DeleteExtraneousPosts => 3600,
|
Self::DeleteExtraneousPosts => 3600,
|
||||||
Self::DeleteEmptyProfiles => 3600,
|
Self::DeleteEmptyProfiles => 3600,
|
||||||
|
|
||||||
|
#[cfg(feature = "ethereum-extras")]
|
||||||
|
Self::NftMonitor => 30,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,12 +58,14 @@ pub fn run(
|
||||||
) -> () {
|
) -> () {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut scheduler_state = HashMap::from([
|
let mut scheduler_state = HashMap::from([
|
||||||
(PeriodicTask::NftMonitor, None),
|
|
||||||
(PeriodicTask::EthereumSubscriptionMonitor, None),
|
(PeriodicTask::EthereumSubscriptionMonitor, None),
|
||||||
(PeriodicTask::SubscriptionExpirationMonitor, None),
|
(PeriodicTask::SubscriptionExpirationMonitor, None),
|
||||||
(PeriodicTask::MoneroPaymentMonitor, None),
|
(PeriodicTask::MoneroPaymentMonitor, None),
|
||||||
(PeriodicTask::IncomingActivityQueueExecutor, None),
|
(PeriodicTask::IncomingActivityQueueExecutor, None),
|
||||||
(PeriodicTask::OutgoingActivityQueueExecutor, None),
|
(PeriodicTask::OutgoingActivityQueueExecutor, None),
|
||||||
|
|
||||||
|
#[cfg(feature = "ethereum-extras")]
|
||||||
|
(PeriodicTask::NftMonitor, None),
|
||||||
]);
|
]);
|
||||||
if config.retention.extraneous_posts.is_some() {
|
if config.retention.extraneous_posts.is_some() {
|
||||||
scheduler_state.insert(PeriodicTask::DeleteExtraneousPosts, None);
|
scheduler_state.insert(PeriodicTask::DeleteExtraneousPosts, None);
|
||||||
|
@ -77,12 +83,6 @@ pub fn run(
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let task_result = match task {
|
let task_result = match task {
|
||||||
PeriodicTask::NftMonitor => {
|
|
||||||
nft_monitor(
|
|
||||||
maybe_blockchain.as_mut(),
|
|
||||||
&db_pool,
|
|
||||||
).await
|
|
||||||
},
|
|
||||||
PeriodicTask::EthereumSubscriptionMonitor => {
|
PeriodicTask::EthereumSubscriptionMonitor => {
|
||||||
ethereum_subscription_monitor(
|
ethereum_subscription_monitor(
|
||||||
&config,
|
&config,
|
||||||
|
@ -108,6 +108,13 @@ pub fn run(
|
||||||
PeriodicTask::DeleteEmptyProfiles => {
|
PeriodicTask::DeleteEmptyProfiles => {
|
||||||
delete_empty_profiles(&config, &db_pool).await
|
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| {
|
task_result.unwrap_or_else(|err| {
|
||||||
log::error!("{:?}: {}", task, err);
|
log::error!("{:?}: {}", task, err);
|
||||||
|
|
|
@ -13,10 +13,7 @@ use chrono::Utc;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use mitra_config::Config;
|
use mitra_config::Config;
|
||||||
use mitra_utils::{
|
use mitra_utils::markdown::markdown_lite_to_html;
|
||||||
currencies::Currency,
|
|
||||||
markdown::markdown_lite_to_html,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::activitypub::builders::{
|
use crate::activitypub::builders::{
|
||||||
announce::prepare_announce,
|
announce::prepare_announce,
|
||||||
|
@ -28,12 +25,10 @@ use crate::activitypub::builders::{
|
||||||
};
|
};
|
||||||
use crate::database::{get_database_client, DatabaseError, DbPool};
|
use crate::database::{get_database_client, DatabaseError, DbPool};
|
||||||
use crate::errors::ValidationError;
|
use crate::errors::ValidationError;
|
||||||
use crate::ethereum::nft::create_mint_signature;
|
|
||||||
use crate::http::{get_request_base_url, FormOrJson};
|
use crate::http::{get_request_base_url, FormOrJson};
|
||||||
use crate::ipfs::{
|
use crate::ipfs::{
|
||||||
store as ipfs_store,
|
store as ipfs_store,
|
||||||
posts::PostMetadata,
|
posts::PostMetadata,
|
||||||
utils::get_ipfs_url,
|
|
||||||
};
|
};
|
||||||
use crate::mastodon_api::{
|
use crate::mastodon_api::{
|
||||||
errors::MastodonError,
|
errors::MastodonError,
|
||||||
|
@ -47,7 +42,6 @@ use crate::models::{
|
||||||
get_thread,
|
get_thread,
|
||||||
find_reposts_by_user,
|
find_reposts_by_user,
|
||||||
set_post_ipfs_cid,
|
set_post_ipfs_cid,
|
||||||
set_post_token_tx_id,
|
|
||||||
delete_post,
|
delete_post,
|
||||||
},
|
},
|
||||||
posts::types::{PostCreateData, Visibility},
|
posts::types::{PostCreateData, Visibility},
|
||||||
|
@ -74,7 +68,6 @@ use super::types::{
|
||||||
StatusData,
|
StatusData,
|
||||||
StatusPreview,
|
StatusPreview,
|
||||||
StatusPreviewData,
|
StatusPreviewData,
|
||||||
TransactionData,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[post("")]
|
#[post("")]
|
||||||
|
@ -600,6 +593,16 @@ async fn make_permanent(
|
||||||
Ok(HttpResponse::Ok().json(status))
|
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")]
|
#[get("/{status_id}/signature")]
|
||||||
async fn get_signature(
|
async fn get_signature(
|
||||||
auth: BearerAuth,
|
auth: BearerAuth,
|
||||||
|
@ -634,6 +637,7 @@ async fn get_signature(
|
||||||
Ok(HttpResponse::Ok().json(signature))
|
Ok(HttpResponse::Ok().json(signature))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ethereum-extras")]
|
||||||
#[post("/{status_id}/token_minted")]
|
#[post("/{status_id}/token_minted")]
|
||||||
async fn token_minted(
|
async fn token_minted(
|
||||||
auth: BearerAuth,
|
auth: BearerAuth,
|
||||||
|
@ -666,8 +670,19 @@ async fn token_minted(
|
||||||
Ok(HttpResponse::Ok().json(status))
|
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 {
|
pub fn status_api_scope() -> Scope {
|
||||||
web::scope("/api/v1/statuses")
|
let scope = web::scope("/api/v1/statuses")
|
||||||
// Routes without status ID
|
// Routes without status ID
|
||||||
.service(create_status)
|
.service(create_status)
|
||||||
.service(preview_status)
|
.service(preview_status)
|
||||||
|
@ -680,7 +695,6 @@ pub fn status_api_scope() -> Scope {
|
||||||
.service(unfavourite)
|
.service(unfavourite)
|
||||||
.service(reblog)
|
.service(reblog)
|
||||||
.service(unreblog)
|
.service(unreblog)
|
||||||
.service(make_permanent)
|
.service(make_permanent);
|
||||||
.service(get_signature)
|
with_ethereum_extras(scope)
|
||||||
.service(token_minted)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue