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
c9693b47
Commit
c9693b47
authored
Jan 21, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
contract.html example is working with sync api
parent
ceb4357a
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
60 additions
and
62 deletions
+60
-62
ethereum.js
dist/ethereum.js
+21
-20
ethereum.js.map
dist/ethereum.js.map
+4
-4
ethereum.min.js
dist/ethereum.min.js
+1
-1
balance.html
example/balance.html
+7
-9
contract.html
example/contract.html
+6
-8
abi.js
lib/abi.js
+5
-3
contract.js
lib/contract.js
+15
-16
httpsync.js
lib/httpsync.js
+1
-1
No files found.
dist/ethereum.js
View file @
c9693b47
...
...
@@ -33,6 +33,9 @@ BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN });
var
ETH_PADDING
=
32
;
/// method signature length in bytes
var
ETH_METHOD_SIGNATURE_LENGTH
=
4
;
/// Finds first index of array element matching pattern
/// @param array
/// @param callback pattern
...
...
@@ -390,11 +393,10 @@ var outputParser = function (json) {
return
parser
;
};
/// @param json abi for contract
/// @param method name for which we want to get method signature
/// @returns (promise) contract method signature for method with given name
var
methodSignature
=
function
(
json
,
name
)
{
return
web3
.
sha3
(
web3
.
fromAscii
(
name
));
var
methodSignature
=
function
(
name
)
{
return
web3
.
sha3
(
web3
.
fromAscii
(
name
))
.
slice
(
0
,
2
+
ETH_METHOD_SIGNATURE_LENGTH
*
2
)
;
};
module
.
exports
=
{
...
...
@@ -432,8 +434,7 @@ module.exports = {
var
web3
=
require
(
'./web3'
);
// jshint ignore:line
var
abi
=
require
(
'./abi'
);
/// method signature length in bytes
var
ETH_METHOD_SIGNATURE_LENGTH
=
4
;
/**
* This method should be called when we want to call / transact some solidity method from javascript
...
...
@@ -469,29 +470,29 @@ var contract = function (address, desc) {
var
impl
=
function
()
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
);
var
parsed
=
inputParser
[
displayName
][
typeName
].
apply
(
null
,
params
);
var
onSuccess
=
function
(
result
)
{
return
outputParser
[
displayName
][
typeName
](
result
);
};
var
signature
=
abi
.
methodSignature
(
method
.
name
);
return
{
call
:
function
(
extra
)
{
extra
=
extra
||
{};
extra
.
to
=
address
;
return
abi
.
methodSignature
(
desc
,
method
.
name
).
then
(
function
(
signature
)
{
extra
.
data
=
signature
.
slice
(
0
,
2
+
ETH_METHOD_SIGNATURE_LENGTH
*
2
)
+
parsed
;
return
web3
.
eth
.
call
(
extra
).
then
(
onSuccess
);
}
);
extra
.
data
=
signature
+
parsed
;
var
result
=
web3
.
eth
.
call
(
extra
);
return
outputParser
[
displayName
][
typeName
](
result
);
},
transact
:
function
(
extra
)
{
extra
=
extra
||
{};
extra
.
to
=
address
;
return
abi
.
methodSignature
(
desc
,
method
.
name
).
then
(
function
(
signature
)
{
extra
.
data
=
signature
.
slice
(
0
,
2
+
ETH_METHOD_SIGNATURE_LENGTH
*
2
)
+
parsed
;
web3
.
_currentContractAbi
=
desc
;
web3
.
_currentContractAddress
=
address
;
return
web3
.
eth
.
transact
(
extra
).
then
(
onSuccess
);
});
extra
.
data
=
signature
+
parsed
;
/// it's used by natspec.js
/// TODO: figure a better way to solve this
web3
.
_currentContractAbi
=
desc
;
web3
.
_currentContractAddress
=
address
;
var
result
=
web3
.
eth
.
transact
(
extra
);
return
outputParser
[
displayName
][
typeName
](
result
);
}
};
};
...
...
@@ -623,7 +624,7 @@ module.exports = Filter;
var
HttpSyncProvider
=
function
(
host
)
{
this
.
handlers
=
[];
this
.
host
=
host
;
this
.
host
=
host
||
'http://localhost:8080'
;
};
/// Transforms inner message to proper jsonrpc object
...
...
dist/ethereum.js.map
View file @
c9693b47
This diff is collapsed.
Click to expand it.
dist/ethereum.min.js
View file @
c9693b47
This diff is collapsed.
Click to expand it.
example/balance.html
View file @
c9693b47
...
...
@@ -14,17 +14,15 @@
var
coinbase
=
web3
.
eth
.
coinbase
;
var
originalBalance
=
0
;
web3
.
eth
.
balanceAt
(
coinbase
).
then
(
function
(
balance
)
{
originalBalance
=
web3
.
toDecimal
(
balance
);
document
.
getElementById
(
'original'
).
innerText
=
'original balance: '
+
originalBalance
+
' watching...'
;
});
var
balance
=
web3
.
eth
.
balanceAt
(
coinbase
);
var
originalBalance
=
web3
.
toDecimal
(
balance
);
document
.
getElementById
(
'original'
).
innerText
=
'original balance: '
+
originalBalance
+
' watching...'
;
web3
.
eth
.
watch
({
altered
:
coinbase
}).
changed
(
function
()
{
web3
.
eth
.
balanceAt
(
coinbase
).
then
(
function
(
balance
)
{
var
currentBalance
=
web3
.
toDecimal
(
balance
);
document
.
getElementById
(
"current"
).
innerText
=
'current: '
+
currentBalance
;
document
.
getElementById
(
"diff"
).
innerText
=
'diff: '
+
(
currentBalance
-
originalBalance
);
});
balance
=
web3
.
eth
.
balanceAt
(
coinbase
)
var
currentBalance
=
web3
.
toDecimal
(
balance
);
document
.
getElementById
(
"current"
).
innerText
=
'current: '
+
currentBalance
;
document
.
getElementById
(
"diff"
).
innerText
=
'diff: '
+
(
currentBalance
-
originalBalance
);
});
}
...
...
example/contract.html
View file @
c9693b47
...
...
@@ -8,7 +8,7 @@
<script
type=
"text/javascript"
>
var
web3
=
require
(
'web3'
);
web3
.
setProvider
(
new
web3
.
providers
.
Auto
Provider
());
web3
.
setProvider
(
new
web3
.
providers
.
HttpSync
Provider
());
// solidity source code
var
source
=
""
+
...
...
@@ -43,10 +43,9 @@
document
.
getElementById
(
'source'
).
innerText
=
source
;
// create contract
web3
.
eth
.
transact
({
code
:
web3
.
eth
.
solidity
(
source
)}).
then
(
function
(
address
)
{
contract
=
web3
.
eth
.
contract
(
address
,
desc
);
document
.
getElementById
(
'call'
).
style
.
visibility
=
'visible'
;
});
var
address
=
web3
.
eth
.
transact
({
code
:
web3
.
eth
.
solidity
(
source
)});
contract
=
web3
.
eth
.
contract
(
address
,
desc
);
document
.
getElementById
(
'call'
).
style
.
visibility
=
'visible'
;
}
function
callExampleContract
()
{
...
...
@@ -54,9 +53,8 @@
var
param
=
parseInt
(
document
.
getElementById
(
'value'
).
value
);
// call the contract
contract
.
multiply
(
param
).
call
().
then
(
function
(
res
)
{
document
.
getElementById
(
'result'
).
innerText
=
res
[
0
];
});
var
res
=
contract
.
multiply
(
param
).
call
();
document
.
getElementById
(
'result'
).
innerText
=
res
[
0
];
}
</script>
...
...
lib/abi.js
View file @
c9693b47
...
...
@@ -32,6 +32,9 @@ BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN });
var
ETH_PADDING
=
32
;
/// method signature length in bytes
var
ETH_METHOD_SIGNATURE_LENGTH
=
4
;
/// Finds first index of array element matching pattern
/// @param array
/// @param callback pattern
...
...
@@ -389,11 +392,10 @@ var outputParser = function (json) {
return
parser
;
};
/// @param json abi for contract
/// @param method name for which we want to get method signature
/// @returns (promise) contract method signature for method with given name
var
methodSignature
=
function
(
json
,
name
)
{
return
web3
.
sha3
(
web3
.
fromAscii
(
name
));
var
methodSignature
=
function
(
name
)
{
return
web3
.
sha3
(
web3
.
fromAscii
(
name
))
.
slice
(
0
,
2
+
ETH_METHOD_SIGNATURE_LENGTH
*
2
)
;
};
module
.
exports
=
{
...
...
lib/contract.js
View file @
c9693b47
...
...
@@ -23,8 +23,7 @@
var
web3
=
require
(
'./web3'
);
// jshint ignore:line
var
abi
=
require
(
'./abi'
);
/// method signature length in bytes
var
ETH_METHOD_SIGNATURE_LENGTH
=
4
;
/**
* This method should be called when we want to call / transact some solidity method from javascript
...
...
@@ -60,29 +59,29 @@ var contract = function (address, desc) {
var
impl
=
function
()
{
var
params
=
Array
.
prototype
.
slice
.
call
(
arguments
);
var
parsed
=
inputParser
[
displayName
][
typeName
].
apply
(
null
,
params
);
var
onSuccess
=
function
(
result
)
{
return
outputParser
[
displayName
][
typeName
](
result
);
};
var
signature
=
abi
.
methodSignature
(
method
.
name
);
return
{
call
:
function
(
extra
)
{
extra
=
extra
||
{};
extra
.
to
=
address
;
return
abi
.
methodSignature
(
desc
,
method
.
name
).
then
(
function
(
signature
)
{
extra
.
data
=
signature
.
slice
(
0
,
2
+
ETH_METHOD_SIGNATURE_LENGTH
*
2
)
+
parsed
;
return
web3
.
eth
.
call
(
extra
).
then
(
onSuccess
);
}
);
extra
.
data
=
signature
+
parsed
;
var
result
=
web3
.
eth
.
call
(
extra
);
return
outputParser
[
displayName
][
typeName
](
result
);
},
transact
:
function
(
extra
)
{
extra
=
extra
||
{};
extra
.
to
=
address
;
return
abi
.
methodSignature
(
desc
,
method
.
name
).
then
(
function
(
signature
)
{
extra
.
data
=
signature
.
slice
(
0
,
2
+
ETH_METHOD_SIGNATURE_LENGTH
*
2
)
+
parsed
;
web3
.
_currentContractAbi
=
desc
;
web3
.
_currentContractAddress
=
address
;
return
web3
.
eth
.
transact
(
extra
).
then
(
onSuccess
);
});
extra
.
data
=
signature
+
parsed
;
/// it's used by natspec.js
/// TODO: figure a better way to solve this
web3
.
_currentContractAbi
=
desc
;
web3
.
_currentContractAddress
=
address
;
var
result
=
web3
.
eth
.
transact
(
extra
);
return
outputParser
[
displayName
][
typeName
](
result
);
}
};
};
...
...
lib/httpsync.js
View file @
c9693b47
...
...
@@ -23,7 +23,7 @@
var
HttpSyncProvider
=
function
(
host
)
{
this
.
handlers
=
[];
this
.
host
=
host
;
this
.
host
=
host
||
'http://localhost:8080'
;
};
/// Transforms inner message to proper jsonrpc object
...
...
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