diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-15 03:34:30 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-15 03:34:30 +0800 |
commit | 6efdd21633c1d21f36080754a89ad82c0c244128 (patch) | |
tree | 873da7787044997e5590d35e32076ecb7a21dae4 /ethchain | |
parent | 283f4d8eb3e223f89fd613767e1c6c318ac2bb75 (diff) | |
parent | ad4ffdc9474aca48ab1d3d361797398f795a6d31 (diff) | |
download | go-tangerine-6efdd21633c1d21f36080754a89ad82c0c244128.tar go-tangerine-6efdd21633c1d21f36080754a89ad82c0c244128.tar.gz go-tangerine-6efdd21633c1d21f36080754a89ad82c0c244128.tar.bz2 go-tangerine-6efdd21633c1d21f36080754a89ad82c0c244128.tar.lz go-tangerine-6efdd21633c1d21f36080754a89ad82c0c244128.tar.xz go-tangerine-6efdd21633c1d21f36080754a89ad82c0c244128.tar.zst go-tangerine-6efdd21633c1d21f36080754a89ad82c0c244128.zip |
Merge branch 'release/poc5-rc6'
Diffstat (limited to 'ethchain')
-rw-r--r-- | ethchain/keypair.go | 87 | ||||
-rw-r--r-- | ethchain/state_manager.go | 1 | ||||
-rw-r--r-- | ethchain/transaction_pool.go | 17 |
3 files changed, 15 insertions, 90 deletions
diff --git a/ethchain/keypair.go b/ethchain/keypair.go deleted file mode 100644 index 0f23bacdf..000000000 --- a/ethchain/keypair.go +++ /dev/null @@ -1,87 +0,0 @@ -package ethchain - -import ( - "github.com/ethereum/eth-go/ethutil" - "github.com/obscuren/secp256k1-go" - "math/big" -) - -type KeyPair struct { - PrivateKey []byte - PublicKey []byte - - // The associated account - account *StateObject - state *State -} - -func NewKeyPairFromSec(seckey []byte) (*KeyPair, error) { - pubkey, err := secp256k1.GeneratePubKey(seckey) - if err != nil { - return nil, err - } - - 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()} - - return keyPair -} - -func (k *KeyPair) Address() []byte { - return ethutil.Sha3Bin(k.PublicKey[1:])[12:] -} - -func (k *KeyPair) Account() *StateObject { - 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 { - /* TODO - 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 - */ - return nil -} - -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 -} diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go index 8f1eb1ce5..57d56469b 100644 --- a/ethchain/state_manager.go +++ b/ethchain/state_manager.go @@ -200,6 +200,7 @@ func (sm *StateManager) ProcessBlock(block *Block, dontReact bool) error { sm.Ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{block.Value().Val}) + sm.Ethereum.TxPool().RemoveInvalid(sm.procState) } else { fmt.Println("total diff failed") } diff --git a/ethchain/transaction_pool.go b/ethchain/transaction_pool.go index 56deae0c6..6c0282dc6 100644 --- a/ethchain/transaction_pool.go +++ b/ethchain/transaction_pool.go @@ -210,9 +210,9 @@ func (pool *TxPool) CurrentTransactions() []*Transaction { txList := make([]*Transaction, pool.pool.Len()) i := 0 for e := pool.pool.Front(); e != nil; e = e.Next() { - if tx, ok := e.Value.(*Transaction); ok { - txList[i] = tx - } + tx := e.Value.(*Transaction) + + txList[i] = tx i++ } @@ -220,6 +220,17 @@ func (pool *TxPool) CurrentTransactions() []*Transaction { return txList } +func (pool *TxPool) RemoveInvalid(state *State) { + for e := pool.pool.Front(); e != nil; e = e.Next() { + tx := e.Value.(*Transaction) + sender := state.GetAccount(tx.Sender()) + err := pool.ValidateTransaction(tx) + if err != nil || sender.Nonce != tx.Nonce { + pool.pool.Remove(e) + } + } +} + func (pool *TxPool) Flush() []*Transaction { txList := pool.CurrentTransactions() |