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
92b6667b
Commit
92b6667b
authored
Jan 08, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor update
parent
9f42835a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
126 additions
and
44 deletions
+126
-44
ethereum.go
ethereum.go
+25
-2
memory_database.go
memory_database.go
+9
-0
server.go
server.go
+12
-3
testing.go
testing.go
+6
-6
trie.go
trie.go
+12
-10
util.go
util.go
+13
-0
vm.go
vm.go
+49
-23
No files found.
ethereum.go
View file @
92b6667b
...
@@ -5,13 +5,16 @@ import (
...
@@ -5,13 +5,16 @@ import (
"os"
"os"
"os/signal"
"os/signal"
"flag"
"flag"
"runtime"
)
)
const
Debug
=
true
const
Debug
=
true
var
StartDBQueryInterface
bool
var
StartDBQueryInterface
bool
var
StartMining
bool
func
Init
()
{
func
Init
()
{
flag
.
BoolVar
(
&
StartDBQueryInterface
,
"db"
,
false
,
"start db query interface"
)
flag
.
BoolVar
(
&
StartDBQueryInterface
,
"db"
,
false
,
"start db query interface"
)
flag
.
BoolVar
(
&
StartMining
,
"mine"
,
false
,
"start dagger mining"
)
flag
.
Parse
()
flag
.
Parse
()
}
}
...
@@ -24,7 +27,7 @@ func RegisterInterupts(s *Server) {
...
@@ -24,7 +27,7 @@ func RegisterInterupts(s *Server) {
signal
.
Notify
(
c
,
os
.
Interrupt
)
signal
.
Notify
(
c
,
os
.
Interrupt
)
go
func
()
{
go
func
()
{
for
sig
:=
range
c
{
for
sig
:=
range
c
{
fmt
.
Print
ln
(
"Shutting down (%v) ...
\n
"
,
sig
)
fmt
.
Print
f
(
"Shutting down (%v) ...
\n
"
,
sig
)
s
.
Stop
()
s
.
Stop
()
}
}
...
@@ -32,6 +35,8 @@ func RegisterInterupts(s *Server) {
...
@@ -32,6 +35,8 @@ func RegisterInterupts(s *Server) {
}
}
func
main
()
{
func
main
()
{
runtime
.
GOMAXPROCS
(
runtime
.
NumCPU
())
InitFees
()
InitFees
()
Init
()
Init
()
...
@@ -39,7 +44,25 @@ func main() {
...
@@ -39,7 +44,25 @@ func main() {
if
StartDBQueryInterface
{
if
StartDBQueryInterface
{
dbInterface
:=
NewDBInterface
()
dbInterface
:=
NewDBInterface
()
dbInterface
.
Start
()
dbInterface
.
Start
()
}
else
if
StartMining
{
dagger
:=
&
Dagger
{}
seed
:=
dagger
.
Search
(
BigPow
(
2
,
36
))
fmt
.
Println
(
"dagger res = "
,
seed
)
}
else
{
}
else
{
Testing
()
fmt
.
Println
(
"[DBUG]: Starting Ethereum"
)
server
,
err
:=
NewServer
()
if
err
!=
nil
{
fmt
.
Println
(
"error NewServer:"
,
err
)
return
}
RegisterInterupts
(
server
)
server
.
Start
()
// Wait for shutdown
server
.
WaitForShutdown
()
}
}
}
}
memory_database.go
View file @
92b6667b
package
main
package
main
import
(
import
(
"fmt"
)
)
/*
/*
...
@@ -23,3 +24,11 @@ func (db *MemDatabase) Put(key []byte, value []byte) {
...
@@ -23,3 +24,11 @@ func (db *MemDatabase) Put(key []byte, value []byte) {
func
(
db
*
MemDatabase
)
Get
(
key
[]
byte
)
([]
byte
,
error
)
{
func
(
db
*
MemDatabase
)
Get
(
key
[]
byte
)
([]
byte
,
error
)
{
return
db
.
db
[
string
(
key
)],
nil
return
db
.
db
[
string
(
key
)],
nil
}
}
func
(
db
*
MemDatabase
)
Print
()
{
for
key
,
val
:=
range
db
.
db
{
fmt
.
Printf
(
"%x(%d):"
,
key
,
len
(
key
))
decoded
:=
DecodeNode
(
val
)
PrintSlice
(
decoded
)
}
}
server.go
View file @
92b6667b
...
@@ -5,11 +5,15 @@ import (
...
@@ -5,11 +5,15 @@ import (
"time"
"time"
)
)
var
Db
*
LDBDatabase
type
Server
struct
{
type
Server
struct
{
// Channel for shutting down the server
// Channel for shutting down the server
shutdownChan
chan
bool
shutdownChan
chan
bool
// DB interface
// DB interface
db
*
LDBDatabase
db
*
LDBDatabase
// Block manager for processing new blocks and managing the block chain
blockManager
*
BlockManager
// Peers (NYI)
// Peers (NYI)
peers
*
list
.
List
peers
*
list
.
List
}
}
...
@@ -20,8 +24,11 @@ func NewServer() (*Server, error) {
...
@@ -20,8 +24,11 @@ func NewServer() (*Server, error) {
return
nil
,
err
return
nil
,
err
}
}
Db
=
db
server
:=
&
Server
{
server
:=
&
Server
{
shutdownChan
:
make
(
chan
bool
),
shutdownChan
:
make
(
chan
bool
),
blockManager
:
NewBlockManager
(),
db
:
db
,
db
:
db
,
peers
:
list
.
New
(),
peers
:
list
.
New
(),
}
}
...
@@ -32,9 +39,11 @@ func NewServer() (*Server, error) {
...
@@ -32,9 +39,11 @@ func NewServer() (*Server, error) {
// Start the server
// Start the server
func
(
s
*
Server
)
Start
()
{
func
(
s
*
Server
)
Start
()
{
// For now this function just blocks the main thread
// For now this function just blocks the main thread
for
{
go
func
()
{
time
.
Sleep
(
time
.
Second
)
for
{
}
time
.
Sleep
(
time
.
Second
)
}
}()
}
}
func
(
s
*
Server
)
Stop
()
{
func
(
s
*
Server
)
Stop
()
{
...
...
testing.go
View file @
92b6667b
package
main
package
main
/*
import (
import (
"fmt"
_
"fmt"
)
)
// This will eventually go away
// This will eventually go away
...
@@ -15,18 +16,17 @@ func Testing() {
...
@@ -15,18 +16,17 @@ func Testing() {
tx := NewTransaction("\x00", 20, []string{"PUSH"})
tx := NewTransaction("\x00", 20, []string{"PUSH"})
txData := tx.MarshalRlp()
txData := tx.MarshalRlp()
fmt
.
Printf
(
"%q
\n
"
,
txData
)
//
fmt.Printf("%q\n", txData)
copyTx := &Transaction{}
copyTx := &Transaction{}
copyTx.UnmarshalRlp(txData)
copyTx.UnmarshalRlp(txData)
fmt
.
Println
(
tx
)
//
fmt.Println(tx)
fmt
.
Println
(
copyTx
)
//
fmt.Println(copyTx)
tx2 := NewTransaction("\x00", 20, []string{"SET 10 6", "LD 10 10"})
tx2 := NewTransaction("\x00", 20, []string{"SET 10 6", "LD 10 10"})
blck := CreateTestBlock([]*Transaction{tx2, tx})
blck := CreateTestBlock([]*Transaction{tx2, tx})
bm.ProcessBlock( blck )
bm.ProcessBlock( blck )
fmt
.
Println
(
"GenesisBlock:"
,
GenisisBlock
,
"hash"
,
string
(
GenisisBlock
.
Hash
()))
}
}
*/
trie.go
View file @
92b6667b
...
@@ -36,6 +36,8 @@ func DecodeNode(data []byte) []string {
...
@@ -36,6 +36,8 @@ func DecodeNode(data []byte) []string {
}
}
return
strSlice
return
strSlice
}
else
{
fmt
.
Printf
(
"It wasn't a []. It's a %T
\n
"
,
dec
)
}
}
return
nil
return
nil
...
@@ -70,16 +72,6 @@ func (t *Trie) Get(key string) string {
...
@@ -70,16 +72,6 @@ func (t *Trie) Get(key string) string {
* State functions (shouldn't be needed directly).
* State functions (shouldn't be needed directly).
*/
*/
// Wrapper around the regular db "Put" which generates a key and value
func
(
t
*
Trie
)
Put
(
node
interface
{})
[]
byte
{
enc
:=
Encode
(
node
)
sha
:=
Sha256Bin
(
enc
)
t
.
db
.
Put
([]
byte
(
sha
),
enc
)
return
sha
}
// Helper function for printing a node (using fetch, decode and slice printing)
// Helper function for printing a node (using fetch, decode and slice printing)
func
(
t
*
Trie
)
PrintNode
(
n
string
)
{
func
(
t
*
Trie
)
PrintNode
(
n
string
)
{
data
,
_
:=
t
.
db
.
Get
([]
byte
(
n
))
data
,
_
:=
t
.
db
.
Get
([]
byte
(
n
))
...
@@ -133,6 +125,16 @@ func (t *Trie) UpdateState(node string, key []int, value string) string {
...
@@ -133,6 +125,16 @@ func (t *Trie) UpdateState(node string, key []int, value string) string {
return
""
return
""
}
}
// Wrapper around the regular db "Put" which generates a key and value
func
(
t
*
Trie
)
Put
(
node
interface
{})
[]
byte
{
enc
:=
Encode
(
node
)
var
sha
[]
byte
sha
=
Sha256Bin
(
enc
)
t
.
db
.
Put
([]
byte
(
sha
),
enc
)
return
sha
}
func
(
t
*
Trie
)
InsertState
(
node
string
,
key
[]
int
,
value
string
)
string
{
func
(
t
*
Trie
)
InsertState
(
node
string
,
key
[]
int
,
value
string
)
string
{
if
len
(
key
)
==
0
{
if
len
(
key
)
==
0
{
...
...
util.go
View file @
92b6667b
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"encoding/hex"
"encoding/hex"
_
"fmt"
_
"fmt"
_
"math"
_
"math"
"github.com/obscuren/sha3"
)
)
func
Uitoa
(
i
uint32
)
string
{
func
Uitoa
(
i
uint32
)
string
{
...
@@ -24,6 +25,14 @@ func Sha256Bin(data []byte) []byte {
...
@@ -24,6 +25,14 @@ func Sha256Bin(data []byte) []byte {
return
hash
[
:
]
return
hash
[
:
]
}
}
func
Sha3Bin
(
data
[]
byte
)
[]
byte
{
d
:=
sha3
.
NewKeccak224
()
d
.
Reset
()
d
.
Write
(
data
)
return
d
.
Sum
(
nil
)
}
// Helper function for comparing slices
// Helper function for comparing slices
func
CompareIntSlice
(
a
,
b
[]
int
)
bool
{
func
CompareIntSlice
(
a
,
b
[]
int
)
bool
{
if
len
(
a
)
!=
len
(
b
)
{
if
len
(
a
)
!=
len
(
b
)
{
...
@@ -48,3 +57,7 @@ func MatchingNibbleLength(a, b []int) int {
...
@@ -48,3 +57,7 @@ func MatchingNibbleLength(a, b []int) int {
return
i
return
i
}
}
func
Hex
(
d
[]
byte
)
string
{
return
hex
.
EncodeToString
(
d
)
}
vm.go
View file @
92b6667b
...
@@ -11,29 +11,55 @@ import (
...
@@ -11,29 +11,55 @@ import (
// Op codes
// Op codes
const
(
const
(
oSTOP
int
=
0x00
oSTOP
int
=
0x00
oADD
int
=
0x01
oADD
int
=
0x01
oMUL
int
=
0x02
oMUL
int
=
0x02
oSUB
int
=
0x03
oSUB
int
=
0x03
oDIV
int
=
0x04
oDIV
int
=
0x04
oSDIV
int
=
0x05
oSDIV
int
=
0x05
oMOD
int
=
0x06
oMOD
int
=
0x06
oSMOD
int
=
0x07
oSMOD
int
=
0x07
oEXP
int
=
0x08
oEXP
int
=
0x08
oNEG
int
=
0x09
oNEG
int
=
0x09
oLT
int
=
0x0a
oLT
int
=
0x0a
oLE
int
=
0x0b
oLE
int
=
0x0b
oGT
int
=
0x0c
oGT
int
=
0x0c
oGE
int
=
0x0d
oGE
int
=
0x0d
oEQ
int
=
0x0e
oEQ
int
=
0x0e
oNOT
int
=
0x0f
oNOT
int
=
0x0f
oMYADDRESS
int
=
0x10
oMYADDRESS
int
=
0x10
oTXSENDER
int
=
0x11
oTXSENDER
int
=
0x11
oTXVALUE
int
=
0x12
oTXFEE
int
=
0x13
oPUSH
int
=
0x30
oTXDATAN
int
=
0x14
oPOP
int
=
0x31
oTXDATA
int
=
0x15
oLOAD
int
=
0x36
oBLK_PREVHASH
int
=
0x16
oBLK_COINBASE
int
=
0x17
oBLK_TIMESTAMP
int
=
0x18
oBLK_NUMBER
int
=
0x19
oBLK_DIFFICULTY
int
=
0x1a
oSHA256
int
=
0x20
oRIPEMD160
int
=
0x21
oECMUL
int
=
0x22
oECADD
int
=
0x23
oECSIGN
int
=
0x24
oECRECOVER
int
=
0x25
oECVALID
int
=
0x26
oPUSH
int
=
0x30
oPOP
int
=
0x31
oDUP
int
=
0x32
oDUPN
int
=
0x33
oSWAP
int
=
0x34
oSWAPN
int
=
0x35
oLOAD
int
=
0x36
oSTORE
int
=
0x37
oJMP
int
=
0x40
oJMPI
int
=
0x41
oIND
int
=
0x42
oEXTRO
int
=
0x50
oBALANCE
int
=
0x51
oMKTX
int
=
0x60
oSUICIDE
int
=
0xff
)
)
type
OpType
int
type
OpType
int
...
...
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