Skip to content

Commit 4abe75e

Browse files
committed
status and root for getTransactionReceipt
1 parent b56be25 commit 4abe75e

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/miner/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::collections::HashMap;
1212
use std::time::{SystemTime, UNIX_EPOCH};
1313
use std::sync::{Arc, Mutex};
1414
use std::sync::mpsc::{channel, Sender, Receiver};
15-
use sputnikvm::{AccountChange, ValidTransaction, Patch, AccountCommitment, AccountState, HeaderParams, SeqTransactionVM, VM};
15+
use sputnikvm::{AccountChange, ValidTransaction, Patch, AccountCommitment, AccountState, HeaderParams, SeqTransactionVM, VM, VMStatus};
1616
use sputnikvm::errors::RequireError;
1717
use sputnikvm_stateful::MemoryStateful;
1818
use rand::os::OsRng;
@@ -167,6 +167,7 @@ pub fn mine_one<P: Patch>(state: Arc<Mutex<MinerState>>, address: Address) {
167167
state.fat_transit(current_block.header.number.as_usize(), &[]);
168168

169169
for transaction in transactions.clone() {
170+
let transaction_hash = transaction.rlp_hash();
170171
let valid = state.stateful_mut().to_valid::<P>(transaction).unwrap();
171172
let vm: SeqTransactionVM<P> = {
172173
let vm = state.stateful_mut().call(valid, HeaderParams::from(&current_block.header),
@@ -197,6 +198,14 @@ pub fn mine_one<P: Patch>(state: Arc<Mutex<MinerState>>, address: Address) {
197198
state_root: state.stateful_mut().root(),
198199
};
199200
receipts.push(receipt);
201+
202+
state.set_receipt_status(
203+
transaction_hash,
204+
match vm.status() {
205+
VMStatus::ExitedOk => true,
206+
_ => false,
207+
}
208+
);
200209
}
201210

202211
let root = state.stateful_mut().root();

src/miner/state.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct MinerState {
2525
block_database: HashMap<H256, Block>,
2626
receipt_database: HashMap<H256, Receipt>,
2727
fat_database: Vec<HashMap<Address, HashMap<U256, M256>>>,
28+
status_database: HashMap<H256, bool>,
2829

2930
accounts: Vec<SecretKey>,
3031
database: &'static MemoryDatabase,
@@ -60,6 +61,7 @@ impl MinerState {
6061
transaction_database: HashMap::new(),
6162
receipt_database: HashMap::new(),
6263
fat_database: vec![HashMap::new()],
64+
status_database: HashMap::new(),
6365

6466
accounts: Vec::new(),
6567
}
@@ -249,4 +251,12 @@ impl MinerState {
249251
pub fn append_account(&mut self, key: SecretKey) {
250252
self.accounts.push(key)
251253
}
254+
255+
pub fn set_receipt_status(&mut self, transaction_hash: H256, is_okay: bool) {
256+
self.status_database.insert(transaction_hash, is_okay);
257+
}
258+
259+
pub fn receipt_status(&self, transaction_hash: H256) -> bool {
260+
*self.status_database.get(&transaction_hash).unwrap_or(&false)
261+
}
252262
}

src/rpc/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ pub struct RPCReceipt {
6767
pub cumulative_gas_used: String,
6868
pub gas_used: String,
6969
pub contract_address: Option<String>,
70-
pub logs: Vec<RPCLog>
70+
pub logs: Vec<RPCLog>,
71+
pub root: Hex<H256>,
72+
pub status: usize,
7173
}
7274

7375
#[derive(Serialize, Deserialize, Debug, Clone)]

src/rpc/util.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use miner::MinerState;
77
use rlp::{self, UntrustedRlp};
88
use bigint::{M256, U256, H256, H2048, Address, Gas};
99
use hexutil::{read_hex, to_hex};
10-
use block::{Block, TotalHeader, Account, Log, Receipt, FromKey, Transaction, UnsignedTransaction, TransactionAction, GlobalSignaturePatch};
10+
use block::{Block, TotalHeader, Account, Log, Receipt, FromKey, Transaction, UnsignedTransaction, TransactionAction, GlobalSignaturePatch, RlpHash};
1111
use blockchain::chain::HeaderHash;
1212
use sputnikvm::{ValidTransaction, VM, VMStatus, MachineStatus, HeaderParams, SeqTransactionVM, Patch, Memory};
1313
use sputnikvm_stateful::MemoryStateful;
@@ -117,6 +117,8 @@ pub fn to_rpc_receipt(state: &MinerState, receipt: Receipt, transaction: &Transa
117117
}
118118
ret
119119
},
120+
root: Hex(receipt.state_root),
121+
status: if state.receipt_status(transaction.rlp_hash()) { 1 } else { 0 },
120122
})
121123
}
122124

0 commit comments

Comments
 (0)