Skip to content

add example contract#130

Open
SIDDHANTCOOKIE wants to merge 1 commit into
mainfrom
feat/example-composite-keys
Open

add example contract#130
SIDDHANTCOOKIE wants to merge 1 commit into
mainfrom
feat/example-composite-keys

Conversation

@SIDDHANTCOOKIE

@SIDDHANTCOOKIE SIDDHANTCOOKIE commented Jul 13, 2026

Copy link
Copy Markdown
Member

Addressed Issues:

Fixes #(TODO:issue number)

Screenshots/Recordings:

TODO: If applicable, add screenshots or recordings that demonstrate the interface before and after the changes.

Additional Notes:

AI Usage Disclosure:

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: TODO

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

  • New Features
    • Added a complete user profile storage example.
    • Demonstrates grouped and composite approaches for storing and updating profile data.
    • Includes commands for setting profiles and updating ages without overwriting unrelated data.
    • Validates input formats, missing profiles, and unsupported commands with clear errors.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds examples/user_profile.py, demonstrating grouped dictionary storage and composite-key storage for setting and updating user profile fields with command validation.

Changes

User profile storage example

Layer / File(s) Summary
Command parsing and input setup
examples/user_profile.py
Documents supported commands and extracts payload and sender from msg.
Grouped profile storage
examples/user_profile.py
Stores profiles under storage[sender] and updates age by rewriting the complete profile dictionary.
Composite profile storage and validation
examples/user_profile.py
Stores age and name under separate namespaced keys, updates only age, and rejects unknown commands.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: Python Lang

Poem

A bunny stores names, ages bright,
In grouped hops or keys set right.
No field gets lost, no slots collide,
Age updates safely side by side.
“Command the carrots!” the rabbit cried.

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is related to the change, but it is too generic to convey the main update clearly. Rename it to describe the example more specifically, e.g. adding a user profile storage example with composite keys.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/example-composite-keys

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
minichain
   block.py881484%11, 15, 18–24, 73, 160, 165, 174, 176
   chain.py1673380%16, 21, 27, 31, 34, 38, 62–67, 74–75, 105–108, 141, 154–157, 167–168, 177–178, 181–182, 186–187, 224, 236–237
   contract.py1267342%11–12, 15–20, 36–80, 115, 123, 175–178, 186–201, 209–210, 212–213, 218–219, 221–222, 224–225, 227–228
   mempool.py591476%15–16, 30–32, 37–38, 40–41, 47, 50–51, 58–60
   mpt.py14379%18–20
   p2p.py26719627%27–28, 76, 79, 82, 85, 88–95, 98–99, 102–103, 108, 123, 126, 129–131, 134–136, 139, 142, 145, 149–150, 160–162, 173–187, 194–200, 209–263, 268–378
   persistence.py1713977%84, 90, 92, 133, 143–144, 223–224, 244, 247–248, 270, 282–293, 296–297, 303–307, 310–313, 316–320
   pow.py391464%26, 34, 44–46, 50–52, 62, 67–71
   rpc.py792371%41–42, 45, 61, 64, 68, 73–76, 78–88, 93–95
   state.py1352482%29, 48–49, 93, 105, 189–204, 225–228, 231–236
   validators.py9189%13
TOTAL124443465% 

Tests Skipped Failures Errors Time
74 0 💤 7 ❌ 0 🔥 22.372s ⏱️

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/user_profile.py`:
- Around line 32-38: Update the payload parsing for both set_grouped and the
other set command around their respective split calls to use a maximum of two
delimiters, preserving any remaining colons in the name field. Keep the existing
three-part validation and age/name assignment behavior unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 376f7e85-d5ef-4b10-8541-36df8f9fa132

📥 Commits

Reviewing files that changed from the base of the PR and between 187eb71 and cd72d68.

📒 Files selected for processing (1)
  • examples/user_profile.py

Comment thread examples/user_profile.py
Comment on lines +32 to +38
if payload.startswith('set_grouped:'):
parts = payload.split(':')
if len(parts) != 3:
raise Exception("Invalid format. Use set_grouped:<age>:<name>")

age = int(parts[1])
name = parts[2]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Names containing colons are rejected by the parser.

payload.split(':') without a maxsplit limit produces more than 3 parts when the name itself contains a colon (e.g., set_grouped:25:John:Doe → 4 parts → "Invalid format"). Since <name> is the last field, use split(':', 2) so the name captures any remaining colons.

🐛 Proposed fix for both set commands
 if payload.startswith('set_grouped:'):
-    parts = payload.split(':')
+    parts = payload.split(':', 2)
     if len(parts) != 3:
 elif payload.startswith('set_composite:'):
-    parts = payload.split(':')
+    parts = payload.split(':', 2)
     if len(parts) != 3:

Also applies to: 69-75

🧰 Tools
🪛 Ruff (0.15.21)

[warning] 35-35: Create your own exception

(TRY002)


[warning] 35-35: Avoid specifying long messages outside the exception class

(TRY003)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/user_profile.py` around lines 32 - 38, Update the payload parsing
for both set_grouped and the other set command around their respective split
calls to use a maximum of two delimiters, preserving any remaining colons in the
name field. Keep the existing three-part validation and age/name assignment
behavior unchanged.

Comment thread examples/user_profile.py

new_age = int(parts[1])

# Notice the inefficiency here: we must load the entire dict,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not loading the entire dict. We are loading the entire profile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants