3 - Create Coin Module
Organization
All CoinModules are located in libs/coin-modules.
A CoinModule has the following directories/modules:
api(optional): interface for exposing the CoinModule to a backend service (cf. (TODO))bridge: implementation of Bridges interface (cf. Bridge)logic: contains all core logic of the blockchain. The code here is agnostic of all external interface (i.e. Bridge or Api) and relies only on external libs andnetworkdirectorynetwork: communication logic with explorer/index/node (cf. How to wrap you api)signer: defines the interface definition to the Embedded App and the logic to retrieve derive address
Here is a typical family folder structure (TS integration):
./libs
├── coin-modules/coin-mycoin/src
│ ├── api
│ │ └── index.ts
│ ├── bridge
│ │ ├── broadcast.ts
│ │ ├── buildTransaction.ts
│ │ ├── createTransaction.ts
│ │ ├── estimateMaxSpendable.ts
│ │ ├── formatters.ts
│ │ ├── getFeesForTransaction.ts
│ │ ├── getTransactionStatus.ts
│ │ ├── prepareTransaction.ts
│ │ ├── signOperation.ts
│ │ ├── synchronization.ts
│ │ └── index.ts
│ ├── logic
│ │ ├── broadcast.ts
│ │ ├── craftTransaction.ts
│ │ ├── estimateFees.ts
│ │ ├── getBalance.ts
│ │ ├── lastBlock.ts
│ │ ├── listOperations.ts
│ │ ├── signTransaction.ts
│ │ └── index.ts
│ ├── network
│ │ ├── explorer.ts
│ │ └── index.ts
│ ├── signer
│ │ ├── getAddress.ts
│ │ └── index.ts
│ ├── test
│ │ ├── bot-deviceActions.ts
│ │ ├── bot-specs.ts
│ │ ├── bridgeDatasetTest.ts
│ │ ├── cli.ts
│ │ └── index.ts
│ ├── types
│ │ ├── bridge.ts
│ │ ├── errors.ts
│ │ ├── model.ts
│ │ ├── signer.ts
│ │ └── index.ts
│ ├── config.ts
│ └── index.ts
├── ledger-live-common/src/families/mycoin
│ ├── bridge.integration.test.ts
│ ├── config.ts
│ ├── logic.ts
│ ├── react.ts
│ ├── setup.ts
│ ├── types.ts
│ └── walletApiAdapter.ts
└── ledgerjs/packages/hw-app-mycoin/src
│ ├── MyCoin.ts
│ └── index.tsSome architectural decision
For consistency among all the CoinModule, please consider the following principles:
- Always use an
index.tsfile in each directory. The goal is to “control” what is exposed from the module and allow to be used from outside. - The
index.tsin the root of the CoinModule should only expose:- Bridge interface
- Bridge type
- bot test
- …
- Inside CoinModule, the dependency between module is only one direction (avoid cyclic dependency or mutual ones). Example: From the
logicmodule, it is forbidden to use some functions declared inbridge.
…
The following steps (3-A to 3-D), your work will have some impact on the Ledger Wallet repository.
Therefore, make sure you have setup your environment to work with ledger-live.