|
|
|
@ -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 : <account - 0> is resolved to the first account in the list of accounts given from universaldapp. |
|
|
|
|
> <account - 1> 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 : <account - 0> is resolved to the first account in the list of accounts given from universaldapp.
|
|
|
|
|
// > <account - 1> 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 |
|
|
|
|