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
d99fea2d
Commit
d99fea2d
authored
Nov 13, 2014
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
abi output formatting
parent
7ce63d32
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
46 deletions
+115
-46
ethereum.js
dist/ethereum.js
+1
-1
ethereum.js.map
dist/ethereum.js.map
+1
-1
ethereum.min.js
dist/ethereum.min.js
+1
-1
index.html
example/index.html
+23
-30
abi.js
lib/abi.js
+89
-13
No files found.
dist/ethereum.js
View file @
d99fea2d
require
=
(
function
e
(
t
,
n
,
r
){
function
s
(
o
,
u
){
if
(
!
n
[
o
]){
if
(
!
t
[
o
]){
var
a
=
typeof
require
==
"function"
&&
require
;
if
(
!
u
&&
a
)
return
a
(
o
,
!
0
);
if
(
i
)
return
i
(
o
,
!
0
);
var
f
=
new
Error
(
"Cannot find module '"
+
o
+
"'"
);
throw
f
.
code
=
"MODULE_NOT_FOUND"
,
f
}
var
l
=
n
[
o
]
=
{
exports
:{}};
t
[
o
][
0
].
call
(
l
.
exports
,
function
(
e
){
var
n
=
t
[
o
][
1
][
e
];
return
s
(
n
?
n
:
e
)},
l
,
l
.
exports
,
e
,
t
,
n
,
r
)}
return
n
[
o
].
exports
}
var
i
=
typeof
require
==
"function"
&&
require
;
for
(
var
o
=
0
;
o
<
r
.
length
;
o
++
)
s
(
r
[
o
]);
return
s
})({
1
:[
function
(
require
,
module
,
exports
){
require
=
(
function
e
(
t
,
n
,
r
){
function
s
(
o
,
u
){
if
(
!
n
[
o
]){
if
(
!
t
[
o
]){
var
a
=
typeof
require
==
"function"
&&
require
;
if
(
!
u
&&
a
)
return
a
(
o
,
!
0
);
if
(
i
)
return
i
(
o
,
!
0
);
var
f
=
new
Error
(
"Cannot find module '"
+
o
+
"'"
);
throw
f
.
code
=
"MODULE_NOT_FOUND"
,
f
}
var
l
=
n
[
o
]
=
{
exports
:{}};
t
[
o
][
0
].
call
(
l
.
exports
,
function
(
e
){
var
n
=
t
[
o
][
1
][
e
];
return
s
(
n
?
n
:
e
)},
l
,
l
.
exports
,
e
,
t
,
n
,
r
)}
return
n
[
o
].
exports
}
var
i
=
typeof
require
==
"function"
&&
require
;
for
(
var
o
=
0
;
o
<
r
.
length
;
o
++
)
s
(
r
[
o
]);
return
s
})({
1
:[
function
(
require
,
module
,
exports
){
var
findIndex
=
function
(
array
,
callback
){
for
(
var
end
=!
1
,
i
=
0
;
i
<
array
.
length
&&!
end
;
i
++
)
end
=
callback
(
array
[
i
]);
return
end
?
i
-
1
:
-
1
},
padLeft
=
function
(
number
,
n
){
return
new
Array
(
2
*
n
-
number
.
toString
().
length
+
1
).
join
(
"0"
)
+
number
},
setupTypes
=
function
(){
var
prefixedType
=
function
(
prefix
){
return
function
(
type
,
value
){
var
padding
,
expected
=
prefix
;
return
0
!==
type
.
indexOf
(
expected
)?
!
1
:(
padding
=
parseInt
(
type
.
slice
(
expected
.
length
))
/
8
,
padLeft
(
value
,
padding
))}},
namedType
=
function
(
name
,
padding
){
return
function
(
type
,
value
){
return
type
!==
name
?
!
1
:
padLeft
(
value
,
padding
)}};
return
[
prefixedType
(
"uint"
),
prefixedType
(
"int"
),
namedType
(
"address"
,
20
),
namedType
(
"bool"
,
1
)]},
types
=
setupTypes
(),
toBytes
=
function
(
json
,
methodName
,
params
){
var
method
,
i
,
found
,
j
,
bytes
=
""
,
index
=
findIndex
(
json
,
function
(
method
){
return
method
.
name
===
methodName
});
if
(
-
1
!==
index
){
for
(
bytes
=
bytes
+
index
+
"x0"
,
method
=
json
[
index
],
i
=
0
;
i
<
method
.
inputs
.
length
;
i
++
){
for
(
found
=!
1
,
j
=
0
;
j
<
types
.
length
&&!
found
;
j
++
)
found
=
types
[
j
](
method
.
inputs
[
i
].
type
,
params
[
i
]);
found
||
console
.
error
(
"unsupported json type: "
+
method
.
inputs
[
i
].
type
),
bytes
+=
found
}
return
bytes
}};
module
.
exports
=
{
toBytes
:
toBytes
};
var
findIndex
=
function
(
array
,
callback
){
for
(
var
end
=!
1
,
i
=
0
;
i
<
array
.
length
&&!
end
;
i
++
)
end
=
callback
(
array
[
i
]);
return
end
?
i
-
1
:
-
1
},
findMethodIndex
=
function
(
json
,
methodName
){
return
findIndex
(
json
,
function
(
method
){
return
method
.
name
===
methodName
})},
padLeft
=
function
(
number
,
n
){
return
new
Array
(
2
*
n
-
number
.
toString
().
length
+
1
).
join
(
"0"
)
+
number
},
setupInputTypes
=
function
(){
var
prefixedType
=
function
(
prefix
){
return
function
(
type
,
value
){
var
padding
,
expected
=
prefix
;
return
0
!==
type
.
indexOf
(
expected
)?
!
1
:(
padding
=
parseInt
(
type
.
slice
(
expected
.
length
))
/
8
,
padLeft
(
value
,
padding
))}},
namedType
=
function
(
name
,
padding
,
formatter
){
return
function
(
type
,
value
){
return
type
!==
name
?
!
1
:
padLeft
(
formatter
?
value
:
formatter
(
value
),
padding
)}},
formatBool
=
function
(
value
){
return
value
?
"1"
:
"0"
};
return
[
prefixedType
(
"uint"
),
prefixedType
(
"int"
),
namedType
(
"address"
,
20
),
namedType
(
"bool"
,
1
,
formatBool
)]},
inputTypes
=
setupInputTypes
(),
toAbiInput
=
function
(
json
,
methodName
,
params
){
var
method
,
i
,
found
,
j
,
bytes
=
""
,
index
=
findMethodIndex
(
json
,
methodName
);
if
(
-
1
!==
index
){
for
(
bytes
=
bytes
+
index
+
"x0"
,
method
=
json
[
index
],
i
=
0
;
i
<
method
.
inputs
.
length
;
i
++
){
for
(
found
=!
1
,
j
=
0
;
j
<
inputTypes
.
length
&&!
found
;
j
++
)
found
=
inputTypes
[
j
](
method
.
inputs
[
i
].
type
,
params
[
i
]);
found
||
console
.
error
(
"unsupported json type: "
+
method
.
inputs
[
i
].
type
),
bytes
+=
found
}
return
bytes
}},
setupOutputTypes
=
function
(){
var
prefixedType
=
function
(
prefix
){
return
function
(
type
){
var
padding
,
expected
=
prefix
;
return
0
!==
type
.
indexOf
(
expected
)?
-
1
:(
padding
=
parseInt
(
type
.
slice
(
expected
.
length
))
/
8
,
2
*
padding
)}},
namedType
=
function
(
name
,
padding
){
return
function
(
type
){
return
name
===
type
?
2
*
padding
:
-
1
}},
formatInt
=
function
(
value
){
return
parseInt
(
value
,
16
)},
formatBool
=
function
(
value
){
return
"1"
===
value
?
!
0
:
!
1
};
return
[{
padding
:
prefixedType
(
"uint"
),
format
:
formatInt
},{
padding
:
prefixedType
(
"int"
),
format
:
formatInt
},{
padding
:
namedType
(
"address"
,
20
)},{
padding
:
namedType
(
"bool"
,
1
),
format
:
formatBool
}]},
outputTypes
=
setupOutputTypes
(),
fromAbiOutput
=
function
(
json
,
methodName
,
output
){
var
result
,
method
,
i
,
padding
,
j
,
res
,
formatter
,
index
=
findMethodIndex
(
json
,
methodName
);
if
(
-
1
!==
index
){
for
(
output
=
output
.
slice
(
2
),
result
=
[],
method
=
json
[
index
],
i
=
0
;
i
<
method
.
outputs
.
length
;
i
++
){
for
(
padding
=-
1
,
j
=
0
;
j
<
outputTypes
.
length
&&-
1
===
padding
;
j
++
)
padding
=
outputTypes
[
j
].
padding
(
method
.
outputs
[
i
].
type
);
-
1
!==
padding
&&
(
res
=
output
.
slice
(
0
,
padding
),
formatter
=
outputTypes
[
j
-
1
].
format
,
result
.
push
(
formatter
?
formatter
(
res
):
res
),
output
=
output
.
slice
(
padding
))}
return
result
}};
module
.
exports
=
{
toAbiInput
:
toAbiInput
,
fromAbiOutput
:
fromAbiOutput
};
},{}],
2
:[
function
(
require
,
module
,
exports
){
},{}],
2
:[
function
(
require
,
module
,
exports
){
var
AutoProvider
=
function
(
userOptions
){
var
options
,
self
,
closeWithSuccess
,
ws
;
if
(
!
web3
.
haveProvider
()){
if
(
this
.
sendQueue
=
[],
this
.
onmessageQueue
=
[],
navigator
.
qt
)
return
void
(
this
.
provider
=
new
web3
.
providers
.
QtProvider
);
userOptions
=
userOptions
||
{},
options
=
{
httprpc
:
userOptions
.
httprpc
||
"http://localhost:8080"
,
websockets
:
userOptions
.
websockets
||
"ws://localhost:40404/eth"
},
self
=
this
,
closeWithSuccess
=
function
(
success
){
ws
.
close
(),
success
?
self
.
provider
=
new
web3
.
providers
.
WebSocketProvider
(
options
.
websockets
):(
self
.
provider
=
new
web3
.
providers
.
HttpRpcProvider
(
options
.
httprpc
),
self
.
poll
=
self
.
provider
.
poll
.
bind
(
self
.
provider
)),
self
.
sendQueue
.
forEach
(
function
(
payload
){
self
.
provider
(
payload
)}),
self
.
onmessageQueue
.
forEach
(
function
(
handler
){
self
.
provider
.
onmessage
=
handler
})},
ws
=
new
WebSocket
(
options
.
websockets
),
ws
.
onopen
=
function
(){
closeWithSuccess
(
!
0
)},
ws
.
onerror
=
function
(){
closeWithSuccess
(
!
1
)}}};
AutoProvider
.
prototype
.
send
=
function
(
payload
){
return
this
.
provider
?
void
this
.
provider
.
send
(
payload
):
void
this
.
sendQueue
.
push
(
payload
)},
Object
.
defineProperty
(
AutoProvider
.
prototype
,
"onmessage"
,{
set
:
function
(
handler
){
return
this
.
provider
?
void
(
this
.
provider
.
onmessage
=
handler
):
void
this
.
onmessageQueue
.
push
(
handler
)}}),
module
.
exports
=
AutoProvider
;
var
AutoProvider
=
function
(
userOptions
){
var
options
,
self
,
closeWithSuccess
,
ws
;
if
(
!
web3
.
haveProvider
()){
if
(
this
.
sendQueue
=
[],
this
.
onmessageQueue
=
[],
navigator
.
qt
)
return
void
(
this
.
provider
=
new
web3
.
providers
.
QtProvider
);
userOptions
=
userOptions
||
{},
options
=
{
httprpc
:
userOptions
.
httprpc
||
"http://localhost:8080"
,
websockets
:
userOptions
.
websockets
||
"ws://localhost:40404/eth"
},
self
=
this
,
closeWithSuccess
=
function
(
success
){
ws
.
close
(),
success
?
self
.
provider
=
new
web3
.
providers
.
WebSocketProvider
(
options
.
websockets
):(
self
.
provider
=
new
web3
.
providers
.
HttpRpcProvider
(
options
.
httprpc
),
self
.
poll
=
self
.
provider
.
poll
.
bind
(
self
.
provider
)),
self
.
sendQueue
.
forEach
(
function
(
payload
){
self
.
provider
(
payload
)}),
self
.
onmessageQueue
.
forEach
(
function
(
handler
){
self
.
provider
.
onmessage
=
handler
})},
ws
=
new
WebSocket
(
options
.
websockets
),
ws
.
onopen
=
function
(){
closeWithSuccess
(
!
0
)},
ws
.
onerror
=
function
(){
closeWithSuccess
(
!
1
)}}};
AutoProvider
.
prototype
.
send
=
function
(
payload
){
return
this
.
provider
?
void
this
.
provider
.
send
(
payload
):
void
this
.
sendQueue
.
push
(
payload
)},
Object
.
defineProperty
(
AutoProvider
.
prototype
,
"onmessage"
,{
set
:
function
(
handler
){
return
this
.
provider
?
void
(
this
.
provider
.
onmessage
=
handler
):
void
this
.
onmessageQueue
.
push
(
handler
)}}),
module
.
exports
=
AutoProvider
;
},{}],
3
:[
function
(
require
,
module
,
exports
){
},{}],
3
:[
function
(
require
,
module
,
exports
){
...
...
dist/ethereum.js.map
View file @
d99fea2d
This diff is collapsed.
Click to expand it.
dist/ethereum.min.js
View file @
d99fea2d
This diff is collapsed.
Click to expand it.
example/index.html
View file @
d99fea2d
...
@@ -6,39 +6,32 @@
...
@@ -6,39 +6,32 @@
<script
type=
"text/javascript"
src=
"../dist/ethereum.js"
></script>
<script
type=
"text/javascript"
src=
"../dist/ethereum.js"
></script>
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
if
(
window
.
Promise
===
undefined
)
{
if
(
window
.
Promise
===
undefined
)
{
window
.
Promise
=
ES6Promise
.
Promise
;
window
.
Promise
=
ES6Promise
.
Promise
;
}
}
var
web3
=
require
(
'web3'
);
var
web3
=
require
(
'web3'
);
web3
.
setProvider
(
new
web3
.
providers
.
AutoProvider
());
//web3.setProvider(new web3.providers.QtProvider());
//web3.setProvider(new web3.providers.HttpRpcProvider("http://localhost:8080"));
function
testSnippet
()
{
// web3.setProvider(new web3.providers.WebSocketProvider("ws://localhost:40404/eth"));
web3
.
eth
.
watch
({
altered
:
web3
.
eth
.
coinbase
}).
changed
(
function
()
{
web3
.
setProvider
(
new
web3
.
providers
.
AutoProvider
());
web3
.
eth
.
balanceAt
(
web3
.
eth
.
coinbase
).
then
(
function
(
balance
)
{
console
.
log
(
parseInt
(
balance
,
16
));
function
testSnippet
()
{
console
.
log
(
typeof
balance
);
web3
.
eth
.
watch
({
altered
:
web3
.
eth
.
coinbase
}).
changed
(
function
()
{
document
.
getElementById
(
"result"
).
innerText
=
+
balance
;
web3
.
eth
.
balanceAt
(
web3
.
eth
.
coinbase
).
then
(
function
(
balance
)
{
});
console
.
log
(
parseInt
(
balance
,
16
));
console
.
log
(
typeof
balance
);
document
.
getElementById
(
"result"
).
innerText
=
+
balance
;
});
});
});
}
}
</script>
</script>
</head>
</head>
<body>
<body>
<h1>
std::name_reg
</h1>
<h1>
std::name_reg
</h1>
<input
type=
"text"
id=
"name"
></input>
<input
type=
"text"
id=
"name"
></input>
<button
type=
"button"
onClick=
"testSnippet();"
>
test snippet
</button>
<button
type=
"button"
onClick=
"testSnippet();"
>
test snippet
</button>
<div></div>
result:
<div></div>
<div
id=
"result"
></div>
result:
<div
id=
"result"
></div>
</body>
</body>
</html>
</html>
lib/abi.js
View file @
d99fea2d
...
@@ -8,11 +8,17 @@ var findIndex = function (array, callback) {
...
@@ -8,11 +8,17 @@ var findIndex = function (array, callback) {
return
end
?
i
-
1
:
-
1
;
return
end
?
i
-
1
:
-
1
;
};
};
var
findMethodIndex
=
function
(
json
,
methodName
)
{
return
findIndex
(
json
,
function
(
method
)
{
return
method
.
name
===
methodName
;
});
};
var
padLeft
=
function
(
number
,
n
)
{
var
padLeft
=
function
(
number
,
n
)
{
return
(
new
Array
(
n
*
2
-
number
.
toString
().
length
+
1
)).
join
(
"0"
)
+
number
;
return
(
new
Array
(
n
*
2
-
number
.
toString
().
length
+
1
)).
join
(
"0"
)
+
number
;
};
};
var
setupTypes
=
function
()
{
var
setup
Input
Types
=
function
()
{
var
prefixedType
=
function
(
prefix
)
{
var
prefixedType
=
function
(
prefix
)
{
return
function
(
type
,
value
)
{
return
function
(
type
,
value
)
{
var
expected
=
prefix
;
var
expected
=
prefix
;
...
@@ -25,32 +31,34 @@ var setupTypes = function () {
...
@@ -25,32 +31,34 @@ var setupTypes = function () {
};
};
};
};
var
namedType
=
function
(
name
,
padding
)
{
var
namedType
=
function
(
name
,
padding
,
formatter
)
{
return
function
(
type
,
value
)
{
return
function
(
type
,
value
)
{
if
(
type
!==
name
)
{
if
(
type
!==
name
)
{
return
false
;
return
false
;
}
}
return
padLeft
(
value
,
padding
);
return
padLeft
(
formatter
?
value
:
formatter
(
value
)
,
padding
);
};
};
};
};
var
formatBool
=
function
(
value
)
{
return
value
?
'1'
:
'0'
;
};
return
[
return
[
prefixedType
(
'uint'
),
prefixedType
(
'uint'
),
prefixedType
(
'int'
),
prefixedType
(
'int'
),
namedType
(
'address'
,
20
),
namedType
(
'address'
,
20
),
namedType
(
'bool'
,
1
),
namedType
(
'bool'
,
1
,
formatBool
),
];
];
};
};
var
types
=
setup
Types
();
var
inputTypes
=
setupInput
Types
();
var
to
Bytes
=
function
(
json
,
methodName
,
params
)
{
var
to
AbiInput
=
function
(
json
,
methodName
,
params
)
{
var
bytes
=
""
;
var
bytes
=
""
;
var
index
=
findIndex
(
json
,
function
(
method
)
{
var
index
=
findMethodIndex
(
json
,
methodName
);
return
method
.
name
===
methodName
;
});
if
(
index
===
-
1
)
{
if
(
index
===
-
1
)
{
return
;
return
;
}
}
...
@@ -62,8 +70,8 @@ var toBytes = function (json, methodName, params) {
...
@@ -62,8 +70,8 @@ var toBytes = function (json, methodName, params) {
for
(
var
i
=
0
;
i
<
method
.
inputs
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
method
.
inputs
.
length
;
i
++
)
{
var
found
=
false
;
var
found
=
false
;
for
(
var
j
=
0
;
j
<
t
ypes
.
length
&&
!
found
;
j
++
)
{
for
(
var
j
=
0
;
j
<
inputT
ypes
.
length
&&
!
found
;
j
++
)
{
found
=
t
ypes
[
j
](
method
.
inputs
[
i
].
type
,
params
[
i
]);
found
=
inputT
ypes
[
j
](
method
.
inputs
[
i
].
type
,
params
[
i
]);
}
}
if
(
!
found
)
{
if
(
!
found
)
{
console
.
error
(
'unsupported json type: '
+
method
.
inputs
[
i
].
type
);
console
.
error
(
'unsupported json type: '
+
method
.
inputs
[
i
].
type
);
...
@@ -73,7 +81,75 @@ var toBytes = function (json, methodName, params) {
...
@@ -73,7 +81,75 @@ var toBytes = function (json, methodName, params) {
return
bytes
;
return
bytes
;
};
};
var
setupOutputTypes
=
function
()
{
var
prefixedType
=
function
(
prefix
)
{
return
function
(
type
)
{
var
expected
=
prefix
;
if
(
type
.
indexOf
(
expected
)
!==
0
)
{
return
-
1
;
}
var
padding
=
parseInt
(
type
.
slice
(
expected
.
length
))
/
8
;
return
padding
*
2
;
};
};
var
namedType
=
function
(
name
,
padding
)
{
return
function
(
type
)
{
return
name
===
type
?
padding
*
2
:
-
1
;
};
};
var
formatInt
=
function
(
value
)
{
return
parseInt
(
value
,
16
);
};
var
formatBool
=
function
(
value
)
{
return
value
===
'1'
?
true
:
false
;
};
return
[
{
padding
:
prefixedType
(
'uint'
),
format
:
formatInt
},
{
padding
:
prefixedType
(
'int'
),
format
:
formatInt
},
{
padding
:
namedType
(
'address'
,
20
)
},
{
padding
:
namedType
(
'bool'
,
1
),
format
:
formatBool
}
];
};
var
outputTypes
=
setupOutputTypes
();
var
fromAbiOutput
=
function
(
json
,
methodName
,
output
)
{
var
index
=
findMethodIndex
(
json
,
methodName
);
if
(
index
===
-
1
)
{
return
;
}
output
=
output
.
slice
(
2
);
var
result
=
[];
var
method
=
json
[
index
];
for
(
var
i
=
0
;
i
<
method
.
outputs
.
length
;
i
++
)
{
var
padding
=
-
1
;
for
(
var
j
=
0
;
j
<
outputTypes
.
length
&&
padding
===
-
1
;
j
++
)
{
padding
=
outputTypes
[
j
].
padding
(
method
.
outputs
[
i
].
type
);
}
if
(
padding
===
-
1
)
{
// not found output parsing
continue
;
}
var
res
=
output
.
slice
(
0
,
padding
);
var
formatter
=
outputTypes
[
j
-
1
].
format
;
result
.
push
(
formatter
?
formatter
(
res
):
res
);
output
=
output
.
slice
(
padding
);
}
return
result
;
};
module
.
exports
=
{
module
.
exports
=
{
toBytes
:
toBytes
toAbiInput
:
toAbiInput
,
fromAbiOutput
:
fromAbiOutput
};
};
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