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
2d8ed0b5
Commit
2d8ed0b5
authored
Apr 08, 2016
by
chriseth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #126 from axic/patch/vm-multiaddr
Support multiple accounts in VM mode
parents
e756686e
05f4abaa
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
17 deletions
+37
-17
app.js
assets/js/app.js
+8
-8
universal-dapp.js
assets/js/universal-dapp.js
+29
-9
No files found.
assets/js/app.js
View file @
2d8ed0b5
...
@@ -684,14 +684,8 @@
...
@@ -684,14 +684,8 @@
}});
}});
var
$contractOutput
=
dapp
.
render
();
var
$contractOutput
=
dapp
.
render
();
$txOrigin
=
$
(
'#txorigin'
);
$txOrigin
=
$
(
'#txorigin'
);
if
(
executionContext
===
'vm'
)
{
function
renderAccounts
(
err
,
accounts
)
{
$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
)
{
if
(
err
)
if
(
err
)
renderError
(
err
.
message
);
renderError
(
err
.
message
);
if
(
accounts
&&
accounts
[
0
]){
if
(
accounts
&&
accounts
[
0
]){
...
@@ -699,7 +693,13 @@
...
@@ -699,7 +693,13 @@
for
(
var
a
in
accounts
)
{
$txOrigin
.
append
(
$
(
'<option />'
).
val
(
accounts
[
a
]).
text
(
accounts
[
a
]));
}
for
(
var
a
in
accounts
)
{
$txOrigin
.
append
(
$
(
'<option />'
).
val
(
accounts
[
a
]).
text
(
accounts
[
a
]));
}
$txOrigin
.
val
(
accounts
[
0
]);
$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'
);
});
$contractOutput
.
find
(
'.title'
).
click
(
function
(
ev
){
$
(
this
).
closest
(
'.contract'
).
toggleClass
(
'hide'
);
});
$
(
'#output'
).
append
(
$contractOutput
);
$
(
'#output'
).
append
(
$contractOutput
);
...
...
assets/js/universal-dapp.js
View file @
2d8ed0b5
...
@@ -7,16 +7,14 @@ function UniversalDApp (contracts, options) {
...
@@ -7,16 +7,14 @@ function UniversalDApp (contracts, options) {
if
(
!
options
.
vm
&&
web3
.
currentProvider
)
{
if
(
!
options
.
vm
&&
web3
.
currentProvider
)
{
}
else
if
(
options
.
vm
)
{
}
else
if
(
options
.
vm
)
{
this
.
accounts
=
{}
this
.
BN
=
EthJS
.
BN
;
this
.
BN
=
EthJS
.
BN
;
this
.
stateTrie
=
new
EthJS
.
Trie
();
this
.
stateTrie
=
new
EthJS
.
Trie
();
this
.
vm
=
new
EthJS
.
VM
(
this
.
stateTrie
);
this
.
vm
=
new
EthJS
.
VM
(
this
.
stateTrie
);
this
.
secretKey
=
'3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511'
this
.
publicKey
=
'0406cc661590d48ee972944b35ad13ff03c7876eae3fd191e8a2f77311b0a3c6613407b5005e63d7d8d76b89d5f900cde691497688bb281e07a5052ff61edebdc0'
this
.
addAccount
(
'3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511'
)
this
.
address
=
ethUtil
.
pubToAddress
(
new
Buffer
(
this
.
publicKey
,
'hex'
),
true
);
this
.
addAccount
(
'2ac6c190b09897cd8987869cc7b918cfea07ee82038d492abce033c75c1b1d0c'
)
this
.
account
=
new
EthJS
.
Account
();
this
.
account
.
balance
=
'f00000000000000001'
;
this
.
nonce
=
0
;
this
.
vm
.
stateManager
.
trie
.
put
(
this
.
address
,
this
.
account
.
serialize
());
}
else
{
}
else
{
var
host
=
options
.
host
||
"localhost"
;
var
host
=
options
.
host
||
"localhost"
;
var
port
=
options
.
port
||
"8545"
;
var
port
=
options
.
port
||
"8545"
;
...
@@ -25,6 +23,26 @@ function UniversalDApp (contracts, options) {
...
@@ -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
()
{
UniversalDApp
.
prototype
.
render
=
function
()
{
if
(
this
.
contracts
.
length
==
0
)
{
if
(
this
.
contracts
.
length
==
0
)
{
this
.
$el
.
append
(
this
.
getABIInputForm
()
);
this
.
$el
.
append
(
this
.
getABIInputForm
()
);
...
@@ -437,15 +455,17 @@ UniversalDApp.prototype.runTx = function( data, args, cb) {
...
@@ -437,15 +455,17 @@ UniversalDApp.prototype.runTx = function( data, args, cb) {
}
}
}
else
{
}
else
{
try
{
try
{
var
address
=
this
.
options
.
getAddress
?
this
.
options
.
getAddress
()
:
this
.
getAccounts
()[
0
];
var
account
=
this
.
accounts
[
address
];
var
tx
=
new
EthJS
.
Tx
({
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
,
gasPrice
:
1
,
gasLimit
:
3000000000
,
//plenty
gasLimit
:
3000000000
,
//plenty
to
:
to
,
to
:
to
,
value
:
value
,
value
:
value
,
data
:
new
Buffer
(
data
.
slice
(
2
),
'hex'
)
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
);
this
.
vm
.
runTx
({
tx
:
tx
,
skipBalance
:
true
,
skipNonce
:
true
,
enableHomestead
:
true
},
cb
);
}
catch
(
e
)
{
}
catch
(
e
)
{
cb
(
e
,
null
);
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