Skip to content

Commit

Permalink
Merge pull request #37 from ethereumproject/develop
Browse files Browse the repository at this point in the history
status and root for getTransactionReceipt
  • Loading branch information
sorpaas authored Sep 28, 2017
2 parents bbf9d21 + 4abe75e commit 5025c59
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/miner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::collections::HashMap;
use std::time::{SystemTime, UNIX_EPOCH};
use std::sync::{Arc, Mutex};
use std::sync::mpsc::{channel, Sender, Receiver};
use sputnikvm::{AccountChange, ValidTransaction, Patch, AccountCommitment, AccountState, HeaderParams, SeqTransactionVM, VM};
use sputnikvm::{AccountChange, ValidTransaction, Patch, AccountCommitment, AccountState, HeaderParams, SeqTransactionVM, VM, VMStatus};
use sputnikvm::errors::RequireError;
use sputnikvm_stateful::MemoryStateful;
use rand::os::OsRng;
Expand Down Expand Up @@ -167,6 +167,7 @@ pub fn mine_one<P: Patch>(state: Arc<Mutex<MinerState>>, address: Address) {
state.fat_transit(current_block.header.number.as_usize(), &[]);

for transaction in transactions.clone() {
let transaction_hash = transaction.rlp_hash();
let valid = state.stateful_mut().to_valid::<P>(transaction).unwrap();
let vm: SeqTransactionVM<P> = {
let vm = state.stateful_mut().call(valid, HeaderParams::from(&current_block.header),
Expand Down Expand Up @@ -197,6 +198,14 @@ pub fn mine_one<P: Patch>(state: Arc<Mutex<MinerState>>, address: Address) {
state_root: state.stateful_mut().root(),
};
receipts.push(receipt);

state.set_receipt_status(
transaction_hash,
match vm.status() {
VMStatus::ExitedOk => true,
_ => false,
}
);
}

let root = state.stateful_mut().root();
Expand Down
10 changes: 10 additions & 0 deletions src/miner/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct MinerState {
block_database: HashMap<H256, Block>,
receipt_database: HashMap<H256, Receipt>,
fat_database: Vec<HashMap<Address, HashMap<U256, M256>>>,
status_database: HashMap<H256, bool>,

accounts: Vec<SecretKey>,
database: &'static MemoryDatabase,
Expand Down Expand Up @@ -60,6 +61,7 @@ impl MinerState {
transaction_database: HashMap::new(),
receipt_database: HashMap::new(),
fat_database: vec![HashMap::new()],
status_database: HashMap::new(),

accounts: Vec::new(),
}
Expand Down Expand Up @@ -249,4 +251,12 @@ impl MinerState {
pub fn append_account(&mut self, key: SecretKey) {
self.accounts.push(key)
}

pub fn set_receipt_status(&mut self, transaction_hash: H256, is_okay: bool) {
self.status_database.insert(transaction_hash, is_okay);
}

pub fn receipt_status(&self, transaction_hash: H256) -> bool {
*self.status_database.get(&transaction_hash).unwrap_or(&false)
}
}
4 changes: 3 additions & 1 deletion src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ pub struct RPCReceipt {
pub cumulative_gas_used: String,
pub gas_used: String,
pub contract_address: Option<String>,
pub logs: Vec<RPCLog>
pub logs: Vec<RPCLog>,
pub root: Hex<H256>,
pub status: usize,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down
4 changes: 3 additions & 1 deletion src/rpc/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use miner::MinerState;
use rlp::{self, UntrustedRlp};
use bigint::{M256, U256, H256, H2048, Address, Gas};
use hexutil::{read_hex, to_hex};
use block::{Block, TotalHeader, Account, Log, Receipt, FromKey, Transaction, UnsignedTransaction, TransactionAction, GlobalSignaturePatch};
use block::{Block, TotalHeader, Account, Log, Receipt, FromKey, Transaction, UnsignedTransaction, TransactionAction, GlobalSignaturePatch, RlpHash};
use blockchain::chain::HeaderHash;
use sputnikvm::{ValidTransaction, VM, VMStatus, MachineStatus, HeaderParams, SeqTransactionVM, Patch, Memory};
use sputnikvm_stateful::MemoryStateful;
Expand Down Expand Up @@ -117,6 +117,8 @@ pub fn to_rpc_receipt(state: &MinerState, receipt: Receipt, transaction: &Transa
}
ret
},
root: Hex(receipt.state_root),
status: if state.receipt_status(transaction.rlp_hash()) { 1 } else { 0 },
})
}

Expand Down

0 comments on commit 5025c59

Please sign in to comment.