Skip to content

Commit

Permalink
feat: get fee for transactions for stratum transcoder
Browse files Browse the repository at this point in the history
cargo-fmt
  • Loading branch information
StriderDM committed Nov 15, 2021
1 parent f013e19 commit 12f59d8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions applications/tari_stratum_transcoder/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,64 @@ impl InnerService {
proxy::json_response(StatusCode::OK, &json_response)
}

async fn handle_get_fee(
&self,
request: Request<json::Value>,
) -> Result<Response<Body>, StratumTranscoderProxyError> {
let request = request.body();
let transactions = match request["params"]["transactions"].as_array() {
Some(v) => v,
None => {
return proxy::json_response(
StatusCode::OK,
&json_rpc::error_response(
request["id"].as_i64(),
1,
"`transactions` field is empty or an invalid type for transfer request.",
None,
),
)
},
};

let mut grpc_transaction_info = Vec::new();
for transaction in transactions.iter() {
grpc_transaction_info.push(
transaction["transaction_id"]
.as_str()
.unwrap()
.to_string()
.parse::<u64>()
.unwrap(),
);
}

let mut client = self.wallet_client.clone();

let transaction_info_results = client
.get_transaction_info(grpc::GetTransactionInfoRequest {
transaction_ids: grpc_transaction_info,
})
.await?
.into_inner();
let info_results = &transaction_info_results.transactions;

let mut results = Vec::new();
for info_result in info_results.iter() {
let result = json!({
"transaction_id": info_result.tx_id,
"fee": info_result.fee,
});
results.push(result.as_object().unwrap().clone());
}

let json_response = json!({
"jsonrpc": "2.0",
"result": {"fee_results" : results},
});
proxy::json_response(StatusCode::OK, &json_response)
}

async fn handle_transfer(
&self,
request: Request<json::Value>,
Expand Down Expand Up @@ -586,6 +644,7 @@ impl InnerService {
"getlastblockheader" | "get_last_block_header" => self.handle_get_last_block_header(request).await,
"transfer" => self.handle_transfer(request).await,
"getbalance" | "get_balance" => self.handle_get_balance(request).await,
"getfee" | "get_fee" => self.handle_get_fee(request).await,
_ => {
let request = request.body();
proxy_resp = Response::new(standard_error_response(
Expand Down

0 comments on commit 12f59d8

Please sign in to comment.