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
685ea3e9
Commit
685ea3e9
authored
Mar 07, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wip keychains
parent
ea873304
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
0 deletions
+74
-0
keypair.go
ethchain/keypair.go
+74
-0
No files found.
ethchain/keypair.go
0 → 100644
View file @
685ea3e9
package
ethchain
import
(
"github.com/ethereum/eth-go/ethutil"
"math/big"
)
type
KeyPair
struct
{
PrivateKey
[]
byte
PublicKey
[]
byte
// The associated account
account
*
Account
state
*
State
}
func
NewKeyPairFromValue
(
val
*
ethutil
.
Value
)
*
KeyPair
{
keyPair
:=
&
KeyPair
{
PrivateKey
:
val
.
Get
(
0
)
.
Bytes
(),
PublicKey
:
val
.
Get
(
1
)
.
Bytes
()}
return
keyPair
}
func
(
k
*
KeyPair
)
Address
()
[]
byte
{
return
ethutil
.
Sha3Bin
(
k
.
PublicKey
[
1
:
])[
12
:
]
}
func
(
k
*
KeyPair
)
Account
()
*
Account
{
if
k
.
account
==
nil
{
k
.
account
=
k
.
state
.
GetAccount
(
k
.
Address
())
}
return
k
.
account
}
// Create transaction, creates a new and signed transaction, ready for processing
func
(
k
*
KeyPair
)
CreateTx
(
receiver
[]
byte
,
value
*
big
.
Int
,
data
[]
string
)
*
Transaction
{
tx
:=
NewTransaction
(
receiver
,
value
,
data
)
tx
.
Nonce
=
k
.
account
.
Nonce
// Sign the transaction with the private key in this key chain
tx
.
Sign
(
k
.
PrivateKey
)
return
tx
}
func
(
k
*
KeyPair
)
RlpEncode
()
[]
byte
{
return
ethutil
.
EmptyValue
()
.
Append
(
k
.
PrivateKey
)
.
Append
(
k
.
PublicKey
)
.
Encode
()
}
type
KeyRing
struct
{
keys
[]
*
KeyPair
}
func
(
k
*
KeyRing
)
Add
(
pair
*
KeyPair
)
{
k
.
keys
=
append
(
k
.
keys
,
pair
)
}
// The public "singleton" keyring
var
keyRing
*
KeyRing
func
GetKeyRing
(
state
*
State
)
*
KeyRing
{
if
keyRing
==
nil
{
keyRing
=
&
KeyRing
{}
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
"KeyRing"
))
it
:=
ethutil
.
NewValueFromBytes
(
data
)
.
NewIterator
()
for
it
.
Next
()
{
v
:=
it
.
Value
()
keyRing
.
Add
(
NewKeyPairFromValue
(
v
))
}
}
return
keyRing
}
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