Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions wallet/core/src/api/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,25 @@ pub struct AccountsPskbBroadcastRequest {
pub pskb: String,
}

#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct PskbBroadcastRequest {
pub pskb: String,
pub network_id: NetworkId,
}

#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountsPskbBroadcastResponse {
pub transaction_ids: Vec<TransactionId>,
}

#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct PskbBroadcastResponse {
pub transaction_ids: Vec<TransactionId>,
}

#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountsPskbSendRequest {
Expand Down
8 changes: 8 additions & 0 deletions wallet/core/src/api/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ pub trait WalletApi: Send + Sync + AnySync {
self.accounts_pskb_broadcast_call(request).await
}

/// Wrapper around [`pskb_broadcast_call()`](Self::pskb_broadcast_call)
async fn pskb_broadcast(self: Arc<Self>, request: PskbBroadcastRequest) -> Result<PskbBroadcastResponse> {
self.pskb_broadcast_call(request).await
}

/// Broadcast a PSKB.
async fn pskb_broadcast_call(self: Arc<Self>, request: PskbBroadcastRequest) -> Result<PskbBroadcastResponse>;

/// Broadcast a PSKB.
async fn accounts_pskb_broadcast_call(
self: Arc<Self>,
Expand Down
2 changes: 2 additions & 0 deletions wallet/core/src/api/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl WalletApi for WalletClient {
AccountsSend,
AccountsPskbSign,
AccountsPskbBroadcast,
PskbBroadcast,
AccountsPskbSend,
AccountsGetUtxos,
AccountsTransfer,
Expand Down Expand Up @@ -187,6 +188,7 @@ impl WalletServer {
AccountsSend,
AccountsPskbSign,
AccountsPskbBroadcast,
PskbBroadcast,
AccountsPskbSend,
AccountsGetUtxos,
AccountsTransfer,
Expand Down
32 changes: 32 additions & 0 deletions wallet/core/src/wallet/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! [`WalletApi`] trait implementation for the [`Wallet`] struct.
//!

use crate::account::pskb::bundle_to_finalizer_stream;
use crate::api::{message::*, traits::WalletApi};
use crate::events::Events;
use crate::imports::*;
Expand All @@ -11,6 +12,7 @@ use crate::storage::Binding;
use crate::tx::Fees;
use kaspa_rpc_core::RpcFeeEstimate;
use kaspa_wallet_pskt::bundle::Bundle;

use workflow_core::channel::Receiver;
#[async_trait]
impl WalletApi for super::Wallet {
Expand Down Expand Up @@ -432,6 +434,36 @@ impl WalletApi for super::Wallet {
Ok(AccountsPskbBroadcastResponse { transaction_ids })
}

async fn pskb_broadcast_call(self: Arc<Self>, request: PskbBroadcastRequest) -> Result<PskbBroadcastResponse> {
let PskbBroadcastRequest { pskb, network_id } = request;
let pskb = Bundle::deserialize(&pskb)?;

let mut transaction_ids = Vec::new();
let mut stream = bundle_to_finalizer_stream(&pskb);
let rpc = self.rpc_api();
while let Some(result) = stream.next().await {
match result {
Ok(finalized_pskt) => {
let signed_tx = match finalized_pskt.extractor() {
Ok(extractor) => match extractor.extract_tx(&network_id.into()) {
Ok(tx) => tx.tx,
Err(e) => return Err(Error::PendingTransactionFromPSKTError(e.to_string())),
},
Err(e) => return Err(Error::PendingTransactionFromPSKTError(e.to_string())),
};
log_info!("Submitting to rpc");
transaction_ids.push(rpc.submit_transaction((&signed_tx).into(), false).await?);
log_info!("Submitted to rpc");
}
Err(e) => {
log_info!("Error processing a PSKT from bundle: {:?}", e);
}
}
}

Ok(PskbBroadcastResponse { transaction_ids })
}

async fn accounts_get_utxos_call(self: Arc<Self>, request: AccountsGetUtxosRequest) -> Result<AccountsGetUtxosResponse> {
let AccountsGetUtxosRequest { account_id, addresses, min_amount_sompi } = request;
let guard = self.guard();
Expand Down
41 changes: 41 additions & 0 deletions wallet/core/src/wasm/api/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,47 @@ try_from! ( args: AccountsPskbBroadcastResponse, IAccountsPskbBroadcastResponse,
Ok(to_value(&args)?.into())
});

// ---

declare! {
IPskbBroadcastRequest,
r#"
/**
*
*
* @category Wallet API
*/
export interface IPskbBroadcastRequest {
pskb : string;
networkId : NetworkId | string;
}
"#,
}

try_from! ( args: IPskbBroadcastRequest, PskbBroadcastRequest, {
let pskb = args.get_string("pskb")?;
let network_id = args.get_network_id("networkId")?;
Ok(PskbBroadcastRequest { pskb, network_id })
});

declare! {
IPskbBroadcastResponse,
r#"
/**
*
*
* @category Wallet API
*/
export interface IPskbBroadcastResponse {
transactionIds : HexString[];
}
"#,
}

try_from! ( args: PskbBroadcastResponse, IPskbBroadcastResponse, {
Ok(to_value(&args)?.into())
});

declare! {
IAccountsPskbSendRequest,
r#"
Expand Down
1 change: 1 addition & 0 deletions wallet/core/src/wasm/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ declare_wasm_handlers!([
AccountsSend,
AccountsPskbSign,
AccountsPskbBroadcast,
PskbBroadcast,
AccountsPskbSend,
AccountsGetUtxos,
AccountsTransfer,
Expand Down