LoginSignup
1
1

More than 1 year has passed since last update.

Symbolのノードのバージョンを取得する

Last updated at Posted at 2021-02-27

catapult-restの/node/infoに出てくるversionが、いつしか0でない値になってしばらく経ちました。

ふと気になって、どういう意味か考えてみました。

image.png

まずは、Windowsの電卓で16進数にしてみました。

image.png

0xA0007と出ています。

これまでの経験から、4バイトの値であることを感じるので、こうなるでしょう

0x000A0007

ああ、なるほどなるほど、これは1バイトずつ区切って、

0.10.0.7

を表しているように見える。

https://symbolnodes.org/nodes/ を見てみると、なんかそんな感じ。

image.png

すっきりしました。

バージョンをパースするコードをJavaScriptで書いてみました

function parseNodeVersion(num) {
    const hex = `00000000${Number(num).toString(16)}`.substr(-8)
    const strArray = []
    for (let i = 0; i < 8; i += 2) {
        const octet = Number(`0x${hex[i]}${hex[i + 1]}`).toString(10)
        strArray.push(octet)
    }

    return strArray.join('.')
}

parseNodeVersion(655367)
// return 0.10.0.7
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1