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
05f4abaa
Commit
05f4abaa
authored
Apr 04, 2016
by
Alex Beregszaszi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support multiple accounts in VM mode
parent
e756686e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
18 deletions
+38
-18
app.js
assets/js/app.js
+9
-9
universal-dapp.js
assets/js/universal-dapp.js
+29
-9
No files found.
assets/js/app.js
View file @
05f4abaa
...
...
@@ -684,22 +684,22 @@
}});
var
$contractOutput
=
dapp
.
render
();
$txOrigin
=
$
(
'#txorigin'
);
if
(
executionContext
===
'vm'
)
{
$txOrigin
.
empty
();
var
addr
=
'0x'
+
dapp
.
address
.
toString
(
'hex'
);
$txOrigin
.
val
(
addr
);
$txOrigin
.
append
(
$
(
'<option />'
).
val
(
addr
).
text
(
addr
));
}
else
web3
.
eth
.
getAccounts
(
function
(
err
,
accounts
)
{
function
renderAccounts
(
err
,
accounts
)
{
if
(
err
)
renderError
(
err
.
message
);
if
(
accounts
&&
accounts
[
0
]){
$txOrigin
.
empty
();
for
(
var
a
in
accounts
)
{
$txOrigin
.
append
(
$
(
'<option />'
).
val
(
accounts
[
a
]).
text
(
accounts
[
a
]));
}
$txOrigin
.
val
(
accounts
[
0
]);
}
else
$txOrigin
.
val
(
'unknown'
);
});
}
else
$txOrigin
.
val
(
'unknown'
);
}
if
(
executionContext
===
'vm'
)
{
dapp
.
getAccounts
(
renderAccounts
);
}
else
{
web3
.
eth
.
getAccounts
(
renderAccounts
);
}
$contractOutput
.
find
(
'.title'
).
click
(
function
(
ev
){
$
(
this
).
closest
(
'.contract'
).
toggleClass
(
'hide'
);
});
$
(
'#output'
).
append
(
$contractOutput
);
...
...
assets/js/universal-dapp.js
View file @
05f4abaa
...
...
@@ -7,16 +7,14 @@ function UniversalDApp (contracts, options) {
if
(
!
options
.
vm
&&
web3
.
currentProvider
)
{
}
else
if
(
options
.
vm
)
{
this
.
accounts
=
{}
this
.
BN
=
EthJS
.
BN
;
this
.
stateTrie
=
new
EthJS
.
Trie
();
this
.
vm
=
new
EthJS
.
VM
(
this
.
stateTrie
);
this
.
secretKey
=
'3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511'
this
.
publicKey
=
'0406cc661590d48ee972944b35ad13ff03c7876eae3fd191e8a2f77311b0a3c6613407b5005e63d7d8d76b89d5f900cde691497688bb281e07a5052ff61edebdc0'
this
.
address
=
ethUtil
.
pubToAddress
(
new
Buffer
(
this
.
publicKey
,
'hex'
),
true
);
this
.
account
=
new
EthJS
.
Account
();
this
.
account
.
balance
=
'f00000000000000001'
;
this
.
nonce
=
0
;
this
.
vm
.
stateManager
.
trie
.
put
(
this
.
address
,
this
.
account
.
serialize
());
this
.
addAccount
(
'3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511'
)
this
.
addAccount
(
'2ac6c190b09897cd8987869cc7b918cfea07ee82038d492abce033c75c1b1d0c'
)
}
else
{
var
host
=
options
.
host
||
"localhost"
;
var
port
=
options
.
port
||
"8545"
;
...
...
@@ -25,6 +23,26 @@ function UniversalDApp (contracts, options) {
}
}
UniversalDApp
.
prototype
.
addAccount
=
function
(
privateKey
,
balance
)
{
if
(
this
.
accounts
)
{
privateKey
=
new
Buffer
(
privateKey
,
'hex'
)
var
address
=
EthJS
.
Util
.
privateToAddress
(
privateKey
);
var
account
=
new
EthJS
.
Account
();
account
.
balance
=
balance
||
'f00000000000000001'
;
this
.
vm
.
stateManager
.
trie
.
put
(
address
,
account
.
serialize
());
this
.
accounts
[
'0x'
+
address
.
toString
(
'hex'
)]
=
{
privateKey
:
privateKey
,
nonce
:
0
};
}
};
UniversalDApp
.
prototype
.
getAccounts
=
function
(
cb
)
{
if
(
!
this
.
accounts
)
return
cb
(
"No accounts?"
);
cb
(
null
,
Object
.
keys
(
this
.
accounts
));
};
UniversalDApp
.
prototype
.
render
=
function
()
{
if
(
this
.
contracts
.
length
==
0
)
{
this
.
$el
.
append
(
this
.
getABIInputForm
()
);
...
...
@@ -437,15 +455,17 @@ UniversalDApp.prototype.runTx = function( data, args, cb) {
}
}
else
{
try
{
var
address
=
this
.
options
.
getAddress
?
this
.
options
.
getAddress
()
:
this
.
getAccounts
()[
0
];
var
account
=
this
.
accounts
[
address
];
var
tx
=
new
EthJS
.
Tx
({
nonce
:
new
Buffer
([
this
.
nonce
++
]),
//@todo count beyond 255
nonce
:
new
Buffer
([
account
.
nonce
++
]),
//@todo count beyond 255
gasPrice
:
1
,
gasLimit
:
3000000000
,
//plenty
to
:
to
,
value
:
value
,
data
:
new
Buffer
(
data
.
slice
(
2
),
'hex'
)
});
tx
.
sign
(
new
Buffer
(
this
.
secretKey
,
'hex'
)
);
tx
.
sign
(
account
.
privateKey
);
this
.
vm
.
runTx
({
tx
:
tx
,
skipBalance
:
true
,
skipNonce
:
true
,
enableHomestead
:
true
},
cb
);
}
catch
(
e
)
{
cb
(
e
,
null
);
...
...
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