Dereplicode send_transaction and request_airdrop RPC handlers
(cherry picked from commit a7079e4dde
)
This commit is contained in:
committed by
Trent Nelson
parent
e8e74ee009
commit
1b2fdcd3a2
@ -1132,6 +1132,18 @@ pub trait RpcSol {
|
|||||||
) -> Result<RpcStakeActivation>;
|
) -> Result<RpcStakeActivation>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn _send_transaction(
|
||||||
|
meta: JsonRpcRequestProcessor,
|
||||||
|
transaction: Transaction,
|
||||||
|
wire_transaction: Vec<u8>,
|
||||||
|
last_valid_slot: Slot,
|
||||||
|
) -> Result<String> {
|
||||||
|
let signature = transaction.signatures[0];
|
||||||
|
meta.send_transaction_service
|
||||||
|
.send(signature, wire_transaction, last_valid_slot);
|
||||||
|
Ok(signature.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
pub struct RpcSolImpl;
|
pub struct RpcSolImpl;
|
||||||
impl RpcSol for RpcSolImpl {
|
impl RpcSol for RpcSolImpl {
|
||||||
type Metadata = JsonRpcRequestProcessor;
|
type Metadata = JsonRpcRequestProcessor;
|
||||||
@ -1477,17 +1489,13 @@ impl RpcSol for RpcSolImpl {
|
|||||||
info!("request_airdrop_transaction failed: {:?}", err);
|
info!("request_airdrop_transaction failed: {:?}", err);
|
||||||
Error::internal_error()
|
Error::internal_error()
|
||||||
})?;
|
})?;
|
||||||
let signature = transaction.signatures[0];
|
|
||||||
|
|
||||||
let wire_transaction = serialize(&transaction).map_err(|err| {
|
let wire_transaction = serialize(&transaction).map_err(|err| {
|
||||||
info!("request_airdrop: serialize error: {:?}", err);
|
info!("request_airdrop: serialize error: {:?}", err);
|
||||||
Error::internal_error()
|
Error::internal_error()
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
meta.send_transaction_service
|
_send_transaction(meta, transaction, wire_transaction, last_valid_slot)
|
||||||
.send(signature, wire_transaction, last_valid_slot);
|
|
||||||
|
|
||||||
Ok(signature.to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_transaction(
|
fn send_transaction(
|
||||||
@ -1499,7 +1507,6 @@ impl RpcSol for RpcSolImpl {
|
|||||||
debug!("send_transaction rpc request received");
|
debug!("send_transaction rpc request received");
|
||||||
let config = config.unwrap_or_default();
|
let config = config.unwrap_or_default();
|
||||||
let (wire_transaction, transaction) = deserialize_bs58_transaction(data)?;
|
let (wire_transaction, transaction) = deserialize_bs58_transaction(data)?;
|
||||||
let signature = transaction.signatures[0];
|
|
||||||
let bank = &*meta.bank(None)?;
|
let bank = &*meta.bank(None)?;
|
||||||
let last_valid_slot = bank
|
let last_valid_slot = bank
|
||||||
.get_blockhash_last_valid_slot(&transaction.message.recent_blockhash)
|
.get_blockhash_last_valid_slot(&transaction.message.recent_blockhash)
|
||||||
@ -1520,7 +1527,8 @@ impl RpcSol for RpcSolImpl {
|
|||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let (Err(err), _log_output) = run_transaction_simulation(&bank, transaction) {
|
if let (Err(err), _log_output) = run_transaction_simulation(&bank, transaction.clone())
|
||||||
|
{
|
||||||
// Note: it's possible that the transaction simulation failed but the actual
|
// Note: it's possible that the transaction simulation failed but the actual
|
||||||
// transaction would succeed, such as when a transaction depends on an earlier
|
// transaction would succeed, such as when a transaction depends on an earlier
|
||||||
// transaction that has yet to reach max confirmations. In these cases the user
|
// transaction that has yet to reach max confirmations. In these cases the user
|
||||||
@ -1533,9 +1541,7 @@ impl RpcSol for RpcSolImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.send_transaction_service
|
_send_transaction(meta, transaction, wire_transaction, last_valid_slot)
|
||||||
.send(signature, wire_transaction, last_valid_slot);
|
|
||||||
Ok(signature.to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn simulate_transaction(
|
fn simulate_transaction(
|
||||||
|
Reference in New Issue
Block a user