ざっくり手順
- Get the unlocked harvesting account public keys.
- Get accounts information
- Get accounts information
- 公開鍵からいつものアドレスへ
1.Get the unlocked harvesting account public keys.
Returns array of unlocked account public keys.
ロックされていないアカウントの公開鍵の配列を返します。 ロックされていないって表現がよくわからないのですが、委任ハーベスターのアカウントのPublic Keyを取得できます。
2.Get accounts information
Returns the account information for an array of accounts.
アカウントの配列のアカウント情報を返します。 ここで先ほど取得したPublic Keyを使用して全アカウントの情報を一発で取得します。 ただし、ここで取得されるのは、そもそもプロキシリモートアカウントの公開鍵で問い合わせをかけるので、プロキシリモートアカウントの情報になります。
3.Get accounts information
先ほど取得したアカウント情報から[supplementalPublicKeys]->[linked] -> [publicKey]を使用して再度アカウント情報を問い合わせます。
これで、委任者のアドレスや残高・インポータンススコアが取得できます。
4.公開鍵からいつものアドレスへ
みなさんご存じの通り、公開鍵があればアドレスは生成可能ですのでアドレスを生成します。
ちょっと汚いですが、こんな感じです。
$networkTypeValueHex = '68'; // 104 (main net)
$publicKeyHashHex = hash('sha3-256', hex2bin($publicKey));
$ripemd160StepOneHashHex = hash('ripemd160',hex2bin($publicKeyHashHex));
$versionPrefixedRipemd160HashHex = $networkTypeValueHex.$ripemd160StepOneHashHex;
$stepThreeChecksum = substr(hash('sha3-256', hex2bin($versionPrefixedRipemd160HashHex)),0,6);
$concatStepThreeAndStepSix = $versionPrefixedRipemd160HashHex . $stepThreeChecksum;
$address = hex2bin($concatStepThreeAndStepSix);
return substr(Base32::encode($address), 0, 39);