Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
serichoi65 committed Feb 12, 2025
1 parent 84426bb commit bfeb579
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
61 changes: 61 additions & 0 deletions pkg/contractManager/contractManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,64 @@ func (cm *ContractManager) GetContractWithProxy(

return contract, nil
}

func (cm *ContractManager) CreateProxyContract(
contractAddress string,
proxyContractAddress string,
blockNumber uint64,
reindexContract bool,
) (*contractStore.ProxyContract, error) {
proxyContract, found, err := cm.ContractStore.FindOrCreateProxyContract(blockNumber, contractAddress, proxyContractAddress)
if err != nil {
cm.Logger.Sugar().Errorw("Failed to create proxy contract",
zap.Error(err),
zap.String("contractAddress", contractAddress),
zap.String("proxyContractAddress", proxyContractAddress),
)
} else {
if found {
cm.Logger.Sugar().Debugw("Found existing proxy contract",
zap.String("contractAddress", contractAddress),
zap.String("proxyContractAddress", proxyContractAddress),
)
} else {
cm.Logger.Sugar().Debugw("Created proxy contract",
zap.String("contractAddress", contractAddress),
zap.String("proxyContractAddress", proxyContractAddress),
)
}
}
// Check to see if the contract we're proxying to is already in the database
proxiedContract, err := cm.ContractStore.GetContractForAddress(proxyContractAddress)
if err != nil {
cm.Logger.Sugar().Errorw("Failed to get contract for address",
zap.Error(err),
zap.String("contractAddress", proxyContractAddress),
)
}
if proxiedContract != nil {
cm.Logger.Sugar().Debugw("Found proxied contract",
zap.String("contractAddress", proxyContractAddress),
zap.String("proxiedContractAddress", proxiedContract.ContractAddress),
)
if proxiedContract.ContractAbi == "" {
updatedContract := cm.FindAndSetContractAbi(proxyContractAddress)
if updatedContract != nil {
proxiedContract = updatedContract
}
}
} else {
_, err := cm.CreateContract(proxyContractAddress, "", reindexContract)
if err != nil {
cm.Logger.Sugar().Errorw("Failed to create contract",
zap.Error(err),
zap.String("contractAddress", proxyContractAddress),
)
} else {
cm.Logger.Sugar().Debugw("Created contract",
zap.String("contractAddress", proxyContractAddress),
)
}
}
return proxyContract, nil
}
14 changes: 8 additions & 6 deletions pkg/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func (idx *Indexer) IndexContractUpgrade(ctx context.Context, blockNumber uint64

// Check the arguments for the new address. EIP-1967 contracts include this as an argument.
// Otherwise, we'll check the storage slot
// TODO: Arguments is a string
for _, arg := range upgradedLog.Arguments {
if arg.Name == "implementation" && arg.Value != "" && arg.Value != nil {
newProxiedAddress = arg.Value.(common.Address).String()
Expand All @@ -178,26 +177,29 @@ func (idx *Indexer) IndexContractUpgrade(ctx context.Context, blockNumber uint64
zap.Uint64("block", blockNumber),
zap.String("upgradedLogAddress", upgradedLog.Address)
)
} else if len(storageValue) != 66 {
return err
if len(storageValue) != 66 {
idx.Logger.Sugar().Errorw("Invalid storage value",
zap.Uint64("block", blockNumber),
zap.String("storageValue", storageValue)
)
} else {
newProxiedAddress = storageValue[26:]
return err
}

newProxiedAddress = storageValue[26:]
}

if newProxiedAddress == "" {
idx.Logger.Sugar().Debugw("No new proxied address found", zap.String("address", upgradedLog.Address))
return
return nil
}

_, err := idx.ContractManager.CreateProxyContract(upgradedLog.Address, newProxiedAddress, blockNumber, reindexContract)
if err != nil {
idx.Logger.Sugar().Errorw("Failed to create proxy contract", zap.Error(err))
return
return err
}

idx.Logger.Sugar().Infow("Upgraded proxy contract", zap.String("contractAddress", upgradedLog.Address), zap.String("proxyContractAddress", newProxiedAddress))
return nil
}
Expand Down

0 comments on commit bfeb579

Please sign in to comment.