fix: bug UTC time.

This commit is contained in:
Waris Aiemworawutikul
2024-07-16 13:25:49 +07:00
parent 6be4c877d6
commit b10b8c59d7
5 changed files with 10 additions and 9 deletions

View File

@@ -192,7 +192,7 @@ func (h *handler) eventsHandler(ctx *fiber.Ctx) error {
err = ctx.JSON(responses)
if err != nil {
return errors.Wrap(err, "Go fiber cannot parse JSON: %w")
return errors.Wrap(err, "Go fiber cannot parse JSON")
}
return nil
}

View File

@@ -17,7 +17,6 @@ import (
"github.com/gaze-network/indexer-network/modules/nodesale/protobuf"
repository "github.com/gaze-network/indexer-network/modules/nodesale/repository/postgres"
"github.com/gaze-network/indexer-network/modules/nodesale/repository/postgres/gen"
"github.com/jackc/pgx/v5"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
@@ -27,14 +26,13 @@ var p *Processor
var postgresConf postgres.Config = postgres.Config{
User: "postgres",
Password: "P@ssw0rd",
DBName: "gaze_indexer",
}
var qtx datagateway.NodesaleDataGatewayWithTx
var ctx context.Context
var tx pgx.Tx
var (
testBlockHeigh int64 = 101
testTxIndex int = 1
@@ -62,7 +60,7 @@ func TestMain(m *testing.M) {
qtx, _ = p.datagateway.BeginNodesaleTx(ctx)
res := m.Run()
tx.Commit(ctx)
qtx.Commit(ctx)
db.Close()
os.Exit(res)
}

View File

@@ -158,10 +158,12 @@ func (p *Processor) processPurchase(ctx context.Context, qtx datagateway.Nodesal
var txPaid int64 = 0
meta := metaData{}
if valid {
// get total amount paid to seller
for _, txOut := range event.transaction.TxOut {
_, txOutAddrs, _, _ := txscript.ExtractPkScriptAddrs(txOut.PkScript, p.network.ChainParams())
if len(txOutAddrs) == 1 && bytes.Equal(
[]byte(sellerAddr.EncodeAddress()),
[]byte(txOutAddrs[0].EncodeAddress()),

View File

@@ -400,6 +400,7 @@ func TestValidPurchase(t *testing.T) {
},
}
p.processPurchase(ctx, qtx, block, event)
nodes, _ := qtx.GetNodes(ctx, datagateway.GetNodesParams{
SaleBlock: testBlockHeigh - 2,
SaleTxIndex: int32(testTxIndex) - 2,

View File

@@ -120,7 +120,7 @@ func (repo *Repository) AddEvent(ctx context.Context, arg datagateway.AddEventPa
Action: arg.Action,
RawMessage: arg.RawMessage,
ParsedMessage: arg.ParsedMessage,
BlockTimestamp: pgtype.Timestamp{Time: arg.BlockTimestamp, Valid: true},
BlockTimestamp: pgtype.Timestamp{Time: arg.BlockTimestamp.UTC(), Valid: true},
BlockHash: arg.BlockHash,
Metadata: arg.Metadata,
})
@@ -148,8 +148,8 @@ func (repo *Repository) AddNodesale(ctx context.Context, arg datagateway.AddNode
BlockHeight: arg.BlockHeight,
TxIndex: arg.TxIndex,
Name: arg.Name,
StartsAt: pgtype.Timestamp{Time: arg.StartsAt, Valid: true},
EndsAt: pgtype.Timestamp{Time: arg.EndsAt, Valid: true},
StartsAt: pgtype.Timestamp{Time: arg.StartsAt.UTC(), Valid: true},
EndsAt: pgtype.Timestamp{Time: arg.EndsAt.UTC(), Valid: true},
Tiers: arg.Tiers,
SellerPublicKey: arg.SellerPublicKey,
MaxPerAddress: arg.MaxPerAddress,
@@ -286,7 +286,7 @@ func (repo *Repository) GetEventsByWallet(ctx context.Context, walletAddress str
Action: item.Action,
RawMessage: item.RawMessage,
ParsedMessage: item.ParsedMessage,
BlockTimestamp: item.BlockTimestamp.Time,
BlockTimestamp: item.BlockTimestamp.Time.UTC(),
BlockHash: item.BlockHash,
Metadata: item.Metadata,
}