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

fix failed back transfer #83

Merged
merged 14 commits into from
Jan 31, 2024
32 changes: 18 additions & 14 deletions contracts/cw721-tester/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_schema::cw_serde;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{Addr, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult};
use cosmwasm_std::{Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult};
use cw2::set_contract_version;
use cw721_base::{msg, ContractError, Extension};
use cw_storage_plus::Item;
Expand All @@ -14,13 +14,13 @@ pub struct InstantiateMsg {
pub name: String,
pub symbol: String,
pub minter: String,
/// An address which will be unable to transfer NFTs away from
/// themselves (they are a black hole). If this address attempts a
/// `TransferNft` message it will fail with an out-of-gas error.
pub target: String,
/// An address which will be unable receive NFT on `TransferNft` message
/// If `TransferNft` message attempts sending to banned recipient
/// it will fail with an out-of-gas error.
pub banned_recipient: String,
}

const TARGET: Item<Addr> = Item::new("target");
const BANNED_RECIPIENT: Item<String> = Item::new("banned_recipient");

const CONTRACT_NAME: &str = "crates.io:cw721-gas-tester";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand All @@ -43,7 +43,7 @@ pub fn instantiate(
withdraw_address: None,
},
)?;
TARGET.save(deps.storage, &deps.api.addr_validate(&msg.target)?)?;
BANNED_RECIPIENT.save(deps.storage, &msg.banned_recipient)?;
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

Ok(response)
Expand All @@ -56,13 +56,17 @@ pub fn execute(
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
if matches!(msg, ExecuteMsg::TransferNft { .. }) && info.sender == TARGET.load(deps.storage)? {
// loop here causes the relayer to hang while it tries to
// simulate the TX.
panic!("gotem")
// loop {}
} else {
cw721_base::entry::execute(deps, env, info, msg)
match msg.clone() {
ExecuteMsg::TransferNft { recipient, .. } => {
if recipient == BANNED_RECIPIENT.load(deps.storage)? {
// loop here causes the relayer to hang while it tries to
// simulate the TX.
panic!("gotem")
// loop {}
}
cw721_base::entry::execute(deps, env, info, msg)
}
_ => cw721_base::entry::execute(deps, env, info, msg),
}
}

Expand Down
25 changes: 25 additions & 0 deletions packages/ics721/schema/ics721.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,31 @@
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"redeem_outgoing_channel_entries"
],
"properties": {
"redeem_outgoing_channel_entries": {
"type": "array",
"items": {
"type": "array",
"items": [
{
"$ref": "#/definitions/ClassId"
},
{
"$ref": "#/definitions/TokenId"
}
],
"maxItems": 2,
"minItems": 2
}
}
},
"additionalProperties": false
},
{
"description": "Mints a NFT of collection class_id for receiver with the provided id and metadata. Only callable by this contract.",
"type": "object",
Expand Down
25 changes: 25 additions & 0 deletions packages/ics721/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,31 @@
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"redeem_outgoing_channel_entries"
],
"properties": {
"redeem_outgoing_channel_entries": {
"type": "array",
"items": {
"type": "array",
"items": [
{
"$ref": "#/definitions/ClassId"
},
{
"$ref": "#/definitions/TokenId"
}
],
"maxItems": 2,
"minItems": 2
}
}
},
"additionalProperties": false
},
{
"description": "Mints a NFT of collection class_id for receiver with the provided id and metadata. Only callable by this contract.",
"type": "object",
Expand Down
34 changes: 31 additions & 3 deletions packages/ics721/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use crate::{
msg::{CallbackMsg, ExecuteMsg, InstantiateMsg, MigrateMsg},
state::{
CollectionData, UniversalAllNftInfoResponse, ADMIN_USED_FOR_CW721, CLASS_ID_TO_CLASS,
CLASS_ID_TO_NFT_CONTRACT, CW721_CODE_ID, INCOMING_PROXY, NFT_CONTRACT_TO_CLASS_ID,
OUTGOING_CLASS_TOKEN_TO_CHANNEL, OUTGOING_PROXY, PO, TOKEN_METADATA,
CLASS_ID_TO_NFT_CONTRACT, CW721_CODE_ID, INCOMING_CLASS_TOKEN_TO_CHANNEL, INCOMING_PROXY,
NFT_CONTRACT_TO_CLASS_ID, OUTGOING_CLASS_TOKEN_TO_CHANNEL, OUTGOING_PROXY, PO,
TOKEN_METADATA,
},
token_types::{VoucherCreation, VoucherRedemption},
ContractError,
Expand Down Expand Up @@ -294,7 +295,12 @@ where
tokens,
receiver,
} => self.callback_mint(deps, class_id, tokens, receiver),

CallbackMsg::RedeemOutgoingChannelEntries(entries) => {
self.callback_redeem_outgoing_channel_entries(deps, entries)
}
CallbackMsg::AddIncomingChannelEntries(entries) => {
self.callback_save_incoming_channel_entries(deps, entries)
}
CallbackMsg::Conjunction { operands } => {
Ok(Response::default().add_messages(operands))
}
Expand Down Expand Up @@ -475,6 +481,28 @@ where
.add_messages(mint))
}

fn callback_redeem_outgoing_channel_entries(
&self,
deps: DepsMut,
entries: Vec<(ClassId, TokenId)>,
) -> Result<Response<T>, ContractError> {
for (class_id, token_id) in entries {
OUTGOING_CLASS_TOKEN_TO_CHANNEL.remove(deps.storage, (class_id, token_id));
}
Ok(Response::default().add_attribute("method", "callback_redeem_outgoing_channel_entries"))
}

fn callback_save_incoming_channel_entries(
&self,
deps: DepsMut,
entries: Vec<((ClassId, TokenId), String)>,
) -> Result<Response<T>, ContractError> {
for (key, channel) in entries {
INCOMING_CLASS_TOKEN_TO_CHANNEL.save(deps.storage, key, &channel)?;
}
Ok(Response::default().add_attribute("method", "callback_redeem_outgoing_channel_entries"))
}

fn migrate(
&self,
deps: DepsMut,
Expand Down
Loading
Loading