Skip to content

Commit

Permalink
Use int64 for API timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
G10h4ck committed Mar 2, 2022
1 parent 3a06499 commit 4205624
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type APIrequest struct {
Signature types.HexBytes `json:"signature,omitempty"`
SrcNetId string `json:"sourceNetworkId,omitempty"`
Status string `json:"status,omitempty"`
Timestamp int32 `json:"timestamp"`
Timestamp int64 `json:"timestamp,string"`
TxIndex int32 `json:"txIndex,omitempty"`
Type string `json:"type,omitempty"`
URI string `json:"uri,omitempty"`
Expand All @@ -98,7 +98,7 @@ func (a *APIrequest) SetAddress(addr *common.Address) {
func (a *APIrequest) SetID(id string) {
}

func (a *APIrequest) SetTimestamp(ts int32) {
func (a *APIrequest) SetTimestamp(ts int64) {
a.Timestamp = ts
}

Expand Down Expand Up @@ -204,7 +204,7 @@ type APIresponse struct {
Size *int64 `json:"size,omitempty"`
State string `json:"state,omitempty"`
Stats *VochainStats `json:"stats,omitempty"`
Timestamp int32 `json:"timestamp"`
Timestamp int64 `json:"timestamp,string"`
Type string `json:"type,omitempty"`
Tx *indexertypes.TxPackage `json:"tx,omitempty"`
TxList []*indexertypes.TxMetadata `json:"txList,omitempty"`
Expand All @@ -214,7 +214,7 @@ type APIresponse struct {
Weight *types.BigInt `json:"weight,omitempty"`
}

func (a *APIresponse) SetTimestamp(ts int32) {
func (a *APIresponse) SetTimestamp(ts int64) {
a.Timestamp = ts
}

Expand Down
2 changes: 1 addition & 1 deletion census/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (m *Manager) Handler(ctx context.Context, r *api.APIrequest,
// Process data
log.Debugf("processing data %s", r.String())
resp.Ok = true
resp.Timestamp = int32(time.Now().Unix())
resp.Timestamp = time.Now().Unix()

// Trim Hex on censusID and RootHash
if len(r.CensusID) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions client/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *Client) CheckClose(err *error) {
// Request makes a request to the previously connected endpoint
func (c *Client) Request(req api.APIrequest, signer *ethereum.SignKeys) (*api.APIresponse, error) {
method := req.Method
req.Timestamp = int32(time.Now().Unix())
req.Timestamp = time.Now().Unix()
reqInner, err := crypto.SortedMarshalJSON(req)
if err != nil {
return nil, fmt.Errorf("%s: %v", method, err)
Expand Down Expand Up @@ -122,7 +122,7 @@ func (c *Client) ForTest(tb testing.TB, req *api.APIrequest) func(
tb.Fatalf("request is nil")
}
req.Method = method
req.Timestamp = int32(time.Now().Unix())
req.Timestamp = time.Now().Unix()
resp, err := c.Request(*req, signer)
if err != nil {
tb.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions httprouter/jsonrpcapi/jsonrpcapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type API struct {
ID string `json:"id"`
Ok bool `json:"ok,omitempty"`
Error string `json:"error,omitempty"`
Timestamp int32 `json:"timestamp"`
Timestamp int64 `json:"timestamp,string"`
}

func (a *API) GetMethod() string {
Expand All @@ -115,7 +115,7 @@ func (a *API) SetError(errorMsg string) {
a.Error = errorMsg
}

func (a *API) SetTimestamp(ts int32) {
func (a *API) SetTimestamp(ts int64) {
a.Timestamp = ts
}

Expand Down
4 changes: 2 additions & 2 deletions httprouter/jsonrpcapi/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// MessageAPI inteface defines the methods that the SignedJRPC custom message type must contain.
type MessageAPI interface {
SetID(string)
SetTimestamp(int32)
SetTimestamp(int64)
SetError(string)
GetMethod() string
}
Expand All @@ -40,7 +40,7 @@ func BuildReply(signer *ethereum.SignKeys, msg MessageAPI, requestID string) ([]
var err error
respRequest := &ResponseMessage{ID: requestID}
msg.SetID(requestID)
msg.SetTimestamp(int32(time.Now().Unix()))
msg.SetTimestamp(time.Now().Unix())
respRequest.MessageAPI, err = crypto.SortedMarshalJSON(msg)
if err != nil {
return nil, err
Expand Down

0 comments on commit 4205624

Please sign in to comment.