mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-31 04:01:55 +00:00
uint* to int* whereever appropriate; https://www.reddit.com/r/golang/comments/2q5vdu/int_vs_uint/
This commit is contained in:
24
vm/native.go
24
vm/native.go
@@ -11,17 +11,17 @@ import (
|
||||
var nativeContracts = make(map[Word256]NativeContract)
|
||||
|
||||
func init() {
|
||||
nativeContracts[Uint64ToWord256(1)] = ecrecoverFunc
|
||||
nativeContracts[Uint64ToWord256(2)] = sha256Func
|
||||
nativeContracts[Uint64ToWord256(3)] = ripemd160Func
|
||||
nativeContracts[Uint64ToWord256(4)] = identityFunc
|
||||
nativeContracts[Int64ToWord256(1)] = ecrecoverFunc
|
||||
nativeContracts[Int64ToWord256(2)] = sha256Func
|
||||
nativeContracts[Int64ToWord256(3)] = ripemd160Func
|
||||
nativeContracts[Int64ToWord256(4)] = identityFunc
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
type NativeContract func(input []byte, gas *uint64) (output []byte, err error)
|
||||
type NativeContract func(input []byte, gas *int64) (output []byte, err error)
|
||||
|
||||
func ecrecoverFunc(input []byte, gas *uint64) (output []byte, err error) {
|
||||
func ecrecoverFunc(input []byte, gas *int64) (output []byte, err error) {
|
||||
// Deduct gas
|
||||
gasRequired := GasEcRecover
|
||||
if *gas < gasRequired {
|
||||
@@ -42,9 +42,9 @@ func ecrecoverFunc(input []byte, gas *uint64) (output []byte, err error) {
|
||||
return LeftPadBytes(hashed, 32), nil
|
||||
}
|
||||
|
||||
func sha256Func(input []byte, gas *uint64) (output []byte, err error) {
|
||||
func sha256Func(input []byte, gas *int64) (output []byte, err error) {
|
||||
// Deduct gas
|
||||
gasRequired := uint64((len(input)+31)/32)*GasSha256Word + GasSha256Base
|
||||
gasRequired := int64((len(input)+31)/32)*GasSha256Word + GasSha256Base
|
||||
if *gas < gasRequired {
|
||||
return nil, ErrInsufficientGas
|
||||
} else {
|
||||
@@ -59,9 +59,9 @@ func sha256Func(input []byte, gas *uint64) (output []byte, err error) {
|
||||
return hasher.Sum(nil), nil
|
||||
}
|
||||
|
||||
func ripemd160Func(input []byte, gas *uint64) (output []byte, err error) {
|
||||
func ripemd160Func(input []byte, gas *int64) (output []byte, err error) {
|
||||
// Deduct gas
|
||||
gasRequired := uint64((len(input)+31)/32)*GasRipemd160Word + GasRipemd160Base
|
||||
gasRequired := int64((len(input)+31)/32)*GasRipemd160Word + GasRipemd160Base
|
||||
if *gas < gasRequired {
|
||||
return nil, ErrInsufficientGas
|
||||
} else {
|
||||
@@ -76,9 +76,9 @@ func ripemd160Func(input []byte, gas *uint64) (output []byte, err error) {
|
||||
return LeftPadBytes(hasher.Sum(nil), 32), nil
|
||||
}
|
||||
|
||||
func identityFunc(input []byte, gas *uint64) (output []byte, err error) {
|
||||
func identityFunc(input []byte, gas *int64) (output []byte, err error) {
|
||||
// Deduct gas
|
||||
gasRequired := uint64((len(input)+31)/32)*GasIdentityWord + GasIdentityBase
|
||||
gasRequired := int64((len(input)+31)/32)*GasIdentityWord + GasIdentityBase
|
||||
if *gas < gasRequired {
|
||||
return nil, ErrInsufficientGas
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user