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
4bdf52fc
Commit
4bdf52fc
authored
Jan 31, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
toAscii && fromAscii moved to utils
parent
0b82a05a
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
122 additions
and
146 deletions
+122
-146
ethereum.js
dist/ethereum.js
+59
-71
ethereum.js.map
dist/ethereum.js.map
+5
-5
ethereum.min.js
dist/ethereum.min.js
+1
-1
abi.js
lib/abi.js
+7
-30
formatters.js
lib/formatters.js
+3
-4
utils.js
lib/utils.js
+43
-1
web3.js
lib/web3.js
+4
-34
No files found.
dist/ethereum.js
View file @
4bdf52fc
...
...
@@ -38,23 +38,6 @@ var ETH_PADDING = 32;
/// method signature length in bytes
var
ETH_METHOD_SIGNATURE_LENGTH
=
4
;
/// @returns a function that is used as a pattern for 'findIndex'
var
findMethodIndex
=
function
(
json
,
methodName
)
{
return
utils
.
findIndex
(
json
,
function
(
method
)
{
return
method
.
name
===
methodName
;
});
};
/// @returns method with given method name
var
getMethodWithName
=
function
(
json
,
methodName
)
{
var
index
=
findMethodIndex
(
json
,
methodName
);
if
(
index
===
-
1
)
{
console
.
error
(
'method '
+
methodName
+
' not found in the abi'
);
return
undefined
;
}
return
json
[
index
];
};
/// Filters all function from input abi
/// @returns abi array with filtered objects of type 'function'
var
filterFunctions
=
function
(
json
)
{
...
...
@@ -87,14 +70,11 @@ var dynamicTypeBytes = function (type, value) {
var
inputTypes
=
types
.
inputTypes
();
/// Formats input params to bytes
/// @param contract json abi
/// @param name of the method that we want to use
/// @param abi contract method
/// @param array of params that will be formatted to bytes
/// @returns bytes representation of input params
var
toAbiInput
=
function
(
json
,
methodName
,
params
)
{
var
toAbiInput
=
function
(
method
,
params
)
{
var
bytes
=
""
;
var
method
=
getMethodWithName
(
json
,
methodName
);
var
padding
=
ETH_PADDING
*
2
;
/// first we iterate in search for dynamic
...
...
@@ -135,15 +115,13 @@ var dynamicBytesLength = function (type) {
var
outputTypes
=
types
.
outputTypes
();
/// Formats output bytes back to param list
/// @param contract json abi
/// @param name of the method that we want to use
/// @param contract abi method
/// @param bytes representtion of output
/// @returns array of output params
var
fromAbiOutput
=
function
(
json
,
methodName
,
output
)
{
var
fromAbiOutput
=
function
(
method
,
output
)
{
output
=
output
.
slice
(
2
);
var
result
=
[];
var
method
=
getMethodWithName
(
json
,
methodName
);
var
padding
=
ETH_PADDING
*
2
;
var
dynamicPartLength
=
method
.
outputs
.
reduce
(
function
(
acc
,
curr
)
{
...
...
@@ -195,7 +173,7 @@ var methodDisplayName = function (method) {
/// @returns overloaded part of method's name
var
methodTypeName
=
function
(
method
)
{
/// TODO: make it
not
vulnerable
/// TODO: make it
in
vulnerable
var
length
=
method
.
indexOf
(
'('
);
return
length
!==
-
1
?
method
.
substr
(
length
+
1
,
method
.
length
-
1
-
(
length
+
1
))
:
""
;
};
...
...
@@ -211,7 +189,7 @@ var inputParser = function (json) {
var
impl
=
function
()
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
);
return
toAbiInput
(
json
,
method
.
name
,
params
);
return
toAbiInput
(
method
,
params
);
};
if
(
parser
[
displayName
]
===
undefined
)
{
...
...
@@ -234,7 +212,7 @@ var outputParser = function (json) {
var
typeName
=
methodTypeName
(
method
.
name
);
var
impl
=
function
(
output
)
{
return
fromAbiOutput
(
json
,
method
.
name
,
output
);
return
fromAbiOutput
(
method
,
output
);
};
if
(
parser
[
displayName
]
===
undefined
)
{
...
...
@@ -259,7 +237,6 @@ module.exports = {
methodSignature
:
methodSignature
,
methodDisplayName
:
methodDisplayName
,
methodTypeName
:
methodTypeName
,
getMethodWithName
:
getMethodWithName
,
filterFunctions
:
filterFunctions
,
filterEvents
:
filterEvents
};
...
...
@@ -673,8 +650,7 @@ if ("build" !== 'build') {/*
var BigNumber = require('bignumber.js'); // jshint ignore:line
*/
}
// TODO: remove web3 dependency from here!
var
web3
=
require
(
'./web3'
);
var
utils
=
require
(
'./utils'
);
BigNumber
.
config
({
ROUNDING_MODE
:
BigNumber
.
ROUND_DOWN
});
...
...
@@ -715,7 +691,7 @@ var formatInputInt = function (value) {
/// Formats input value to byte representation of string
/// @returns left-algined byte representation of string
var
formatInputString
=
function
(
value
)
{
return
web3
.
fromAscii
(
value
,
ETH_PADDING
).
substr
(
2
);
return
utils
.
fromAscii
(
value
,
ETH_PADDING
).
substr
(
2
);
};
/// Formats input value to byte representation of bool
...
...
@@ -780,7 +756,7 @@ var formatOutputBool = function (value) {
/// @returns left-aligned input bytes formatted to ascii string
var
formatOutputString
=
function
(
value
)
{
return
web3
.
toAscii
(
value
);
return
utils
.
toAscii
(
value
);
};
/// @returns right-aligned input bytes formatted to address
...
...
@@ -805,7 +781,7 @@ module.exports = {
};
},{
"./
web3"
:
11
}],
6
:[
function
(
require
,
module
,
exports
){
},{
"./
utils"
:
10
}],
6
:[
function
(
require
,
module
,
exports
){
/*
This file is part of ethereum.js.
...
...
@@ -1140,8 +1116,50 @@ var findIndex = function (array, callback) {
return
end
?
i
-
1
:
-
1
;
};
/// @returns ascii string representation of hex value prefixed with 0x
var
toAscii
=
function
(
hex
)
{
// Find termination
var
str
=
""
;
var
i
=
0
,
l
=
hex
.
length
;
if
(
hex
.
substring
(
0
,
2
)
===
'0x'
)
{
i
=
2
;
}
for
(;
i
<
l
;
i
+=
2
)
{
var
code
=
parseInt
(
hex
.
substr
(
i
,
2
),
16
);
if
(
code
===
0
)
{
break
;
}
str
+=
String
.
fromCharCode
(
code
);
}
return
str
;
};
var
toHex
=
function
(
str
)
{
var
hex
=
""
;
for
(
var
i
=
0
;
i
<
str
.
length
;
i
++
)
{
var
n
=
str
.
charCodeAt
(
i
).
toString
(
16
);
hex
+=
n
.
length
<
2
?
'0'
+
n
:
n
;
}
return
hex
;
};
/// @returns hex representation (prefixed by 0x) of ascii string
var
fromAscii
=
function
(
str
,
pad
)
{
pad
=
pad
===
undefined
?
0
:
pad
;
var
hex
=
toHex
(
str
);
while
(
hex
.
length
<
pad
*
2
)
hex
+=
"00"
;
return
"0x"
+
hex
;
};
module
.
exports
=
{
findIndex
:
findIndex
findIndex
:
findIndex
,
toAscii
:
toAscii
,
fromAscii
:
fromAscii
};
...
...
@@ -1175,6 +1193,8 @@ if ("build" !== 'build') {/*
var BigNumber = require('bignumber.js');
*/
}
var
utils
=
require
(
'./utils'
);
var
ETH_UNITS
=
[
'wei'
,
'Kwei'
,
...
...
@@ -1340,43 +1360,11 @@ var web3 = {
_events
:
{},
providers
:
{},
toHex
:
function
(
str
)
{
var
hex
=
""
;
for
(
var
i
=
0
;
i
<
str
.
length
;
i
++
)
{
var
n
=
str
.
charCodeAt
(
i
).
toString
(
16
);
hex
+=
n
.
length
<
2
?
'0'
+
n
:
n
;
}
return
hex
;
},
/// @returns ascii string representation of hex value prefixed with 0x
toAscii
:
function
(
hex
)
{
// Find termination
var
str
=
""
;
var
i
=
0
,
l
=
hex
.
length
;
if
(
hex
.
substring
(
0
,
2
)
===
'0x'
)
i
=
2
;
for
(;
i
<
l
;
i
+=
2
)
{
var
code
=
parseInt
(
hex
.
substr
(
i
,
2
),
16
);
if
(
code
===
0
)
{
break
;
}
str
+=
String
.
fromCharCode
(
code
);
}
return
str
;
},
toAscii
:
utils
.
toAscii
,
/// @returns hex representation (prefixed by 0x) of ascii string
fromAscii
:
function
(
str
,
pad
)
{
pad
=
pad
===
undefined
?
0
:
pad
;
var
hex
=
this
.
toHex
(
str
);
while
(
hex
.
length
<
pad
*
2
)
hex
+=
"00"
;
return
"0x"
+
hex
;
},
fromAscii
:
utils
.
fromAscii
,
/// @returns decimal representaton of hex value prefixed by 0x
toDecimal
:
function
(
val
)
{
...
...
@@ -1482,7 +1470,7 @@ web3.setProvider = function(provider) {
module
.
exports
=
web3
;
},{}],
"web3"
:[
function
(
require
,
module
,
exports
){
},{
"./utils"
:
10
}],
"web3"
:[
function
(
require
,
module
,
exports
){
var
web3
=
require
(
'./lib/web3'
);
var
ProviderManager
=
require
(
'./lib/providermanager'
);
web3
.
provider
=
new
ProviderManager
();
...
...
dist/ethereum.js.map
View file @
4bdf52fc
This diff is collapsed.
Click to expand it.
dist/ethereum.min.js
View file @
4bdf52fc
This diff is collapsed.
Click to expand it.
lib/abi.js
View file @
4bdf52fc
...
...
@@ -37,23 +37,6 @@ var ETH_PADDING = 32;
/// method signature length in bytes
var
ETH_METHOD_SIGNATURE_LENGTH
=
4
;
/// @returns a function that is used as a pattern for 'findIndex'
var
findMethodIndex
=
function
(
json
,
methodName
)
{
return
utils
.
findIndex
(
json
,
function
(
method
)
{
return
method
.
name
===
methodName
;
});
};
/// @returns method with given method name
var
getMethodWithName
=
function
(
json
,
methodName
)
{
var
index
=
findMethodIndex
(
json
,
methodName
);
if
(
index
===
-
1
)
{
console
.
error
(
'method '
+
methodName
+
' not found in the abi'
);
return
undefined
;
}
return
json
[
index
];
};
/// Filters all function from input abi
/// @returns abi array with filtered objects of type 'function'
var
filterFunctions
=
function
(
json
)
{
...
...
@@ -86,14 +69,11 @@ var dynamicTypeBytes = function (type, value) {
var
inputTypes
=
types
.
inputTypes
();
/// Formats input params to bytes
/// @param contract json abi
/// @param name of the method that we want to use
/// @param abi contract method
/// @param array of params that will be formatted to bytes
/// @returns bytes representation of input params
var
toAbiInput
=
function
(
json
,
methodName
,
params
)
{
var
toAbiInput
=
function
(
method
,
params
)
{
var
bytes
=
""
;
var
method
=
getMethodWithName
(
json
,
methodName
);
var
padding
=
ETH_PADDING
*
2
;
/// first we iterate in search for dynamic
...
...
@@ -134,15 +114,13 @@ var dynamicBytesLength = function (type) {
var
outputTypes
=
types
.
outputTypes
();
/// Formats output bytes back to param list
/// @param contract json abi
/// @param name of the method that we want to use
/// @param contract abi method
/// @param bytes representtion of output
/// @returns array of output params
var
fromAbiOutput
=
function
(
json
,
methodName
,
output
)
{
var
fromAbiOutput
=
function
(
method
,
output
)
{
output
=
output
.
slice
(
2
);
var
result
=
[];
var
method
=
getMethodWithName
(
json
,
methodName
);
var
padding
=
ETH_PADDING
*
2
;
var
dynamicPartLength
=
method
.
outputs
.
reduce
(
function
(
acc
,
curr
)
{
...
...
@@ -194,7 +172,7 @@ var methodDisplayName = function (method) {
/// @returns overloaded part of method's name
var
methodTypeName
=
function
(
method
)
{
/// TODO: make it
not
vulnerable
/// TODO: make it
in
vulnerable
var
length
=
method
.
indexOf
(
'('
);
return
length
!==
-
1
?
method
.
substr
(
length
+
1
,
method
.
length
-
1
-
(
length
+
1
))
:
""
;
};
...
...
@@ -210,7 +188,7 @@ var inputParser = function (json) {
var
impl
=
function
()
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
);
return
toAbiInput
(
json
,
method
.
name
,
params
);
return
toAbiInput
(
method
,
params
);
};
if
(
parser
[
displayName
]
===
undefined
)
{
...
...
@@ -233,7 +211,7 @@ var outputParser = function (json) {
var
typeName
=
methodTypeName
(
method
.
name
);
var
impl
=
function
(
output
)
{
return
fromAbiOutput
(
json
,
method
.
name
,
output
);
return
fromAbiOutput
(
method
,
output
);
};
if
(
parser
[
displayName
]
===
undefined
)
{
...
...
@@ -258,7 +236,6 @@ module.exports = {
methodSignature
:
methodSignature
,
methodDisplayName
:
methodDisplayName
,
methodTypeName
:
methodTypeName
,
getMethodWithName
:
getMethodWithName
,
filterFunctions
:
filterFunctions
,
filterEvents
:
filterEvents
};
...
...
lib/formatters.js
View file @
4bdf52fc
...
...
@@ -24,8 +24,7 @@ if (process.env.NODE_ENV !== 'build') {
var
BigNumber
=
require
(
'bignumber.js'
);
// jshint ignore:line
}
// TODO: remove web3 dependency from here!
var
web3
=
require
(
'./web3'
);
var
utils
=
require
(
'./utils'
);
BigNumber
.
config
({
ROUNDING_MODE
:
BigNumber
.
ROUND_DOWN
});
...
...
@@ -66,7 +65,7 @@ var formatInputInt = function (value) {
/// Formats input value to byte representation of string
/// @returns left-algined byte representation of string
var
formatInputString
=
function
(
value
)
{
return
web3
.
fromAscii
(
value
,
ETH_PADDING
).
substr
(
2
);
return
utils
.
fromAscii
(
value
,
ETH_PADDING
).
substr
(
2
);
};
/// Formats input value to byte representation of bool
...
...
@@ -131,7 +130,7 @@ var formatOutputBool = function (value) {
/// @returns left-aligned input bytes formatted to ascii string
var
formatOutputString
=
function
(
value
)
{
return
web3
.
toAscii
(
value
);
return
utils
.
toAscii
(
value
);
};
/// @returns right-aligned input bytes formatted to address
...
...
lib/utils.js
View file @
4bdf52fc
...
...
@@ -33,7 +33,49 @@ var findIndex = function (array, callback) {
return
end
?
i
-
1
:
-
1
;
};
/// @returns ascii string representation of hex value prefixed with 0x
var
toAscii
=
function
(
hex
)
{
// Find termination
var
str
=
""
;
var
i
=
0
,
l
=
hex
.
length
;
if
(
hex
.
substring
(
0
,
2
)
===
'0x'
)
{
i
=
2
;
}
for
(;
i
<
l
;
i
+=
2
)
{
var
code
=
parseInt
(
hex
.
substr
(
i
,
2
),
16
);
if
(
code
===
0
)
{
break
;
}
str
+=
String
.
fromCharCode
(
code
);
}
return
str
;
};
var
toHex
=
function
(
str
)
{
var
hex
=
""
;
for
(
var
i
=
0
;
i
<
str
.
length
;
i
++
)
{
var
n
=
str
.
charCodeAt
(
i
).
toString
(
16
);
hex
+=
n
.
length
<
2
?
'0'
+
n
:
n
;
}
return
hex
;
};
/// @returns hex representation (prefixed by 0x) of ascii string
var
fromAscii
=
function
(
str
,
pad
)
{
pad
=
pad
===
undefined
?
0
:
pad
;
var
hex
=
toHex
(
str
);
while
(
hex
.
length
<
pad
*
2
)
hex
+=
"00"
;
return
"0x"
+
hex
;
};
module
.
exports
=
{
findIndex
:
findIndex
findIndex
:
findIndex
,
toAscii
:
toAscii
,
fromAscii
:
fromAscii
};
lib/web3.js
View file @
4bdf52fc
...
...
@@ -27,6 +27,8 @@ if (process.env.NODE_ENV !== 'build') {
var
BigNumber
=
require
(
'bignumber.js'
);
}
var
utils
=
require
(
'./utils'
);
var
ETH_UNITS
=
[
'wei'
,
'Kwei'
,
...
...
@@ -192,43 +194,11 @@ var web3 = {
_events
:
{},
providers
:
{},
toHex
:
function
(
str
)
{
var
hex
=
""
;
for
(
var
i
=
0
;
i
<
str
.
length
;
i
++
)
{
var
n
=
str
.
charCodeAt
(
i
).
toString
(
16
);
hex
+=
n
.
length
<
2
?
'0'
+
n
:
n
;
}
return
hex
;
},
/// @returns ascii string representation of hex value prefixed with 0x
toAscii
:
function
(
hex
)
{
// Find termination
var
str
=
""
;
var
i
=
0
,
l
=
hex
.
length
;
if
(
hex
.
substring
(
0
,
2
)
===
'0x'
)
i
=
2
;
for
(;
i
<
l
;
i
+=
2
)
{
var
code
=
parseInt
(
hex
.
substr
(
i
,
2
),
16
);
if
(
code
===
0
)
{
break
;
}
str
+=
String
.
fromCharCode
(
code
);
}
return
str
;
},
toAscii
:
utils
.
toAscii
,
/// @returns hex representation (prefixed by 0x) of ascii string
fromAscii
:
function
(
str
,
pad
)
{
pad
=
pad
===
undefined
?
0
:
pad
;
var
hex
=
this
.
toHex
(
str
);
while
(
hex
.
length
<
pad
*
2
)
hex
+=
"00"
;
return
"0x"
+
hex
;
},
fromAscii
:
utils
.
fromAscii
,
/// @returns decimal representaton of hex value prefixed by 0x
toDecimal
:
function
(
val
)
{
...
...
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