Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
8ddd4c4c
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8ddd4c4c
编写于
6月 30, 2014
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip
上级
5a86892e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
59 addition
and
2 deletion
+59
-2
ethchain/state_manager.go
ethchain/state_manager.go
+2
-1
ethchain/state_object.go
ethchain/state_object.go
+4
-1
ethchain/state_transition.go
ethchain/state_transition.go
+45
-0
ethutil/value.go
ethutil/value.go
+8
-0
未找到文件。
ethchain/state_manager.go
浏览文件 @
8ddd4c4c
...
...
@@ -3,6 +3,7 @@ package ethchain
import
(
"bytes"
"container/list"
"fmt"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
...
...
@@ -200,7 +201,7 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
}
if
!
block
.
State
()
.
Cmp
(
state
)
{
statelogger
.
Errorf
(
"Invalid merkle root.
\n
rec: %x
\n
is: %x"
,
block
.
State
()
.
trie
.
Root
,
state
.
trie
.
Root
)
err
=
fmt
.
Errorf
(
"Invalid merkle root.
\n
rec: %x
\n
is: %x"
,
block
.
State
()
.
trie
.
Root
,
state
.
trie
.
Root
)
return
}
...
...
ethchain/state_object.go
浏览文件 @
8ddd4c4c
...
...
@@ -48,7 +48,10 @@ func MakeContract(tx *Transaction, state *State) *StateObject {
}
func
NewStateObject
(
addr
[]
byte
)
*
StateObject
{
return
&
StateObject
{
address
:
addr
,
Amount
:
new
(
big
.
Int
),
gasPool
:
new
(
big
.
Int
)}
object
:=
&
StateObject
{
address
:
addr
,
Amount
:
new
(
big
.
Int
),
gasPool
:
new
(
big
.
Int
)}
object
.
state
=
NewState
(
ethutil
.
NewTrie
(
ethutil
.
Config
.
Db
,
""
))
return
object
}
func
NewContract
(
address
[]
byte
,
Amount
*
big
.
Int
,
root
[]
byte
)
*
StateObject
{
...
...
ethchain/state_transition.go
浏览文件 @
8ddd4c4c
package
ethchain
import
(
"bytes"
"fmt"
"github.com/ethereum/eth-go/ethutil"
"math/big"
)
...
...
@@ -236,6 +238,8 @@ func (self *StateTransition) transferValue(sender, receiver *StateObject) error
return
nil
}
var
testAddr
=
ethutil
.
FromHex
(
"ec4f34c97e43fbb2816cfd95e388353c7181dab1"
)
func
(
self
*
StateTransition
)
Eval
(
script
[]
byte
,
context
*
StateObject
)
(
ret
[]
byte
,
err
error
,
deepErr
bool
)
{
var
(
block
=
self
.
block
...
...
@@ -258,5 +262,46 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
ret
,
_
,
err
=
closure
.
Call
(
vm
,
self
.
data
,
nil
)
deepErr
=
vm
.
err
!=
nil
/*
if bytes.Compare(testAddr, context.Address()) == 0 {
trie := context.state.trie
trie.NewIterator().Each(func(key string, v *ethutil.Value) {
v.Decode()
fmt.Printf("%x : %x\n", key, v.Str())
})
fmt.Println("\n\n")
}
*/
Paranoia
:=
true
if
Paranoia
{
var
(
trie
=
context
.
state
.
trie
trie2
=
ethutil
.
NewTrie
(
ethutil
.
Config
.
Db
,
""
)
)
trie
.
NewIterator
()
.
Each
(
func
(
key
string
,
v
*
ethutil
.
Value
)
{
trie2
.
Update
(
key
,
v
.
Str
())
})
a
:=
ethutil
.
NewValue
(
trie2
.
Root
)
.
Bytes
()
b
:=
ethutil
.
NewValue
(
context
.
state
.
trie
.
Root
)
.
Bytes
()
if
bytes
.
Compare
(
a
,
b
)
!=
0
{
fmt
.
Printf
(
"original: %x
\n
"
,
trie
.
Root
)
trie
.
NewIterator
()
.
Each
(
func
(
key
string
,
v
*
ethutil
.
Value
)
{
v
.
Decode
()
fmt
.
Printf
(
"%x : %x
\n
"
,
key
,
v
.
Str
())
})
fmt
.
Printf
(
"new: %x
\n
"
,
trie2
.
Root
)
trie2
.
NewIterator
()
.
Each
(
func
(
key
string
,
v
*
ethutil
.
Value
)
{
v
.
Decode
()
fmt
.
Printf
(
"%x : %x
\n
"
,
key
,
v
.
Str
())
})
return
nil
,
fmt
.
Errorf
(
"PARANOIA: Different state object roots during copy"
),
false
}
}
return
}
ethutil/value.go
浏览文件 @
8ddd4c4c
...
...
@@ -116,6 +116,8 @@ func (val *Value) Bytes() []byte {
return
a
}
else
if
s
,
ok
:=
val
.
Val
.
(
byte
);
ok
{
return
[]
byte
{
s
}
}
else
if
s
,
ok
:=
val
.
Val
.
(
string
);
ok
{
return
[]
byte
(
s
)
}
return
[]
byte
{}
...
...
@@ -196,6 +198,12 @@ func (val *Value) Encode() []byte {
return
Encode
(
val
.
Val
)
}
// Assume that the data we have is encoded
func
(
self
*
Value
)
Decode
()
{
v
,
_
:=
Decode
(
self
.
Bytes
(),
0
)
self
.
Val
=
v
}
func
NewValueFromBytes
(
data
[]
byte
)
*
Value
{
if
len
(
data
)
!=
0
{
data
,
_
:=
Decode
(
data
,
0
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录