Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
cf7cef42
Commit
cf7cef42
authored
Aug 07, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xeth: added address hex check and length check
parent
698e98d9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
xeth.go
xeth/xeth.go
+11
-0
xeth_test.go
xeth/xeth_test.go
+26
-0
No files found.
xeth/xeth.go
View file @
cf7cef42
...
@@ -20,8 +20,10 @@ package xeth
...
@@ -20,8 +20,10 @@ package xeth
import
(
import
(
"bytes"
"bytes"
"encoding/json"
"encoding/json"
"errors"
"fmt"
"fmt"
"math/big"
"math/big"
"regexp"
"sync"
"sync"
"time"
"time"
...
@@ -45,6 +47,7 @@ var (
...
@@ -45,6 +47,7 @@ var (
defaultGasPrice
=
big
.
NewInt
(
10000000000000
)
//150000000000
defaultGasPrice
=
big
.
NewInt
(
10000000000000
)
//150000000000
defaultGas
=
big
.
NewInt
(
90000
)
//500000
defaultGas
=
big
.
NewInt
(
90000
)
//500000
dappStorePre
=
[]
byte
(
"dapp-"
)
dappStorePre
=
[]
byte
(
"dapp-"
)
addrReg
=
regexp
.
MustCompile
(
`^(0x)?[a-fA-F0-9]{40}$`
)
)
)
// byte will be inferred
// byte will be inferred
...
@@ -878,6 +881,10 @@ func (self *XEth) Sign(fromStr, hashStr string, didUnlock bool) (string, error)
...
@@ -878,6 +881,10 @@ func (self *XEth) Sign(fromStr, hashStr string, didUnlock bool) (string, error)
return
common
.
ToHex
(
sig
),
nil
return
common
.
ToHex
(
sig
),
nil
}
}
func
isAddress
(
addr
string
)
bool
{
return
addrReg
.
MatchString
(
addr
)
}
func
(
self
*
XEth
)
Transact
(
fromStr
,
toStr
,
nonceStr
,
valueStr
,
gasStr
,
gasPriceStr
,
codeStr
string
)
(
string
,
error
)
{
func
(
self
*
XEth
)
Transact
(
fromStr
,
toStr
,
nonceStr
,
valueStr
,
gasStr
,
gasPriceStr
,
codeStr
string
)
(
string
,
error
)
{
// this minimalistic recoding is enough (works for natspec.js)
// this minimalistic recoding is enough (works for natspec.js)
...
@@ -887,6 +894,10 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS
...
@@ -887,6 +894,10 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS
return
""
,
err
return
""
,
err
}
}
if
!
isAddress
(
toStr
)
{
return
""
,
errors
.
New
(
"Invalid address"
)
}
var
(
var
(
from
=
common
.
HexToAddress
(
fromStr
)
from
=
common
.
HexToAddress
(
fromStr
)
to
=
common
.
HexToAddress
(
toStr
)
to
=
common
.
HexToAddress
(
toStr
)
...
...
xeth/xeth_test.go
0 → 100644
View file @
cf7cef42
package
xeth
import
"testing"
func
TestIsAddress
(
t
*
testing
.
T
)
{
for
_
,
invalid
:=
range
[]
string
{
"0x00"
,
"0xNN"
,
"0x00000000000000000000000000000000000000NN"
,
"0xAAar000000000000000000000000000000000000"
,
}
{
if
isAddress
(
invalid
)
{
t
.
Error
(
"Expected"
,
invalid
,
"to be invalid"
)
}
}
for
_
,
valid
:=
range
[]
string
{
"0x0000000000000000000000000000000000000000"
,
"0xAABBbbCCccff9900000000000000000000000000"
,
"AABBbbCCccff9900000000000000000000000000"
,
}
{
if
!
isAddress
(
valid
)
{
t
.
Error
(
"Expected"
,
valid
,
"to be valid"
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment