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
Errorwith the messageburnHeight is before first-burnchain-block-heightwhenburnHeightis belowpoxInfo.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?