Skip to content

feat: tron returns staking/voting data for accounts#1467

Open
cranycrane wants to merge 16 commits intomasterfrom
1451-tron-freezing-governance-data
Open

feat: tron returns staking/voting data for accounts#1467
cranycrane wants to merge 16 commits intomasterfrom
1451-tron-freezing-governance-data

Conversation

@cranycrane
Copy link
Copy Markdown
Contributor

  • Implemented Tron staking/governance (TronStakingInfo) into TronAccountExtraData
  • Added necessary unit tests with (real) mocked responses from the HTTP API

@cranycrane cranycrane linked an issue Apr 10, 2026 that may be closed by this pull request
@cranycrane cranycrane self-assigned this Apr 10, 2026
@cranycrane cranycrane force-pushed the 1451-tron-freezing-governance-data branch from d387c8b to fd2ffd1 Compare April 15, 2026 11:27
@cranycrane cranycrane marked this pull request as ready for review April 15, 2026 12:34
}
}

func (b *TronRPC) SendRawTransaction(tx string, disableAlternativeRPC bool) (string, error) {
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.

this tronBuildStakingInfo method is huge and I don't see a unit test for it, it does many computations. So it should be unit tested perhaps ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it is already tested through GetAddressChainExtraData

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Tron staking/governance metadata to account-level chain extra data so API consumers and the UI can display staking balances, unstaking batches, votes, voting power, rewards, and delegated stake for Tron addresses.

Changes:

  • Extend Tron account chainExtraData with stakingInfo populated from /wallet/getaccountresource, /wallet/getaccount, and /wallet/getReward.
  • Render staking/governance details in the Tron address UI template.
  • Update generated TypeScript API types and expand unit/integration tests with mocked HTTP responses.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/dbtestdata/fakechain_tron.go Extends fake chain extra payload with stakingInfo for fixtures.
static/templates/address_chainextra_tron.html Adds UI section to render staking/voting/unstaking/reward/delegations.
server/tron_template.go Adds template data structs and parsing for staking amounts/unstaking batches.
server/tron_template_test.go Extends template unit test to assert parsed staking fields.
server/public_tron_test.go Updates HTTP/UI expected output and API responses to include stakingInfo.
docs/api-tron.md Documents stakingInfo schema for Tron account chain extra payload.
build/tools/typescriptify/typescriptify.go Includes TronAccountExtraData in TS generation inputs.
blockbook-api.ts Updates generated TS interfaces for Tron staking account data.
bchain/types_tron_chainextradata.go Moves/extends Tron chain/account extra data types; adds staking-related types.
bchain/types_chainextradata.go Removes Tron type definitions moved to dedicated Tron types file.
bchain/coins/tron/tronhttp_endpoints.go Implements concurrent fetching + normalization of staking info for accounts.
bchain/coins/tron/tronrpc_test.go Expands tests for new staking info behavior and failure/omission cases.
bchain/coins/tron/tronInternalDataProvider_test.go Enhances mock HTTP client to return responses/errors per-path and record calls.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bchain/coins/tron/tronInternalDataProvider_test.go
Comment thread bchain/coins/tron/tronhttp_endpoints.go
Comment thread bchain/coins/tron/tronhttp_endpoints.go Outdated
Comment thread docs/api-tron.md Outdated
Comment on lines +243 to +246
totalVotingPower := resourceResp.TronPowerLimit
if totalVotingPower < 0 {
totalVotingPower = 0
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
totalVotingPower := resourceResp.TronPowerLimit
if totalVotingPower < 0 {
totalVotingPower = 0
}
totalVotingPower := max(resourceResp.TronPowerLimit, 0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same can be applied to availableVotingPower, unclaimedReward, delegatedEnergy and delegatedBandwidth

@cranycrane cranycrane force-pushed the 1451-tron-freezing-governance-data branch from 0234903 to f2d6058 Compare April 30, 2026 11:42
pragmaxim added 3 commits May 3, 2026 08:39
…gInfo

big.Int.Add(x, y) stores the sum in the receiver and does not mutate
its operands, so the inner new(big.Int).Set(stakedBandwidth) copy was
redundant. Drop it and pass stakedBandwidth directly to Add.

No behavior change; same result, one fewer big.Int allocation per call.
Previously, a negative limit returned by the Tron API combined with a
smaller used value would yield a non-sensical positive availability
(e.g., limit=10, used=-50 -> 60). All other resource fields in
tronBuildStakingInfo already clamp negative values to zero, so make
tronAvailableResource symmetric and treat any non-positive limit as
zero availability.

Real Tron nodes shouldn't return negative limits, but this hardens the
function against malformed responses.
In Stake 2.0, only BANDWIDTH and ENERGY freeze types produce frozen
TRX; TRON_POWER is a derived voting weight, not a separate stake.
The frozenV2 loop in tronBuildStakingInfo therefore intentionally
ignores TRON_POWER entries when summing stakedBalance.

Add an inline comment explaining the intent so the silent drop is
not mistaken for a missing case.
Copy link
Copy Markdown
Contributor

@pragmaxim pragmaxim left a comment

Choose a reason for hiding this comment

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

There is a possibility to cache stakingInfo to absorb the 3× backend fan-out, but only OPTIONAL and probably necessary only if it turned out to be slow.

Details

GetAddressChainExtraData now issues three concurrent calls (/wallet getaccountresource, /wallet/getaccount, /wallet/getReward) per address request, where it previously issued one. Wall-clock latency is unchanged, but backend RPS for the address endpoint is tripled.

StakingInfo only changes on freeze / unfreeze / vote / withdraw-reward transactions, so a short-TTL per-address cache (e.g. 10–30 s, or invalidated on relevant tx events) would let frequent address-page polling reuse the previous result and bring the steady-state load back down to roughly 1× — while still serving fresh data right after a staking action.

Optional refinement: skip /wallet/getReward when the cached unclaimedReward was 0 and no reward-bearing tx has been seen since.

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.

Tron freezing + governance data

4 participants