watchtower/wtwire/summary: adds message summaries

This commit is contained in:
Conner Fromknecht 2019-01-08 00:13:20 -08:00
parent 53a181ce49
commit 00db396b51
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -0,0 +1,35 @@
package wtwire
import "fmt"
// MessageSummary creates a human-readable description of a given Message. If
// the type is unknown, an empty string is returned.
func MessageSummary(msg Message) string {
switch msg := msg.(type) {
case *Init:
return ""
case *CreateSession:
return fmt.Sprintf("blob_type=%s, max_updates=%d "+
"reward_rate=%d sweep_fee_rate=%d", msg.BlobType,
msg.MaxUpdates, msg.RewardRate, msg.SweepFeeRate)
case *CreateSessionReply:
return fmt.Sprintf("code=%d", msg.Code)
case *StateUpdate:
return fmt.Sprintf("seqnum=%d last_applied=%d is_complete=%d "+
"hint=%x", msg.SeqNum, msg.LastApplied, msg.IsComplete,
msg.Hint)
case *StateUpdateReply:
return fmt.Sprintf("code=%d last_applied=%d", msg.Code,
msg.LastApplied)
case *Error:
return fmt.Sprintf("code=%d", msg.Code)
default:
return ""
}
}