fix: notify collectible data update when transferID is set
This commit is contained in:
parent
7f6f8b3f7c
commit
12d70e0ce4
|
@ -806,6 +806,18 @@ func (o *Manager) getCacheFullCollectibleData(uniqueIDs []thirdparty.Collectible
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
func (o *Manager) SetCollectibleTransferID(ownerAddress common.Address, id thirdparty.CollectibleUniqueID, transferID common.Hash, notify bool) error {
|
||||
changed, err := o.ownershipDB.SetTransferID(ownerAddress, id, transferID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if changed && notify {
|
||||
o.signalUpdatedCollectiblesData([]thirdparty.CollectibleUniqueID{id})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset connection status to trigger notifications
|
||||
// on the next status update
|
||||
func (o *Manager) ResetConnectionStatus() {
|
||||
|
|
|
@ -512,23 +512,32 @@ func (o *OwnershipDB) GetOwnership(id thirdparty.CollectibleUniqueID) ([]thirdpa
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
func (o *OwnershipDB) SetTransferID(ownerAddress common.Address, id thirdparty.CollectibleUniqueID, transferID common.Hash) error {
|
||||
func (o *OwnershipDB) SetTransferID(ownerAddress common.Address, id thirdparty.CollectibleUniqueID, transferID common.Hash) (bool, error) {
|
||||
query := `UPDATE collectibles_ownership_cache
|
||||
SET transfer_id = ?
|
||||
WHERE chain_id = ? AND contract_address = ? AND token_id = ? AND owner_address = ?`
|
||||
|
||||
stmt, err := o.db.Prepare(query)
|
||||
if err != nil {
|
||||
return err
|
||||
return false, err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
_, err = stmt.Exec(transferID, id.ContractID.ChainID, id.ContractID.Address, (*bigint.SQLBigIntBytes)(id.TokenID.Int), ownerAddress)
|
||||
res, err := stmt.Exec(transferID, id.ContractID.ChainID, id.ContractID.Address, (*bigint.SQLBigIntBytes)(id.TokenID.Int), ownerAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
return false, err
|
||||
}
|
||||
|
||||
return nil
|
||||
rowsAffected, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if rowsAffected > 0 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (o *OwnershipDB) GetTransferID(ownerAddress common.Address, id thirdparty.CollectibleUniqueID) (*common.Hash, error) {
|
||||
|
|
|
@ -426,6 +426,7 @@ func TestCollectibleTransferID(t *testing.T) {
|
|||
timestampChain0 := int64(1234567890)
|
||||
|
||||
var err error
|
||||
var changed bool
|
||||
|
||||
_, _, _, err = oDB.Update(chainID0, ownerAddress1, ownedBalancesChain0, timestampChain0)
|
||||
require.NoError(t, err)
|
||||
|
@ -440,10 +441,24 @@ func TestCollectibleTransferID(t *testing.T) {
|
|||
require.Nil(t, loadedTransferID)
|
||||
}
|
||||
|
||||
randomAddress := common.HexToAddress("0xFFFF")
|
||||
randomCollectibleID := thirdparty.CollectibleUniqueID{
|
||||
ContractID: thirdparty.ContractID{
|
||||
ChainID: 0xABCDEF,
|
||||
Address: common.BigToAddress(big.NewInt(int64(123456789))),
|
||||
},
|
||||
TokenID: &bigint.BigInt{Int: big.NewInt(int64(987654321))},
|
||||
}
|
||||
randomTxID := common.HexToHash("0xEEEE")
|
||||
changed, err = oDB.SetTransferID(randomAddress, randomCollectibleID, randomTxID)
|
||||
require.NoError(t, err)
|
||||
require.False(t, changed)
|
||||
|
||||
firstCollectibleID := ownedListChain0[0]
|
||||
firstTxID := common.HexToHash("0x1234")
|
||||
err = oDB.SetTransferID(ownerAddress1, firstCollectibleID, firstTxID)
|
||||
changed, err = oDB.SetTransferID(ownerAddress1, firstCollectibleID, firstTxID)
|
||||
require.NoError(t, err)
|
||||
require.True(t, changed)
|
||||
|
||||
for _, id := range ownedListChain0 {
|
||||
loadedTransferID, err := oDB.GetTransferID(ownerAddress1, id)
|
||||
|
|
|
@ -430,7 +430,7 @@ func (s *Service) onCollectiblesTransfer(account common.Address, chainID walletC
|
|||
},
|
||||
TokenID: &bigint.BigInt{Int: transfer.TokenID},
|
||||
}
|
||||
err := s.ownershipDB.SetTransferID(account, id, transfer.ID)
|
||||
err := s.manager.SetCollectibleTransferID(account, id, transfer.ID, true)
|
||||
if err != nil {
|
||||
log.Error("Error setting transfer ID for collectible", "error", err)
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ func (s *Service) lookupTransferForCollectibles(ownedCollectibles OwnedCollectib
|
|||
continue
|
||||
}
|
||||
if transfer != nil {
|
||||
err = s.ownershipDB.SetTransferID(ownedCollectibles.account, id, transfer.ID)
|
||||
err = s.manager.SetCollectibleTransferID(ownedCollectibles.account, id, transfer.ID, false)
|
||||
if err != nil {
|
||||
log.Error("Error setting transfer ID for collectible", "error", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue