How iosh/cive works
Main Components
• Client Libraries: Represented under the directories “src/clients” and “src/clients/transports”. This component handles creation of public and wallet clients and managing the underlying network transports (HTTP, WebSocket, custom, and fallback).
• Blockchain Actions: Located under “src/actions” with submodules for public actions (e.g., “call”, “getBalance”, “getBlock”, etc.) and wallet actions (e.g., “sendTransaction”, “signMessage”, “writeContract”, etc.). These actions encapsulate the interactions with the blockchain.
• Accounts Module: Found in “src/accounts”, this component provides functionalities such as deriving accounts from mnemonic, private key conversions, cryptographic signing, and message verification.
• Chain Definitions: Located under “src/chains/definitions” (e.g., localhost, mainnet, testnet). These definitions configure the blockchain network details.
• Utilities, Formatters, and Helpers: Spread across “src/utils”, “src/utils/abi”, “src/utils/address”, etc. They offer low-level operations for ABI encoding/decoding, address formatting, error handling, and transaction serialization.
• Types and Error Handling: Under “src/types” and “src/errors”, this part defines the common types (ABI specifications, contract types, transaction types, etc.) and standardized error objects for robust error handling.
• Documentation and Examples: Although separate from the core runtime, the “site” and “examples” directories provide real-world usage examples and documentation that reinforces the intended interactions between components.
Relationships and Interactions
• Blockchain Actions serve as the API layer that abstracts the complex interactions. They use:
– The Accounts Module for cryptographic signing and account-related operations.
– The Chain Definitions for network-specific operations.
– The underlying Client libraries when executing transactions or contract interactions.
• Utilities and Formatters support all these components by ensuring proper data conversion, error handling, and logging.
• Types and Errors are cross-cutting concerns that inform the design and data flow throughout the system.
Architectural Patterns / Design Principles
• Modular Design: Each major functionality (clients, accounts, actions, chains, etc.) is encapsulated in its own module, enabling separation of concerns.
• Layered Abstraction: At the base, low-level transports and utilities build up to higher-level blockchain interactions and client APIs.
• Extensibility: The structure (directories like “src/clients/transports” and “src/actions”) is designed to easily add new transports or actions in the future.
• Test-Driven Development: With a dedicated “test” directory and extensive tests in each module (notice the *.test.ts files), emphasis is placed on reliability.