[DOCUMENTATION] Per-file Markdown Documentation
Describe the feature you'd like
All core source files in the Canopy project have a corresponding markdown documentation file that describes at a high level what can be found in the referenced source file.
Motivation
This is to create an intermediate documentation resource that exists between the gitbook documentation and inspecting the source code.
The primary goal is to help onboard developers by helping them efficiently browse Canopy's source code and come away with a general understanding of each file and the module as a whole.
Thoughts
- Each file could be short enough so that someone could conceivably read every one in a single sitting. For example, a committed developer sets aside two hours and comes away seeing a reasonably clear path to the realization of their vision through Canopy. Clear enough it generates the required excitement and confidence to start building.
- List of function signatures and their comments, grouped by the high level components/types in that file? This may belong in gitbook or godoc but it would also be helpful here as a quick reference to reinforce ideas when reading the text.
- If the file contains a component likely to be customized, perhaps provide a quick example or a brief discussion of the possibilities?
Possible implementation
See some LLM-generated examples in the comments below.
Required Tags
- Priority: Medium
- Module: Multi-Module
Package: fsm
File: account.go
Title: Account, Pool and Supply Management
OVERVIEW
This source code is responsible for managing accounts, pools, and supply tracking within a financial state machine.
Components
- Account: Represents a financial entity with an address and a corresponding amount.
- Pool: Represents a set of funds earmarked for a specific purpose within the state.
- Supply: Represents the total financial status, tracking amounts across accounts and pools.
Capabilities
- Accounts: Create, retrieve, update, and delete account records; manage balances; account fee deductions; and addition of tokens.
- Pools: Create, retrieve, update, and delete pool records; manage balance distributions; and token minting.
- Supply Tracking: Monitor the overall financial supply, including total, staked, and delegated amounts.
Function Signatures
Account Functions
-
GetAccount(address crypto.AddressI):
(*Account, lib.ErrorI)
Retrieves an account structure for a specific address. -
GetAccounts():
([]*Account, lib.ErrorI)
Returns all account structures in the state. -
GetAccountsPaginated(p lib.PageParams):
(*lib.Page, lib.ErrorI)
Returns a page of account structures in the state. -
GetAccountBalance(address crypto.AddressI):
(uint64, lib.ErrorI)
Returns the balance of an account at a specific address. -
SetAccount(account *Account):
lib.ErrorI
Upserts an account into the state. -
SetAccounts(accounts []*Account, supply *Supply):
lib.ErrorI
Upserts multiple accounts into the state. -
AccountDeductFees(address crypto.AddressI, fee uint64):
lib.ErrorI
Removes fees from an address and adds them to the reward pool. -
AccountAdd(address crypto.AddressI, amountToAdd uint64):
lib.ErrorI
Adds tokens to an account. -
AccountSub(address crypto.AddressI, amountToSub uint64):
lib.ErrorI
Removes tokens from an account.
Pool Functions
-
GetPool(id uint64):
(*Pool, lib.ErrorI)
Retrieves a pool structure for a specific ID. -
GetPools():
([]*Pool, lib.ErrorI)
Returns all pool structures in the state. -
GetPoolsPaginated(p lib.PageParams):
(*lib.Page, lib.ErrorI)
Returns a page of pool structures in the state. -
GetPoolBalance(id uint64):
(uint64, lib.ErrorI)
Returns the balance of a pool at an ID. -
SetPool(pool *Pool):
lib.ErrorI
Upserts a pool structure into the state. -
SetPools(pools []*Pool, supply *Supply):
lib.ErrorI
Upserts multiple pool structures into the state. -
MintToPool(id uint64, amount uint64):
lib.ErrorI
Adds newly created tokens to the pool structure. -
PoolAdd(id uint64, amountToAdd uint64):
lib.ErrorI
Adds tokens to the pool structure. -
PoolSub(id uint64, amountToSub uint64):
lib.ErrorI
Removes tokens from the pool structure.
Supply Functions
-
AddToTotalSupply(amount uint64):
lib.ErrorI
Adds to the total supply count. -
AddToStakedSupply(amount uint64):
lib.ErrorI
Adds to the staked supply count. -
AddToDelegateSupply(amount uint64):
lib.ErrorI
Adds to the delegated supply count. -
SubFromTotalSupply(amount uint64):
lib.ErrorI
Removes from the total supply count. -
SubFromStakedSupply(amount uint64):
lib.ErrorI
Removes from the staked supply count. -
SubFromDelegateSupply(amount uint64):
lib.ErrorI
Removes from the delegated supply count. -
GetSupply():
(*Supply, lib.ErrorI)
Returns the supply structure held in the state. -
SetSupply(supply *Supply):
lib.ErrorI
Upserts the supply structure into the state.
Canopy Network
Title: State Management for Accounts, Pools, and Supply in the Canopy FSM Module
Overview
This file is part of the finite state machine (FSM) module for the Canopy blockchain. It defines state interactions for managing accounts, pools, and the overall supply within the blockchain system. The functionality is vast, covering operations to query, update, and manage the balances of accounts and pools, in addition to modifying the total, staked, and delegated supplies. Below, we provide a detailed description of the core components of this file.
Core Components
Account Management
This component provides methods for the manipulation of the state. Key actions include:
-
Retrieving Account Information: Methods are available to get details of a specific account, either by its address or all existing accounts collectively. Pagination support helps manage large data sets.
-
Account Balance Operations: The state of an account's balance can be manipulated via methods that allow for adding or subtracting funds. These methods ensure the balance integrity, such as preventing subtraction that results in negative balances.
-
Account State Update: Facilities are in place to update or delete account records within the state. An account is removed from the state if its balance reaches zero, which aids in optimizing storage space.
Pool Management
Pools in Canopy act as owner-less funds designated for particular purposes. The component includes the following:
-
Retrieving Pool Information: Just like accounts, pool data can be fetched by using specific pool IDs or through bulk retrieval of all pool data with pagination support.
-
Pool Balance Operations: Methods exist to modify the balance of a pool by adding or subtracting funds. These operations ensure that pool balances reflect accurate financial states.
-
Pool State Update: Pool states can be updated or removed depending on the balance. This ensures that the state does not retain unnecessary pool data where the balance is zero.
Supply Management
This component handles the overall supply state of the blockchain, keeping track of the total supply of tokens as well as specific allocations for staking and delegation:
-
Total Supply Management: Allows for adjusting the total supply, either by adding newly minted tokens or subtracting tokens when necessary.
-
Staked and Delegated Supply Management: There are dedicated methods to manage supply counts that are particularly allocated for staked and delegated purposes. These methods ensure the blockchain can account for tokens that are either actively staked or set aside for delegation purposes.
-
Committee and Delegate Supply Tracking: Supply segregation based on chain IDs helps in managing supply pools. Operations are available to adjust and retrieve these pools, aiding in financial tracking specific to committees and delegates.
I understand that the examples provided are mostly LLM generated but I don't think we should add an explanation of each function individually bus focus more on what's the package about and what is supposed to do, if the user wants to see specific implementations then she can go to the code. Also by explaining functions it would require to check the markdown file each time a function is modified for whatever reason even if the intend of the package overall stays the same
Also by explaining functions it would require to check the markdown file each time a function
That's a good point on maintainability, but there is some decent content there prior to the function definitions - let's try to strike a balance