Skip to content

Commit

Permalink
satellite/console: use correct link for zkSync
Browse files Browse the repository at this point in the history
This change uses the right block explorer link for zkSync transactions.

Issue: #6873

Change-Id: I49165e2b0becf45bc64ee7e6d04913e3a23f344f
  • Loading branch information
wilfred-asomanii authored and Storj Robot committed Mar 28, 2024
1 parent 78991b2 commit dab2464
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
1 change: 1 addition & 0 deletions satellite/console/config.go
Expand Up @@ -27,6 +27,7 @@ type Config struct {
UserBalanceForUpgrade int64 `help:"amount of base units of US micro dollars needed to upgrade user's tier status" default:"10000000"`
PlacementEdgeURLOverrides PlacementEdgeURLOverrides `help:"placement-specific edge service URL overrides in the format {\"placementID\": {\"authService\": \"...\", \"publicLinksharing\": \"...\", \"internalLinksharing\": \"...\"}, \"placementID2\": ...}"`
BlockExplorerURL string `help:"url of the transaction block explorer" default:"https://etherscan.io/"`
ZkSyncBlockExplorerURL string `help:"url of the zkSync transaction block explorer" default:"https://explorer.zksync.io/"`
BillingFeaturesEnabled bool `help:"indicates if billing features should be enabled" default:"true"`
StripePaymentElementEnabled bool `help:"indicates whether the stripe payment element should be used to collect card info" default:"true"`
SignupActivationCodeEnabled bool `help:"indicates whether the whether account activation is done using activation code" default:"false"`
Expand Down
26 changes: 20 additions & 6 deletions satellite/console/service.go
Expand Up @@ -206,6 +206,8 @@ type Service struct {

varPartners map[string]struct{}

paymentSourceChainIDs map[int64]string

versioningConfig VersioningConfig

nowFn func() time.Time
Expand All @@ -229,7 +231,7 @@ type Payments struct {
}

// NewService returns new instance of Service.
func NewService(log *zap.Logger, store DB, restKeys RESTKeys, projectAccounting accounting.ProjectAccounting, projectUsage *accounting.Service, buckets buckets.DB, accounts payments.Accounts, depositWallets payments.DepositWallets, billing billing.TransactionsDB, analytics *analytics.Service, tokens *consoleauth.Service, mailService *mailservice.Service, accountFreezeService *AccountFreezeService, emission *emission.Service, satelliteAddress string, satelliteName string, maxProjectBuckets int, placements nodeselection.PlacementDefinitions, versioning VersioningConfig, config Config) (*Service, error) {
func NewService(log *zap.Logger, store DB, restKeys RESTKeys, projectAccounting accounting.ProjectAccounting, projectUsage *accounting.Service, buckets buckets.DB, accounts payments.Accounts, depositWallets payments.DepositWallets, billingDb billing.TransactionsDB, analytics *analytics.Service, tokens *consoleauth.Service, mailService *mailservice.Service, accountFreezeService *AccountFreezeService, emission *emission.Service, satelliteAddress string, satelliteName string, maxProjectBuckets int, placements nodeselection.PlacementDefinitions, versioning VersioningConfig, config Config) (*Service, error) {
if store == nil {
return nil, errs.New("store can't be nil")
}
Expand Down Expand Up @@ -271,6 +273,13 @@ func NewService(log *zap.Logger, store DB, restKeys RESTKeys, projectAccounting
versioning.projectMap[projectID] = struct{}{}
}

paymentSourceChainIDs := make(map[int64]string)
for source, IDs := range billing.SourceChainIDs {
for _, ID := range IDs {
paymentSourceChainIDs[ID] = source
}
}

return &Service{
log: log,
auditLogger: log.Named("auditlog"),
Expand All @@ -282,7 +291,7 @@ func NewService(log *zap.Logger, store DB, restKeys RESTKeys, projectAccounting
placements: placements,
accounts: accounts,
depositWallets: depositWallets,
billing: billing,
billing: billingDb,
registrationCaptchaHandler: registrationCaptchaHandler,
loginCaptchaHandler: loginCaptchaHandler,
analytics: analytics,
Expand All @@ -296,6 +305,7 @@ func NewService(log *zap.Logger, store DB, restKeys RESTKeys, projectAccounting
config: config,
varPartners: partners,
versioningConfig: versioning,
paymentSourceChainIDs: paymentSourceChainIDs,
nowFn: time.Now,
}, nil
}
Expand Down Expand Up @@ -3569,9 +3579,12 @@ type WalletPayments struct {
Payments []PaymentInfo `json:"payments"`
}

// EtherscanURL creates etherscan transaction URI.
func (payment Payments) EtherscanURL(tx string) string {
// BlockExplorerURL creates zkSync/etherscan transaction URI based on source.
func (payment Payments) BlockExplorerURL(tx string, source string) string {
url := payment.service.config.BlockExplorerURL
if source == billing.StorjScanZkSyncSource {
url = payment.service.config.ZkSyncBlockExplorerURL
}
if !strings.HasSuffix(url, "/") {
url += "/"
}
Expand Down Expand Up @@ -3661,13 +3674,14 @@ func (payment Payments) WalletPayments(ctx context.Context) (_ WalletPayments, e

var paymentInfos []PaymentInfo
for _, walletPayment := range walletPayments {
source := payment.service.paymentSourceChainIDs[walletPayment.ChainID]
paymentInfos = append(paymentInfos, PaymentInfo{
ID: fmt.Sprintf("%s#%d", walletPayment.Transaction.Hex(), walletPayment.LogIndex),
Type: "storjscan",
Wallet: walletPayment.To.Hex(),
Amount: walletPayment.USDValue,
Status: string(walletPayment.Status),
Link: payment.EtherscanURL(walletPayment.Transaction.Hex()),
Link: payment.BlockExplorerURL(walletPayment.Transaction.Hex(), source),
Timestamp: walletPayment.Timestamp,
})
}
Expand Down Expand Up @@ -3698,7 +3712,7 @@ func (payment Payments) WalletPayments(ctx context.Context) (_ WalletPayments, e
Wallet: address.Hex(),
Amount: txn.Amount,
Status: string(txn.Status),
Link: payment.EtherscanURL(meta.ReferenceID),
Link: payment.BlockExplorerURL(meta.ReferenceID, txn.Source),
Timestamp: txn.Timestamp,
})
}
Expand Down
24 changes: 20 additions & 4 deletions satellite/console/service_test.go
Expand Up @@ -2199,8 +2199,12 @@ func TestPaymentsWalletPayments(t *testing.T) {

var cachedPayments []storjscan.CachedPayment
for i := 0; i < 10; i++ {
chainID := billing.SourceChainIDs[billing.StorjScanZkSyncSource]
if i%2 == 0 {
chainID = billing.SourceChainIDs[billing.StorjScanEthereumSource]
}
cachedPayments = append(cachedPayments, storjscan.CachedPayment{
ChainID: 1337,
ChainID: chainID[0],
From: blockchaintest.NewAddress(),
To: wallet,
TokenValue: currency.AmountFromBaseUnits(1000, currency.StorjToken),
Expand All @@ -2219,12 +2223,24 @@ func TestPaymentsWalletPayments(t *testing.T) {
reqCtx := console.WithUser(ctx, user)

sort.Slice(cachedPayments, func(i, j int) bool {
return cachedPayments[i].BlockNumber > cachedPayments[j].BlockNumber
if cachedPayments[i].ChainID != cachedPayments[j].ChainID {
return cachedPayments[i].ChainID > cachedPayments[j].ChainID
}
if cachedPayments[i].BlockNumber != cachedPayments[j].BlockNumber {
return cachedPayments[i].BlockNumber > cachedPayments[j].BlockNumber
}
return cachedPayments[i].LogIndex > cachedPayments[j].LogIndex
})
sort.Slice(transactions, func(i, j int) bool {
return transactions[i].CreatedAt.After(transactions[j].CreatedAt)
})

paymentSourceChainIDs := make(map[int64]string)
for source, IDs := range billing.SourceChainIDs {
for _, ID := range IDs {
paymentSourceChainIDs[ID] = source
}
}
var expected []console.PaymentInfo
for _, pmnt := range cachedPayments {
expected = append(expected, console.PaymentInfo{
Expand All @@ -2233,7 +2249,7 @@ func TestPaymentsWalletPayments(t *testing.T) {
Wallet: pmnt.To.Hex(),
Amount: pmnt.USDValue,
Status: string(pmnt.Status),
Link: sat.API.Console.Service.Payments().EtherscanURL(pmnt.Transaction.Hex()),
Link: sat.API.Console.Service.Payments().BlockExplorerURL(pmnt.Transaction.Hex(), paymentSourceChainIDs[pmnt.ChainID]),
Timestamp: pmnt.Timestamp,
})
}
Expand Down Expand Up @@ -2275,7 +2291,7 @@ func TestPaymentsWalletPayments(t *testing.T) {
Wallet: meta.Wallet,
Amount: txn.Amount,
Status: string(txn.Status),
Link: sat.API.Console.Service.Payments().EtherscanURL(meta.ReferenceID),
Link: sat.API.Console.Service.Payments().BlockExplorerURL(meta.ReferenceID, txn.Source),
Timestamp: txn.Timestamp,
})
}
Expand Down
3 changes: 3 additions & 0 deletions satellite/satellite-config.yaml.lock
Expand Up @@ -517,6 +517,9 @@ compensation.withheld-percents: 75,75,75,50,50,50,25,25,25,0,0,0,0,0,0
# whether to load templates on each request
# console.watch: false

# url of the zkSync transaction block explorer
# console.zk-sync-block-explorer-url: https://explorer.zksync.io/

# allow private IPs in CheckIn and PingMe
# contact.allow-private-ip: false

Expand Down

0 comments on commit dab2464

Please sign in to comment.