[#248] *: Fix integer types

When using contracts as a dependency, out-of-range `int` can cause
problems on 32-bit architectures. Contract byte-code hasn't changed.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-07-06 12:22:43 +03:00 committed by fyrchik
parent a92ad8b8f0
commit 69b308e792
3 changed files with 12 additions and 12 deletions

View file

@ -34,7 +34,7 @@ const (
processingContractKey = "processingScriptHash"
maxBalanceAmount = 9000 // Max integer of Fixed12 in JSON bound (2**53-1)
maxBalanceAmountGAS = maxBalanceAmount * 1_0000_0000
maxBalanceAmountGAS = int64(maxBalanceAmount) * 1_0000_0000
// hardcoded value to ignore deposit notification in onReceive
ignoreDepositNotification = "\x57\x0b"
@ -241,7 +241,7 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
if amount <= 0 {
common.AbortWithMessage("amount must be positive")
} else if maxBalanceAmountGAS < amount {
} else if maxBalanceAmountGAS < int64(amount) {
common.AbortWithMessage("out of max amount limit")
}

View file

@ -9,13 +9,13 @@ import (
type NameState struct {
Owner interop.Hash160
Name string
Expiration int
Expiration int64
Admin interop.Hash160
}
// ensureNotExpired panics if domain name is expired.
func (n NameState) ensureNotExpired() {
if runtime.GetTime() >= n.Expiration {
if int64(runtime.GetTime()) >= n.Expiration {
panic("name has expired")
}
}

View file

@ -46,7 +46,7 @@ const (
// Values constraints.
const (
// maxRegisterPrice is the maximum price of register method.
maxRegisterPrice = 1_0000_0000_0000
maxRegisterPrice = int64(1_0000_0000_0000)
// maxRootLength is the maximum domain root length.
maxRootLength = 16
// maxDomainNameFragmentLength is the maximum length of the domain name fragment.
@ -64,7 +64,7 @@ const (
// defaultRegisterPrice is the default price for new domain registration.
defaultRegisterPrice = 10_0000_0000
// millisecondsInYear is amount of milliseconds per year.
millisecondsInYear = 365 * 24 * 3600 * 1000
millisecondsInYear = int64(365 * 24 * 3600 * 1000)
)
// RecordState is a type that registered entities are saved to.
@ -203,7 +203,7 @@ func Roots() iterator.Iterator {
}
// SetPrice sets the domain registration price.
func SetPrice(price int) {
func SetPrice(price int64) {
checkCommittee()
if price < 0 || price > maxRegisterPrice {
panic("The price is out of range.")
@ -238,7 +238,7 @@ func IsAvailable(name string) bool {
// parentExpired returns true if any domain from fragments doesn't exist or is expired.
// first denotes the deepest subdomain to check.
func parentExpired(ctx storage.Context, first int, fragments []string) bool {
now := runtime.GetTime()
now := int64(runtime.GetTime())
last := len(fragments) - 1
name := fragments[last]
for i := last; i >= first; i-- {
@ -310,7 +310,7 @@ func Register(name string, owner interop.Hash160, email string, refresh, retry,
nsBytes := storage.Get(ctx, append([]byte{prefixName}, tokenKey...))
if nsBytes != nil {
ns := std.Deserialize(nsBytes.([]byte)).(NameState)
if runtime.GetTime() < ns.Expiration {
if int64(runtime.GetTime()) < ns.Expiration {
return false
}
oldOwner = ns.Owner
@ -321,7 +321,7 @@ func Register(name string, owner interop.Hash160, email string, refresh, retry,
ns := NameState{
Owner: owner,
Name: name,
Expiration: runtime.GetTime() + millisecondsInYear,
Expiration: int64(runtime.GetTime()) + millisecondsInYear,
}
putNameStateWithKey(ctx, tokenKey, ns)
putSoaRecord(ctx, name, email, refresh, retry, expire, ttl)
@ -331,7 +331,7 @@ func Register(name string, owner interop.Hash160, email string, refresh, retry,
}
// Renew increases domain expiration date.
func Renew(name string) int {
func Renew(name string) int64 {
if len(name) > maxDomainNameLength {
panic("invalid domain name format")
}
@ -859,7 +859,7 @@ func tokenIDFromName(name string) string {
nsBytes := storage.Get(ctx, nameKey)
if nsBytes != nil {
ns := std.Deserialize(nsBytes.([]byte)).(NameState)
if runtime.GetTime() < ns.Expiration {
if int64(runtime.GetTime()) < ns.Expiration {
return name[sum:]
}
}