2020-01-20 20:56:06 +00:00
|
|
|
package ext
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"database/sql"
|
2021-09-01 12:02:18 +00:00
|
|
|
"encoding/hex"
|
|
|
|
"errors"
|
2023-03-21 13:52:14 +00:00
|
|
|
"fmt"
|
2020-01-20 20:56:06 +00:00
|
|
|
"math/big"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2023-03-21 13:52:14 +00:00
|
|
|
"strings"
|
2020-01-20 20:56:06 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/syndtr/goleveldb/leveldb"
|
2022-06-15 14:49:31 +00:00
|
|
|
"go.uber.org/zap"
|
2020-01-20 20:56:06 +00:00
|
|
|
|
|
|
|
commongethtypes "github.com/ethereum/go-ethereum/common"
|
|
|
|
gethtypes "github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/ethereum/go-ethereum/ethclient"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2022-06-02 12:17:52 +00:00
|
|
|
gethrpc "github.com/ethereum/go-ethereum/rpc"
|
2020-01-20 20:56:06 +00:00
|
|
|
|
2023-03-10 12:53:40 +00:00
|
|
|
"github.com/status-im/status-go/account"
|
2023-03-21 13:52:14 +00:00
|
|
|
"github.com/status-im/status-go/api/multiformat"
|
2021-05-14 10:55:42 +00:00
|
|
|
"github.com/status-im/status-go/connection"
|
2020-01-20 20:56:06 +00:00
|
|
|
"github.com/status-im/status-go/db"
|
|
|
|
coretypes "github.com/status-im/status-go/eth-node/core/types"
|
2021-09-01 12:02:18 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
2020-01-20 20:56:06 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2023-09-21 12:40:58 +00:00
|
|
|
"github.com/status-im/status-go/images"
|
2020-11-25 11:39:01 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts"
|
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
|
|
|
"github.com/status-im/status-go/params"
|
2020-01-20 20:56:06 +00:00
|
|
|
"github.com/status-im/status-go/protocol"
|
2021-09-01 12:02:18 +00:00
|
|
|
"github.com/status-im/status-go/protocol/anonmetrics"
|
2023-03-21 13:52:14 +00:00
|
|
|
"github.com/status-im/status-go/protocol/common"
|
2023-09-21 12:40:58 +00:00
|
|
|
"github.com/status-im/status-go/protocol/communities"
|
|
|
|
"github.com/status-im/status-go/protocol/communities/token"
|
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2020-07-22 07:41:40 +00:00
|
|
|
"github.com/status-im/status-go/protocol/pushnotificationclient"
|
|
|
|
"github.com/status-im/status-go/protocol/pushnotificationserver"
|
2020-01-20 20:56:06 +00:00
|
|
|
"github.com/status-im/status-go/protocol/transport"
|
2022-06-15 14:49:31 +00:00
|
|
|
"github.com/status-im/status-go/rpc"
|
|
|
|
"github.com/status-im/status-go/server"
|
|
|
|
"github.com/status-im/status-go/services/browsers"
|
2023-08-25 15:36:39 +00:00
|
|
|
"github.com/status-im/status-go/services/communitytokens"
|
2020-11-25 11:39:01 +00:00
|
|
|
"github.com/status-im/status-go/services/ext/mailservers"
|
2021-01-26 11:49:37 +00:00
|
|
|
localnotifications "github.com/status-im/status-go/services/local-notifications"
|
2021-01-14 22:15:13 +00:00
|
|
|
mailserversDB "github.com/status-im/status-go/services/mailservers"
|
2023-04-25 12:00:17 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet"
|
2023-05-19 15:31:45 +00:00
|
|
|
w_common "github.com/status-im/status-go/services/wallet/common"
|
2023-03-21 13:52:14 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet/thirdparty"
|
2020-01-20 20:56:06 +00:00
|
|
|
)
|
|
|
|
|
2023-09-21 12:40:58 +00:00
|
|
|
const infinityString = "∞"
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
// EnvelopeEventsHandler used for two different event types.
|
|
|
|
type EnvelopeEventsHandler interface {
|
|
|
|
EnvelopeSent([][]byte)
|
|
|
|
EnvelopeExpired([][]byte, error)
|
|
|
|
MailServerRequestCompleted(types.Hash, types.Hash, []byte, error)
|
|
|
|
MailServerRequestExpired(types.Hash)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Service is a service that provides some additional API to whisper-based protocols like Whisper or Waku.
|
|
|
|
type Service struct {
|
2021-05-13 13:30:33 +00:00
|
|
|
messenger *protocol.Messenger
|
|
|
|
identity *ecdsa.PrivateKey
|
|
|
|
cancelMessenger chan struct{}
|
|
|
|
storage db.TransactionalStorage
|
|
|
|
n types.Node
|
2022-06-02 12:17:52 +00:00
|
|
|
rpcClient *rpc.Client
|
2022-01-12 16:02:01 +00:00
|
|
|
config params.NodeConfig
|
2021-05-13 13:30:33 +00:00
|
|
|
mailMonitor *MailRequestMonitor
|
|
|
|
server *p2p.Server
|
|
|
|
peerStore *mailservers.PeerStore
|
|
|
|
accountsDB *accounts.Database
|
|
|
|
multiAccountsDB *multiaccounts.Database
|
|
|
|
account *multiaccounts.Account
|
2020-01-20 20:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that Service implements node.Service interface.
|
2021-06-30 11:40:54 +00:00
|
|
|
var _ node.Lifecycle = (*Service)(nil)
|
2020-01-20 20:56:06 +00:00
|
|
|
|
|
|
|
func New(
|
2022-01-12 16:02:01 +00:00
|
|
|
config params.NodeConfig,
|
2020-01-20 20:56:06 +00:00
|
|
|
n types.Node,
|
2022-06-02 12:17:52 +00:00
|
|
|
rpcClient *rpc.Client,
|
2020-01-20 20:56:06 +00:00
|
|
|
ldb *leveldb.DB,
|
|
|
|
mailMonitor *MailRequestMonitor,
|
|
|
|
eventSub mailservers.EnvelopeEventSubscriber,
|
|
|
|
) *Service {
|
|
|
|
cache := mailservers.NewCache(ldb)
|
|
|
|
peerStore := mailservers.NewPeerStore(cache)
|
|
|
|
return &Service{
|
2021-05-13 13:30:33 +00:00
|
|
|
storage: db.NewLevelDBStorage(ldb),
|
|
|
|
n: n,
|
2022-06-02 12:17:52 +00:00
|
|
|
rpcClient: rpcClient,
|
2021-05-13 13:30:33 +00:00
|
|
|
config: config,
|
|
|
|
mailMonitor: mailMonitor,
|
|
|
|
peerStore: peerStore,
|
2020-01-20 20:56:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) NodeID() *ecdsa.PrivateKey {
|
|
|
|
if s.server == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return s.server.PrivateKey
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) GetPeer(rawURL string) (*enode.Node, error) {
|
|
|
|
if len(rawURL) == 0 {
|
|
|
|
return mailservers.GetFirstConnected(s.server, s.peerStore)
|
|
|
|
}
|
|
|
|
return enode.ParseV4(rawURL)
|
|
|
|
}
|
|
|
|
|
2023-08-25 15:36:39 +00:00
|
|
|
func (s *Service) InitProtocol(nodeName string, identity *ecdsa.PrivateKey, appDb, walletDb *sql.DB, httpServer *server.MediaServer, multiAccountDb *multiaccounts.Database, acc *multiaccounts.Account, accountManager *account.GethManager, rpcClient *rpc.Client, walletService *wallet.Service, communityTokensService *communitytokens.Service, logger *zap.Logger) error {
|
2022-03-23 18:47:00 +00:00
|
|
|
var err error
|
2022-01-12 16:02:01 +00:00
|
|
|
if !s.config.ShhextConfig.PFSEnabled {
|
2020-01-20 20:56:06 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// If Messenger has been already set up, we need to shut it down
|
|
|
|
// before we init it again. Otherwise, it will lead to goroutines leakage
|
|
|
|
// due to not stopped filters.
|
|
|
|
if s.messenger != nil {
|
|
|
|
if err := s.messenger.Shutdown(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s.identity = identity
|
|
|
|
|
2022-01-12 16:02:01 +00:00
|
|
|
dataDir := filepath.Clean(s.config.ShhextConfig.BackupDisabledDataDir)
|
2020-01-20 20:56:06 +00:00
|
|
|
|
|
|
|
if err := os.MkdirAll(dataDir, os.ModePerm); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
envelopesMonitorConfig := &transport.EnvelopesMonitorConfig{
|
2022-01-12 16:02:01 +00:00
|
|
|
MaxAttempts: s.config.ShhextConfig.MaxMessageDeliveryAttempts,
|
|
|
|
AwaitOnlyMailServerConfirmations: s.config.ShhextConfig.MailServerConfirmations,
|
2020-01-20 20:56:06 +00:00
|
|
|
IsMailserver: func(peer types.EnodeID) bool {
|
|
|
|
return s.peerStore.Exist(peer)
|
|
|
|
},
|
|
|
|
EnvelopeEventsHandler: EnvelopeSignalHandler{},
|
2020-02-18 11:21:01 +00:00
|
|
|
Logger: logger,
|
2020-01-20 20:56:06 +00:00
|
|
|
}
|
2023-08-11 11:25:14 +00:00
|
|
|
s.accountsDB, err = accounts.NewDB(appDb)
|
2022-03-23 18:47:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-24 13:13:46 +00:00
|
|
|
s.multiAccountsDB = multiAccountDb
|
2020-12-09 14:03:43 +00:00
|
|
|
s.account = acc
|
2020-07-15 12:25:01 +00:00
|
|
|
|
2023-08-25 15:36:39 +00:00
|
|
|
options, err := buildMessengerOptions(s.config, identity, appDb, walletDb, httpServer, s.rpcClient, s.multiAccountsDB, acc, envelopesMonitorConfig, s.accountsDB, walletService, communityTokensService, logger, &MessengerSignalsHandler{})
|
2020-07-15 12:25:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-01-20 20:56:06 +00:00
|
|
|
|
|
|
|
messenger, err := protocol.NewMessenger(
|
2021-11-03 12:38:37 +00:00
|
|
|
nodeName,
|
2020-01-20 20:56:06 +00:00
|
|
|
identity,
|
|
|
|
s.n,
|
2022-01-12 16:02:01 +00:00
|
|
|
s.config.ShhextConfig.InstallationID,
|
|
|
|
s.peerStore,
|
2023-03-10 12:53:40 +00:00
|
|
|
accountManager,
|
2020-01-20 20:56:06 +00:00
|
|
|
options...,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
s.messenger = messenger
|
2022-01-12 16:02:01 +00:00
|
|
|
s.messenger.SetP2PServer(s.server)
|
2023-07-20 10:08:57 +00:00
|
|
|
if s.config.ProcessBackedupMessages {
|
|
|
|
s.messenger.EnableBackedupMessagesProcessing()
|
|
|
|
}
|
2020-01-29 19:40:06 +00:00
|
|
|
return messenger.Init()
|
|
|
|
}
|
|
|
|
|
2021-01-14 22:15:13 +00:00
|
|
|
func (s *Service) StartMessenger() (*protocol.MessengerResponse, error) {
|
2022-07-17 13:37:14 +00:00
|
|
|
// Start a loop that retrieves all messages and propagates them to status-mobile.
|
2020-01-20 20:56:06 +00:00
|
|
|
s.cancelMessenger = make(chan struct{})
|
2021-01-14 22:15:13 +00:00
|
|
|
response, err := s.messenger.Start()
|
2020-07-31 09:46:38 +00:00
|
|
|
if err != nil {
|
2021-01-14 22:15:13 +00:00
|
|
|
return nil, err
|
2020-07-31 09:46:38 +00:00
|
|
|
}
|
2020-01-20 20:56:06 +00:00
|
|
|
go s.retrieveMessagesLoop(time.Second, s.cancelMessenger)
|
|
|
|
go s.verifyTransactionLoop(30*time.Second, s.cancelMessenger)
|
2021-09-29 14:52:45 +00:00
|
|
|
|
2022-01-12 16:02:01 +00:00
|
|
|
if s.config.ShhextConfig.BandwidthStatsEnabled {
|
2021-09-29 14:52:45 +00:00
|
|
|
go s.retrieveStats(5*time.Second, s.cancelMessenger)
|
|
|
|
}
|
|
|
|
|
2021-01-14 22:15:13 +00:00
|
|
|
return response, nil
|
2020-01-20 20:56:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
func publishMessengerResponse(response *protocol.MessengerResponse) {
|
|
|
|
if !response.IsEmpty() {
|
2021-03-31 16:23:45 +00:00
|
|
|
notifications := response.Notifications()
|
2021-01-11 10:32:51 +00:00
|
|
|
// Clear notifications as not used for now
|
2021-03-31 16:23:45 +00:00
|
|
|
response.ClearNotifications()
|
|
|
|
PublisherSignalHandler{}.NewMessages(response)
|
|
|
|
localnotifications.PushMessages(notifications)
|
2021-01-11 10:32:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
func (s *Service) retrieveMessagesLoop(tick time.Duration, cancel <-chan struct{}) {
|
|
|
|
ticker := time.NewTicker(tick)
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
2022-01-31 10:33:56 +00:00
|
|
|
// We might be shutting down here
|
|
|
|
if s.messenger == nil {
|
|
|
|
return
|
|
|
|
}
|
2020-01-20 20:56:06 +00:00
|
|
|
response, err := s.messenger.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
log.Error("failed to retrieve raw messages", "err", err)
|
|
|
|
continue
|
|
|
|
}
|
2021-01-11 10:32:51 +00:00
|
|
|
publishMessengerResponse(response)
|
2020-01-20 20:56:06 +00:00
|
|
|
case <-cancel:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-03 19:27:15 +00:00
|
|
|
func (s *Service) retrieveStats(tick time.Duration, cancel <-chan struct{}) {
|
|
|
|
ticker := time.NewTicker(tick)
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
|
|
|
response := s.messenger.GetStats()
|
|
|
|
PublisherSignalHandler{}.Stats(response)
|
|
|
|
case <-cancel:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
type verifyTransactionClient struct {
|
|
|
|
chainID *big.Int
|
|
|
|
url string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *verifyTransactionClient) TransactionByHash(ctx context.Context, hash types.Hash) (coretypes.Message, coretypes.TransactionStatus, error) {
|
2021-07-07 06:11:09 +00:00
|
|
|
signer := gethtypes.NewLondonSigner(c.chainID)
|
2020-01-20 20:56:06 +00:00
|
|
|
client, err := ethclient.Dial(c.url)
|
|
|
|
if err != nil {
|
|
|
|
return coretypes.Message{}, coretypes.TransactionStatusPending, err
|
|
|
|
}
|
|
|
|
|
|
|
|
transaction, pending, err := client.TransactionByHash(ctx, commongethtypes.BytesToHash(hash.Bytes()))
|
|
|
|
if err != nil {
|
|
|
|
return coretypes.Message{}, coretypes.TransactionStatusPending, err
|
|
|
|
}
|
|
|
|
|
2021-06-30 11:40:54 +00:00
|
|
|
message, err := transaction.AsMessage(signer, nil)
|
2020-01-20 20:56:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return coretypes.Message{}, coretypes.TransactionStatusPending, err
|
|
|
|
}
|
|
|
|
from := types.BytesToAddress(message.From().Bytes())
|
|
|
|
to := types.BytesToAddress(message.To().Bytes())
|
|
|
|
|
|
|
|
if pending {
|
|
|
|
return coretypes.NewMessage(
|
|
|
|
from,
|
|
|
|
&to,
|
|
|
|
message.Nonce(),
|
|
|
|
message.Value(),
|
|
|
|
message.Gas(),
|
|
|
|
message.GasPrice(),
|
|
|
|
message.Data(),
|
|
|
|
message.CheckNonce(),
|
|
|
|
), coretypes.TransactionStatusPending, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
receipt, err := client.TransactionReceipt(ctx, commongethtypes.BytesToHash(hash.Bytes()))
|
|
|
|
if err != nil {
|
|
|
|
return coretypes.Message{}, coretypes.TransactionStatusPending, err
|
|
|
|
}
|
|
|
|
|
|
|
|
coremessage := coretypes.NewMessage(
|
|
|
|
from,
|
|
|
|
&to,
|
|
|
|
message.Nonce(),
|
|
|
|
message.Value(),
|
|
|
|
message.Gas(),
|
|
|
|
message.GasPrice(),
|
|
|
|
message.Data(),
|
|
|
|
message.CheckNonce(),
|
|
|
|
)
|
|
|
|
|
|
|
|
// Token transfer, check the logs
|
|
|
|
if len(coremessage.Data()) != 0 {
|
2023-05-19 15:31:45 +00:00
|
|
|
if w_common.IsTokenTransfer(receipt.Logs) {
|
2020-01-20 20:56:06 +00:00
|
|
|
return coremessage, coretypes.TransactionStatus(receipt.Status), nil
|
|
|
|
}
|
|
|
|
return coremessage, coretypes.TransactionStatusFailed, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return coremessage, coretypes.TransactionStatus(receipt.Status), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) verifyTransactionLoop(tick time.Duration, cancel <-chan struct{}) {
|
2022-01-12 16:02:01 +00:00
|
|
|
if s.config.ShhextConfig.VerifyTransactionURL == "" {
|
2020-01-20 20:56:06 +00:00
|
|
|
log.Warn("not starting transaction loop")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ticker := time.NewTicker(tick)
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
ctx, cancelVerifyTransaction := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
2023-07-25 15:17:17 +00:00
|
|
|
accounts, err := s.accountsDB.GetActiveAccounts()
|
2020-01-20 20:56:06 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error("failed to retrieve accounts", "err", err)
|
|
|
|
}
|
|
|
|
var wallets []types.Address
|
|
|
|
for _, account := range accounts {
|
2020-12-07 14:03:18 +00:00
|
|
|
if account.IsOwnAccount() {
|
2020-01-20 20:56:06 +00:00
|
|
|
wallets = append(wallets, types.BytesToAddress(account.Address.Bytes()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
response, err := s.messenger.ValidateTransactions(ctx, wallets)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("failed to validate transactions", "err", err)
|
|
|
|
continue
|
|
|
|
}
|
2021-01-11 10:32:51 +00:00
|
|
|
publishMessengerResponse(response)
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
case <-cancel:
|
|
|
|
cancelVerifyTransaction()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) EnableInstallation(installationID string) error {
|
|
|
|
return s.messenger.EnableInstallation(installationID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DisableInstallation disables an installation for multi-device sync.
|
|
|
|
func (s *Service) DisableInstallation(installationID string) error {
|
|
|
|
return s.messenger.DisableInstallation(installationID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Protocols returns a new protocols list. In this case, there are none.
|
|
|
|
func (s *Service) Protocols() []p2p.Protocol {
|
|
|
|
return []p2p.Protocol{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// APIs returns a list of new APIs.
|
2022-06-02 12:17:52 +00:00
|
|
|
func (s *Service) APIs() []gethrpc.API {
|
2020-01-20 20:56:06 +00:00
|
|
|
panic("this is abstract service, use shhext or wakuext implementation")
|
|
|
|
}
|
|
|
|
|
2021-06-30 11:40:54 +00:00
|
|
|
func (s *Service) SetP2PServer(server *p2p.Server) {
|
|
|
|
s.server = server
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
// Start is run when a service is started.
|
|
|
|
// It does nothing in this case but is required by `node.Service` interface.
|
2021-06-30 11:40:54 +00:00
|
|
|
func (s *Service) Start() error {
|
2020-01-20 20:56:06 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop is run when a service is stopped.
|
|
|
|
func (s *Service) Stop() error {
|
|
|
|
log.Info("Stopping shhext service")
|
|
|
|
if s.cancelMessenger != nil {
|
|
|
|
select {
|
|
|
|
case <-s.cancelMessenger:
|
|
|
|
// channel already closed
|
|
|
|
default:
|
|
|
|
close(s.cancelMessenger)
|
|
|
|
s.cancelMessenger = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.messenger != nil {
|
|
|
|
if err := s.messenger.Shutdown(); err != nil {
|
2021-01-14 22:15:13 +00:00
|
|
|
log.Error("failed to stop messenger", "err", err)
|
2020-01-20 20:56:06 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-07-07 06:11:09 +00:00
|
|
|
s.messenger = nil
|
2020-01-20 20:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildMessengerOptions(
|
2022-01-12 16:02:01 +00:00
|
|
|
config params.NodeConfig,
|
2020-07-03 10:08:47 +00:00
|
|
|
identity *ecdsa.PrivateKey,
|
2023-08-11 11:25:14 +00:00
|
|
|
appDb *sql.DB,
|
|
|
|
walletDb *sql.DB,
|
2022-06-15 14:49:31 +00:00
|
|
|
httpServer *server.MediaServer,
|
2022-06-02 12:17:52 +00:00
|
|
|
rpcClient *rpc.Client,
|
2020-11-24 13:13:46 +00:00
|
|
|
multiAccounts *multiaccounts.Database,
|
2020-12-09 14:03:43 +00:00
|
|
|
account *multiaccounts.Account,
|
2020-01-20 20:56:06 +00:00
|
|
|
envelopesMonitorConfig *transport.EnvelopesMonitorConfig,
|
2020-07-15 12:25:01 +00:00
|
|
|
accountsDB *accounts.Database,
|
2023-04-25 12:00:17 +00:00
|
|
|
walletService *wallet.Service,
|
2023-08-25 15:36:39 +00:00
|
|
|
communityTokensService *communitytokens.Service,
|
2020-01-20 20:56:06 +00:00
|
|
|
logger *zap.Logger,
|
2021-04-19 12:09:46 +00:00
|
|
|
messengerSignalsHandler protocol.MessengerSignalsHandler,
|
2020-07-15 12:25:01 +00:00
|
|
|
) ([]protocol.Option, error) {
|
2020-01-20 20:56:06 +00:00
|
|
|
options := []protocol.Option{
|
|
|
|
protocol.WithCustomLogger(logger),
|
2020-07-29 06:59:16 +00:00
|
|
|
protocol.WithPushNotifications(),
|
2023-08-11 11:25:14 +00:00
|
|
|
protocol.WithDatabase(appDb),
|
|
|
|
protocol.WithWalletDatabase(walletDb),
|
2020-11-24 13:13:46 +00:00
|
|
|
protocol.WithMultiAccounts(multiAccounts),
|
2023-08-11 11:25:14 +00:00
|
|
|
protocol.WithMailserversDatabase(mailserversDB.NewDB(appDb)),
|
2020-12-09 14:03:43 +00:00
|
|
|
protocol.WithAccount(account),
|
2023-08-11 11:25:14 +00:00
|
|
|
protocol.WithBrowserDatabase(browsers.NewDB(appDb)),
|
2020-01-20 20:56:06 +00:00
|
|
|
protocol.WithEnvelopesMonitorConfig(envelopesMonitorConfig),
|
2021-04-19 12:09:46 +00:00
|
|
|
protocol.WithSignalsHandler(messengerSignalsHandler),
|
2022-01-12 16:02:01 +00:00
|
|
|
protocol.WithENSVerificationConfig(publishMessengerResponse, config.ShhextConfig.VerifyENSURL, config.ShhextConfig.VerifyENSContractAddress),
|
|
|
|
protocol.WithClusterConfig(config.ClusterConfig),
|
2022-03-08 13:17:26 +00:00
|
|
|
protocol.WithTorrentConfig(&config.TorrentConfig),
|
2022-05-09 13:07:57 +00:00
|
|
|
protocol.WithHTTPServer(httpServer),
|
2022-06-02 12:17:52 +00:00
|
|
|
protocol.WithRPCClient(rpcClient),
|
2022-08-24 12:06:48 +00:00
|
|
|
protocol.WithMessageCSV(config.OutputMessageCSVEnabled),
|
2023-03-27 09:35:03 +00:00
|
|
|
protocol.WithWalletConfig(&config.WalletConfig),
|
2023-04-25 12:00:17 +00:00
|
|
|
protocol.WithWalletService(walletService),
|
2023-08-25 15:36:39 +00:00
|
|
|
protocol.WithCommunityTokensService(communityTokensService),
|
2021-01-11 10:32:51 +00:00
|
|
|
}
|
2020-01-20 20:56:06 +00:00
|
|
|
|
2022-01-12 16:02:01 +00:00
|
|
|
if config.ShhextConfig.DataSyncEnabled {
|
2020-01-20 20:56:06 +00:00
|
|
|
options = append(options, protocol.WithDatasync())
|
|
|
|
}
|
2021-01-11 10:32:51 +00:00
|
|
|
|
2020-07-15 12:25:01 +00:00
|
|
|
settings, err := accountsDB.GetSettings()
|
2020-07-22 07:41:40 +00:00
|
|
|
if err != sql.ErrNoRows && err != nil {
|
2020-07-15 12:25:01 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2020-01-20 20:56:06 +00:00
|
|
|
|
2021-09-01 12:02:18 +00:00
|
|
|
// Generate anon metrics client config
|
|
|
|
if settings.AnonMetricsShouldSend {
|
2022-01-12 16:02:01 +00:00
|
|
|
keyBytes, err := hex.DecodeString(config.ShhextConfig.AnonMetricsSendID)
|
2021-09-01 12:02:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
key, err := crypto.UnmarshalPubkey(keyBytes)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
amcc := &anonmetrics.ClientConfig{
|
|
|
|
ShouldSend: true,
|
|
|
|
SendAddress: key,
|
|
|
|
}
|
|
|
|
options = append(options, protocol.WithAnonMetricsClientConfig(amcc))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate anon metrics server config
|
2022-01-12 16:02:01 +00:00
|
|
|
if config.ShhextConfig.AnonMetricsServerEnabled {
|
|
|
|
if len(config.ShhextConfig.AnonMetricsServerPostgresURI) == 0 {
|
2021-09-01 12:02:18 +00:00
|
|
|
return nil, errors.New("AnonMetricsServerPostgresURI must be set")
|
|
|
|
}
|
|
|
|
|
|
|
|
amsc := &anonmetrics.ServerConfig{
|
|
|
|
Enabled: true,
|
2022-01-12 16:02:01 +00:00
|
|
|
PostgresURI: config.ShhextConfig.AnonMetricsServerPostgresURI,
|
2021-09-01 12:02:18 +00:00
|
|
|
}
|
|
|
|
options = append(options, protocol.WithAnonMetricsServerConfig(amsc))
|
|
|
|
}
|
|
|
|
|
2021-11-03 12:38:37 +00:00
|
|
|
if settings.TelemetryServerURL != "" {
|
|
|
|
options = append(options, protocol.WithTelemetry(settings.TelemetryServerURL))
|
|
|
|
}
|
|
|
|
|
2020-07-17 11:41:49 +00:00
|
|
|
if settings.PushNotificationsServerEnabled {
|
2020-07-22 07:41:40 +00:00
|
|
|
config := &pushnotificationserver.Config{
|
2020-08-20 07:26:00 +00:00
|
|
|
Enabled: true,
|
|
|
|
Logger: logger,
|
2020-07-03 10:08:47 +00:00
|
|
|
}
|
|
|
|
options = append(options, protocol.WithPushNotificationServerConfig(config))
|
|
|
|
}
|
|
|
|
|
2022-04-25 11:27:40 +00:00
|
|
|
var pushNotifServKey []*ecdsa.PublicKey
|
|
|
|
for _, d := range config.ShhextConfig.DefaultPushNotificationsServers {
|
|
|
|
pushNotifServKey = append(pushNotifServKey, d.PublicKey)
|
|
|
|
}
|
|
|
|
|
2020-07-22 07:41:40 +00:00
|
|
|
options = append(options, protocol.WithPushNotificationClientConfig(&pushnotificationclient.Config{
|
2022-04-25 11:27:40 +00:00
|
|
|
DefaultServers: pushNotifServKey,
|
2020-09-03 07:30:03 +00:00
|
|
|
BlockMentions: settings.PushNotificationsBlockMentions,
|
2020-07-15 12:25:01 +00:00
|
|
|
SendEnabled: settings.SendPushNotifications,
|
2020-07-22 07:41:40 +00:00
|
|
|
AllowFromContactsOnly: settings.PushNotificationsFromContactsOnly,
|
2020-07-15 12:25:01 +00:00
|
|
|
RemoteNotificationsEnabled: settings.RemotePushNotificationsEnabled,
|
|
|
|
}))
|
|
|
|
|
2022-01-12 16:02:01 +00:00
|
|
|
if config.ShhextConfig.VerifyTransactionURL != "" {
|
2020-01-20 20:56:06 +00:00
|
|
|
client := &verifyTransactionClient{
|
2022-01-12 16:02:01 +00:00
|
|
|
url: config.ShhextConfig.VerifyTransactionURL,
|
|
|
|
chainID: big.NewInt(config.ShhextConfig.VerifyTransactionChainID),
|
2020-01-20 20:56:06 +00:00
|
|
|
}
|
|
|
|
options = append(options, protocol.WithVerifyTransactionClient(client))
|
|
|
|
}
|
|
|
|
|
2020-07-15 12:25:01 +00:00
|
|
|
return options, nil
|
2020-01-20 20:56:06 +00:00
|
|
|
}
|
2021-05-14 10:55:42 +00:00
|
|
|
|
|
|
|
func (s *Service) ConnectionChanged(state connection.State) {
|
|
|
|
if s.messenger != nil {
|
|
|
|
s.messenger.ConnectionChanged(state)
|
|
|
|
}
|
|
|
|
}
|
2021-08-05 13:27:47 +00:00
|
|
|
|
|
|
|
func (s *Service) Messenger() *protocol.Messenger {
|
|
|
|
return s.messenger
|
|
|
|
}
|
2023-03-21 13:52:14 +00:00
|
|
|
|
|
|
|
func tokenURIToCommunityID(tokenURI string) string {
|
|
|
|
tmpStr := strings.Split(tokenURI, "/")
|
|
|
|
|
|
|
|
// Community NFTs have a tokenURI of the form "compressedCommunityID/tokenID"
|
|
|
|
if len(tmpStr) != 2 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
compressedCommunityID := tmpStr[0]
|
|
|
|
|
|
|
|
hexCommunityID, err := multiformat.DeserializeCompressedKey(compressedCommunityID)
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
pubKey, err := common.HexToPubkey(hexCommunityID)
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
communityID := types.EncodeHex(crypto.CompressPubkey(pubKey))
|
|
|
|
|
|
|
|
return communityID
|
|
|
|
}
|
|
|
|
|
2023-10-26 06:30:18 +00:00
|
|
|
func (s *Service) GetCommunityID(tokenURI string) string {
|
|
|
|
if tokenURI != "" {
|
|
|
|
return tokenURIToCommunityID(tokenURI)
|
|
|
|
}
|
|
|
|
return ""
|
2023-03-21 13:52:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-26 06:30:18 +00:00
|
|
|
func (s *Service) FillCollectibleMetadata(collectible *thirdparty.FullCollectibleData) error {
|
2023-10-12 19:21:49 +00:00
|
|
|
if s.messenger == nil {
|
2023-10-26 06:30:18 +00:00
|
|
|
return fmt.Errorf("messenger not ready")
|
|
|
|
}
|
|
|
|
|
|
|
|
if collectible == nil {
|
|
|
|
return fmt.Errorf("empty collectible")
|
2023-10-12 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2023-10-26 06:30:18 +00:00
|
|
|
id := collectible.CollectibleData.ID
|
|
|
|
communityID := collectible.CollectibleData.CommunityID
|
2023-03-21 13:52:14 +00:00
|
|
|
|
|
|
|
if communityID == "" {
|
2023-10-26 06:30:18 +00:00
|
|
|
return fmt.Errorf("invalid communityID")
|
2023-03-21 13:52:14 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 12:40:58 +00:00
|
|
|
community, err := s.fetchCommunity(communityID)
|
|
|
|
|
|
|
|
if err != nil {
|
2023-10-26 06:30:18 +00:00
|
|
|
return err
|
2023-09-21 12:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if community == nil {
|
2023-10-26 06:30:18 +00:00
|
|
|
return nil
|
2023-09-21 12:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tokenMetadata, err := s.fetchCommunityCollectibleMetadata(community, id.ContractID)
|
|
|
|
|
|
|
|
if err != nil {
|
2023-10-26 06:30:18 +00:00
|
|
|
return err
|
2023-09-21 12:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if tokenMetadata == nil {
|
2023-10-26 06:30:18 +00:00
|
|
|
return nil
|
2023-09-21 12:40:58 +00:00
|
|
|
}
|
|
|
|
|
2023-10-26 06:30:18 +00:00
|
|
|
communityToken, err := s.fetchCommunityToken(communityID, id.ContractID)
|
2023-09-21 12:40:58 +00:00
|
|
|
if err != nil {
|
2023-10-26 06:30:18 +00:00
|
|
|
return err
|
2023-09-21 12:40:58 +00:00
|
|
|
}
|
|
|
|
|
2023-10-26 06:30:18 +00:00
|
|
|
permission := fetchCommunityCollectiblePermission(community, id)
|
|
|
|
|
|
|
|
privilegesLevel := token.CommunityLevel
|
|
|
|
if permission != nil {
|
|
|
|
privilegesLevel = permissionTypeToPrivilegesLevel(permission.GetType())
|
|
|
|
}
|
|
|
|
|
|
|
|
collectible.CollectibleData.Name = tokenMetadata.GetName()
|
|
|
|
collectible.CollectibleData.Description = tokenMetadata.GetDescription()
|
|
|
|
collectible.CollectibleData.ImageURL = tokenMetadata.GetImage()
|
|
|
|
collectible.CollectibleData.Traits = getCollectibleCommunityTraits(communityToken)
|
|
|
|
|
|
|
|
if collectible.CollectionData == nil {
|
|
|
|
collectible.CollectionData = &thirdparty.CollectionData{
|
2023-09-21 12:40:58 +00:00
|
|
|
ID: id.ContractID,
|
|
|
|
CommunityID: communityID,
|
2023-10-26 06:30:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
collectible.CollectionData.Name = tokenMetadata.GetName()
|
|
|
|
collectible.CollectionData.ImageURL = tokenMetadata.GetImage()
|
|
|
|
|
|
|
|
collectible.CommunityInfo = &thirdparty.CollectibleCommunityInfo{
|
|
|
|
PrivilegesLevel: privilegesLevel,
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2023-09-21 12:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func permissionTypeToPrivilegesLevel(permissionType protobuf.CommunityTokenPermission_Type) token.PrivilegesLevel {
|
|
|
|
switch permissionType {
|
|
|
|
case protobuf.CommunityTokenPermission_BECOME_TOKEN_OWNER:
|
|
|
|
return token.OwnerLevel
|
|
|
|
case protobuf.CommunityTokenPermission_BECOME_TOKEN_MASTER:
|
|
|
|
return token.MasterLevel
|
|
|
|
default:
|
|
|
|
return token.CommunityLevel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-26 06:30:18 +00:00
|
|
|
func (s *Service) FetchCommunityInfo(communityID string) (*thirdparty.CommunityInfo, error) {
|
2023-09-21 12:40:58 +00:00
|
|
|
community, err := s.fetchCommunity(communityID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if community == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2023-10-26 06:30:18 +00:00
|
|
|
communityInfo := &thirdparty.CommunityInfo{
|
|
|
|
CommunityName: community.Name(),
|
|
|
|
CommunityColor: community.Color(),
|
|
|
|
CommunityImage: fetchCommunityImage(community),
|
2023-09-21 12:40:58 +00:00
|
|
|
}
|
|
|
|
|
2023-10-26 06:30:18 +00:00
|
|
|
return communityInfo, nil
|
2023-09-21 12:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) fetchCommunity(communityID string) (*communities.Community, error) {
|
|
|
|
if s.messenger == nil {
|
|
|
|
return nil, fmt.Errorf("messenger not ready")
|
|
|
|
}
|
|
|
|
|
2023-03-21 13:52:14 +00:00
|
|
|
// Try to fetch metadata from Messenger communities
|
2023-10-12 19:21:49 +00:00
|
|
|
|
|
|
|
// TODO: we need the shard information in the collectible to be able to retrieve info for
|
|
|
|
// communities that have specific shards
|
|
|
|
|
|
|
|
var shard *common.Shard = nil // TODO: build this with info from token
|
2023-11-03 10:30:24 +00:00
|
|
|
community, err := s.messenger.FetchCommunity(&protocol.FetchCommunityRequest{
|
|
|
|
CommunityKey: communityID,
|
|
|
|
Shard: shard,
|
|
|
|
TryDatabase: true,
|
|
|
|
WaitForResponse: true,
|
|
|
|
})
|
2023-03-21 13:52:14 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-09-21 12:40:58 +00:00
|
|
|
return community, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) fetchCommunityToken(communityID string, contractID thirdparty.ContractID) (*token.CommunityToken, error) {
|
|
|
|
if s.messenger == nil {
|
|
|
|
return nil, fmt.Errorf("messenger not ready")
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.messenger.GetCommunityToken(communityID, int(contractID.ChainID), contractID.Address.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) fetchCommunityCollectibleMetadata(community *communities.Community, contractID thirdparty.ContractID) (*protobuf.CommunityTokenMetadata, error) {
|
|
|
|
tokensMetadata := community.CommunityTokensMetadata()
|
|
|
|
|
|
|
|
for _, tokenMetadata := range tokensMetadata {
|
|
|
|
contractAddresses := tokenMetadata.GetContractAddresses()
|
|
|
|
if contractAddresses[uint64(contractID.ChainID)] == contractID.Address.Hex() {
|
|
|
|
return tokenMetadata, nil
|
2023-03-21 13:52:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
2023-09-21 12:40:58 +00:00
|
|
|
|
|
|
|
func tokenCriterionContainsCollectible(tokenCriterion *protobuf.TokenCriteria, id thirdparty.CollectibleUniqueID) bool {
|
|
|
|
// Check if token type matches
|
|
|
|
if tokenCriterion.Type != protobuf.CommunityTokenType_ERC721 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for chainID, contractAddressStr := range tokenCriterion.ContractAddresses {
|
|
|
|
if chainID != uint64(id.ContractID.ChainID) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
contractAddress := commongethtypes.HexToAddress(contractAddressStr)
|
|
|
|
if contractAddress != id.ContractID.Address {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tokenCriterion.TokenIds) == 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tokenID := range tokenCriterion.TokenIds {
|
|
|
|
tokenIDBigInt := new(big.Int).SetUint64(tokenID)
|
|
|
|
if id.TokenID.Cmp(tokenIDBigInt) == 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func permissionContainsCollectible(permission *communities.CommunityTokenPermission, id thirdparty.CollectibleUniqueID) bool {
|
|
|
|
// See if any token criterion contains the collectible we're looking for
|
|
|
|
for _, tokenCriterion := range permission.TokenCriteria {
|
|
|
|
if tokenCriterionContainsCollectible(tokenCriterion, id) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchCommunityCollectiblePermission(community *communities.Community, id thirdparty.CollectibleUniqueID) *communities.CommunityTokenPermission {
|
|
|
|
// Permnission types of interest
|
|
|
|
permissionTypes := []protobuf.CommunityTokenPermission_Type{
|
|
|
|
protobuf.CommunityTokenPermission_BECOME_TOKEN_OWNER,
|
|
|
|
protobuf.CommunityTokenPermission_BECOME_TOKEN_MASTER,
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, permissionType := range permissionTypes {
|
|
|
|
permissions := community.TokenPermissionsByType(permissionType)
|
|
|
|
// See if any community permission matches the type we're looking for
|
|
|
|
for _, permission := range permissions {
|
|
|
|
if permissionContainsCollectible(permission, id) {
|
|
|
|
return permission
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchCommunityImage(community *communities.Community) string {
|
|
|
|
imageTypes := []string{
|
|
|
|
images.LargeDimName,
|
|
|
|
images.SmallDimName,
|
|
|
|
}
|
|
|
|
|
|
|
|
communityImages := community.Images()
|
|
|
|
|
|
|
|
for _, imageType := range imageTypes {
|
|
|
|
if pbImage, ok := communityImages[imageType]; ok {
|
|
|
|
imageBase64, err := images.GetPayloadDataURI(pbImage.Payload)
|
|
|
|
if err == nil {
|
|
|
|
return imageBase64
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func boolToString(value bool) string {
|
|
|
|
if value {
|
|
|
|
return "Yes"
|
|
|
|
}
|
|
|
|
return "No"
|
|
|
|
}
|
|
|
|
|
|
|
|
func getCollectibleCommunityTraits(token *token.CommunityToken) []thirdparty.CollectibleTrait {
|
|
|
|
if token == nil {
|
|
|
|
return make([]thirdparty.CollectibleTrait, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
totalStr := infinityString
|
|
|
|
availableStr := infinityString
|
|
|
|
if !token.InfiniteSupply {
|
|
|
|
totalStr = token.Supply.String()
|
|
|
|
// TODO: calculate available supply. See services/communitytokens/api.go
|
|
|
|
availableStr = totalStr
|
|
|
|
}
|
|
|
|
|
|
|
|
transferableStr := boolToString(token.Transferable)
|
|
|
|
|
|
|
|
destructibleStr := boolToString(token.RemoteSelfDestruct)
|
|
|
|
|
|
|
|
return []thirdparty.CollectibleTrait{
|
|
|
|
{
|
|
|
|
TraitType: "Symbol",
|
|
|
|
Value: token.Symbol,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TraitType: "Total",
|
|
|
|
Value: totalStr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TraitType: "Available",
|
|
|
|
Value: availableStr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TraitType: "Transferable",
|
|
|
|
Value: transferableStr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
TraitType: "Destructible",
|
|
|
|
Value: destructibleStr,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|