# Nervos Notes To date, there is functionality (pre 0.0.6) for the offchain module, nervos interactions (not integration tested), and partial functionality on the ADA chain. Remaining tasks are: - Update the offchain modules to the latest standard in the force bridge - Support multisig transactions in cardano, cardano side of the burn transactions - Detect new transactions on the cardano side, and write to the DB for further monitoring - Perform integration tests with the nervos functionality # Existing code structure The interactions we should deal with in the cardano code are in 3 chunks: - The cardano integration - Nervos integration - Offchain processing There are 2 supported user flows in question: 1. User locks ADA, and a SUDT asset is minted on the nervos chain 2. User burns SUDT at the force bridge, and ADA is unlocked on the cardano chain Thre are integration tests in `offchain-modules/packages/scripts/src/integration-test/ada.ts` to cover parts of these flows. You can run it with: `yarn ada-test` # Getting Started - Clone cardano branch of norestlabs/force-bridge - Copy working configs for (`config.json` and `config-cli.json`) to the `offchain-modules` directory. These should reflect assets and the network you have setup. - Start docker images for cardano-wallet, cardano-node, cardano-graphql, cardano-db-sync-extended - Run `make docker-start` in the base directory. This will start the required docker images for nervos - Run `cd offchain-modules && yarn --frozen-lockfile && yarn build` to build - Run `yarn ada-test` to run the cardano integration test # Code Overview The offchain modules serve as a store for the state of pending transactions. When detected in the force bridge, they should be stored locally. Our DB models for them can be found at: - `offchain-modules/packages/x/src/db/entity/AdaLock.ts` - `offchain-modules/packages/x/src/db/entity/AdaUnlock.ts` Chain handlers should watch for events, and update the db state when received: - `offchain-modules/packages/x/src/handlers/ada.ts` Right now, the ADA handler doesn't monitor the chain to do this, it monitors the status of an event that is already monitored. This function should be extended to monitor the chain for new events as well. When money is received on the cardano chain, a function (in `offchain-modules/packages/x/src/xchain/ada/scripts.ts`) sendLockTxs is invoked. In a similar manner, `sendUnlockTxs` should be invoked when transferring in the opposite direction. These functions currently are for transferring from a single wallet to another single wallet. These should be changed to a multisig process. In cardano, a multisig transaction is created by a single address first proposing the transaction. Then each of the other signers add their witness data. Finally, the transaction and all of the witness data can be submitted. To accomplish this, a SDK for cardano multisig should first be built. There is no JS SDK for multisig so far, but there are two possible solutions: 1 - Shell out to the cardano node, run the command and parse the result. This is less effort up front, but presents a bit of a headache in testing. 2 - Use the serialization library to call the commands to generate a multisig transaction. The set of commands to follow for multisig can be found here: https://github.com/input-output-hk/cardano-node/blob/master/doc/reference/simple-scripts.md#example-of-using-a-script-for-multi-signatures While this hasn't been implemented to a JS/typescript SDK yet, the two approaches for interacting with a cardano node can be seen below: An example of how to call via shell in another project is here: https://github.com/input-output-hk/cardano-rosetta/blob/master/cardano-rosetta-server/src/server/utils/cardano/cli/cardanonode-cli.ts An example of how to call via serialization library is here: https://github.com/Emurgo/cardano-serialization-lib