Skip to content

Commit d9e57c0

Browse files
committed
Add util makeMptID
1 parent 131ca15 commit d9e57c0

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"require": {
2727
"php": "^8.1.0",
2828
"guzzlehttp/guzzle": "^7.4",
29-
"brick/math": "^0.10.2|^0.11|^0.12"
29+
"brick/math": "^0.10.2|^0.11|^0.12",
30+
"hardcastle/xrpl_php": "^0.8|^0.9"
3031
},
3132
"require-dev": {
3233
"phpunit/phpunit": "^10.1",

src/Utilities/Util.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,15 @@ public static function ieee754FloatFromBytes(array $bytes): float|null|bool
113113

114114
}
115115

116+
/**
117+
* Test: makeMptID(4369311,'rGepNyxjJbtN75Zb4fgkjQsnv3UUcbp45E') should output: 0042AB9FAB8A5036CE4DB80D47016F557F9BFC9523985BF1
118+
* @return string
119+
*/
120+
public static function makeMptID(int $sequence, string $issuer): string {
121+
$sequence = pack('N', $sequence); // 'N' = unsigned long (32-bit big endian)
122+
$codec = new \Hardcastle\XRPL_PHP\Core\RippleAddressCodec\AddressCodec();
123+
$accountID = $codec->decodeAccountId($issuer)->toUtf8();
124+
return \strtoupper(\bin2hex($sequence . $accountID)); //Return as hex string
125+
}
126+
116127
}

tests/Unit/UtilTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ public function testConvertCurrencyToSymbolLP()
3737
{
3838
$this->assertEquals('LP 03B20F3A7D26D33C6DA3503E5CCE3E67B102D4D2',Util::currencyToSymbol('03B20F3A7D26D33C6DA3503E5CCE3E67B102D4D2'));
3939
}
40+
41+
public function testMakeMptId() {
42+
$sequence = 4369311;
43+
$issuer = 'rGepNyxjJbtN75Zb4fgkjQsnv3UUcbp45E';
44+
$this->assertEquals('0042AB9FAB8A5036CE4DB80D47016F557F9BFC9523985BF1',Util::makeMptID($sequence,$issuer));
45+
46+
}
4047
}

0 commit comments

Comments
 (0)