chore: Pass tx ID instead of hash (#4769)

This commit is contained in:
Cuteivist 2024-02-22 23:40:36 +01:00 committed by GitHub
parent 34c693bdea
commit 83678042f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 8 deletions

View File

@ -61,6 +61,11 @@ const (
FetchTypeFetchIfCacheOld FetchTypeFetchIfCacheOld
) )
type TxHashData struct {
Hash common.Hash
TxID common.Hash
}
type FetchCriteria struct { type FetchCriteria struct {
FetchType FetchType `json:"fetch_type"` FetchType FetchType `json:"fetch_type"`
MaxCacheAgeSeconds int64 `json:"max_cache_age_seconds"` MaxCacheAgeSeconds int64 `json:"max_cache_age_seconds"`
@ -437,7 +442,7 @@ func (s *Service) onCollectiblesTransfer(account common.Address, chainID walletC
} }
} }
func (s *Service) lookupTransferForCollectibles(ownedCollectibles OwnedCollectibles) map[thirdparty.CollectibleUniqueID]common.Hash { func (s *Service) lookupTransferForCollectibles(ownedCollectibles OwnedCollectibles) map[thirdparty.CollectibleUniqueID]TxHashData {
// There are some limitations to this approach: // There are some limitations to this approach:
// - Collectibles ownership and transfers are not in sync and might represent the state at different moments. // - Collectibles ownership and transfers are not in sync and might represent the state at different moments.
// - We have no way of knowing if the latest collectible transfer we've detected is actually the latest one, so the timestamp we // - We have no way of knowing if the latest collectible transfer we've detected is actually the latest one, so the timestamp we
@ -446,7 +451,7 @@ func (s *Service) lookupTransferForCollectibles(ownedCollectibles OwnedCollectib
// - For ERC721 tokens we should only look for incoming transfers. For ERC1155 tokens we should look for both incoming and outgoing transfers. // - For ERC721 tokens we should only look for incoming transfers. For ERC1155 tokens we should look for both incoming and outgoing transfers.
// We need to get the contract standard for each collectible to know which approach to take. // We need to get the contract standard for each collectible to know which approach to take.
result := make(map[thirdparty.CollectibleUniqueID]common.Hash) result := make(map[thirdparty.CollectibleUniqueID]TxHashData)
for _, id := range ownedCollectibles.ids { for _, id := range ownedCollectibles.ids {
transfer, err := s.transferDB.GetLatestCollectibleTransfer(ownedCollectibles.account, id) transfer, err := s.transferDB.GetLatestCollectibleTransfer(ownedCollectibles.account, id)
@ -455,7 +460,10 @@ func (s *Service) lookupTransferForCollectibles(ownedCollectibles OwnedCollectib
continue continue
} }
if transfer != nil { if transfer != nil {
result[id] = transfer.Transaction.Hash() result[id] = TxHashData{
Hash: transfer.Transaction.Hash(),
TxID: transfer.ID,
}
err = s.manager.SetCollectibleTransferID(ownedCollectibles.account, id, transfer.ID, false) err = s.manager.SetCollectibleTransferID(ownedCollectibles.account, id, transfer.ID, false)
if err != nil { if err != nil {
log.Error("Error setting transfer ID for collectible", "error", err) log.Error("Error setting transfer ID for collectible", "error", err)
@ -465,7 +473,7 @@ func (s *Service) lookupTransferForCollectibles(ownedCollectibles OwnedCollectib
return result return result
} }
func (s *Service) notifyCommunityCollectiblesReceived(ownedCollectibles OwnedCollectibles, hashMap map[thirdparty.CollectibleUniqueID]common.Hash) { func (s *Service) notifyCommunityCollectiblesReceived(ownedCollectibles OwnedCollectibles, hashMap map[thirdparty.CollectibleUniqueID]TxHashData) {
ctx := context.Background() ctx := context.Background()
firstCollectibles, err := s.ownershipDB.GetIsFirstOfCollection(ownedCollectibles.account, ownedCollectibles.ids) firstCollectibles, err := s.ownershipDB.GetIsFirstOfCollection(ownedCollectibles.account, ownedCollectibles.ids)
@ -491,24 +499,26 @@ func (s *Service) notifyCommunityCollectiblesReceived(ownedCollectibles OwnedCol
} }
groups := make(map[CollectibleGroup]Collectible) groups := make(map[CollectibleGroup]Collectible)
for i, collectible := range communityCollectibles { for _, collectible := range communityCollectibles {
txHash := ""
for key, value := range hashMap { for key, value := range hashMap {
if key.Same(&collectible.ID) { if key.Same(&collectible.ID) {
communityCollectibles[i].LatestTxHash = value.Hex() collectible.LatestTxHash = value.TxID.Hex()
txHash = value.Hash.Hex()
break break
} }
} }
for id, value := range firstCollectibles { for id, value := range firstCollectibles {
if value && id.Same(&collectible.ID) { if value && id.Same(&collectible.ID) {
communityCollectibles[i].IsFirst = true collectible.IsFirst = true
break break
} }
} }
group := CollectibleGroup{ group := CollectibleGroup{
contractID: collectible.ID.ContractID, contractID: collectible.ID.ContractID,
txHash: collectible.LatestTxHash, txHash: txHash,
} }
_, ok := groups[group] _, ok := groups[group]
if !ok { if !ok {