MCPcopy Create free account
hub / github.com/ddimaria/rust-blockchain-tutorial / send_transaction

Method send_transaction

chain/src/blockchain.rs:87–104  ·  view source on GitHub ↗
(
        &mut self,
        transaction_request: TransactionRequest,
    )

Source from the content-addressed store, hash-verified

85 }
86
87 pub(crate) async fn send_transaction(
88 &mut self,
89 transaction_request: TransactionRequest,
90 ) -> Result<H256> {
91 let mut transaction: Transaction = transaction_request.try_into()?;
92 let account = self.accounts.get_account(&transaction.from)?;
93 let nonce = transaction.nonce.unwrap_or_else(|| account.nonce + 1_u64);
94
95 transaction.nonce = Some(nonce);
96
97 // regenerate the transaction hash with the nonce in place
98 let transaction_hash = transaction.hash()?;
99
100 // add to the transaction mempool
101 self.transactions.lock().await.send_transaction(transaction);
102
103 Ok(transaction_hash)
104 }
105
106 pub(crate) async fn send_raw_transaction(&mut self, transaction: Bytes) -> Result<H256> {
107 let signed_transaction: SignedTransaction = bincode::deserialize(&transaction)?;

Callers 3

send_raw_transactionMethod · 0.45
sends_a_transactionFunction · 0.45
eth_send_transactionFunction · 0.45

Calls 3

get_accountMethod · 0.80
hashMethod · 0.80
try_intoMethod · 0.45

Tested by

no test coverage detected