This repository has been archived by the owner on Aug 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Runtime - extracting code to `load_template` * Runtime#spawn uses `create_account` * Adding `GasTank` * Using the term `gas_limit` only in the context of the `Envelope` * Fixed a couple of tests * GasTank#unwrap * Returning back test assertions * cargo doc fix * Runtime#create_genesis_account (changes requested during PR review)
- Loading branch information
1 parent
a3147f6
commit 6edb73d
Showing
20 changed files
with
411 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use svm_types::Gas; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq)] | ||
pub enum GasTank { | ||
NonEmpty(u64), | ||
Empty, | ||
} | ||
|
||
impl GasTank { | ||
pub fn new(gas: Gas) -> Self { | ||
let gas = gas.unwrap_or(std::u64::MAX); | ||
|
||
if gas > 0 { | ||
GasTank::NonEmpty(gas) | ||
} else { | ||
GasTank::Empty | ||
} | ||
} | ||
|
||
pub fn is_empty(&self) -> bool { | ||
matches!(self, Self::Empty) | ||
} | ||
|
||
pub fn consume(self, gas: u64) -> GasTank { | ||
match self { | ||
GasTank::Empty => GasTank::Empty, | ||
GasTank::NonEmpty(left) => { | ||
if left > gas { | ||
GasTank::NonEmpty(left - gas) | ||
} else { | ||
GasTank::Empty | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn unwrap(self) -> u64 { | ||
match self { | ||
GasTank::Empty => 0, | ||
GasTank::NonEmpty(gas) => gas, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.