fetchLastRewardComputeHeight
Reads the calculation height stored by the last calculate-rewards call: the Bitcoin block before the start of the distribution cycle it ran in. Wraps the pox-5 read-only get-last-reward-compute-height, which returns the last-reward-compute-height data-var.
Usage
import {
currentDistributionCycle,
distributionCycleToBurnHeight,
fetchLastRewardComputeHeight,
fetchPoxInfo,
} from '@stacks/bitcoin-staking';
const poxInfo = await fetchPoxInfo({ network: 'mainnet' });
const lastHeight = await fetchLastRewardComputeHeight({ network: 'mainnet' });
// The height calculate-rewards would use now
const calculationHeight =
distributionCycleToBurnHeight({ distributionCycle: currentDistributionCycle(poxInfo), poxInfo }) - 1;
const pending = calculationHeight > lastHeight;Notes
calculate-rewardsreverts withERR_DISTRIBUTION_ALREADY_COMPUTED (u30)unless the current calculation height is greater than this value (calculate-rewards). It stores the new height on success (calculate-rewards).A distribution cycle is half a reward cycle: 1,050 Bitcoin blocks on mainnet (distribution-cycle-to-burn-height). distributionCycleToBurnHeight and currentDistributionCycle compute the same values locally.
The data-var starts at
0(last-reward-compute-height).A non-2xx response throws an
Errorwhose message starts withError calling read-only function.and includes the status code and URL. If the node reports that the call failed, theErrormessage is the node'scause.
Signature
opts is a NetworkClientParam.
Returns
Promise<number>
Resolves to a Bitcoin block height as a number.
Parameters
opts.network (optional)
Type:
StacksNetworkName | StacksNetwork
The network to query: a name such as 'mainnet' or 'testnet', or a StacksNetwork object. Defaults to 'mainnet'.
opts.client (optional)
Type:
{ baseUrl?: string; fetch?: FetchFn }
Overrides the API base URL or the fetch function, for example to query your own node. Fields you set replace the network's defaults.
Was this helpful?