Skip to content

Commit

Permalink
chore: update rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
samlior committed May 19, 2023
1 parent ef74416 commit b5a76f8
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions packages/api/src/controller/rei.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,28 @@ export class ReiController extends Controller {
* @returns Miner reward factor
*/
async getMinerRewardFactor([tag]: [string]) {
const num = await this.getBlockNumberByTag(tag);
const common = this.node.getCommon(num);
const factor = common.param('vm', 'minerRewardFactor');
if (typeof factor !== 'number' || factor < 0 || factor > 100) {
return null;
const block = await this.getBlockByTag(tag);

let factor: number | undefined = undefined;
if (block.header.number.gten(1)) {
const parent = await this.node.db.getHeader(block.header.parentHash, block.header.number.subn(1));
const parentCommon = parent._common;
if (isEnableDAO(parentCommon)) {
// load minerRewardFactor from contract
const parentVM = await this.node.getVM(parent.stateRoot, parentCommon);
const config = await this.node.reimint.getConfig(parentVM, block, parentCommon);
factor = (await config.minerRewardFactor()).toNumber();
}
}

// load minerRewardFactor from common
if (factor === undefined) {
factor = block._common.param('vm', 'minerRewardFactor');
if (typeof factor !== 'number' || factor < 0 || factor > 100) {
return null;
}
}

return intToHex(factor);
}
}

0 comments on commit b5a76f8

Please sign in to comment.