Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47fd5697ed |
@@ -695,6 +695,46 @@ pub trait MixnetSigningClient {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn admin_add_mixnode(
|
||||||
|
&self,
|
||||||
|
mix_node: MixNode,
|
||||||
|
cost_params: MixNodeCostParams,
|
||||||
|
owner: String,
|
||||||
|
pledge: Coin,
|
||||||
|
fee: Option<Fee>,
|
||||||
|
) -> Result<ExecuteResult, NyxdError> {
|
||||||
|
self.execute_mixnet_contract(
|
||||||
|
fee,
|
||||||
|
MixnetExecuteMsg::UncheckedImportMixnode {
|
||||||
|
mix_node,
|
||||||
|
cost_params,
|
||||||
|
owner,
|
||||||
|
pledge: pledge.into(),
|
||||||
|
},
|
||||||
|
vec![],
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn admin_add_gateway(
|
||||||
|
&self,
|
||||||
|
gateway: Gateway,
|
||||||
|
owner: String,
|
||||||
|
pledge: Coin,
|
||||||
|
fee: Option<Fee>,
|
||||||
|
) -> Result<ExecuteResult, NyxdError> {
|
||||||
|
self.execute_mixnet_contract(
|
||||||
|
fee,
|
||||||
|
MixnetExecuteMsg::UncheckedImportGateway {
|
||||||
|
gateway,
|
||||||
|
owner,
|
||||||
|
pledge: pledge.into(),
|
||||||
|
},
|
||||||
|
vec![],
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
|
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
|
||||||
@@ -734,6 +774,7 @@ where
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::nyxd::contract_traits::tests::{mock_coin, IgnoreValue};
|
use crate::nyxd::contract_traits::tests::{mock_coin, IgnoreValue};
|
||||||
|
use nym_mixnet_contract_common::ExecuteMsg;
|
||||||
|
|
||||||
// it's enough that this compiles and clippy is happy about it
|
// it's enough that this compiles and clippy is happy about it
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@@ -933,6 +974,21 @@ mod tests {
|
|||||||
MixnetExecuteMsg::TestingResolveAllPendingEvents { .. } => {
|
MixnetExecuteMsg::TestingResolveAllPendingEvents { .. } => {
|
||||||
client.testing_resolve_all_pending_events(None).ignore()
|
client.testing_resolve_all_pending_events(None).ignore()
|
||||||
}
|
}
|
||||||
|
ExecuteMsg::UncheckedImportMixnode {
|
||||||
|
mix_node,
|
||||||
|
cost_params,
|
||||||
|
owner,
|
||||||
|
pledge,
|
||||||
|
} => client
|
||||||
|
.admin_add_mixnode(mix_node, cost_params, owner, pledge.into(), None)
|
||||||
|
.ignore(),
|
||||||
|
ExecuteMsg::UncheckedImportGateway {
|
||||||
|
gateway,
|
||||||
|
owner,
|
||||||
|
pledge,
|
||||||
|
} => client
|
||||||
|
.admin_add_gateway(gateway, owner, pledge.into(), None)
|
||||||
|
.ignore(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -274,6 +274,19 @@ pub enum ExecuteMsg {
|
|||||||
TestingResolveAllPendingEvents {
|
TestingResolveAllPendingEvents {
|
||||||
limit: Option<u32>,
|
limit: Option<u32>,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// speedtest:
|
||||||
|
UncheckedImportMixnode {
|
||||||
|
mix_node: MixNode,
|
||||||
|
cost_params: MixNodeCostParams,
|
||||||
|
owner: String,
|
||||||
|
pledge: Coin,
|
||||||
|
},
|
||||||
|
UncheckedImportGateway {
|
||||||
|
gateway: Gateway,
|
||||||
|
owner: String,
|
||||||
|
pledge: Coin,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExecuteMsg {
|
impl ExecuteMsg {
|
||||||
@@ -385,6 +398,9 @@ impl ExecuteMsg {
|
|||||||
ExecuteMsg::TestingResolveAllPendingEvents { .. } => {
|
ExecuteMsg::TestingResolveAllPendingEvents { .. } => {
|
||||||
"resolving all pending events".into()
|
"resolving all pending events".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExecuteMsg::UncheckedImportMixnode { .. } => "unchecked import mixnode".into(),
|
||||||
|
ExecuteMsg::UncheckedImportGateway { .. } => "unchecked import gateway".into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use crate::interval::storage as interval_storage;
|
|||||||
use crate::mixnet_contract_settings::storage as mixnet_params_storage;
|
use crate::mixnet_contract_settings::storage as mixnet_params_storage;
|
||||||
use crate::mixnodes::storage as mixnode_storage;
|
use crate::mixnodes::storage as mixnode_storage;
|
||||||
use crate::rewards::storage as rewards_storage;
|
use crate::rewards::storage as rewards_storage;
|
||||||
|
use crate::speedtest_tmp::{admin_add_gateway, admin_add_mixnode};
|
||||||
use cosmwasm_std::{
|
use cosmwasm_std::{
|
||||||
entry_point, to_binary, Addr, Coin, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response,
|
entry_point, to_binary, Addr, Coin, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response,
|
||||||
};
|
};
|
||||||
@@ -372,6 +373,18 @@ pub fn execute(
|
|||||||
ExecuteMsg::TestingResolveAllPendingEvents { limit } => {
|
ExecuteMsg::TestingResolveAllPendingEvents { limit } => {
|
||||||
crate::testing::transactions::try_resolve_all_pending_events(deps, env, limit)
|
crate::testing::transactions::try_resolve_all_pending_events(deps, env, limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExecuteMsg::UncheckedImportMixnode {
|
||||||
|
mix_node,
|
||||||
|
cost_params,
|
||||||
|
owner,
|
||||||
|
pledge,
|
||||||
|
} => admin_add_mixnode(deps, env, info, mix_node, cost_params, pledge, owner),
|
||||||
|
ExecuteMsg::UncheckedImportGateway {
|
||||||
|
gateway,
|
||||||
|
owner,
|
||||||
|
pledge,
|
||||||
|
} => admin_add_gateway(deps, env, info, gateway, pledge, owner),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,3 +19,5 @@ mod support;
|
|||||||
|
|
||||||
#[cfg(feature = "contract-testing")]
|
#[cfg(feature = "contract-testing")]
|
||||||
mod testing;
|
mod testing;
|
||||||
|
|
||||||
|
mod speedtest_tmp;
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
use crate::gateways::storage::gateways;
|
||||||
|
use crate::mixnet_contract_settings::storage as mixnet_params_storage;
|
||||||
|
use crate::mixnodes::helpers::save_new_mixnode;
|
||||||
|
use crate::support::helpers::ensure_no_existing_bond;
|
||||||
|
use cosmwasm_std::{Coin, DepsMut, Env, MessageInfo, Response};
|
||||||
|
use mixnet_contract_common::error::MixnetContractError;
|
||||||
|
use mixnet_contract_common::{Gateway, GatewayBond, MixNode, MixNodeCostParams};
|
||||||
|
|
||||||
|
pub fn admin_add_mixnode(
|
||||||
|
deps: DepsMut<'_>,
|
||||||
|
env: Env,
|
||||||
|
info: MessageInfo,
|
||||||
|
mixnode: MixNode,
|
||||||
|
cost_params: MixNodeCostParams,
|
||||||
|
pledge: Coin,
|
||||||
|
owner: String,
|
||||||
|
) -> Result<Response, MixnetContractError> {
|
||||||
|
let state = mixnet_params_storage::CONTRACT_STATE.load(deps.storage)?;
|
||||||
|
|
||||||
|
// check if this is executed by the owner, if not reject the transaction
|
||||||
|
if info.sender != state.owner {
|
||||||
|
return Err(MixnetContractError::Unauthorized);
|
||||||
|
}
|
||||||
|
|
||||||
|
let owner = deps.api.addr_validate(&owner)?;
|
||||||
|
|
||||||
|
ensure_no_existing_bond(&owner, deps.storage)?;
|
||||||
|
|
||||||
|
save_new_mixnode(deps.storage, env, mixnode, cost_params, owner, None, pledge)?;
|
||||||
|
|
||||||
|
Ok(Response::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn admin_add_gateway(
|
||||||
|
deps: DepsMut<'_>,
|
||||||
|
env: Env,
|
||||||
|
info: MessageInfo,
|
||||||
|
gateway: Gateway,
|
||||||
|
pledge: Coin,
|
||||||
|
owner: String,
|
||||||
|
) -> Result<Response, MixnetContractError> {
|
||||||
|
let state = mixnet_params_storage::CONTRACT_STATE.load(deps.storage)?;
|
||||||
|
|
||||||
|
// check if this is executed by the owner, if not reject the transaction
|
||||||
|
if info.sender != state.owner {
|
||||||
|
return Err(MixnetContractError::Unauthorized);
|
||||||
|
}
|
||||||
|
|
||||||
|
let owner = deps.api.addr_validate(&owner)?;
|
||||||
|
|
||||||
|
ensure_no_existing_bond(&owner, deps.storage)?;
|
||||||
|
|
||||||
|
let bond = GatewayBond::new(pledge, owner, env.block.height, gateway, None);
|
||||||
|
gateways().save(deps.storage, bond.identity(), &bond)?;
|
||||||
|
|
||||||
|
Ok(Response::new())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user