aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/sqlvm/parser/parser.go
diff options
context:
space:
mode:
authorTing-Wei Lan <tingwei.lan@cobinhood.com>2019-02-20 16:32:14 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:04 +0800
commit124183ce94ef9941a077ff7e2a84738dfd7f8dcb (patch)
treedadac101dbc8833c2562c169276751906fa7abb6 /core/vm/sqlvm/parser/parser.go
parentb414e5491c58bab824d0a6bb9fd94e17b2a9659a (diff)
downloaddexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.tar
dexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.tar.gz
dexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.tar.bz2
dexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.tar.lz
dexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.tar.xz
dexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.tar.zst
dexon-124183ce94ef9941a077ff7e2a84738dfd7f8dcb.zip
core: vm: sqlvm: check if a number is a valid address
This commit implements isAddress function to allow a number literal to be considered as an address literal. Since Solidity only allows '0x' to be written in lower case, we remove the handling of upper case '0X' to keep the behavior in sync with Solidity. In addition to isAddress implementation, this commit also removes 'String' methods from AST nodes to prevent them from implementing the builtin 'Stringer' interface. Therefore, our AST printer is now able to print struct fields of value nodes instead of only one string.
Diffstat (limited to 'core/vm/sqlvm/parser/parser.go')
-rw-r--r--core/vm/sqlvm/parser/parser.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/core/vm/sqlvm/parser/parser.go b/core/vm/sqlvm/parser/parser.go
index 5cfe9400e..fdde37dd5 100644
--- a/core/vm/sqlvm/parser/parser.go
+++ b/core/vm/sqlvm/parser/parser.go
@@ -8,6 +8,7 @@ import (
"strings"
"unicode/utf8"
+ "github.com/dexon-foundation/dexon/common"
"github.com/dexon-foundation/dexon/core/vm/sqlvm/ast"
"github.com/dexon-foundation/dexon/core/vm/sqlvm/errors"
"github.com/shopspring/decimal"
@@ -52,16 +53,20 @@ func assertExprSlice(x interface{}) []ast.ExprNode {
return es
}
-// TODO(wmin0): finish it.
func isAddress(h []byte) bool {
- return false
+ ma, err := common.NewMixedcaseAddressFromString(string(h))
+ if err != nil {
+ return false
+ }
+ return ma.ValidChecksum()
}
func hexToInteger(h []byte) *ast.IntegerValueNode {
d := decimal.Zero
- l := len(h)
+ x := h[2:]
+ l := len(x)
base := decimal.New(16, 0)
- for idx, b := range h {
+ for idx, b := range x {
i, err := strconv.ParseInt(string([]byte{b}), 16, 32)
if err != nil {
panic(fmt.Sprintf("invalid hex digit %s: %v", []byte{b}, err))