forked from TrueCloudLab/frostfs-contract
[#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:
parent
a92ad8b8f0
commit
69b308e792
3 changed files with 12 additions and 12 deletions
|
@ -34,7 +34,7 @@ const (
|
||||||
processingContractKey = "processingScriptHash"
|
processingContractKey = "processingScriptHash"
|
||||||
|
|
||||||
maxBalanceAmount = 9000 // Max integer of Fixed12 in JSON bound (2**53-1)
|
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
|
// hardcoded value to ignore deposit notification in onReceive
|
||||||
ignoreDepositNotification = "\x57\x0b"
|
ignoreDepositNotification = "\x57\x0b"
|
||||||
|
@ -241,7 +241,7 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
||||||
|
|
||||||
if amount <= 0 {
|
if amount <= 0 {
|
||||||
common.AbortWithMessage("amount must be positive")
|
common.AbortWithMessage("amount must be positive")
|
||||||
} else if maxBalanceAmountGAS < amount {
|
} else if maxBalanceAmountGAS < int64(amount) {
|
||||||
common.AbortWithMessage("out of max amount limit")
|
common.AbortWithMessage("out of max amount limit")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,13 @@ import (
|
||||||
type NameState struct {
|
type NameState struct {
|
||||||
Owner interop.Hash160
|
Owner interop.Hash160
|
||||||
Name string
|
Name string
|
||||||
Expiration int
|
Expiration int64
|
||||||
Admin interop.Hash160
|
Admin interop.Hash160
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensureNotExpired panics if domain name is expired.
|
// ensureNotExpired panics if domain name is expired.
|
||||||
func (n NameState) ensureNotExpired() {
|
func (n NameState) ensureNotExpired() {
|
||||||
if runtime.GetTime() >= n.Expiration {
|
if int64(runtime.GetTime()) >= n.Expiration {
|
||||||
panic("name has expired")
|
panic("name has expired")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ const (
|
||||||
// Values constraints.
|
// Values constraints.
|
||||||
const (
|
const (
|
||||||
// maxRegisterPrice is the maximum price of register method.
|
// 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 is the maximum domain root length.
|
||||||
maxRootLength = 16
|
maxRootLength = 16
|
||||||
// maxDomainNameFragmentLength is the maximum length of the domain name fragment.
|
// 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 is the default price for new domain registration.
|
||||||
defaultRegisterPrice = 10_0000_0000
|
defaultRegisterPrice = 10_0000_0000
|
||||||
// millisecondsInYear is amount of milliseconds per year.
|
// 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.
|
// RecordState is a type that registered entities are saved to.
|
||||||
|
@ -203,7 +203,7 @@ func Roots() iterator.Iterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPrice sets the domain registration price.
|
// SetPrice sets the domain registration price.
|
||||||
func SetPrice(price int) {
|
func SetPrice(price int64) {
|
||||||
checkCommittee()
|
checkCommittee()
|
||||||
if price < 0 || price > maxRegisterPrice {
|
if price < 0 || price > maxRegisterPrice {
|
||||||
panic("The price is out of range.")
|
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.
|
// parentExpired returns true if any domain from fragments doesn't exist or is expired.
|
||||||
// first denotes the deepest subdomain to check.
|
// first denotes the deepest subdomain to check.
|
||||||
func parentExpired(ctx storage.Context, first int, fragments []string) bool {
|
func parentExpired(ctx storage.Context, first int, fragments []string) bool {
|
||||||
now := runtime.GetTime()
|
now := int64(runtime.GetTime())
|
||||||
last := len(fragments) - 1
|
last := len(fragments) - 1
|
||||||
name := fragments[last]
|
name := fragments[last]
|
||||||
for i := last; i >= first; i-- {
|
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...))
|
nsBytes := storage.Get(ctx, append([]byte{prefixName}, tokenKey...))
|
||||||
if nsBytes != nil {
|
if nsBytes != nil {
|
||||||
ns := std.Deserialize(nsBytes.([]byte)).(NameState)
|
ns := std.Deserialize(nsBytes.([]byte)).(NameState)
|
||||||
if runtime.GetTime() < ns.Expiration {
|
if int64(runtime.GetTime()) < ns.Expiration {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
oldOwner = ns.Owner
|
oldOwner = ns.Owner
|
||||||
|
@ -321,7 +321,7 @@ func Register(name string, owner interop.Hash160, email string, refresh, retry,
|
||||||
ns := NameState{
|
ns := NameState{
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
Name: name,
|
Name: name,
|
||||||
Expiration: runtime.GetTime() + millisecondsInYear,
|
Expiration: int64(runtime.GetTime()) + millisecondsInYear,
|
||||||
}
|
}
|
||||||
putNameStateWithKey(ctx, tokenKey, ns)
|
putNameStateWithKey(ctx, tokenKey, ns)
|
||||||
putSoaRecord(ctx, name, email, refresh, retry, expire, ttl)
|
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.
|
// Renew increases domain expiration date.
|
||||||
func Renew(name string) int {
|
func Renew(name string) int64 {
|
||||||
if len(name) > maxDomainNameLength {
|
if len(name) > maxDomainNameLength {
|
||||||
panic("invalid domain name format")
|
panic("invalid domain name format")
|
||||||
}
|
}
|
||||||
|
@ -859,7 +859,7 @@ func tokenIDFromName(name string) string {
|
||||||
nsBytes := storage.Get(ctx, nameKey)
|
nsBytes := storage.Get(ctx, nameKey)
|
||||||
if nsBytes != nil {
|
if nsBytes != nil {
|
||||||
ns := std.Deserialize(nsBytes.([]byte)).(NameState)
|
ns := std.Deserialize(nsBytes.([]byte)).(NameState)
|
||||||
if runtime.GetTime() < ns.Expiration {
|
if int64(runtime.GetTime()) < ns.Expiration {
|
||||||
return name[sum:]
|
return name[sum:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue