Skip to content

Commit

Permalink
Merge pull request #590 from oasisprotocol/pro-wh/bugfix/nftburn
Browse files Browse the repository at this point in the history
runtime: add explicit PossibleNFT.Burned field
  • Loading branch information
pro-wh authored Dec 20, 2023
2 parents 7bc521f + 587790b commit d088140
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions analyzer/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ var (

RuntimeEVMNFTUpdateTransfer = `
UPDATE chain.evm_nfts SET
owner = $4,
num_transfers = num_transfers + $5
num_transfers = num_transfers + $4,
owner = $5
WHERE
runtime = $1 AND
token_address = $2 AND
Expand Down
15 changes: 9 additions & 6 deletions analyzer/runtime/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ type NFTKey struct {
}

type PossibleNFT struct {
// NewOwner has the latest owner if .NumTransfers is more than zero. If
// the last transfer burned this NFT instance, then it's the empty string.
NewOwner apiTypes.Address
// NumTransfers is how many times we saw it transferred. If it's more than
// zero, the new owner is in .NewOwner.
// zero, Burned or NewOwner will be set.
NumTransfers int
// Burned is true if NumTransfers is more than zero and the NFT instance
// was burned.
Burned bool
// NewOwner has the latest owner if NumTransfers is more than zero.
NewOwner apiTypes.Address
}

type BlockData struct {
Expand Down Expand Up @@ -271,9 +273,10 @@ func registerNFTExist(nftChanges map[NFTKey]*PossibleNFT, contractAddr apiTypes.
findPossibleNFT(nftChanges, contractAddr, tokenID)
}

func registerNFTTransfer(nftChanges map[NFTKey]*PossibleNFT, contractAddr apiTypes.Address, tokenID *big.Int, newOwner apiTypes.Address) {
func registerNFTTransfer(nftChanges map[NFTKey]*PossibleNFT, contractAddr apiTypes.Address, tokenID *big.Int, burned bool, newOwner apiTypes.Address) {
possibleNFT := findPossibleNFT(nftChanges, contractAddr, tokenID)
possibleNFT.NumTransfers++
possibleNFT.Burned = burned
possibleNFT.NewOwner = newOwner
}

Expand Down Expand Up @@ -1006,7 +1009,7 @@ func extractEvents(blockData *BlockData, relatedAccountAddresses map[apiTypes.Ad
}
registerNFTExist(blockData.PossibleNFTs, eventAddr, tokenID)
// Mints, burns, and zero-value transfers all count as transfers.
registerNFTTransfer(blockData.PossibleNFTs, eventAddr, tokenID, toAddr)
registerNFTTransfer(blockData.PossibleNFTs, eventAddr, tokenID, toZero, toAddr)
eventData.EvmLogName = evmabi.ERC721.Events["Transfer"].Name
eventData.EvmLogSignature = ethCommon.BytesToHash(event.Topics[0])
eventData.EvmLogParams = []*apiTypes.EvmEventParam{
Expand Down
4 changes: 2 additions & 2 deletions analyzer/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,16 @@ func (m *processor) queueDbUpdates(batch *storage.QueryBatch, data *BlockData) {
)
if possibleNFT.NumTransfers > 0 {
var newOwner *apiTypes.Address
if possibleNFT.NewOwner != "" {
if !possibleNFT.Burned {
newOwner = &possibleNFT.NewOwner
}
batch.Queue(
queries.RuntimeEVMNFTUpdateTransfer,
m.runtime,
key.TokenAddress,
key.TokenID,
newOwner,
possibleNFT.NumTransfers,
newOwner,
)
}
}
Expand Down

0 comments on commit d088140

Please sign in to comment.