Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
505f1fbc
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,发现更多精彩内容 >>
提交
505f1fbc
编写于
3月 25, 2015
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added tx tests and fixed block tests
上级
65ea55bc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
59 addition
and
4 deletion
+59
-4
core/block_processor.go
core/block_processor.go
+1
-1
core/types/derive_sha.go
core/types/derive_sha.go
+1
-1
core/types/transaction.go
core/types/transaction.go
+4
-2
core/types/transaction_test.go
core/types/transaction_test.go
+53
-0
未找到文件。
core/block_processor.go
浏览文件 @
505f1fbc
...
...
@@ -195,7 +195,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
return
}
// The transactions Trie's root (R = (Tr [[
H1, T1], [H2, T2], ... [Hn, Tn
]]))
// The transactions Trie's root (R = (Tr [[
i, RLP(T1)], [i, RLP(T2)], ... [n, RLP(Tn)
]]))
// can be used by light clients to make sure they've received the correct Txs
txSha
:=
types
.
DeriveSha
(
block
.
Transactions
())
if
txSha
!=
header
.
TxHash
{
...
...
core/types/derive_sha.go
浏览文件 @
505f1fbc
...
...
@@ -16,7 +16,7 @@ func DeriveSha(list DerivableList) common.Hash {
db
,
_
:=
ethdb
.
NewMemDatabase
()
trie
:=
trie
.
New
(
nil
,
db
)
for
i
:=
0
;
i
<
list
.
Len
();
i
++
{
key
,
_
:=
rlp
.
EncodeToBytes
(
i
)
key
,
_
:=
rlp
.
EncodeToBytes
(
uint
(
i
)
)
trie
.
Update
(
key
,
list
.
GetRlp
(
i
))
}
...
...
core/types/transaction.go
浏览文件 @
505f1fbc
...
...
@@ -79,6 +79,7 @@ func (self *Transaction) From() (common.Address, error) {
if
len
(
pubkey
)
==
0
||
pubkey
[
0
]
!=
4
{
return
common
.
Address
{},
errors
.
New
(
"invalid public key"
)
}
var
addr
common
.
Address
copy
(
addr
[
:
],
crypto
.
Sha3
(
pubkey
[
1
:
])[
12
:
])
return
addr
,
nil
...
...
@@ -110,8 +111,9 @@ func (tx *Transaction) PublicKey() []byte {
sig
:=
append
(
r
,
s
...
)
sig
=
append
(
sig
,
v
-
27
)
//pubkey := crypto.Ecrecover(append(hash, sig...))
pubkey
,
_
:=
secp256k1
.
RecoverPubkey
(
hash
[
:
],
sig
)
//pubkey := crypto.Ecrecover(append(hash[:], sig...))
//pubkey, _ := secp256k1.RecoverPubkey(hash[:], sig)
pubkey
:=
crypto
.
FromECDSAPub
(
crypto
.
SigToPub
(
hash
[
:
],
sig
))
return
pubkey
}
...
...
core/types/transaction_test.go
浏览文件 @
505f1fbc
...
...
@@ -2,10 +2,12 @@ package types
import
(
"bytes"
"crypto/ecdsa"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
)
...
...
@@ -56,3 +58,54 @@ func TestTransactionEncode(t *testing.T) {
t
.
Errorf
(
"encoded RLP mismatch, got %x"
,
txb
)
}
}
func
decodeTx
(
data
[]
byte
)
(
*
Transaction
,
error
)
{
var
tx
Transaction
return
&
tx
,
rlp
.
Decode
(
bytes
.
NewReader
(
data
),
&
tx
)
}
func
defaultTestKey
()
(
*
ecdsa
.
PrivateKey
,
[]
byte
)
{
key
:=
crypto
.
ToECDSA
(
common
.
Hex2Bytes
(
"45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
))
addr
:=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
return
key
,
addr
}
func
TestRecipientEmpty
(
t
*
testing
.
T
)
{
_
,
addr
:=
defaultTestKey
()
tx
,
err
:=
decodeTx
(
common
.
Hex2Bytes
(
"f8498080808080011ca09b16de9d5bdee2cf56c28d16275a4da68cd30273e2525f3959f5d62557489921a0372ebd8fb3345f7db7b5a86d42e24d36e983e259b0664ceb8c227ec9af572f3d"
))
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
FailNow
()
}
from
,
err
:=
tx
.
From
()
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
FailNow
()
}
if
!
bytes
.
Equal
(
addr
,
from
.
Bytes
())
{
t
.
Error
(
"derived address doesn't match"
)
}
}
func
TestRecipientNormal
(
t
*
testing
.
T
)
{
_
,
addr
:=
defaultTestKey
()
tx
,
err
:=
decodeTx
(
common
.
Hex2Bytes
(
"f85d80808094000000000000000000000000000000000000000080011ca0527c0d8f5c63f7b9f41324a7c8a563ee1190bcbf0dac8ab446291bdbf32f5c79a0552c4ef0a09a04395074dab9ed34d3fbfb843c2f2546cc30fe89ec143ca94ca6"
))
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
FailNow
()
}
from
,
err
:=
tx
.
From
()
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
FailNow
()
}
if
!
bytes
.
Equal
(
addr
,
from
.
Bytes
())
{
t
.
Error
(
"derived address doesn't match"
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录