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
c8ee08c2
Commit
c8ee08c2
authored
Jan 29, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
contract.js simplified
parent
842b8cf3
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
231 additions
and
188 deletions
+231
-188
ethereum.js
dist/ethereum.js
+124
-93
ethereum.js.map
dist/ethereum.js.map
+4
-2
ethereum.min.js
dist/ethereum.min.js
+1
-1
contract.js
lib/contract.js
+99
-86
event.js
lib/event.js
+1
-1
event.js
test/event.js
+2
-5
No files found.
dist/ethereum.js
View file @
c8ee08c2
This diff is collapsed.
Click to expand it.
dist/ethereum.js.map
View file @
c8ee08c2
This diff is collapsed.
Click to expand it.
dist/ethereum.min.js
View file @
c8ee08c2
This diff is collapsed.
Click to expand it.
lib/contract.js
View file @
c8ee08c2
...
...
@@ -22,78 +22,35 @@
var
web3
=
require
(
'./web3'
);
var
abi
=
require
(
'./abi'
);
var
eventImplementation
=
require
(
'./event'
);
/**
* This method should be called when we want to call / transact some solidity method from javascript
* it returns an object which has same methods available as solidity contract description
* usage example:
*
* var abi = [{
* name: 'myMethod',
* inputs: [{ name: 'a', type: 'string' }],
* outputs: [{name: 'd', type: 'string' }]
* }]; // contract abi
*
* var myContract = web3.eth.contract('0x0123123121', abi); // creation of contract object
*
* myContract.myMethod('this is test string param for call'); // myMethod call (implicit, default)
* myContract.call().myMethod('this is test string param for call'); // myMethod call (explicit)
* myContract.transact().myMethod('this is test string param for transact'); // myMethod transact
*
* @param address - address of the contract, which should be called
* @param desc - abi json description of the contract, which is being created
* @returns contract object
*/
var
contract
=
function
(
address
,
desc
)
{
desc
.
forEach
(
function
(
method
)
{
// 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
();
method
.
name
=
displayName
+
'('
+
typeName
+
')'
;
}
});
var
inputParser
=
abi
.
inputParser
(
desc
);
var
outputParser
=
abi
.
outputParser
(
desc
);
var
result
=
{
address
:
address
,
};
Object
.
defineProperty
(
result
,
'topics'
,
{
get
:
function
()
{
return
abi
.
filterEvents
(
desc
).
map
(
function
(
event
)
{
return
abi
.
methodSignature
(
event
.
name
);
});
}
});
result
.
call
=
function
(
options
)
{
result
.
_isTransact
=
false
;
result
.
_options
=
options
;
return
result
;
var
addFunctionRelatedPropertiesToContract
=
function
(
contract
)
{
contract
.
call
=
function
(
options
)
{
contract
.
_isTransact
=
false
;
contract
.
_options
=
options
;
return
contract
;
};
resul
t
.
transact
=
function
(
options
)
{
resul
t
.
_isTransact
=
true
;
resul
t
.
_options
=
options
;
return
resul
t
;
contrac
t
.
transact
=
function
(
options
)
{
contrac
t
.
_isTransact
=
true
;
contrac
t
.
_options
=
options
;
return
contrac
t
;
};
resul
t
.
_options
=
{};
contrac
t
.
_options
=
{};
[
'gas'
,
'gasPrice'
,
'value'
,
'from'
].
forEach
(
function
(
p
)
{
resul
t
[
p
]
=
function
(
v
)
{
resul
t
.
_options
[
p
]
=
v
;
return
resul
t
;
contrac
t
[
p
]
=
function
(
v
)
{
contrac
t
.
_options
[
p
]
=
v
;
return
contrac
t
;
};
});
};
var
addFunctionsToContract
=
function
(
contract
,
desc
,
address
)
{
var
inputParser
=
abi
.
inputParser
(
desc
);
var
outputParser
=
abi
.
outputParser
(
desc
);
// create contract functions
abi
.
filterFunctions
(
desc
).
forEach
(
function
(
method
)
{
...
...
@@ -106,16 +63,16 @@ var contract = function (address, desc) {
var
signature
=
abi
.
methodSignature
(
method
.
name
);
var
parsed
=
inputParser
[
displayName
][
typeName
].
apply
(
null
,
params
);
var
options
=
resul
t
.
_options
||
{};
var
options
=
contrac
t
.
_options
||
{};
options
.
to
=
address
;
options
.
data
=
signature
+
parsed
;
var
isTransact
=
result
.
_isTransact
===
true
||
(
resul
t
.
_isTransact
!==
false
&&
!
method
.
constant
);
var
isTransact
=
contract
.
_isTransact
===
true
||
(
contrac
t
.
_isTransact
!==
false
&&
!
method
.
constant
);
var
collapse
=
options
.
collapse
!==
false
;
// reset
resul
t
.
_options
=
{};
resul
t
.
_isTransact
=
null
;
contrac
t
.
_options
=
{};
contrac
t
.
_isTransact
=
null
;
if
(
isTransact
)
{
// it's used byt natspec.js
...
...
@@ -142,40 +99,96 @@ var contract = function (address, desc) {
return
ret
;
};
if
(
resul
t
[
displayName
]
===
undefined
)
{
resul
t
[
displayName
]
=
impl
;
if
(
contrac
t
[
displayName
]
===
undefined
)
{
contrac
t
[
displayName
]
=
impl
;
}
result
[
displayName
][
typeName
]
=
impl
;
contract
[
displayName
][
typeName
]
=
impl
;
});
};
// create contract events
abi
.
filterEvents
(
desc
).
forEach
(
function
(
event
)
{
var
addEventRelatedPropertiesToContract
=
function
(
contract
,
desc
,
address
)
{
contract
.
address
=
address
;
// TODO: rename these methods, cause they are used not only for methods
var
displayName
=
abi
.
methodDisplayName
(
event
.
name
);
var
typeName
=
abi
.
methodTypeName
(
event
.
name
);
Object
.
defineProperty
(
contract
,
'topics'
,
{
get
:
function
()
{
return
abi
.
filterEvents
(
desc
).
map
(
function
(
e
)
{
return
abi
.
methodSignature
(
e
.
name
);
});
}
});
};
var
impl
=
function
(
options
)
{
var
signature
=
abi
.
methodSignature
(
event
.
name
);
var
o
=
options
||
{};
o
.
address
=
o
.
address
||
address
;
o
.
topics
=
o
.
topics
||
[];
o
.
topics
.
push
(
signature
);
var
addEventsToContract
=
function
(
contract
,
desc
,
address
)
{
// create contract events
abi
.
filterEvents
(
desc
).
forEach
(
function
(
e
)
{
var
impl
=
function
()
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
);
var
signature
=
abi
.
methodSignature
(
e
.
name
);
var
eventImpl
=
eventImplementation
(
address
,
signature
);
var
o
=
eventImpl
.
apply
(
null
,
params
);
return
web3
.
eth
.
watch
(
o
);
};
// TODO: rename these methods, cause they are used not only for methods
var
displayName
=
abi
.
methodDisplayName
(
e
.
name
);
var
typeName
=
abi
.
methodTypeName
(
e
.
name
);
if
(
resul
t
[
displayName
]
===
undefined
)
{
resul
t
[
displayName
]
=
impl
;
if
(
contrac
t
[
displayName
]
===
undefined
)
{
contrac
t
[
displayName
]
=
impl
;
}
resul
t
[
displayName
][
typeName
]
=
impl
;
contrac
t
[
displayName
][
typeName
]
=
impl
;
});
};
/**
* This method should be called when we want to call / transact some solidity method from javascript
* it returns an object which has same methods available as solidity contract description
* usage example:
*
* var abi = [{
* name: 'myMethod',
* inputs: [{ name: 'a', type: 'string' }],
* outputs: [{name: 'd', type: 'string' }]
* }]; // contract abi
*
* var myContract = web3.eth.contract('0x0123123121', abi); // creation of contract object
*
* myContract.myMethod('this is test string param for call'); // myMethod call (implicit, default)
* myContract.call().myMethod('this is test string param for call'); // myMethod call (explicit)
* myContract.transact().myMethod('this is test string param for transact'); // myMethod transact
*
* @param address - address of the contract, which should be called
* @param desc - abi json description of the contract, which is being created
* @returns contract object
*/
var
contract
=
function
(
address
,
desc
)
{
desc
.
forEach
(
function
(
method
)
{
// 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
();
method
.
name
=
displayName
+
'('
+
typeName
+
')'
;
}
});
var
result
=
{};
addFunctionRelatedPropertiesToContract
(
result
);
addFunctionsToContract
(
result
,
desc
,
address
);
addEventRelatedPropertiesToContract
(
result
,
desc
,
address
);
addEventsToContract
(
result
,
desc
,
address
);
return
result
;
};
...
...
lib/event.js
View file @
c8ee08c2
var
abi
=
require
(
'./abi'
);
var
implementationOfEvent
=
function
(
event
,
address
,
signature
)
{
var
implementationOfEvent
=
function
(
address
,
signature
)
{
return
function
(
options
)
{
var
o
=
options
||
{};
...
...
test/event.js
View file @
c8ee08c2
...
...
@@ -7,13 +7,9 @@ describe('event', function () {
// given
var
address
=
'0x012345'
;
var
signature
=
'0x987654'
;
var
e
=
{
name
:
'test'
,
type
:
'event'
,
};
// when
var
impl
=
event
(
e
,
address
,
signature
);
var
impl
=
event
(
address
,
signature
);
var
result
=
impl
();
// then
...
...
@@ -23,3 +19,4 @@ describe('event', function () {
});
});
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