mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 11:38:12 +00:00
step by step encoding
This commit is contained in:
parent
d319ee8d92
commit
2559b958a6
@ -100,7 +100,7 @@ SolidityType.prototype.encode = function (value, name) {
|
||||
var nestedName = this.nestedName(name);
|
||||
|
||||
var result = [];
|
||||
result.push(f.formatInputInt(length));
|
||||
result.push(f.formatInputInt(length)).encode();
|
||||
|
||||
var self = this;
|
||||
value.forEach(function (v) {
|
||||
@ -235,9 +235,23 @@ SolidityCoder.prototype.encodeParams = function (types, params) {
|
||||
|
||||
console.log(encoded);
|
||||
|
||||
return encoded[0];
|
||||
var totalOffset = solidityTypes.reduce(function (acc, solidityType, index) {
|
||||
return acc + solidityType.staticPartLength(types[index]);
|
||||
}, 0);
|
||||
|
||||
var result = solidityTypes.reduce(function (acc, solidityType, index) {
|
||||
if (solidityType.isDynamicArray(types[index])) {
|
||||
return acc + f.formatInputInt(offsets[index]).encode();
|
||||
} else {
|
||||
return acc + encoded[index];
|
||||
}
|
||||
}, "");
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Should be used to decode bytes to plain param
|
||||
*
|
||||
@ -320,8 +334,6 @@ SolidityTypeAddress.prototype.staticArrayLength = function (name) {
|
||||
return name.match(/address(\[([0-9]*)\])?/)[2] || 1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
SolidityTypeAddress.prototype.nestedName = function (name) {
|
||||
// removes first [] in name
|
||||
return name.replace(/\[([0-9])*\]/, '');
|
||||
|
@ -117,6 +117,9 @@ describe('lib/solidity/coder', function () {
|
||||
};
|
||||
|
||||
|
||||
test({ types: ['address', 'address'], values: ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', '0x407d73d8a49eeb85d32cf465507dd71d507100c3'],
|
||||
expected: '000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1' +
|
||||
'000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c3'});
|
||||
//test({ types: ['int'], values: [1], expected: '0000000000000000000000000000000000000000000000000000000000000001'});
|
||||
//test({ types: ['int'], values: [16], expected: '0000000000000000000000000000000000000000000000000000000000000010'});
|
||||
//test({ types: ['int'], values: [-1], expected: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'});
|
||||
|
Loading…
x
Reference in New Issue
Block a user