Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor updates #259

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions contracts/name-minter/schema/name-minter.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,6 @@
"properties": {
"address": {
"type": "string"
},
"whitelist_type": {
"anyOf": [
{
"$ref": "#/definitions/WhitelistType"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
Expand All @@ -188,16 +178,6 @@
"properties": {
"address": {
"type": "string"
},
"whitelist_type": {
"anyOf": [
{
"$ref": "#/definitions/WhitelistType"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -252,13 +232,6 @@
"Uint64": {
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
"type": "string"
},
"WhitelistType": {
"type": "string",
"enum": [
"Updatable",
"Flatrate"
]
}
}
},
Expand Down
14 changes: 8 additions & 6 deletions contracts/name-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ pub fn execute_mint_and_list(
.transpose()?
.unwrap_or(None);

println!("discount: {:?}", discount);

let price = validate_payment(name.len(), &info, params.base_price.u128(), discount)?;
if price.clone().is_some() {
charge_fees(
Expand Down Expand Up @@ -343,10 +341,14 @@ fn validate_payment(
})
.into();

if discount.is_some() && amount.ge(&Uint128::from(discount.unwrap())) {
amount = amount
.checked_sub(Uint128::from(discount.unwrap()))
.unwrap();
if let Some(discount_value) = discount {
let discount_amount = Uint128::from(discount_value);
// TODO: should we handle the case where discount > amount (eg 1,000 discount but buying a 100 name)
if amount.ge(&discount_amount) {
amount = amount
.checked_sub(discount_amount)
.map_err(|_| StdError::generic_err("invalid discount amount"))?;
}
}

if amount.is_zero() {
Expand Down
6 changes: 1 addition & 5 deletions contracts/whitelist-updatable-flatrate/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ pub fn execute_add_addresses(

for address in addresses.into_iter() {
let addr = deps.api.addr_validate(&address.clone())?;
if WHITELIST.has(deps.storage, addr.clone()) {
return Err(ContractError::AddressAlreadyExists {
addr: addr.to_string(),
});
} else {
if !WHITELIST.has(deps.storage, addr.clone()) {
WHITELIST.save(deps.storage, addr, &0u32)?;
count += 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ mod tests {
],
};
let res = app.execute_contract(Addr::unchecked(OTHER_ADMIN), wl_addr.clone(), &msg, &[]);
assert!(res.is_err());
assert!(res.is_ok());
let res: bool = app
.wrap()
.query_wasm_smart(
Expand All @@ -254,12 +254,12 @@ mod tests {
}),
)
.unwrap();
assert!(!res);
assert!(res);
let res: u64 = app
.wrap()
.query_wasm_smart(&wl_addr, &(QueryMsg::AddressCount {}))
.unwrap();
assert_eq!(res, 5);
assert_eq!(res, 6);
let msg = ExecuteMsg::AddAddresses {
addresses: vec!["addr0007".to_string(), "addr0006".to_string()],
};
Expand Down
Loading