Add API method for registering minted tokens
This commit is contained in:
parent
c5e292d39f
commit
4b5b98135d
5 changed files with 63 additions and 2 deletions
|
@ -138,6 +138,7 @@ Additional methods:
|
|||
```
|
||||
POST /api/v1/statuses/{status_id}/make_permanent
|
||||
GET /api/v1/statuses/{status_id}/signature
|
||||
POST /api/v1/statuses/{status_id}/token_minted
|
||||
```
|
||||
|
||||
[OpenAPI spec](./docs/openapi.yaml)
|
||||
|
|
|
@ -56,6 +56,32 @@ paths:
|
|||
description: Ethereum integration is not enabled
|
||||
422:
|
||||
description: Post is not saved to IPFS
|
||||
/api/v1/{status_id}/token_minted:
|
||||
post:
|
||||
summary: Register transaction that mints a token
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/status_id'
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
properties:
|
||||
transaction_id:
|
||||
type: string
|
||||
description: Transaction ID
|
||||
responses:
|
||||
200:
|
||||
description: Successful operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Status'
|
||||
403:
|
||||
description: Post does not belong to user or is not public
|
||||
404:
|
||||
description: Post not found
|
||||
422:
|
||||
description: Transaction already registered
|
||||
|
||||
components:
|
||||
parameters:
|
||||
|
@ -78,3 +104,7 @@ components:
|
|||
type: string
|
||||
nullable: true
|
||||
example: 'bafkr...'
|
||||
token_tx_id:
|
||||
type: string
|
||||
nullable: true
|
||||
example: '0x5fe80cdea7f...'
|
||||
|
|
|
@ -123,3 +123,8 @@ impl From<StatusData> for PostCreateData {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct TransactionData {
|
||||
pub transaction_id: String,
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ use crate::models::reactions::queries::{
|
|||
create_reaction,
|
||||
delete_reaction,
|
||||
};
|
||||
use super::types::{Status, StatusData};
|
||||
use super::types::{Status, StatusData, TransactionData};
|
||||
|
||||
#[post("")]
|
||||
async fn create_status(
|
||||
|
@ -395,6 +395,31 @@ async fn get_signature(
|
|||
Ok(HttpResponse::Ok().json(signature))
|
||||
}
|
||||
|
||||
#[post("/{status_id}/token_minted")]
|
||||
async fn token_minted(
|
||||
auth: BearerAuth,
|
||||
config: web::Data<Config>,
|
||||
db_pool: web::Data<Pool>,
|
||||
web::Path(status_id): web::Path<Uuid>,
|
||||
data: web::Json<TransactionData>,
|
||||
) -> Result<HttpResponse, HttpError> {
|
||||
let db_client = &**get_database_client(&db_pool).await?;
|
||||
let current_user = get_current_user(db_client, auth.token()).await?;
|
||||
let mut post = get_post_by_id(db_client, &status_id).await?;
|
||||
if post.token_tx_id.is_some() {
|
||||
return Err(HttpError::OperationError("transaction is already registered"));
|
||||
};
|
||||
if post.author.id != current_user.id || !post.is_public() {
|
||||
return Err(HttpError::PermissionError);
|
||||
};
|
||||
post.token_tx_id = Some(data.into_inner().transaction_id);
|
||||
update_post(db_client, &post).await?;
|
||||
get_reposted_posts(db_client, vec![&mut post]).await?;
|
||||
get_actions_for_posts(db_client, ¤t_user.id, vec![&mut post]).await?;
|
||||
let status = Status::from_post(post, &config.instance_url());
|
||||
Ok(HttpResponse::Ok().json(status))
|
||||
}
|
||||
|
||||
pub fn status_api_scope() -> Scope {
|
||||
web::scope("/api/v1/statuses")
|
||||
// Routes without status ID
|
||||
|
@ -408,4 +433,5 @@ pub fn status_api_scope() -> Scope {
|
|||
.service(unreblog)
|
||||
.service(make_permanent)
|
||||
.service(get_signature)
|
||||
.service(token_minted)
|
||||
}
|
||||
|
|
|
@ -450,7 +450,6 @@ pub async fn update_post(
|
|||
db_client: &impl GenericClient,
|
||||
post: &Post,
|
||||
) -> Result<(), DatabaseError> {
|
||||
// TODO: create PostUpdateData type
|
||||
let updated_count = db_client.execute(
|
||||
"
|
||||
UPDATE post
|
||||
|
|
Loading…
Reference in a new issue