switch account resolution logic into recorder + switch transaction copy2clipboard to create scenario.json file

pull/1/head
serapath 7 years ago committed by yann300
parent dfdde07da7
commit a11b616e74
  1. 1
      src/app.js
  2. 18
      src/app/tabs/run-tab.js
  3. 10
      src/recorder.js
  4. 2
      src/universal-dapp.js

@ -556,6 +556,7 @@ function run () {
udapp: () => {
return udapp
},
filesProviders: filesProviders,
fileProviderOf: (path) => {
return fileManager.fileProviderOf(path)
},

@ -303,8 +303,14 @@ function makeRecorder (self, appAPI, appEvents) {
`
recordButton.onclick = () => {
var txJSON = JSON.stringify(recorder.getAll(), null, 2)
copy(txJSON)
modalDialogCustom.alert(txJSON)
modalDialogCustom.prompt(null, 'journal file name', 'scenario.json', input => {
var newName = appAPI.filesProvider['browser'].type + '/' + helper.createNonClashingName(input, appAPI.filesProvider['browser'])
if (!appAPI.filesProvider['browser'].set(newName, txJSON)) {
modalDialogCustom.alert('Failed to create file ' + newName)
} else {
appAPI.switchFile(newName)
}
})
}
runButton.onclick = () => {
var opts = { title: `Enter Transactions`, text: `Paste the array of transaction you want to replay here`, inputValue: '', multiline: true }
@ -315,7 +321,13 @@ function makeRecorder (self, appAPI, appEvents) {
modalDialogCustom.alert('Invalid JSON, please try again')
}
if (txArray.length) {
txArray.forEach(tx => udapp.rerunTx(tx.record, CALLBACK))
txArray.forEach(tx => {
udapp.getAccounts((err, accounts = []) => {
if (err) console.error(err)
tx.record = recorder.resolveAddress(tx.record, accounts)
udapp.rerunTx(tx.record, CALLBACK)
})
})
}
}, function cancel () { })
}

@ -44,6 +44,16 @@ class Recorder {
})
})
}
resolveAddress (record, accounts) {
if (record.to && record.to[0] === '<') record.to = accounts[record.to.split('>')[0].slice(11)]
if (record.from && record.from[0] === '<') record.from = accounts[record.from.split('>')[0].slice(11)]
// @TODO: change copy/paste to write and read from history file
// @TODO: writing browser test
// @TODO: replace addresses with custom ones (maybe address mapping file?)
return record
}
append (timestamp, record) {
var self = this
self.data.journal.push({ timestamp, record })

@ -471,8 +471,6 @@ UniversalDApp.prototype.rerunTx = function (args, cb) {
var self = this
self.getAccounts(function (err, accounts = []) {
if (err) console.error(err)
if (args.to && args.to[0] === '<') args.to = accounts[args.to.split('>')[0].slice(11)]
if (args.from && args.from[0] === '<') args.from = accounts[args.from.split('>')[0].slice(11)]
var pipeline = [queryGasLimit, runTransaction]
var env = { self, args, tx: { to: args.to, from: args.from, data: args.data, useCall: args.useCall } }
execute(pipeline, env, cb)

Loading…
Cancel
Save