* feat: update rosetta sdk to v0.6.10 embed from v1.0.0 release branch of the library: https://github.com/tendermint/cosmos-rosetta-gateway/tree/release/v1.0.0 closes: https://github.com/cosmos/cosmos-sdk/issues/9300 Co-authored-by: Alessio Treglia <alessio@tendermint.com>
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package rosetta
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
crgerrs "github.com/cosmos/cosmos-sdk/server/rosetta/lib/errors"
|
|
)
|
|
|
|
// timeToMilliseconds converts time to milliseconds timestamp
|
|
func timeToMilliseconds(t time.Time) int64 {
|
|
return t.UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond))
|
|
}
|
|
|
|
// unmarshalMetadata unmarshals the given meta to the target
|
|
func unmarshalMetadata(meta map[string]interface{}, target interface{}) error {
|
|
b, err := json.Marshal(meta)
|
|
if err != nil {
|
|
return crgerrs.WrapError(crgerrs.ErrCodec, err.Error())
|
|
}
|
|
|
|
err = json.Unmarshal(b, target)
|
|
if err != nil {
|
|
return crgerrs.WrapError(crgerrs.ErrCodec, err.Error())
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// marshalMetadata marshals the given interface to map[string]interface{}
|
|
func marshalMetadata(o interface{}) (meta map[string]interface{}, err error) {
|
|
b, err := json.Marshal(o)
|
|
if err != nil {
|
|
return nil, crgerrs.WrapError(crgerrs.ErrCodec, err.Error())
|
|
}
|
|
meta = make(map[string]interface{})
|
|
err = json.Unmarshal(b, &meta)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return
|
|
}
|