Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(opbot): transaction age textblock #2890

Merged
merged 6 commits into from
Jul 19, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions contrib/opbot/botmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
"context"
"errors"
"fmt"
"log"
"math/big"
"regexp"
"strings"
"sync"
"time"

"github.com/dustin/go-humanize"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand All @@ -17,12 +25,6 @@
rfqClient "github.com/synapsecns/sanguine/services/rfq/api/client"
"github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge"
"github.com/synapsecns/sanguine/services/rfq/relayer/relapi"
"log"
"math/big"
"regexp"
"strings"
"sync"
"time"
)

func (b *Bot) requiresSignoz(definition *slacker.CommandDefinition) *slacker.CommandDefinition {
Expand Down Expand Up @@ -138,7 +140,7 @@
})
}

func (b *Bot) rfqLookupCommand() *slacker.CommandDefinition {

Check failure on line 143 in contrib/opbot/botmd/commands.go

View workflow job for this annotation

GitHub Actions / Lint (contrib/opbot)

cognitive complexity 37 of func `(*Bot).rfqLookupCommand` is high (> 30) (gocognit)
return &slacker.CommandDefinition{
Command: "rfq <tx>",
Description: "find a rfq transaction by either tx hash or txid on all configured relayers",
Expand Down Expand Up @@ -204,7 +206,26 @@
}

var slackBlocks []slack.Block

Check warning on line 209 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L209

Added line #L209 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary leading newline.

There is an unnecessary leading newline at line 209.

-
  for _, status := range statuses {

Committable suggestion was skipped due to low confidence.

for _, status := range statuses {

Check failure on line 210 in contrib/opbot/botmd/commands.go

View workflow job for this annotation

GitHub Actions / Lint (contrib/opbot)

unnecessary leading newline (whitespace)

// TODO: add CreatedAt field to GetQuoteRequestStatusResponse so we don't need to make network calls?
client, err := b.rpcClient.GetChainClient(ctx.Context(), int(status.OriginChainID))
if err != nil {
log.Printf("error getting chain client: %v\n", err)
}

Check warning on line 216 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L211-L216

Added lines #L211 - L216 were not covered by tests

receipt, err := client.TransactionReceipt(ctx.Context(), common.HexToHash(status.OriginTxHash))
if err != nil {
log.Printf("error getting transaction receipt: %v\n", err)
}
txBlock, err := client.BlockByHash(ctx.Context(), receipt.BlockHash)
if err != nil {
log.Printf("error getting block by hash: %v\n", err)
}

Check warning on line 225 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L218-L225

Added lines #L218 - L225 were not covered by tests

txTime := time.Unix(int64(txBlock.Time()), 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize timestamp conversion.

The timestamp conversion to time.Time can be optimized by directly using the Unix method.

-  txTime := time.Unix(int64(txBlock.Time()), 0)
+  txTime := time.Unix(txBlock.Time().Int64(), 0)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
txTime := time.Unix(int64(txBlock.Time()), 0)
txTime := time.Unix(txBlock.Time().Int64(), 0)


Check warning on line 228 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L227-L228

Added lines #L227 - L228 were not covered by tests
objects := []*slack.TextBlockObject{
{
Type: slack.MarkdownType,
Expand All @@ -222,6 +243,10 @@
Type: slack.MarkdownType,
Text: fmt.Sprintf("*OriginTxHash*: %s", toTXSlackLink(status.OriginTxHash, status.OriginChainID)),
},
{
Type: slack.MarkdownType,
Text: fmt.Sprintf("*Estimated Tx Age*: %s", humanize.Time(txTime)),
},

Check warning on line 249 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L246-L249

Added lines #L246 - L249 were not covered by tests
}

if status.DestTxHash == (common.Hash{}).String() {
Expand Down
Loading