Skip to content

Commit

Permalink
Add fund_xcc_sub_account support to standalone engine
Browse files Browse the repository at this point in the history
  • Loading branch information
birchmd committed Mar 23, 2023
1 parent a332a4e commit a2406c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
15 changes: 14 additions & 1 deletion engine-standalone-storage/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ fn non_submit_execute<'db>(

None
}
TransactionKind::FundXccSubAccound(args) => {
let mut handler = crate::promise::NoScheduler { promise_data };
xcc::fund_xcc_sub_account(&io, &mut handler, &env, args.clone())?;

None
}
TransactionKind::Unknown => None,
// Not handled in this function; is handled by the general `execute_transaction` function
TransactionKind::Submit(_) | TransactionKind::SubmitWithArgs(_) => unreachable!(),
Expand Down Expand Up @@ -468,7 +474,7 @@ pub enum TransactionExecutionResult {
}

pub mod error {
use aurora_engine::{connector, engine, fungible_token, state};
use aurora_engine::{connector, engine, fungible_token, state, xcc};

#[derive(Debug)]
pub enum Error {
Expand All @@ -484,6 +490,7 @@ pub mod error {
InvalidAddress(aurora_engine_types::types::address::error::AddressError),
ConnectorInit(connector::error::InitContractError),
ConnectorStorage(connector::error::StorageReadError),
FundXccError(xcc::FundXccError),
}

impl From<state::EngineStateError> for Error {
Expand Down Expand Up @@ -557,4 +564,10 @@ pub mod error {
Self::ConnectorStorage(e)
}
}

impl From<xcc::FundXccError> for Error {
fn from(e: xcc::FundXccError) -> Self {
Self::FundXccError(e)
}
}
}
9 changes: 8 additions & 1 deletion engine-standalone-storage/src/sync/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Storage;
use aurora_engine::parameters;
use aurora_engine::xcc::AddressVersionUpdateArgs;
use aurora_engine::xcc::{AddressVersionUpdateArgs, FundXccArgs};
use aurora_engine_transactions::{EthTransactionKind, NormalizedEthTransaction};
use aurora_engine_types::account_id::AccountId;
use aurora_engine_types::types::Address;
Expand Down Expand Up @@ -128,6 +128,7 @@ pub enum TransactionKind {
/// Update the version of a deployed xcc-router contract
FactoryUpdateAddressVersion(AddressVersionUpdateArgs),
FactorySetWNearAddress(Address),
FundXccSubAccound(FundXccArgs),
/// Sentinel kind for cases where a NEAR receipt caused a
/// change in Aurora state, but we failed to parse the Action.
Unknown,
Expand Down Expand Up @@ -349,6 +350,7 @@ impl TransactionKind {
Self::PausePrecompiles(_) => Self::no_evm_execution("pause_precompiles"),
Self::ResumePrecompiles(_) => Self::no_evm_execution("resume_precompiles"),
Self::SetOwner(_) => Self::no_evm_execution("set_owner"),
Self::FundXccSubAccound(_) => Self::no_evm_execution("fund_xcc_sub_account"),
}
}

Expand Down Expand Up @@ -516,6 +518,7 @@ enum BorshableTransactionKind<'a> {
Unknown,
SetOwner(Cow<'a, parameters::SetOwnerArgs>),
SubmitWithArgs(Cow<'a, parameters::SubmitArgs>),
FundXccSubAccound(Cow<'a, FundXccArgs>),
}

impl<'a> From<&'a TransactionKind> for BorshableTransactionKind<'a> {
Expand Down Expand Up @@ -558,6 +561,7 @@ impl<'a> From<&'a TransactionKind> for BorshableTransactionKind<'a> {
TransactionKind::PausePrecompiles(x) => Self::PausePrecompiles(Cow::Borrowed(x)),
TransactionKind::ResumePrecompiles(x) => Self::ResumePrecompiles(Cow::Borrowed(x)),
TransactionKind::SetOwner(x) => Self::SetOwner(Cow::Borrowed(x)),
TransactionKind::FundXccSubAccound(x) => Self::FundXccSubAccound(Cow::Borrowed(x)),
}
}
}
Expand Down Expand Up @@ -617,6 +621,9 @@ impl<'a> TryFrom<BorshableTransactionKind<'a>> for TransactionKind {
Ok(Self::ResumePrecompiles(x.into_owned()))
}
BorshableTransactionKind::SetOwner(x) => Ok(Self::SetOwner(x.into_owned())),
BorshableTransactionKind::FundXccSubAccound(x) => {
Ok(Self::FundXccSubAccound(x.into_owned()))
}
}
}
}
1 change: 1 addition & 0 deletions engine/src/xcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ pub fn set_code_version_of_address<I: IO>(io: &mut I, address: &Address, version
io.write_storage(&key, &value_bytes);
}

#[derive(Debug, Clone, Copy)]
pub enum FundXccError {
InsufficientBalance,
InvalidAccount,
Expand Down

0 comments on commit a2406c4

Please sign in to comment.