Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
083df317
Commit
083df317
authored
Oct 09, 2015
by
chriseth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #38 from chriseth/libraries
Libraries
parents
31ca4c4d
1594aebb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
44 deletions
+131
-44
index.html
index.html
+26
-16
universal-dapp.js
libs/universal-dapp.js
+100
-20
browser-solidity.css
stylesheets/browser-solidity.css
+4
-8
universal-dapp.css
stylesheets/universal-dapp.css
+1
-0
No files found.
index.html
View file @
083df317
...
@@ -500,34 +500,44 @@ THE SOFTWARE.
...
@@ -500,34 +500,44 @@ THE SOFTWARE.
};
};
var
renderContracts
=
function
(
data
,
source
)
{
var
renderContracts
=
function
(
data
,
source
)
{
var
udappContracts
=
[];
for
(
var
contractName
in
data
.
contracts
)
{
for
(
var
contractName
in
data
.
contracts
)
{
var
contract
=
data
.
contracts
[
contractName
];
var
contract
=
data
.
contracts
[
contractName
];
var
dapp
=
new
UniversalDApp
([
{
udappContracts
.
push
(
{
name
:
contractName
,
name
:
contractName
,
interface
:
contract
[
'interface'
],
interface
:
contract
[
'interface'
],
bytecode
:
contract
.
bytecode
bytecode
:
contract
.
bytecode
}],
{
vm
:
executionContext
===
'vm'
,
removable
:
false
,
removable_instances
:
true
});
});
var
$contractOutput
=
dapp
.
render
();
}
$contractOutput
var
dapp
=
new
UniversalDApp
(
udappContracts
,
{
vm
:
executionContext
===
'vm'
,
removable
:
false
,
removable_instances
:
true
,
renderOutputModifier
:
function
(
contractName
,
$contractOutput
)
{
var
contract
=
data
.
contracts
[
contractName
];
return
$contractOutput
.
append
(
textRow
(
'Bytecode'
,
contract
.
bytecode
))
.
append
(
textRow
(
'Bytecode'
,
contract
.
bytecode
))
.
append
(
textRow
(
'Interface'
,
contract
[
'interface'
]))
.
append
(
textRow
(
'Interface'
,
contract
[
'interface'
]))
.
append
(
textRow
(
'Web3 deploy'
,
gethDeploy
(
contractName
.
toLowerCase
(),
contract
[
'interface'
],
contract
.
bytecode
),
'deploy'
))
.
append
(
textRow
(
'Web3 deploy'
,
gethDeploy
(
contractName
.
toLowerCase
(),
contract
[
'interface'
],
contract
.
bytecode
),
'deploy'
))
.
append
(
textRow
(
'uDApp'
,
combined
(
contractName
,
contract
[
'interface'
],
contract
.
bytecode
),
'deploy'
))
.
append
(
textRow
(
'uDApp'
,
combined
(
contractName
,
contract
[
'interface'
],
contract
.
bytecode
),
'deploy'
))
.
append
(
getDetails
(
contract
,
source
,
contractName
));
.
append
(
getDetails
(
contract
,
source
,
contractName
));
}});
if
(
executionContext
===
'vm'
)
$
(
'#txorigin'
).
text
(
'0x'
+
dapp
.
address
.
toString
(
'hex'
));
var
$contractOutput
=
dapp
.
render
();
else
web3
.
eth
.
getAccounts
(
function
(
err
,
accounts
)
{
if
(
err
)
renderError
(
err
.
message
);
if
(
executionContext
===
'vm'
)
$
(
'#txorigin'
).
text
(
accounts
[
0
]);
$
(
'#txorigin'
).
text
(
'0x'
+
dapp
.
address
.
toString
(
'hex'
));
else
web3
.
eth
.
getAccounts
(
function
(
err
,
accounts
)
{
if
(
err
)
renderError
(
err
.
message
);
if
(
accounts
&&
accounts
[
0
])
$
(
'#txorigin'
).
text
(
accounts
[
0
]);
else
$
(
'#txorigin'
).
text
(
'unknown'
);
});
});
$contractOutput
.
find
(
'.title'
).
click
(
function
(
ev
){
$
(
this
).
closest
(
'.udapp'
).
toggleClass
(
'hide'
)
});
$contractOutput
.
find
(
'.title'
).
click
(
function
(
ev
){
$
(
this
).
closest
(
'.contract'
).
toggleClass
(
'hide'
);
});
$
(
'#output'
).
append
(
$contractOutput
);
$
(
'#output'
).
append
(
$contractOutput
);
}
$
(
'.col2 input,textarea'
).
click
(
function
()
{
this
.
select
();
});
$
(
'.col2 input,textarea'
).
click
(
function
()
{
this
.
select
();
});
};
};
var
tableRowItems
=
function
(
first
,
second
,
cls
)
{
var
tableRowItems
=
function
(
first
,
second
,
cls
)
{
...
...
libs/universal-dapp.js
View file @
083df317
...
@@ -2,6 +2,7 @@ function UniversalDApp (contracts, options) {
...
@@ -2,6 +2,7 @@ function UniversalDApp (contracts, options) {
this
.
options
=
options
||
{};
this
.
options
=
options
||
{};
this
.
$el
=
$
(
'<div class="udapp" />'
);
this
.
$el
=
$
(
'<div class="udapp" />'
);
this
.
contracts
=
contracts
;
this
.
contracts
=
contracts
;
this
.
renderOutputModifier
=
options
.
renderOutputModifier
||
function
(
name
,
content
)
{
return
content
;
};
if
(
!
options
.
vm
&&
web3
.
currentProvider
)
{
if
(
!
options
.
vm
&&
web3
.
currentProvider
)
{
...
@@ -44,7 +45,7 @@ UniversalDApp.prototype.render = function () {
...
@@ -44,7 +45,7 @@ UniversalDApp.prototype.render = function () {
}
}
$contractEl
.
append
(
$title
).
append
(
this
.
getCreateInterface
(
$contractEl
,
this
.
contracts
[
c
])
);
$contractEl
.
append
(
$title
).
append
(
this
.
getCreateInterface
(
$contractEl
,
this
.
contracts
[
c
])
);
}
}
this
.
$el
.
append
(
$contractEl
);
this
.
$el
.
append
(
this
.
renderOutputModifier
(
this
.
contracts
[
c
].
name
,
$contractEl
)
);
}
}
}
}
$legend
=
$
(
'<div class="legend" />'
)
$legend
=
$
(
'<div class="legend" />'
)
...
@@ -59,10 +60,17 @@ UniversalDApp.prototype.render = function () {
...
@@ -59,10 +60,17 @@ UniversalDApp.prototype.render = function () {
return
this
.
$el
;
return
this
.
$el
;
}
}
UniversalDApp
.
prototype
.
getContractByName
=
function
(
contractName
)
{
for
(
var
c
in
this
.
contracts
)
if
(
this
.
contracts
[
c
].
name
==
contractName
)
return
this
.
contracts
[
c
];
return
null
;
};
UniversalDApp
.
prototype
.
getABIInputForm
=
function
(
cb
){
UniversalDApp
.
prototype
.
getABIInputForm
=
function
(
cb
){
var
self
=
this
;
var
self
=
this
;
var
$el
=
$
(
'<div class="udapp-setup" />'
);
var
$el
=
$
(
'<div class="udapp-setup" />'
);
var
$jsonInput
=
$
(
'<textarea class="json" placeholder=
\'
[ { "name": name, "bytecode": byt
y
ecode, "interface": abi }, { ... } ]
\'
/>'
)
var
$jsonInput
=
$
(
'<textarea class="json" placeholder=
\'
[ { "name": name, "bytecode": bytecode, "interface": abi }, { ... } ]
\'
/>'
)
var
$createButton
=
$
(
'<button class="udapp-create"/>'
).
text
(
'Create a Universal ÐApp'
)
var
$createButton
=
$
(
'<button class="udapp-create"/>'
).
text
(
'Create a Universal ÐApp'
)
$createButton
.
click
(
function
(
ev
){
$createButton
.
click
(
function
(
ev
){
var
contracts
=
$
.
parseJSON
(
$jsonInput
.
val
()
);
var
contracts
=
$
.
parseJSON
(
$jsonInput
.
val
()
);
...
@@ -157,6 +165,7 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar
...
@@ -157,6 +165,7 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar
if
(
!
address
||
!
$target
)
{
if
(
!
address
||
!
$target
)
{
$createInterface
.
append
(
this
.
getCallButton
({
$createInterface
.
append
(
this
.
getCallButton
({
abi
:
funABI
,
abi
:
funABI
,
contractName
:
contract
.
name
,
bytecode
:
contract
.
bytecode
,
bytecode
:
contract
.
bytecode
,
appendFunctions
:
appendFunctions
appendFunctions
:
appendFunctions
}));
}));
...
@@ -179,7 +188,7 @@ UniversalDApp.prototype.getConstructorInterface = function(abi) {
...
@@ -179,7 +188,7 @@ UniversalDApp.prototype.getConstructorInterface = function(abi) {
UniversalDApp
.
prototype
.
getCallButton
=
function
(
args
)
{
UniversalDApp
.
prototype
.
getCallButton
=
function
(
args
)
{
var
self
=
this
;
var
self
=
this
;
// args.abi, args.
bytecode [constr only]
, args.address [fun only]
// args.abi, args.
contractName [constr only], args.bytecode
, args.address [fun only]
// args.appendFunctions [constr only]
// args.appendFunctions [constr only]
var
isConstructor
=
args
.
bytecode
!==
undefined
;
var
isConstructor
=
args
.
bytecode
!==
undefined
;
var
lookupOnly
=
(
args
.
abi
.
constant
&&
!
isConstructor
);
var
lookupOnly
=
(
args
.
abi
.
constant
&&
!
isConstructor
);
...
@@ -212,40 +221,65 @@ UniversalDApp.prototype.getCallButton = function(args) {
...
@@ -212,40 +221,65 @@ UniversalDApp.prototype.getCallButton = function(args) {
}
}
var
getOutput
=
function
()
{
var
getOutput
=
function
()
{
var
values
=
Array
.
prototype
.
slice
.
call
(
arguments
);
var
$result
=
$
(
'<div class="result" />'
);
var
$result
=
$
(
'<div class="result" />'
);
var
$close
=
$
(
'<div class="udapp-close" />'
);
var
$close
=
$
(
'<div class="udapp-close" />'
);
$close
.
click
(
function
(){
$result
.
remove
();
}
);
$close
.
click
(
function
(){
$result
.
remove
();
}
);
$result
.
append
(
$close
);
$result
.
append
(
$close
);
for
(
var
v
in
values
)
{
$result
.
append
(
values
[
v
]
);
}
return
$result
;
return
$result
;
}
};
var
clearOutput
=
function
(
$result
)
{
var
handleCallButtonClick
=
function
(
ev
)
{
$
(
':not(.udapp-close)'
,
$result
).
remove
();
};
var
replaceOutput
=
function
(
$result
,
message
)
{
clearOutput
(
$result
);
$result
.
append
(
message
);
};
var
handleCallButtonClick
=
function
(
ev
,
$result
)
{
var
funArgs
=
$
.
parseJSON
(
'['
+
inputField
.
val
()
+
']'
);
var
funArgs
=
$
.
parseJSON
(
'['
+
inputField
.
val
()
+
']'
);
var
data
=
fun
.
toPayload
(
funArgs
).
data
;
var
data
=
fun
.
toPayload
(
funArgs
).
data
;
if
(
data
.
slice
(
0
,
2
)
==
'0x'
)
data
=
data
.
slice
(
2
);
if
(
data
.
slice
(
0
,
2
)
==
'0x'
)
data
=
data
.
slice
(
2
);
if
(
isConstructor
)
data
=
args
.
bytecode
+
data
.
slice
(
8
);
var
$result
=
getOutput
(
$
(
'<a class="waiting" href="#" title="Waiting for transaction to be mined.">Polling for tx receipt...</a>'
)
);
if
(
lookupOnly
&&
!
inputs
.
length
)
{
if
(
!
$result
)
{
$outputOverride
.
empty
().
append
(
$result
);
$result
=
getOutput
();
}
else
{
if
(
lookupOnly
&&
!
inputs
.
length
)
outputSpan
.
append
(
$result
);
$outputOverride
.
empty
().
append
(
$result
);
else
outputSpan
.
append
(
$result
);
}
replaceOutput
(
$result
,
$
(
'<span>Waiting for transaction to be mined...</span>'
));
if
(
isConstructor
)
{
if
(
args
.
bytecode
.
indexOf
(
'_'
)
>=
0
)
{
replaceOutput
(
$result
,
$
(
'<span>Deploying and linking required libraries...</span>'
));
if
(
self
.
options
.
vm
)
self
.
linkBytecode
(
args
.
contractName
,
function
(
err
,
bytecode
)
{
if
(
err
)
replaceOutput
(
$result
,
$
(
'<span/>'
).
text
(
'Error deploying required libraries: '
+
err
));
else
{
args
.
bytecode
=
bytecode
;
handleCallButtonClick
(
ev
,
$result
);
}
});
else
replaceOutput
(
$result
,
$
(
'<span>Contract needs to be linked to a library, this is only supported in the JavaScript VM for now.</span>'
));
return
;
}
else
data
=
args
.
bytecode
+
data
.
slice
(
8
);
}
}
self
.
runTx
(
data
,
args
,
function
(
err
,
result
)
{
self
.
runTx
(
data
,
args
,
function
(
err
,
result
)
{
if
(
err
)
{
if
(
err
)
{
$result
.
replaceWith
(
getOutput
(
$
(
'<span/>'
).
text
(
err
).
addClass
(
'error'
)
)
);
replaceOutput
(
$result
,
$
(
'<span/>'
).
text
(
err
).
addClass
(
'error'
)
);
}
else
if
(
self
.
options
.
vm
&&
isConstructor
)
{
}
else
if
(
self
.
options
.
vm
&&
isConstructor
)
{
$result
.
replaceWith
(
getOutput
(
getGasUsedOutput
(
result
)
)
);
replaceOutput
(
$result
,
getGasUsedOutput
(
result
)
);
args
.
appendFunctions
(
result
.
createdAddress
);
args
.
appendFunctions
(
result
.
createdAddress
);
}
else
if
(
self
.
options
.
vm
){
}
else
if
(
self
.
options
.
vm
){
var
outputObj
=
fun
.
unpackOutput
(
'0x'
+
result
.
vm
.
return
.
toString
(
'hex'
));
var
outputObj
=
fun
.
unpackOutput
(
'0x'
+
result
.
vm
.
return
.
toString
(
'hex'
));
$result
.
replaceWith
(
getOutput
(
getReturnOutput
(
outputObj
),
getGasUsedOutput
(
result
.
vm
)
)
);
clearOutput
(
$result
);
$result
.
append
(
getReturnOutput
(
outputObj
)).
append
(
getGasUsedOutput
(
result
.
vm
));
}
else
if
(
args
.
abi
.
constant
&&
!
isConstructor
)
{
}
else
if
(
args
.
abi
.
constant
&&
!
isConstructor
)
{
$result
.
replaceWith
(
getOutput
(
getReturnOutput
(
result
)
)
);
replaceOutput
(
$result
,
getReturnOutput
(
result
)
);
}
else
{
}
else
{
function
tryTillResponse
(
txhash
,
done
)
{
function
tryTillResponse
(
txhash
,
done
)
{
...
@@ -262,7 +296,10 @@ UniversalDApp.prototype.getCallButton = function(args) {
...
@@ -262,7 +296,10 @@ UniversalDApp.prototype.getCallButton = function(args) {
if
(
isConstructor
)
{
if
(
isConstructor
)
{
$result
.
html
(
''
);
$result
.
html
(
''
);
args
.
appendFunctions
(
result
.
contractAddress
);
args
.
appendFunctions
(
result
.
contractAddress
);
}
else
$result
.
replaceWith
(
getOutput
(
getReturnOutput
(
result
),
getGasUsedOutput
(
result
)
)
);
}
else
{
clearOutput
(
$result
);
$result
.
append
(
getReturnOutput
(
result
)).
append
(
getGasUsedOutput
(
result
));
}
})
})
}
}
...
@@ -289,6 +326,49 @@ UniversalDApp.prototype.getCallButton = function(args) {
...
@@ -289,6 +326,49 @@ UniversalDApp.prototype.getCallButton = function(args) {
return
$contractProperty
.
append
(
outputSpan
);
return
$contractProperty
.
append
(
outputSpan
);
}
}
UniversalDApp
.
prototype
.
linkBytecode
=
function
(
contractName
,
cb
)
{
var
bytecode
=
this
.
getContractByName
(
contractName
).
bytecode
;
if
(
bytecode
.
indexOf
(
'_'
)
<
0
)
return
cb
(
null
,
bytecode
);
var
m
=
bytecode
.
match
(
/__
([^
_
]{1,36})
__/
);
if
(
!
m
)
return
cb
(
"Invalid bytecode format."
);
var
libraryName
=
m
[
1
];
if
(
!
this
.
getContractByName
(
contractName
))
return
cb
(
"Library "
+
libraryName
+
" not found."
);
var
self
=
this
;
this
.
deployLibrary
(
libraryName
,
function
(
err
,
address
)
{
if
(
err
)
return
cb
(
err
);
var
libLabel
=
'__'
+
libraryName
+
Array
(
39
-
libraryName
.
length
).
join
(
'_'
);
var
hexAddress
=
address
.
toString
(
'hex'
);
if
(
hexAddress
.
slice
(
0
,
2
)
==
'0x'
)
hexAddress
=
hexAddress
.
slice
(
2
);
hexAddress
=
Array
(
40
-
hexAddress
.
length
+
1
).
join
(
'0'
)
+
hexAddress
;
while
(
bytecode
.
indexOf
(
libLabel
)
>=
0
)
bytecode
=
bytecode
.
replace
(
libLabel
,
hexAddress
);
self
.
getContractByName
(
contractName
).
bytecode
=
bytecode
;
self
.
linkBytecode
(
contractName
,
cb
);
});
};
UniversalDApp
.
prototype
.
deployLibrary
=
function
(
contractName
,
cb
)
{
if
(
this
.
getContractByName
(
contractName
).
address
)
return
cb
(
null
,
this
.
getContractByName
(
contractName
).
address
);
var
self
=
this
;
var
bytecode
=
this
.
getContractByName
(
contractName
).
bytecode
;
if
(
bytecode
.
indexOf
(
'_'
)
>=
0
)
this
.
linkBytecode
(
contractName
,
function
(
err
,
bytecode
)
{
if
(
err
)
cb
(
err
);
else
self
.
deployLibrary
(
contractName
,
cb
);
});
else
{
this
.
runTx
(
bytecode
,
{
abi
:
{
constant
:
false
},
bytecode
:
bytecode
},
function
(
err
,
result
)
{
if
(
err
)
return
cb
(
err
);
self
.
getContractByName
(
contractName
).
address
=
result
.
createdAddress
;
cb
(
err
,
result
.
createdAddress
);
});
}
};
UniversalDApp
.
prototype
.
clickNewContract
=
function
(
self
,
$contract
,
contract
)
{
UniversalDApp
.
prototype
.
clickNewContract
=
function
(
self
,
$contract
,
contract
)
{
$contract
.
append
(
self
.
getInstanceInterface
(
contract
)
);
$contract
.
append
(
self
.
getInstanceInterface
(
contract
)
);
}
}
...
...
stylesheets/browser-solidity.css
View file @
083df317
...
@@ -126,19 +126,15 @@ body {
...
@@ -126,19 +126,15 @@ body {
float
:
left
;
float
:
left
;
}
}
.
udapp
.hide
{
.
contract
.hide
{
padding-bottom
:
0
;
padding-bottom
:
0
;
}
}
.udapp.hide
>
*
:not
(
.contract
)
{
.contract.hide
{
display
:
none
;
}
.udapp.hide
.contract
{
margin
:
0
;
margin
:
0
;
}
}
.
udapp.hide
.contract
>
*
:not
(
.title
)
{
.
contract.hide
>
*
:not
(
.title
)
{
display
:
none
;
display
:
none
;
}
}
...
@@ -153,7 +149,7 @@ body {
...
@@ -153,7 +149,7 @@ body {
font-size
:
10px
;
font-size
:
10px
;
}
}
.
udapp.hide
>
.contract
>
.title
:before
{
.
contract.hide
>
.title
:before
{
content
:
"\25B6"
;
content
:
"\25B6"
;
}
}
...
...
stylesheets/universal-dapp.css
View file @
083df317
...
@@ -43,6 +43,7 @@
...
@@ -43,6 +43,7 @@
.udapp
.contract
{
.udapp
.contract
{
margin-bottom
:
1em
;
margin-bottom
:
1em
;
clear
:
both
;
}
}
.udapp
.create
{
.udapp
.create
{
...
...
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