Ether Binder
Set of utilities for interacting with Ethereum and it's smart contracts with PHP, with generating ABI bindings and Ethereum-related types
Loading...
Searching...
No Matches
M8B\EtherBinder\Utils\Functions Class Reference

Static Public Member Functions

static mustHexLen (string $hex, int $len)
 
static lPadHex (string $hex, int $padTo, bool $closestMultiplier=true)
 
static int2hex (int $val, bool $with0x=true)
 
static hex2int (string $val)
 
static getPessimisticBlockBaseFee (Block $previous, int $blocksAhead, ?EIP1559Config $config=null)
 
static hex2bin (string $hex)
 
static getNextBlockBaseFee (Block $previous, EIP1559Config $config)
 
static waitForTxReceipt (Transaction|Hash $txHash, AbstractRPC $rpc, int $timeoutSeconds=60, int $intervalMS=500)
 

Detailed Description

Functions is an abstract utility class that holds static utility methods.

Author
DubbaThony

Member Function Documentation

◆ getNextBlockBaseFee()

static M8B\EtherBinder\Utils\Functions::getNextBlockBaseFee ( Block $previous,
EIP1559Config $config )
static

Calculates the base fee for the next block in an EIP1559 compatible chain.

Parameters
Block$previousThe previous block.
EIP1559Config$configThe EIP1559 configuration. Only required field is $config->activationBlockNumber
Returns
OOGmp The calculated base fee.

◆ getPessimisticBlockBaseFee()

static M8B\EtherBinder\Utils\Functions::getPessimisticBlockBaseFee ( Block $previous,
int $blocksAhead,
?EIP1559Config $config = null )
static

Returns worst case scenario base fee for block currentBlock + blocksAhead. Useful for estimating base fee for transactions. Since the fee is base fee, it shouldn't matter if it's overestimated, since consensus will prevent spending surplus

Parameters
Block$previous
int$blocksAhead
EIP1559Config | null$config
Returns
OOGmp

◆ hex2bin()

static M8B\EtherBinder\Utils\Functions::hex2bin ( string $hex)
static

0x tolerant, exceptions-compatible hex2bin() drop-in replacement, that never returns false, handles empty strings and prefixes "0" if odd amount of characters is spotted.

Parameters
string$hex
Returns
string Binary blob
Exceptions
InvalidHexException

◆ hex2int()

static M8B\EtherBinder\Utils\Functions::hex2int ( string $val)
static

Converts hex string to integer

Parameters
string$valThe hexadecimal string
Returns
int The integer value
Exceptions
EthBinderRuntimeExceptionwhen number exceeds PHP_INT_MAX

◆ int2hex()

static M8B\EtherBinder\Utils\Functions::int2hex ( int $val,
bool $with0x = true )
static

Converts an integer to a hex string.

Parameters
int$valThe integer value.
bool$with0xWhether to include the "0x" prefix.
Returns
string The hex string.

◆ lPadHex()

static M8B\EtherBinder\Utils\Functions::lPadHex ( string $hex,
int $padTo,
bool $closestMultiplier = true )
static

Left-pads a hex string to a specific length.

Parameters
string$hexThe hex string.
int$padToThe length to pad to.
bool$closestMultiplierWhether to pad to the closest multiple of $padTo, instead of just to $padTo
Returns
string The padded hex string.

◆ mustHexLen()

static M8B\EtherBinder\Utils\Functions::mustHexLen ( string $hex,
int $len )
static

Validates the length of a hexadecimal string. In case the length is invalid, exception is risen.

Parameters
string$hexThe hex string.
int$lenThe expected length.
Exceptions
InvalidHexException
InvalidHexLengthException

◆ waitForTxReceipt()

static M8B\EtherBinder\Utils\Functions::waitForTxReceipt ( Transaction|Hash $txHash,
AbstractRPC $rpc,
int $timeoutSeconds = 60,
int $intervalMS = 500 )
static

This function will wait and block until the transaction is confirmed via repetatively checking receipt

Parameters
Transaction | Hash$txHashHash of the transaction or signed transaction
AbstractRPC$rpcRPC to use for transaction receipt pooling
int$timeoutSecondsAfter how many seconds to give up
int$intervalMSHow long to wait between pooling attempts
Returns
Receipt Transaction receipt
Exceptions
EthBinderRuntimeExceptionif timeout happens. It does not mean the transaction will not get confirmed!
EthBinderLogicException
NotSupportedException

The documentation for this class was generated from the following file: