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
ea7c2fc6
Commit
ea7c2fc6
authored
Jan 28, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
abi function type
parent
63d9c070
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
209 additions
and
12 deletions
+209
-12
ethereum.js
dist/ethereum.js
+14
-4
ethereum.js.map
dist/ethereum.js.map
+3
-3
ethereum.min.js
dist/ethereum.min.js
+1
-1
abi.js
lib/abi.js
+12
-3
contract.js
lib/contract.js
+2
-1
abi.parsers.js
test/abi.parsers.js
+5
-0
eth.contract.js
test/eth.contract.js
+172
-0
eth.event.js
test/eth.event.js
+0
-0
No files found.
dist/ethereum.js
View file @
ea7c2fc6
...
...
@@ -66,6 +66,14 @@ var getMethodWithName = function (json, methodName) {
return
json
[
index
];
};
/// Filters all function from input abi
/// @returns abi array with filtered objects of type 'function'
var
filterFunctions
=
function
(
json
)
{
return
json
.
filter
(
function
(
current
)
{
return
current
.
type
===
'function'
;
});
};
/// @param string string to be padded
/// @param number of characters that result string should have
/// @param sign, by default 0
...
...
@@ -352,7 +360,7 @@ var methodTypeName = function (method) {
/// @returns input parser object for given json abi
var
inputParser
=
function
(
json
)
{
var
parser
=
{};
json
.
forEach
(
function
(
method
)
{
filterFunctions
(
json
)
.
forEach
(
function
(
method
)
{
var
displayName
=
methodDisplayName
(
method
.
name
);
var
typeName
=
methodTypeName
(
method
.
name
);
...
...
@@ -375,7 +383,7 @@ var inputParser = function (json) {
/// @returns output parser for given json abi
var
outputParser
=
function
(
json
)
{
var
parser
=
{};
json
.
forEach
(
function
(
method
)
{
filterFunctions
(
json
)
.
forEach
(
function
(
method
)
{
var
displayName
=
methodDisplayName
(
method
.
name
);
var
typeName
=
methodTypeName
(
method
.
name
);
...
...
@@ -406,7 +414,8 @@ module.exports = {
methodSignature
:
methodSignature
,
methodDisplayName
:
methodDisplayName
,
methodTypeName
:
methodTypeName
,
getMethodWithName
:
getMethodWithName
getMethodWithName
:
getMethodWithName
,
filterFunctions
:
filterFunctions
};
...
...
@@ -464,6 +473,7 @@ var contract = function (address, desc) {
// workaround for invalid assumption that method.name is the full anonymous prototype of the method.
// it's not. it's just the name. the rest of the code assumes it's actually the anonymous
// prototype, so we make it so as a workaround.
// TODO: we may not want to modify input params, maybe use copy instead?
if
(
method
.
name
.
indexOf
(
'('
)
===
-
1
)
{
var
displayName
=
method
.
name
;
var
typeName
=
method
.
inputs
.
map
(
function
(
i
){
return
i
.
type
;
}).
join
();
...
...
@@ -497,7 +507,7 @@ var contract = function (address, desc) {
});
desc
.
forEach
(
function
(
method
)
{
abi
.
filterFunctions
(
desc
)
.
forEach
(
function
(
method
)
{
var
displayName
=
abi
.
methodDisplayName
(
method
.
name
);
var
typeName
=
abi
.
methodTypeName
(
method
.
name
);
...
...
dist/ethereum.js.map
View file @
ea7c2fc6
This diff is collapsed.
Click to expand it.
dist/ethereum.min.js
View file @
ea7c2fc6
This diff is collapsed.
Click to expand it.
lib/abi.js
View file @
ea7c2fc6
...
...
@@ -65,6 +65,14 @@ var getMethodWithName = function (json, methodName) {
return
json
[
index
];
};
/// Filters all function from input abi
/// @returns abi array with filtered objects of type 'function'
var
filterFunctions
=
function
(
json
)
{
return
json
.
filter
(
function
(
current
)
{
return
current
.
type
===
'function'
;
});
};
/// @param string string to be padded
/// @param number of characters that result string should have
/// @param sign, by default 0
...
...
@@ -351,7 +359,7 @@ var methodTypeName = function (method) {
/// @returns input parser object for given json abi
var
inputParser
=
function
(
json
)
{
var
parser
=
{};
json
.
forEach
(
function
(
method
)
{
filterFunctions
(
json
)
.
forEach
(
function
(
method
)
{
var
displayName
=
methodDisplayName
(
method
.
name
);
var
typeName
=
methodTypeName
(
method
.
name
);
...
...
@@ -374,7 +382,7 @@ var inputParser = function (json) {
/// @returns output parser for given json abi
var
outputParser
=
function
(
json
)
{
var
parser
=
{};
json
.
forEach
(
function
(
method
)
{
filterFunctions
(
json
)
.
forEach
(
function
(
method
)
{
var
displayName
=
methodDisplayName
(
method
.
name
);
var
typeName
=
methodTypeName
(
method
.
name
);
...
...
@@ -405,6 +413,7 @@ module.exports = {
methodSignature
:
methodSignature
,
methodDisplayName
:
methodDisplayName
,
methodTypeName
:
methodTypeName
,
getMethodWithName
:
getMethodWithName
getMethodWithName
:
getMethodWithName
,
filterFunctions
:
filterFunctions
};
lib/contract.js
View file @
ea7c2fc6
...
...
@@ -51,6 +51,7 @@ var contract = function (address, desc) {
// workaround for invalid assumption that method.name is the full anonymous prototype of the method.
// it's not. it's just the name. the rest of the code assumes it's actually the anonymous
// prototype, so we make it so as a workaround.
// TODO: we may not want to modify input params, maybe use copy instead?
if
(
method
.
name
.
indexOf
(
'('
)
===
-
1
)
{
var
displayName
=
method
.
name
;
var
typeName
=
method
.
inputs
.
map
(
function
(
i
){
return
i
.
type
;
}).
join
();
...
...
@@ -84,7 +85,7 @@ var contract = function (address, desc) {
});
desc
.
forEach
(
function
(
method
)
{
abi
.
filterFunctions
(
desc
)
.
forEach
(
function
(
method
)
{
var
displayName
=
abi
.
methodDisplayName
(
method
.
name
);
var
typeName
=
abi
.
methodTypeName
(
method
.
name
);
...
...
test/abi.parsers.js
View file @
ea7c2fc6
...
...
@@ -5,6 +5,7 @@ var clone = function (object) { return JSON.parse(JSON.stringify(object)); };
var
description
=
[{
"name"
:
"test"
,
"type"
:
"function"
,
"inputs"
:
[{
"name"
:
"a"
,
"type"
:
"uint256"
...
...
@@ -339,10 +340,12 @@ describe('abi', function() {
// given
var
d
=
[{
name
:
"test"
,
type
:
"function"
,
inputs
:
[{
type
:
"int"
}],
outputs
:
[{
type
:
"int"
}]
},{
name
:
"test2"
,
type
:
"function"
,
inputs
:
[{
type
:
"string"
}],
outputs
:
[{
type
:
"string"
}]
}];
...
...
@@ -775,10 +778,12 @@ describe('abi', function() {
// given
var
d
=
[{
name
:
"test"
,
type
:
"function"
,
inputs
:
[{
type
:
"int"
}],
outputs
:
[{
type
:
"int"
}]
},{
name
:
"test2"
,
type
:
"function"
,
inputs
:
[{
type
:
"string"
}],
outputs
:
[{
type
:
"string"
}]
}];
...
...
test/eth.contract.js
0 → 100644
View file @
ea7c2fc6
var
assert
=
require
(
'assert'
);
var
contract
=
require
(
'../lib/contract.js'
);
describe
(
'contract'
,
function
()
{
it
(
'should create simple contract with one method from abi with explicit type name'
,
function
()
{
// given
var
description
=
[{
"name"
:
"test(uint256)"
,
"type"
:
"function"
,
"inputs"
:
[{
"name"
:
"a"
,
"type"
:
"uint256"
}
],
"outputs"
:
[
{
"name"
:
"d"
,
"type"
:
"uint256"
}
]
}];
// when
var
con
=
contract
(
null
,
description
);
// then
assert
.
equal
(
'function'
,
typeof
con
.
test
);
assert
.
equal
(
'function'
,
typeof
con
.
test
[
'uint256'
]);
});
it
(
'should create simple contract with one method from abi with implicit type name'
,
function
()
{
// given
var
description
=
[{
"name"
:
"test"
,
"type"
:
"function"
,
"inputs"
:
[{
"name"
:
"a"
,
"type"
:
"uint256"
}
],
"outputs"
:
[
{
"name"
:
"d"
,
"type"
:
"uint256"
}
]
}];
// when
var
con
=
contract
(
null
,
description
);
// then
assert
.
equal
(
'function'
,
typeof
con
.
test
);
assert
.
equal
(
'function'
,
typeof
con
.
test
[
'uint256'
]);
});
it
(
'should create contract with multiple methods'
,
function
()
{
// given
var
description
=
[{
"name"
:
"test"
,
"type"
:
"function"
,
"inputs"
:
[{
"name"
:
"a"
,
"type"
:
"uint256"
}
],
"outputs"
:
[
{
"name"
:
"d"
,
"type"
:
"uint256"
}
],
},
{
"name"
:
"test2"
,
"type"
:
"function"
,
"inputs"
:
[{
"name"
:
"a"
,
"type"
:
"uint256"
}
],
"outputs"
:
[
{
"name"
:
"d"
,
"type"
:
"uint256"
}
]
}];
// when
var
con
=
contract
(
null
,
description
);
// then
assert
.
equal
(
'function'
,
typeof
con
.
test
);
assert
.
equal
(
'function'
,
typeof
con
.
test
[
'uint256'
]);
assert
.
equal
(
'function'
,
typeof
con
.
test2
);
assert
.
equal
(
'function'
,
typeof
con
.
test2
[
'uint256'
]);
});
it
(
'should create contract with overloaded methods'
,
function
()
{
// given
var
description
=
[{
"name"
:
"test"
,
"type"
:
"function"
,
"inputs"
:
[{
"name"
:
"a"
,
"type"
:
"uint256"
}
],
"outputs"
:
[
{
"name"
:
"d"
,
"type"
:
"uint256"
}
],
},
{
"name"
:
"test"
,
"type"
:
"function"
,
"inputs"
:
[{
"name"
:
"a"
,
"type"
:
"string"
}
],
"outputs"
:
[
{
"name"
:
"d"
,
"type"
:
"uint256"
}
]
}];
// when
var
con
=
contract
(
null
,
description
);
// then
assert
.
equal
(
'function'
,
typeof
con
.
test
);
assert
.
equal
(
'function'
,
typeof
con
.
test
[
'uint256'
]);
assert
.
equal
(
'function'
,
typeof
con
.
test
[
'string'
]);
});
it
(
'should create contract with no methods'
,
function
()
{
// given
var
description
=
[{
"name"
:
"test(uint256)"
,
"type"
:
"event"
,
"inputs"
:
[{
"name"
:
"a"
,
"type"
:
"uint256"
}
],
"outputs"
:
[
{
"name"
:
"d"
,
"type"
:
"uint256"
}
]
}];
// when
var
con
=
contract
(
null
,
description
);
// then
assert
.
equal
(
'undefined'
,
typeof
con
.
test
);
});
});
test/eth.event.js
0 → 100644
View file @
ea7c2fc6
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