Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gas_charge function to the interpreter #8

Merged
merged 2 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod error;
mod executors;
mod flow;
mod frame;
mod gas;
mod log;
mod memory;

Expand All @@ -26,6 +27,7 @@ pub use contract::Contract;
pub use error::ExecuteError;
pub use executors::ProgramState;
pub use frame::{Call, CallFrame};
pub use gas::GasUnit;
pub use log::LogEvent;
pub use memory::MemoryRange;

Expand Down Expand Up @@ -118,6 +120,10 @@ impl<S> Interpreter<S> {
u32::MAX >> 1
}

pub const fn gas_price(&self) -> Word {
self.tx.gas_price()
}

pub fn set_flag(&mut self, a: Word) {
self.registers[REG_FLAG] = a;
}
Expand Down Expand Up @@ -158,6 +164,10 @@ impl<S> Interpreter<S> {
self.context().is_external()
}

pub const fn is_predicate(&self) -> bool {
matches!(self.context, Context::Predicate)
}

pub const fn is_unsafe_math(&self) -> bool {
self.registers[REG_FLAG] & 0x01 == 0x01
}
Expand Down
1 change: 1 addition & 0 deletions src/interpreter/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum ExecuteError {
NotEnoughBalance,
ExpectedInternalContext,
ExternalColorNotFound,
OutOfGas,

#[cfg(feature = "debug")]
DebugStateNotInitialized,
Expand Down
Loading