Comments (2)
Ignore my squabbles, I was able to make it work. i will make. pull request after Im done with everything. I noticed you are treating fixed size arrays as variable size array. In the spec the fixed size arrays are treated as Tuples and have no need to prefix the the encoded length. Modifying the Encode Input function to encode a fixed size array as a tuple fixes this problem, look below.
private static function EncodeInput($input, $inputData, $round, &$currentDynamicIndex)
{
$hash = "";
if ($round == 1) {
$input_type = is_string($input) ? $input : $input->type;
$varType = self::GetParameterType($input_type);
//dynamic
if (Utils::string_contains($input->type, '[]')) {
$input->hash = self::EncodeInput_Array($input, $inputData);
$res = self::EncodeInput_UInt($currentDynamicIndex);
return $res;
} else if (preg_match_all('/\[(\d+)\]/', $input->type, $matches)) {
$typeStr = str_replace($matches[0], "", $input->type);
$type = (object)['type' => $typeStr];
$inferredType = array_fill(0, (int)$matches[1][0], $type);
$res = self::EncodeGroup($inferredType, $inputData);
return $res;
} else if ($varType == VariableType::Tuple) {
$res = self::EncodeGroup($input->components, $inputData);
// if the tuple is dynamic, we return offset and add tuple's data at the end
if (self::ExistsDynamicParameter($input->components)) {
$input->hash = $res;
return self::EncodeInput_UInt($currentDynamicIndex);
}
return $res;
} else if ($varType == VariableType::String) {
$input->hash = self::EncodeInput_String($inputData);
$res = self::EncodeInput_UInt($currentDynamicIndex);
return $res;
} else if ($varType == VariableType::Bytes) {
$input->hash = self::EncodeInput_Bytes($inputData);
$res = self::EncodeInput_UInt($currentDynamicIndex);
return $res;
}
//static
else if ($varType == VariableType::UInt) {
return self::EncodeInput_UInt($inputData);
} else if ($varType == VariableType::Int) {
return self::EncodeInput_Int($inputData);
} else if ($varType == VariableType::Bool) {
return self::EncodeInput_Bool($inputData);
} else if ($varType == VariableType::Address) {
return self::EncodeInput_Address($inputData);
} else if ($varType == VariableType::BytesFixed) {
return self::EncodeInput_BytesFixed($inputData);
}
} else if ($round == 2) {
if (isset($input->hash) and $input->hash != '') {
return $input->hash;
}
}
return $hash;
}
```php
from simple-web3-php.
Sorry for the delay.
Yes, I was handling static types & static length while decoding, but not on encoding.
I added the same logic to check array mode on Encoding operations.
from simple-web3-php.
Related Issues (20)
- Split ABIv2 encoding/decoding HOT 1
- substr(): Argument #3 ($length) must be of type ?int, float given HOT 3
- Add blockTag to the SWeb3_Contract.php HOT 1
- why is there a memory shortage during the Call contract command? HOT 1
- The output data of the read contract command is missing [solved] HOT 7
- can I get the Latest 25 BEP-20 Token Transfer Events on a specified contract through Simple-Web3-Php? HOT 2
- how to call the interface functions of contract? HOT 1
- How to query the number of Token holdings on a specified contract? [Solved] HOT 7
- Stargate finance tuple issue HOT 1
- Please upgrade kornrunner/ethereum-offline-raw-tx ^0.4.0 to ^0.6.0
- How to obtain correct bytes32 string? HOT 2
- ABI Encoding, Keccak256 Hashing HOT 2
- Error sending wallet address different from contract HOT 3
- unable to decode data via DecodeData method HOT 1
- Core/ABI->GetEventFromHash throws exception on invalid index. HOT 1
- Custom blockchain ID HOT 1
- How to use that library in a server without Composer?
- How to encode address[] and uint256[] arrays
- how to customize batch ids?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-web3-php.