From 11c34f947a429471370eb4a04fac44b1ce522dbf Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 24 Mar 2023 14:39:05 +0300 Subject: [PATCH] adm: print NNS expiration time along with hash dump We print versions already, domain expirations might be useful as well. nns (v0.16.0): fb08ccf30ab534a871b7b092a49fe70c154ed678 unknown alphabet 0 (v0.16.0): 61936114ea7fb0e7b5a2723b02f505f126bb2c02 2023-07-18 19:01:16.974 +0300 MSK alphabet 1 (v0.16.0): 1bf134b7e68195ef3c41b50652f4ea0f1447bbd6 2023-07-18 19:01:16.974 +0300 MSK alphabet 2 (v0.16.0): 3cf31e25947842a3f7670896fd852bc3247e2737 2023-07-18 19:01:16.974 +0300 MSK alphabet 3 (v0.16.0): d793058938c787a4a4eafa210d9828a754c5abbf 2023-07-18 19:01:16.974 +0300 MSK alphabet 4 (v0.16.0): 8a6212f6300e8cf76865e428e8d7c990d2e4e94c 2023-07-18 19:01:16.974 +0300 MSK alphabet 5 (v0.16.0): 3456b29877fd90d980a3350dbfea448b02e86ed3 2023-07-18 19:01:16.974 +0300 MSK alphabet 6 (v0.16.0): 08fad4051210a66c03b819a00a60330ddae2c67a 2023-07-18 19:01:16.974 +0300 MSK audit (v0.15.4): 0b2e571aa760c22a5ab94bae3a9752bb2eb918f5 2023-07-18 19:01:16.974 +0300 MSK balance (v0.15.4): 54f3bd4dbec6ecd0f5177b5bd86f09043e34d45f 2023-07-18 19:01:16.974 +0300 MSK container (v0.15.4): 70cf38deb1ff7a4f64cb1127eafcd75cd38083d4 2023-07-18 19:01:16.974 +0300 MSK neofsid (v0.15.4): 821fbe90b21986883cd19551be689cca0170e9fb 2023-07-18 19:01:16.974 +0300 MSK netmap (v0.15.4): c4576ea5c3081dd765a17aaaa73d9352e74bdc28 2023-07-18 19:01:16.974 +0300 MSK proxy (v0.15.4): b88b7ad0899766ee39bf554018f2df008f930a61 2023-07-18 19:01:16.974 +0300 MSK reputation (v0.15.4): 2fbca91096822825b8e9f71ff596381ceb4bd749 2023-07-18 19:01:16.974 +0300 MSK subnet (v0.15.4): e0a2dcc4da7e8c48ae289c14dc6c0583493daf90 2023-07-18 19:01:16.974 +0300 MSK Signed-off-by: Roman Khimov --- CHANGELOG.md | 1 + .../internal/modules/morph/dump_hashes.go | 48 +++++++++++++++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d142a0f766..a74bb570f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Changelog for NeoFS Node - Doc for extended headers (#2128) - Separate batching for replicated operations over the same container in pilorama (#1621) - `object.delete.tombstone_lifetime` config parameter to set tombstone lifetime in the DELETE service (#2246) +- neofs-adm morph dump-hashes command now also prints NNS domain expiration time (#2295) ### Changed - `common.PrintVerbose` prints via `cobra.Command.Printf` (#1962) diff --git a/cmd/neofs-adm/internal/modules/morph/dump_hashes.go b/cmd/neofs-adm/internal/modules/morph/dump_hashes.go index 9f7ea51368..3378d8a967 100644 --- a/cmd/neofs-adm/internal/modules/morph/dump_hashes.go +++ b/cmd/neofs-adm/internal/modules/morph/dump_hashes.go @@ -6,9 +6,11 @@ import ( "fmt" "strings" "text/tabwriter" + "time" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11" "github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/util" @@ -24,9 +26,10 @@ import ( const lastGlagoliticLetter = 41 type contractDumpInfo struct { - hash util.Uint160 - name string - version string + hash util.Uint160 + name string + version string + expiration int64 } func dumpContractHashes(cmd *cobra.Command, _ []string) error { @@ -101,6 +104,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { } fillContractVersion(cmd, c, infos) + fillContractExpiration(cmd, c, infos) printContractInfo(cmd, infos) return nil @@ -174,6 +178,7 @@ func dumpCustomZoneHashes(cmd *cobra.Command, nnsHash util.Uint160, zone string, } fillContractVersion(cmd, c, infos) + fillContractExpiration(cmd, c, infos) printContractInfo(cmd, infos) return nil @@ -200,11 +205,16 @@ func printContractInfo(cmd *cobra.Command, infos []contractDumpInfo) { buf := bytes.NewBuffer(nil) tw := tabwriter.NewWriter(buf, 0, 2, 2, ' ', 0) for _, info := range infos { + var timeStr = "unknown" + if info.expiration != 0 { + timeStr = time.UnixMilli(info.expiration).String() + } if info.version == "" { info.version = "unknown" } - _, _ = tw.Write([]byte(fmt.Sprintf("%s\t(%s):\t%s\n", - info.name, info.version, info.hash.StringLE()))) + _, _ = tw.Write([]byte(fmt.Sprintf("%s\t(%s):\t%s\t%s\n", + info.name, info.version, info.hash.StringLE(), + timeStr))) } _ = tw.Flush() @@ -248,3 +258,31 @@ func fillContractVersion(cmd *cobra.Command, c Client, infos []contractDumpInfo) } } } + +func fillContractExpiration(cmd *cobra.Command, c Client, infos []contractDumpInfo) { + n11r := nep11.NewNonDivisibleReader(invoker.New(c, nil), infos[0].hash) + for i := range infos { + if infos[i].hash.Equals(util.Uint160{}) { + continue + } + props, err := n11r.Properties([]byte(strings.ReplaceAll(infos[i].name, " ", "") + ".neofs")) + if err != nil { + continue // OK for NNS itself, for example. + } + elems := props.Value().([]stackitem.MapElement) + for _, e := range elems { + k, err := e.Key.TryBytes() + if err != nil { + continue + } + + if string(k) == "expiration" { + v, err := e.Value.TryInteger() + if err != nil || !v.IsInt64() { + continue + } + infos[i].expiration = v.Int64() + } + } + } +}