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
82405501
Commit
82405501
authored
Dec 03, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated to types
parent
709eff4e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
59 deletions
+31
-59
chain_manager.go
chain/chain_manager.go
+8
-6
transaction_pool.go
chain/transaction_pool.go
+4
-41
common.go
chain/types/common.go
+2
-1
transaction.go
chain/types/transaction.go
+10
-4
ethereum.go
ethereum.go
+1
-1
hexface.go
xeth/hexface.go
+1
-1
pipe.go
xeth/pipe.go
+5
-5
No files found.
chain/chain_manager.go
View file @
82405501
...
...
@@ -6,6 +6,7 @@ import (
"github.com/ethereum/go-ethereum/chain/types"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
)
...
...
@@ -45,6 +46,7 @@ func CalcDifficulty(block, parent *types.Block) *big.Int {
type
ChainManager
struct
{
//eth EthManager
processor
types
.
BlockProcessor
eventMux
*
event
.
TypeMux
genesisBlock
*
types
.
Block
// Last known total difficulty
TD
*
big
.
Int
...
...
@@ -55,10 +57,10 @@ type ChainManager struct {
LastBlockHash
[]
byte
}
func
NewChainManager
()
*
ChainManager
{
func
NewChainManager
(
mux
*
event
.
TypeMux
)
*
ChainManager
{
bc
:=
&
ChainManager
{}
bc
.
genesisBlock
=
types
.
NewBlockFromBytes
(
ethutil
.
Encode
(
Genesis
))
//bc.eth = ethereum
bc
.
eventMux
=
mux
bc
.
setLastBlock
()
...
...
@@ -250,9 +252,9 @@ func (bc *ChainManager) Stop() {
}
}
func
(
self
*
ChainManager
)
InsertChain
(
chain
Blocks
)
error
{
func
(
self
*
ChainManager
)
InsertChain
(
chain
types
.
Blocks
)
error
{
for
_
,
block
:=
range
chain
{
td
,
messages
,
err
:=
self
.
Ethereum
.
BlockManager
()
.
Process
(
block
)
td
,
messages
,
err
:=
self
.
processor
.
Process
(
block
)
if
err
!=
nil
{
if
IsKnownBlockErr
(
err
)
{
continue
...
...
@@ -266,8 +268,8 @@ func (self *ChainManager) InsertChain(chain Blocks) error {
self
.
add
(
block
)
self
.
SetTotalDifficulty
(
td
)
self
.
Ethereum
.
EventMux
()
.
Post
(
NewBlockEvent
{
block
})
self
.
Ethereum
.
EventMux
()
.
Post
(
messages
)
self
.
eventMux
.
Post
(
NewBlockEvent
{
block
})
self
.
eventMux
.
Post
(
messages
)
}
return
nil
...
...
chain/transaction_pool.go
View file @
82405501
...
...
@@ -110,7 +110,8 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return
fmt
.
Errorf
(
"Invalid recipient. len = %d"
,
len
(
tx
.
Recipient
))
}
if
tx
.
v
>
28
||
tx
.
v
<
27
{
v
,
_
,
_
:=
tx
.
Curve
()
if
v
>
28
||
v
<
27
{
return
fmt
.
Errorf
(
"tx.v != (28 || 27)"
)
}
...
...
@@ -142,7 +143,7 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
func
(
self
*
TxPool
)
Add
(
tx
*
types
.
Transaction
)
error
{
hash
:=
tx
.
Hash
()
foundTx
:=
FindTx
(
self
.
pool
,
func
(
tx
*
Transaction
,
e
*
list
.
Element
)
bool
{
foundTx
:=
FindTx
(
self
.
pool
,
func
(
tx
*
types
.
Transaction
,
e
*
list
.
Element
)
bool
{
return
bytes
.
Compare
(
tx
.
Hash
(),
hash
)
==
0
})
...
...
@@ -168,42 +169,6 @@ func (self *TxPool) Add(tx *types.Transaction) error {
return
nil
}
func
(
pool
*
TxPool
)
queueHandler
()
{
out
:
for
{
select
{
case
tx
:=
<-
pool
.
queueChan
:
hash
:=
tx
.
Hash
()
foundTx
:=
FindTx
(
pool
.
pool
,
func
(
tx
*
types
.
Transaction
,
e
*
list
.
Element
)
bool
{
return
bytes
.
Compare
(
tx
.
Hash
(),
hash
)
==
0
})
if
foundTx
!=
nil
{
break
}
// Validate the transaction
err
:=
pool
.
ValidateTransaction
(
tx
)
if
err
!=
nil
{
txplogger
.
Debugln
(
"Validating Tx failed"
,
err
)
}
else
{
// Call blocking version.
pool
.
addTransaction
(
tx
)
tmp
:=
make
([]
byte
,
4
)
copy
(
tmp
,
tx
.
Recipient
)
txplogger
.
Debugf
(
"(t) %x => %x (%v) %x
\n
"
,
tx
.
Sender
()[
:
4
],
tmp
,
tx
.
Value
,
tx
.
Hash
())
// Notify the subscribers
pool
.
Ethereum
.
EventMux
()
.
Post
(
TxPreEvent
{
tx
})
}
case
<-
pool
.
quit
:
break
out
}
}
}
func
(
pool
*
TxPool
)
CurrentTransactions
()
[]
*
types
.
Transaction
{
pool
.
mutex
.
Lock
()
defer
pool
.
mutex
.
Unlock
()
...
...
@@ -261,12 +226,10 @@ func (pool *TxPool) Flush() []*types.Transaction {
}
func
(
pool
*
TxPool
)
Start
()
{
go
pool
.
queueHandler
()
//
go pool.queueHandler()
}
func
(
pool
*
TxPool
)
Stop
()
{
close
(
pool
.
quit
)
pool
.
Flush
()
txplogger
.
Infoln
(
"Stopped"
)
...
...
chain/types/common.go
View file @
82405501
...
...
@@ -2,9 +2,10 @@ package types
import
(
"math/big"
"github.com/ethereum/go-ethereum/state"
)
type
BlockProcessor
interface
{
Process
WithParent
(
*
Block
,
*
Block
)
(
*
big
.
Int
,
state
.
Messages
,
error
)
Process
(
*
Block
)
(
*
big
.
Int
,
state
.
Messages
,
error
)
}
chain/types/transaction.go
View file @
82405501
...
...
@@ -82,6 +82,14 @@ func (tx *Transaction) CreationAddress(state *state.State) []byte {
return
crypto
.
Sha3
(
ethutil
.
NewValue
([]
interface
{}{
tx
.
Sender
(),
tx
.
Nonce
})
.
Encode
())[
12
:
]
}
func
(
tx
*
Transaction
)
Curve
()
(
v
byte
,
r
[]
byte
,
s
[]
byte
)
{
v
=
tx
.
v
r
=
ethutil
.
LeftPadBytes
(
tx
.
r
,
32
)
s
=
ethutil
.
LeftPadBytes
(
tx
.
s
,
32
)
return
}
func
(
tx
*
Transaction
)
Signature
(
key
[]
byte
)
[]
byte
{
hash
:=
tx
.
Hash
()
...
...
@@ -93,12 +101,10 @@ func (tx *Transaction) Signature(key []byte) []byte {
func
(
tx
*
Transaction
)
PublicKey
()
[]
byte
{
hash
:=
tx
.
Hash
()
// TODO
r
:=
ethutil
.
LeftPadBytes
(
tx
.
r
,
32
)
s
:=
ethutil
.
LeftPadBytes
(
tx
.
s
,
32
)
v
,
r
,
s
:=
tx
.
Curve
()
sig
:=
append
(
r
,
s
...
)
sig
=
append
(
sig
,
tx
.
v
-
27
)
sig
=
append
(
sig
,
v
-
27
)
pubkey
:=
crypto
.
Ecrecover
(
append
(
hash
,
sig
...
))
//pubkey, _ := secp256k1.RecoverPubkey(hash, sig)
...
...
ethereum.go
View file @
82405501
...
...
@@ -129,7 +129,7 @@ func New(db ethutil.Database, clientIdentity wire.ClientIdentity, keyManager *cr
ethereum
.
blockPool
=
NewBlockPool
(
ethereum
)
ethereum
.
txPool
=
chain
.
NewTxPool
(
ethereum
)
ethereum
.
blockChain
=
chain
.
NewChainManager
()
ethereum
.
blockChain
=
chain
.
NewChainManager
(
ethereum
.
EventMux
()
)
ethereum
.
blockManager
=
chain
.
NewBlockManager
(
ethereum
)
ethereum
.
blockChain
.
SetProcessor
(
ethereum
.
blockManager
)
...
...
xeth/hexface.go
View file @
82405501
...
...
@@ -215,7 +215,7 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
if
err
!=
nil
{
return
""
,
err
}
if
chain
.
IsContractAddr
(
to
)
{
if
types
.
IsContractAddr
(
to
)
{
return
ethutil
.
Bytes2Hex
(
tx
.
CreationAddress
(
nil
)),
nil
}
...
...
xeth/pipe.go
View file @
82405501
...
...
@@ -93,7 +93,7 @@ func (self *XEth) Exists(addr []byte) bool {
return
self
.
World
()
.
Get
(
addr
)
!=
nil
}
func
(
self
*
XEth
)
TransactString
(
key
*
crypto
.
KeyPair
,
rec
string
,
value
,
gas
,
price
*
ethutil
.
Value
,
data
[]
byte
)
(
*
chain
.
Transaction
,
error
)
{
func
(
self
*
XEth
)
TransactString
(
key
*
crypto
.
KeyPair
,
rec
string
,
value
,
gas
,
price
*
ethutil
.
Value
,
data
[]
byte
)
(
*
types
.
Transaction
,
error
)
{
// Check if an address is stored by this address
var
hash
[]
byte
addr
:=
self
.
World
()
.
Config
()
.
Get
(
"NameReg"
)
.
StorageString
(
rec
)
.
Bytes
()
...
...
@@ -108,10 +108,10 @@ func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, pr
return
self
.
Transact
(
key
,
hash
,
value
,
gas
,
price
,
data
)
}
func
(
self
*
XEth
)
Transact
(
key
*
crypto
.
KeyPair
,
to
[]
byte
,
value
,
gas
,
price
*
ethutil
.
Value
,
data
[]
byte
)
(
*
chain
.
Transaction
,
error
)
{
func
(
self
*
XEth
)
Transact
(
key
*
crypto
.
KeyPair
,
to
[]
byte
,
value
,
gas
,
price
*
ethutil
.
Value
,
data
[]
byte
)
(
*
types
.
Transaction
,
error
)
{
var
hash
[]
byte
var
contractCreation
bool
if
chain
.
IsContractAddr
(
to
)
{
if
types
.
IsContractAddr
(
to
)
{
contractCreation
=
true
}
else
{
// Check if an address is stored by this address
...
...
@@ -125,9 +125,9 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et
var
tx
*
types
.
Transaction
if
contractCreation
{
tx
=
chain
.
NewContractCreationTx
(
value
.
BigInt
(),
gas
.
BigInt
(),
price
.
BigInt
(),
data
)
tx
=
types
.
NewContractCreationTx
(
value
.
BigInt
(),
gas
.
BigInt
(),
price
.
BigInt
(),
data
)
}
else
{
tx
=
chain
.
NewTransactionMessage
(
hash
,
value
.
BigInt
(),
gas
.
BigInt
(),
price
.
BigInt
(),
data
)
tx
=
types
.
NewTransactionMessage
(
hash
,
value
.
BigInt
(),
gas
.
BigInt
(),
price
.
BigInt
(),
data
)
}
state
:=
self
.
blockManager
.
TransState
()
...
...
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