refactor from Binary centric model to global method model

This commit is contained in:
Jae Kwon
2014-09-03 20:41:57 -07:00
parent d0ec18dc16
commit e53b148acf
23 changed files with 624 additions and 692 deletions
+10 -10
View File
@@ -8,10 +8,10 @@ import (
// NOTE: consensus/Validator embeds this, so..
type Account struct {
Id uint64 // Numeric id of account, incrementing.
PubKey ByteSlice
PubKey []byte
}
func (self *Account) Verify(msg ByteSlice, sig ByteSlice) bool {
func (self *Account) Verify(msg []byte, sig []byte) bool {
return false
}
@@ -19,10 +19,10 @@ func (self *Account) Verify(msg ByteSlice, sig ByteSlice) bool {
type PrivAccount struct {
Account
PrivKey ByteSlice
PrivKey []byte
}
func (self *PrivAccount) Sign(msg ByteSlice) Signature {
func (self *PrivAccount) Sign(msg []byte) Signature {
return Signature{}
}
@@ -42,13 +42,13 @@ It usually follows the message to be signed.
type Signature struct {
SignerId uint64
Bytes ByteSlice
Bytes []byte
}
func ReadSignature(r io.Reader) Signature {
func ReadSignature(r io.Reader, n *int64, err *error) Signature {
return Signature{
SignerId: Readuint64(r),
Bytes: ReadByteSlice(r),
SignerId: ReadUInt64(r, n, err),
Bytes: ReadByteSlice(r, n, err),
}
}
@@ -57,7 +57,7 @@ func (sig Signature) IsZero() bool {
}
func (sig Signature) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(UInt64(sig.SignerId), w, n, err)
n, err = WriteTo(sig.Bytes, w, n, err)
WriteUInt64(w, sig.SignerId, &n, &err)
WriteByteSlice(w, sig.Bytes, &n, &err)
return
}
+45 -45
View File
@@ -16,41 +16,41 @@ import (
TODO: signing a bad checkpoint (block)
*/
type Adjustment interface {
Type() Byte
Type() byte
Binary
}
const (
ADJ_TYPE_BOND = Byte(0x01)
ADJ_TYPE_UNBOND = Byte(0x02)
ADJ_TYPE_TIMEOUT = Byte(0x03)
ADJ_TYPE_DUPEOUT = Byte(0x04)
ADJ_TYPE_BOND = byte(0x01)
ADJ_TYPE_UNBOND = byte(0x02)
ADJ_TYPE_TIMEOUT = byte(0x03)
ADJ_TYPE_DUPEOUT = byte(0x04)
)
func ReadAdjustment(r io.Reader) Adjustment {
switch t := ReadByte(r); t {
func ReadAdjustment(r io.Reader, n *int64, err *error) Adjustment {
switch t := ReadByte(r, n, err); t {
case ADJ_TYPE_BOND:
return &Bond{
Fee: Readuint64(r),
UnbondTo: Readuint64(r),
Amount: Readuint64(r),
Signature: ReadSignature(r),
Fee: ReadUInt64(r, n, err),
UnbondTo: ReadUInt64(r, n, err),
Amount: ReadUInt64(r, n, err),
Signature: ReadSignature(r, n, err),
}
case ADJ_TYPE_UNBOND:
return &Unbond{
Fee: Readuint64(r),
Amount: Readuint64(r),
Signature: ReadSignature(r),
Fee: ReadUInt64(r, n, err),
Amount: ReadUInt64(r, n, err),
Signature: ReadSignature(r, n, err),
}
case ADJ_TYPE_TIMEOUT:
return &Timeout{
AccountId: Readuint64(r),
Penalty: Readuint64(r),
AccountId: ReadUInt64(r, n, err),
Penalty: ReadUInt64(r, n, err),
}
case ADJ_TYPE_DUPEOUT:
return &Dupeout{
VoteA: ReadBlockVote(r),
VoteB: ReadBlockVote(r),
VoteA: ReadBlockVote(r, n, err),
VoteB: ReadBlockVote(r, n, err),
}
default:
Panicf("Unknown Adjustment type %x", t)
@@ -68,16 +68,16 @@ type Bond struct {
Signature
}
func (self *Bond) Type() Byte {
func (self *Bond) Type() byte {
return ADJ_TYPE_BOND
}
func (self *Bond) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(self.Type(), w, n, err)
n, err = WriteTo(UInt64(self.Fee), w, n, err)
n, err = WriteTo(UInt64(self.UnbondTo), w, n, err)
n, err = WriteTo(UInt64(self.Amount), w, n, err)
n, err = WriteTo(self.Signature, w, n, err)
WriteByte(w, self.Type(), &n, &err)
WriteUInt64(w, self.Fee, &n, &err)
WriteUInt64(w, self.UnbondTo, &n, &err)
WriteUInt64(w, self.Amount, &n, &err)
WriteBinary(w, self.Signature, &n, &err)
return
}
@@ -90,15 +90,15 @@ type Unbond struct {
Signature
}
func (self *Unbond) Type() Byte {
func (self *Unbond) Type() byte {
return ADJ_TYPE_UNBOND
}
func (self *Unbond) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(self.Type(), w, n, err)
n, err = WriteTo(UInt64(self.Fee), w, n, err)
n, err = WriteTo(UInt64(self.Amount), w, n, err)
n, err = WriteTo(self.Signature, w, n, err)
WriteByte(w, self.Type(), &n, &err)
WriteUInt64(w, self.Fee, &n, &err)
WriteUInt64(w, self.Amount, &n, &err)
WriteBinary(w, self.Signature, &n, &err)
return
}
@@ -110,14 +110,14 @@ type Timeout struct {
Penalty uint64
}
func (self *Timeout) Type() Byte {
func (self *Timeout) Type() byte {
return ADJ_TYPE_TIMEOUT
}
func (self *Timeout) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(self.Type(), w, n, err)
n, err = WriteTo(UInt64(self.AccountId), w, n, err)
n, err = WriteTo(UInt64(self.Penalty), w, n, err)
WriteByte(w, self.Type(), &n, &err)
WriteUInt64(w, self.AccountId, &n, &err)
WriteUInt64(w, self.Penalty, &n, &err)
return
}
@@ -129,22 +129,22 @@ Typically only the signature is passed around, as the hash & height are implied.
*/
type BlockVote struct {
Height uint64
BlockHash ByteSlice
BlockHash []byte
Signature
}
func ReadBlockVote(r io.Reader) BlockVote {
func ReadBlockVote(r io.Reader, n *int64, err *error) BlockVote {
return BlockVote{
Height: Readuint64(r),
BlockHash: ReadByteSlice(r),
Signature: ReadSignature(r),
Height: ReadUInt64(r, n, err),
BlockHash: ReadByteSlice(r, n, err),
Signature: ReadSignature(r, n, err),
}
}
func (self BlockVote) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(UInt64(self.Height), w, n, err)
n, err = WriteTo(self.BlockHash, w, n, err)
n, err = WriteTo(self.Signature, w, n, err)
WriteUInt64(w, self.Height, &n, &err)
WriteByteSlice(w, self.BlockHash, &n, &err)
WriteBinary(w, self.Signature, &n, &err)
return
}
@@ -154,13 +154,13 @@ type Dupeout struct {
VoteB BlockVote
}
func (self *Dupeout) Type() Byte {
func (self *Dupeout) Type() byte {
return ADJ_TYPE_DUPEOUT
}
func (self *Dupeout) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(self.Type(), w, n, err)
n, err = WriteTo(self.VoteA, w, n, err)
n, err = WriteTo(self.VoteB, w, n, err)
WriteByte(w, self.Type(), &n, &err)
WriteBinary(w, self.VoteA, &n, &err)
WriteBinary(w, self.VoteB, &n, &err)
return
}
+65 -61
View File
@@ -4,6 +4,7 @@ import (
"crypto/sha256"
"fmt"
"io"
"time"
. "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
@@ -32,18 +33,18 @@ type Block struct {
hash []byte
}
func ReadBlock(r io.Reader) *Block {
func ReadBlock(r io.Reader, n *int64, err *error) *Block {
return &Block{
Header: ReadHeader(r),
Validation: ReadValidation(r),
Txs: ReadTxs(r),
Header: ReadHeader(r, n, err),
Validation: ReadValidation(r, n, err),
Txs: ReadTxs(r, n, err),
}
}
func (b *Block) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(&b.Header, w, n, err)
n, err = WriteTo(&b.Validation, w, n, err)
n, err = WriteTo(&b.Txs, w, n, err)
WriteBinary(w, &b.Header, &n, &err)
WriteBinary(w, &b.Validation, &n, &err)
WriteBinary(w, &b.Txs, &n, &err)
return
}
@@ -54,20 +55,20 @@ func (b *Block) ValidateBasic() error {
}
func (b *Block) URI() string {
return CalcBlockURI(uint32(b.Height), b.Hash())
return CalcBlockURI(b.Height, b.Hash())
}
func (b *Block) Hash() []byte {
if b.hash != nil {
return b.hash
} else {
hashes := []Binary{
ByteSlice(b.Header.Hash()),
ByteSlice(b.Validation.Hash()),
ByteSlice(b.Txs.Hash()),
hashes := [][]byte{
b.Header.Hash(),
b.Validation.Hash(),
b.Txs.Hash(),
}
// Merkle hash from sub-hashes.
return merkle.HashFromBinarySlice(hashes)
return merkle.HashFromByteSlices(hashes)
}
}
@@ -104,31 +105,31 @@ type BlockPart struct {
Round uint16 // Add Round? Well I need to know...
Index uint16
Total uint16
Bytes ByteSlice
Bytes []byte
Signature
// Volatile
hash []byte
}
func ReadBlockPart(r io.Reader) *BlockPart {
func ReadBlockPart(r io.Reader, n *int64, err *error) *BlockPart {
return &BlockPart{
Height: Readuint32(r),
Round: Readuint16(r),
Index: Readuint16(r),
Total: Readuint16(r),
Bytes: ReadByteSlice(r),
Signature: ReadSignature(r),
Height: ReadUInt32(r, n, err),
Round: ReadUInt16(r, n, err),
Index: ReadUInt16(r, n, err),
Total: ReadUInt16(r, n, err),
Bytes: ReadByteSlice(r, n, err),
Signature: ReadSignature(r, n, err),
}
}
func (bp *BlockPart) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(UInt32(bp.Height), w, n, err)
n, err = WriteTo(UInt16(bp.Round), w, n, err)
n, err = WriteTo(UInt16(bp.Index), w, n, err)
n, err = WriteTo(UInt16(bp.Total), w, n, err)
n, err = WriteTo(bp.Bytes, w, n, err)
n, err = WriteTo(bp.Signature, w, n, err)
WriteUInt32(w, bp.Height, &n, &err)
WriteUInt16(w, bp.Round, &n, &err)
WriteUInt16(w, bp.Index, &n, &err)
WriteUInt16(w, bp.Total, &n, &err)
WriteByteSlice(w, bp.Bytes, &n, &err)
WriteBinary(w, bp.Signature, &n, &err)
return
}
@@ -173,38 +174,41 @@ func (bp *BlockPart) ValidateWithSigner(signer *Account) error {
/* Header is part of a Block */
type Header struct {
Name String
Name string
Height uint32
Fees uint64
Time Time
PrevHash ByteSlice
ValidationHash ByteSlice
TxsHash ByteSlice
Time time.Time
PrevHash []byte
ValidationHash []byte
TxsHash []byte
// Volatile
hash []byte
}
func ReadHeader(r io.Reader) Header {
func ReadHeader(r io.Reader, n *int64, err *error) (h Header) {
if *err != nil {
return Header{}
}
return Header{
Name: ReadString(r),
Height: Readuint32(r),
Fees: Readuint64(r),
Time: ReadTime(r),
PrevHash: ReadByteSlice(r),
ValidationHash: ReadByteSlice(r),
TxsHash: ReadByteSlice(r),
Name: ReadString(r, n, err),
Height: ReadUInt32(r, n, err),
Fees: ReadUInt64(r, n, err),
Time: ReadTime(r, n, err),
PrevHash: ReadByteSlice(r, n, err),
ValidationHash: ReadByteSlice(r, n, err),
TxsHash: ReadByteSlice(r, n, err),
}
}
func (h *Header) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(h.Name, w, n, err)
n, err = WriteTo(UInt32(h.Height), w, n, err)
n, err = WriteTo(UInt64(h.Fees), w, n, err)
n, err = WriteTo(h.Time, w, n, err)
n, err = WriteTo(h.PrevHash, w, n, err)
n, err = WriteTo(h.ValidationHash, w, n, err)
n, err = WriteTo(h.TxsHash, w, n, err)
WriteString(w, h.Name, &n, &err)
WriteUInt32(w, h.Height, &n, &err)
WriteUInt64(w, h.Fees, &n, &err)
WriteTime(w, h.Time, &n, &err)
WriteByteSlice(w, h.PrevHash, &n, &err)
WriteByteSlice(w, h.ValidationHash, &n, &err)
WriteByteSlice(w, h.TxsHash, &n, &err)
return
}
@@ -231,16 +235,16 @@ type Validation struct {
hash []byte
}
func ReadValidation(r io.Reader) Validation {
numSigs := Readuint32(r)
numAdjs := Readuint32(r)
func ReadValidation(r io.Reader, n *int64, err *error) Validation {
numSigs := ReadUInt32(r, n, err)
numAdjs := ReadUInt32(r, n, err)
sigs := make([]Signature, 0, numSigs)
for i := uint32(0); i < numSigs; i++ {
sigs = append(sigs, ReadSignature(r))
sigs = append(sigs, ReadSignature(r, n, err))
}
adjs := make([]Adjustment, 0, numAdjs)
for i := uint32(0); i < numAdjs; i++ {
adjs = append(adjs, ReadAdjustment(r))
adjs = append(adjs, ReadAdjustment(r, n, err))
}
return Validation{
Signatures: sigs,
@@ -249,13 +253,13 @@ func ReadValidation(r io.Reader) Validation {
}
func (v *Validation) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(UInt32(len(v.Signatures)), w, n, err)
n, err = WriteTo(UInt32(len(v.Adjustments)), w, n, err)
WriteUInt32(w, uint32(len(v.Signatures)), &n, &err)
WriteUInt32(w, uint32(len(v.Adjustments)), &n, &err)
for _, sig := range v.Signatures {
n, err = WriteTo(sig, w, n, err)
WriteBinary(w, sig, &n, &err)
}
for _, adj := range v.Adjustments {
n, err = WriteTo(adj, w, n, err)
WriteBinary(w, adj, &n, &err)
}
return
}
@@ -282,19 +286,19 @@ type Txs struct {
hash []byte
}
func ReadTxs(r io.Reader) Txs {
numTxs := Readuint32(r)
func ReadTxs(r io.Reader, n *int64, err *error) Txs {
numTxs := ReadUInt32(r, n, err)
txs := make([]Tx, 0, numTxs)
for i := uint32(0); i < numTxs; i++ {
txs = append(txs, ReadTx(r))
txs = append(txs, ReadTx(r, n, err))
}
return Txs{Txs: txs}
}
func (txs *Txs) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(UInt32(len(txs.Txs)), w, n, err)
WriteUInt32(w, uint32(len(txs.Txs)), &n, &err)
for _, tx := range txs.Txs {
n, err = WriteTo(tx, w, n, err)
WriteBinary(w, tx, &n, &err)
}
return
}
+4 -2
View File
@@ -95,7 +95,7 @@ func (bps *BlockPartSet) AddBlockPart(part *BlockPart) (added bool, err error) {
// Check for existing parts.
existing := bps.parts[part.Index]
if existing != nil {
if existing.Bytes.Equals(part.Bytes) {
if bytes.Equal(existing.Bytes, part.Bytes) {
// Ignore duplicate
return false, nil
} else {
@@ -127,7 +127,9 @@ func (bps *BlockPartSet) Block() *Block {
for _, part := range bps.parts {
blockBytes = append(blockBytes, part.Bytes...)
}
block := ReadBlock(bytes.NewReader(blockBytes))
var n int64
var err error
block := ReadBlock(bytes.NewReader(blockBytes), &n, &err)
bps._block = block
}
return bps._block
+27 -25
View File
@@ -9,7 +9,7 @@ import (
)
// Distributed pseudo-exponentially to test for various cases
func randuint64() uint64 {
func randUInt64() uint64 {
bits := rand.Uint32() % 64
if bits == 0 {
return 0
@@ -19,7 +19,7 @@ func randuint64() uint64 {
return n
}
func randuint32() uint32 {
func randUInt32() uint32 {
bits := rand.Uint32() % 32
if bits == 0 {
return 0
@@ -29,18 +29,18 @@ func randuint32() uint32 {
return n
}
func randTime() Time {
return Time{time.Unix(int64(randuint64()), 0)}
func randTime() time.Time {
return time.Unix(int64(randUInt64()), 0)
}
func randAccount() Account {
return Account{
Id: randuint64(),
Id: randUInt64(),
PubKey: randBytes(32),
}
}
func randBytes(n int) ByteSlice {
func randBytes(n int) []byte {
bs := make([]byte, n)
for i := 0; i < n; i++ {
bs[i] = byte(rand.Intn(256))
@@ -49,7 +49,7 @@ func randBytes(n int) ByteSlice {
}
func randSig() Signature {
return Signature{randuint64(), randBytes(32)}
return Signature{randUInt64(), randBytes(32)}
}
func TestBlock(t *testing.T) {
@@ -58,15 +58,15 @@ func TestBlock(t *testing.T) {
sendTx := &SendTx{
Signature: randSig(),
Fee: randuint64(),
To: randuint64(),
Amount: randuint64(),
Fee: randUInt64(),
To: randUInt64(),
Amount: randUInt64(),
}
nameTx := &NameTx{
Signature: randSig(),
Fee: randuint64(),
Name: String(randBytes(12)),
Fee: randUInt64(),
Name: string(randBytes(12)),
PubKey: randBytes(32),
}
@@ -74,30 +74,30 @@ func TestBlock(t *testing.T) {
bond := &Bond{
Signature: randSig(),
Fee: randuint64(),
UnbondTo: randuint64(),
Amount: randuint64(),
Fee: randUInt64(),
UnbondTo: randUInt64(),
Amount: randUInt64(),
}
unbond := &Unbond{
Signature: randSig(),
Fee: randuint64(),
Amount: randuint64(),
Fee: randUInt64(),
Amount: randUInt64(),
}
timeout := &Timeout{
AccountId: randuint64(),
Penalty: randuint64(),
AccountId: randUInt64(),
Penalty: randUInt64(),
}
dupeout := &Dupeout{
VoteA: BlockVote{
Height: randuint64(),
Height: randUInt64(),
BlockHash: randBytes(32),
Signature: randSig(),
},
VoteB: BlockVote{
Height: randuint64(),
Height: randUInt64(),
BlockHash: randBytes(32),
Signature: randSig(),
},
@@ -108,8 +108,8 @@ func TestBlock(t *testing.T) {
block := &Block{
Header: Header{
Name: "Tendermint",
Height: randuint32(),
Fees: randuint64(),
Height: randUInt32(),
Fees: randUInt64(),
Time: randTime(),
PrevHash: randBytes(32),
ValidationHash: randBytes(32),
@@ -129,10 +129,12 @@ func TestBlock(t *testing.T) {
// Then, compare.
blockBytes := BinaryBytes(block)
block2 := ReadBlock(bytes.NewReader(blockBytes))
var n int64
var err error
block2 := ReadBlock(bytes.NewReader(blockBytes), &n, &err)
blockBytes2 := BinaryBytes(block2)
if !BinaryEqual(blockBytes, blockBytes2) {
if !bytes.Equal(blockBytes, blockBytes2) {
t.Fatal("Write->Read of block failed.")
}
}
+11 -9
View File
@@ -5,8 +5,8 @@ import (
"encoding/gob"
"encoding/json"
"testing"
"time"
. "github.com/tendermint/tendermint/binary"
"github.com/ugorji/go/codec"
"github.com/vmihailenco/msgpack"
)
@@ -18,10 +18,10 @@ func BenchmarkTestCustom(b *testing.B) {
Name: "Header",
Height: 123,
Fees: 123,
Time: TimeFromUnix(123),
PrevHash: ByteSlice("prevhash"),
ValidationHash: ByteSlice("validationhash"),
TxsHash: ByteSlice("txshash"),
Time: time.Unix(123, 0),
PrevHash: []byte("prevhash"),
ValidationHash: []byte("validationhash"),
TxsHash: []byte("txshash"),
}
buf := bytes.NewBuffer(nil)
@@ -30,7 +30,9 @@ func BenchmarkTestCustom(b *testing.B) {
for i := 0; i < b.N; i++ {
buf.Reset()
h.WriteTo(buf)
h2 := ReadHeader(buf)
var n int64
var err error
h2 := ReadHeader(buf, &n, &err)
if h2.Name != "Header" {
b.Fatalf("wrong name")
}
@@ -83,7 +85,7 @@ func BenchmarkTestGob(b *testing.B) {
Name: "Header",
Height: 123,
Fees: 123,
Time: TimeFromUnix(123),
Time: time.Unix(123, 0),
PrevHash: []byte("prevhash"),
ValidationHash: []byte("validationhash"),
TxsHash: []byte("txshash"),
@@ -112,7 +114,7 @@ func BenchmarkTestMsgPack(b *testing.B) {
Name: "Header",
Height: 123,
Fees: 123,
Time: TimeFromUnix(123),
Time: time.Unix(123, 0),
PrevHash: []byte("prevhash"),
ValidationHash: []byte("validationhash"),
TxsHash: []byte("txshash"),
@@ -141,7 +143,7 @@ func BenchmarkTestMsgPack2(b *testing.B) {
Name: "Header",
Height: 123,
Fees: 123,
Time: TimeFromUnix(123),
Time: time.Unix(123, 0),
PrevHash: []byte("prevhash"),
ValidationHash: []byte("validationhash"),
TxsHash: []byte("txshash"),
+2 -6
View File
@@ -79,7 +79,8 @@ func (bs *BlockStore) LoadBlockPart(height uint32, index uint16) *BlockPart {
if partBytes == nil {
return nil
}
return ReadBlockPart(bytes.NewReader(partBytes))
var n int64
return ReadBlockPart(bytes.NewReader(partBytes), &n, &err)
}
// Convenience method for loading block parts and merging to a block.
@@ -93,11 +94,6 @@ func (bs *BlockStore) LoadBlock(height uint32) *Block {
panic("TODO: Not implemented")
}
func (bs *BlockStore) StageBlockAndParts(block *Block, parts []*BlockPart) error {
// XXX validate
return nil
}
// NOTE: Assumes that parts as well as the block are valid. See StageBlockParts().
// Writes are synchronous and atomic.
func (bs *BlockStore) SaveBlockParts(height uint32, parts []*BlockPart) error {
+27 -27
View File
@@ -21,30 +21,30 @@ Tx wire format:
*/
type Tx interface {
Type() Byte
Type() byte
Binary
}
const (
TX_TYPE_SEND = Byte(0x01)
TX_TYPE_NAME = Byte(0x02)
TX_TYPE_SEND = byte(0x01)
TX_TYPE_NAME = byte(0x02)
)
func ReadTx(r io.Reader) Tx {
switch t := ReadByte(r); t {
func ReadTx(r io.Reader, n *int64, err *error) Tx {
switch t := ReadByte(r, n, err); t {
case TX_TYPE_SEND:
return &SendTx{
Fee: Readuint64(r),
To: Readuint64(r),
Amount: Readuint64(r),
Signature: ReadSignature(r),
Fee: ReadUInt64(r, n, err),
To: ReadUInt64(r, n, err),
Amount: ReadUInt64(r, n, err),
Signature: ReadSignature(r, n, err),
}
case TX_TYPE_NAME:
return &NameTx{
Fee: Readuint64(r),
Name: ReadString(r),
PubKey: ReadByteSlice(r),
Signature: ReadSignature(r),
Fee: ReadUInt64(r, n, err),
Name: ReadString(r, n, err),
PubKey: ReadByteSlice(r, n, err),
Signature: ReadSignature(r, n, err),
}
default:
Panicf("Unknown Tx type %x", t)
@@ -61,16 +61,16 @@ type SendTx struct {
Signature
}
func (self *SendTx) Type() Byte {
func (self *SendTx) Type() byte {
return TX_TYPE_SEND
}
func (self *SendTx) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(self.Type(), w, n, err)
n, err = WriteTo(UInt64(self.Fee), w, n, err)
n, err = WriteTo(UInt64(self.To), w, n, err)
n, err = WriteTo(UInt64(self.Amount), w, n, err)
n, err = WriteTo(self.Signature, w, n, err)
WriteByte(w, self.Type(), &n, &err)
WriteUInt64(w, self.Fee, &n, &err)
WriteUInt64(w, self.To, &n, &err)
WriteUInt64(w, self.Amount, &n, &err)
WriteBinary(w, self.Signature, &n, &err)
return
}
@@ -78,20 +78,20 @@ func (self *SendTx) WriteTo(w io.Writer) (n int64, err error) {
type NameTx struct {
Fee uint64
Name String
PubKey ByteSlice
Name string
PubKey []byte
Signature
}
func (self *NameTx) Type() Byte {
func (self *NameTx) Type() byte {
return TX_TYPE_NAME
}
func (self *NameTx) WriteTo(w io.Writer) (n int64, err error) {
n, err = WriteTo(self.Type(), w, n, err)
n, err = WriteTo(UInt64(self.Fee), w, n, err)
n, err = WriteTo(self.Name, w, n, err)
n, err = WriteTo(self.PubKey, w, n, err)
n, err = WriteTo(self.Signature, w, n, err)
WriteByte(w, self.Type(), &n, &err)
WriteUInt64(w, self.Fee, &n, &err)
WriteString(w, self.Name, &n, &err)
WriteByteSlice(w, self.PubKey, &n, &err)
WriteBinary(w, self.Signature, &n, &err)
return
}