Mining Claims
CityCoin contract functions related to mining claims.
Overview
After miners send their STX to the contract, a winner is later calculated by a Verifiable Random Function (VRF) weighted by the individual miner's bid compared to the total miners' bids sent in that block.
Claiming a mining reward happens by calling the claim-mining-reward function in the contract.
Details
Miners must wait for a maturity window of 100 blocks (~16 hours) before they can know the winner of a given block in order to protect the VRF seed.
After this window passes miners can claim their CityCoin block rewards at any time.
If the user won the block, the transaction will succeed and mint them the block reward per the Emissions Schedule.
If a user did not win the block, the transaction will fail.
Optionally, a user can call the is-block-winner and can-claim-mining-reward functions to see if their address can claim a given block before submitting the claim transaction.
Functions
claim-mining-reward
Type: Public Function
Input: minerBlockHeight as uint
Success: (ok true)
Errors:
ERR_USER_NOT_FOUND u1002ERR_USER_ID_NOT_FOUND u1003ERR_USER_DID_NOT_MINE_IN_BLOCK u1009ERR_CLAIMED_BEFORE_MATURITY u1010ERR_NO_MINERS_AT_BLOCK u1011ERR_REWARD_ALREADY_CLAIMED u1012ERR_MINER_DID_NOT_WIN u1013ERR_NO_VRF_SEED_FOUND u1014ERR_CLAIM_IN_WRONG_CONTRACT u1020
Claiming mining rewards happens through calling the claim-mining-reward function in the contract, which accepts the block height the miner mined in, and checks if the VRF value is between the lowValue and highValue for the miner.
If the miner won the block, then the coinbase is minted for them based on block height of the claim and the emissions schedule.
is-block-winner
Type: Read-only Function
Input: user as principal and minerBlockHeight as uint
Returns: true or false
Returns a boolean value indicating if the user's principal won at a given block height.
Note: this function will always return false if the token maturity window of 100 blocks did not pass.
can-claim-mining-reward
Type: Read-only Function
Input: user as principal and minerBlockHeight as uint
Returns: true or false
Returns a boolean value indicating if the user's principal won and is eligible to claim the block reward at a given block height.
Note: this function will always return false if the token maturity window of 100 blocks did not pass.
Last updated
Was this helpful?