commit
87dbe235a4
@ -6,4 +6,4 @@ RUN npm install -g ganache-cli
|
|||||||
|
|
||||||
EXPOSE 8545
|
EXPOSE 8545
|
||||||
|
|
||||||
CMD ganache-cli --hostname=0.0.0.0
|
CMD ganache-cli -g 0 -l 6000000 --hostname=0.0.0.0
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
ganache-cli -g 0 -l 0 > /dev/null &
|
ganache-cli -g 0 -l 6000000 > /dev/null &
|
||||||
ganachecli_pid=$!
|
ganachecli_pid=$!
|
||||||
echo "Start ganache-cli pid: $ganachecli_pid and sleep 3 seconds"
|
echo "Start ganache-cli pid: $ganachecli_pid and sleep 3 seconds"
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ use Web3\Contracts\Ethabi;
|
|||||||
use Web3\Contracts\Types\Address;
|
use Web3\Contracts\Types\Address;
|
||||||
use Web3\Contracts\Types\Boolean;
|
use Web3\Contracts\Types\Boolean;
|
||||||
use Web3\Contracts\Types\Bytes;
|
use Web3\Contracts\Types\Bytes;
|
||||||
|
use Web3\Contracts\Types\DynamicBytes;
|
||||||
use Web3\Contracts\Types\Integer;
|
use Web3\Contracts\Types\Integer;
|
||||||
use Web3\Contracts\Types\Str;
|
use Web3\Contracts\Types\Str;
|
||||||
use Web3\Contracts\Types\Uinteger;
|
use Web3\Contracts\Types\Uinteger;
|
||||||
@ -133,6 +134,7 @@ class Contract
|
|||||||
'address' => new Address,
|
'address' => new Address,
|
||||||
'bool' => new Boolean,
|
'bool' => new Boolean,
|
||||||
'bytes' => new Bytes,
|
'bytes' => new Bytes,
|
||||||
|
'dynamicBytes' => new DynamicBytes,
|
||||||
'int' => new Integer,
|
'int' => new Integer,
|
||||||
'string' => new Str,
|
'string' => new Str,
|
||||||
'uint' => new Uinteger,
|
'uint' => new Uinteger,
|
||||||
|
@ -249,7 +249,7 @@ class Ethabi
|
|||||||
$param = mb_strtolower(Utils::stripZero($param));
|
$param = mb_strtolower(Utils::stripZero($param));
|
||||||
|
|
||||||
for ($i=0; $i<$typesLength; $i++) {
|
for ($i=0; $i<$typesLength; $i++) {
|
||||||
if (isset($outputTypes['outputs'][$i]['name'])) {
|
if (isset($outputTypes['outputs'][$i]['name']) && empty($outputTypes['outputs'][$i]['name']) === false) {
|
||||||
$result[$outputTypes['outputs'][$i]['name']] = $solidityTypes[$i]->decode($param, $offsets[$i], $types[$i]);
|
$result[$outputTypes['outputs'][$i]['name']] = $solidityTypes[$i]->decode($param, $offsets[$i], $types[$i]);
|
||||||
} else {
|
} else {
|
||||||
$result[$i] = $solidityTypes[$i]->decode($param, $offsets[$i], $types[$i]);
|
$result[$i] = $solidityTypes[$i]->decode($param, $offsets[$i], $types[$i]);
|
||||||
@ -280,7 +280,12 @@ class Ethabi
|
|||||||
$className = $this->types[$match[0]];
|
$className = $this->types[$match[0]];
|
||||||
|
|
||||||
if (call_user_func([$this->types[$match[0]], 'isType'], $type) === false) {
|
if (call_user_func([$this->types[$match[0]], 'isType'], $type) === false) {
|
||||||
throw new InvalidArgumentException('Unsupport solidity parameter type: ' . $type);
|
// check dynamic bytes
|
||||||
|
if ($match[0] === 'bytes') {
|
||||||
|
$className = $this->types['dynamicBytes'];
|
||||||
|
} else {
|
||||||
|
throw new InvalidArgumentException('Unsupport solidity parameter type: ' . $type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$solidityTypes[$key] = $className;
|
$solidityTypes[$key] = $className;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class Address extends SolidityType implements IType
|
|||||||
*/
|
*/
|
||||||
public function isType($name)
|
public function isType($name)
|
||||||
{
|
{
|
||||||
return (preg_match('/address(\[([0-9]*)\])*/', $name) === 1);
|
return (preg_match('/^address(\[([0-9]*)\])*$/', $name) === 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +35,7 @@ class Boolean extends SolidityType implements IType
|
|||||||
*/
|
*/
|
||||||
public function isType($name)
|
public function isType($name)
|
||||||
{
|
{
|
||||||
return (preg_match('/bool(\[([0-9]*)\])*/', $name) === 1);
|
return (preg_match('/^bool(\[([0-9]*)\])*$/', $name) === 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,7 +36,7 @@ class Bytes extends SolidityType implements IType
|
|||||||
*/
|
*/
|
||||||
public function isType($name)
|
public function isType($name)
|
||||||
{
|
{
|
||||||
return (preg_match('/bytes([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1);
|
return (preg_match('/^bytes([0-9]{1,})(\[([0-9]*)\])*$/', $name) === 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,6 +90,11 @@ class Bytes extends SolidityType implements IType
|
|||||||
if (empty($checkZero)) {
|
if (empty($checkZero)) {
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
|
if (preg_match('/^bytes([0-9]*)/', $name, $match) === 1) {
|
||||||
|
$size = intval($match[1]);
|
||||||
|
$length = 2 * $size;
|
||||||
|
$value = mb_substr($value, 0, $length);
|
||||||
|
}
|
||||||
return '0x' . $value;
|
return '0x' . $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,7 +36,7 @@ class DynamicBytes extends SolidityType implements IType
|
|||||||
*/
|
*/
|
||||||
public function isType($name)
|
public function isType($name)
|
||||||
{
|
{
|
||||||
return (preg_match('/bytes(\[([0-9]*)\])*/', $name) === 1);
|
return (preg_match('/^bytes(\[([0-9]*)\])*$/', $name) === 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,6 +89,9 @@ class DynamicBytes extends SolidityType implements IType
|
|||||||
if (empty($checkZero)) {
|
if (empty($checkZero)) {
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
return '0x' . $value;
|
$size = intval(Utils::toBn(mb_substr($value, 0, 64))->toString());
|
||||||
|
$length = 2 * $size;
|
||||||
|
|
||||||
|
return '0x' . mb_substr($value, 64, $length);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -37,7 +37,7 @@ class Integer extends SolidityType implements IType
|
|||||||
*/
|
*/
|
||||||
public function isType($name)
|
public function isType($name)
|
||||||
{
|
{
|
||||||
return (preg_match('/int([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1);
|
return (preg_match('/^int([0-9]{1,})?(\[([0-9]*)\])*$/', $name) === 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +37,7 @@ class Str extends SolidityType implements IType
|
|||||||
*/
|
*/
|
||||||
public function isType($name)
|
public function isType($name)
|
||||||
{
|
{
|
||||||
return (preg_match('/string(\[([0-9]*)\])*/', $name) === 1);
|
return (preg_match('/^string(\[([0-9]*)\])*$/', $name) === 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +37,7 @@ class Uinteger extends SolidityType implements IType
|
|||||||
*/
|
*/
|
||||||
public function isType($name)
|
public function isType($name)
|
||||||
{
|
{
|
||||||
return (preg_match('/uint([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1);
|
return (preg_match('/^uint([0-9]{1,})?(\[([0-9]*)\])*$/', $name) === 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,22 +16,22 @@ class BytesTypeTest extends TestCase
|
|||||||
protected $testTypes = [
|
protected $testTypes = [
|
||||||
[
|
[
|
||||||
'value' => 'bytes',
|
'value' => 'bytes',
|
||||||
'result' => true
|
'result' => false
|
||||||
], [
|
], [
|
||||||
'value' => 'bytes[]',
|
'value' => 'bytes[]',
|
||||||
'result' => true
|
'result' => false
|
||||||
], [
|
], [
|
||||||
'value' => 'bytes[4]',
|
'value' => 'bytes[4]',
|
||||||
'result' => true
|
'result' => false
|
||||||
], [
|
], [
|
||||||
'value' => 'bytes[][]',
|
'value' => 'bytes[][]',
|
||||||
'result' => true
|
'result' => false
|
||||||
], [
|
], [
|
||||||
'value' => 'bytes[3][]',
|
'value' => 'bytes[3][]',
|
||||||
'result' => true
|
'result' => false
|
||||||
], [
|
], [
|
||||||
'value' => 'bytes[][6][]',
|
'value' => 'bytes[][6][]',
|
||||||
'result' => true
|
'result' => false
|
||||||
], [
|
], [
|
||||||
'value' => 'bytes32',
|
'value' => 'bytes32',
|
||||||
'result' => true
|
'result' => true
|
||||||
|
File diff suppressed because one or more lines are too long
@ -34,10 +34,10 @@ class DynamicBytesTypeTest extends TestCase
|
|||||||
'result' => true
|
'result' => true
|
||||||
], [
|
], [
|
||||||
'value' => 'bytes32',
|
'value' => 'bytes32',
|
||||||
'result' => true
|
'result' => false
|
||||||
], [
|
], [
|
||||||
'value' => 'bytes8[4]',
|
'value' => 'bytes8[4]',
|
||||||
'result' => true
|
'result' => false
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ use Web3\Contracts\Ethabi;
|
|||||||
use Web3\Contracts\Types\Address;
|
use Web3\Contracts\Types\Address;
|
||||||
use Web3\Contracts\Types\Boolean;
|
use Web3\Contracts\Types\Boolean;
|
||||||
use Web3\Contracts\Types\Bytes;
|
use Web3\Contracts\Types\Bytes;
|
||||||
|
use Web3\Contracts\Types\DynamicBytes;
|
||||||
use Web3\Contracts\Types\Integer;
|
use Web3\Contracts\Types\Integer;
|
||||||
use Web3\Contracts\Types\Str;
|
use Web3\Contracts\Types\Str;
|
||||||
use Web3\Contracts\Types\Uinteger;
|
use Web3\Contracts\Types\Uinteger;
|
||||||
@ -179,9 +180,10 @@ class EthabiTest extends TestCase
|
|||||||
'address' => new Address,
|
'address' => new Address,
|
||||||
'bool' => new Boolean,
|
'bool' => new Boolean,
|
||||||
'bytes' => new Bytes,
|
'bytes' => new Bytes,
|
||||||
|
'dynamicBytes' => new DynamicBytes,
|
||||||
'int' => new Integer,
|
'int' => new Integer,
|
||||||
'string' => new Str,
|
'string' => new Str,
|
||||||
'uint' => new Uinteger,
|
'uint' => new Uinteger
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user