Repository: shardeum/shardeum
File: src/tx/setCertTime.ts (TypeScript)

Code before:
  operatorEVMAccount.operatorAccountInfo.certExp =
    txTimestamp + serverConfig.p2p.cycleDuration * ONE_SECOND * duration

  // deduct tx fee if certExp is not set yet or far from expiration
  /* prettier-ignore */ if (logFlags.dapp_verbose) console.log(`applySetCertTimeTx shouldChargeTxFee: ${shouldChargeTxFee}`)

  let amountSpent = bigIntToHex(BigInt(0))
  if (shouldChargeTxFee) {
    const costTxFee = scaleByStabilityFactor(
      BigInt(ShardeumFlags.constantTxFeeUsd),
      AccountsStorage.cachedNetworkAccount
    )
    operatorEVMAccount.account.balance = SafeBalance.subtractBigintBalance(operatorEVMAccount.account.balance, costTxFee)
    amountSpent = bigIntToHex(costTxFee)
  }

  /* prettier-ignore */ if (logFlags.dapp_verbose) console.log('operatorEVMAccount After', operatorEVMAccount)

  // Apply state
  if (ShardeumFlags.useAccountWrites) {
    const wrappedChangedAccount = WrappedEVMAccountFunctions._shardusWrappedAccount(operatorEVMAccount)
    shardus.applyResponseAddChangedAccount(
      applyResponse,
      wrappedChangedAccount.accountId,
      wrappedChangedAccount,
      txId,
      txTimestamp
    )
  }

  if (ShardeumFlags.supportInternalTxReceipt) {
    createInternalTxReceipt(
      shardus,
      applyResponse,
      tx,
      tx.nominee,
      tx.nominator,
      txTimestamp,
      txId,
      amountSpent
    )
  }
}


Review comment (suggestion):
is it okay to pass null here? (just want to confirm as we have a null check [above](https://github.com/shardeum/shardeum/pull/203/files#diff-801f96452344614d27069c631ad031a8fb1eca5974d2971e1acbc71bdb318c9cR165))

Code after:
  // this avoids a problem where new nodes syncing into the network may not have correct duration setting
  // as they are not aware of the global network setting
  // ...but in the future we should perhaps do a trustless get of the network object for standby nodes
  //    in case there are other settings that are important to know
  if (ShardeumFlags.setCertTimeDurationOverride) {
    duration = getCertCycleDuration()
  }

  // update operator cert expiration
  operatorEVMAccount.operatorAccountInfo.certExp =
    txTimestamp + serverConfig.p2p.cycleDuration * ONE_SECOND * duration

  // deduct tx fee if certExp is not set yet or far from expiration
  /* prettier-ignore */ if (logFlags.dapp_verbose) console.log(`applySetCertTimeTx shouldChargeTxFee: ${shouldChargeTxFee}`)

  let network: NetworkAccount
  // eslint-disable-next-line security/detect-object-injection
  if (wrappedStates[networkAccount]?.data && isNetworkAccount(wrappedStates[networkAccount].data)) {
    // eslint-disable-next-line security/detect-object-injection
    network = wrappedStates[networkAccount].data as NetworkAccount
  }
  let amountSpent = bigIntToHex(BigInt(0))
  if (shouldChargeTxFee) {
    const costTxFee = scaleByStabilityFactor(
      BigInt(ShardeumFlags.constantTxFeeUsd),
      network
    )
    operatorEVMAccount.account.balance = SafeBalance.subtractBigintBalance(operatorEVMAccount.account.balance, costTxFee)
    amountSpent = bigIntToHex(costTxFee)
  }

  /* prettier-ignore */ if (logFlags.dapp_verbose) console.log('operatorEVMAccount After', operatorEVMAccount)

  // Apply state
  if (ShardeumFlags.useAccountWrites) {
    const wrappedChangedAccount = WrappedEVMAccountFunctions._shardusWrappedAccount(operatorEVMAccount)
    shardus.applyResponseAddChangedAccount(
      applyResponse,
      wrappedChangedAccount.accountId,
      wrappedChangedAccount,
      txId,
      txTimestamp
    )
  }

  if (ShardeumFlags.supportInternalTxReceipt) {
    createInternalTxReceipt(
      shardus,
      applyResponse,
      tx,
      tx.nominee,