Skip to content

Commit

Permalink
cw721: Move transfer events after action event (sei-protocol#1679)
Browse files Browse the repository at this point in the history
* move transfer events after action event

* Update compiled contract file and bump version

* Update module test with new key

---------

Co-authored-by: dvli2007 <[email protected]>
Co-authored-by: davyli <[email protected]>
  • Loading branch information
3 people authored May 17, 2024
1 parent 2babe51 commit 96ec672
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
Binary file modified contracts/wasm/cwerc721.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion example/cosmwasm/cw721/artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dc05f927aaacb4d0f500ef7712607e06a55fa2d812cd21505bd1e98ed942273b cwerc721.wasm
4355b9f7c6a3337ee6994512155435bdfc80bd151a57e78fd50f9d41e62a8aaa cwerc721.wasm
Binary file modified example/cosmwasm/cw721/artifacts/cwerc721.wasm
Binary file not shown.
34 changes: 18 additions & 16 deletions example/cosmwasm/cw721/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ pub fn execute_transfer_nft(
recipient: String,
token_id: String,
) -> Result<Response<EvmMsg>, ContractError> {
let mut res = transfer_nft(deps, info, recipient, token_id)?;
res = res.add_attribute("action", "transfer_nft");
let mut res = transfer_nft(deps, &info, &recipient, &token_id)?;
res = res.add_attribute("action", "transfer_nft")
.add_attribute("sender", info.sender)
.add_attribute("recipient", recipient)
.add_attribute("token_id", token_id);
Ok(res)
}

Expand All @@ -76,15 +79,18 @@ pub fn execute_send_nft(
token_id: String,
msg: Binary,
) -> Result<Response<EvmMsg>, ContractError> {
let mut res = transfer_nft(deps, info.clone(), recipient.clone(), token_id.clone())?;
let mut res = transfer_nft(deps, &info, &recipient, &token_id)?;
let send = Cw721ReceiveMsg {
sender: info.sender.to_string(),
token_id: token_id.clone(),
token_id: token_id.to_string(),
msg,
};
res = res
.add_message(send.into_cosmos_msg(recipient.clone())?)
.add_attribute("action", "send_nft");
.add_attribute("action", "send_nft")
.add_attribute("sender", info.sender)
.add_attribute("recipient", recipient)
.add_attribute("token_id", token_id);
Ok(res)
}

Expand Down Expand Up @@ -159,23 +165,19 @@ pub fn execute_extension() -> Result<Response<EvmMsg>, ContractError> {

fn transfer_nft(
deps: DepsMut<EvmQueryWrapper>,
info: MessageInfo,
recipient: String,
token_id: String,
info: &MessageInfo,
recipient: &str,
token_id: &str,
) -> Result<Response<EvmMsg>, ContractError> {
deps.api.addr_validate(&recipient)?;
deps.api.addr_validate(recipient)?;

let erc_addr = ERC721_ADDRESS.load(deps.storage)?;

let querier = EvmQuerier::new(&deps.querier);
let owner = querier.erc721_owner(info.sender.clone().into_string(), erc_addr.clone(), token_id.clone())?.owner;
let payload = querier.erc721_transfer_payload(owner, recipient.clone(), token_id.clone())?;
let owner = querier.erc721_owner(info.sender.to_string(), erc_addr.to_string(), token_id.to_string())?.owner;
let payload = querier.erc721_transfer_payload(owner, recipient.to_string(), token_id.to_string())?;
let msg = EvmMsg::DelegateCallEvm { to: erc_addr, data: payload.encoded_payload };
let res = Response::new()
.add_attribute("sender", info.sender)
.add_attribute("recipient", recipient)
.add_attribute("token_id", token_id)
.add_message(msg);
let res = Response::new().add_message(msg);

Ok(res)
}
Expand Down
2 changes: 1 addition & 1 deletion x/evm/artifacts/erc721/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package erc721

import "embed"

const CurrentVersion uint16 = 4
const CurrentVersion uint16 = 5

//go:embed cwerc721.wasm
var f embed.FS
Expand Down
Binary file modified x/evm/artifacts/erc721/cwerc721.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion x/evm/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestModuleExportGenesis(t *testing.T) {
module := evm.NewAppModule(nil, k)
jsonMsg := module.ExportGenesis(ctx, types.ModuleCdc)
jsonStr := string(jsonMsg)
assert.Equal(t, "{\"params\":{\"priority_normalizer\":\"1.000000000000000000\",\"base_fee_per_gas\":\"0.000000000000000000\",\"minimum_fee_per_gas\":\"1000000000.000000000000000000\",\"whitelisted_cw_code_hashes_for_delegate_call\":[]},\"address_associations\":[{\"sei_address\":\"sei17xpfvakm2amg962yls6f84z3kell8c5la4jkdu\",\"eth_address\":\"0x27F7B8B8B5A4e71E8E9aA671f4e4031E3773303F\"}],\"codes\":[],\"states\":[],\"nonces\":[],\"serialized\":[{\"prefix\":\"Fg==\",\"key\":\"AwAB\",\"value\":\"AAAAAAAAAAM=\"},{\"prefix\":\"Fg==\",\"key\":\"BAAE\",\"value\":\"AAAAAAAAAAQ=\"}]}", jsonStr)
assert.Equal(t, "{\"params\":{\"priority_normalizer\":\"1.000000000000000000\",\"base_fee_per_gas\":\"0.000000000000000000\",\"minimum_fee_per_gas\":\"1000000000.000000000000000000\",\"whitelisted_cw_code_hashes_for_delegate_call\":[]},\"address_associations\":[{\"sei_address\":\"sei17xpfvakm2amg962yls6f84z3kell8c5la4jkdu\",\"eth_address\":\"0x27F7B8B8B5A4e71E8E9aA671f4e4031E3773303F\"}],\"codes\":[],\"states\":[],\"nonces\":[],\"serialized\":[{\"prefix\":\"Fg==\",\"key\":\"AwAB\",\"value\":\"AAAAAAAAAAM=\"},{\"prefix\":\"Fg==\",\"key\":\"BAAF\",\"value\":\"AAAAAAAAAAQ=\"}]}", jsonStr)
}

func TestConsensusVersion(t *testing.T) {
Expand Down

0 comments on commit 96ec672

Please sign in to comment.