-
Notifications
You must be signed in to change notification settings - Fork 5
/
helper.go
45 lines (36 loc) · 1.45 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package tokencollections
import (
"context"
"math/big"
"github.com/benleb/gloomberg/internal/collections"
"github.com/benleb/gloomberg/internal/gbl"
"github.com/benleb/gloomberg/internal/nemo/collectionsource"
"github.com/benleb/gloomberg/internal/nemo/gloomberg"
"github.com/ethereum/go-ethereum/common"
)
func GetCollection(gb *gloomberg.Gloomberg, contractAddress common.Address, tokenID int64) *collections.Collection {
// collection information
gb.CollectionDB.RWMu.RLock()
collection := gb.CollectionDB.Collections[contractAddress]
gb.CollectionDB.RWMu.RUnlock()
if collection == nil {
name := ""
// if tokenName, err := gb.Nodes.GetERC1155TokenName(contractAddress, big.NewInt(tokenID)); err == nil && tokenName != "" {
if tokenName, err := gb.ProviderPool.ERC1155TokenName(context.Background(), contractAddress, big.NewInt(tokenID)); err == nil && tokenName != "" {
name = tokenName
gbl.Log.Debugf("found token name: %s | %s", name, contractAddress.String())
} else if err != nil {
gbl.Log.Debugf("failed to get collection name: %s", err)
}
collection = collections.NewCollection(contractAddress, name, gb.ProviderPool, collectionsource.FromStream)
if collection != nil {
gb.CollectionDB.RWMu.Lock()
gb.CollectionDB.Collections[contractAddress] = collection
gb.CollectionDB.RWMu.Unlock()
} else {
gbl.Log.Warnf("❗️ collection not found: %s", contractAddress.String())
return nil
}
}
return collection
}