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
955355cd
Commit
955355cd
authored
Nov 28, 2017
by
serapath
Committed by
yann300
Dec 06, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UPDATE save/run transaction from copy2clipboard to files
parent
60e80de3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
49 deletions
+67
-49
run-tab.js
src/app/tabs/run-tab.js
+17
-22
recorder.js
src/recorder.js
+48
-23
universal-dapp.js
src/universal-dapp.js
+2
-4
No files found.
src/app/tabs/run-tab.js
View file @
955355cd
...
@@ -195,18 +195,8 @@ function runTab (container, appAPI, appEvents, opts) {
...
@@ -195,18 +195,8 @@ function runTab (container, appAPI, appEvents, opts) {
`
`
container
.
appendChild
(
el
)
container
.
appendChild
(
el
)
function
addInstance
(
result
)
{
function
addInstance
(
sourcename
)
{
// {
var
contract
=
appAPI
.
getContract
(
sourcename
)
// "result": {
// "gasUsed": "5318",
// "vm": { "exception": 1, "selfdestruct": {} },
// "bloom": { "bitvector": { "type": "Buffer", "data": [0, /* ... */ 0, 0] } },
// "amountSpent": "5318"
// },
// "transactionHash": "0x84f68f96944a47b27af4b4ed1986637aa1bc05fd7a6f5cb1d6a53f68058276d8"
// }
var
contractNames
=
document
.
querySelector
(
`.
${
css
.
contractNames
.
classNames
[
0
]}
`
)
var
contract
=
appAPI
.
getContract
(
contractNames
.
children
[
contractNames
.
selectedIndex
].
innerHTML
)
var
address
=
self
.
_view
.
atAddressButtonInput
.
value
var
address
=
self
.
_view
.
atAddressButtonInput
.
value
var
instance
=
udapp
.
renderInstance
(
contract
.
object
,
address
,
self
.
_view
.
selectContractNames
.
value
)
var
instance
=
udapp
.
renderInstance
(
contract
.
object
,
address
,
self
.
_view
.
selectContractNames
.
value
)
instanceContainer
.
appendChild
(
instance
)
instanceContainer
.
appendChild
(
instance
)
...
@@ -322,22 +312,27 @@ function makeRecorder (self, appAPI, appEvents) {
...
@@ -322,22 +312,27 @@ function makeRecorder (self, appAPI, appEvents) {
var
json
=
appAPI
.
filesProviders
[
'browser'
].
get
(
filename
)
var
json
=
appAPI
.
filesProviders
[
'browser'
].
get
(
filename
)
if
(
!
json
)
return
modalDialogCustom
.
alert
(
'Could not find file with transactions, please try again'
)
if
(
!
json
)
return
modalDialogCustom
.
alert
(
'Could not find file with transactions, please try again'
)
try
{
try
{
var
txArray
=
JSON
.
parse
(
json
)
var
obj
=
JSON
.
parse
(
json
)
var
txArray
=
obj
.
transactions
||
[]
var
addresses
=
obj
.
addresses
||
{}
}
catch
(
e
)
{
}
catch
(
e
)
{
modalDialogCustom
.
alert
(
'Invalid JSON, please try again'
)
modalDialogCustom
.
alert
(
'Invalid JSON, please try again'
)
}
}
if
(
txArray
.
length
)
{
if
(
txArray
.
length
)
{
txArray
.
forEach
(
tx
=>
{
txArray
.
forEach
(
tx
=>
{
udapp
.
getAccounts
((
err
,
accounts
=
[])
=>
{
var
record
=
recorder
.
resolveAddress
(
tx
.
record
,
addresses
)
if
(
err
)
console
.
error
(
err
)
udapp
.
rerunTx
(
record
,
function
(
err
,
result
)
{
tx
.
record
=
recorder
.
resolveAddress
(
tx
.
record
,
accounts
)
// {
udapp
.
rerunTx
(
tx
.
record
,
function
(
err
,
result
)
{
// "result": {
// "gasUsed": "5318",
// "vm": { "exception": 1, "selfdestruct": {} },
// "bloom": { "bitvector": { "type": "Buffer", "data": [0, /* ... */ 0, 0] } },
// "amountSpent": "5318"
// },
// "transactionHash": "0x84f68f96944a47b27af4b4ed1986637aa1bc05fd7a6f5cb1d6a53f68058276d8"
// }
if
(
err
)
console
.
error
(
err
)
if
(
err
)
console
.
error
(
err
)
else
{
else
if
(
record
.
src
)
self
.
addInstance
(
record
.
src
)
// at each callback call, if the transaction succeed and if this is a creation transaction, we should call
self
.
addInstance
(
result
)
}
})
})
})
})
})
}
}
...
...
src/recorder.js
View file @
955355cd
...
@@ -7,25 +7,35 @@ class Recorder {
...
@@ -7,25 +7,35 @@ class Recorder {
self
.
_api
=
opts
.
api
self
.
_api
=
opts
.
api
self
.
event
=
new
EventManager
()
self
.
event
=
new
EventManager
()
self
.
data
=
{
journal
:
[],
_pendingCreation
:
{}
}
self
.
data
=
{
journal
:
[],
_pendingCreation
:
{}
}
opts
.
events
.
executioncontext
.
register
(
'contextChanged'
,
function
()
{
opts
.
events
.
executioncontext
.
register
(
'contextChanged'
,
()
=>
self
.
clearAll
())
self
.
clearAll
()
})
var
counter
=
0
var
counter
=
0
function
getIndex
(
accounts
,
address
)
{
var
index
accounts
.
forEach
((
addr
,
idx
)
=>
{
if
(
address
===
addr
)
index
=
idx
})
if
(
!
index
)
index
=
(
++
counter
)
return
index
}
self
.
_addressCache
=
{}
self
.
_addressCache
=
{}
function
getAddresses
(
cb
)
{
self
.
_api
.
getAccounts
(
function
(
err
,
accounts
=
[])
{
if
(
err
)
console
.
error
(
err
)
var
addresses
=
accounts
.
reduce
((
addr
,
account
)
=>
{
if
(
!
addr
[
account
])
addr
[
account
]
=
`account{
${
++
counter
}
}`
return
addr
},
self
.
_addressCache
)
cb
(
addresses
)
})
}
function
getCurrentContractName
()
{
var
contractNames
=
document
.
querySelector
(
`[class^="contractNames"]`
)
var
contractName
=
contractNames
.
children
[
contractNames
.
selectedIndex
].
innerHTML
return
contractName
}
opts
.
events
.
udapp
.
register
(
'initiatingTransaction'
,
(
timestamp
,
tx
)
=>
{
opts
.
events
.
udapp
.
register
(
'initiatingTransaction'
,
(
timestamp
,
tx
)
=>
{
var
{
from
,
to
,
value
,
gas
,
data
}
=
tx
var
{
from
,
to
,
value
,
gas
,
data
}
=
tx
var
record
=
{
value
,
gas
,
data
}
var
record
=
{
value
,
gas
,
data
}
self
.
_api
.
getAccounts
(
function
(
err
,
accounts
=
[])
{
getAddresses
(
addresses
=>
{
if
(
err
)
console
.
error
(
err
)
if
(
to
)
record
.
to
=
addresses
[
to
]
||
(
addresses
[
to
]
=
self
.
_addressCache
[
to
]
=
`contract{
${
++
counter
}
}`
)
record
.
from
=
self
.
_addressCache
[
from
]
||
(
self
.
_addressCache
[
from
]
=
`<account -
${
getIndex
(
accounts
,
from
)}
>`
)
else
{
if
(
to
)
record
.
to
=
self
.
_addressCache
[
to
]
||
(
self
.
_addressCache
[
to
]
=
`<account -
${
getIndex
(
accounts
,
to
)}
>`
)
record
.
src
=
getCurrentContractName
()
else
self
.
data
.
_pendingCreation
[
timestamp
]
=
record
self
.
data
.
_pendingCreation
[
timestamp
]
=
record
}
record
.
from
=
addresses
[
from
]
||
(
addresses
[
from
]
=
self
.
_addressCache
[
from
]
=
`account{
${
++
counter
}
}`
)
self
.
append
(
timestamp
,
record
)
self
.
append
(
timestamp
,
record
)
})
})
})
})
...
@@ -38,20 +48,32 @@ class Recorder {
...
@@ -38,20 +48,32 @@ class Recorder {
delete
self
.
data
.
_pendingCreation
[
timestamp
]
delete
self
.
data
.
_pendingCreation
[
timestamp
]
if
(
!
record
)
return
if
(
!
record
)
return
var
to
=
args
[
2
]
var
to
=
args
[
2
]
self
.
_api
.
getAccounts
(
function
(
err
,
accounts
=
[])
{
getAddresses
(
addresses
=>
{
if
(
err
)
console
.
error
(
err
)
if
(
to
)
{
if
(
to
)
record
.
to
=
self
.
_addressCache
[
to
]
||
(
self
.
_addressCache
[
to
]
=
`<contract -
${
getIndex
(
accounts
,
to
)}
>`
)
delete
record
.
src
record
.
to
=
addresses
[
to
]
||
(
addresses
[
to
]
=
self
.
_addressCache
[
to
]
=
`account{
${
++
counter
}
}`
)
}
else
record
.
src
=
getCurrentContractName
()
})
})
})
})
}
}
resolveAddress
(
record
,
accounts
)
{
resolveAddress
(
record
,
addresses
)
{
if
(
record
.
to
&&
record
.
to
[
0
]
===
'<'
)
record
.
to
=
accounts
[
record
.
to
.
split
(
'>'
)[
0
].
slice
(
11
)]
// var getPseudoAddress = placeholder => placeholder.split(' ')[0]//.split('-')[1].slice(1)
if
(
record
.
from
&&
record
.
from
[
0
]
===
'<'
)
record
.
from
=
accounts
[
record
.
from
.
split
(
'>'
)[
0
].
slice
(
11
)]
var
pseudos
=
Object
.
keys
(
addresses
).
reduce
((
pseudos
,
address
)
=>
{
// @TODO: change copy/paste to write and read from history file
// var p = addresses[address]//getPseudoAddress()//.split('>')[0].split('-')[1].slice(1)
pseudos
[
addresses
[
address
]]
=
address
return
pseudos
},
{})
if
(
record
.
to
&&
record
.
to
[
0
]
!==
'0'
)
record
.
to
=
pseudos
[
record
.
to
]
if
(
record
.
from
&&
record
.
from
[
0
]
!==
'0'
)
record
.
from
=
pseudos
[
record
.
from
]
// @TODO: fix load transactions and execute !
// @TODO: add 'clean' button to clear all recorded transactions
// @TODO: prefix path with `browser/` or `localhost/` if user provides
// @TODO: offer users by default a "save path" prefixed with the currently open file in the editor
// @TODO: offer users by default a "load path" prefixed with the currently open file in the editor (show first one that comes)
// @TODO: writing browser test
// @TODO: writing browser test
// @TODO: replace addresses with custom ones (maybe address mapping file?)
return
record
return
record
}
}
append
(
timestamp
,
record
)
{
append
(
timestamp
,
record
)
{
...
@@ -61,12 +83,15 @@ class Recorder {
...
@@ -61,12 +83,15 @@ class Recorder {
getAll
()
{
getAll
()
{
var
self
=
this
var
self
=
this
var
records
=
[].
concat
(
self
.
data
.
journal
)
var
records
=
[].
concat
(
self
.
data
.
journal
)
return
records
.
sort
((
A
,
B
)
=>
{
return
{
addresses
:
self
.
_addressCache
,
transactions
:
records
.
sort
((
A
,
B
)
=>
{
var
stampA
=
A
.
timestamp
var
stampA
=
A
.
timestamp
var
stampB
=
B
.
timestamp
var
stampB
=
B
.
timestamp
return
stampA
-
stampB
return
stampA
-
stampB
})
})
}
}
}
clearAll
()
{
clearAll
()
{
var
self
=
this
var
self
=
this
self
.
data
.
journal
=
[]
self
.
data
.
journal
=
[]
...
...
src/universal-dapp.js
View file @
955355cd
...
@@ -469,12 +469,10 @@ function execute (pipeline, env, callback) {
...
@@ -469,12 +469,10 @@ function execute (pipeline, env, callback) {
UniversalDApp
.
prototype
.
rerunTx
=
function
(
args
,
cb
)
{
UniversalDApp
.
prototype
.
rerunTx
=
function
(
args
,
cb
)
{
var
self
=
this
var
self
=
this
self
.
getAccounts
(
function
(
err
,
accounts
=
[])
{
var
tx
=
{
to
:
args
.
to
,
from
:
args
.
from
,
data
:
args
.
data
,
useCall
:
args
.
useCall
}
if
(
err
)
console
.
error
(
err
)
var
pipeline
=
[
queryGasLimit
,
runTransaction
]
var
pipeline
=
[
queryGasLimit
,
runTransaction
]
var
env
=
{
self
,
args
,
tx
:
{
to
:
args
.
to
,
from
:
args
.
from
,
data
:
args
.
data
,
useCall
:
args
.
useCall
}
}
var
env
=
{
self
,
args
,
tx
}
execute
(
pipeline
,
env
,
cb
)
execute
(
pipeline
,
env
,
cb
)
})
}
}
UniversalDApp
.
prototype
.
runTx
=
function
(
args
,
cb
)
{
UniversalDApp
.
prototype
.
runTx
=
function
(
args
,
cb
)
{
...
...
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