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
8e7c4f91
Commit
8e7c4f91
authored
Jul 29, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ops
parent
41bd3814
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
2 deletions
+73
-2
value.go
ethutil/value.go
+58
-2
value_test.go
ethutil/value_test.go
+15
-0
No files found.
ethutil/value.go
View file @
8e7c4f91
package
ethutil
package
ethutil
import
(
import
(
"bytes"
"fmt"
"fmt"
"math/big"
"math/big"
"reflect"
"reflect"
...
@@ -67,7 +66,8 @@ func (val *Value) Uint() uint64 {
...
@@ -67,7 +66,8 @@ func (val *Value) Uint() uint64 {
}
else
if
Val
,
ok
:=
val
.
Val
.
(
uint
);
ok
{
}
else
if
Val
,
ok
:=
val
.
Val
.
(
uint
);
ok
{
return
uint64
(
Val
)
return
uint64
(
Val
)
}
else
if
Val
,
ok
:=
val
.
Val
.
([]
byte
);
ok
{
}
else
if
Val
,
ok
:=
val
.
Val
.
([]
byte
);
ok
{
return
ReadVarint
(
bytes
.
NewReader
(
Val
))
return
new
(
big
.
Int
)
.
SetBytes
(
Val
)
.
Uint64
()
//return ReadVarint(bytes.NewReader(Val))
}
else
if
Val
,
ok
:=
val
.
Val
.
(
*
big
.
Int
);
ok
{
}
else
if
Val
,
ok
:=
val
.
Val
.
(
*
big
.
Int
);
ok
{
return
Val
.
Uint64
()
return
Val
.
Uint64
()
}
}
...
@@ -207,6 +207,13 @@ func (val *Value) Cmp(o *Value) bool {
...
@@ -207,6 +207,13 @@ func (val *Value) Cmp(o *Value) bool {
return
reflect
.
DeepEqual
(
val
.
Val
,
o
.
Val
)
return
reflect
.
DeepEqual
(
val
.
Val
,
o
.
Val
)
}
}
func
(
self
*
Value
)
DeepCmp
(
o
*
Value
)
bool
{
a
:=
NewValue
(
self
.
BigInt
())
b
:=
NewValue
(
o
.
BigInt
())
return
a
.
Cmp
(
b
)
}
func
(
val
*
Value
)
Encode
()
[]
byte
{
func
(
val
*
Value
)
Encode
()
[]
byte
{
return
Encode
(
val
.
Val
)
return
Encode
(
val
.
Val
)
}
}
...
@@ -262,6 +269,55 @@ func (val *Value) Append(v interface{}) *Value {
...
@@ -262,6 +269,55 @@ func (val *Value) Append(v interface{}) *Value {
return
val
return
val
}
}
const
(
valOpAdd
=
iota
valOpDiv
valOpMul
valOpPow
valOpSub
)
// Math stuff
func
(
self
*
Value
)
doOp
(
op
int
,
other
interface
{})
*
Value
{
left
:=
self
.
BigInt
()
right
:=
NewValue
(
other
)
.
BigInt
()
switch
op
{
case
valOpAdd
:
self
.
Val
=
left
.
Add
(
left
,
right
)
case
valOpDiv
:
self
.
Val
=
left
.
Div
(
left
,
right
)
case
valOpMul
:
self
.
Val
=
left
.
Mul
(
left
,
right
)
case
valOpPow
:
self
.
Val
=
left
.
Exp
(
left
,
right
,
Big0
)
case
valOpSub
:
self
.
Val
=
left
.
Sub
(
left
,
right
)
}
return
self
}
func
(
self
*
Value
)
Add
(
other
interface
{})
*
Value
{
return
self
.
doOp
(
valOpAdd
,
other
)
}
func
(
self
*
Value
)
Sub
(
other
interface
{})
*
Value
{
return
self
.
doOp
(
valOpSub
,
other
)
}
func
(
self
*
Value
)
Div
(
other
interface
{})
*
Value
{
return
self
.
doOp
(
valOpDiv
,
other
)
}
func
(
self
*
Value
)
Mul
(
other
interface
{})
*
Value
{
return
self
.
doOp
(
valOpMul
,
other
)
}
func
(
self
*
Value
)
Pow
(
other
interface
{})
*
Value
{
return
self
.
doOp
(
valOpPow
,
other
)
}
type
ValueIterator
struct
{
type
ValueIterator
struct
{
value
*
Value
value
*
Value
currentValue
*
Value
currentValue
*
Value
...
...
ethutil/value_test.go
View file @
8e7c4f91
...
@@ -63,3 +63,18 @@ func TestIterator(t *testing.T) {
...
@@ -63,3 +63,18 @@ func TestIterator(t *testing.T) {
i
++
i
++
}
}
}
}
func
TestMath
(
t
*
testing
.
T
)
{
a
:=
NewValue
(
1
)
a
.
Add
(
1
)
.
Add
(
1
)
if
!
a
.
DeepCmp
(
NewValue
(
3
))
{
t
.
Error
(
"Expected 3, got"
,
a
)
}
a
=
NewValue
(
2
)
a
.
Sub
(
1
)
.
Sub
(
1
)
if
!
a
.
DeepCmp
(
NewValue
(
0
))
{
t
.
Error
(
"Expected 0, got"
,
a
)
}
}
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