fix(Collectibles): Trigger transaction event when creating transaction

Issue #11565
This commit is contained in:
Michal Iskierko 2023-07-18 15:32:31 +02:00 committed by Michał Iskierko
parent 71ca35bf34
commit 7d9092e295
4 changed files with 59 additions and 14 deletions

View File

@ -419,7 +419,7 @@ func (b *StatusNode) ensService(timesource func() time.Time) *ens.Service {
func (b *StatusNode) collectiblesService() *collectibles.Service { func (b *StatusNode) collectiblesService() *collectibles.Service {
if b.collectiblesSrvc == nil { if b.collectiblesSrvc == nil {
b.collectiblesSrvc = collectibles.NewService(b.rpcClient, b.gethAccountManager, b.config, b.appDB) b.collectiblesSrvc = collectibles.NewService(b.rpcClient, b.gethAccountManager, b.rpcFiltersSrvc, b.config, b.appDB)
} }
return b.collectiblesSrvc return b.collectiblesSrvc
} }

View File

@ -20,15 +20,17 @@ import (
"github.com/status-im/status-go/params" "github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/protobuf" "github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/rpc" "github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/rpcfilters"
"github.com/status-im/status-go/services/utils" "github.com/status-im/status-go/services/utils"
"github.com/status-im/status-go/services/wallet/bigint" "github.com/status-im/status-go/services/wallet/bigint"
"github.com/status-im/status-go/transactions" "github.com/status-im/status-go/transactions"
) )
func NewAPI(rpcClient *rpc.Client, accountsManager *account.GethManager, config *params.NodeConfig, appDb *sql.DB) *API { func NewAPI(rpcClient *rpc.Client, accountsManager *account.GethManager, rpcFiltersSrvc *rpcfilters.Service, config *params.NodeConfig, appDb *sql.DB) *API {
return &API{ return &API{
RPCClient: rpcClient, RPCClient: rpcClient,
accountsManager: accountsManager, accountsManager: accountsManager,
rpcFiltersSrvc: rpcFiltersSrvc,
config: config, config: config,
db: NewCommunityTokensDatabase(appDb), db: NewCommunityTokensDatabase(appDb),
} }
@ -37,6 +39,7 @@ func NewAPI(rpcClient *rpc.Client, accountsManager *account.GethManager, config
type API struct { type API struct {
RPCClient *rpc.Client RPCClient *rpc.Client
accountsManager *account.GethManager accountsManager *account.GethManager
rpcFiltersSrvc *rpcfilters.Service
config *params.NodeConfig config *params.NodeConfig
db *Database db *Database
} }
@ -114,6 +117,13 @@ func (api *API) DeployCollectibles(ctx context.Context, chainID uint64, deployme
return DeploymentDetails{}, err return DeploymentDetails{}, err
} }
go api.rpcFiltersSrvc.TriggerTransactionSentToUpstreamEvent(&rpcfilters.PendingTxInfo{
Hash: tx.Hash(),
Type: string(transactions.DeployCommunityToken),
From: common.Address(txArgs.From),
ChainID: chainID,
})
return DeploymentDetails{address.Hex(), tx.Hash().Hex()}, nil return DeploymentDetails{address.Hex(), tx.Hash().Hex()}, nil
} }
@ -139,6 +149,13 @@ func (api *API) DeployAssets(ctx context.Context, chainID uint64, deploymentPara
return DeploymentDetails{}, err return DeploymentDetails{}, err
} }
go api.rpcFiltersSrvc.TriggerTransactionSentToUpstreamEvent(&rpcfilters.PendingTxInfo{
Hash: tx.Hash(),
Type: string(transactions.DeployCommunityToken),
From: common.Address(txArgs.From),
ChainID: chainID,
})
return DeploymentDetails{address.Hex(), tx.Hash().Hex()}, nil return DeploymentDetails{address.Hex(), tx.Hash().Hex()}, nil
} }
@ -243,6 +260,13 @@ func (api *API) MintCollectibles(ctx context.Context, chainID uint64, contractAd
return "", err return "", err
} }
go api.rpcFiltersSrvc.TriggerTransactionSentToUpstreamEvent(&rpcfilters.PendingTxInfo{
Hash: tx.Hash(),
Type: string(transactions.AirdropCommunityToken),
From: common.Address(txArgs.From),
ChainID: chainID,
})
return tx.Hash().Hex(), nil return tx.Hash().Hex(), nil
} }
@ -288,6 +312,13 @@ func (api *API) MintAssets(ctx context.Context, chainID uint64, contractAddress
return "", err return "", err
} }
go api.rpcFiltersSrvc.TriggerTransactionSentToUpstreamEvent(&rpcfilters.PendingTxInfo{
Hash: tx.Hash(),
Type: string(transactions.AirdropCommunityToken),
From: common.Address(txArgs.From),
ChainID: chainID,
})
return tx.Hash().Hex(), nil return tx.Hash().Hex(), nil
} }
@ -325,6 +356,13 @@ func (api *API) RemoteBurn(ctx context.Context, chainID uint64, contractAddress
return "", err return "", err
} }
go api.rpcFiltersSrvc.TriggerTransactionSentToUpstreamEvent(&rpcfilters.PendingTxInfo{
Hash: tx.Hash(),
Type: string(transactions.RemoteDestructCollectible),
From: common.Address(txArgs.From),
ChainID: chainID,
})
return tx.Hash().Hex(), nil return tx.Hash().Hex(), nil
} }
@ -418,7 +456,6 @@ func (api *API) remainingCollectiblesSupply(ctx context.Context, chainID uint64,
} }
var res = new(big.Int) var res = new(big.Int)
res.Sub(maxSupply, mintedCount) res.Sub(maxSupply, mintedCount)
fmt.Printf("Remaining: %v for chain: %v and addr: %v", res, chainID, contractAddress)
return &bigint.BigInt{Int: res}, nil return &bigint.BigInt{Int: res}, nil
} }
@ -536,6 +573,13 @@ func (api *API) Burn(ctx context.Context, chainID uint64, contractAddress string
return "", err return "", err
} }
go api.rpcFiltersSrvc.TriggerTransactionSentToUpstreamEvent(&rpcfilters.PendingTxInfo{
Hash: tx.Hash(),
Type: string(transactions.BurnCommunityToken),
From: common.Address(txArgs.From),
ChainID: chainID,
})
return tx.Hash().Hex(), nil return tx.Hash().Hex(), nil
} }

