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
338b6980
Commit
338b6980
authored
Apr 27, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring and added documentation comments
parent
16e52327
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
62 deletions
+68
-62
asm.go
ethutil/asm.go
+19
-36
asm_test.go
ethutil/asm_test.go
+0
-0
big.go
ethutil/big.go
+21
-10
bytes.go
ethutil/bytes.go
+12
-1
common.go
ethutil/common.go
+9
-3
config.go
ethutil/config.go
+7
-2
rlp.go
ethutil/rlp.go
+0
-10
No files found.
ethutil/
parsing
.go
→
ethutil/
asm
.go
View file @
338b6980
...
...
@@ -79,6 +79,10 @@ var OpCodes = map[string]byte{
"SUICIDE"
:
0x7f
,
}
// Is op code
//
// Check whether the given string matches anything in
// the OpCode list
func
IsOpCode
(
s
string
)
bool
{
for
key
,
_
:=
range
OpCodes
{
if
key
==
s
{
...
...
@@ -88,6 +92,10 @@ func IsOpCode(s string) bool {
return
false
}
// Compile instruction
//
// Attempts to compile and parse the given instruction in "s"
// and returns the byte sequence
func
CompileInstr
(
s
interface
{})
([]
byte
,
error
)
{
switch
s
.
(
type
)
{
case
string
:
...
...
@@ -119,8 +127,9 @@ func CompileInstr(s interface{}) ([]byte, error) {
return
nil
,
nil
}
// Script compilation functions
// Compiles strings to machine code
// Assemble
//
// Assembles the given instructions and returns EVM byte code
func
Assemble
(
instructions
...
interface
{})
(
script
[]
byte
)
{
//script = make([]string, len(instructions))
...
...
@@ -134,38 +143,22 @@ func Assemble(instructions ...interface{}) (script []byte) {
return
}
/*
Prepocessing function that takes init and main apart:
init() {
// something
}
main() {
// main something
}
// Pre process script
//
// Take data apart and attempt to find the "init" section and
// "main" section. `main { } init { }`
func
PreProcess
(
data
string
)
(
mainInput
,
initInput
string
)
{
reg := "\\(\\)\\s*{([\\d\\w\\W\\n\\s]+?)}"
mainReg := regexp.MustCompile("main" + reg)
initReg := regexp.MustCompile("init" + reg)
main := mainReg.FindStringSubmatch(data)
if len(main) > 0 {
mainInput = main[1]
} else {
mainInput
=
getCodeSectionFor
(
"main"
,
data
)
if
mainInput
==
""
{
mainInput
=
data
}
init := initReg.FindStringSubmatch(data)
if len(init) > 0 {
initInput = init[1]
}
initInput
=
getCodeSectionFor
(
"init"
,
data
)
return
}
*/
// Very, very dumb parser. Heed no attention :-)
func
Find
For
(
blockMatcher
,
input
string
)
string
{
func
getCodeSection
For
(
blockMatcher
,
input
string
)
string
{
curCount
:=
-
1
length
:=
len
(
blockMatcher
)
matchfst
:=
rune
(
blockMatcher
[
0
])
...
...
@@ -198,13 +191,3 @@ func FindFor(blockMatcher, input string) string {
return
currStr
}
func
PreProcess
(
data
string
)
(
mainInput
,
initInput
string
)
{
mainInput
=
FindFor
(
"main"
,
data
)
if
mainInput
==
""
{
mainInput
=
data
}
initInput
=
FindFor
(
"init"
,
data
)
return
}
ethutil/
parsing
_test.go
→
ethutil/
asm
_test.go
View file @
338b6980
File moved
ethutil/big.go
View file @
338b6980
...
...
@@ -12,7 +12,9 @@ var BigTrue *big.Int = big.NewInt(1)
// False
var
BigFalse
*
big
.
Int
=
big
.
NewInt
(
0
)
// Returns the power of two integers
// Big pow
//
// Returns the power of two big integers
func
BigPow
(
a
,
b
int
)
*
big
.
Int
{
c
:=
new
(
big
.
Int
)
c
.
Exp
(
big
.
NewInt
(
int64
(
a
)),
big
.
NewInt
(
int64
(
b
)),
big
.
NewInt
(
0
))
...
...
@@ -20,7 +22,9 @@ func BigPow(a, b int) *big.Int {
return
c
}
// Like big.NewInt(uint64); this takes a string instead.
// Big
//
// Shortcut for new(big.Int).SetString(..., 0)
func
Big
(
num
string
)
*
big
.
Int
{
n
:=
new
(
big
.
Int
)
n
.
SetString
(
num
,
0
)
...
...
@@ -28,7 +32,9 @@ func Big(num string) *big.Int {
return
n
}
// Like big.NewInt(uint64); this takes a byte buffer instead.
// BigD
//
// Shortcut for new(big.Int).SetBytes(...)
func
BigD
(
data
[]
byte
)
*
big
.
Int
{
n
:=
new
(
big
.
Int
)
n
.
SetBytes
(
data
)
...
...
@@ -36,21 +42,26 @@ func BigD(data []byte) *big.Int {
return
n
}
// Big to bytes
//
// Returns the bytes of a big integer with the size specified by **base**
// Attempts to pad the byte array with zeros.
func
BigToBytes
(
num
*
big
.
Int
,
base
int
)
[]
byte
{
ret
:=
make
([]
byte
,
base
/
8
)
return
append
(
ret
[
:
len
(
ret
)
-
len
(
num
.
Bytes
())],
num
.
Bytes
()
...
)
}
// Functions like the build in "copy" function
// but works on big integers
func
BigCopy
(
src
*
big
.
Int
)
(
ret
*
big
.
Int
)
{
ret
=
new
(
big
.
Int
)
ret
.
Add
(
ret
,
src
)
return
// Big copy
//
// Creates a copy of the given big integer
func
BigCopy
(
src
*
big
.
Int
)
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Set
(
src
)
}
// Big max
//
// Returns the maximum size big integer
func
BigMax
(
x
,
y
*
big
.
Int
)
*
big
.
Int
{
if
x
.
Cmp
(
y
)
<=
0
{
return
x
...
...
ethutil/bytes.go
View file @
338b6980
...
...
@@ -6,6 +6,9 @@ import (
"fmt"
)
// Number to bytes
//
// Returns the number in bytes with the specified base
func
NumberToBytes
(
num
interface
{},
bits
int
)
[]
byte
{
buf
:=
new
(
bytes
.
Buffer
)
err
:=
binary
.
Write
(
buf
,
binary
.
BigEndian
,
num
)
...
...
@@ -16,6 +19,9 @@ func NumberToBytes(num interface{}, bits int) []byte {
return
buf
.
Bytes
()[
buf
.
Len
()
-
(
bits
/
8
)
:
]
}
// Bytes to number
//
// Attempts to cast a byte slice to a unsigned integer
func
BytesToNumber
(
b
[]
byte
)
uint64
{
var
number
uint64
...
...
@@ -32,7 +38,9 @@ func BytesToNumber(b []byte) uint64 {
return
number
}
// Read variable integer in big endian
// Read variable int
//
// Read a variable length number in big endian byte order
func
ReadVarint
(
reader
*
bytes
.
Reader
)
(
ret
uint64
)
{
if
reader
.
Len
()
==
8
{
var
num
uint64
...
...
@@ -55,6 +63,9 @@ func ReadVarint(reader *bytes.Reader) (ret uint64) {
return
ret
}
// Binary length
//
// Returns the true binary length of the given number
func
BinaryLength
(
num
int
)
int
{
if
num
==
0
{
return
0
...
...
ethutil/common.go
View file @
338b6980
...
...
@@ -5,16 +5,20 @@ import (
"math/big"
)
// The different number of units
var
(
Ether
=
BigPow
(
10
,
18
)
Finney
=
BigPow
(
10
,
15
)
Szabo
=
BigPow
(
10
,
12
)
Vit
o
=
BigPow
(
10
,
9
)
Vit
a
=
BigPow
(
10
,
9
)
Turing
=
BigPow
(
10
,
6
)
Eins
=
BigPow
(
10
,
3
)
Wei
=
big
.
NewInt
(
1
)
)
// Currency to string
//
// Returns a string representing a human readable format
func
CurrencyToString
(
num
*
big
.
Int
)
string
{
switch
{
case
num
.
Cmp
(
Ether
)
>=
0
:
...
...
@@ -23,8 +27,8 @@ func CurrencyToString(num *big.Int) string {
return
fmt
.
Sprintf
(
"%v Finney"
,
new
(
big
.
Int
)
.
Div
(
num
,
Finney
))
case
num
.
Cmp
(
Szabo
)
>=
0
:
return
fmt
.
Sprintf
(
"%v Szabo"
,
new
(
big
.
Int
)
.
Div
(
num
,
Szabo
))
case
num
.
Cmp
(
Vit
o
)
>=
0
:
return
fmt
.
Sprintf
(
"%v Vit
o"
,
new
(
big
.
Int
)
.
Div
(
num
,
Vito
))
case
num
.
Cmp
(
Vit
a
)
>=
0
:
return
fmt
.
Sprintf
(
"%v Vit
a"
,
new
(
big
.
Int
)
.
Div
(
num
,
Vita
))
case
num
.
Cmp
(
Turing
)
>=
0
:
return
fmt
.
Sprintf
(
"%v Turing"
,
new
(
big
.
Int
)
.
Div
(
num
,
Turing
))
case
num
.
Cmp
(
Eins
)
>=
0
:
...
...
@@ -34,6 +38,7 @@ func CurrencyToString(num *big.Int) string {
return
fmt
.
Sprintf
(
"%v Wei"
,
num
)
}
// Common big integers often used
var
(
Big1
=
big
.
NewInt
(
1
)
Big2
=
big
.
NewInt
(
1
)
...
...
@@ -42,6 +47,7 @@ var (
Big256
=
big
.
NewInt
(
0xff
)
)
// Creates an ethereum address given the bytes and the nonce
func
CreateAddress
(
b
[]
byte
,
nonce
*
big
.
Int
)
[]
byte
{
addrBytes
:=
append
(
b
,
nonce
.
Bytes
()
...
)
...
...
ethutil/config.go
View file @
338b6980
...
...
@@ -9,6 +9,7 @@ import (
"runtime"
)
// Log types available
type
LogType
byte
const
(
...
...
@@ -16,7 +17,7 @@ const (
LogTypeFile
=
2
)
// Config struct
isn't exposed
// Config struct
type
config
struct
{
Db
Database
...
...
@@ -31,7 +32,9 @@ type config struct {
var
Config
*
config
// Read config doesn't read anything yet.
// Read config
//
// Initialize the global Config variable with default settings
func
ReadConfig
(
base
string
)
*
config
{
if
Config
==
nil
{
usr
,
_
:=
user
.
Current
()
...
...
@@ -56,6 +59,8 @@ func ReadConfig(base string) *config {
return
Config
}
// Set client string
//
func
(
c
*
config
)
SetClientString
(
str
string
)
{
Config
.
ClientString
=
fmt
.
Sprintf
(
"%s nv%s/%s"
,
str
,
c
.
Ver
,
runtime
.
GOOS
)
}
...
...
ethutil/rlp.go
View file @
338b6980
...
...
@@ -26,16 +26,6 @@ func (coder *RlpEncoder) EncodeData(rlpData interface{}) []byte {
return
Encode
(
rlpData
)
}
/*
func FromBin(data []byte) uint64 {
if len(data) == 0 {
return 0
}
return FromBin(data[:len(data)-1])*256 + uint64(data[len(data)-1])
}
*/
const
(
RlpEmptyList
=
0x80
RlpEmptyStr
=
0x40
...
...
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