From 420562439d7d427f6af4fefa4f76634e503624da Mon Sep 17 00:00:00 2001 From: G10h4ck Date: Wed, 2 Mar 2022 10:51:35 +0100 Subject: [PATCH] Use int64 for API timestamp --- api/types.go | 8 ++++---- census/handler.go | 2 +- client/connection.go | 4 ++-- httprouter/jsonrpcapi/jsonrpcapi_test.go | 4 ++-- httprouter/jsonrpcapi/message.go | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/api/types.go b/api/types.go index eac0b8836..b3d730333 100644 --- a/api/types.go +++ b/api/types.go @@ -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"` @@ -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 } @@ -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"` @@ -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 } diff --git a/census/handler.go b/census/handler.go index a410225bf..df328538f 100644 --- a/census/handler.go +++ b/census/handler.go @@ -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 { diff --git a/client/connection.go b/client/connection.go index 483f4cb9b..d76c5d484 100644 --- a/client/connection.go +++ b/client/connection.go @@ -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) @@ -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) diff --git a/httprouter/jsonrpcapi/jsonrpcapi_test.go b/httprouter/jsonrpcapi/jsonrpcapi_test.go index 1cd7e66b6..be14fcce2 100644 --- a/httprouter/jsonrpcapi/jsonrpcapi_test.go +++ b/httprouter/jsonrpcapi/jsonrpcapi_test.go @@ -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 { @@ -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 } diff --git a/httprouter/jsonrpcapi/message.go b/httprouter/jsonrpcapi/message.go index 81695643c..f76e8434c 100644 --- a/httprouter/jsonrpcapi/message.go +++ b/httprouter/jsonrpcapi/message.go @@ -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 } @@ -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