Refactor Tx, Validator, and Account structure

This commit is contained in:
Jae Kwon
2014-12-16 05:45:40 -08:00
parent 4424a85fbd
commit 83d313cbe5
56 changed files with 1917 additions and 2022 deletions
+2 -2
View File
@@ -59,14 +59,14 @@ func (mem *Mempool) ResetForBlockAndState(block *Block, state *state.State) {
// First, create a lookup map of txns in new block.
blockTxsMap := make(map[string]struct{})
for _, tx := range block.Data.Txs {
txHash := BinaryHash(tx)
txHash := BinarySha256(tx)
blockTxsMap[string(txHash)] = struct{}{}
}
// Next, filter all txs from mem.txs that are in blockTxsMap
txs := []Tx{}
for _, tx := range mem.txs {
txHash := BinaryHash(tx)
txHash := BinarySha256(tx)
if _, ok := blockTxsMap[string(txHash)]; ok {
continue
} else {
+2 -15
View File
@@ -3,7 +3,6 @@ package mempool
import (
"bytes"
"fmt"
"io"
"sync/atomic"
. "github.com/tendermint/tendermint/binary"
@@ -119,12 +118,10 @@ const (
// TODO: check for unnecessary extra bytes at the end.
func decodeMessage(bz []byte) (msgType byte, msg interface{}) {
n, err := new(int64), new(error)
// log.Debug("decoding msg bytes: %X", bz)
msgType = bz[0]
switch msgType {
case msgTypeTx:
msg = readTxMessage(bytes.NewReader(bz[1:]), n, err)
// case ...:
msg = ReadBinary(&TxMessage{}, bytes.NewReader(bz[1:]), n, err)
default:
msg = nil
}
@@ -137,17 +134,7 @@ type TxMessage struct {
Tx Tx
}
func readTxMessage(r io.Reader, n *int64, err *error) *TxMessage {
return &TxMessage{
Tx: ReadTx(r, n, err),
}
}
func (m *TxMessage) WriteTo(w io.Writer) (n int64, err error) {
WriteByte(w, msgTypeTx, &n, &err)
WriteBinary(w, m.Tx, &n, &err)
return
}
func (m *TxMessage) TypeByte() byte { return msgTypeTx }
func (m *TxMessage) String() string {
return fmt.Sprintf("[TxMessage %v]", m.Tx)