|
| 1 | +--- |
| 2 | +description: Casper Network Unity SDK - Project knowledge and conventions |
| 3 | +--- |
| 4 | + |
| 5 | +# Casper Network Unity SDK - Project Guide |
| 6 | + |
| 7 | +## ⚠️ IMPORTANT: Keep This Document Updated |
| 8 | +After making significant changes to the project structure, deployment process, or conventions, UPDATE THIS FILE to reflect the changes. This ensures future conversations have accurate context. |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +## Project Structure |
| 13 | + |
| 14 | +``` |
| 15 | +Assets/CasperSDK/ |
| 16 | +├── Editor/ # Editor tools (DemoSceneCreator - internal only) |
| 17 | +├── Runtime/ # Main SDK code |
| 18 | +│ ├── Core/ # Configuration, interfaces |
| 19 | +│ ├── Models/ # Data models (KeyPair, CLValue, Deploy) |
| 20 | +│ ├── Network/ # RPC client, network communication |
| 21 | +│ ├── Services/ # Account, Transfer, Deploy services |
| 22 | +│ └── Utilities/ # Cryptography, helpers |
| 23 | +├── Plugins/ # External DLLs (BouncyCastle) |
| 24 | +├── Samples/ # Demo scenes (becomes Samples~ in UPM) |
| 25 | +│ └── CasperWalletDemo/ |
| 26 | +│ ├── Editor/ # Custom inspectors |
| 27 | +│ └── *.cs, *.unity |
| 28 | +├── Tests/ # Unit tests (excluded from UPM) |
| 29 | +└── package.json # UPM package manifest |
| 30 | +``` |
| 31 | + |
| 32 | +--- |
| 33 | + |
| 34 | +## UPM Package Distribution |
| 35 | + |
| 36 | +### Repositories |
| 37 | +- **Source**: `github.com/SamDreamsMaker/Casper-Network-Unity-SDK` |
| 38 | +- **UPM Package**: `github.com/SamDreamsMaker/com.caspernetwork.sdk` |
| 39 | + |
| 40 | +### How It Works |
| 41 | +1. Push to `main` branch triggers `.github/workflows/publish-upm.yml` |
| 42 | +2. Workflow copies `Assets/CasperSDK/*` to UPM repo |
| 43 | +3. **Excludes**: Tests/, DemoSceneCreator.cs |
| 44 | +4. **Renames**: Samples/ → Samples~ (UPM convention) |
| 45 | +5. Force-pushes with tag v{version} from package.json |
| 46 | + |
| 47 | +### Triggering Deployment |
| 48 | +Workflow triggers on changes to: |
| 49 | +- `Assets/CasperSDK/**` |
| 50 | +- `.github/workflows/publish-upm.yml` |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +## Key Conventions |
| 55 | + |
| 56 | +### Samples Structure |
| 57 | +- Keep `Samples/` (visible in dev) - workflow renames to `Samples~` on deploy |
| 58 | +- Sample scripts in `Samples/CasperWalletDemo/` |
| 59 | +- Sample editor scripts in `Samples/CasperWalletDemo/Editor/` |
| 60 | + |
| 61 | +### Things Excluded from UPM Package |
| 62 | +- `Tests/` - Unit tests not needed by end users |
| 63 | +- `DemoSceneCreator.cs` - Internal dev tool, causes errors if samples not imported |
| 64 | + |
| 65 | +### Custom Editors |
| 66 | +- Use `[CustomEditor]` for better Inspector UX |
| 67 | +- Example: `CasperWalletDemoControllerEditor.cs` shows "Create Network Config" button |
| 68 | + |
| 69 | +### Cross-Platform Compatibility |
| 70 | +- Use reflection to detect optional packages (Input System, URP) |
| 71 | +- Example: `Type.GetType("UnityEngine.InputSystem.UI.InputSystemUIInputModule, Unity.InputSystem")` |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## Common Tasks |
| 76 | + |
| 77 | +### Regenerate Demo Scene |
| 78 | +1. Open Unity in source project (not the package) |
| 79 | +2. Window → Casper SDK → Create Demo Scene |
| 80 | +3. Commit the updated .unity file |
| 81 | + |
| 82 | +### Test Package Import |
| 83 | +1. Clear Unity cache: `%LOCALAPPDATA%\Unity\cache\packages` |
| 84 | +2. Create new Unity project |
| 85 | +3. Package Manager → Add from Git URL |
| 86 | +4. Enter: `https://github.com/SamDreamsMaker/com.caspernetwork.sdk.git` |
| 87 | + |
| 88 | +### Update Version |
| 89 | +1. Edit `Assets/CasperSDK/package.json` → `version` field |
| 90 | +2. Commit and push to main |
| 91 | +3. Workflow auto-creates new tag |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## Casper Blockchain Specifics |
| 96 | + |
| 97 | +### Key Formats |
| 98 | +- **ED25519**: `01` + 32 bytes (64 hex + 2 prefix = 66 chars) |
| 99 | +- **SECP256K1**: `02` + 33 bytes compressed point (66 hex + 2 prefix = 68 chars) |
| 100 | + |
| 101 | +### Deploy Serialization |
| 102 | +- Binary serialization for hashes (body hash, deploy hash) |
| 103 | +- JSON-RPC format for API calls (CLType as objects for complex types) |
| 104 | + |
| 105 | +### Networks |
| 106 | +- **Testnet**: chain_name = "casper-test" |
| 107 | +- **Mainnet**: chain_name = "casper" |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +## Troubleshooting |
| 112 | + |
| 113 | +### "no such addressable entity" Error |
| 114 | +- Account hasn't received any funds yet |
| 115 | +- Use faucet (testnet) or transfer from existing account |
| 116 | + |
| 117 | +### Package Cache Issues |
| 118 | +- Delete `%LOCALAPPDATA%\Unity\cache\packages` |
| 119 | +- Restart Unity |
| 120 | + |
| 121 | +### Workflow Not Triggering |
| 122 | +- Check if changed files are in trigger paths |
| 123 | +- Verify GitHub Actions secret `UPM_DEPLOY_TOKEN` is valid |
0 commit comments