Skip to content

Commit

Permalink
adm: print NNS expiration time along with hash dump
Browse files Browse the repository at this point in the history
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 <roman@nspcc.ru>
  • Loading branch information
roman-khimov committed Mar 27, 2023
1 parent 197251d commit 11c34f9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 43 additions & 5 deletions cmd/neofs-adm/internal/modules/morph/dump_hashes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -101,6 +104,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
}

fillContractVersion(cmd, c, infos)
fillContractExpiration(cmd, c, infos)
printContractInfo(cmd, infos)

return nil
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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()
}
}
}
}

0 comments on commit 11c34f9

Please sign in to comment.