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
505f1fbc
Commit
505f1fbc
authored
Mar 25, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added tx tests and fixed block tests
parent
65ea55bc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
4 deletions
+59
-4
block_processor.go
core/block_processor.go
+1
-1
derive_sha.go
core/types/derive_sha.go
+1
-1
transaction.go
core/types/transaction.go
+4
-2
transaction_test.go
core/types/transaction_test.go
+53
-0
No files found.
core/block_processor.go
View file @
505f1fbc
...
@@ -195,7 +195,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
...
@@ -195,7 +195,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
return
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
// can be used by light clients to make sure they've received the correct Txs
txSha
:=
types
.
DeriveSha
(
block
.
Transactions
())
txSha
:=
types
.
DeriveSha
(
block
.
Transactions
())
if
txSha
!=
header
.
TxHash
{
if
txSha
!=
header
.
TxHash
{
...
...
core/types/derive_sha.go
View file @
505f1fbc
...
@@ -16,7 +16,7 @@ func DeriveSha(list DerivableList) common.Hash {
...
@@ -16,7 +16,7 @@ func DeriveSha(list DerivableList) common.Hash {
db
,
_
:=
ethdb
.
NewMemDatabase
()
db
,
_
:=
ethdb
.
NewMemDatabase
()
trie
:=
trie
.
New
(
nil
,
db
)
trie
:=
trie
.
New
(
nil
,
db
)
for
i
:=
0
;
i
<
list
.
Len
();
i
++
{
for
i
:=
0
;
i
<
list
.
Len
();
i
++
{
key
,
_
:=
rlp
.
EncodeToBytes
(
i
)
key
,
_
:=
rlp
.
EncodeToBytes
(
uint
(
i
)
)
trie
.
Update
(
key
,
list
.
GetRlp
(
i
))
trie
.
Update
(
key
,
list
.
GetRlp
(
i
))
}
}
...
...
core/types/transaction.go
View file @
505f1fbc
...
@@ -79,6 +79,7 @@ func (self *Transaction) From() (common.Address, error) {
...
@@ -79,6 +79,7 @@ func (self *Transaction) From() (common.Address, error) {
if
len
(
pubkey
)
==
0
||
pubkey
[
0
]
!=
4
{
if
len
(
pubkey
)
==
0
||
pubkey
[
0
]
!=
4
{
return
common
.
Address
{},
errors
.
New
(
"invalid public key"
)
return
common
.
Address
{},
errors
.
New
(
"invalid public key"
)
}
}
var
addr
common
.
Address
var
addr
common
.
Address
copy
(
addr
[
:
],
crypto
.
Sha3
(
pubkey
[
1
:
])[
12
:
])
copy
(
addr
[
:
],
crypto
.
Sha3
(
pubkey
[
1
:
])[
12
:
])
return
addr
,
nil
return
addr
,
nil
...
@@ -110,8 +111,9 @@ func (tx *Transaction) PublicKey() []byte {
...
@@ -110,8 +111,9 @@ func (tx *Transaction) PublicKey() []byte {
sig
:=
append
(
r
,
s
...
)
sig
:=
append
(
r
,
s
...
)
sig
=
append
(
sig
,
v
-
27
)
sig
=
append
(
sig
,
v
-
27
)
//pubkey := crypto.Ecrecover(append(hash, sig...))
//pubkey := crypto.Ecrecover(append(hash[:], sig...))
pubkey
,
_
:=
secp256k1
.
RecoverPubkey
(
hash
[
:
],
sig
)
//pubkey, _ := secp256k1.RecoverPubkey(hash[:], sig)
pubkey
:=
crypto
.
FromECDSAPub
(
crypto
.
SigToPub
(
hash
[
:
],
sig
))
return
pubkey
return
pubkey
}
}
...
...
core/types/transaction_test.go
View file @
505f1fbc
...
@@ -2,10 +2,12 @@ package types
...
@@ -2,10 +2,12 @@ package types
import
(
import
(
"bytes"
"bytes"
"crypto/ecdsa"
"math/big"
"math/big"
"testing"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
)
)
...
@@ -56,3 +58,54 @@ func TestTransactionEncode(t *testing.T) {
...
@@ -56,3 +58,54 @@ func TestTransactionEncode(t *testing.T) {
t
.
Errorf
(
"encoded RLP mismatch, got %x"
,
txb
)
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"
)
}
}
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