Skip to content

Commit

Permalink
Move UnixTimeSeconds to solana package
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Sep 11, 2021
1 parent d91a74a commit f48fa05
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,7 @@ func TestClient_GetTransaction(t *testing.T) {
)

blockTimeSeconds := int64(1624821990)
blockTime := UnixTimeSeconds(blockTimeSeconds)
blockTime := solana.UnixTimeSeconds(blockTimeSeconds)
expected := &GetTransactionResult{
Slot: 83311386,
BlockTime: &blockTime,
Expand Down
4 changes: 3 additions & 1 deletion rpc/getBlockTime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package rpc

import (
"context"

"github.com/gagliardetto/solana-go"
)

// GetBlockTime returns the estimated production time of a block.
Expand All @@ -18,7 +20,7 @@ import (
func (cl *Client) GetBlockTime(
ctx context.Context,
block uint64, // block, identified by Slot
) (out *UnixTimeSeconds, err error) {
) (out *solana.UnixTimeSeconds, err error) {
params := []interface{}{block}
err = cl.rpcClient.CallForInto(ctx, &out, "getBlockTime", params)
return
Expand Down
2 changes: 1 addition & 1 deletion rpc/getTransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type GetTransactionResult struct {
// Estimated production time, as Unix timestamp (seconds since the Unix epoch)
// of when the transaction was processed.
// Nil if not available.
BlockTime *UnixTimeSeconds `json:"blockTime"`
BlockTime *solana.UnixTimeSeconds `json:"blockTime"`

Transaction *TransactionResultEnvelope `json:"transaction"`
Meta *TransactionMeta `json:"meta,omitempty"`
Expand Down
10 changes: 1 addition & 9 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package rpc
import (
stdjson "encoding/json"
"fmt"
"time"

"github.com/gagliardetto/solana-go"
)
Expand Down Expand Up @@ -188,7 +187,7 @@ type TransactionSignature struct {

// Estimated production time, as Unix timestamp (seconds since the Unix epoch)
// of when transaction was processed. Nil if not available.
BlockTime *UnixTimeSeconds `json:"blockTime,omitempty"`
BlockTime *solana.UnixTimeSeconds `json:"blockTime,omitempty"`

ConfirmationStatus ConfirmationStatusType `json:"confirmationStatus,omitempty"`
}
Expand Down Expand Up @@ -380,10 +379,3 @@ func (p *ParsedInstruction) IsParsed() bool {
}

type M map[string]interface{}

// Unix timestamp (seconds since the Unix epoch)
type UnixTimeSeconds int64

func (res UnixTimeSeconds) Time() time.Time {
return time.Unix(int64(res), 0)
}
4 changes: 2 additions & 2 deletions rpc/ws/slotsUpdatesSubscribe.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package ws

import "github.com/gagliardetto/solana-go/rpc"
import "github.com/gagliardetto/solana-go"

type SlotsUpdatesResult struct {
// The parent slot.
Parent uint64 `json:"parent"`
// The newly updated slot.
Slot uint64 `json:"slot"`
// The Unix timestamp of the update.
Timestamp *rpc.UnixTimeSeconds `json:"timestamp"`
Timestamp *solana.UnixTimeSeconds `json:"timestamp"`
// The update type.
Type SlotsUpdatesType `json:"type"`
}
Expand Down
3 changes: 1 addition & 2 deletions rpc/ws/voteSubscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ws

import (
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"
)

type VoteResult struct {
Expand All @@ -11,7 +10,7 @@ type VoteResult struct {
// The slots covered by the vote.
Slots []uint64 `json:"slots"`
// The timestamp of the vote.
Timestamp *rpc.UnixTimeSeconds `json:"timestamp,omitempty"`
Timestamp *solana.UnixTimeSeconds `json:"timestamp,omitempty"`
}

// VoteSubscribe (UNSTABLE, disabled by default) subscribes
Expand Down
8 changes: 8 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package solana

import (
"fmt"
"time"

bin "github.com/gagliardetto/binary"
"github.com/gagliardetto/solana-go/text"
Expand Down Expand Up @@ -319,3 +320,10 @@ func MustTransactionFromDecoder(decoder *bin.Decoder) *Transaction {
}
return out
}

// Unix timestamp (seconds since the Unix epoch)
type UnixTimeSeconds int64

func (res UnixTimeSeconds) Time() time.Time {
return time.Unix(int64(res), 0)
}

0 comments on commit f48fa05

Please sign in to comment.