Skip to content

Commit

Permalink
Merge pull request #497 from oasisprotocol/andrew7234/bugfix-total-su…
Browse files Browse the repository at this point in the history
…pply-change

bugfix: initialize possibleToken fields
  • Loading branch information
Andrew7234 authored Aug 7, 2023
2 parents 803ca11 + 137d753 commit f3354c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion analyzer/runtime/evm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const NativeRuntimeTokenAddress = "oasis1runt1menat1vet0ken000000000000000000000

type EVMPossibleToken struct {
Mutated bool
TotalSupplyChange *big.Int
TotalSupplyChange big.Int
}

type EVMTokenData struct {
Expand Down
8 changes: 3 additions & 5 deletions analyzer/runtime/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,22 +751,20 @@ func extractEvents(blockData *BlockData, relatedAccountAddresses map[apiTypes.Ad
}
// TODO: Reckon ownership.
if _, ok := blockData.PossibleTokens[eventAddr]; !ok {
blockData.PossibleTokens[eventAddr] = &evm.EVMPossibleToken{
TotalSupplyChange: &big.Int{},
}
blockData.PossibleTokens[eventAddr] = &evm.EVMPossibleToken{}
}
// Mark as mutated if transfer is between zero address
// and nonzero address (either direction) and nonzero
// amount. These will change the total supply as mint/
// burn.
if fromZero && !toZero && tokenID.Cmp(&big.Int{}) != 0 {
pt := blockData.PossibleTokens[eventAddr]
pt.TotalSupplyChange.Add(pt.TotalSupplyChange, big.NewInt(1))
pt.TotalSupplyChange.Add(&pt.TotalSupplyChange, big.NewInt(1))
pt.Mutated = true
}
if !fromZero && toZero && tokenID.Cmp(&big.Int{}) != 0 {
pt := blockData.PossibleTokens[eventAddr]
pt.TotalSupplyChange.Sub(pt.TotalSupplyChange, big.NewInt(1))
pt.TotalSupplyChange.Sub(&pt.TotalSupplyChange, big.NewInt(1))
pt.Mutated = true
}
eventData.EvmLogName = evmabi.ERC721.Events["Transfer"].Name
Expand Down
13 changes: 5 additions & 8 deletions analyzer/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,24 +286,21 @@ func (m *processor) queueDbUpdates(batch *storage.QueryBatch, data *BlockData) {

// Insert EVM token addresses.
for addr, possibleToken := range data.PossibleTokens {
totalSupply := "0"
if possibleToken.TotalSupplyChange != nil {
totalSupply = possibleToken.TotalSupplyChange.String()
}
totalSupplyChange := possibleToken.TotalSupplyChange.String()
if possibleToken.Mutated {
batch.Queue(queries.RuntimeEVMTokenAnalysisMutateUpsert, m.runtime, addr, totalSupply, data.Header.Round)
batch.Queue(queries.RuntimeEVMTokenAnalysisMutateUpsert, m.runtime, addr, totalSupplyChange, data.Header.Round)
} else {
batch.Queue(queries.RuntimeEVMTokenAnalysisInsert, m.runtime, addr, totalSupply, data.Header.Round)
batch.Queue(queries.RuntimeEVMTokenAnalysisInsert, m.runtime, addr, totalSupplyChange, data.Header.Round)
}
// Dead reckon total_supply because it's optional for ERC721 contracts.
// If the evm_tokens analyzer is able to fetch the total supply from the node,
// it will supersede this.
if possibleToken.TotalSupplyChange != nil && possibleToken.TotalSupplyChange.Cmp(&big.Int{}) != 0 {
if possibleToken.TotalSupplyChange.Cmp(&big.Int{}) != 0 {
batch.Queue(
queries.RuntimeEVMTokenTotalSupplyChangeUpdate,
m.runtime,
addr,
possibleToken.TotalSupplyChange.String(),
totalSupplyChange,
)
}
}
Expand Down

0 comments on commit f3354c0

Please sign in to comment.