aboutsummaryrefslogtreecommitdiffstats
path: root/chain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-03 21:05:19 +0800
committerobscuren <geffobscura@gmail.com>2014-12-03 21:05:19 +0800
commit82405501872385b240012070bad2f0eda643d423 (patch)
tree97fcdb3fb3be607d0b21e5da01bbd0f33372ffc2 /chain
parent709eff4ea77b965cdf763ada8ab248e3d850406f (diff)
downloadgo-tangerine-82405501872385b240012070bad2f0eda643d423.tar.gz
go-tangerine-82405501872385b240012070bad2f0eda643d423.tar.zst
go-tangerine-82405501872385b240012070bad2f0eda643d423.zip
updated to types
Diffstat (limited to 'chain')
-rw-r--r--chain/chain_manager.go14
-rw-r--r--chain/transaction_pool.go45
-rw-r--r--chain/types/common.go3
-rw-r--r--chain/types/transaction.go14
4 files changed, 24 insertions, 52 deletions
diff --git a/chain/chain_manager.go b/chain/chain_manager.go
index 8525ffdfd..9b35ce08a 100644
--- a/chain/chain_manager.go
+++ b/chain/chain_manager.go
@@ -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
diff --git a/chain/transaction_pool.go b/chain/transaction_pool.go
index 15c34cc39..ad89c0a98 100644
--- a/chain/transaction_pool.go
+++ b/chain/transaction_pool.go
@@ -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")
diff --git a/chain/types/common.go b/chain/types/common.go
index ae0e7c3fa..ba88b77e1 100644
--- a/chain/types/common.go
+++ b/chain/types/common.go
@@ -2,9 +2,10 @@ package types
import (
"math/big"
+
"github.com/ethereum/go-ethereum/state"
)
type BlockProcessor interface {
- ProcessWithParent(*Block, *Block) (*big.Int, state.Messages, error)
+ Process(*Block) (*big.Int, state.Messages, error)
}
diff --git a/chain/types/transaction.go b/chain/types/transaction.go
index b6424482a..efc90b6f2 100644
--- a/chain/types/transaction.go
+++ b/chain/types/transaction.go
@@ -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)