mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-02 13:23:10 +00:00
53 lines
1.8 KiB
Rust
53 lines
1.8 KiB
Rust
use common::{error::ExecutionFailureKind, rpc_primitives::requests::SendTxResponse};
|
|
use nssa::AccountId;
|
|
use nssa_core::SharedSecretKey;
|
|
|
|
use crate::{PrivacyPreservingAccount, WalletCore};
|
|
|
|
pub struct Pinata<'w>(pub &'w WalletCore);
|
|
|
|
impl Pinata<'_> {
|
|
pub async fn claim(
|
|
&self,
|
|
pinata_account_id: AccountId,
|
|
winner_account_id: AccountId,
|
|
solution: u128,
|
|
) -> Result<SendTxResponse, ExecutionFailureKind> {
|
|
let account_ids = vec![pinata_account_id, winner_account_id];
|
|
let program_id = nssa::program::Program::pinata().id();
|
|
let message =
|
|
nssa::public_transaction::Message::try_new(program_id, account_ids, vec![], solution)
|
|
.unwrap();
|
|
|
|
let witness_set = nssa::public_transaction::WitnessSet::for_message(&message, &[]);
|
|
let tx = nssa::PublicTransaction::new(message, witness_set);
|
|
|
|
Ok(self.0.sequencer_client.send_tx_public(tx).await?)
|
|
}
|
|
|
|
pub async fn claim_private_owned_account(
|
|
&self,
|
|
pinata_account_id: AccountId,
|
|
winner_account_id: AccountId,
|
|
solution: u128,
|
|
) -> Result<(SendTxResponse, SharedSecretKey), ExecutionFailureKind> {
|
|
self.0
|
|
.send_privacy_preserving_tx(
|
|
vec![
|
|
PrivacyPreservingAccount::Public(pinata_account_id),
|
|
PrivacyPreservingAccount::PrivateOwned(winner_account_id),
|
|
],
|
|
&nssa::program::Program::serialize_instruction(solution).unwrap(),
|
|
&nssa::program::Program::pinata(),
|
|
)
|
|
.await
|
|
.map(|(resp, secrets)| {
|
|
let first = secrets
|
|
.into_iter()
|
|
.next()
|
|
.expect("expected recipient's secret");
|
|
(resp, first)
|
|
})
|
|
}
|
|
}
|