good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
cf7cef42
Commit
cf7cef42
authored
Aug 7, 2015
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
xeth: added address hex check and length check
parent
698e98d9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
xeth/xeth.go
+11
-0
11 additions, 0 deletions
xeth/xeth.go
xeth/xeth_test.go
+26
-0
26 additions, 0 deletions
xeth/xeth_test.go
with
37 additions
and
0 deletions
xeth/xeth.go
+
11
−
0
View file @
cf7cef42
...
...
@@ -20,8 +20,10 @@ package xeth
import
(
"bytes"
"encoding/json"
"errors"
"fmt"
"math/big"
"regexp"
"sync"
"time"
...
...
@@ -45,6 +47,7 @@ var (
defaultGasPrice
=
big
.
NewInt
(
10000000000000
)
//150000000000
defaultGas
=
big
.
NewInt
(
90000
)
//500000
dappStorePre
=
[]
byte
(
"dapp-"
)
addrReg
=
regexp
.
MustCompile
(
`^(0x)?[a-fA-F0-9]{40}$`
)
)
// byte will be inferred
...
...
@@ -878,6 +881,10 @@ func (self *XEth) Sign(fromStr, hashStr string, didUnlock bool) (string, error)
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
)
{
// this minimalistic recoding is enough (works for natspec.js)
...
...
@@ -887,6 +894,10 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS
return
""
,
err
}
if
!
isAddress
(
toStr
)
{
return
""
,
errors
.
New
(
"Invalid address"
)
}
var
(
from
=
common
.
HexToAddress
(
fromStr
)
to
=
common
.
HexToAddress
(
toStr
)
...
...
This diff is collapsed.
Click to expand it.
xeth/xeth_test.go
0 → 100644
+
26
−
0
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"
)
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment