Browse Source

proper string formatting for txs

pull/39/head
Jae Kwon 10 years ago
parent
commit
3f159dab69
8 changed files with 63 additions and 8 deletions
  1. +4
    -0
      account/priv_account.go
  2. +5
    -0
      account/privkey.go
  3. +9
    -0
      account/pubkey.go
  4. +29
    -0
      block/tx.go
  5. +6
    -2
      common/repeat_timer.go
  6. +6
    -2
      common/throttle_timer.go
  7. +3
    -3
      p2p/connection.go
  8. +1
    -1
      p2p/pex_reactor.go

+ 4
- 0
account/priv_account.go View File

@ -23,3 +23,7 @@ func GenPrivAccount() *PrivAccount {
func (privAccount *PrivAccount) Sign(o Signable) Signature { func (privAccount *PrivAccount) Sign(o Signable) Signature {
return privAccount.PrivKey.Sign(SignBytes(o)) return privAccount.PrivKey.Sign(SignBytes(o))
} }
func (privAccount *PrivAccount) String() string {
return Fmt("PrivAccount{%X}", privAccount.Address)
}

+ 5
- 0
account/privkey.go View File

@ -5,6 +5,7 @@ import (
"github.com/tendermint/go-ed25519" "github.com/tendermint/go-ed25519"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
) )
// PrivKey is part of PrivAccount and state.PrivValidator. // PrivKey is part of PrivAccount and state.PrivValidator.
@ -46,3 +47,7 @@ func (key PrivKeyEd25519) Sign(msg []byte) Signature {
func (key PrivKeyEd25519) PubKey() PubKey { func (key PrivKeyEd25519) PubKey() PubKey {
return PubKeyEd25519(ed25519.MakePubKey(key)) return PubKeyEd25519(ed25519.MakePubKey(key))
} }
func (key PrivKeyEd25519) String() string {
return Fmt("PrivKeyEd25519{*****}")
}

+ 9
- 0
account/pubkey.go View File

@ -5,6 +5,7 @@ import (
"github.com/tendermint/go-ed25519" "github.com/tendermint/go-ed25519"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
) )
// PubKey is part of Account and Validator. // PubKey is part of Account and Validator.
@ -42,6 +43,10 @@ func (key PubKeyNil) VerifyBytes(msg []byte, sig_ Signature) bool {
panic("PubKeyNil cannot verify messages") panic("PubKeyNil cannot verify messages")
} }
func (key PubKeyNil) String() string {
return "PubKeyNil{}"
}
//------------------------------------- //-------------------------------------
// Implements PubKey // Implements PubKey
@ -71,3 +76,7 @@ func (key PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool {
} }
return ed25519.VerifyBatch([]*ed25519.Verify{v1}) return ed25519.VerifyBatch([]*ed25519.Verify{v1})
} }
func (key PubKeyEd25519) String() string {
return Fmt("PubKeyEd25519{%X}", []byte(key))
}

+ 29
- 0
block/tx.go View File

@ -6,6 +6,7 @@ import (
"github.com/tendermint/tendermint/account" "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
) )
var ( var (
@ -82,6 +83,10 @@ func (txIn *TxInput) WriteSignBytes(w io.Writer, n *int64, err *error) {
binary.WriteUvarint(txIn.Sequence, w, n, err) binary.WriteUvarint(txIn.Sequence, w, n, err)
} }
func (txIn *TxInput) String() string {
return Fmt("TxInput{%X,%v,%v,%v,%v}", txIn.Address, txIn.Amount, txIn.Sequence, txIn.Signature, txIn.PubKey)
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type TxOutput struct { type TxOutput struct {
@ -104,6 +109,10 @@ func (txOut *TxOutput) WriteSignBytes(w io.Writer, n *int64, err *error) {
binary.WriteUint64(txOut.Amount, w, n, err) binary.WriteUint64(txOut.Amount, w, n, err)
} }
func (txOut *TxOutput) String() string {
return Fmt("TxOutput{%X,%v}", txOut.Address, txOut.Amount)
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type SendTx struct { type SendTx struct {
@ -124,6 +133,10 @@ func (tx *SendTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
} }
} }
func (tx *SendTx) String() string {
return Fmt("SendTx{%v -> %v}", tx.Inputs, tx.Outputs)
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type BondTx struct { type BondTx struct {
@ -146,6 +159,10 @@ func (tx *BondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
} }
} }
func (tx *BondTx) String() string {
return Fmt("BondTx{%v: %v -> %v}", tx.PubKey, tx.Inputs, tx.UnbondTo)
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type UnbondTx struct { type UnbondTx struct {
@ -161,6 +178,10 @@ func (tx *UnbondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
binary.WriteUvarint(tx.Height, w, n, err) binary.WriteUvarint(tx.Height, w, n, err)
} }
func (tx *UnbondTx) String() string {
return Fmt("UnbondTx{%X,%v,%v}", tx.Address, tx.Height, tx.Signature)
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type RebondTx struct { type RebondTx struct {
@ -176,6 +197,10 @@ func (tx *RebondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
binary.WriteUvarint(tx.Height, w, n, err) binary.WriteUvarint(tx.Height, w, n, err)
} }
func (tx *RebondTx) String() string {
return Fmt("RebondTx{%X,%v,%v}", tx.Address, tx.Height, tx.Signature)
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type DupeoutTx struct { type DupeoutTx struct {
@ -189,3 +214,7 @@ func (tx *DupeoutTx) TypeByte() byte { return TxTypeDupeout }
func (tx *DupeoutTx) WriteSignBytes(w io.Writer, n *int64, err *error) { func (tx *DupeoutTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
panic("DupeoutTx has no sign bytes") panic("DupeoutTx has no sign bytes")
} }
func (tx *DupeoutTx) String() string {
return Fmt("DupeoutTx{%X,%v,%v}", tx.Address, tx.VoteA, tx.VoteB)
}

+ 6
- 2
common/repeat_timer.go View File

@ -7,16 +7,17 @@ RepeatTimer repeatedly sends a struct{}{} to .Ch after each "dur" period.
It's good for keeping connections alive. It's good for keeping connections alive.
*/ */
type RepeatTimer struct { type RepeatTimer struct {
Name string
Ch chan struct{} Ch chan struct{}
quit chan struct{} quit chan struct{}
dur time.Duration dur time.Duration
timer *time.Timer timer *time.Timer
} }
func NewRepeatTimer(dur time.Duration) *RepeatTimer {
func NewRepeatTimer(name string, dur time.Duration) *RepeatTimer {
var ch = make(chan struct{}) var ch = make(chan struct{})
var quit = make(chan struct{}) var quit = make(chan struct{})
var t = &RepeatTimer{Ch: ch, dur: dur, quit: quit}
var t = &RepeatTimer{Name: name, Ch: ch, dur: dur, quit: quit}
t.timer = time.AfterFunc(dur, t.fireRoutine) t.timer = time.AfterFunc(dur, t.fireRoutine)
return t return t
} }
@ -26,6 +27,9 @@ func (t *RepeatTimer) fireRoutine() {
case t.Ch <- struct{}{}: case t.Ch <- struct{}{}:
t.timer.Reset(t.dur) t.timer.Reset(t.dur)
case <-t.quit: case <-t.quit:
// do nothing
default:
t.timer.Reset(t.dur)
} }
} }


+ 6
- 2
common/throttle_timer.go View File

@ -12,6 +12,7 @@ If a long continuous burst of .Set() calls happens, ThrottleTimer fires
at most once every "dur". at most once every "dur".
*/ */
type ThrottleTimer struct { type ThrottleTimer struct {
Name string
Ch chan struct{} Ch chan struct{}
quit chan struct{} quit chan struct{}
dur time.Duration dur time.Duration
@ -19,10 +20,10 @@ type ThrottleTimer struct {
isSet uint32 isSet uint32
} }
func NewThrottleTimer(dur time.Duration) *ThrottleTimer {
func NewThrottleTimer(name string, dur time.Duration) *ThrottleTimer {
var ch = make(chan struct{}) var ch = make(chan struct{})
var quit = make(chan struct{}) var quit = make(chan struct{})
var t = &ThrottleTimer{Ch: ch, dur: dur, quit: quit}
var t = &ThrottleTimer{Name: name, Ch: ch, dur: dur, quit: quit}
t.timer = time.AfterFunc(dur, t.fireRoutine) t.timer = time.AfterFunc(dur, t.fireRoutine)
t.timer.Stop() t.timer.Stop()
return t return t
@ -33,6 +34,9 @@ func (t *ThrottleTimer) fireRoutine() {
case t.Ch <- struct{}{}: case t.Ch <- struct{}{}:
atomic.StoreUint32(&t.isSet, 0) atomic.StoreUint32(&t.isSet, 0)
case <-t.quit: case <-t.quit:
// do nothing
default:
t.timer.Reset(t.dur)
} }
} }


+ 3
- 3
p2p/connection.go View File

@ -93,12 +93,12 @@ func NewMConnection(conn net.Conn, chDescs []*ChannelDescriptor, onReceive recei
recvMonitor: flow.New(0, 0), recvMonitor: flow.New(0, 0),
sendRate: defaultSendRate, sendRate: defaultSendRate,
recvRate: defaultRecvRate, recvRate: defaultRecvRate,
flushTimer: NewThrottleTimer(flushThrottleMS * time.Millisecond),
flushTimer: NewThrottleTimer("flush", flushThrottleMS*time.Millisecond),
send: make(chan struct{}, 1), send: make(chan struct{}, 1),
quit: make(chan struct{}), quit: make(chan struct{}),
pingTimer: NewRepeatTimer(pingTimeoutMinutes * time.Minute),
pingTimer: NewRepeatTimer("ping", pingTimeoutMinutes*time.Minute),
pong: make(chan struct{}), pong: make(chan struct{}),
chStatsTimer: NewRepeatTimer(updateStatsSeconds * time.Second),
chStatsTimer: NewRepeatTimer("chStats", updateStatsSeconds*time.Second),
onReceive: onReceive, onReceive: onReceive,
onError: onError, onError: onError,
LocalAddress: NewNetAddress(conn.LocalAddr()), LocalAddress: NewNetAddress(conn.LocalAddr()),


+ 1
- 1
p2p/pex_reactor.go View File

@ -133,7 +133,7 @@ func (pexR *PEXReactor) ensurePeersRoutine() {
// fire once immediately. // fire once immediately.
pexR.ensurePeers() pexR.ensurePeers()
// fire periodically // fire periodically
timer := NewRepeatTimer(ensurePeersPeriodSeconds * time.Second)
timer := NewRepeatTimer("pex", ensurePeersPeriodSeconds*time.Second)
FOR_LOOP: FOR_LOOP:
for { for {
select { select {


Loading…
Cancel
Save