forked from Fenguoz/bsc-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormatter.php
More file actions
57 lines (50 loc) · 1.22 KB
/
Formatter.php
File metadata and controls
57 lines (50 loc) · 1.22 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
<?php
namespace Binance;
/**
* 数据签名
* Class Formatter
* @package Binance
*/
class Formatter
{
/**
* 对于方法名和参数类型做签名
* @param $method
* @return string
*/
public static function toMethodFormat($method)
{
return Utils::stripZero(substr(Utils::sha3($method), 0, 10));
}
/**
* 地址签名
* @param $address
* @return string
*/
public static function toAddressFormat($address)
{
if (Utils::isAddress($address)) {
$address = strtolower($address);
if (Utils::isZeroPrefixed($address)) {
$address = Utils::stripZero($address);
}
}
return implode('', array_fill(0, 64 - strlen($address), 0)) . $address;
}
/**
* 数字签名
* @param $value
* @param int $digit
* @return string
*/
public static function toIntegerFormat($value, $digit = 64)
{
$bn = Utils::toBn($value);
$bnHex = $bn->toHex(true);
$padded = mb_substr($bnHex, 0, 1);
if ($padded !== 'f') {
$padded = '0';
}
return implode('', array_fill(0, $digit - mb_strlen($bnHex), $padded)) . $bnHex;
}
}