fix: ensure atomic collectibles ownership updates
This commit is contained in:
parent
71377a50d7
commit
55e8fd4554
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ const InvalidTimestamp = int64(-1)
|
||||||
|
|
||||||
type OwnershipDB struct {
|
type OwnershipDB struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOwnershipDB(sqlDb *sql.DB) *OwnershipDB {
|
func NewOwnershipDB(sqlDb *sql.DB) *OwnershipDB {
|
||||||
|
@ -358,6 +360,10 @@ func (o *OwnershipDB) GetIsFirstOfCollection(onwerAddress common.Address, newIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OwnershipDB) Update(chainID w_common.ChainID, ownerAddress common.Address, balances thirdparty.TokenBalancesPerContractAddress, timestamp int64) (removedIDs, updatedIDs, insertedIDs []thirdparty.CollectibleUniqueID, err error) {
|
func (o *OwnershipDB) Update(chainID w_common.ChainID, ownerAddress common.Address, balances thirdparty.TokenBalancesPerContractAddress, timestamp int64) (removedIDs, updatedIDs, insertedIDs []thirdparty.CollectibleUniqueID, err error) {
|
||||||
|
// Ensure all steps are done atomically
|
||||||
|
o.mu.Lock()
|
||||||
|
defer o.mu.Unlock()
|
||||||
|
|
||||||
err = insertTmpOwnership(o.db, chainID, ownerAddress, balances)
|
err = insertTmpOwnership(o.db, chainID, ownerAddress, balances)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue