|
| 1 | +--- |
| 2 | +description: "Investigate nano contract architecture, blueprints, runner execution, storage layer, actions, and inter-contract calls" |
| 3 | +--- |
| 4 | + |
| 5 | +# Nano Contract Architecture |
| 6 | + |
| 7 | +When the user asks about nano contracts, blueprints, runner, storage, or actions, follow these steps: |
| 8 | + |
| 9 | +## Step 1: Understand the blueprint system |
| 10 | +- `hathor/nanocontracts/` — main nano contracts package |
| 11 | +- Blueprints are contract templates that define methods, fields, and behavior |
| 12 | +- Look for blueprint base class and how blueprints are registered |
| 13 | + |
| 14 | +## Step 2: Read the runner |
| 15 | +- `hathor/nanocontracts/runner/runner.py` — `Runner` executes contract methods |
| 16 | +- Understand the execution model: method dispatch, argument parsing, context injection |
| 17 | +- Check how the runner manages contract state during execution |
| 18 | + |
| 19 | +## Step 3: Read the execution layer |
| 20 | +- `hathor/nanocontracts/execution/` — block-level execution orchestration |
| 21 | +- `hathor/nanocontracts/execution/block_executor.py` — executes NC txs within a block |
| 22 | +- Understand ordering, dependency resolution, and rollback on failure |
| 23 | + |
| 24 | +## Step 4: Understand storage |
| 25 | +- `hathor/nanocontracts/storage/` — contract storage layer |
| 26 | +- How contract fields/state are persisted and retrieved |
| 27 | +- Storage key formats, serialization, and caching |
| 28 | + |
| 29 | +## Step 5: Understand actions |
| 30 | +Actions represent token movements in NC transactions: |
| 31 | +- **Deposit** — tokens flow TO the contract (appears on output side) |
| 32 | +- **Withdrawal** — tokens flow FROM the contract (appears on input side) |
| 33 | +- **Grant/Acquire** — authority token operations |
| 34 | +- Check `hathor/transaction/headers/nano_header.py` for the NanoHeader structure |
| 35 | + |
| 36 | +## Step 6: Check inter-contract calls |
| 37 | +- If the user asks about contracts calling other contracts, look for call/invoke mechanisms in the runner |
| 38 | +- Check for context propagation and reentrancy protections |
| 39 | + |
| 40 | +## Step 7: Explain |
| 41 | +Present the architecture, execution flow, or specific mechanism relevant to the user's question. |
0 commit comments