diff --git a/src/app.js b/src/app.js
index f1e0ccb6fc..ecce1e1980 100644
--- a/src/app.js
+++ b/src/app.js
@@ -6,8 +6,6 @@ var yo = require('yo-yo')
var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager
-var Recorder = require('./recorder')
-
var UniversalDApp = require('./universal-dapp.js')
var Remixd = require('./lib/remixd')
var OffsetToLineColumnConverter = require('./lib/offsetToLineColumnConverter')
@@ -774,55 +772,4 @@ function run () {
self.event.trigger('debuggingRequested', [])
transactionDebugger.debug(txHash)
}
-
- /****************************************************************************
- RECORDER
- ****************************************************************************/
- var recorder = new Recorder({ events: {
- udapp: udapp.event,
- executioncontext: executionContext.event
- }})
-
- var css = csjs`
- .recorder {
- background-color: red;
- }
- .runTxs {
- background-color: green;
- }
- `
- var recordButton = yo``
- var runButton = yo``
-
- console.error('@TODO: append record and run buttons')
-
- recordButton.onclick = () => {
- var txJSON = JSON.stringify(recorder.getAll(), null, 2)
- copy2clipboard(txJSON)
- modalDialogCustom.alert(txJSON)
- }
- runButton.onclick = () => { // on modal OR run tab
- var txArray = recorder.getAll()
- udapp.runTx(txArray, CALLBACK) // ???
- // OR
- txArray.forEach(tx => udap.runTx(tx, CALLBACK)) // ???
- }
-
- function CALLBACK () {
- /*
- at each callback call, if the transaction succeed and if this is a creation transaction, we should call
- runtab.addInstance( ... ) which basically do:
- instanceContainer.appendChild(appAPI.udapp().renderInstance(contract, address,
- selectContractNames.value))
- */
- }
- function copy2clipboard (json) {
- var textarea = document.createElement('textarea')
- textarea.textContent = json
- document.body.appendChild(textarea)
- textarea.select()
- try { document.execCommand('copy') }
- catch (e) { }
- finally { document.body.removeChild(textarea) }
- }
}
diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js
index e1639fbfc1..a79892f3e1 100644
--- a/src/app/tabs/run-tab.js
+++ b/src/app/tabs/run-tab.js
@@ -8,6 +8,7 @@ var txHelper = require('../execution/txHelper')
var modalDialogCustom = require('../ui/modal-dialog-custom')
var executionContext = require('../../execution-context')
var copyToClipboard = require('../ui/copy-to-clipboard')
+var Recorder = require('../../recorder')
// -------------- styling ----------------------
var csjs = require('csjs-inject')
@@ -240,6 +241,59 @@ function updateAccountBalances (container, appAPI) {
})
}
+/* ------------------------------------------------
+ RECORDER
+------------------------------------------------ */
+function makeRecorder (appAPI, appEvents) {
+ var udapp = appAPI.udapp()
+ var recorder = new Recorder({ events: {
+ udapp: appEvents.udapp,
+ executioncontext: executionContext.event
+ }})
+ var css = csjs`
+ .container {
+ margin-top: 10px;
+ display: flex;
+ }
+ .recorder {
+ ${styles.button}
+ width: 135px;
+ }
+ .runTxs {
+ ${styles.button}
+ margin-left: 10px;
+ width: 135px;
+ }
+ `
+ var recordButton = yo``
+ var runButton = yo``
+ var el = yo`
+
+ ${recordButton}
+ ${runButton}
+
+ `
+ recordButton.onclick = () => {
+ var txJSON = JSON.stringify(recorder.getAll(), null, 2)
+ copy(txJSON)
+ modalDialogCustom.alert(txJSON)
+ }
+ runButton.onclick = () => { // on modal OR run tab
+ var txArray = recorder.getAll()
+ udapp.runTx(txArray, CALLBACK) // ???
+ // OR
+ // txArray.forEach(tx => udapp.runTx(tx, CALLBACK)) // ???
+ }
+ function CALLBACK () {
+ /*
+ at each callback call, if the transaction succeed and if this is a creation transaction, we should call
+ runtab.addInstance( ... ) which basically do:
+ instanceContainer.appendChild(appAPI.udapp().renderInstance(contract, address,
+ selectContractNames.value))
+ */
+ }
+ return el
+}
/* ------------------------------------------------
section CONTRACT DROPDOWN and BUTTONS
------------------------------------------------ */
@@ -429,6 +483,9 @@ function settings (appAPI, appEvents) {
+
+ ${makeRecorder(appAPI, appEvents)}
+
`
diff --git a/src/recorder.js b/src/recorder.js
index d72824d517..8897d26fd5 100644
--- a/src/recorder.js
+++ b/src/recorder.js
@@ -1,5 +1,3 @@
-var csjs = require('csjs-inject')
-var yo = require('yo-yo')
var remix = require('ethereum-remix')
var EventManager = remix.lib.EventManager
@@ -8,42 +6,45 @@ class Recorder {
var self = this
self._api = opts.api
self.event = new EventManager()
- self.data = { journal: [] }
- opts.events.txlogger.register('initiatingTransaction', (stamp, tx) => {
+ self.data = { journal: [], _pending: {} }
+ opts.events.executioncontext.register('contextChanged', function () {
+ self.clearAll()
+ })
+ opts.events.udapp.register('initiatingTransaction', (stamp, tx) => {
var { from, to, value, gas, data } = tx
- from = self.translate(from)
- to = self.translate(to)
- var deTx = { from, to, value, gas, data }
- self.append(stamp, deTx)
+ var deTx = { from, to, value, gas, data, pending: true }
+ self.data._pending[stamp] = deTx
})
opts.events.udapp.register('transactionExecuted', args => {
- var [err, from, to, data, isUserCall, result, stamp] = args
- console.log('@TODO: should i do something here?')
+ var [err, from, to, data, /* isUserCall, result, */ stamp] = args
+ if (err) console.error(err)
+ else update(stamp, from, to, data)
})
opts.events.udapp.register('callExecuted', args => {
- var [err, from, to, data, isUserCall, result, stamp] = args
- console.log('@TODO: should i do something here?')
+ var [err, from, to, data, /* isUserCall, result, */ stamp] = args
+ if (err) console.error(err)
+ else update(stamp, from, to, data)
})
- opts.events.executioncontext.register('contextChanged', function () {
- self.clearAll()
- })
- }
- translate (prop) {
- /* what to apply this to and why and how does it work?
- > Basically, transaction from / to tokens will be resolved as follow:
- > if (start with 0x) do nothing (we already have a supposed address)
- > if not : is resolved to the first account in the list of accounts given from universaldapp.
- > is resolved to second first account in the list of accounts given from universaldapp.
- > if the account list is not large enough, we take the last one.
-
- @TODO: what does it mean? (does that talk about the same as the next 4 lines of comments?)
-
- > Real addresses should be translated into token (apply to: to / from / return value of contract creation)
- > e.g: from: 0x123...123 , to: 0x123...145 should be saved as: from:, to:
- > e.g: from: 0x123...123, to: null (cause this is a contract creation),
- > the return value is the address of the created contract.
- */
- return prop
+ function update (stamp, from, to, data) {
+ var record = self._pending[stamp]
+ delete self._pending[stamp]
+ if (!record) return
+ // at this point you have a map 0x123789 <=> < contractName - 1>
+ // if a from` is 0x123789 you ill replace it by < contractName - 1>
+ // > if (start with 0x) do nothing (we already have a supposed address)
+ // > if not : is resolved to the first account in the list of accounts given from universaldapp.
+ // > is resolved to second first account in the list of accounts given from universaldapp.
+ // > if the account list is not large enough, we take the last one.
+ // > Real addresses should be translated into token (apply to: to / from / return value of contract creation)
+ // > e.g: from: 0x123...123 , to: 0x123...145 should be saved as: from:, to:
+ // > e.g: from: 0x123...123, to: null (cause this is a contract creation),
+ // > the return value is the address of the created contract.
+ console.log('@TODO: probably the below translation need to be adapted to the comments above')
+ record.from = from
+ record.to = to
+ record.data = data
+ self.append(stamp, record)
+ }
}
append (timestamp, record) {
var self = this