Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
6aa390ab
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,发现更多精彩内容 >>
提交
6aa390ab
编写于
3月 16, 2015
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'conversion' of github.com-obscure:ethereum/go-ethereum into conversion
上级
91b0b148
16df850a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
69 deletion
+36
-69
core/types/block.go
core/types/block.go
+2
-3
core/types/transaction.go
core/types/transaction.go
+24
-65
crypto/crypto.go
crypto/crypto.go
+10
-1
未找到文件。
core/types/block.go
浏览文件 @
6aa390ab
package
types
import
(
"bytes"
"encoding/binary"
"fmt"
"math/big"
...
...
@@ -156,9 +155,9 @@ func (self *Block) Transactions() Transactions {
return
self
.
transactions
}
func
(
self
*
Block
)
Transaction
(
hash
[]
byte
)
*
Transaction
{
func
(
self
*
Block
)
Transaction
(
hash
common
.
Hash
)
*
Transaction
{
for
_
,
transaction
:=
range
self
.
transactions
{
if
bytes
.
Equal
(
hash
,
transaction
.
Hash
())
{
if
transaction
.
Hash
()
==
hash
{
return
transaction
}
}
...
...
core/types/transaction.go
浏览文件 @
6aa390ab
...
...
@@ -2,13 +2,13 @@ package types
import
(
"bytes"
"crypto/ecdsa"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/c
ommon
"
"github.com/ethereum/go-ethereum/c
rypto/sha3
"
"github.com/ethereum/go-ethereum/rlp"
)
...
...
@@ -20,7 +20,7 @@ type Transaction struct {
AccountNonce
uint64
Price
*
big
.
Int
GasLimit
*
big
.
Int
Recipient
[]
byte
Recipient
common
.
Address
Amount
*
big
.
Int
Payload
[]
byte
V
byte
...
...
@@ -28,31 +28,24 @@ type Transaction struct {
}
func
NewContractCreationTx
(
Amount
,
gasAmount
,
price
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
return
NewTransactionMessage
(
nil
,
Amount
,
gasAmount
,
price
,
data
)
return
NewTransactionMessage
(
common
.
Address
{}
,
Amount
,
gasAmount
,
price
,
data
)
}
func
NewTransactionMessage
(
to
[]
byte
,
Amount
,
gasAmount
,
price
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
func
NewTransactionMessage
(
to
common
.
Address
,
Amount
,
gasAmount
,
price
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
return
&
Transaction
{
Recipient
:
to
,
Amount
:
Amount
,
Price
:
price
,
GasLimit
:
gasAmount
,
Payload
:
data
}
}
func
NewTransactionFromBytes
(
data
[]
byte
)
*
Transaction
{
tx
:=
&
Transaction
{}
tx
.
RlpDecode
(
data
)
tx
:=
new
(
Transaction
)
rlp
.
Decode
(
bytes
.
NewReader
(
data
),
tx
)
return
tx
}
func
NewTransactionFromAmount
(
val
*
common
.
Value
)
*
Transaction
{
tx
:=
&
Transaction
{}
tx
.
RlpValueDecode
(
val
)
return
tx
}
func
(
tx
*
Transaction
)
Hash
()
[]
byte
{
data
:=
[]
interface
{}{
tx
.
AccountNonce
,
tx
.
Price
,
tx
.
GasLimit
,
tx
.
Recipient
,
tx
.
Amount
,
tx
.
Payload
}
return
crypto
.
Sha3
(
common
.
Encode
(
data
))
func
(
tx
*
Transaction
)
Hash
()
(
a
common
.
Hash
)
{
h
:=
sha3
.
NewKeccak256
()
rlp
.
Encode
(
h
,
[]
interface
{}{
tx
.
AccountNonce
,
tx
.
Price
,
tx
.
GasLimit
,
tx
.
Recipient
,
tx
.
Amount
,
tx
.
Payload
})
h
.
Sum
(
a
[
:
])
return
a
}
func
(
self
*
Transaction
)
Data
()
[]
byte
{
...
...
@@ -79,11 +72,11 @@ func (self *Transaction) SetNonce(AccountNonce uint64) {
self
.
AccountNonce
=
AccountNonce
}
func
(
self
*
Transaction
)
From
()
[]
byte
{
func
(
self
*
Transaction
)
From
()
common
.
Address
{
return
self
.
sender
()
}
func
(
self
*
Transaction
)
To
()
[]
byte
{
func
(
self
*
Transaction
)
To
()
common
.
Address
{
return
self
.
Recipient
}
...
...
@@ -97,48 +90,31 @@ func (tx *Transaction) Curve() (v byte, r []byte, s []byte) {
func
(
tx
*
Transaction
)
Signature
(
key
[]
byte
)
[]
byte
{
hash
:=
tx
.
Hash
()
sig
,
_
:=
secp256k1
.
Sign
(
hash
,
key
)
sig
,
_
:=
secp256k1
.
Sign
(
hash
[
:
],
key
)
return
sig
}
func
(
tx
*
Transaction
)
PublicKey
()
[]
byte
{
hash
:=
tx
.
Hash
()
v
,
r
,
s
:=
tx
.
Curve
()
sig
:=
append
(
r
,
s
...
)
sig
=
append
(
sig
,
v
-
27
)
//pubkey := crypto.Ecrecover(append(hash, sig...))
pubkey
,
_
:=
secp256k1
.
RecoverPubkey
(
hash
,
sig
)
pubkey
,
_
:=
secp256k1
.
RecoverPubkey
(
hash
[
:
],
sig
)
return
pubkey
}
func
(
tx
*
Transaction
)
sender
()
[]
byte
{
func
(
tx
*
Transaction
)
sender
()
(
a
common
.
Address
)
{
pubkey
:=
tx
.
PublicKey
()
// Validate the returned key.
// Return nil if public key isn't in full format
if
len
(
pubkey
)
==
0
||
pubkey
[
0
]
!=
4
{
return
nil
return
a
}
return
crypto
.
Sha3
(
pubkey
[
1
:
])[
12
:
]
}
// TODO: deprecate after new accounts & key stores are integrated
func
(
tx
*
Transaction
)
Sign
(
privk
[]
byte
)
error
{
sig
:=
tx
.
Signature
(
privk
)
tx
.
R
=
sig
[
:
32
]
tx
.
S
=
sig
[
32
:
64
]
tx
.
V
=
sig
[
64
]
+
27
return
nil
copy
(
a
[
:
],
crypto
.
Sha3
(
pubkey
[
1
:
]))
return
a
}
func
(
tx
*
Transaction
)
SetSignatureValues
(
sig
[]
byte
)
error
{
...
...
@@ -148,36 +124,17 @@ func (tx *Transaction) SetSignatureValues(sig []byte) error {
return
nil
}
func
(
tx
*
Transaction
)
SignECDSA
(
key
*
ecdsa
.
PrivateKey
)
error
{
return
tx
.
Sign
(
crypto
.
FromECDSA
(
key
))
}
// TODO: remove
func
(
tx
*
Transaction
)
RlpData
()
interface
{}
{
data
:=
[]
interface
{}{
tx
.
AccountNonce
,
tx
.
Price
,
tx
.
GasLimit
,
tx
.
Recipient
,
tx
.
Amount
,
tx
.
Payload
}
return
append
(
data
,
tx
.
V
,
new
(
big
.
Int
)
.
SetBytes
(
tx
.
R
)
.
Bytes
(),
new
(
big
.
Int
)
.
SetBytes
(
tx
.
S
)
.
Bytes
())
}
// TODO: remove
func
(
tx
*
Transaction
)
RlpEncode
()
[]
byte
{
return
common
.
Encode
(
tx
)
}
func
(
tx
*
Transaction
)
RlpDecode
(
data
[]
byte
)
{
rlp
.
Decode
(
bytes
.
NewReader
(
data
),
tx
)
}
func
(
tx
*
Transaction
)
RlpValueDecode
(
decoder
*
common
.
Value
)
{
tx
.
AccountNonce
=
decoder
.
Get
(
0
)
.
Uint
()
tx
.
Price
=
decoder
.
Get
(
1
)
.
BigInt
()
tx
.
GasLimit
=
decoder
.
Get
(
2
)
.
BigInt
()
tx
.
Recipient
=
decoder
.
Get
(
3
)
.
Bytes
()
tx
.
Amount
=
decoder
.
Get
(
4
)
.
BigInt
()
tx
.
Payload
=
decoder
.
Get
(
5
)
.
Bytes
()
tx
.
V
=
decoder
.
Get
(
6
)
.
Byte
()
tx
.
R
=
decoder
.
Get
(
7
)
.
Bytes
()
tx
.
S
=
decoder
.
Get
(
8
)
.
Bytes
()
}
func
(
tx
*
Transaction
)
String
()
string
{
return
fmt
.
Sprintf
(
`
TX(%x)
...
...
@@ -213,6 +170,7 @@ func (tx *Transaction) String() string {
// Transaction slice type for basic sorting
type
Transactions
[]
*
Transaction
// TODO: remove
func
(
self
Transactions
)
RlpData
()
interface
{}
{
// Marshal the transactions of this block
enc
:=
make
([]
interface
{},
len
(
self
))
...
...
@@ -223,6 +181,7 @@ func (self Transactions) RlpData() interface{} {
return
enc
}
func
(
s
Transactions
)
Len
()
int
{
return
len
(
s
)
}
func
(
s
Transactions
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
func
(
s
Transactions
)
GetRlp
(
i
int
)
[]
byte
{
return
common
.
Rlp
(
s
[
i
])
}
...
...
crypto/crypto.go
浏览文件 @
6aa390ab
...
...
@@ -16,10 +16,10 @@ import (
"errors"
"code.google.com/p/go-uuid/uuid"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/common"
"golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/ripemd160"
)
...
...
@@ -37,6 +37,15 @@ func Sha3(data ...[]byte) []byte {
return
d
.
Sum
(
nil
)
}
func
Sha3Hash
(
data
...
[]
byte
)
(
h
common
.
Hash
)
{
d
:=
sha3
.
NewKeccak256
()
for
_
,
b
:=
range
data
{
d
.
Write
(
b
)
}
d
.
Sum
(
h
[
:
])
return
h
}
// Creates an ethereum address given the bytes and the nonce
func
CreateAddress
(
b
[]
byte
,
nonce
uint64
)
[]
byte
{
return
Sha3
(
common
.
NewValue
([]
interface
{}{
b
,
nonce
})
.
Encode
())[
12
:
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录