Skip to content

Commit

Permalink
Update default genesis tx type
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Nov 4, 2024
1 parent 83b3c2f commit 19b7a0d
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 134 deletions.
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 @@ -69,10 +69,11 @@ func (s *Service) ExecuteBackup(ctx context.Context, cfg Config) error {

// Save the block transaction data, if any
for _, tx := range block.Txs {
data := &types.TxData{
Tx: tx,
BlockNum: block.Height,
Timestamp: block.Timestamp,
data := &gnoland.TxWithMetadata{
Tx: tx,
Metadata: &gnoland.GnoTxMetadata{
Timestamp: block.Timestamp,
},
}

// Write the tx data to the file
Expand Down
12 changes: 5 additions & 7 deletions backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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 @@ -16,7 +17,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 @@ -151,16 +151,15 @@ func TestBackup_ExecuteBackup_FixedRange(t *testing.T) {

// Iterate over each line in the file
for scanner.Scan() {
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 {
t.Fatalf("unable to unmarshal JSON line, %v", err)
}

assert.Equal(t, expectedBlock, txData.BlockNum)
assert.Equal(t, exampleTx, txData.Tx)
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))

expectedBlock++
}
Expand Down Expand Up @@ -252,16 +251,15 @@ func TestBackup_ExecuteBackup_Watch(t *testing.T) {

// Iterate over each line in the file
for scanner.Scan() {
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 {
t.Fatalf("unable to unmarshal JSON line, %v", err)
}

assert.Equal(t, expectedBlock, txData.BlockNum)
assert.Equal(t, exampleTx, txData.Tx)
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))

expectedBlock++
}
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
}
60 changes: 34 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
module github.com/gnolang/tx-archive

go 1.21
go 1.22

require (
github.com/gnolang/gno v0.1.0-nightly.20240627
github.com/gnolang/gno v0.0.0-20241104162246-c776e32b0843
github.com/peterbourgon/ff/v3 v3.4.0
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.27.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.22.0 // 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/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
go.etcd.io/bbolt v1.3.11 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // 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/net v0.25.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.26.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.24.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 19b7a0d

Please sign in to comment.