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
f4fa0d48
Commit
f4fa0d48
authored
May 14, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved keyring to ethutil & removed old methods. Implements #20
parent
0512113b
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
122 additions
and
31 deletions
+122
-31
database.go
ethdb/database.go
+2
-0
memory_database.go
ethdb/memory_database.go
+2
-0
pub.go
ethpub/pub.go
+5
-8
types.go
ethpub/types.go
+1
-1
db.go
ethutil/db.go
+1
-1
key.go
ethutil/key.go
+0
-19
keypair.go
ethutil/keypair.go
+109
-0
peer.go
peer.go
+2
-2
No files found.
ethdb/database.go
View file @
f4fa0d48
...
...
@@ -54,11 +54,13 @@ func (db *LDBDatabase) LastKnownTD() []byte {
return
data
}
/*
func (db *LDBDatabase) GetKeys() []*ethutil.Key {
data, _ := db.Get([]byte("KeyRing"))
return []*ethutil.Key{ethutil.NewKeyFromBytes(data)}
}
*/
func
(
db
*
LDBDatabase
)
Close
()
{
// Close the leveldb database
...
...
ethdb/memory_database.go
View file @
f4fa0d48
...
...
@@ -26,11 +26,13 @@ func (db *MemDatabase) Get(key []byte) ([]byte, error) {
return
db
.
db
[
string
(
key
)],
nil
}
/*
func (db *MemDatabase) GetKeys() []*ethutil.Key {
data, _ := db.Get([]byte("KeyRing"))
return []*ethutil.Key{ethutil.NewKeyFromBytes(data)}
}
*/
func
(
db
*
MemDatabase
)
Delete
(
key
[]
byte
)
error
{
delete
(
db
.
db
,
string
(
key
))
...
...
ethpub/pub.go
View file @
f4fa0d48
...
...
@@ -39,10 +39,7 @@ func (lib *PEthereum) GetBlock(hexHash string) *PBlock {
}
func
(
lib
*
PEthereum
)
GetKey
()
*
PKey
{
keyPair
,
err
:=
ethchain
.
NewKeyPairFromSec
(
ethutil
.
Config
.
Db
.
GetKeys
()[
0
]
.
PrivateKey
)
if
err
!=
nil
{
return
nil
}
keyPair
:=
ethutil
.
GetKeyRing
()
.
Get
(
0
)
return
NewPKey
(
keyPair
)
}
...
...
@@ -90,7 +87,7 @@ func (lib *PEthereum) IsContract(address string) bool {
}
func
(
lib
*
PEthereum
)
SecretToAddress
(
key
string
)
string
{
pair
,
err
:=
eth
chain
.
NewKeyPairFromSec
(
ethutil
.
FromHex
(
key
))
pair
,
err
:=
eth
util
.
NewKeyPairFromSec
(
ethutil
.
FromHex
(
key
))
if
err
!=
nil
{
return
""
}
...
...
@@ -115,12 +112,12 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in
hash
=
ethutil
.
FromHex
(
recipient
)
}
var
keyPair
*
eth
chain
.
KeyPair
var
keyPair
*
eth
util
.
KeyPair
var
err
error
if
key
[
0
:
2
]
==
"0x"
{
keyPair
,
err
=
eth
chain
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
FromHex
(
key
[
0
:
2
])))
keyPair
,
err
=
eth
util
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
FromHex
(
key
[
0
:
2
])))
}
else
{
keyPair
,
err
=
eth
chain
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
FromHex
(
key
)))
keyPair
,
err
=
eth
util
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
FromHex
(
key
)))
}
if
err
!=
nil
{
...
...
ethpub/types.go
View file @
f4fa0d48
...
...
@@ -39,7 +39,7 @@ type PKey struct {
PublicKey
string
`json:"publicKey"`
}
func
NewPKey
(
key
*
eth
chain
.
KeyPair
)
*
PKey
{
func
NewPKey
(
key
*
eth
util
.
KeyPair
)
*
PKey
{
return
&
PKey
{
ethutil
.
Hex
(
key
.
Address
()),
ethutil
.
Hex
(
key
.
PrivateKey
),
ethutil
.
Hex
(
key
.
PublicKey
)}
}
...
...
ethutil/db.go
View file @
f4fa0d48
...
...
@@ -4,7 +4,7 @@ package ethutil
type
Database
interface
{
Put
(
key
[]
byte
,
value
[]
byte
)
Get
(
key
[]
byte
)
([]
byte
,
error
)
GetKeys
()
[]
*
Key
//
GetKeys() []*Key
Delete
(
key
[]
byte
)
error
LastKnownTD
()
[]
byte
Close
()
...
...
ethutil/key.go
deleted
100644 → 0
View file @
0512113b
package
ethutil
type
Key
struct
{
PrivateKey
[]
byte
PublicKey
[]
byte
}
func
NewKeyFromBytes
(
data
[]
byte
)
*
Key
{
val
:=
NewValueFromBytes
(
data
)
return
&
Key
{
val
.
Get
(
0
)
.
Bytes
(),
val
.
Get
(
1
)
.
Bytes
()}
}
func
(
k
*
Key
)
Address
()
[]
byte
{
return
Sha3Bin
(
k
.
PublicKey
[
1
:
])[
12
:
]
}
func
(
k
*
Key
)
RlpEncode
()
[]
byte
{
return
EmptyValue
()
.
Append
(
k
.
PrivateKey
)
.
Append
(
k
.
PublicKey
)
.
Encode
()
}
eth
chain
/keypair.go
→
eth
util
/keypair.go
View file @
f4fa0d48
package
eth
chain
package
eth
util
import
(
"github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/secp256k1-go"
"math/big"
)
type
KeyPair
struct
{
...
...
@@ -12,7 +10,6 @@ type KeyPair struct {
// The associated account
account
*
StateObject
state
*
State
}
func
NewKeyPairFromSec
(
seckey
[]
byte
)
(
*
KeyPair
,
error
)
{
...
...
@@ -24,62 +21,87 @@ func NewKeyPairFromSec(seckey []byte) (*KeyPair, error) {
return
&
KeyPair
{
PrivateKey
:
seckey
,
PublicKey
:
pubkey
},
nil
}
func
NewKeyPairFromValue
(
val
*
ethutil
.
Value
)
*
KeyPair
{
keyPair
:=
&
KeyPair
{
PrivateKey
:
val
.
Get
(
0
)
.
Bytes
(),
PublicKey
:
val
.
Get
(
1
)
.
Bytes
()}
func
NewKeyPairFromValue
(
val
*
Value
)
*
KeyPair
{
v
,
_
:=
NewKeyPairFromSec
(
val
.
Bytes
())
return
keyPair
return
v
}
func
(
k
*
KeyPair
)
Address
()
[]
byte
{
return
ethutil
.
Sha3Bin
(
k
.
PublicKey
[
1
:
])[
12
:
]
return
Sha3Bin
(
k
.
PublicKey
[
1
:
])[
12
:
]
}
func
(
k
*
KeyPair
)
Account
()
*
StateObject
{
if
k
.
account
==
nil
{
k
.
account
=
k
.
state
.
GetAccount
(
k
.
Address
())
}
func
(
k
*
KeyPair
)
RlpEncode
()
[]
byte
{
return
k
.
RlpValue
()
.
Encode
()
}
return
k
.
account
func
(
k
*
KeyPair
)
RlpValue
()
*
Value
{
return
NewValue
(
k
.
PrivateKey
)
}
type
KeyRing
struct
{
keys
[]
*
KeyPair
}
// Create transaction, creates a new and signed transaction, ready for processing
func
(
k
*
KeyPair
)
CreateTx
(
receiver
[]
byte
,
value
*
big
.
Int
,
data
[]
string
)
*
Transaction
{
/* TODO
tx := NewTransaction(receiver, value, data)
tx.Nonce = k.account.Nonce
func
(
k
*
KeyRing
)
Add
(
pair
*
KeyPair
)
{
k
.
keys
=
append
(
k
.
keys
,
pair
)
}
// Sign the transaction with the private key in this key chain
tx.Sign(k.PrivateKey)
func
(
k
*
KeyRing
)
Get
(
i
int
)
*
KeyPair
{
if
len
(
k
.
keys
)
>
i
{
return
k
.
keys
[
i
]
}
return tx
*/
return
nil
}
func
(
k
*
Key
Pair
)
RlpEncode
()
[]
byte
{
return
ethutil
.
EmptyValue
()
.
Append
(
k
.
PrivateKey
)
.
Append
(
k
.
PublicKey
)
.
Encode
(
)
func
(
k
*
Key
Ring
)
Len
()
int
{
return
len
(
k
.
keys
)
}
type
KeyRing
struct
{
keys
[]
*
KeyPair
func
(
k
*
KeyRing
)
NewKeyPair
(
sec
[]
byte
)
(
*
KeyPair
,
error
)
{
keyPair
,
err
:=
NewKeyPairFromSec
(
sec
)
if
err
!=
nil
{
return
nil
,
err
}
k
.
Add
(
keyPair
)
Config
.
Db
.
Put
([]
byte
(
"KeyRing"
),
k
.
RlpValue
()
.
Encode
())
return
keyPair
,
nil
}
func
(
k
*
KeyRing
)
Add
(
pair
*
KeyPair
)
{
k
.
keys
=
append
(
k
.
keys
,
pair
)
func
(
k
*
KeyRing
)
Reset
()
{
Config
.
Db
.
Put
([]
byte
(
"KeyRing"
),
nil
)
k
.
keys
=
nil
}
func
(
k
*
KeyRing
)
RlpValue
()
*
Value
{
v
:=
EmptyValue
()
for
_
,
keyPair
:=
range
k
.
keys
{
v
.
Append
(
keyPair
.
RlpValue
())
}
return
v
}
// The public "singleton" keyring
var
keyRing
*
KeyRing
func
GetKeyRing
(
state
*
State
)
*
KeyRing
{
func
GetKeyRing
()
*
KeyRing
{
if
keyRing
==
nil
{
keyRing
=
&
KeyRing
{}
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
"KeyRing"
))
it
:=
ethutil
.
NewValueFromBytes
(
data
)
.
NewIterator
()
data
,
_
:=
Config
.
Db
.
Get
([]
byte
(
"KeyRing"
))
it
:=
NewValueFromBytes
(
data
)
.
NewIterator
()
for
it
.
Next
()
{
v
:=
it
.
Value
()
keyRing
.
Add
(
NewKeyPairFromValue
(
v
))
key
,
err
:=
NewKeyPairFromSec
(
v
.
Bytes
())
if
err
!=
nil
{
panic
(
err
)
}
keyRing
.
Add
(
key
)
}
}
...
...
peer.go
View file @
f4fa0d48
...
...
@@ -581,8 +581,8 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
p
.
port
=
uint16
(
c
.
Get
(
4
)
.
Uint
())
// Self connect detection
key
:=
ethutil
.
Config
.
Db
.
GetKeys
()[
0
]
if
bytes
.
Compare
(
key
.
PublicKey
,
p
.
pubkey
)
==
0
{
key
Pair
:=
ethutil
.
GetKeyRing
()
.
Get
(
0
)
if
bytes
.
Compare
(
key
Pair
.
PublicKey
,
p
.
pubkey
)
==
0
{
p
.
Stop
()
return
...
...
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