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
c6062c53
Commit
c6062c53
authored
Oct 08, 2015
by
chriseth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Automatically deploy and link required libraries.
parent
e7fe06c8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
7 deletions
+76
-7
index.html
index.html
+1
-4
universal-dapp.js
libs/universal-dapp.js
+75
-3
No files found.
index.html
View file @
c6062c53
...
...
@@ -533,10 +533,7 @@ THE SOFTWARE.
$
(
'#txorigin'
).
text
(
accounts
[
0
]);
});
$contractOutput
.
find
(
'.title'
).
click
(
function
(
ev
){
console
.
log
(
$
(
this
));
$
(
this
).
closest
(
'.contract'
).
toggleClass
(
'hide'
);
});
$contractOutput
.
find
(
'.title'
).
click
(
function
(
ev
){
$
(
this
).
closest
(
'.contract'
).
toggleClass
(
'hide'
);
});
$
(
'#output'
).
append
(
$contractOutput
);
$
(
'.col2 input,textarea'
).
click
(
function
()
{
this
.
select
();
});
};
...
...
libs/universal-dapp.js
View file @
c6062c53
...
...
@@ -60,10 +60,17 @@ UniversalDApp.prototype.render = function () {
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
){
var
self
=
this
;
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'
)
$createButton
.
click
(
function
(
ev
){
var
contracts
=
$
.
parseJSON
(
$jsonInput
.
val
()
);
...
...
@@ -158,6 +165,7 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar
if
(
!
address
||
!
$target
)
{
$createInterface
.
append
(
this
.
getCallButton
({
abi
:
funABI
,
contractName
:
contract
.
name
,
bytecode
:
contract
.
bytecode
,
appendFunctions
:
appendFunctions
}));
...
...
@@ -180,7 +188,7 @@ UniversalDApp.prototype.getConstructorInterface = function(abi) {
UniversalDApp
.
prototype
.
getCallButton
=
function
(
args
)
{
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]
var
isConstructor
=
args
.
bytecode
!==
undefined
;
var
lookupOnly
=
(
args
.
abi
.
constant
&&
!
isConstructor
);
...
...
@@ -226,10 +234,27 @@ UniversalDApp.prototype.getCallButton = function(args) {
var
funArgs
=
$
.
parseJSON
(
'['
+
inputField
.
val
()
+
']'
);
var
data
=
fun
.
toPayload
(
funArgs
).
data
;
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
(
isConstructor
)
{
if
(
args
.
bytecode
.
indexOf
(
'_'
)
>=
0
)
{
if
(
self
.
options
.
vm
)
self
.
linkBytecode
(
args
.
contractName
,
function
(
err
,
bytecode
)
{
if
(
err
)
$result
.
replaceWith
(
getOutput
(
$
(
'<span/>'
).
text
(
'Error deploying required libraries: '
+
err
)));
else
{
args
.
bytecode
=
bytecode
;
handleCallButtonClick
(
ev
);
}
});
else
$result
.
replaceWeth
(
getOutput
(
$
(
'<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
);
}
if
(
lookupOnly
&&
!
inputs
.
length
)
{
$outputOverride
.
empty
().
append
(
$result
);
}
else
{
...
...
@@ -290,6 +315,53 @@ UniversalDApp.prototype.getCallButton = function(args) {
return
$contractProperty
.
append
(
outputSpan
);
}
UniversalDApp
.
prototype
.
linkBytecode
=
function
(
contractName
,
cb
)
{
console
.
log
(
"linking "
+
contractName
);
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
)
{
console
.
log
(
"deploying librari "
+
contractName
);
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
{
console
.
log
(
cb
);
this
.
runTx
(
bytecode
,
{
abi
:
{
constant
:
false
},
bytecode
:
bytecode
},
function
(
err
,
result
)
{
console
.
log
(
cb
);
if
(
err
)
return
cb
(
err
);
self
.
getContractByName
(
contractName
).
address
=
result
.
createdAddress
;
cb
(
err
,
result
.
createdAddress
);
});
}
};
UniversalDApp
.
prototype
.
clickNewContract
=
function
(
self
,
$contract
,
contract
)
{
$contract
.
append
(
self
.
getInstanceInterface
(
contract
)
);
}
...
...
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