Skip to content

Commit

Permalink
modules/consensus_accounts: handle incoming message tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Mar 15, 2022
1 parent b0dad9d commit 524cfcc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions runtime-sdk/src/modules/consensus_accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,41 @@ impl<Accounts: modules::accounts::API, Consensus: modules::consensus::API>
impl<Accounts: modules::accounts::API, Consensus: modules::consensus::API>
module::IncomingMessageHandler for Module<Accounts, Consensus>
{
fn prefetch_in_msg(
_prefixes: &mut BTreeSet<Prefix>,
_in_msg: &roothash::IncomingMessage,
_data: &IncomingMessageData,
_tx: &Option<Transaction>,
) -> Result<(), error::RuntimeError> {
// todo: their account
Ok(())
}

fn execute_in_msg<C: Context>(
ctx: &mut C,
in_msg: &roothash::IncomingMessage,
_data: &IncomingMessageData,
_tx: &Option<Transaction>,
) -> Result<(), error::RuntimeError> {
if !in_msg.fee.is_zero() {
let amount = token::BaseUnits(
Consensus::amount_from_consensus(ctx, (&in_msg.fee).try_into().unwrap()).unwrap(),
Consensus::consensus_denomination(ctx).unwrap(),
);
Accounts::mint_into_fee_accumulator(ctx, &amount).unwrap();
// TODO: Emit event that fee has been paid.
}
if !in_msg.tokens.is_zero() {
let amount = token::BaseUnits(
Consensus::amount_from_consensus(ctx, (&in_msg.tokens).try_into().unwrap())
.unwrap(),
Consensus::consensus_denomination(ctx).unwrap(),
);
Accounts::mint(ctx, (&in_msg.caller).into(), &amount).unwrap();
// TODO: Emit event.
}
Ok(())
}
}

impl<Accounts: modules::accounts::API, Consensus: modules::consensus::API> module::BlockHandler
Expand Down

0 comments on commit 524cfcc

Please sign in to comment.