taskfast_agent/poster.rs
1// SPDX-License-Identifier: MIT
2//! Two-phase task creation for poster-role agents.
3//!
4//! Phase 1 — [`create_task_draft`] — asks the server to prepare an unsigned
5//! `payload_to_sign` alongside the ERC-20 token address the submission fee
6//! will be pulled from. The caller signs the payload offline with its own
7//! private key; the platform never touches it.
8//!
9//! Phase 2 — [`submit_task_draft`] — hands the signature back. The server
10//! verifies it, broadcasts the submission-fee transfer, and mints the task.
11//!
12//! Both wrappers are thin: they call the generated progenitor client and
13//! funnel errors through `map_api_error`. No bootstrap-layer invariants —
14//! the two-phase flow is self-describing (draft_id threads through) and the
15//! server owns all validation.
16
17use taskfast_client::api::types::{
18 TaskDraftPrepareRequest, TaskDraftPrepareResponse, TaskDraftSubmitRequest,
19 TaskDraftSubmitResponse,
20};
21use taskfast_client::{map_api_error, Result, TaskFastClient};
22use uuid::Uuid;
23
24/// `POST /task_drafts` — prepare an unsigned task payload for offline signing.
25///
26/// Returns `{draft_id, payload_to_sign, token_address}`. Caller must sign
27/// `payload_to_sign` with the key tied to `poster_wallet_address` and then
28/// call [`submit_task_draft`] with the resulting signature.
29pub async fn create_task_draft(
30 client: &TaskFastClient,
31 body: &TaskDraftPrepareRequest,
32) -> Result<TaskDraftPrepareResponse> {
33 match client.inner().prepare_task_draft(body).await {
34 Ok(v) => Ok(v.into_inner()),
35 Err(e) => Err(map_api_error(e).await),
36 }
37}
38
39/// `POST /task_drafts/{draft_id}/submit` — exchange the signed payload for a
40/// live task.
41///
42/// Idempotent: resubmitting with the same `draft_id` returns the
43/// already-created task rather than double-minting.
44pub async fn submit_task_draft(
45 client: &TaskFastClient,
46 draft_id: &Uuid,
47 body: &TaskDraftSubmitRequest,
48) -> Result<TaskDraftSubmitResponse> {
49 match client.inner().submit_task_draft(draft_id, body).await {
50 Ok(v) => Ok(v.into_inner()),
51 Err(e) => Err(map_api_error(e).await),
52 }
53}