From f3f8764857e3d6067f12b3b43e5ec2339379f736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Fri, 26 Feb 2021 11:37:00 +0100 Subject: [PATCH 1/2] go/staking/api/token: Print token's symbol after the amount This is more consistent with how others present token amounts. --- .changelog/3784.breaking.1.md | 3 +++ go/staking/api/token/prettyprint.go | 2 +- go/staking/api/token/prettyprint_test.go | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 .changelog/3784.breaking.1.md diff --git a/.changelog/3784.breaking.1.md b/.changelog/3784.breaking.1.md new file mode 100644 index 00000000000..0fab5becf37 --- /dev/null +++ b/.changelog/3784.breaking.1.md @@ -0,0 +1,3 @@ +go/staking/api/token: Print token's symbol after the amount + +This is more consistent with how others present token amounts. diff --git a/go/staking/api/token/prettyprint.go b/go/staking/api/token/prettyprint.go index 129d740cfef..3cb047190a5 100644 --- a/go/staking/api/token/prettyprint.go +++ b/go/staking/api/token/prettyprint.go @@ -67,6 +67,6 @@ func PrettyPrintAmount(ctx context.Context, amount quantity.Quantity, w io.Write if useBaseUnits { fmt.Fprintf(w, "%s%s base units", sign, amount) } else { - fmt.Fprintf(w, "%s %s%s", symbol, sign, tokenAmount) + fmt.Fprintf(w, "%s%s %s", sign, tokenAmount, symbol) } } diff --git a/go/staking/api/token/prettyprint_test.go b/go/staking/api/token/prettyprint_test.go index d6c2b069636..ca8ca7d80aa 100644 --- a/go/staking/api/token/prettyprint_test.go +++ b/go/staking/api/token/prettyprint_test.go @@ -62,25 +62,25 @@ func TestPrettyPrintAmount(t *testing.T) { addSign bool sign string }{ - {"CORE 10000000000.0", quantity.NewFromUint64(10000000000000000000), true, "CORE", true, 9, false, ""}, - {"CORE 100.0", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, false, ""}, - {"CORE 7999217230.1196", quantity.NewFromUint64(7999217230119600000), true, "CORE", true, 9, false, ""}, - {"CORE 0.0", quantity.NewFromUint64(0), true, "CORE", true, 9, false, ""}, - {"CORE -100.0", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, true, "-"}, - {"CORE +100.0", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, true, "+"}, + {"10000000000.0 CORE", quantity.NewFromUint64(10000000000000000000), true, "CORE", true, 9, false, ""}, + {"100.0 CORE", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, false, ""}, + {"7999217230.1196 CORE", quantity.NewFromUint64(7999217230119600000), true, "CORE", true, 9, false, ""}, + {"0.0 CORE", quantity.NewFromUint64(0), true, "CORE", true, 9, false, ""}, + {"-100.0 CORE", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, true, "-"}, + {"+100.0 CORE", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, true, "+"}, // Check large and small token's value base-10 exponents. - {"BIG 10.0", quantity.NewFromUint64(10000000000000000000), true, "BIG", true, 18, false, ""}, - {"SMALL -10000000000000000001.0", quantity.NewFromUint64(10000000000000000001), true, "SMALL", true, 0, true, "-"}, + {"10.0 BIG", quantity.NewFromUint64(10000000000000000000), true, "BIG", true, 18, false, ""}, + {"-10000000000000000001.0 SMALL", quantity.NewFromUint64(10000000000000000001), true, "SMALL", true, 0, true, "-"}, // Check invalid token's value base-10 exponent. {"100000000 base units", quantity.NewFromUint64(100000000), true, "TOOBIG", true, 21, false, ""}, // Check invalid token's ticker symbol. {"-100000 base units", quantity.NewFromUint64(100000), true, "SOMETHINGLONG", true, 6, true, "-"}, {"100000 base units", quantity.NewFromUint64(100000), true, "", true, 6, false, ""}, // Check invalid token's value sign. - {"CORE 100.0", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, true, ""}, - {"CORE 100.0", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, true, "--"}, - {"CORE 100.0", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, true, "++"}, - {"CORE 100.0", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, true, "?"}, + {"100.0 CORE", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, true, ""}, + {"100.0 CORE", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, true, "--"}, + {"100.0 CORE", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, true, "++"}, + {"100.0 CORE", quantity.NewFromUint64(100000000000), true, "CORE", true, 9, true, "?"}, // Check missing combinations of token's symbol, value exponent and value sign. {"+100000 base units", quantity.NewFromUint64(100000), false, "MISSING", true, 6, true, "+"}, {"-100000 base units", quantity.NewFromUint64(100000), true, "NOEXP", false, 0, true, "-"}, From 25828b4f75145f1197139705869611abf38b88df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Tue, 16 Mar 2021 13:16:12 +0100 Subject: [PATCH 2/2] go/consensus/api/transaction: Print txn's method and body before rest This is more intuitive and enables people to discover the transaction's main information quicker. --- .changelog/3784.breaking.2.md | 4 ++++ go/consensus/api/transaction/transaction.go | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 .changelog/3784.breaking.2.md diff --git a/.changelog/3784.breaking.2.md b/.changelog/3784.breaking.2.md new file mode 100644 index 00000000000..a5faaae35e7 --- /dev/null +++ b/.changelog/3784.breaking.2.md @@ -0,0 +1,4 @@ +go/consensus/api/transaction: Print txn's method and body before the rest + +This is more intuitive and enables people to discover the transaction's main +information quicker. diff --git a/go/consensus/api/transaction/transaction.go b/go/consensus/api/transaction/transaction.go index febbccd7b0b..f20e0d81924 100644 --- a/go/consensus/api/transaction/transaction.go +++ b/go/consensus/api/transaction/transaction.go @@ -85,6 +85,9 @@ func (t Transaction) PrettyPrintBody(ctx context.Context, prefix string, w io.Wr // PrettyPrint writes a pretty-printed representation of the transaction to the // given writer. func (t Transaction) PrettyPrint(ctx context.Context, prefix string, w io.Writer) { + fmt.Fprintf(w, "%sMethod: %s\n", prefix, t.Method) + fmt.Fprintf(w, "%sBody:\n", prefix) + t.PrettyPrintBody(ctx, prefix+" ", w) fmt.Fprintf(w, "%sNonce: %d\n", prefix, t.Nonce) if t.Fee != nil { fmt.Fprintf(w, "%sFee:\n", prefix) @@ -92,10 +95,6 @@ func (t Transaction) PrettyPrint(ctx context.Context, prefix string, w io.Writer } else { fmt.Fprintf(w, "%sFee: none\n", prefix) } - fmt.Fprintf(w, "%sMethod: %s\n", prefix, t.Method) - fmt.Fprintf(w, "%sBody:\n", prefix) - t.PrettyPrintBody(ctx, prefix+" ", w) - if genesisHash, ok := ctx.Value(prettyprint.ContextKeyGenesisHash).(hash.Hash); ok { fmt.Println("Other info:") fmt.Printf(" Genesis document's hash: %s\n", genesisHash)