diff --git a/rpc/client_test.go b/rpc/client_test.go index a3c6237a..ce122670 100644 --- a/rpc/client_test.go +++ b/rpc/client_test.go @@ -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, diff --git a/rpc/getBlockTime.go b/rpc/getBlockTime.go index 4136c290..a461e0c5 100644 --- a/rpc/getBlockTime.go +++ b/rpc/getBlockTime.go @@ -2,6 +2,8 @@ package rpc import ( "context" + + "github.com/gagliardetto/solana-go" ) // GetBlockTime returns the estimated production time of a block. @@ -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 diff --git a/rpc/getTransaction.go b/rpc/getTransaction.go index 38cd1003..2c240147 100644 --- a/rpc/getTransaction.go +++ b/rpc/getTransaction.go @@ -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"` diff --git a/rpc/types.go b/rpc/types.go index 459856ef..2613da1a 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -17,7 +17,6 @@ package rpc import ( stdjson "encoding/json" "fmt" - "time" "github.com/gagliardetto/solana-go" ) @@ -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"` } @@ -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) -} diff --git a/rpc/ws/slotsUpdatesSubscribe.go b/rpc/ws/slotsUpdatesSubscribe.go index 80b762db..ca9b04cb 100644 --- a/rpc/ws/slotsUpdatesSubscribe.go +++ b/rpc/ws/slotsUpdatesSubscribe.go @@ -1,6 +1,6 @@ package ws -import "github.com/gagliardetto/solana-go/rpc" +import "github.com/gagliardetto/solana-go" type SlotsUpdatesResult struct { // The parent slot. @@ -8,7 +8,7 @@ type SlotsUpdatesResult struct { // 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"` } diff --git a/rpc/ws/voteSubscribe.go b/rpc/ws/voteSubscribe.go index 896e6f58..2779868d 100644 --- a/rpc/ws/voteSubscribe.go +++ b/rpc/ws/voteSubscribe.go @@ -2,7 +2,6 @@ package ws import ( "github.com/gagliardetto/solana-go" - "github.com/gagliardetto/solana-go/rpc" ) type VoteResult struct { @@ -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 diff --git a/types.go b/types.go index f01167ff..481077d0 100644 --- a/types.go +++ b/types.go @@ -16,6 +16,7 @@ package solana import ( "fmt" + "time" bin "github.com/gagliardetto/binary" "github.com/gagliardetto/solana-go/text" @@ -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) +}