From b72d7b04bba7ce3a3117b61b15cad3c40e19f1c0 Mon Sep 17 00:00:00 2001
From: Ting-Wei Lan <tingwei.lan@cobinhood.com>
Date: Tue, 26 Mar 2019 15:31:56 +0800
Subject: core: vm: sqlvm: use common.HashLength instead of 32

Keep them consisitent with ast/types.go.
---
 core/vm/sqlvm/common/storage.go      | 10 +++++-----
 core/vm/sqlvm/common/storage_test.go |  6 +++---
 core/vm/sqlvm/schema/schema.go       |  3 ++-
 3 files changed, 10 insertions(+), 9 deletions(-)

(limited to 'core')

diff --git a/core/vm/sqlvm/common/storage.go b/core/vm/sqlvm/common/storage.go
index 4595a773b..674efbf17 100644
--- a/core/vm/sqlvm/common/storage.go
+++ b/core/vm/sqlvm/common/storage.go
@@ -78,15 +78,15 @@ func getDByteSize(data common.Hash) uint64 {
 func (s Storage) DecodeDByteBySlot(address common.Address, slot common.Hash) []byte {
 	data := s.GetState(address, slot)
 	length := getDByteSize(data)
-	if length < 32 {
+	if length < common.HashLength {
 		return data[:length]
 	}
 	ptr := crypto.Keccak256Hash(slot.Bytes())
-	slotNum := (length-1)/32 + 1
-	rVal := make([]byte, slotNum*32)
+	slotNum := (length-1)/common.HashLength + 1
+	rVal := make([]byte, slotNum*common.HashLength)
 	for i := uint64(0); i < slotNum; i++ {
-		start := i * 32
-		copy(rVal[start:start+32], s.GetState(address, ptr).Bytes())
+		start := i * common.HashLength
+		copy(rVal[start:start+common.HashLength], s.GetState(address, ptr).Bytes())
 		ptr = s.ShiftHashUint64(ptr, 1)
 	}
 	return rVal[:length]
diff --git a/core/vm/sqlvm/common/storage_test.go b/core/vm/sqlvm/common/storage_test.go
index 42b8c2298..3a7633496 100644
--- a/core/vm/sqlvm/common/storage_test.go
+++ b/core/vm/sqlvm/common/storage_test.go
@@ -84,11 +84,11 @@ func SetDataToStateDB(head common.Hash, storage Storage, addr common.Address,
 		b := t.slotData.Bytes()
 		if b[len(b)-1]&0x1 != 0 {
 			length := len(t.result)
-			slotNum := (length-1)/32 + 1
+			slotNum := (length-1)/common.HashLength + 1
 			ptr := crypto.Keccak256Hash(slot.Bytes())
 			for s := 0; s < slotNum; s++ {
-				start := s * 32
-				end := (s + 1) * 32
+				start := s * common.HashLength
+				end := (s + 1) * common.HashLength
 				if end > len(t.result) {
 					end = len(t.result)
 				}
diff --git a/core/vm/sqlvm/schema/schema.go b/core/vm/sqlvm/schema/schema.go
index f2a46631d..d77cd3855 100644
--- a/core/vm/sqlvm/schema/schema.go
+++ b/core/vm/sqlvm/schema/schema.go
@@ -6,6 +6,7 @@ import (
 
 	"github.com/shopspring/decimal"
 
+	"github.com/dexon-foundation/dexon/common"
 	"github.com/dexon-foundation/dexon/core/vm/sqlvm/ast"
 	se "github.com/dexon-foundation/dexon/core/vm/sqlvm/errors"
 	"github.com/dexon-foundation/dexon/rlp"
@@ -136,7 +137,7 @@ func (t *Table) SetupColumnOffset() {
 	byteOffset := uint8(0)
 	for i, col := range t.Columns {
 		size := col.Type.Size()
-		if size+byteOffset > 32 {
+		if size+byteOffset > common.HashLength {
 			slotOffset++
 			byteOffset = 0
 		}
-- 
cgit v1.2.3