Skip to content

Commit

Permalink
reduce logging
Browse files Browse the repository at this point in the history
  • Loading branch information
benleb committed Jul 27, 2023
1 parent d621ea1 commit abea905
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
10 changes: 5 additions & 5 deletions internal/chawago/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,25 @@ func (ww *WalletWatcher) Watch() {
// do something with the transaction
if tx.Sender() != nil && ww.watchedWallets.Contains(*tx.Sender()) {
// do something
log.Printf("Transaction from wallet %s: %s", ww.Wallets[*tx.Sender()].Name, style.TerminalLink("https://etherscan.io/tx/"+tx.Hash().Hex(), style.AlmostWhiteStyle.Render(tx.Hash().Hex())))
log.Debugf("Transaction from wallet %s: %s", ww.Wallets[*tx.Sender()].Name, style.TerminalLink("https://etherscan.io/tx/"+tx.Hash().Hex(), style.AlmostWhiteStyle.Render(tx.Hash().Hex())))
}

for _, txLog := range tx.Logs {
if len(txLog.Topics) > 0 && ww.watchedWallets.Contains(common.HexToAddress(txLog.Topics[0].Hex())) {
// do something
log.Printf("wallet %s in topic0: %s", ww.Wallets[common.HexToAddress(txLog.Topics[0].Hex())].Name, style.TerminalLink("https://etherscan.io/tx/"+tx.Hash().Hex(), style.AlmostWhiteStyle.Render(tx.Hash().Hex())))
log.Debugf("wallet %s in topic0: %s", ww.Wallets[common.HexToAddress(txLog.Topics[0].Hex())].Name, style.TerminalLink("https://etherscan.io/tx/"+tx.Hash().Hex(), style.AlmostWhiteStyle.Render(tx.Hash().Hex())))
}
if len(txLog.Topics) > 1 && ww.watchedWallets.Contains(common.HexToAddress(txLog.Topics[1].Hex())) {
// do something
log.Printf("wallet %s in topic1: %s", ww.Wallets[common.HexToAddress(txLog.Topics[1].Hex())].Name, style.TerminalLink("https://etherscan.io/tx/"+tx.Hash().Hex(), style.AlmostWhiteStyle.Render(tx.Hash().Hex())))
log.Debugf("wallet %s in topic1: %s", ww.Wallets[common.HexToAddress(txLog.Topics[1].Hex())].Name, style.TerminalLink("https://etherscan.io/tx/"+tx.Hash().Hex(), style.AlmostWhiteStyle.Render(tx.Hash().Hex())))
}
if len(txLog.Topics) > 2 && ww.watchedWallets.Contains(common.HexToAddress(txLog.Topics[2].Hex())) {
// do something
log.Printf("wallet %s in topic2: %s:", ww.Wallets[common.HexToAddress(txLog.Topics[2].Hex())].Name, style.TerminalLink("https://etherscan.io/tx/"+tx.Hash().Hex(), style.AlmostWhiteStyle.Render(tx.Hash().Hex())))
log.Debugf("wallet %s in topic2: %s:", ww.Wallets[common.HexToAddress(txLog.Topics[2].Hex())].Name, style.TerminalLink("https://etherscan.io/tx/"+tx.Hash().Hex(), style.AlmostWhiteStyle.Render(tx.Hash().Hex())))
}
if len(txLog.Topics) > 3 && ww.watchedWallets.Contains(common.HexToAddress(txLog.Topics[3].Hex())) {
// do something
log.Printf("wallet %s in topic3: %s", ww.Wallets[common.HexToAddress(txLog.Topics[3].Hex())].Name, style.TerminalLink("https://etherscan.io/tx/"+tx.Hash().Hex(), style.AlmostWhiteStyle.Render(tx.Hash().Hex())))
log.Debugf("wallet %s in topic3: %s", ww.Wallets[common.HexToAddress(txLog.Topics[3].Hex())].Name, style.TerminalLink("https://etherscan.io/tx/"+tx.Hash().Hex(), style.AlmostWhiteStyle.Render(tx.Hash().Hex())))
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions internal/nemo/gloomberg/opportunities.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func CheckEIP6551TokenAccount(gb *Gloomberg, tokenContract *common.Address, toke
return false, nil, nil
}

log.Printf("‼️ EIP6551 account %s is a contract!? 🧐", eip6551AccountAddress.String())
gbl.Log.Infof("‼️ EIP6551 account %s is a contract!? 🧐", eip6551AccountAddress.String())

// check if account has nonce
nonceAt, err := gb.ProviderPool.GetNonceAt(context.Background(), eip6551AccountAddress)
Expand All @@ -107,19 +107,19 @@ func CheckEIP6551TokenAccount(gb *Gloomberg, tokenContract *common.Address, toke
return false, nil, fmt.Errorf("failed to get nonce for %s: %w", eip6551AccountAddress.String(), err)
}

log.Debugf("EIP6551 nonceAt: %d", nonceAt)
gbl.Log.Infof("EIP6551 nonceAt: %d", nonceAt)

if nonceAt == 0 {
log.Debugf("EIP6551 account %s has a zero nonce", eip6551AccountAddress.String())
if nonceAt < 2 {
log.Debugf("EIP6551 account %s has no transactions besides contract creation 🤷‍♀️", eip6551AccountAddress.String())

// not a hard criteria for now, so don't stop here
// return false, nil, nil
return false, nil, fmt.Errorf("EIP6551 account %s has no transactions besides contract creation 🤷‍♀️", eip6551AccountAddress.String())
}

gb.PrModf(
"e6551", "💥 %s → %+v",
"e6551", "💥 %s → %+v (nonce: %d)",
style.TerminalLink(utils.GetEtherscanAddressURL(tokenContract), style.ShortenAddressStyled(tokenContract, lipgloss.NewStyle().Foreground(style.GenerateColorWithSeed(tokenContract.Hash().Big().Int64())))),
style.TerminalLink(utils.GetEtherscanAddressURL(&eip6551AccountAddress), eip6551AccountAddress.String()),
nonceAt,
)

eip6551TokenDiscoveredCounter.Inc()
Expand Down
4 changes: 2 additions & 2 deletions internal/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func SendNotification(gb *gloomberg.Gloomberg, ttx *totra.TokenTransaction) {
defer notificationLock()

gbl.Log.Infof("🔐 notification lock for %s acquired (%.0fsec)", fmtHash, viper.GetDuration("cache.notifications_lock_ttl").Seconds())
log.Printf("🔒 %s | notification lock acquired (%.0fsec)", style.ShortenHashStyled(ttx.TxHash), viper.GetDuration("cache.notifications_lock_ttl").Seconds())
log.Debugf("🔒 %s | notification lock acquired (%.0fsec)", style.ShortenHashStyled(ttx.TxHash), viper.GetDuration("cache.notifications_lock_ttl").Seconds())
}

messagesPerUserMap := make(map[*watch.WUser]*strings.Builder)
Expand Down Expand Up @@ -109,7 +109,7 @@ func SendNotification(gb *gloomberg.Gloomberg, ttx *totra.TokenTransaction) {

gbl.Log.Debugf("📸 imageURI: %s", imageURI)

log.Printf("ttx: %+v | transfer: %+v | collection: %+v | userName: %s | triggerAddress: %s", ttx, transfer, collection, userName, triggerAddress.String())
gbl.Log.Infof("ttx: %+v | transfer: %+v | collection: %+v | userName: %s | triggerAddress: %s", ttx, transfer, collection, userName, triggerAddress.String())

// collect telegram messages per user
msgTelegram := buildNotificationMessage(ttx, transfer, collection, userName, triggerAddress)
Expand Down
19 changes: 18 additions & 1 deletion internal/seawa/seawatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,25 @@ func (sw *SeaWatcher) GetItemListedEvents(req *SubscriptionRequest, stream SeaWa
sw.Prf("🐔 received osEvent %s", style.AlmostWhiteStyle.Render(fmt.Sprint(itemListed)))

if err := stream.Send(itemListed); err != nil {
return err
log.Printf("❌ error sending event to grpc client: %s", err)

continue
}

// output to terminal
price := price.NewPrice(event.Payload.BasePrice)
eventType := degendb.GetEventType(event.EventType)
collectionPrimaryStyle := lipgloss.NewStyle().Foreground(style.GenerateColorWithSeed(event.Payload.Item.NftID.ContractAddress().Hash().Big().Int64()))
collectionSecondaryStyle := lipgloss.NewStyle().Foreground(style.GenerateColorWithSeed(event.Payload.Item.NftID.ContractAddress().Big().Int64() ^ 2))
currencySymbol := collectionPrimaryStyle.Bold(false).Render("Ξ")

fmtPrice := style.BoldAlmostWhite(fmt.Sprintf("%5.2f", price.Ether())) + currencySymbol
fmtItemName := strings.ReplaceAll(collectionPrimaryStyle.Bold(true).Render(event.Payload.Item.Name), "#", collectionSecondaryStyle.Render("#"))

fmtItemLink := style.TerminalLink(event.Payload.Item.Permalink, fmtItemName)
// fmtCollectionLink := style.TerminalLink(utils.GetOpenseaCollectionLink(event.Payload.Slug), style.LightGrayStyle.Render(fmt.Sprint(event.Payload.Slug)))

sw.Prf("%s %s %s", eventType.Icon(), fmtPrice, fmtItemLink)
}

return nil
Expand Down

0 comments on commit abea905

Please sign in to comment.