Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
589c4fb3
Commit
589c4fb3
authored
Jan 31, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
formatInput && formatOutput simplified
parent
b20e972b
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
52 deletions
+56
-52
ethereum.js
dist/ethereum.js
+26
-24
ethereum.js.map
dist/ethereum.js.map
+3
-3
ethereum.min.js
dist/ethereum.min.js
+1
-1
abi.js
lib/abi.js
+23
-17
event.js
lib/event.js
+3
-7
No files found.
dist/ethereum.js
View file @
589c4fb3
...
@@ -28,6 +28,10 @@ var types = require('./types');
...
@@ -28,6 +28,10 @@ var types = require('./types');
var
c
=
require
(
'./const'
);
var
c
=
require
(
'./const'
);
var
f
=
require
(
'./formatters'
);
var
f
=
require
(
'./formatters'
);
var
displayTypeError
=
function
(
type
)
{
console
.
error
(
'parser does not support type: '
+
type
);
};
/// This method should be called if we want to check if givent type is an array type
/// This method should be called if we want to check if givent type is an array type
/// @returns true if it is, otherwise false
/// @returns true if it is, otherwise false
var
arrayType
=
function
(
type
)
{
var
arrayType
=
function
(
type
)
{
...
@@ -44,31 +48,31 @@ var dynamicTypeBytes = function (type, value) {
...
@@ -44,31 +48,31 @@ var dynamicTypeBytes = function (type, value) {
var
inputTypes
=
types
.
inputTypes
();
var
inputTypes
=
types
.
inputTypes
();
/// Formats input params to bytes
/// Formats input params to bytes
/// @param abi contract method
/// @param abi contract method
inputs
/// @param array of params that will be formatted to bytes
/// @param array of params that will be formatted to bytes
/// @returns bytes representation of input params
/// @returns bytes representation of input params
var
toAbiInput
=
function
(
method
,
params
)
{
var
formatInput
=
function
(
inputs
,
params
)
{
var
bytes
=
""
;
var
bytes
=
""
;
var
padding
=
c
.
ETH_PADDING
*
2
;
var
padding
=
c
.
ETH_PADDING
*
2
;
/// first we iterate in search for dynamic
/// first we iterate in search for dynamic
method
.
inputs
.
forEach
(
function
(
input
,
index
)
{
inputs
.
forEach
(
function
(
input
,
index
)
{
bytes
+=
dynamicTypeBytes
(
input
.
type
,
params
[
index
]);
bytes
+=
dynamicTypeBytes
(
input
.
type
,
params
[
index
]);
});
});
method
.
inputs
.
forEach
(
function
(
input
,
i
)
{
inputs
.
forEach
(
function
(
input
,
i
)
{
var
typeMatch
=
false
;
var
typeMatch
=
false
;
for
(
var
j
=
0
;
j
<
inputTypes
.
length
&&
!
typeMatch
;
j
++
)
{
for
(
var
j
=
0
;
j
<
inputTypes
.
length
&&
!
typeMatch
;
j
++
)
{
typeMatch
=
inputTypes
[
j
].
type
(
method
.
inputs
[
i
].
type
,
params
[
i
]);
typeMatch
=
inputTypes
[
j
].
type
(
inputs
[
i
].
type
,
params
[
i
]);
}
}
if
(
!
typeMatch
)
{
if
(
!
typeMatch
)
{
console
.
error
(
'input parser does not support type: '
+
method
.
inputs
[
i
].
type
);
displayTypeError
(
inputs
[
i
].
type
);
}
}
var
formatter
=
inputTypes
[
j
-
1
].
format
;
var
formatter
=
inputTypes
[
j
-
1
].
format
;
var
toAppend
=
""
;
var
toAppend
=
""
;
if
(
arrayType
(
method
.
inputs
[
i
].
type
))
if
(
arrayType
(
inputs
[
i
].
type
))
toAppend
=
params
[
i
].
reduce
(
function
(
acc
,
curr
)
{
toAppend
=
params
[
i
].
reduce
(
function
(
acc
,
curr
)
{
return
acc
+
formatter
(
curr
);
return
acc
+
formatter
(
curr
);
},
""
);
},
""
);
...
@@ -89,34 +93,34 @@ var dynamicBytesLength = function (type) {
...
@@ -89,34 +93,34 @@ var dynamicBytesLength = function (type) {
var
outputTypes
=
types
.
outputTypes
();
var
outputTypes
=
types
.
outputTypes
();
/// Formats output bytes back to param list
/// Formats output bytes back to param list
/// @param contract abi method
/// @param contract abi method
outputs
/// @param bytes representtion of output
/// @param bytes representtion of output
/// @returns array of output params
/// @returns array of output params
var
f
romAbiOutput
=
function
(
method
,
output
)
{
var
f
ormatOutput
=
function
(
outs
,
output
)
{
output
=
output
.
slice
(
2
);
output
=
output
.
slice
(
2
);
var
result
=
[];
var
result
=
[];
var
padding
=
c
.
ETH_PADDING
*
2
;
var
padding
=
c
.
ETH_PADDING
*
2
;
var
dynamicPartLength
=
method
.
outp
uts
.
reduce
(
function
(
acc
,
curr
)
{
var
dynamicPartLength
=
o
uts
.
reduce
(
function
(
acc
,
curr
)
{
return
acc
+
dynamicBytesLength
(
curr
.
type
);
return
acc
+
dynamicBytesLength
(
curr
.
type
);
},
0
);
},
0
);
var
dynamicPart
=
output
.
slice
(
0
,
dynamicPartLength
);
var
dynamicPart
=
output
.
slice
(
0
,
dynamicPartLength
);
output
=
output
.
slice
(
dynamicPartLength
);
output
=
output
.
slice
(
dynamicPartLength
);
method
.
outp
uts
.
forEach
(
function
(
out
,
i
)
{
o
uts
.
forEach
(
function
(
out
,
i
)
{
var
typeMatch
=
false
;
var
typeMatch
=
false
;
for
(
var
j
=
0
;
j
<
outputTypes
.
length
&&
!
typeMatch
;
j
++
)
{
for
(
var
j
=
0
;
j
<
outputTypes
.
length
&&
!
typeMatch
;
j
++
)
{
typeMatch
=
outputTypes
[
j
].
type
(
method
.
outp
uts
[
i
].
type
);
typeMatch
=
outputTypes
[
j
].
type
(
o
uts
[
i
].
type
);
}
}
if
(
!
typeMatch
)
{
if
(
!
typeMatch
)
{
console
.
error
(
'output parser does not support type: '
+
method
.
outp
uts
[
i
].
type
);
displayTypeError
(
o
uts
[
i
].
type
);
}
}
var
formatter
=
outputTypes
[
j
-
1
].
format
;
var
formatter
=
outputTypes
[
j
-
1
].
format
;
if
(
arrayType
(
method
.
outp
uts
[
i
].
type
))
{
if
(
arrayType
(
o
uts
[
i
].
type
))
{
var
size
=
f
.
formatOutputUInt
(
dynamicPart
.
slice
(
0
,
padding
));
var
size
=
f
.
formatOutputUInt
(
dynamicPart
.
slice
(
0
,
padding
));
dynamicPart
=
dynamicPart
.
slice
(
padding
);
dynamicPart
=
dynamicPart
.
slice
(
padding
);
var
array
=
[];
var
array
=
[];
...
@@ -126,7 +130,7 @@ var fromAbiOutput = function (method, output) {
...
@@ -126,7 +130,7 @@ var fromAbiOutput = function (method, output) {
}
}
result
.
push
(
array
);
result
.
push
(
array
);
}
}
else
if
(
types
.
prefixedType
(
'string'
)(
method
.
outp
uts
[
i
].
type
))
{
else
if
(
types
.
prefixedType
(
'string'
)(
o
uts
[
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
);
...
@@ -150,7 +154,7 @@ var inputParser = function (json) {
...
@@ -150,7 +154,7 @@ var inputParser = function (json) {
var
impl
=
function
()
{
var
impl
=
function
()
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
);
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
);
return
toAbiInput
(
method
,
params
);
return
formatInput
(
method
.
inputs
,
params
);
};
};
if
(
parser
[
displayName
]
===
undefined
)
{
if
(
parser
[
displayName
]
===
undefined
)
{
...
@@ -173,7 +177,7 @@ var outputParser = function (json) {
...
@@ -173,7 +177,7 @@ var outputParser = function (json) {
var
typeName
=
utils
.
extractTypeName
(
method
.
name
);
var
typeName
=
utils
.
extractTypeName
(
method
.
name
);
var
impl
=
function
(
output
)
{
var
impl
=
function
(
output
)
{
return
f
romAbiOutput
(
method
,
output
);
return
f
ormatOutput
(
method
.
outputs
,
output
);
};
};
if
(
parser
[
displayName
]
===
undefined
)
{
if
(
parser
[
displayName
]
===
undefined
)
{
...
@@ -195,6 +199,8 @@ var signatureFromAscii = function (name) {
...
@@ -195,6 +199,8 @@ var signatureFromAscii = function (name) {
module
.
exports
=
{
module
.
exports
=
{
inputParser
:
inputParser
,
inputParser
:
inputParser
,
outputParser
:
outputParser
,
outputParser
:
outputParser
,
formatInput
:
formatInput
,
formatOutput
:
formatOutput
,
signatureFromAscii
:
signatureFromAscii
signatureFromAscii
:
signatureFromAscii
};
};
...
@@ -485,19 +491,15 @@ var inputWithName = function (inputs, name) {
...
@@ -485,19 +491,15 @@ var inputWithName = function (inputs, name) {
var
indexedParamsToTopics
=
function
(
event
,
indexed
)
{
var
indexedParamsToTopics
=
function
(
event
,
indexed
)
{
// sort keys?
// sort keys?
return
Object
.
keys
(
indexed
).
map
(
function
(
key
)
{
return
Object
.
keys
(
indexed
).
map
(
function
(
key
)
{
// TODO: simplify this!
var
inputs
=
[
inputWithName
(
event
.
inputs
,
key
)];
var
parser
=
abi
.
inputParser
([{
name
:
'test'
,
inputs
:
[
inputWithName
(
event
.
inputs
,
key
)]
}]);
var
value
=
indexed
[
key
];
var
value
=
indexed
[
key
];
if
(
value
instanceof
Array
)
{
if
(
value
instanceof
Array
)
{
return
value
.
map
(
function
(
v
)
{
return
value
.
map
(
function
(
v
)
{
return
parser
.
test
(
v
);
return
abi
.
formatInput
(
inputs
,
[
v
]
);
});
});
}
}
return
parser
.
test
(
value
);
return
abi
.
formatInput
(
inputs
,
[
value
]
);
});
});
};
};
...
...
dist/ethereum.js.map
View file @
589c4fb3
This diff is collapsed.
Click to expand it.
dist/ethereum.min.js
View file @
589c4fb3
This diff is collapsed.
Click to expand it.
lib/abi.js
View file @
589c4fb3
...
@@ -27,6 +27,10 @@ var types = require('./types');
...
@@ -27,6 +27,10 @@ var types = require('./types');
var
c
=
require
(
'./const'
);
var
c
=
require
(
'./const'
);
var
f
=
require
(
'./formatters'
);
var
f
=
require
(
'./formatters'
);
var
displayTypeError
=
function
(
type
)
{
console
.
error
(
'parser does not support type: '
+
type
);
};
/// This method should be called if we want to check if givent type is an array type
/// This method should be called if we want to check if givent type is an array type
/// @returns true if it is, otherwise false
/// @returns true if it is, otherwise false
var
arrayType
=
function
(
type
)
{
var
arrayType
=
function
(
type
)
{
...
@@ -43,31 +47,31 @@ var dynamicTypeBytes = function (type, value) {
...
@@ -43,31 +47,31 @@ var dynamicTypeBytes = function (type, value) {
var
inputTypes
=
types
.
inputTypes
();
var
inputTypes
=
types
.
inputTypes
();
/// Formats input params to bytes
/// Formats input params to bytes
/// @param abi contract method
/// @param abi contract method
inputs
/// @param array of params that will be formatted to bytes
/// @param array of params that will be formatted to bytes
/// @returns bytes representation of input params
/// @returns bytes representation of input params
var
toAbiInput
=
function
(
method
,
params
)
{
var
formatInput
=
function
(
inputs
,
params
)
{
var
bytes
=
""
;
var
bytes
=
""
;
var
padding
=
c
.
ETH_PADDING
*
2
;
var
padding
=
c
.
ETH_PADDING
*
2
;
/// first we iterate in search for dynamic
/// first we iterate in search for dynamic
method
.
inputs
.
forEach
(
function
(
input
,
index
)
{
inputs
.
forEach
(
function
(
input
,
index
)
{
bytes
+=
dynamicTypeBytes
(
input
.
type
,
params
[
index
]);
bytes
+=
dynamicTypeBytes
(
input
.
type
,
params
[
index
]);
});
});
method
.
inputs
.
forEach
(
function
(
input
,
i
)
{
inputs
.
forEach
(
function
(
input
,
i
)
{
var
typeMatch
=
false
;
var
typeMatch
=
false
;
for
(
var
j
=
0
;
j
<
inputTypes
.
length
&&
!
typeMatch
;
j
++
)
{
for
(
var
j
=
0
;
j
<
inputTypes
.
length
&&
!
typeMatch
;
j
++
)
{
typeMatch
=
inputTypes
[
j
].
type
(
method
.
inputs
[
i
].
type
,
params
[
i
]);
typeMatch
=
inputTypes
[
j
].
type
(
inputs
[
i
].
type
,
params
[
i
]);
}
}
if
(
!
typeMatch
)
{
if
(
!
typeMatch
)
{
console
.
error
(
'input parser does not support type: '
+
method
.
inputs
[
i
].
type
);
displayTypeError
(
inputs
[
i
].
type
);
}
}
var
formatter
=
inputTypes
[
j
-
1
].
format
;
var
formatter
=
inputTypes
[
j
-
1
].
format
;
var
toAppend
=
""
;
var
toAppend
=
""
;
if
(
arrayType
(
method
.
inputs
[
i
].
type
))
if
(
arrayType
(
inputs
[
i
].
type
))
toAppend
=
params
[
i
].
reduce
(
function
(
acc
,
curr
)
{
toAppend
=
params
[
i
].
reduce
(
function
(
acc
,
curr
)
{
return
acc
+
formatter
(
curr
);
return
acc
+
formatter
(
curr
);
},
""
);
},
""
);
...
@@ -88,34 +92,34 @@ var dynamicBytesLength = function (type) {
...
@@ -88,34 +92,34 @@ var dynamicBytesLength = function (type) {
var
outputTypes
=
types
.
outputTypes
();
var
outputTypes
=
types
.
outputTypes
();
/// Formats output bytes back to param list
/// Formats output bytes back to param list
/// @param contract abi method
/// @param contract abi method
outputs
/// @param bytes representtion of output
/// @param bytes representtion of output
/// @returns array of output params
/// @returns array of output params
var
f
romAbiOutput
=
function
(
method
,
output
)
{
var
f
ormatOutput
=
function
(
outs
,
output
)
{
output
=
output
.
slice
(
2
);
output
=
output
.
slice
(
2
);
var
result
=
[];
var
result
=
[];
var
padding
=
c
.
ETH_PADDING
*
2
;
var
padding
=
c
.
ETH_PADDING
*
2
;
var
dynamicPartLength
=
method
.
outp
uts
.
reduce
(
function
(
acc
,
curr
)
{
var
dynamicPartLength
=
o
uts
.
reduce
(
function
(
acc
,
curr
)
{
return
acc
+
dynamicBytesLength
(
curr
.
type
);
return
acc
+
dynamicBytesLength
(
curr
.
type
);
},
0
);
},
0
);
var
dynamicPart
=
output
.
slice
(
0
,
dynamicPartLength
);
var
dynamicPart
=
output
.
slice
(
0
,
dynamicPartLength
);
output
=
output
.
slice
(
dynamicPartLength
);
output
=
output
.
slice
(
dynamicPartLength
);
method
.
outp
uts
.
forEach
(
function
(
out
,
i
)
{
o
uts
.
forEach
(
function
(
out
,
i
)
{
var
typeMatch
=
false
;
var
typeMatch
=
false
;
for
(
var
j
=
0
;
j
<
outputTypes
.
length
&&
!
typeMatch
;
j
++
)
{
for
(
var
j
=
0
;
j
<
outputTypes
.
length
&&
!
typeMatch
;
j
++
)
{
typeMatch
=
outputTypes
[
j
].
type
(
method
.
outp
uts
[
i
].
type
);
typeMatch
=
outputTypes
[
j
].
type
(
o
uts
[
i
].
type
);
}
}
if
(
!
typeMatch
)
{
if
(
!
typeMatch
)
{
console
.
error
(
'output parser does not support type: '
+
method
.
outp
uts
[
i
].
type
);
displayTypeError
(
o
uts
[
i
].
type
);
}
}
var
formatter
=
outputTypes
[
j
-
1
].
format
;
var
formatter
=
outputTypes
[
j
-
1
].
format
;
if
(
arrayType
(
method
.
outp
uts
[
i
].
type
))
{
if
(
arrayType
(
o
uts
[
i
].
type
))
{
var
size
=
f
.
formatOutputUInt
(
dynamicPart
.
slice
(
0
,
padding
));
var
size
=
f
.
formatOutputUInt
(
dynamicPart
.
slice
(
0
,
padding
));
dynamicPart
=
dynamicPart
.
slice
(
padding
);
dynamicPart
=
dynamicPart
.
slice
(
padding
);
var
array
=
[];
var
array
=
[];
...
@@ -125,7 +129,7 @@ var fromAbiOutput = function (method, output) {
...
@@ -125,7 +129,7 @@ var fromAbiOutput = function (method, output) {
}
}
result
.
push
(
array
);
result
.
push
(
array
);
}
}
else
if
(
types
.
prefixedType
(
'string'
)(
method
.
outp
uts
[
i
].
type
))
{
else
if
(
types
.
prefixedType
(
'string'
)(
o
uts
[
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
);
...
@@ -149,7 +153,7 @@ var inputParser = function (json) {
...
@@ -149,7 +153,7 @@ var inputParser = function (json) {
var
impl
=
function
()
{
var
impl
=
function
()
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
);
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
);
return
toAbiInput
(
method
,
params
);
return
formatInput
(
method
.
inputs
,
params
);
};
};
if
(
parser
[
displayName
]
===
undefined
)
{
if
(
parser
[
displayName
]
===
undefined
)
{
...
@@ -172,7 +176,7 @@ var outputParser = function (json) {
...
@@ -172,7 +176,7 @@ var outputParser = function (json) {
var
typeName
=
utils
.
extractTypeName
(
method
.
name
);
var
typeName
=
utils
.
extractTypeName
(
method
.
name
);
var
impl
=
function
(
output
)
{
var
impl
=
function
(
output
)
{
return
f
romAbiOutput
(
method
,
output
);
return
f
ormatOutput
(
method
.
outputs
,
output
);
};
};
if
(
parser
[
displayName
]
===
undefined
)
{
if
(
parser
[
displayName
]
===
undefined
)
{
...
@@ -194,6 +198,8 @@ var signatureFromAscii = function (name) {
...
@@ -194,6 +198,8 @@ var signatureFromAscii = function (name) {
module
.
exports
=
{
module
.
exports
=
{
inputParser
:
inputParser
,
inputParser
:
inputParser
,
outputParser
:
outputParser
,
outputParser
:
outputParser
,
formatInput
:
formatInput
,
formatOutput
:
formatOutput
,
signatureFromAscii
:
signatureFromAscii
signatureFromAscii
:
signatureFromAscii
};
};
lib/event.js
View file @
589c4fb3
...
@@ -38,19 +38,15 @@ var inputWithName = function (inputs, name) {
...
@@ -38,19 +38,15 @@ var inputWithName = function (inputs, name) {
var
indexedParamsToTopics
=
function
(
event
,
indexed
)
{
var
indexedParamsToTopics
=
function
(
event
,
indexed
)
{
// sort keys?
// sort keys?
return
Object
.
keys
(
indexed
).
map
(
function
(
key
)
{
return
Object
.
keys
(
indexed
).
map
(
function
(
key
)
{
// TODO: simplify this!
var
inputs
=
[
inputWithName
(
event
.
inputs
,
key
)];
var
parser
=
abi
.
inputParser
([{
name
:
'test'
,
inputs
:
[
inputWithName
(
event
.
inputs
,
key
)]
}]);
var
value
=
indexed
[
key
];
var
value
=
indexed
[
key
];
if
(
value
instanceof
Array
)
{
if
(
value
instanceof
Array
)
{
return
value
.
map
(
function
(
v
)
{
return
value
.
map
(
function
(
v
)
{
return
parser
.
test
(
v
);
return
abi
.
formatInput
(
inputs
,
[
v
]
);
});
});
}
}
return
parser
.
test
(
value
);
return
abi
.
formatInput
(
inputs
,
[
value
]
);
});
});
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment