Michal Iskierko c4cd5775db feat(MasterToken): Add MasterToken.go
Small refactoring in Collectibles service in order to make API code more simple.
Add TokenInstance interface with some common functions.
Implementations of TokenInstance for TokenMaster, Collectibles and Assets contracts.

Issue #11276
2023-08-16 11:31:12 +02:00

48 lines
1.3 KiB
Go

package collectibles
import (
"database/sql"
"fmt"
"github.com/status-im/status-go/protocol/communities/token"
"github.com/status-im/status-go/protocol/protobuf"
)
type Database struct {
db *sql.DB
}
func NewCommunityTokensDatabase(db *sql.DB) *Database {
return &Database{db: db}
}
func (db *Database) GetTokenType(chainID uint64, contractAddress string) (protobuf.CommunityTokenType, error) {
var result = protobuf.CommunityTokenType_UNKNOWN_TOKEN_TYPE
rows, err := db.db.Query(`SELECT type FROM community_tokens WHERE chain_id=? AND address=? LIMIT 1`, chainID, contractAddress)
if err != nil {
return result, err
}
defer rows.Close()
if rows.Next() {
err := rows.Scan(&result)
return result, err
}
return result, fmt.Errorf("can't find token: chainId %v, contractAddress %v", chainID, contractAddress)
}
func (db *Database) GetTokenPrivilegesLevel(chainID uint64, contractAddress string) (token.PrivilegesLevel, error) {
var result = token.CommunityLevel
rows, err := db.db.Query(`SELECT privileges_level FROM community_tokens WHERE chain_id=? AND address=? LIMIT 1`, chainID, contractAddress)
if err != nil {
return result, err
}
defer rows.Close()
if rows.Next() {
err := rows.Scan(&result)
return result, err
}
return result, fmt.Errorf("can't find privileges level: chainId %v, contractAddress %v", chainID, contractAddress)
}