From 00db396b51916cd39786fa45067b7bd7218e4c59 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 8 Jan 2019 00:13:20 -0800 Subject: [PATCH] watchtower/wtwire/summary: adds message summaries --- watchtower/wtwire/summary.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 watchtower/wtwire/summary.go diff --git a/watchtower/wtwire/summary.go b/watchtower/wtwire/summary.go new file mode 100644 index 00000000..32f682b7 --- /dev/null +++ b/watchtower/wtwire/summary.go @@ -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 "" + } +}