-
Notifications
You must be signed in to change notification settings - Fork 9
/
lib.rs
168 lines (152 loc) · 6.07 KB
/
lib.rs
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
mod contract_tests;
mod error;
pub mod execute;
pub mod msg;
pub mod query;
pub mod state;
pub mod utils;
use cosmwasm_std::{ensure_eq, to_binary, Empty};
use cw2::set_contract_version;
use execute::{
burn, execute_instantiate, mint, mint_path, send_nft, set_admin_address,
set_username_length_cap, transfer_nft, update_metadata, update_minting_fees,
update_primary_alias, CONTRACT_NAME, CONTRACT_VERSION,
};
use query::{
address_of, contract_info, get_base_tokens_for_owner, get_parent_id, get_parent_nft_info,
get_path, get_paths_for_owner, get_paths_for_owner_and_token, is_contract, list_info_by_alias,
primary_alias,
};
pub use crate::msg::{ContractInfo, ExecuteMsg, Extension, InstantiateMsg, MigrateMsg, QueryMsg};
pub use crate::error::ContractError;
pub type Cw721MetadataContract<'a> = cw721_base::Cw721Contract<'a, Extension, Empty>;
pub mod entry {
use super::*;
use crate::state::{CONTRACT_INFO, LEGACY_CONTRACT_INFO};
use cosmwasm_std::entry_point;
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: InstantiateMsg,
) -> StdResult<Response> {
let tract = Cw721MetadataContract::default();
execute_instantiate(tract, deps, env, info, msg)
}
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
let tract = Cw721MetadataContract::default();
match msg {
ExecuteMsg::UpdateMintingFees(msg) => update_minting_fees(tract, deps, env, info, msg),
ExecuteMsg::UpdateUsernameLengthCap { new_length } => {
set_username_length_cap(tract, deps, env, info, new_length)
}
ExecuteMsg::Mint(msg) => mint(tract, deps, env, info, msg),
ExecuteMsg::MintPath(msg) => mint_path(tract, deps, env, info, msg),
ExecuteMsg::UpdateMetadata(msg) => update_metadata(tract, deps, env, info, msg),
ExecuteMsg::UpdatePrimaryAlias { token_id } => {
update_primary_alias(tract, deps, env, info, token_id)
}
// this actually sets the minter field,
// but the interface is that we call it an admin_address
ExecuteMsg::SetAdminAddress { admin_address } => {
set_admin_address(tract, deps, env, info, admin_address)
}
// we override these purely because in each one of these cases
// we want to remove any preferred username entries
ExecuteMsg::TransferNft {
recipient,
token_id,
} => transfer_nft(tract, deps, env, info, recipient, token_id),
ExecuteMsg::SendNft {
contract,
token_id,
msg,
} => send_nft(tract, deps, env, info, contract, token_id, msg),
ExecuteMsg::Burn { token_id } => burn(tract, deps, env, info, token_id),
_ => tract
.execute(deps, env, info, msg.into())
.map_err(ContractError::Base),
}
}
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
let tract = Cw721MetadataContract::default();
match msg {
QueryMsg::BaseTokens {
owner,
start_after,
limit,
} => to_binary(&get_base_tokens_for_owner(
tract,
deps,
owner,
start_after,
limit,
)?),
QueryMsg::PrimaryAlias { address } => {
to_binary(&primary_alias(tract, deps, env, address)?)
}
QueryMsg::ContractInfo {} => to_binary(&contract_info(deps)?),
QueryMsg::IsContract { token_id } => to_binary(&is_contract(tract, deps, token_id)?),
QueryMsg::AddressOf { token_id } => to_binary(&address_of(tract, deps, token_id)?),
QueryMsg::GetParentId { token_id } => to_binary(&get_parent_id(tract, deps, token_id)?),
QueryMsg::GetParentInfo { token_id } => {
to_binary(&get_parent_nft_info(tract, deps, token_id)?)
}
QueryMsg::GetFullPath { token_id } => to_binary(&get_path(tract, deps, token_id)?),
QueryMsg::Paths {
owner,
start_after,
limit,
} => to_binary(&get_paths_for_owner(
tract,
deps,
owner,
start_after,
limit,
)?),
QueryMsg::PathsForToken {
owner,
token_id,
start_after,
limit,
} => to_binary(&get_paths_for_owner_and_token(
deps,
owner,
token_id,
start_after,
limit,
)?),
QueryMsg::ListInfoByAlias { aliases } => {
to_binary(&list_info_by_alias(tract, deps, aliases)?)
}
_ => tract.query(deps, env, msg.into()).map_err(|err| err),
}
}
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
ensure_eq!(
msg.target_version,
CONTRACT_VERSION,
ContractError::Unauthorized {}
);
let contract_info = LEGACY_CONTRACT_INFO.load(deps.storage)?;
let info = ContractInfo {
name: contract_info.name,
symbol: "DENS".to_string(),
};
// in this version of the code
// the storage key has been changed
CONTRACT_INFO.save(deps.storage, &info)?;
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::new().add_attribute("action", "migrate"))
}
}