aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJhih-Ming Huang <jm.huang@cobinhood.com>2019-04-03 17:17:21 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:04 +0800
commit9b8e66235752d5334a10023f9e00218904d746e8 (patch)
treef27ce2212802d5fa075dfe76660b2670bb6077a2
parent66a6bea86c7c007562a51d3720a4f7667ce1b64e (diff)
downloaddexon-9b8e66235752d5334a10023f9e00218904d746e8.tar.gz
dexon-9b8e66235752d5334a10023f9e00218904d746e8.tar.zst
dexon-9b8e66235752d5334a10023f9e00218904d746e8.zip
core: vm: sqlvm: ast: decimal decode for bool
-rw-r--r--core/vm/sqlvm/ast/types.go5
-rw-r--r--core/vm/sqlvm/runtime/instructions_test.go13
2 files changed, 17 insertions, 1 deletions
diff --git a/core/vm/sqlvm/ast/types.go b/core/vm/sqlvm/ast/types.go
index 9bb48bc65..5f7f1b886 100644
--- a/core/vm/sqlvm/ast/types.go
+++ b/core/vm/sqlvm/ast/types.go
@@ -385,6 +385,11 @@ func DecimalDecode(dt DataType, b []byte) (decimal.Decimal, error) {
return decimalDecode(true, b), nil
case DataTypeMajorUint:
return decimalDecode(false, b), nil
+ case DataTypeMajorBool:
+ if b[0] == 0 {
+ return dec.False, nil
+ }
+ return dec.True, nil
}
switch {
case major.IsFixedRange():
diff --git a/core/vm/sqlvm/runtime/instructions_test.go b/core/vm/sqlvm/runtime/instructions_test.go
index b679c366f..576a7783a 100644
--- a/core/vm/sqlvm/runtime/instructions_test.go
+++ b/core/vm/sqlvm/runtime/instructions_test.go
@@ -14,6 +14,7 @@ import (
"github.com/dexon-foundation/dexon/core/vm"
"github.com/dexon-foundation/dexon/core/vm/sqlvm/ast"
"github.com/dexon-foundation/dexon/core/vm/sqlvm/common"
+ dec "github.com/dexon-foundation/dexon/core/vm/sqlvm/common/decimal"
"github.com/dexon-foundation/dexon/core/vm/sqlvm/errors"
"github.com/dexon-foundation/dexon/core/vm/sqlvm/schema"
"github.com/dexon-foundation/dexon/crypto"
@@ -101,6 +102,16 @@ func setSlotDataInStateDB(head dexCommon.Hash, addr dexCommon.Address,
},
{
Raw: Raw{
+ Value: dec.False,
+ Bytes: nil,
+ },
+ slotShift: 0,
+ byteShift: 10,
+ major: ast.DataTypeMajorBool,
+ minor: ast.DataTypeMinor(0),
+ },
+ {
+ Raw: Raw{
Bytes: []byte("Hello, world!"),
},
slotShift: 1,
@@ -158,7 +169,7 @@ func setSlotDataInStateDB(head dexCommon.Hash, addr dexCommon.Address,
}
// set dynamic bytes data
- longDBytesLoc := 5
+ longDBytesLoc := 6
longRaw := raws[longDBytesLoc]
hash.SetBytes(longRaw.Bytes)
ptr = storage.ShiftHashUint64(head, uint64(longRaw.slotShift))