Overview
I hinted at the need for a refactor last week, and that's what I ended up doing. Diagnosing the issues in the API were tricky, which could be summed up as it would only occassionally work. Breaking it apart helped me realize a few things:
- The wallet connected to the API, which was only there to verify
curl
routes were working, was taking precedence for transactions, not the wallet connected to the CLI. - The transaction hash generated was not a valid Ethereum transaction hash, so verifying the transaction completed was impossible.
- The gas fees were, in fact, too low to prioritize the transaction on chain, so it was stuck forever in the mempool.
I'm glad I did this, as it makes the API more robust, easier to diagnose and much simpler to add to in the future. I've gone from an api directory structure of:
api/
├── contract-abi.json # decxpress functionality abstracted into JSON
├── server.ts # all the functionality
└── test-client.js # all tests for the API
to
api/
├── controllers/
│ ├── balanceController.ts # logic for /balance endpoint
│ ├── hashController.ts # logic for /hash/:hash endpoint
│ ├── pressController.ts # logic for /press endpoint
│ ├── releaseController.ts # logic for /release endpoint
│ ├── statusController.ts # logic for /status endpoint
├── middleware/
│ ├── errorHandler.ts # consistent formatting for errors
│ ├── requestLogger.ts # consistent formatting for logged messages
├── routes/
│ ├── balance.ts # definition for /balance endpoint
│ ├── hash.ts # definition for /hash/:hash endpoint
│ ├── press.ts # definition for /press endpoint
│ ├── release.ts # definition for /release endpoint
│ ├── status.ts # definition for /status endpoint
├── services/
│ ├── transactionStore.ts # comprehensive logic & logging for a transaction
│ ├── walletService.ts # comprehensive logic & logging for wallet connection
├── contract-abi.json # decxpress functionality abstracted into JSON
├── server.ts # minimal init file to call the API
├── test-local-storage.js # tests for local storage
├── test-performance.js # tests for deduplication verification
└── test-client.js # tests for the connection
I had heavy LLM help in defining how I'd break things apart and the best practices for storing the concerns across multiple files. But the big takeaway was I was doing 19 files worth of functionality in 3 files, so now it's much easier to make small, isolated changes and feel I'm having the maxium amount of impact with the least amount of consequences.
As mentioned above, the gas fees were too low, which means that I've made decx.press too effecient. I've added some multipliers so that it at least hits the gas fee minimum to be incorporated on-chain. However, I know that Sepolia, which is the testing environment I am using to test my functionality on, has much lower gas fees than the Ethereum mainnetgit . It will be something I'll keep my eye on once I deploy to production.
Last Week
- Finish up the work on the pressing functionality, finding a consistent way to press content [CLI#3] (almost done with this)
Next Week
- Merge in the pressing functionality [CLI#3]
- Start building the storage functionality for pressed (& TBD released) content [CLI#4]
Blockers
None.
Reflections on Process
Things are moving much slower than they were at the beginning of the semester. All the decisions from the past are piling up and making each continued step harder and harder to move forward on. I read an article once that (I cannot find currently) that made the case that the last 20% of the work takes up 80% of the time, and I'm finding that to be true now. I do feel like the end is in sight, or at least a satisfactory stopping point with robust enough functionality, so I'll keep hacking away at the vines.