Skip to content

Commit

Permalink
chore: add convert timestamp to second
Browse files Browse the repository at this point in the history
  • Loading branch information
ThanhNhann committed Jul 12, 2024
1 parent ca84799 commit f3b2eca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/stork.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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\"]}"
19 changes: 18 additions & 1 deletion oracle/feed_stork.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit f3b2eca

Please sign in to comment.