For the complete documentation index, see llms.txt. This page is also available as Markdown.

burnHeightToRewardCycle

Returns the reward cycle that contains a Bitcoin block height. Pure computation that mirrors the pox-5 read-only burn-height-to-reward-cycle.


Usage

import { burnHeightToRewardCycle, fetchPoxInfo } from '@stacks/bitcoin-staking';

const poxInfo = await fetchPoxInfo({ network: 'mainnet' });

const cycle = burnHeightToRewardCycle({ burnHeight: poxInfo.currentBurnchainBlockHeight, poxInfo });

Notes

  • Computes floor((burnHeight - firstBurnchainBlockHeight) / rewardCycleLength).

  • Throws an Error with the message burnHeight is before first-burnchain-block-height when burnHeight is below poxInfo.firstBurnchainBlockHeight. The contract aborts at runtime in the same case.


Signature

function burnHeightToRewardCycle(opts: { burnHeight: number; poxInfo: PoxInfo }): number;

Returns

number

The reward cycle ID.


Parameters

opts.burnHeight (required)

  • Type: number

A Bitcoin block height at or above poxInfo.firstBurnchainBlockHeight.

opts.poxInfo (required)

  • Type: PoxInfo

A PoxInfo, usually from fetchPoxInfo.

Was this helpful?