-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathArgumentDecoder.php
More file actions
62 lines (45 loc) · 1.2 KB
/
ArgumentDecoder.php
File metadata and controls
62 lines (45 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
namespace ArkEcosystem\Crypto\Utils\Abi;
use ArkEcosystem\Crypto\Utils\AbiDecoder;
final class ArgumentDecoder
{
private string $bytes;
public function __construct(string $bytes)
{
if (! ctype_xdigit($bytes) || strlen($bytes) % 2 !== 0) {
$bytes = false;
} else {
$bytes = hex2bin($bytes);
}
if ($bytes === false) {
$bytes = '';
}
$this->bytes = $bytes;
}
public function decodeString(): string
{
[$value] = AbiDecoder::decodeString($this->bytes, 0);
return $value;
}
public function decodeAddress(): string
{
[$value] = AbiDecoder::decodeAddress($this->bytes, 0);
return $value;
}
public function decodeUnsignedInt(): string
{
[$value] = AbiDecoder::decodeNumber($this->bytes, 0, 32, false);
return $value;
}
public function decodeSignedInt(): string
{
[$value] = AbiDecoder::decodeNumber($this->bytes, 0, 32, true);
return $value;
}
public function decodeBool(): bool
{
[$value] = AbiDecoder::decodeBool($this->bytes, 0);
return $value;
}
}