2026-05-18 15:06:09 +03:00
|
|
|
use common::HashType;
|
|
|
|
|
use nssa::{AccountId, program::Program};
|
2026-02-20 11:20:30 +00:00
|
|
|
use nssa_core::{MembershipProof, SharedSecretKey};
|
2025-11-30 01:57:59 +03:00
|
|
|
|
2026-05-18 13:44:03 +03:00
|
|
|
use crate::{AccountManagerAccountIdentity, ExecutionFailureKind, WalletCore};
|
2025-11-30 01:57:59 +03:00
|
|
|
|
2026-03-04 18:42:33 +03:00
|
|
|
pub struct Pinata<'wallet>(pub &'wallet WalletCore);
|
2025-11-30 01:57:59 +03:00
|
|
|
|
|
|
|
|
impl Pinata<'_> {
|
|
|
|
|
pub async fn claim(
|
|
|
|
|
&self,
|
|
|
|
|
pinata_account_id: AccountId,
|
|
|
|
|
winner_account_id: AccountId,
|
|
|
|
|
solution: u128,
|
2026-03-13 22:38:23 +03:00
|
|
|
) -> Result<HashType, ExecutionFailureKind> {
|
2026-05-18 15:06:09 +03:00
|
|
|
let program = Program::pinata();
|
|
|
|
|
let instruction = solution;
|
|
|
|
|
let instruction_data =
|
|
|
|
|
Program::serialize_instruction(instruction).expect("Instruction should serialize");
|
2025-11-30 01:57:59 +03:00
|
|
|
|
2026-05-18 15:06:09 +03:00
|
|
|
self.0
|
|
|
|
|
.send_pub_tx(
|
|
|
|
|
vec![
|
2026-05-19 17:54:25 +03:00
|
|
|
AccountManagerAccountIdentity::PublicNoSign(pinata_account_id),
|
|
|
|
|
AccountManagerAccountIdentity::PublicNoSign(winner_account_id),
|
2026-05-18 15:06:09 +03:00
|
|
|
],
|
|
|
|
|
instruction_data,
|
|
|
|
|
&program.into(),
|
|
|
|
|
)
|
|
|
|
|
.await
|
2025-11-30 01:57:59 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-20 11:20:30 +00:00
|
|
|
/// Claim a pinata reward using a privacy-preserving transaction for an already-initialized
|
|
|
|
|
/// owned private account.
|
|
|
|
|
///
|
|
|
|
|
/// The `winner_proof` parameter is accepted for API completeness; the wallet currently fetches
|
|
|
|
|
/// the membership proof automatically from the chain.
|
|
|
|
|
pub async fn claim_private_owned_account_already_initialized(
|
|
|
|
|
&self,
|
|
|
|
|
pinata_account_id: AccountId,
|
|
|
|
|
winner_account_id: AccountId,
|
|
|
|
|
solution: u128,
|
|
|
|
|
_winner_proof: MembershipProof,
|
2026-03-13 22:38:23 +03:00
|
|
|
) -> Result<(HashType, SharedSecretKey), ExecutionFailureKind> {
|
2026-02-20 11:20:30 +00:00
|
|
|
self.claim_private_owned_account(pinata_account_id, winner_account_id, solution)
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-30 01:57:59 +03:00
|
|
|
pub async fn claim_private_owned_account(
|
|
|
|
|
&self,
|
|
|
|
|
pinata_account_id: AccountId,
|
|
|
|
|
winner_account_id: AccountId,
|
|
|
|
|
solution: u128,
|
2026-03-13 22:38:23 +03:00
|
|
|
) -> Result<(HashType, SharedSecretKey), ExecutionFailureKind> {
|
2025-11-30 01:57:59 +03:00
|
|
|
self.0
|
|
|
|
|
.send_privacy_preserving_tx(
|
|
|
|
|
vec![
|
2026-05-18 13:44:03 +03:00
|
|
|
AccountManagerAccountIdentity::Public(pinata_account_id),
|
2026-05-08 17:44:10 +02:00
|
|
|
self.0
|
|
|
|
|
.resolve_private_account(winner_account_id)
|
|
|
|
|
.ok_or(ExecutionFailureKind::KeyNotFoundError)?,
|
2025-11-30 01:57:59 +03:00
|
|
|
],
|
2025-12-25 01:49:34 +03:00
|
|
|
nssa::program::Program::serialize_instruction(solution).unwrap(),
|
2025-12-12 14:20:58 -03:00
|
|
|
&nssa::program::Program::pinata().into(),
|
2025-11-30 01:57:59 +03:00
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
.map(|(resp, secrets)| {
|
|
|
|
|
let first = secrets
|
|
|
|
|
.into_iter()
|
|
|
|
|
.next()
|
|
|
|
|
.expect("expected recipient's secret");
|
|
|
|
|
(resp, first)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|