-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
107 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/tendermint/tendermint/crypto/tmhash" | ||
tmtime "github.com/tendermint/tendermint/types/time" | ||
) | ||
|
||
// ValidateTime does a basic time validation ensuring time does not drift too | ||
// much: +/- one year. | ||
func ValidateTime(t time.Time) error { | ||
var ( | ||
now = tmtime.Now() | ||
oneYear = 8766 * time.Hour | ||
) | ||
if t.Before(now.Add(-oneYear)) || t.After(now.Add(oneYear)) { | ||
return fmt.Errorf("Time drifted too much. Expected: -1 < %v < 1 year", now) | ||
} | ||
return nil | ||
} | ||
|
||
// ValidateHash returns an error if the hash is not empty, but its | ||
// size != tmhash.Size. | ||
func ValidateHash(h []byte) error { | ||
if len(h) > 0 && len(h) != tmhash.Size { | ||
return fmt.Errorf("Expected size to be %d bytes, got %d bytes", | ||
tmhash.Size, | ||
len(h), | ||
) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters