Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
0b2edf05
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
0b2edf05
编写于
5月 11, 2020
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core/state: make GetCodeSize mirror GetCode implementation wise
上级
e29e4c23
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
14 deletion
+20
-14
core/state/state_object.go
core/state/state_object.go
+17
-0
core/state/statedb.go
core/state/statedb.go
+3
-14
未找到文件。
core/state/state_object.go
浏览文件 @
0b2edf05
...
@@ -454,6 +454,23 @@ func (s *stateObject) Code(db Database) []byte {
...
@@ -454,6 +454,23 @@ func (s *stateObject) Code(db Database) []byte {
return
code
return
code
}
}
// CodeSize returns the size of the contract code associated with this object,
// or zero if none. This methos is an almost mirror of Code, but uses a cache
// inside the database to avoid loading codes seen recently.
func
(
s
*
stateObject
)
CodeSize
(
db
Database
)
int
{
if
s
.
code
!=
nil
{
return
len
(
s
.
code
)
}
if
bytes
.
Equal
(
s
.
CodeHash
(),
emptyCodeHash
)
{
return
0
}
size
,
err
:=
db
.
ContractCodeSize
(
s
.
addrHash
,
common
.
BytesToHash
(
s
.
CodeHash
()))
if
err
!=
nil
{
s
.
setError
(
fmt
.
Errorf
(
"can't load code size %x: %v"
,
s
.
CodeHash
(),
err
))
}
return
size
}
func
(
s
*
stateObject
)
SetCode
(
codeHash
common
.
Hash
,
code
[]
byte
)
{
func
(
s
*
stateObject
)
SetCode
(
codeHash
common
.
Hash
,
code
[]
byte
)
{
prevcode
:=
s
.
Code
(
s
.
db
.
db
)
prevcode
:=
s
.
Code
(
s
.
db
.
db
)
s
.
db
.
journal
.
append
(
codeChange
{
s
.
db
.
journal
.
append
(
codeChange
{
...
...
core/state/statedb.go
浏览文件 @
0b2edf05
...
@@ -18,7 +18,6 @@
...
@@ -18,7 +18,6 @@
package
state
package
state
import
(
import
(
"bytes"
"errors"
"errors"
"fmt"
"fmt"
"math/big"
"math/big"
...
@@ -289,20 +288,10 @@ func (s *StateDB) GetCode(addr common.Address) []byte {
...
@@ -289,20 +288,10 @@ func (s *StateDB) GetCode(addr common.Address) []byte {
func
(
s
*
StateDB
)
GetCodeSize
(
addr
common
.
Address
)
int
{
func
(
s
*
StateDB
)
GetCodeSize
(
addr
common
.
Address
)
int
{
stateObject
:=
s
.
getStateObject
(
addr
)
stateObject
:=
s
.
getStateObject
(
addr
)
if
stateObject
==
nil
{
if
stateObject
!=
nil
{
return
0
return
stateObject
.
CodeSize
(
s
.
db
)
}
if
stateObject
.
code
!=
nil
{
return
len
(
stateObject
.
code
)
}
if
bytes
.
Equal
(
stateObject
.
CodeHash
(),
emptyCode
[
:
])
{
return
0
}
size
,
err
:=
s
.
db
.
ContractCodeSize
(
stateObject
.
addrHash
,
common
.
BytesToHash
(
stateObject
.
CodeHash
()))
if
err
!=
nil
{
s
.
setError
(
fmt
.
Errorf
(
"GetCodeSize (%x) error: %v"
,
addr
[
:
],
err
))
}
}
return
size
return
0
}
}
func
(
s
*
StateDB
)
GetCodeHash
(
addr
common
.
Address
)
common
.
Hash
{
func
(
s
*
StateDB
)
GetCodeHash
(
addr
common
.
Address
)
common
.
Hash
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录