1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
use crate::execute::admin_update_admin::admin_update_admin;
use crate::execute::admin_update_deposit_required_attributes::admin_update_deposit_required_attributes;
use crate::execute::admin_update_withdraw_required_attributes::admin_update_withdraw_required_attributes;
use crate::execute::fund_trading::fund_trading;
use crate::execute::withdraw_trading::withdraw_trading;
use crate::instantiate::instantiate_contract::instantiate_contract;
use crate::migrate::migrate_contract::migrate_contract;
use crate::query::query_contract_state::query_contract_state;
use crate::types::error::ContractError;
use crate::types::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use crate::util::self_validating::SelfValidating;
use cosmwasm_std::{entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Response};
/// The entry point used when an account instantiates a stored code wasm payload of this contract on
/// the Provenance Blockchain.
///
/// # Parameters
///
/// * `deps` A dependencies object provided by the cosmwasm framework. Allows access to useful
/// resources like contract internal storage and a querier to retrieve blockchain objects.
/// * `env` An environment object provided by the cosmwasm framework. Describes the contract's
/// details, as well as blockchain information at the time of the transaction.
/// * `info` A message information object provided by the cosmwasm framework. Describes the sender
/// of the instantiation message, as well as the funds provided as an amount during the transaction.
/// * `msg` A custom instantiation message defined by this contract for creating the initial
/// configuration used by the contract.
#[entry_point]
pub fn instantiate(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
msg.self_validate()?;
instantiate_contract(deps, env, info, msg)
}
/// The entry point used when an account initiates an execution process defined in the contract.
/// This defines the primary purposes of the contract.
///
/// # Parameters
///
/// * `deps` A dependencies object provided by the cosmwasm framework. Allows access to useful
/// resources like contract internal storage and a querier to retrieve blockchain objects.
/// * `env` An environment object provided by the cosmwasm framework. Describes the contract's
/// details, as well as blockchain information at the time of the transaction.
/// * `info` A message information object provided by the cosmwasm framework. Describes the sender
/// of the instantiation message, as well as the funds provided as an amount during the transaction.
/// * `msg` A custom execution message enum defined by this contract to allow multiple different
/// processes to be defined for the singular execution route entry point allowed by the
/// cosmwasm framework.
#[entry_point]
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
msg.self_validate()?;
match msg {
ExecuteMsg::AdminUpdateAdmin { new_admin_address } => {
admin_update_admin(deps, env, info, new_admin_address)
}
ExecuteMsg::AdminUpdateDepositRequiredAttributes { attributes } => {
admin_update_deposit_required_attributes(deps, env, info, attributes)
}
ExecuteMsg::AdminUpdateWithdrawRequiredAttributes { attributes } => {
admin_update_withdraw_required_attributes(deps, env, info, attributes)
}
ExecuteMsg::FundTrading { trade_amount } => {
fund_trading(deps, env, info, trade_amount.u128())
}
ExecuteMsg::WithdrawTrading { trade_amount } => {
withdraw_trading(deps, env, info, trade_amount.u128())
}
}
}
/// The entry point used when an account invokes the contract to retrieve information. Allows
/// access to the internal storage information in an immutable manner.
///
/// # Parameters
///
/// * `deps` A dependencies object provided by the cosmwasm framework. Allows access to useful
/// resources like contract internal storage and a querier to retrieve blockchain objects.
/// * `_env` An environment object provided by the cosmwasm framework. Describes the contract's
/// details, as well as blockchain information at the time of the transaction. Unused by this
/// function, but required by cosmwasm for successfully defined query entrypoint.
/// * `msg` A custom query message enum defined by this contract to allow multiple different results
/// to be determined for this route.
#[entry_point]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractError> {
msg.self_validate()?;
match msg {
QueryMsg::QueryContractState {} => query_contract_state(deps),
}
}
/// The entry point used when the contract admin migrates an existing instance of this contract to
/// a new stored code instance on chain.
///
/// # Parameters
///
/// * `deps` A dependencies object provided by the cosmwasm framework. Allows access to useful
/// resources like contract internal storage and a querier to retrieve blockchain objects.
/// * `_env` An environment object provided by the cosmwasm framework. Describes the contract's
/// details, as well as blockchain information at the time of the transaction. Unused by this
/// function, but required by cosmwasm for successfully defined migration entrypoint.
/// * msg` A custom migrate message enum defined by this contract to allow multiple different
/// results of invoking the migrate endpoint.
#[entry_point]
pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
msg.self_validate()?;
match msg {
MigrateMsg::ContractUpgrade {} => migrate_contract(deps),
}
}