View File

@ -8,6 +8,7 @@ import (
"github.com/status-im/status-go/account" "github.com/status-im/status-go/account"
"github.com/status-im/status-go/params" "github.com/status-im/status-go/params"
"github.com/status-im/status-go/rpc" "github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/rpcfilters"
) )
// Collectibles service // Collectibles service
@ -16,9 +17,9 @@ type Service struct {
} }
// Returns a new Collectibles Service. // Returns a new Collectibles Service.
func NewService(rpcClient *rpc.Client, accountsManager *account.GethManager, config *params.NodeConfig, appDb *sql.DB) *Service { func NewService(rpcClient *rpc.Client, accountsManager *account.GethManager, rpcFiltersSrvc *rpcfilters.Service, config *params.NodeConfig, appDb *sql.DB) *Service {
return &Service{ return &Service{
NewAPI(rpcClient, accountsManager, config, appDb), NewAPI(rpcClient, accountsManager, rpcFiltersSrvc, config, appDb),
} }
} }

View File

@ -99,10 +99,10 @@ const (
SetPubKey PendingTrxType = "SetPubKey" SetPubKey PendingTrxType = "SetPubKey"
BuyStickerPack PendingTrxType = "BuyStickerPack" BuyStickerPack PendingTrxType = "BuyStickerPack"
WalletTransfer PendingTrxType = "WalletTransfer" WalletTransfer PendingTrxType = "WalletTransfer"
CollectibleDeployment PendingTrxType = "CollectibleDeployment" DeployCommunityToken PendingTrxType = "DeployCommunityToken"
CollectibleAirdrop PendingTrxType = "CollectibleAirdrop" AirdropCommunityToken PendingTrxType = "AirdropCommunityToken"
CollectibleRemoteSelfDestruct PendingTrxType = "CollectibleRemoteSelfDestruct" RemoteDestructCollectible PendingTrxType = "RemoteDestructCollectible"
CollectibleBurn PendingTrxType = "CollectibleBurn" BurnCommunityToken PendingTrxType = "BurnCommunityToken"
) )
type PendingTransaction struct { type PendingTransaction struct {