Skip to content

Commit

Permalink
feat(application): add mint transaction (temporarily)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-wright committed Dec 20, 2024
1 parent 930dc70 commit cc714a8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
45 changes: 42 additions & 3 deletions core/application/src/state/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ impl<B: Backend> StateExecutor<B> {
receiving_address,
} => self.withdraw(txn.payload.sender, receiving_address, amount, token),

UpdateMethod::Mint {
amount,
token,
receiving_address,
} => self.mint(txn.payload.sender, receiving_address, amount, token),

UpdateMethod::Deposit {
proof,
token,
Expand Down Expand Up @@ -519,6 +525,41 @@ impl<B: Backend> StateExecutor<B> {
TransactionResponse::Success(ExecutionData::None)
}

// TODO(matthias): temporary until proof of consensus is implemented
fn mint(
&self,
sender: TransactionSender,
reciever: EthAddress,
amount: HpUfixed<18>,
token: Tokens,
) -> TransactionResponse {
// This transaction is only callable by AccountOwners and not nodes
// So revert if the sender is a node public key
let sender = match self.only_account_owner(sender) {
Ok(account) => account,
Err(e) => return e,
};

let governance_address = match self.metadata.get(&Metadata::GovernanceAddress) {
Some(Value::AccountPublicKey(address)) => address,
_ => unreachable!("Governance address is missing from state."),
};
if sender != governance_address {
return TransactionResponse::Revert(ExecutionError::OnlyGovernance);
}

let mut account = self.account_info.get(&reciever).unwrap_or_default();

// Check the token bridged and increment that amount
match token {
Tokens::FLK => account.flk_balance += amount,
Tokens::USDC => account.bandwidth_balance += TryInto::<u128>::try_into(amount).unwrap(),
}

self.account_info.set(reciever, account);
TransactionResponse::Success(ExecutionData::None)
}

fn deposit(
&self,
sender: TransactionSender,
Expand Down Expand Up @@ -887,11 +928,9 @@ impl<B: Backend> StateExecutor<B> {
Ok(account) => account,
Err(e) => return e,
};
// TODO(matthias): should be panic here or revert? Since the governance address will be
// seeded though genesis, this should never happen.
let governance_address = match self.metadata.get(&Metadata::GovernanceAddress) {
Some(Value::AccountPublicKey(address)) => address,
_ => panic!("Governance address is missing from state."),
_ => unreachable!("Governance address is missing from state."),
};
if sender != governance_address {
return TransactionResponse::Revert(ExecutionError::OnlyGovernance);
Expand Down
23 changes: 23 additions & 0 deletions core/types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,17 @@ pub enum UpdateMethod {
/// The address to recieve these tokens on the L2
receiving_address: EthAddress,
},
/// Mint tokens on the network that were bridged over from the L2
// TODO(matthias): this is a temporary transaction type until the proof of consensus is
// implemented for the `Deposit` transaction.
Mint {
/// The amount to mint.
amount: HpUfixed<18>,
/// Which token to mint.
token: Tokens,
/// The address to recieve these tokens on the network
receiving_address: EthAddress,
},
/// Submit of PoC from the bridge on the L2 to get the tokens in network
Deposit {
/// The proof of the bridge recieved from the L2,
Expand Down Expand Up @@ -536,6 +547,18 @@ impl ToDigest for UpdatePayload {
.with("token", token)
.with("receiving_address", &receiving_address.0);
},
UpdateMethod::Mint {
amount,
token,
receiving_address,
} => {
transcript_builder = transcript_builder
.with("transaction_name", &"mint")
.with_prefix("input".to_owned())
.with("amount", &HpUfixedWrapper(amount.clone()))
.with("token", token)
.with("receiving_address", &receiving_address.0);
},
UpdateMethod::Transfer { amount, token, to } => {
transcript_builder = transcript_builder
.with("transaction_name", &"transfer")
Expand Down

0 comments on commit cc714a8

Please sign in to comment.