Skip to content

Commit

Permalink
switch account resolution logic into recorder + switch transaction co…
Browse files Browse the repository at this point in the history
…py2clipboard to create scenario.json file
  • Loading branch information
serapath authored and yann300 committed Dec 6, 2017
1 parent dfdde07 commit a11b616
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ function run () {
udapp: () => {
return udapp
},
filesProviders: filesProviders,
fileProviderOf: (path) => {
return fileManager.fileProviderOf(path)
},
Expand Down
18 changes: 15 additions & 3 deletions src/app/tabs/run-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 () { })
}
Expand Down
10 changes: 10 additions & 0 deletions src/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
2 changes: 0 additions & 2 deletions src/universal-dapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a11b616

Please sign in to comment.