commit
87dbe235a4
@ -6,4 +6,4 @@ RUN npm install -g ganache-cli
|
||||
|
||||
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
|
||||
|
||||
ganache-cli -g 0 -l 0 > /dev/null &
|
||||
ganache-cli -g 0 -l 6000000 > /dev/null &
|
||||
ganachecli_pid=$!
|
||||
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\Boolean;
|
||||
use Web3\Contracts\Types\Bytes;
|
||||
use Web3\Contracts\Types\DynamicBytes;
|
||||
use Web3\Contracts\Types\Integer;
|
||||
use Web3\Contracts\Types\Str;
|
||||
use Web3\Contracts\Types\Uinteger;
|
||||
@ -133,6 +134,7 @@ class Contract
|
||||
'address' => new Address,
|
||||
'bool' => new Boolean,
|
||||
'bytes' => new Bytes,
|
||||
'dynamicBytes' => new DynamicBytes,
|
||||
'int' => new Integer,
|
||||
'string' => new Str,
|
||||
'uint' => new Uinteger,
|
||||
|
@ -249,7 +249,7 @@ class Ethabi
|
||||
$param = mb_strtolower(Utils::stripZero($param));
|
||||
|
||||
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]);
|
||||
} else {
|
||||
$result[$i] = $solidityTypes[$i]->decode($param, $offsets[$i], $types[$i]);
|
||||
@ -280,8 +280,13 @@ class Ethabi
|
||||
$className = $this->types[$match[0]];
|
||||
|
||||
if (call_user_func([$this->types[$match[0]], 'isType'], $type) === false) {
|
||||
// check dynamic bytes
|
||||
if ($match[0] === 'bytes') {
|
||||
$className = $this->types['dynamicBytes'];
|
||||
} else {
|
||||
throw new InvalidArgumentException('Unsupport solidity parameter type: ' . $type);
|
||||
}
|
||||
}
|
||||
$solidityTypes[$key] = $className;
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class Address extends SolidityType implements IType
|
||||
*/
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)) {
|
||||
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;
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ class DynamicBytes extends SolidityType implements IType
|
||||
*/
|
||||
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)) {
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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 = [
|
||||
[
|
||||
'value' => 'bytes',
|
||||
'result' => true
|
||||
'result' => false
|
||||
], [
|
||||
'value' => 'bytes[]',
|
||||
'result' => true
|
||||
'result' => false
|
||||
], [
|
||||
'value' => 'bytes[4]',
|
||||
'result' => true
|
||||
'result' => false
|
||||
], [
|
||||
'value' => 'bytes[][]',
|
||||
'result' => true
|
||||
'result' => false
|
||||
], [
|
||||
'value' => 'bytes[3][]',
|
||||
'result' => true
|
||||
'result' => false
|
||||
], [
|
||||
'value' => 'bytes[][6][]',
|
||||
'result' => true
|
||||
'result' => false
|
||||
], [
|
||||
'value' => 'bytes32',
|
||||
'result' => true
|
||||
|
File diff suppressed because one or more lines are too long
@ -34,10 +34,10 @@ class DynamicBytesTypeTest extends TestCase
|
||||
'result' => true
|
||||
], [
|
||||
'value' => 'bytes32',
|
||||
'result' => true
|
||||
'result' => false
|
||||
], [
|
||||
'value' => 'bytes8[4]',
|
||||
'result' => true
|
||||
'result' => false
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -9,6 +9,7 @@ use Web3\Contracts\Ethabi;
|
||||
use Web3\Contracts\Types\Address;
|
||||
use Web3\Contracts\Types\Boolean;
|
||||
use Web3\Contracts\Types\Bytes;
|
||||
use Web3\Contracts\Types\DynamicBytes;
|
||||
use Web3\Contracts\Types\Integer;
|
||||
use Web3\Contracts\Types\Str;
|
||||
use Web3\Contracts\Types\Uinteger;
|
||||
@ -179,9 +180,10 @@ class EthabiTest extends TestCase
|
||||
'address' => new Address,
|
||||
'bool' => new Boolean,
|
||||
'bytes' => new Bytes,
|
||||
'dynamicBytes' => new DynamicBytes,
|
||||
'int' => new Integer,
|
||||
'string' => new Str,
|
||||
'uint' => new Uinteger,
|
||||
'uint' => new Uinteger
|
||||
]);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user