diff --git a/examples/stork.toml b/examples/stork.toml index 12c63da..5ad65d2 100644 --- a/examples/stork.toml +++ b/examples/stork.toml @@ -3,5 +3,5 @@ ticker = "BTCUSD" pullInterval = "1m" oracleType = "Stork" url = "wss://dev.api.stork-oracle.network/evm/subscribe" -header = "" +header = "injective:dome-van-favorable-continental" message = "{\"type\":\"subscribe\",\"trace_id\":\"123\",\"data\":[\"BTCUSD\"]}" \ No newline at end of file diff --git a/oracle/feed_stork.go b/oracle/feed_stork.go index 5ea1eb0..ec063a7 100644 --- a/oracle/feed_stork.go +++ b/oracle/feed_stork.go @@ -229,12 +229,29 @@ func ConvertSignedPrice(signeds SignedPrice) oracletypes.SignedPriceOfAssetPair signedPriceOfAssetPair.Signature = common.Hex2Bytes(signature) signedPriceOfAssetPair.PublisherKey = signeds.PublisherKey - signedPriceOfAssetPair.Timestamp = signeds.TimestampedSignature.Timestamp + signedPriceOfAssetPair.Timestamp = ConvertTimestampToSecond(signeds.TimestampedSignature.Timestamp) signedPriceOfAssetPair.Price = signeds.Price return signedPriceOfAssetPair } +func ConvertTimestampToSecond(timestamp uint64) uint64 { + switch { + // nanosecond + case timestamp > 1e18: + return timestamp / uint64(1_000_000_000) + // microsecond + case timestamp > 1e15: + return timestamp / uint64(1_000_000) + // millisecond + case timestamp > 1e12: + return timestamp / uint64(1_000) + // second + default: + return timestamp + } +} + // CombineSignatureToString combines a signature to a string func CombineSignatureToString(signature Signature) (result string) { prunedR := strings.TrimPrefix(signature.R, "0x")