Skip to content

Commit f92c833

Browse files
authored
Merge pull request #2162 from onflow/cf/tx-output
Improve tx output readability
2 parents a598c19 + 33a7f22 commit f92c833

1 file changed

Lines changed: 39 additions & 32 deletions

File tree

internal/transactions/transactions.go

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
"github.com/onflow/flowkit/v2/output"
3131

32+
"github.com/onflow/flow-cli/common/branding"
3233
"github.com/onflow/flow-cli/internal/command"
3334
"github.com/onflow/flow-cli/internal/events"
3435
"github.com/onflow/flow-cli/internal/util"
@@ -135,61 +136,67 @@ func (r *transactionResult) String() string {
135136
const feeDeductedEvent = "FeesDeducted"
136137

137138
if r.result != nil {
138-
_, _ = fmt.Fprintf(writer, "Block ID\t%s\n", r.result.BlockID)
139-
_, _ = fmt.Fprintf(writer, "Block Height\t%d\n", r.result.BlockHeight)
139+
_, _ = fmt.Fprintf(writer, "%s\t%s\n", branding.GrayStyle.Render("Block ID"), branding.PurpleStyle.Render(r.result.BlockID.String()))
140+
_, _ = fmt.Fprintf(writer, "%s\t%d\n", branding.GrayStyle.Render("Block Height"), r.result.BlockHeight)
140141
if r.result.Error != nil {
141-
_, _ = fmt.Fprintf(writer, "%s Transaction Error \n%s\n\n\n", output.ErrorEmoji(), r.result.Error.Error())
142+
_, _ = fmt.Fprintf(writer, "%s %s\n%s\n\n\n", output.ErrorEmoji(), branding.GrayStyle.Render("Transaction Error"), branding.ErrorStyle.Render(r.result.Error.Error()))
142143
}
143144

144145
statusBadge := ""
146+
statusText := r.result.Status.String()
145147
if r.result.Status == flow.TransactionStatusSealed {
146148
statusBadge = output.OkEmoji()
149+
statusText = branding.GreenStyle.Render(statusText)
147150
}
148-
_, _ = fmt.Fprintf(writer, "Status\t%s %s\n", statusBadge, r.result.Status)
151+
// leave uncolored for non-sealed statuses
152+
_, _ = fmt.Fprintf(writer, "%s\t%s %s\n", branding.GrayStyle.Render("Status"), statusBadge, statusText)
149153
}
150154

151-
_, _ = fmt.Fprintf(writer, "ID\t%s\n", r.tx.ID())
155+
_, _ = fmt.Fprintf(writer, "%s\t%s\n", branding.GrayStyle.Render("ID"), branding.PurpleStyle.Render(r.tx.ID().String()))
152156

153-
_, _ = fmt.Fprintf(writer, "Payer\t%s\n", r.tx.Payer.Hex())
154-
_, _ = fmt.Fprintf(writer, "Authorizers\t%s\n", r.tx.Authorizers)
157+
_, _ = fmt.Fprintf(writer, "%s\t%s\n", branding.GrayStyle.Render("Payer"), branding.PurpleStyle.Render(r.tx.Payer.Hex()))
158+
_, _ = fmt.Fprintf(writer, "%s\t%s\n", branding.GrayStyle.Render("Authorizers"), branding.PurpleStyle.Render(fmt.Sprintf("%s", r.tx.Authorizers)))
155159

156160
_, _ = fmt.Fprintf(writer,
157-
"\nProposal Key:\t\n Address\t%s\n Index\t%v\n Sequence\t%v\n",
158-
r.tx.ProposalKey.Address, r.tx.ProposalKey.KeyIndex, r.tx.ProposalKey.SequenceNumber,
161+
"\n%s\t\n %s\t%s\n %s\t%v\n %s\t%v\n",
162+
branding.GrayStyle.Render("Proposal Key:"),
163+
branding.GrayStyle.Render("Address"), branding.PurpleStyle.Render(r.tx.ProposalKey.Address.String()),
164+
branding.GrayStyle.Render("Index"), r.tx.ProposalKey.KeyIndex,
165+
branding.GrayStyle.Render("Sequence"), r.tx.ProposalKey.SequenceNumber,
159166
)
160167

161168
if len(r.tx.PayloadSignatures) == 0 {
162-
_, _ = fmt.Fprintf(writer, "\nNo Payload Signatures\n")
169+
_, _ = fmt.Fprintf(writer, "\n%s\n", branding.GrayStyle.Render("No Payload Signatures"))
163170
}
164171

165172
if len(r.tx.EnvelopeSignatures) == 0 {
166-
_, _ = fmt.Fprintf(writer, "\nNo Envelope Signatures\n")
173+
_, _ = fmt.Fprintf(writer, "\n%s\n", branding.GrayStyle.Render("No Envelope Signatures"))
167174
}
168175

169176
for i, e := range r.tx.PayloadSignatures {
170177
if command.ContainsFlag(r.include, "signatures") {
171-
_, _ = fmt.Fprintf(writer, "\nPayload Signature %v:\n", i)
172-
_, _ = fmt.Fprintf(writer, " Address\t%s\n", e.Address)
173-
_, _ = fmt.Fprintf(writer, " Signature\t%x\n", e.Signature)
174-
_, _ = fmt.Fprintf(writer, " Key Index\t%d\n", e.KeyIndex)
178+
_, _ = fmt.Fprintf(writer, "\n%s %d:\n", branding.GrayStyle.Render("Payload Signature"), i)
179+
_, _ = fmt.Fprintf(writer, " %s\t%s\n", branding.GrayStyle.Render("Address"), branding.PurpleStyle.Render(e.Address.String()))
180+
_, _ = fmt.Fprintf(writer, " %s\t%x\n", branding.GrayStyle.Render("Signature"), e.Signature)
181+
_, _ = fmt.Fprintf(writer, " %s\t%d\n", branding.GrayStyle.Render("Key Index"), e.KeyIndex)
175182
} else {
176-
_, _ = fmt.Fprintf(writer, "\nPayload Signature %v: %s", i, e.Address)
183+
_, _ = fmt.Fprintf(writer, "\n%s %d: %s", branding.GrayStyle.Render("Payload Signature"), i, branding.PurpleStyle.Render(e.Address.String()))
177184
}
178185
}
179186

180187
for i, e := range r.tx.EnvelopeSignatures {
181188
if command.ContainsFlag(r.include, "signatures") {
182-
_, _ = fmt.Fprintf(writer, "\nEnvelope Signature %v:\n", i)
183-
_, _ = fmt.Fprintf(writer, " Address\t%s\n", e.Address)
184-
_, _ = fmt.Fprintf(writer, " Signature\t%x\n", e.Signature)
185-
_, _ = fmt.Fprintf(writer, " Key Index\t%d\n", e.KeyIndex)
189+
_, _ = fmt.Fprintf(writer, "\n%s %d:\n", branding.GrayStyle.Render("Envelope Signature"), i)
190+
_, _ = fmt.Fprintf(writer, " %s\t%s\n", branding.GrayStyle.Render("Address"), branding.PurpleStyle.Render(e.Address.String()))
191+
_, _ = fmt.Fprintf(writer, " %s\t%x\n", branding.GrayStyle.Render("Signature"), e.Signature)
192+
_, _ = fmt.Fprintf(writer, " %s\t%d\n", branding.GrayStyle.Render("Key Index"), e.KeyIndex)
186193
} else {
187-
_, _ = fmt.Fprintf(writer, "\nEnvelope Signature %v: %s", i, e.Address)
194+
_, _ = fmt.Fprintf(writer, "\n%s %d: %s", branding.GrayStyle.Render("Envelope Signature"), i, branding.PurpleStyle.Render(e.Address.String()))
188195
}
189196
}
190197

191198
if !command.ContainsFlag(r.include, "signatures") {
192-
_, _ = fmt.Fprintf(writer, "\nSignatures (minimized, use --include signatures)")
199+
_, _ = fmt.Fprintf(writer, "\n%s", branding.GrayStyle.Render("Signatures (minimized, use --include signatures)"))
193200
}
194201

195202
if r.result != nil && !command.ContainsFlag(r.exclude, "events") {
@@ -212,38 +219,38 @@ func (r *transactionResult) String() string {
212219
eventsOutput = "None"
213220
}
214221

215-
_, _ = fmt.Fprintf(writer, "\n\nEvents:\t %s\n", eventsOutput)
222+
_, _ = fmt.Fprintf(writer, "\n\n%s\t %s\n", branding.GrayStyle.Render("Events:"), eventsOutput)
216223
}
217224

218225
if r.tx.Script != nil {
219226
if command.ContainsFlag(r.include, "code") {
220227
if len(r.tx.Arguments) == 0 {
221-
_, _ = fmt.Fprintf(writer, "\n\nArguments\tNo arguments\n")
228+
_, _ = fmt.Fprintf(writer, "\n\n%s\tNo arguments\n", branding.GrayStyle.Render("Arguments"))
222229
} else {
223-
_, _ = fmt.Fprintf(writer, "\n\nArguments (%d):\n", len(r.tx.Arguments))
230+
_, _ = fmt.Fprintf(writer, "\n\n%s (%d)\n", branding.GrayStyle.Render("Arguments"), len(r.tx.Arguments))
224231
for i, argument := range r.tx.Arguments {
225-
_, _ = fmt.Fprintf(writer, " - Argument %d: %s\n", i, argument)
232+
_, _ = fmt.Fprintf(writer, " - %s %d: %s\n", branding.GrayStyle.Render("Argument"), i, string(argument))
226233
}
227234
}
228235

229-
_, _ = fmt.Fprintf(writer, "\nCode\n\n%s\n", r.tx.Script)
236+
_, _ = fmt.Fprintf(writer, "\n%s\n\n%s\n", branding.GrayStyle.Render("Code"), string(r.tx.Script))
230237
} else {
231-
_, _ = fmt.Fprint(writer, "\n\nCode (hidden, use --include code)")
238+
_, _ = fmt.Fprint(writer, "\n\n"+branding.GrayStyle.Render("Code (hidden, use --include code)"))
232239
}
233240
}
234241

235242
if command.ContainsFlag(r.include, "payload") {
236-
_, _ = fmt.Fprintf(writer, "\n\nPayload:\n%x", r.tx.Encode())
243+
_, _ = fmt.Fprintf(writer, "\n\n%s\n%x", branding.GrayStyle.Render("Payload"), r.tx.Encode())
237244
} else {
238-
_, _ = fmt.Fprint(writer, "\n\nPayload (hidden, use --include payload)")
245+
_, _ = fmt.Fprint(writer, "\n\n"+branding.GrayStyle.Render("Payload (hidden, use --include payload)"))
239246
}
240247

241248
if !command.ContainsFlag(r.include, "fee-events") && !command.ContainsFlag(r.exclude, "events") {
242-
_, _ = fmt.Fprint(writer, "\n\nFee Events (hidden, use --include fee-events)")
249+
_, _ = fmt.Fprint(writer, "\n\n"+branding.GrayStyle.Render("Fee Events (hidden, use --include fee-events)"))
243250
}
244251

245252
if blockExplorerLink := r.getBlockExplorerLink(); blockExplorerLink != "" {
246-
_, _ = fmt.Fprintf(writer, "\n\n🔗 View on Block Explorer:\n%s", blockExplorerLink)
253+
_, _ = fmt.Fprintf(writer, "\n\n%s\n%s", branding.GrayStyle.Render("🔗 View on Block Explorer:"), branding.PurpleStyle.Render(blockExplorerLink))
247254
}
248255

249256
_ = writer.Flush()

0 commit comments

Comments
 (0)