Skip to content

Commit

Permalink
Merge branch 'main' into fork/aeddi/dev/aeddi/rpc-batch
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Feb 3, 2025
2 parents 01485a3 + 09edd61 commit 5d203e6
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 148 deletions.
5 changes: 4 additions & 1 deletion .github/golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ linters:
- bidichk # Checks for dangerous unicode character sequences
- durationcheck # Check for two durations multiplied together
- errcheck # Forces to not skip error check
- exportloopref # Checks for pointers to enclosing loop variables
- copyloopvar # Checks for pointers to enclosing loop variables
- gocritic # Bundles different linting checks
- godot # Checks for periods at the end of comments
- gomoddirectives # Allow or ban replace directives in go.mod
Expand Down Expand Up @@ -122,3 +122,6 @@ linters-settings:
rules:
json: goCamel
yaml: goCamel
gosec:
excludes:
- G115 # Potential integer overflow when converting between integer types
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.54 # do not forget to change the version also on the makefile
version: v1.61 # do not forget to change the version also on the makefile
args:
--config=./.github/golangci.yaml
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
go-version: 1.21
cache: true

- uses: sigstore/cosign-installer@v3.6.0
- uses: anchore/sbom-action/[email protected].2
- uses: sigstore/cosign-installer@v3.7.0
- uses: anchore/sbom-action/[email protected].9

- uses: docker/login-action@v3
with:
Expand Down
11 changes: 6 additions & 5 deletions backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"fmt"
"time"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
_ "github.com/gnolang/gno/gno.land/pkg/sdk/vm"

"github.com/gnolang/tx-archive/backup/client"
"github.com/gnolang/tx-archive/backup/writer"
"github.com/gnolang/tx-archive/log"
"github.com/gnolang/tx-archive/log/noop"
"github.com/gnolang/tx-archive/types"
)

