forked from move-language/move
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add balance trait for the substrate layer
Balance trait can be used to inject external balance handler inside the MoveVM.
- Loading branch information
Showing
14 changed files
with
221 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use move_core_types::{account_address::AccountAddress, vm_status::StatusCode}; | ||
|
||
/// Trait for a balance handler. | ||
/// | ||
/// This is used to provide an access to external balance handling functionality from within the | ||
/// MoveVM. | ||
pub trait BalanceHandler { | ||
type Error: Into<StatusCode>; | ||
|
||
fn transfer( | ||
&self, | ||
src: AccountAddress, | ||
dst: AccountAddress, | ||
cheque_amount: u128, | ||
) -> Result<bool, Self::Error>; | ||
|
||
fn cheque_amount(&self, account: AccountAddress) -> Result<u128, Self::Error>; | ||
|
||
fn total_amount(&self, account: AccountAddress) -> Result<u128, Self::Error>; | ||
} | ||
|
||
/// An unused [`BalanceHandler`] implementation that is needed for special cases (genesis configuration). | ||
pub(crate) struct DummyBalanceHandler; | ||
|
||
impl BalanceHandler for DummyBalanceHandler { | ||
type Error = StatusCode; | ||
|
||
fn transfer( | ||
&self, | ||
_src: AccountAddress, | ||
_dst: AccountAddress, | ||
_cheque_amount: u128, | ||
) -> Result<bool, Self::Error> { | ||
unreachable!() | ||
} | ||
|
||
fn cheque_amount(&self, _account: AccountAddress) -> Result<u128, Self::Error> { | ||
unreachable!() | ||
} | ||
|
||
fn total_amount(&self, _account: AccountAddress) -> Result<u128, Self::Error> { | ||
unreachable!() | ||
} | ||
} |
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
Oops, something went wrong.