Skip to content

feat(nano): implement contract accessor#1382

Merged
glevco merged 2 commits intomasterfrom
feat/nano/contract-accessor
Aug 29, 2025
Merged

feat(nano): implement contract accessor#1382
glevco merged 2 commits intomasterfrom
feat/nano/contract-accessor

Conversation

@glevco
Copy link
Contributor

@glevco glevco commented Aug 23, 2025

Motivation

Implement a new API for interacting with contracts. For now, it just supports interacting with view and public methods from other contracts.

# Before
self.syscall.call_public_method(other_id, ‘my_public_method’, [action1, action2], a=abc’)

# After
self.syscall.get_contract(other_id) \
    .prepare_public_call(action1, action2) \
    .my_public_method(a=abc’)

Acceptance Criteria

  • Add HATHOR_TOKEN_UID constant to allowed imports on blueprints.
  • Implement get_contract syscall to be used in blueprint methods. It returns a ContractAccessor instance which is a wrapper for a contract and a runner, allowing blueprints to call methods of other contracts directly on that instance, instead of using manual syscalls.
    • All existing runner protections are still in place. This is just a new layer of abstraction on top of syscalls.
  • Update the test_types_across_contracts.py test to use the new API, as a demo.

Unresolved Discussions

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged

@glevco glevco self-assigned this Aug 23, 2025
@glevco glevco moved this from Todo to In Progress (WIP) in Hathor Network Aug 23, 2025
@glevco glevco force-pushed the feat/nano/contract-accessor branch from 0485558 to 1f8766e Compare August 23, 2025 01:01
@github-actions
Copy link

github-actions bot commented Aug 23, 2025

🐰 Bencher Report

Branchfeat/nano/contract-accessor
Testbedubuntu-22.04

🚨 1 Alert

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
sync-v2 (up to 20000 blocks)Latency
minutes (m)
📈 plot
🚷 threshold
🚨 alert (🔔)
2.16 m
(+28.89%)Baseline: 1.68 m
2.01 m
(107.41%)

Click to view all benchmark results
BenchmarkLatencyBenchmark Result
minutes (m)
(Result Δ%)
Lower Boundary
minutes (m)
(Limit %)
Upper Boundary
minutes (m)
(Limit %)
sync-v2 (up to 20000 blocks)📈 view plot
🚷 view threshold
🚨 view alert (🔔)
2.16 m
(+28.89%)Baseline: 1.68 m
1.51 m
(69.83%)
2.01 m
(107.41%)

🐰 View full continuous benchmarking report in Bencher

@codecov
Copy link

codecov bot commented Aug 23, 2025

Codecov Report

❌ Patch coverage is 99.20635% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.83%. Comparing base (482fec5) to head (be586f6).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
hathor/nanocontracts/runner/runner.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1382      +/-   ##
==========================================
+ Coverage   85.81%   85.83%   +0.02%     
==========================================
  Files         429      430       +1     
  Lines       32453    32570     +117     
  Branches     5057     5072      +15     
==========================================
+ Hits        27850    27957     +107     
- Misses       3586     3593       +7     
- Partials     1017     1020       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@glevco glevco force-pushed the feat/nano/contract-accessor branch 10 times, most recently from d15184b to f16cad4 Compare August 25, 2025 15:56
@glevco glevco moved this from In Progress (WIP) to In Progress (Done) in Hathor Network Aug 25, 2025
@github-project-automation github-project-automation bot moved this from In Progress (Done) to In Review (WIP) in Hathor Network Aug 25, 2025
@glevco glevco force-pushed the feat/nano/contract-accessor branch 2 times, most recently from 5d7e920 to c018c90 Compare August 25, 2025 17:14
@glevco glevco force-pushed the feat/nano/contract-accessor branch from c018c90 to c02679a Compare August 25, 2025 21:53
jansegre
jansegre previously approved these changes Aug 25, 2025
Copy link
Member

@jansegre jansegre left a comment

Choose a reason for hiding this comment

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

I really like the API. I don't really like the prepare_view_call and prepare_public_call names, maybe they are too long. But I don't have a better suggestion. I'm OK with going with those for now.

msbrogli
msbrogli previously approved these changes Aug 26, 2025
@glevco glevco moved this from In Review (WIP) to In Review (Done) in Hathor Network Aug 26, 2025
@glevco glevco dismissed stale reviews from msbrogli and jansegre via ba2ee51 August 26, 2025 15:23
@glevco glevco force-pushed the feat/nano/contract-accessor branch from c02679a to ba2ee51 Compare August 26, 2025 15:23
@glevco glevco moved this from In Review (Done) to In Review (WIP) in Hathor Network Aug 26, 2025
msbrogli
msbrogli previously approved these changes Aug 27, 2025
@glevco glevco force-pushed the feat/nano/contract-accessor branch from 2960f81 to 6166f29 Compare August 29, 2025 19:41
@glevco glevco moved this from In Review (WIP) to In Review (Done) in Hathor Network Aug 29, 2025
@github-project-automation github-project-automation bot moved this from In Review (Done) to In Review (WIP) in Hathor Network Aug 29, 2025
@glevco glevco merged commit ee93952 into master Aug 29, 2025
7 of 8 checks passed
@glevco glevco deleted the feat/nano/contract-accessor branch August 29, 2025 21:28
@github-project-automation github-project-automation bot moved this from In Review (WIP) to Waiting to be deployed in Hathor Network Aug 29, 2025
@jansegre jansegre mentioned this pull request Sep 11, 2025
2 tasks
@jansegre jansegre moved this from Waiting to be deployed to Done in Hathor Network Sep 18, 2025
@jansegre jansegre mentioned this pull request Sep 24, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants