[{"data":1,"prerenderedAt":190},["ShallowReactive",2],{"\u002Fblog\u002F2020-03-21-open-sourcing-the-triveasset-protocol":3},{"id":4,"title":5,"archiveType":6,"body":7,"category":174,"contextDate":175,"cover":176,"coverAlt":177,"date":178,"description":179,"extension":180,"featured":181,"historicalDate":178,"historicalLabel":175,"meta":182,"navigation":183,"path":184,"publishedDate":175,"seo":185,"stem":186,"thumbnail":175,"workPeriod":187,"writtenDate":188,"__hash__":189},"blogs\u002Fblog\u002F2020-03-21-open-sourcing-the-triveasset-protocol.md","Open-sourcing the TriveAsset protocol: tests, CI and a style guide in its first week","retrospective",{"type":8,"value":9,"toc":166},"minimark",[10,28,31,36,39,47,50,54,57,114,118,121,125,128,154,157],[11,12,13,14,21,22,27],"p",{},"On 21 March I made the TriveAsset protocol public on GitHub, under the Trivechain organisation (",[15,16,20],"a",{"href":17,"rel":18},"https:\u002F\u002Fgithub.com\u002Ftrivechain\u002Ftriveasset-protocol\u002Fcommit\u002F47e139a5aa0c8a6326f706b5fd9a05ebc423d6dd",[19],"nofollow","first commit","). It is the library that turns a TriveAsset operation, such as an issuance, a transfer or a burn, into the bytes a Trivechain transaction carries, and reads those bytes back. The same day I opened ",[15,23,26],{"href":24,"rel":25},"https:\u002F\u002Fgithub.com\u002Ftrivechain\u002Fhdwallet",[19],"hdwallet",", our key-handling library, whose interface covers BIP38 key encryption and BIP39 mnemonics.",[11,29,30],{},"This post is about the encoder, and about the week after the first commit.",[32,33,35],"h2",{"id":34},"why-the-encoder-came-first","Why the encoder came first",[11,37,38],{},"An encoder is a format, and on a blockchain a format is fixed as soon as the first transaction using it is mined. Every TriveAsset transaction already on Trivechain was written by this logic, and every wallet or indexer that reads them has to decode the bytes exactly as they were written.",[11,40,41,42,46],{},"A small example shows how little room there is. When an asset is issued, one byte carries three settings: its divisibility (0 to 15 decimal places), whether the issuance is locked, and an aggregation policy that governs whether amounts of the asset can be combined. Move one bit in the encoder and every asset already issued reads differently. Each encoded operation also begins with a two-byte marker, ",[43,44,45],"code",{},"0x5441",", the letters \"TA\", so a reader can tell our data apart from anything else.",[11,48,49],{},"Keeping that logic private would make every other implementation a guess. Opening it lets anyone check a decoder against the one we use. That is the argument for publishing the encoder before anything else in the stack.",[32,51,53],{"id":52},"what-the-week-after-added","What the week after added",[11,55,56],{},"The first commit was the encoders and their test files as they stood: a test runner listed as an ordinary dependency, an old coverage tool, no continuous integration and a README of a few lines. That is enough to read, but not enough to rely on. In the last week of March I added what a stranger needs:",[58,59,60,76,82,88,94,104],"ul",{},[61,62,63,67,68,71,72,75],"li",{},[64,65,66],"strong",{},"A proper structure."," Source in ",[43,69,70],{},"src\u002F",", tests in ",[43,73,74],{},"test\u002F",", and the suite wired up and running, starting with the issuance-flag encoder.",[61,77,78,81],{},[64,79,80],{},"Continuous integration."," Travis CI runs the tests on every push across Node.js 8 to 12, the range the library supports, and the README shows the build status.",[61,83,84,87],{},[64,85,86],{},"A coverage report."," The tests run under nyc and the result goes to Coveralls, so the coverage figure is public, whatever it is.",[61,89,90,93],{},[64,91,92],{},"One code style, enforced."," Prettier formats the code and ESLint applies the Standard rules, configured so the two agree. Review can then be about logic, not spacing.",[61,95,96,99,100,103],{},[64,97,98],{},"A smaller install."," The test runner moved to development dependencies, so installing the encoder no longer installs mocha. I pinned bitcoinjs-lib to an exact version. I also removed the separate ",[43,101,102],{},"triveasset-errors"," package I had opened on the same Saturday as the protocol, replacing its error classes with plain errors whose messages say what is missing.",[61,105,106,109,110,113],{},[64,107,108],{},"The logic in one place."," ",[43,111,112],{},"getAssetsOutputs",", which works out which outputs of a transaction hold which assets, moved into the protocol beside the encoders, with its own test file.",[32,115,117],{"id":116},"where-it-stands","Where it stands",[11,119,120],{},"At the end of the month the suite is thin. The issuance-flag tests and part of the asset ID tests run. Most of the older test files are still commented out, and bringing them back one encoder at a time is the next piece of work. The coverage badge says so plainly, and I would rather it did than show a number nobody can trust.",[32,122,124],{"id":123},"what-open-source-commits-a-maintainer-to","What open source commits a maintainer to",[11,126,127],{},"Publishing code is cheap. What it commits a maintainer to is less obvious:",[58,129,130,136,142,148],{},[61,131,132,135],{},[64,133,134],{},"Old transactions must keep decoding."," Any change to an encoder still has to read every byte already on the chain. Tests are how that promise gets checked, which is why they matter more in a protocol library than in an application.",[61,137,138,141],{},[64,139,140],{},"Stated support means tested support."," Saying Node.js 8 to 12 means running on 8 to 12, and a CI matrix is the cheapest way to keep that promise.",[61,143,144,147],{},[64,145,146],{},"A public build."," A failing build is visible to anyone who opens the repository. That is uncomfortable, and useful.",[61,149,150,153],{},[64,151,152],{},"Fewer dependencies."," Every package a library pulls in becomes part of its users' install. Each one removed is one less thing for them to trust.",[11,155,156],{},"None of this needs anyone else to have read the code yet. It is the work that makes reading it worthwhile, and it is easier to do in the first week than after other people have started building on the library.",[11,158,159,160,165],{},"The state at the end of March is in the ",[15,161,164],{"href":162,"rel":163},"https:\u002F\u002Fgithub.com\u002Ftrivechain\u002Ftriveasset-protocol\u002Ftree\u002F11c59ba49de7e7efd2acebb77e605f6ff4ee1629",[19],"repository at its 29 March commit",".",{"title":167,"searchDepth":168,"depth":168,"links":169},"",2,[170,171,172,173],{"id":34,"depth":168,"text":35},{"id":52,"depth":168,"text":53},{"id":116,"depth":168,"text":117},{"id":123,"depth":168,"text":124},"Architecture",null,"\u002Fimg\u002Fblog-covers\u002F2020-03-21-open-sourcing-the-triveasset-protocol.webp","An open white box showing gears inside, with a short conveyor carrying blue tiles into it.","2020-03-21","Why the encoders behind TriveAsset were the part of Trivechain to open first, and what a week of test structure, CI, coverage and linting added after the first commit.","md",false,{},true,"\u002Fblog\u002F2020-03-21-open-sourcing-the-triveasset-protocol",{"title":5,"description":179},"blog\u002F2020-03-21-open-sourcing-the-triveasset-protocol","2020","2026-11-07","04GUrrfhTsKgfdyHqcbCUC5p-iS26LPacp6CZbT5WLM",1794838285869]