forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
MNT Part 1: feat(types): add QuarkChain MNT account and token types #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ping-ke
wants to merge
15
commits into
goshard/base
Choose a base branch
from
feature/mnt-core-types
base: goshard/base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
78c963e
feat(types): add QuarkChain MNT account and token types
ping-ke 6c2f0be
fix(mnt): carry MNT fields through slim account; drop rlpgen directive
ping-ke 756e577
core/types, qkc/common: move qkc token helpers & params: restore ethe…
ping-ke 7ef2bab
core/types: harden QKC account codec; drop duplicate Uint32
ping-ke 6f001bb
add test case
ping-ke 50d6f84
update
ping-ke 2d589f6
resolve comments
ping-ke 043cca5
Add balanceUpdateCount
ping-ke ac49215
update for review
ping-ke c693d01
add comment
ping-ke c110266
add comment and test case
ping-ke 4aee419
resolve comment
ping-ke c583ec1
resolve comments
ping-ke 9acfbca
change balanceUpdateCount to balanceUpdated
ping-ke 1b7dd7c
resolve comment
ping-ke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // Copyright 2026-2027, QuarkChain. | ||
|
|
||
| package types | ||
|
|
||
| import ( | ||
| "errors" | ||
| "io" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| qkccommon "github.com/ethereum/go-ethereum/qkc/common" | ||
| "github.com/ethereum/go-ethereum/rlp" | ||
| "github.com/holiman/uint256" | ||
| ) | ||
|
|
||
| // qkcAccountRLP is the wire struct for QuarkChain's 6-element account format: | ||
| // [Nonce, TokenBal(bytes), Root, CodeHash, FullShardKey(4B fixed), Optional]. | ||
| // TokenBal is stored as raw serialized bytes (matching pyquarkchain's `binary` type), | ||
| // so nil encodes as 0x80 (empty string), not 0xC0 (empty list). | ||
| type qkcAccountRLP struct { | ||
| Nonce uint64 | ||
| TokenBal []byte // SerializeToBytes output; nil = no balances | ||
| Root common.Hash | ||
| CodeHash []byte | ||
| FullShardKey qkccommon.Uint32 | ||
| Optional []byte | ||
| } | ||
|
|
||
| // tokenBalancesForEncoding combines the split QKC and MNT balances into the | ||
| // unified token table used by the wire format. | ||
| func (acct *StateAccount) tokenBalancesForEncoding() *qkccommon.TokenBalances { | ||
| merged := qkccommon.NewEmptyTokenBalances() | ||
| qkcIsZero := acct.Balance == nil || acct.Balance.IsZero() | ||
| if !qkcIsZero || acct.IsBalanceUpdated() { | ||
| merged.SetValue(acct.Balance, qkccommon.DefaultTokenID) | ||
| } | ||
| if acct.MntBalances != nil && acct.MntBalances.Len() > 0 { | ||
| for id, bal := range acct.MntBalances.GetBalanceMap() { | ||
| merged.SetValue(bal, id) | ||
| } | ||
| } | ||
| return merged | ||
| } | ||
|
|
||
| // EncodeRLP implements rlp.Encoder for StateAccount using QuarkChain's | ||
| // 6-element format. Root is always written as 32 bytes (no nil optimization). | ||
| func (acct *StateAccount) EncodeRLP(w io.Writer) error { | ||
| tokenBal, err := acct.tokenBalancesForEncoding().SerializeToBytes() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| qkc := &qkcAccountRLP{ | ||
| Nonce: acct.Nonce, | ||
| Root: acct.Root, | ||
| CodeHash: acct.CodeHash, | ||
| TokenBal: tokenBal, | ||
| FullShardKey: qkccommon.Uint32(acct.FullShardKey), | ||
| Optional: nil, | ||
| } | ||
| return rlp.Encode(w, qkc) | ||
| } | ||
|
|
||
| // DecodeRLP implements rlp.Decoder for StateAccount using QuarkChain's | ||
| // 6-element format. | ||
| func (acct *StateAccount) DecodeRLP(s *rlp.Stream) error { | ||
| raw, err := s.Raw() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| var qkc qkcAccountRLP | ||
| if err := rlp.DecodeBytes(raw, &qkc); err != nil { | ||
| return err | ||
| } | ||
| acct.Nonce = qkc.Nonce | ||
| acct.CodeHash = qkc.CodeHash | ||
| acct.Root = qkc.Root | ||
| acct.FullShardKey = uint32(qkc.FullShardKey) | ||
| if len(qkc.Optional) != 0 { | ||
| return errors.New("unsupported non-empty QuarkChain account optional field") | ||
| } | ||
| acct.Balance = new(uint256.Int) | ||
| acct.MntBalances = nil | ||
| acct.balanceUpdateCount = 0 | ||
| if len(qkc.TokenBal) > 0 { | ||
| tb, err := qkccommon.NewTokenBalances(qkc.TokenBal) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| balMap := tb.GetBalanceMap() | ||
| qkcBal, hasQKC := balMap[qkccommon.DefaultTokenID] | ||
| if hasQKC { | ||
| acct.Balance.Set(qkcBal) | ||
| delete(balMap, qkccommon.DefaultTokenID) | ||
| } | ||
| if len(balMap) != 0 { | ||
| acct.MntBalances = qkccommon.NewTokenBalancesWithMap(balMap) | ||
| } | ||
| } | ||
| return nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.