Refactor Tx, Validator, and Account structure

This commit is contained in:
Jae Kwon
2014-12-09 18:49:04 -08:00
parent 4424a85fbd
commit 83d313cbe5
56 changed files with 1922 additions and 2027 deletions

View File

@ -2,11 +2,8 @@ package common
import (
"fmt"
"io"
"math/rand"
"strings"
. "github.com/tendermint/tendermint/binary"
)
// Not goroutine safe
@ -19,47 +16,6 @@ func NewBitArray(bits uint) BitArray {
return BitArray{bits, make([]uint64, (bits+63)/64)}
}
func ReadBitArray(r io.Reader, n *int64, err *error) BitArray {
bits := ReadUVarInt(r, n, err)
if bits == 0 {
return BitArray{}
}
elemsWritten := ReadUVarInt(r, n, err)
if *err != nil {
return BitArray{}
}
bA := NewBitArray(bits)
for i := uint(0); i < elemsWritten; i++ {
bA.elems[i] = ReadUInt64(r, n, err)
if *err != nil {
return BitArray{}
}
}
return bA
}
func (bA BitArray) WriteTo(w io.Writer) (n int64, err error) {
WriteUVarInt(w, bA.bits, &n, &err)
if bA.bits == 0 {
return
}
// Count the last element > 0.
elemsToWrite := 0
for i, elem := range bA.elems {
if elem > 0 {
elemsToWrite = i + 1
}
}
WriteUVarInt(w, uint(elemsToWrite), &n, &err)
for i, elem := range bA.elems {
if i >= elemsToWrite {
break
}
WriteUInt64(w, elem, &n, &err)
}
return
}
func (bA BitArray) Size() uint {
return bA.bits
}