mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 11:38:12 +00:00
fixed long bytes dynamic decoding/encoding, #249
This commit is contained in:
parent
d097821665
commit
b3f5d0927c
16
dist/web3-light.js
vendored
16
dist/web3-light.js
vendored
@ -354,9 +354,10 @@ var formatInputBytes = function (value) {
|
||||
* @returns {SolidityParam}
|
||||
*/
|
||||
var formatInputDynamicBytes = function (value) {
|
||||
value = utils.toHex(value);
|
||||
var result = utils.padRight((value).substr(2), 64);
|
||||
var length = Math.floor(value.length / 2 - 1);
|
||||
value = utils.toHex(value).substr(2);
|
||||
var l = Math.floor((value.length + 63) / 64);
|
||||
var result = utils.padRight(value, l * 64);
|
||||
var length = Math.floor(value.length / 2);
|
||||
return new SolidityParam(formatInputInt(length).value + result, 32);
|
||||
};
|
||||
|
||||
@ -721,13 +722,14 @@ var getOffset = function (bytes, index) {
|
||||
*/
|
||||
SolidityParam.decodeBytes = function (bytes, index) {
|
||||
index = index || 0;
|
||||
//TODO add support for strings longer than 32 bytes
|
||||
//var length = parseInt('0x' + bytes.substr(offset * 64, 64));
|
||||
|
||||
var offset = getOffset(bytes, index);
|
||||
|
||||
// 2 * , cause we also parse length
|
||||
return new SolidityParam(bytes.substr(offset * 2, 2 * 64), 0);
|
||||
var l = parseInt('0x' + bytes.substr(offset * 2, 64));
|
||||
l = Math.floor((l + 31) / 32);
|
||||
|
||||
// (1 + l) * , cause we also parse length
|
||||
return new SolidityParam(bytes.substr(offset * 2, (1 + l) * 64), 0);
|
||||
};
|
||||
|
||||
/**
|
||||
|
5
dist/web3-light.min.js
vendored
5
dist/web3-light.min.js
vendored
File diff suppressed because one or more lines are too long
16
dist/web3.js
vendored
16
dist/web3.js
vendored
@ -354,9 +354,10 @@ var formatInputBytes = function (value) {
|
||||
* @returns {SolidityParam}
|
||||
*/
|
||||
var formatInputDynamicBytes = function (value) {
|
||||
value = utils.toHex(value);
|
||||
var result = utils.padRight((value).substr(2), 64);
|
||||
var length = Math.floor(value.length / 2 - 1);
|
||||
value = utils.toHex(value).substr(2);
|
||||
var l = Math.floor((value.length + 63) / 64);
|
||||
var result = utils.padRight(value, l * 64);
|
||||
var length = Math.floor(value.length / 2);
|
||||
return new SolidityParam(formatInputInt(length).value + result, 32);
|
||||
};
|
||||
|
||||
@ -721,13 +722,14 @@ var getOffset = function (bytes, index) {
|
||||
*/
|
||||
SolidityParam.decodeBytes = function (bytes, index) {
|
||||
index = index || 0;
|
||||
//TODO add support for strings longer than 32 bytes
|
||||
//var length = parseInt('0x' + bytes.substr(offset * 64, 64));
|
||||
|
||||
var offset = getOffset(bytes, index);
|
||||
|
||||
// 2 * , cause we also parse length
|
||||
return new SolidityParam(bytes.substr(offset * 2, 2 * 64), 0);
|
||||
var l = parseInt('0x' + bytes.substr(offset * 2, 64));
|
||||
l = Math.floor((l + 31) / 32);
|
||||
|
||||
// (1 + l) * , cause we also parse length
|
||||
return new SolidityParam(bytes.substr(offset * 2, (1 + l) * 64), 0);
|
||||
};
|
||||
|
||||
/**
|
||||
|
87
dist/web3.js.map
vendored
Normal file
87
dist/web3.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
6
dist/web3.min.js
vendored
6
dist/web3.min.js
vendored
File diff suppressed because one or more lines are too long
@ -62,9 +62,10 @@ var formatInputBytes = function (value) {
|
||||
* @returns {SolidityParam}
|
||||
*/
|
||||
var formatInputDynamicBytes = function (value) {
|
||||
value = utils.toHex(value);
|
||||
var result = utils.padRight((value).substr(2), 64);
|
||||
var length = Math.floor(value.length / 2 - 1);
|
||||
value = utils.toHex(value).substr(2);
|
||||
var l = Math.floor((value.length + 63) / 64);
|
||||
var result = utils.padRight(value, l * 64);
|
||||
var length = Math.floor(value.length / 2);
|
||||
return new SolidityParam(formatInputInt(length).value + result, 32);
|
||||
};
|
||||
|
||||
|
@ -182,13 +182,14 @@ var getOffset = function (bytes, index) {
|
||||
*/
|
||||
SolidityParam.decodeBytes = function (bytes, index) {
|
||||
index = index || 0;
|
||||
//TODO add support for strings longer than 32 bytes
|
||||
//var length = parseInt('0x' + bytes.substr(offset * 64, 64));
|
||||
|
||||
var offset = getOffset(bytes, index);
|
||||
|
||||
// 2 * , cause we also parse length
|
||||
return new SolidityParam(bytes.substr(offset * 2, 2 * 64), 0);
|
||||
var l = parseInt('0x' + bytes.substr(offset * 2, 64));
|
||||
l = Math.floor((l + 31) / 32);
|
||||
|
||||
// (1 + l) * , cause we also parse length
|
||||
return new SolidityParam(bytes.substr(offset * 2, (1 + l) * 64), 0);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -20,9 +20,9 @@ describe('lib/solidity/coder', function () {
|
||||
test({ type: 'int256', expected: new bn(1), value: '0000000000000000000000000000000000000000000000000000000000000001'});
|
||||
test({ type: 'int256', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
|
||||
test({ type: 'int256', expected: new bn(-1), value: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'});
|
||||
test({ type: 'int8', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
|
||||
test({ type: 'int32', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
|
||||
test({ type: 'int64', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
|
||||
test({ type: 'int8', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
|
||||
test({ type: 'int32', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
|
||||
test({ type: 'int64', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
|
||||
test({ type: 'int128', expected: new bn(16), value: '0000000000000000000000000000000000000000000000000000000000000010'});
|
||||
test({ type: 'bytes32', expected: '0x6761766f66796f726b0000000000000000000000000000000000000000000000',
|
||||
value: '6761766f66796f726b0000000000000000000000000000000000000000000000'});
|
||||
@ -36,6 +36,20 @@ describe('lib/solidity/coder', function () {
|
||||
value: '0000000000000000000000000000000000000000000000000000000000000020' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000020' +
|
||||
'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
|
||||
test({ type: 'bytes', expected: '0x731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
|
||||
value: '0000000000000000000000000000000000000000000000000000000000000020' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000040' +
|
||||
'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
|
||||
test({ type: 'bytes', expected: '0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
|
||||
value: '0000000000000000000000000000000000000000000000000000000000000020' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000060' +
|
||||
'131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
|
||||
test({ type: 'string', expected: 'gavofyork', value: '0000000000000000000000000000000000000000000000000000000000000020' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000009' +
|
||||
'6761766f66796f726b0000000000000000000000000000000000000000000000'});
|
||||
@ -100,17 +114,35 @@ describe('lib/solidity/coder', function () {
|
||||
test({ types: ['int', 'string', 'int', 'int', 'int', 'int[]'], expected: [new bn(1), 'gavofyork', new bn(2), new bn(3), new bn(4),
|
||||
[new bn(5), new bn(6), new bn(7)]],
|
||||
values: '0000000000000000000000000000000000000000000000000000000000000001' +
|
||||
'00000000000000000000000000000000000000000000000000000000000000c0' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000002' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000003' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000004' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000100' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000009' +
|
||||
'6761766f66796f726b0000000000000000000000000000000000000000000000' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000003' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000005' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000006' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000007'});
|
||||
'00000000000000000000000000000000000000000000000000000000000000c0' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000002' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000003' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000004' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000100' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000009' +
|
||||
'6761766f66796f726b0000000000000000000000000000000000000000000000' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000003' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000005' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000006' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000007'});
|
||||
test({ types: ['int', 'bytes', 'int', 'bytes'], expected: [
|
||||
new bn(5),
|
||||
'0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
|
||||
new bn(3),
|
||||
'0x331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'431a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
|
||||
],
|
||||
values: '0000000000000000000000000000000000000000000000000000000000000005' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000080' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000003' +
|
||||
'00000000000000000000000000000000000000000000000000000000000000e0' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000040' +
|
||||
'131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000040' +
|
||||
'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'431a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -75,6 +75,20 @@ describe('lib/solidity/coder', function () {
|
||||
test({ type: 'ureal', value: 1, expected: '0000000000000000000000000000000100000000000000000000000000000000'});
|
||||
test({ type: 'ureal', value: 2.125, expected: '0000000000000000000000000000000220000000000000000000000000000000'});
|
||||
test({ type: 'ureal', value: 8.5, expected: '0000000000000000000000000000000880000000000000000000000000000000'});
|
||||
test({ type: 'bytes', value: '0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
|
||||
expected: '0000000000000000000000000000000000000000000000000000000000000020' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000040' +
|
||||
'131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
|
||||
test({ type: 'bytes', value: '0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
|
||||
expected: '0000000000000000000000000000000000000000000000000000000000000020' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000060' +
|
||||
'131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
|
||||
});
|
||||
});
|
||||
|
||||
@ -167,6 +181,24 @@ describe('lib/solidity/coder', function () {
|
||||
'0000000000000000000000000000000000000000000000000000000000000005' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000006' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000007'});
|
||||
test({ types: ['int', 'bytes', 'int', 'bytes'], values: [
|
||||
5,
|
||||
'0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
|
||||
3,
|
||||
'0x331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'431a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
|
||||
],
|
||||
expected: '0000000000000000000000000000000000000000000000000000000000000005' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000080' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000003' +
|
||||
'00000000000000000000000000000000000000000000000000000000000000e0' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000040' +
|
||||
'131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000040' +
|
||||
'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' +
|
||||
'431a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user