Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Jul 2, 2024
1 parent 552903c commit 71c0556
Showing 1 changed file with 97 additions and 95 deletions.
192 changes: 97 additions & 95 deletions app/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,101 +56,10 @@ func (app *App) AddCosmosEventsToEVMReceiptIfApplicable(ctx sdk.Context, tx sdk.
// check if there is a ERC721 pointer to contract Addr
pointerAddr, _, exists = app.EvmKeeper.GetERC721CW721Pointer(ctx, contractAddr)
if exists {
action, found := GetAttributeValue(wasmEvent, "action")
if !found {
continue
}
var topics []common.Hash
switch action {
case "transfer_nft", "send_nft", "burn":
topics = []common.Hash{
ERC721TransferTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
app.GetEvmAddressAttribute(ctx, wasmEvent, "recipient"),
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
continue
}
logs = append(logs, &ethtypes.Log{
Address: pointerAddr,
Index: uint(len(logs)),
Topics: topics,
Data: common.BigToHash(tokenID).Bytes(),
})
continue
case "mint":
topics = []common.Hash{
ERC721TransferTopic,
EmptyHash,
app.GetEvmAddressAttribute(ctx, wasmEvent, "owner"),
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
continue
}
logs = append(logs, &ethtypes.Log{
Address: pointerAddr,
Index: uint(len(logs)),
Topics: topics,
Data: common.BigToHash(tokenID).Bytes(),
})
case "approve":
topics = []common.Hash{
ERC721ApprovalTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
app.GetEvmAddressAttribute(ctx, wasmEvent, "spender"),
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
continue
}
logs = append(logs, &ethtypes.Log{
Address: pointerAddr,
Index: uint(len(logs)),
Topics: topics,
Data: common.BigToHash(tokenID).Bytes(),
})
case "revoke":
topics = []common.Hash{
ERC721ApprovalTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
EmptyHash,
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
continue
}
logs = append(logs, &ethtypes.Log{
Address: pointerAddr,
Index: uint(len(logs)),
Topics: topics,
Data: common.BigToHash(tokenID).Bytes(),
})
case "approve_all":
topics = []common.Hash{
ERC721ApproveAllTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
app.GetEvmAddressAttribute(ctx, wasmEvent, "operator"),
}
logs = append(logs, &ethtypes.Log{
Address: pointerAddr,
Index: uint(len(logs)),
Topics: topics,
Data: TrueHash.Bytes(),
})
case "revoke_all":
topics = []common.Hash{
ERC721ApproveAllTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
app.GetEvmAddressAttribute(ctx, wasmEvent, "operator"),
}
logs = append(logs, &ethtypes.Log{
Address: pointerAddr,
Index: uint(len(logs)),
Topics: topics,
Data: EmptyHash.Bytes(),
})
log, eligible := app.translateCW721Event(ctx, wasmEvent, pointerAddr, contractAddr)
if eligible {
log.Index = uint(len(logs))
logs = append(logs, log)
}
continue
}
Expand Down Expand Up @@ -251,6 +160,99 @@ func (app *App) translateCW20Event(ctx sdk.Context, wasmEvent abci.Event, pointe
return nil, false
}

func (app *App) translateCW721Event(ctx sdk.Context, wasmEvent abci.Event, pointerAddr common.Address, contractAddr string) (*ethtypes.Log, bool) {
action, found := GetAttributeValue(wasmEvent, "action")
if !found {
return nil, false
}
var topics []common.Hash
switch action {
case "transfer_nft", "send_nft", "burn":
topics = []common.Hash{
ERC721TransferTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
app.GetEvmAddressAttribute(ctx, wasmEvent, "recipient"),
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: common.BigToHash(tokenID).Bytes(),
}, true
case "mint":
topics = []common.Hash{
ERC721TransferTopic,
EmptyHash,
app.GetEvmAddressAttribute(ctx, wasmEvent, "owner"),
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: common.BigToHash(tokenID).Bytes(),
}, true
case "approve":
topics = []common.Hash{
ERC721ApprovalTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
app.GetEvmAddressAttribute(ctx, wasmEvent, "spender"),
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: common.BigToHash(tokenID).Bytes(),
}, true
case "revoke":
topics = []common.Hash{
ERC721ApprovalTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
EmptyHash,
}
tokenID := GetTokenIDAttribute(wasmEvent)
if tokenID == nil {
return nil, false
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: common.BigToHash(tokenID).Bytes(),
}, true
case "approve_all":
topics = []common.Hash{
ERC721ApproveAllTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
app.GetEvmAddressAttribute(ctx, wasmEvent, "operator"),
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: TrueHash.Bytes(),
}, true
case "revoke_all":
topics = []common.Hash{
ERC721ApproveAllTopic,
app.GetEvmAddressAttribute(ctx, wasmEvent, "sender"),
app.GetEvmAddressAttribute(ctx, wasmEvent, "operator"),
}
return &ethtypes.Log{
Address: pointerAddr,
Topics: topics,
Data: EmptyHash.Bytes(),
}, true
}
return nil, false
}

func (app *App) GetEvmAddressAttribute(ctx sdk.Context, event abci.Event, attribute string) common.Hash {
addrStr, found := GetAttributeValue(event, attribute)
if found {
Expand Down

0 comments on commit 71c0556

Please sign in to comment.