Skip to content

Commit befc07b

Browse files
authored
broadcast tx -> add tx (oreoslabs#33)
Broadcast transaction does not add the transaction to the wallet's own pending transactions. Add does this and by default also broadcasts the transaction.
1 parent 150559e commit befc07b

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

crates/networking/src/rpc_abi.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,14 @@ pub struct RpcCreateTxResponse {
241241
}
242242

243243
#[derive(Debug, Deserialize, Serialize)]
244-
pub struct RpcBroadcastTxRequest {
244+
pub struct RpcAddTxRequest {
245245
pub transaction: String,
246246
}
247247

248248
#[derive(Debug, Deserialize, Serialize)]
249-
pub struct RpcBroadcastTxResponse {
249+
pub struct RpcAddTxResponse {
250250
pub hash: String,
251251
pub accepted: bool,
252-
pub broadcasted: bool,
253252
}
254253

255254
#[derive(Debug, Deserialize, Serialize)]

crates/networking/src/rpc_handler/handler.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use ureq::{Agent, AgentBuilder, Error, Response};
88

99
use crate::{
1010
rpc_abi::{
11-
RpcBroadcastTxRequest, RpcBroadcastTxResponse, RpcCreateTxRequest, RpcCreateTxResponse,
11+
RpcAddTxRequest, RpcAddTxResponse, RpcCreateTxRequest, RpcCreateTxResponse,
1212
RpcExportAccountResponse, RpcGetAccountStatusRequest, RpcGetAccountStatusResponse,
1313
RpcGetAccountTransactionRequest, RpcGetAccountTransactionResponse, RpcGetBalancesRequest,
1414
RpcGetBalancesResponse, RpcGetBlockRequest, RpcGetBlockResponse, RpcGetBlocksRequest,
@@ -155,11 +155,11 @@ impl RpcHandler {
155155
handle_response(resp)
156156
}
157157

158-
pub fn broadcast_transaction(
158+
pub fn add_transaction(
159159
&self,
160-
request: RpcBroadcastTxRequest,
161-
) -> Result<RpcResponse<RpcBroadcastTxResponse>, OreoError> {
162-
let path = format!("http://{}/chain/broadcastTransaction", self.endpoint);
160+
request: RpcAddTxRequest,
161+
) -> Result<RpcResponse<RpcAddTxResponse>, OreoError> {
162+
let path = format!("http://{}/wallet/addTransaction", self.endpoint);
163163
let resp = self.agent.clone().post(&path).send_json(&request);
164164
handle_response(resp)
165165
}

crates/server/src/handlers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use db_handler::DBHandler;
1010
use networking::{
1111
decryption_message::{DecryptionMessage, ScanRequest, ScanResponse, SuccessResponse},
1212
rpc_abi::{
13-
BlockInfo, OutPut, RpcBroadcastTxRequest, RpcCreateTxRequest, RpcGetAccountStatusRequest,
13+
BlockInfo, OutPut, RpcAddTxRequest, RpcCreateTxRequest, RpcGetAccountStatusRequest,
1414
RpcGetAccountTransactionRequest, RpcGetBalancesRequest, RpcGetBalancesResponse,
1515
RpcGetTransactionsRequest, RpcImportAccountRequest, RpcImportAccountResponse,
1616
RpcRemoveAccountRequest, RpcResetAccountRequest, RpcResponse, RpcSetScanningRequest,
@@ -420,13 +420,13 @@ pub async fn create_transaction_handler<T: DBHandler>(
420420
.into_response()
421421
}
422422

423-
pub async fn broadcast_transaction_handler<T: DBHandler>(
423+
pub async fn add_transaction_handler<T: DBHandler>(
424424
State(shared): State<Arc<SharedState<T>>>,
425-
extract::Json(broadcast_transaction): extract::Json<RpcBroadcastTxRequest>,
425+
extract::Json(broadcast_transaction): extract::Json<RpcAddTxRequest>,
426426
) -> impl IntoResponse {
427427
shared
428428
.rpc_handler
429-
.broadcast_transaction(broadcast_transaction)
429+
.add_transaction(broadcast_transaction)
430430
.into_response()
431431
}
432432

crates/server/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tower_http::cors::{Any, CorsLayer};
1515
use tracing::info;
1616

1717
use crate::handlers::{
18-
account_status_handler, broadcast_transaction_handler, create_transaction_handler,
18+
account_status_handler, add_transaction_handler, create_transaction_handler,
1919
get_balances_handler, get_ores_handler, get_transaction_handler, get_transactions_handler,
2020
health_check_handler, import_account_handler, latest_block_handler, remove_account_handler,
2121
rescan_account_handler, update_scan_status_handler,
@@ -107,7 +107,8 @@ pub async fn run_server(
107107
.route("/getTransaction", post(get_transaction_handler))
108108
.route("/getTransactions", post(get_transactions_handler))
109109
.route("/createTx", post(create_transaction_handler))
110-
.route("/broadcastTx", post(broadcast_transaction_handler))
110+
.route("/broadcastTx", post(add_transaction_handler)) // TODO: Remove after front end updates to addTx
111+
.route("/addTx", post(add_transaction_handler))
111112
.route("/accountStatus", post(account_status_handler))
112113
.route("/latestBlock", get(latest_block_handler))
113114
.route("/ores", post(get_ores_handler))

0 commit comments

Comments
 (0)