Skip to content

feat(nano): emit a token-creation event including for nano executions#1494

Merged
jansegre merged 1 commit intomasterfrom
feat/nano/emit-token-creation-event
Dec 3, 2025
Merged

feat(nano): emit a token-creation event including for nano executions#1494
jansegre merged 1 commit intomasterfrom
feat/nano/emit-token-creation-event

Conversation

@jansegre
Copy link
Member

@jansegre jansegre commented Nov 24, 2025

Motivation

Currently there is no way for a wallet observing events from the reliable integration to know when a token has been created from a nano execution.

Introduce two new events: TOKEN_CREATED and TOKEN_REMOVED (for reorgs).

Introduce a new event: TOKEN_CREATED. Removal can be inferred from metadata changes.

Acceptance Criteria

  • Emit TOKEN_CREATED for both TokenCreationTransactions and nano-contract executions, including token metadata and optional nc_exec_info.
  • Emit TOKEN_REMOVED only when a token-creation tx is voided, and for nano-created tokens when their execution is rolled back (reorg/un-execution).
  • EventArguments and event data models updated with explicit token fields; tests assert the emitted event payloads match expected metadata.

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

@jansegre jansegre self-assigned this Nov 24, 2025
@jansegre jansegre moved this from Todo to In Progress (WIP) in Hathor Network Nov 24, 2025
@github-actions
Copy link

github-actions bot commented Nov 24, 2025

🐰 Bencher Report

Branchfeat/nano/emit-token-creation-event
Testbedubuntu-22.04
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
1.69 m
(-2.18%)Baseline: 1.73 m
1.56 m
(92.01%)
2.08 m
(81.51%)
🐰 View full continuous benchmarking report in Bencher

@jansegre jansegre force-pushed the feat/nano/emit-token-creation-event branch from 9d293c8 to 51ac5df Compare November 25, 2025 19:21
@jansegre jansegre marked this pull request as ready for review November 25, 2025 19:28
@jansegre jansegre requested a review from msbrogli as a code owner November 25, 2025 19:28
@jansegre jansegre moved this from In Progress (WIP) to In Progress (Done) in Hathor Network Nov 25, 2025
@jansegre jansegre force-pushed the feat/nano/emit-token-creation-event branch from 51ac5df to f5b90d6 Compare November 25, 2025 20:10
@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

❌ Patch coverage is 97.36842% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.20%. Comparing base (c5509ce) to head (de5fc73).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
hathor/event/event_manager.py 94.59% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1494      +/-   ##
==========================================
+ Coverage   86.15%   86.20%   +0.04%     
==========================================
  Files         440      440              
  Lines       33993    34055      +62     
  Branches     5315     5326      +11     
==========================================
+ Hits        29288    29358      +70     
+ Misses       3677     3673       -4     
+ Partials     1028     1024       -4     

☔ 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.

msbrogli
msbrogli previously approved these changes Nov 25, 2025
"""Calculate the amount minted by a token-creation transaction."""
assert tx.hash is not None
total = 0
for tx_output in tx.outputs:
Copy link
Member

Choose a reason for hiding this comment

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

Since it can have a NanoHeader, what about deposits, transferring token authority to the contract and internal minting?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could those affect the initial amount when a token is created?

Copy link
Member Author

Choose a reason for hiding this comment

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

I assumed they couldn't, and tracking changes to the token is outside of the scope of this event.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could those affect the initial amount when a token is created?

I believe only deposits could, because the initial amount could be partially (or totally) moved to deposits, so the outputs would not reflect the total initial amount.

So you do have to consider deposits in your calculation, but I don't see how any of the other features could impact it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe only deposits could, because the initial amount could be partially (or totally) moved to deposits, so the outputs would not reflect the total initial amount.

Wouldn't that be considered 2 different operations in a single transactions, that is:

  1. token is created with "initial amount"
  2. some of that amount is moved to deposits

Or did I get that wrong? @glevco

Copy link
Member Author

Choose a reason for hiding this comment

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

After a call with @glevco the conclusion is that this case is impossible in a TokenCreateTransaction. Does that make sense? @msbrogli

Copy link
Member

@msbrogli msbrogli Dec 3, 2025

Choose a reason for hiding this comment

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

TokenCreationTransaction is not a multi-token transaction and index 1 always refers to the token being created. So, it might be possible to create and deposit in a contract. Not sure if our implementation supports it, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add an issue to investigate this later. The worst that could happen is undercounting the supply of a token when it was created, but that undercount would not affect the consensus, only informative APIs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, for now I've removed the initial_amount, since the wallet-service doesn't need it.

Copy link
Member Author

@jansegre jansegre Dec 3, 2025

Choose a reason for hiding this comment

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

Issue created: #1503

@jansegre jansegre moved this from In Progress (Done) to In Review (Done) in Hathor Network Nov 26, 2025
@jansegre jansegre force-pushed the feat/nano/emit-token-creation-event branch 3 times, most recently from 36f8640 to 1a93d57 Compare November 27, 2025 22:56
"""Calculate the amount minted by a token-creation transaction."""
assert tx.hash is not None
total = 0
for tx_output in tx.outputs:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could those affect the initial amount when a token is created?

I believe only deposits could, because the initial amount could be partially (or totally) moved to deposits, so the outputs would not reflect the total initial amount.

So you do have to consider deposits in your calculation, but I don't see how any of the other features could impact it.

@github-project-automation github-project-automation bot moved this from In Review (Done) to In Review (WIP) in Hathor Network Nov 28, 2025
@jansegre jansegre force-pushed the feat/nano/emit-token-creation-event branch 2 times, most recently from cb0db80 to 84664c8 Compare December 1, 2025 21:48
@jansegre jansegre mentioned this pull request Dec 2, 2025
2 tasks
@jansegre jansegre force-pushed the feat/nano/emit-token-creation-event branch 2 times, most recently from 95d3445 to 9d55f32 Compare December 2, 2025 17:21
@jansegre jansegre force-pushed the feat/nano/emit-token-creation-event branch from 9d55f32 to 9ec97f0 Compare December 3, 2025 15:24
@jansegre jansegre requested review from glevco and msbrogli December 3, 2025 15:31
msbrogli
msbrogli previously approved these changes Dec 3, 2025
tx.storage.indexes.handle_contract_execution(tx)

# Pubsub event to indicate execution success
self.context.pubsub.publish(HathorEvents.NC_EXEC_SUCCESS, tx=tx)
Copy link
Member

Choose a reason for hiding this comment

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

Don't we emit all events after the consensus is executed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. That's a simple change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@jansegre jansegre force-pushed the feat/nano/emit-token-creation-event branch from 9ec97f0 to ca7b2d3 Compare December 3, 2025 19:04
@jansegre jansegre force-pushed the feat/nano/emit-token-creation-event branch from ca7b2d3 to de5fc73 Compare December 3, 2025 19:59
@jansegre jansegre merged commit a134513 into master Dec 3, 2025
13 of 14 checks passed
@jansegre jansegre deleted the feat/nano/emit-token-creation-event branch December 3, 2025 20:41
@github-project-automation github-project-automation bot moved this from In Review (WIP) to Waiting to be deployed in Hathor Network Dec 3, 2025
@jansegre jansegre mentioned this pull request Dec 3, 2025
2 tasks
@jansegre jansegre moved this from Waiting to be deployed to Done in Hathor Network Dec 4, 2025
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