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
7cd41ac4
Commit
7cd41ac4
authored
Jan 02, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wip VM. Created contracts
parent
9df4c745
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
18 deletions
+80
-18
block.go
block.go
+25
-1
block_manager.go
block_manager.go
+4
-6
contract.go
contract.go
+40
-0
transaction.go
transaction.go
+6
-5
trie.go
trie.go
+1
-1
vm_test.go
vm_test.go
+4
-5
No files found.
block.go
View file @
7cd41ac4
...
...
@@ -4,6 +4,7 @@ import (
_
"fmt"
"time"
_
"bytes"
_
"encoding/hex"
)
type
Block
struct
{
...
...
@@ -63,13 +64,36 @@ func CreateBlock(root string, num int, prevHash string, base string, difficulty
extra
:
extra
,
}
block
.
state
=
NewTrie
(
Db
,
root
)
for
_
,
tx
:=
range
txes
{
block
.
state
.
Update
(
tx
.
recipient
,
string
(
tx
.
MarshalRlp
()))
// Create contract if there's no recipient
if
tx
.
recipient
==
""
{
addr
:=
tx
.
Hash
()
contract
:=
NewContract
(
tx
.
value
,
[]
byte
(
""
))
block
.
state
.
Update
(
string
(
addr
),
string
(
contract
.
MarshalRlp
()))
for
i
,
val
:=
range
tx
.
data
{
contract
.
state
.
Update
(
string
(
Encode
(
i
)),
val
)
}
block
.
UpdateContract
(
addr
,
contract
)
}
}
return
block
}
func
(
block
*
Block
)
GetContract
(
addr
[]
byte
)
*
Contract
{
data
:=
block
.
state
.
Get
(
string
(
addr
))
contract
:=
&
Contract
{}
contract
.
UnmarshalRlp
([]
byte
(
data
))
return
contract
}
func
(
block
*
Block
)
UpdateContract
(
addr
[]
byte
,
contract
*
Contract
)
{
block
.
state
.
Update
(
string
(
addr
),
string
(
contract
.
MarshalRlp
()))
}
func
(
block
*
Block
)
Update
()
{
}
...
...
block_manager.go
View file @
7cd41ac4
...
...
@@ -45,13 +45,11 @@ func (bm *BlockManager) ProcessBlock(block *Block) error {
}
func
(
bm
*
BlockManager
)
ProcessTransaction
(
tx
*
Transaction
,
block
*
Block
,
lockChan
chan
bool
)
{
if
tx
.
recipient
==
"
\x00
"
{
bm
.
vm
.
RunTransaction
(
tx
,
block
,
func
(
opType
OpType
)
bool
{
// TODO calculate fees
bm
.
vm
.
RunTransaction
(
tx
,
block
,
func
(
opType
OpType
)
bool
{
// TODO calculate fees
return
true
// Continue
})
}
return
true
// Continue
})
// Broadcast we're done
lockChan
<-
true
...
...
contract.go
0 → 100644
View file @
7cd41ac4
package
main
import
(
)
type
Contract
struct
{
active
int
amount
uint32
// ???
state
*
Trie
}
func
NewContract
(
amount
uint32
,
root
[]
byte
)
*
Contract
{
contract
:=
&
Contract
{
active
:
1
,
amount
:
amount
}
contract
.
state
=
NewTrie
(
Db
,
string
(
root
))
return
contract
}
func
(
c
*
Contract
)
MarshalRlp
()
[]
byte
{
// Prepare the transaction for serialization
preEnc
:=
[]
interface
{}{
uint32
(
c
.
active
),
c
.
amount
,
c
.
state
.
root
}
return
Encode
(
preEnc
)
}
func
(
c
*
Contract
)
UnmarshalRlp
(
data
[]
byte
)
{
t
,
_
:=
Decode
(
data
,
0
)
if
slice
,
ok
:=
t
.
([]
interface
{});
ok
{
if
active
,
ok
:=
slice
[
0
]
.
(
uint8
);
ok
{
c
.
active
=
int
(
active
)
}
if
amount
,
ok
:=
slice
[
1
]
.
(
uint8
);
ok
{
c
.
amount
=
uint32
(
amount
)
}
if
root
,
ok
:=
slice
[
2
]
.
([]
uint8
);
ok
{
c
.
state
=
NewTrie
(
Db
,
string
(
root
))
}
}
}
transaction.go
View file @
7cd41ac4
...
...
@@ -3,8 +3,8 @@ package main
import
(
"math/big"
"fmt"
"encoding/hex"
"crypto/sha256"
_
"encoding/hex"
_
"crypto/sha256"
_
"bytes"
)
...
...
@@ -63,13 +63,14 @@ func NewTransaction(to string, value uint32, data []string) *Transaction {
tx
.
data
[
i
]
=
instr
}
b
:=
[]
byte
(
tx
.
MarshalRlp
())
hash
:=
sha256
.
Sum256
(
b
)
tx
.
addr
=
hex
.
EncodeToString
(
hash
[
0
:
19
])
return
&
tx
}
func
(
tx
*
Transaction
)
Hash
()
[]
byte
{
return
Sha256Bin
(
tx
.
MarshalRlp
())
}
func
(
tx
*
Transaction
)
MarshalRlp
()
[]
byte
{
// Prepare the transaction for serialization
preEnc
:=
[]
interface
{}{
...
...
trie.go
View file @
7cd41ac4
...
...
@@ -48,7 +48,7 @@ type Trie struct {
}
func
NewTrie
(
db
Database
,
root
string
)
*
Trie
{
return
&
Trie
{
db
:
db
,
root
:
""
}
return
&
Trie
{
db
:
db
,
root
:
root
}
}
/*
...
...
vm_test.go
View file @
7cd41ac4
...
...
@@ -3,7 +3,6 @@ package main
import
(
"fmt"
"testing"
_
"encoding/hex"
)
...
...
@@ -11,7 +10,7 @@ func TestVm(t *testing.T) {
db
,
_
:=
NewMemDatabase
()
Db
=
db
tx
:=
NewTransaction
(
"
\x00
"
,
20
,
[]
string
{
tx
:=
NewTransaction
(
""
,
20
,
[]
string
{
"PSH 10"
,
})
...
...
@@ -20,8 +19,8 @@ func TestVm(t *testing.T) {
bm
:=
NewBlockManager
()
bm
.
ProcessBlock
(
block
)
tx1
:=
&
Transaction
{}
tx1
.
UnmarshalRlp
([]
byte
(
block
.
state
.
Get
(
tx
.
recipient
))
)
fmt
.
Println
(
tx1
)
contract
:=
block
.
GetContract
(
tx
.
Hash
())
fmt
.
Println
(
contract
)
fmt
.
Println
(
"it is"
,
contract
.
state
.
Get
(
string
(
Encode
(
0
)))
)
}
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