Skip to content

Commit 72f99e5

Browse files
committed
rebase and revert owner replacement
1 parent 42d3acf commit 72f99e5

File tree

1 file changed

+21
-34
lines changed

1 file changed

+21
-34
lines changed

app/receipt.go

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func (app *App) AddCosmosEventsToEVMReceiptIfApplicable(ctx sdk.Context, tx sdk.
3939
return
4040
}
4141
logs := []*ethtypes.Log{}
42-
ownerReplacements := map[uint]common.Hash{}
4342
// Note: txs with a very large number of WASM events may run out of gas due to
4443
// additional gas consumption from EVM receipt generation and event translation
4544
wasmToEvmEventGasLimit := app.EvmKeeper.GetDeliverTxHookWasmGasLimit(ctx.WithGasMeter(sdk.NewInfiniteGasMeter(1, 1)))
@@ -61,13 +60,10 @@ func (app *App) AddCosmosEventsToEVMReceiptIfApplicable(ctx sdk.Context, tx sdk.
6160
// check if there is a ERC721 pointer to contract Addr
6261
pointerAddr, _, exists = app.EvmKeeper.GetERC721CW721Pointer(wasmToEvmEventCtx, contractAddr)
6362
if exists {
64-
log, realOwner, eligible := app.translateCW721Event(wasmToEvmEventCtx, wasmEvent, pointerAddr, contractAddr, response)
63+
log, eligible := app.translateCW721Event(wasmToEvmEventCtx, wasmEvent, pointerAddr, contractAddr, response)
6564
if eligible {
6665
log.Index = uint(len(logs))
6766
logs = append(logs, log)
68-
if (realOwner != common.Hash{}) {
69-
ownerReplacements[log.Index] = realOwner
70-
}
7167
}
7268
continue
7369
}
@@ -81,22 +77,15 @@ func (app *App) AddCosmosEventsToEVMReceiptIfApplicable(ctx sdk.Context, tx sdk.
8177
}
8278
var bloom ethtypes.Bloom
8379
if r, err := app.EvmKeeper.GetTransientReceipt(wasmToEvmEventCtx, txHash); err == nil && r != nil {
84-
existingLogCnt := len(r.Logs)
8580
r.Logs = append(r.Logs, utils.Map(logs, evmkeeper.ConvertSyntheticEthLog)...)
8681
for i, l := range r.Logs {
8782
l.Index = uint32(i)
8883
}
8984
bloom = ethtypes.CreateBloom(ethtypes.Receipts{&ethtypes.Receipt{Logs: evmkeeper.GetLogsForTx(r)}})
9085
r.LogsBloom = bloom[:]
91-
for i, o := range ownerReplacements {
92-
r.Logs[existingLogCnt+int(i)].Topics[1] = o.Hex()
93-
}
9486
_ = app.EvmKeeper.SetTransientReceipt(wasmToEvmEventCtx, txHash, r)
9587
} else {
9688
bloom = ethtypes.CreateBloom(ethtypes.Receipts{&ethtypes.Receipt{Logs: logs}})
97-
for i, o := range ownerReplacements {
98-
logs[int(i)].Topics[1] = o
99-
}
10089
receipt := &evmtypes.Receipt{
10190
TxType: ShellEVMTxType,
10291
TxHashHex: txHash.Hex(),
@@ -184,17 +173,17 @@ func (app *App) translateCW20Event(ctx sdk.Context, wasmEvent abci.Event, pointe
184173
return nil, false
185174
}
186175

187-
func (app *App) translateCW721Event(ctx sdk.Context, wasmEvent abci.Event, pointerAddr common.Address, contractAddr string, response sdk.DeliverTxHookInput) (*ethtypes.Log, common.Hash, bool) {
176+
func (app *App) translateCW721Event(ctx sdk.Context, wasmEvent abci.Event, pointerAddr common.Address, contractAddr string, response sdk.DeliverTxHookInput) (*ethtypes.Log, bool) {
188177
action, found := GetAttributeValue(wasmEvent, "action")
189178
if !found {
190-
return nil, common.Hash{}, false
179+
return nil, false
191180
}
192181
var topics []common.Hash
193182
switch action {
194183
case "transfer_nft", "send_nft", "burn":
195184
tokenID := GetTokenIDAttribute(wasmEvent)
196185
if tokenID == nil {
197-
return nil, common.Hash{}, false
186+
return nil, false
198187
}
199188
sender := common.Hash{}
200189
// unfortunately CW721 transfer events differ from ERC721 transfer events
@@ -204,17 +193,15 @@ func (app *App) translateCW721Event(ctx sdk.Context, wasmEvent abci.Event, point
204193
// synthetic ERC721 event.
205194
ownerEvents := GetEventsOfType(response, wasmtypes.EventTypeCW721PreTransferOwner)
206195
for _, ownerEvent := range ownerEvents {
207-
if len(ownerEvent.Attributes) != 3 {
208-
continue
209-
}
210-
if string(ownerEvent.Attributes[0].Key) != wasmtypes.AttributeKeyContractAddr || string(ownerEvent.Attributes[0].Value) != contractAddr {
196+
if len(ownerEvent.Attributes) != 3 ||
197+
string(ownerEvent.Attributes[0].Key) != wasmtypes.AttributeKeyContractAddr ||
198+
string(ownerEvent.Attributes[0].Value) != contractAddr {
211199
continue
212200
}
213201
tokenIDStr, _ := GetAttributeValue(wasmEvent, "token_id")
214-
if string(ownerEvent.Attributes[1].Key) != wasmtypes.AttributeKeyTokenId || string(ownerEvent.Attributes[1].Value) != tokenIDStr {
215-
continue
216-
}
217-
if string(ownerEvent.Attributes[2].Key) != wasmtypes.AttributeKeyOwner {
202+
if string(ownerEvent.Attributes[1].Key) != wasmtypes.AttributeKeyTokenId ||
203+
string(ownerEvent.Attributes[1].Value) != tokenIDStr ||
204+
string(ownerEvent.Attributes[2].Key) != wasmtypes.AttributeKeyOwner {
218205
continue
219206
}
220207
ownerAcc, err := sdk.AccAddressFromBech32(string(ownerEvent.Attributes[2].Value))
@@ -226,19 +213,19 @@ func (app *App) translateCW721Event(ctx sdk.Context, wasmEvent abci.Event, point
226213
}
227214
topics = []common.Hash{
228215
ERC721TransferTopic,
229-
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
216+
sender,
230217
app.GetEvmAddressAttribute(ctx, wasmEvent, "recipient"),
231218
common.BigToHash(tokenID),
232219
}
233220
return &ethtypes.Log{
234221
Address: pointerAddr,
235222
Topics: topics,
236223
Data: EmptyHash.Bytes(),
237-
}, sender, true
224+
}, true
238225
case "mint":
239226
tokenID := GetTokenIDAttribute(wasmEvent)
240227
if tokenID == nil {
241-
return nil, common.Hash{}, false
228+
return nil, false
242229
}
243230
topics = []common.Hash{
244231
ERC721TransferTopic,
@@ -250,11 +237,11 @@ func (app *App) translateCW721Event(ctx sdk.Context, wasmEvent abci.Event, point
250237
Address: pointerAddr,
251238
Topics: topics,
252239
Data: EmptyHash.Bytes(),
253-
}, common.Hash{}, true
240+
}, true
254241
case "approve":
255242
tokenID := GetTokenIDAttribute(wasmEvent)
256243
if tokenID == nil {
257-
return nil, common.Hash{}, false
244+
return nil, false
258245
}
259246
topics = []common.Hash{
260247
ERC721ApprovalTopic,
@@ -266,11 +253,11 @@ func (app *App) translateCW721Event(ctx sdk.Context, wasmEvent abci.Event, point
266253
Address: pointerAddr,
267254
Topics: topics,
268255
Data: EmptyHash.Bytes(),
269-
}, common.Hash{}, true
256+
}, true
270257
case "revoke":
271258
tokenID := GetTokenIDAttribute(wasmEvent)
272259
if tokenID == nil {
273-
return nil, common.Hash{}, false
260+
return nil, false
274261
}
275262
topics = []common.Hash{
276263
ERC721ApprovalTopic,
@@ -282,7 +269,7 @@ func (app *App) translateCW721Event(ctx sdk.Context, wasmEvent abci.Event, point
282269
Address: pointerAddr,
283270
Topics: topics,
284271
Data: EmptyHash.Bytes(),
285-
}, common.Hash{}, true
272+
}, true
286273
case "approve_all":
287274
topics = []common.Hash{
288275
ERC721ApproveAllTopic,
@@ -293,7 +280,7 @@ func (app *App) translateCW721Event(ctx sdk.Context, wasmEvent abci.Event, point
293280
Address: pointerAddr,
294281
Topics: topics,
295282
Data: TrueHash.Bytes(),
296-
}, common.Hash{}, true
283+
}, true
297284
case "revoke_all":
298285
topics = []common.Hash{
299286
ERC721ApproveAllTopic,
@@ -304,9 +291,9 @@ func (app *App) translateCW721Event(ctx sdk.Context, wasmEvent abci.Event, point
304291
Address: pointerAddr,
305292
Topics: topics,
306293
Data: EmptyHash.Bytes(),
307-
}, common.Hash{}, true
294+
}, true
308295
}
309-
return nil, common.Hash{}, false
296+
return nil, false
310297
}
311298

312299
func (app *App) GetEvmAddressAttribute(ctx sdk.Context, event abci.Event, attribute string) common.Hash {

0 commit comments

Comments
 (0)