// Service is the chain backup service
Expand Down Expand Up @@ -124,10 +124,11 @@ func (s *Service) ExecuteBackup(ctx context.Context, cfg Config) error {
for _, block := range blocks {
for i, tx := range block.Txs {
// Write the tx data to the file
txData := &types.TxData{
Tx: tx,
BlockNum: block.Height,
Timestamp: block.Timestamp,
txData := &gnoland.TxWithMetadata{
Tx: tx,
Metadata: &gnoland.GnoTxMetadata{
Timestamp: block.Timestamp,
},
}

if writeErr := s.writer.WriteTxData(txData); writeErr != nil {
Expand Down
24 changes: 15 additions & 9 deletions backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/gno/tm2/pkg/std"
"github.com/stretchr/testify/assert"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/gnolang/tx-archive/backup/client"
"github.com/gnolang/tx-archive/backup/writer/standard"
"github.com/gnolang/tx-archive/log/noop"
"github.com/gnolang/tx-archive/types"
)

func TestBackup_DetermineRightBound(t *testing.T) {
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestBackup_ExecuteBackup_FixedRange(t *testing.T) {
getLatestBlockNumberFn: func() (uint64, error) {
return tCase.toBlock, nil
},
getBlocksFn: func(ctx context.Context, from, to uint64) ([]*client.Block, error) {
getBlocksFn: func(_ context.Context, from, to uint64) ([]*client.Block, error) {
// Sanity check
if from > to {
t.Fatal("invalid block number requested")
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestBackup_ExecuteBackup_FixedRange(t *testing.T) {

// Iterate over each line in the file
for ; scanner.Scan(); lineCount++ {
var txData types.TxData
var txData gnoland.TxWithMetadata

// Unmarshal the JSON data into the Person struct
if err := amino.UnmarshalJSON(scanner.Bytes(), &txData); err != nil {
Expand All @@ -217,9 +217,12 @@ func TestBackup_ExecuteBackup_FixedRange(t *testing.T) {
expectedBlock := tCase.fromBlock + lineCount/tCase.txsPerBlock
expectedTx := lineCount % tCase.txsPerBlock
expectedTxMemo := generateMemo(expectedBlock, expectedTx)
assert.Equal(t, expectedBlock, txData.BlockNum)
assert.Equal(t, expectedTxMemo, txData.Tx.Memo)
assert.Equal(t, blockTime.Add(time.Duration(expectedBlock)*time.Minute).Local(), time.UnixMilli(txData.Timestamp))
assert.Equal(
t,
blockTime.Add(time.Duration(expectedBlock)*time.Minute).Local(),
time.UnixMilli(txData.Metadata.Timestamp),
)
}

// Check for errors during scanning
Expand Down Expand Up @@ -266,7 +269,7 @@ func TestBackup_ExecuteBackup_Watch(t *testing.T) {

return latest, nil
},
getBlocksFn: func(ctx context.Context, from, to uint64) ([]*client.Block, error) {
getBlocksFn: func(_ context.Context, from, to uint64) ([]*client.Block, error) {
// Sanity check
if from > to {
t.Fatal("invalid block number requested")
Expand Down Expand Up @@ -319,7 +322,7 @@ func TestBackup_ExecuteBackup_Watch(t *testing.T) {

// Iterate over each line in the file
for ; scanner.Scan(); lineCount++ {
var txData types.TxData
var txData gnoland.TxWithMetadata

// Unmarshal the JSON data into the Person struct
if err := amino.UnmarshalJSON(scanner.Bytes(), &txData); err != nil {
Expand All @@ -329,9 +332,12 @@ func TestBackup_ExecuteBackup_Watch(t *testing.T) {
expectedBlock := tCase.fromBlock + lineCount/tCase.txsPerBlock
expectedTx := lineCount % tCase.txsPerBlock
expectedTxMemo := generateMemo(expectedBlock, expectedTx)
assert.Equal(t, expectedBlock, txData.BlockNum)
assert.Equal(t, expectedTxMemo, txData.Tx.Memo)
assert.Equal(t, blockTime.Add(time.Duration(expectedBlock)*time.Minute).Local(), time.UnixMilli(txData.Timestamp))
assert.Equal(
t,
blockTime.Add(time.Duration(expectedBlock)*time.Minute).Local(),
time.UnixMilli(txData.Metadata.Timestamp),
)
}

// Check for errors during scanning
Expand Down
7 changes: 3 additions & 4 deletions backup/writer/legacy/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"fmt"
"io"

"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/tx-archive/types"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
_ "github.com/gnolang/gno/gno.land/pkg/sdk/vm"
"github.com/gnolang/gno/tm2/pkg/amino"
)

type Writer struct {
Expand All @@ -22,7 +21,7 @@ func NewWriter(writer io.Writer) *Writer {
}
}

func (w *Writer) WriteTxData(data *types.TxData) error {
func (w *Writer) WriteTxData(data *gnoland.TxWithMetadata) error {
// Marshal tx individual tx into JSON, instead of the entire tx data
jsonData, err := amino.MarshalJSON(data.Tx)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions backup/writer/legacy/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"testing"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/gno/tm2/pkg/std"
"github.com/gnolang/tx-archive/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -17,11 +17,10 @@ func TestWriter_Legacy(t *testing.T) {
var (
b bytes.Buffer

txData = &types.TxData{
txData = &gnoland.TxWithMetadata{
Tx: std.Tx{
Memo: "example tx",
},
BlockNum: 10,
}
)

Expand Down
7 changes: 3 additions & 4 deletions backup/writer/standard/standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"fmt"
"io"

"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/tx-archive/types"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
_ "github.com/gnolang/gno/gno.land/pkg/sdk/vm"
"github.com/gnolang/gno/tm2/pkg/amino"
)

type Writer struct {
Expand All @@ -22,7 +21,7 @@ func NewWriter(writer io.Writer) *Writer {
}
}

func (w *Writer) WriteTxData(data *types.TxData) error {
func (w *Writer) WriteTxData(data *gnoland.TxWithMetadata) error {
// Marshal the entire tx data into JSON
jsonData, err := amino.MarshalJSON(data)
if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions backup/writer/standard/standard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package standard
import (
"bytes"
"testing"
"time"

"github.com/gnolang/gno/gno.land/pkg/gnoland"
"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/gno/tm2/pkg/std"
"github.com/gnolang/tx-archive/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -17,11 +18,13 @@ func TestWriter_Standard(t *testing.T) {
var (
b bytes.Buffer

txData = &types.TxData{
txData = &gnoland.TxWithMetadata{
Tx: std.Tx{
Memo: "example tx",
},
BlockNum: 10,
Metadata: &gnoland.GnoTxMetadata{
Timestamp: time.Now().Unix(),
},
}
)

Expand All @@ -31,7 +34,7 @@ func TestWriter_Standard(t *testing.T) {
// Write example tx data
require.NoError(t, w.WriteTxData(txData))

var readTx types.TxData
var readTx gnoland.TxWithMetadata

readErr := amino.UnmarshalJSON(b.Bytes(), &readTx)
require.NoError(t, readErr)
Expand Down
6 changes: 4 additions & 2 deletions backup/writer/writer.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package writer

import "github.com/gnolang/tx-archive/types"
import (
"github.com/gnolang/gno/gno.land/pkg/gnoland"
)

// Writer defines the backup writer interface
type Writer interface {
// WriteTxData outputs the given TX data
// to some kind of storage
WriteTxData(*types.TxData) error
WriteTxData(*gnoland.TxWithMetadata) error
}
67 changes: 39 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
module github.com/gnolang/tx-archive

go 1.21
go 1.22.0

toolchain go1.23.5

require (
github.com/gnolang/gno v0.1.0-nightly.20240627
github.com/gnolang/gno v0.0.0-20250203085347-dc0b608d46ab
github.com/peterbourgon/ff/v3 v3.4.0
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
go.uber.org/zap v1.27.0
golang.org/x/net v0.25.0
golang.org/x/net v0.34.0
)

require (
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
dario.cat/mergo v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/btcsuite/btcd/btcutil v1.1.6 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/xid v1.5.0 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.25.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.27.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
github.com/rs/cors v1.11.1 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/sig-0/insertion-queue v0.0.0-20241004125609-6b3ca841346b // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
go.etcd.io/bbolt v1.3.11 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.34.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.34.0 // indirect
go.opentelemetry.io/otel/metric v1.34.0 // indirect
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect
go.opentelemetry.io/otel/trace v1.34.0 // indirect
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
google.golang.org/grpc v1.69.4 // indirect
google.golang.org/protobuf v1.36.3 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 5d203e6

Please sign in to comment.