Messing around with @truffle/debugger library to generate sequence diagrams
Messing around with @truffle/debugger as a library, to generate sequence diagrams.
ℹ️ Note: this is an experiment! This is not maintained! The diagrams this produces are almost certainly wrong, and potentially dangerously misleading.
The current plan for this is to make it part of Truffle itself. This repo exists for people that want to try it out in its buggy, incomplete state.
Example ERC20 transfer
This requires two changes to Truffle that aren't merged yet. You'll need to run a local dev clone:
$ git clone [email protected]:trufflesuite/truffle.git
$ cd truffle
$ git checkout bag/tx2seq
$ yarn bootstrap
You'll also need to link @truffle/core. From the Truffle repo root directory:
$ cd packages/core
$ yarn link
This repo isn't published to NPM so you'll need to clone + link manually.
$ git clone [email protected]:gnidan/tx2seq.git
$ cd tx2seq
$ yarn
$ yarn link @truffle/core
$ yarn link
Alright!
This can either be your existing project, or a fresh truffle init
.
So that when you run truffle
, you'll use your local clone instead of what's
installed.
$ alias truffle=node\ <path-to-repo>/packages/truffle/build/cli.bundled.js
$ yarn link tx2seq
Requirement: you need an archive node for this! Preferably one that exposes
geth-style debug_traceTransaction
, but ganache-cli --fork
will do,
provided:
mainnet
, then Ganache better also say that net_version
is 1
)OK good to go? Update your truffle-config.js
! Make sure you configure your
network and add the plugin:
module.exports = {
// ... rest of truffle-config ...
networks: {
// ... rest of networks ...
// make sure the aforementioned debuggable archive node is configured
fork: {
// ...
}
},
// add the plugin
plugins: [
// ... rest of plugins ...
"tx2seq"
]
}
With all that, just run:
$ truffle run tx2seq \
--network=fork --fetch-external <tx-hash> \
> sequence.plantuml
Since it's 2020, you probably don't have Java installed, so just copy the
contents of sequence.plantuml
and head over to https://www.planttext.com/
and paste.
Voil!