Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
b533aaa7
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 搜索 >>
提交
b533aaa7
编写于
7月 06, 2015
作者:
J
Jeffrey Wilcke
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1409 from fjl/fix-tx-hash
core/types, xeth: separate tx hash and tx signature hash
上级
35add89c
ec9620fb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
17 addition
and
9 deletion
+17
-9
core/types/transaction.go
core/types/transaction.go
+13
-5
core/types/transaction_test.go
core/types/transaction_test.go
+3
-3
xeth/xeth.go
xeth/xeth.go
+1
-1
未找到文件。
core/types/transaction.go
浏览文件 @
b533aaa7
...
...
@@ -116,11 +116,21 @@ func (tx *Transaction) To() *common.Address {
}
}
// Hash hashes the RLP encoding of tx.
// It uniquely identifies the transaction.
func
(
tx
*
Transaction
)
Hash
()
common
.
Hash
{
if
hash
:=
tx
.
hash
.
Load
();
hash
!=
nil
{
return
hash
.
(
common
.
Hash
)
}
v
:=
rlpHash
([]
interface
{}{
v
:=
rlpHash
(
tx
)
tx
.
hash
.
Store
(
v
)
return
v
}
// SigHash returns the hash to be signed by the sender.
// It does not uniquely identify the transaction.
func
(
tx
*
Transaction
)
SigHash
()
common
.
Hash
{
return
rlpHash
([]
interface
{}{
tx
.
data
.
AccountNonce
,
tx
.
data
.
Price
,
tx
.
data
.
GasLimit
,
...
...
@@ -128,8 +138,6 @@ func (tx *Transaction) Hash() common.Hash {
tx
.
data
.
Amount
,
tx
.
data
.
Payload
,
})
tx
.
hash
.
Store
(
v
)
return
v
}
func
(
tx
*
Transaction
)
Size
()
common
.
StorageSize
{
...
...
@@ -180,7 +188,7 @@ func (tx *Transaction) publicKey() ([]byte, error) {
sig
[
64
]
=
tx
.
data
.
V
-
27
// recover the public key from the signature
hash
:=
tx
.
Hash
()
hash
:=
tx
.
Sig
Hash
()
pub
,
err
:=
crypto
.
Ecrecover
(
hash
[
:
],
sig
)
if
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infof
(
"Could not get pubkey from signature: "
,
err
)
...
...
@@ -204,7 +212,7 @@ func (tx *Transaction) WithSignature(sig []byte) (*Transaction, error) {
}
func
(
tx
*
Transaction
)
SignECDSA
(
prv
*
ecdsa
.
PrivateKey
)
(
*
Transaction
,
error
)
{
h
:=
tx
.
Hash
()
h
:=
tx
.
Sig
Hash
()
sig
,
err
:=
crypto
.
Sign
(
h
[
:
],
prv
)
if
err
!=
nil
{
return
nil
,
err
...
...
core/types/transaction_test.go
浏览文件 @
b533aaa7
...
...
@@ -34,11 +34,11 @@ var (
)
)
func
TestTransactionHash
(
t
*
testing
.
T
)
{
if
emptyTx
.
Hash
()
!=
common
.
HexToHash
(
"c775b99e7ad12f50d819fcd602390467e28141316969f4b57f0626f74fe3b386"
)
{
func
TestTransaction
Sig
Hash
(
t
*
testing
.
T
)
{
if
emptyTx
.
Sig
Hash
()
!=
common
.
HexToHash
(
"c775b99e7ad12f50d819fcd602390467e28141316969f4b57f0626f74fe3b386"
)
{
t
.
Errorf
(
"empty transaction hash mismatch, got %x"
,
emptyTx
.
Hash
())
}
if
rightvrsTx
.
Hash
()
!=
common
.
HexToHash
(
"fe7a79529ed5f7c3375d06b26b186a8644e0e16c373d7a12be41c62d6042b77a"
)
{
if
rightvrsTx
.
Sig
Hash
()
!=
common
.
HexToHash
(
"fe7a79529ed5f7c3375d06b26b186a8644e0e16c373d7a12be41c62d6042b77a"
)
{
t
.
Errorf
(
"RightVRS transaction hash mismatch, got %x"
,
rightvrsTx
.
Hash
())
}
}
...
...
xeth/xeth.go
浏览文件 @
b533aaa7
...
...
@@ -977,7 +977,7 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS
}
func
(
self
*
XEth
)
sign
(
tx
*
types
.
Transaction
,
from
common
.
Address
,
didUnlock
bool
)
(
*
types
.
Transaction
,
error
)
{
hash
:=
tx
.
Hash
()
hash
:=
tx
.
Sig
Hash
()
sig
,
err
:=
self
.
doSign
(
from
,
hash
,
didUnlock
)
if
err
!=
nil
{
return
tx
,
err
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录