string type basically becomes bytes type

This commit is contained in:
Lefteris Karapetsas 2015-03-13 13:05:13 +01:00
parent 760634a1cd
commit 3a22498281
4 changed files with 16 additions and 18 deletions

View File

@ -57,7 +57,7 @@ var isArrayType = function (type) {
*/ */
var dynamicTypeBytes = function (type, value) { var dynamicTypeBytes = function (type, value) {
// TODO: decide what to do with array of strings // TODO: decide what to do with array of strings
if (isArrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length. if (isArrayType(type) || type === 'bytes')
return f.formatInputInt(value.length); return f.formatInputInt(value.length);
return ""; return "";
}; };
@ -98,7 +98,7 @@ var formatInput = function (inputs, params) {
toAppendArrayContent += params[i].reduce(function (acc, curr) { toAppendArrayContent += params[i].reduce(function (acc, curr) {
return acc + formatter(curr); return acc + formatter(curr);
}, ""); }, "");
else if (inputs[i].type === 'string') else if (inputs[i].type === 'bytes')
toAppendArrayContent += formatter(params[i]); toAppendArrayContent += formatter(params[i]);
else else
toAppendConstant += formatter(params[i]); toAppendConstant += formatter(params[i]);
@ -117,7 +117,7 @@ var formatInput = function (inputs, params) {
* @returns {Number} length of dynamic type, 0 or multiplication of ETH_PADDING (32) * @returns {Number} length of dynamic type, 0 or multiplication of ETH_PADDING (32)
*/ */
var dynamicBytesLength = function (type) { var dynamicBytesLength = function (type) {
if (isArrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length. if (isArrayType(type) || type === 'bytes')
return c.ETH_PADDING * 2; return c.ETH_PADDING * 2;
return 0; return 0;
}; };
@ -167,7 +167,7 @@ var formatOutput = function (outs, output) {
} }
result.push(array); result.push(array);
} }
else if (types.prefixedType('string')(outs[i].type)) { else if (types.prefixedType('bytes')(outs[i].type)) {
dynamicPart = dynamicPart.slice(padding); dynamicPart = dynamicPart.slice(padding);
result.push(formatter(output.slice(0, padding))); result.push(formatter(output.slice(0, padding)));
output = output.slice(padding); output = output.slice(padding);

View File

@ -45,8 +45,7 @@ var inputTypes = function () {
return [ return [
{ type: prefixedType('uint'), format: f.formatInputInt }, { type: prefixedType('uint'), format: f.formatInputInt },
{ type: prefixedType('int'), format: f.formatInputInt }, { type: prefixedType('int'), format: f.formatInputInt },
{ type: prefixedType('hash'), format: f.formatInputInt }, { type: prefixedType('bytes'), format: f.formatInputString },
{ type: prefixedType('string'), format: f.formatInputString },
{ type: prefixedType('real'), format: f.formatInputReal }, { type: prefixedType('real'), format: f.formatInputReal },
{ type: prefixedType('ureal'), format: f.formatInputReal }, { type: prefixedType('ureal'), format: f.formatInputReal },
{ type: namedType('address'), format: f.formatInputInt }, { type: namedType('address'), format: f.formatInputInt },
@ -61,8 +60,7 @@ var outputTypes = function () {
return [ return [
{ type: prefixedType('uint'), format: f.formatOutputUInt }, { type: prefixedType('uint'), format: f.formatOutputUInt },
{ type: prefixedType('int'), format: f.formatOutputInt }, { type: prefixedType('int'), format: f.formatOutputInt },
{ type: prefixedType('hash'), format: f.formatOutputHash }, { type: prefixedType('bytes'), format: f.formatOutputString },
{ type: prefixedType('string'), format: f.formatOutputString },
{ type: prefixedType('real'), format: f.formatOutputReal }, { type: prefixedType('real'), format: f.formatOutputReal },
{ type: prefixedType('ureal'), format: f.formatOutputUReal }, { type: prefixedType('ureal'), format: f.formatOutputUReal },
{ type: namedType('address'), format: f.formatOutputAddress }, { type: namedType('address'), format: f.formatOutputAddress },

View File

@ -250,7 +250,7 @@ describe('abi', function() {
var d = clone(description); var d = clone(description);
d[0].inputs = [ d[0].inputs = [
{ type: "bytes32" } { type: "bytes" }
]; ];
// when // when
@ -275,7 +275,7 @@ describe('abi', function() {
d[0].inputs = [ d[0].inputs = [
{ type: "int" }, { type: "int" },
{ type: "bytes32" } { type: "bytes" }
]; ];
// when // when
@ -296,7 +296,7 @@ describe('abi', function() {
var d = clone(description); var d = clone(description);
d[0].inputs = [ d[0].inputs = [
{ type: "bytes32" }, { type: "bytes" },
{ type: "int" } { type: "int" }
]; ];
@ -341,8 +341,8 @@ describe('abi', function() {
},{ },{
name: "test2", name: "test2",
type: "function", type: "function",
inputs: [{ type: "bytes32" }], inputs: [{ type: "bytes" }],
outputs: [{ type: "bytes32" }] outputs: [{ type: "bytes" }]
}]; }];
// when // when

View File

@ -27,7 +27,7 @@ describe('abi', function() {
var d = clone(description); var d = clone(description);
d[0].outputs = [ d[0].outputs = [
{ type: "bytes32" } { type: "bytes" }
]; ];
// when // when
@ -265,8 +265,8 @@ describe('abi', function() {
var d = clone(description); var d = clone(description);
d[0].outputs = [ d[0].outputs = [
{ type: "bytes32" }, { type: "bytes" },
{ type: "bytes32" } { type: "bytes" }
]; ];
// when // when
@ -322,8 +322,8 @@ describe('abi', function() {
},{ },{
name: "test2", name: "test2",
type: "function", type: "function",
inputs: [{ type: "bytes32" }], inputs: [{ type: "bytes" }],
outputs: [{ type: "bytes32" }] outputs: [{ type: "bytes" }]
}]; }];
// when // when