io.nuls.kernel.model.Block.getHeader()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(79)

本文整理了Java中io.nuls.kernel.model.Block.getHeader()方法的一些代码示例,展示了Block.getHeader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.getHeader()方法的具体详情如下:
包路径:io.nuls.kernel.model.Block
类名称:Block
方法名:getHeader

Block.getHeader介绍

暂无

代码示例

代码示例来源:origin: nuls-io/nuls

public void initData(Block block) {
  this.startBlockHeader = block.getHeader();
  this.endBlockHeader = block.getHeader();
  this.blockHeaderList.add(block.getHeader());
  this.blockList.add(block);
}

代码示例来源:origin: nuls-io/nuls

public void addPreBlock(Block block) {
    this.startBlockHeader = block.getHeader();
    this.blockHeaderList.add(0, block.getHeader());
    this.blockList.add(0, block);
  }
}

代码示例来源:origin: nuls-io/nuls

@Override
  public ValidateResult validate(Block data) {
    if (null == data || data.getHeader() == null) {
      return ValidateResult.getFailedResult(this.getClass().getName(), ProtocolErroeCode.BLOCK_IS_NULL);
    }
    return data.getHeader().verify();
  }
}

代码示例来源:origin: nuls-io/nuls

public boolean addBlock(Block block) {
    long height = block.getHeader().getHeight();
    if (height < startHeight || height > endHeight) {
      return false;
    }
//        Log.info("added block:" + height);
    map.put(height, block);
    return true;
  }

代码示例来源:origin: nuls-io/nuls

public void addBlock(Block block) {
  if (block.getHeader().getHeight() <= endHeight) {
    return;
  }
  CoinBaseTransaction tx = (CoinBaseTransaction) block.getTxs().get(0);
  this.calcReward(block.getHeader().getHeight(), tx);
}

代码示例来源:origin: nuls-io/nuls

/**
 * 获取本地最新高度
 * Get the latest local height.
 *
 * @return long height
 */
public long getBestHeight() {
  if (bestBlock == null) {
    bestBlock = getGenesisBlock();
  }
  return bestBlock.getHeader().getHeight();
}

代码示例来源:origin: nuls-io/nuls

/**
 * get the current block header
 * @return
 * @throws IOException
 */
public BlockHeaderDto getCurrentBlockHeader()  {
  BlockHeader blockHeader = currentBlockHeader.get();
  if(blockHeader == null) {
    blockHeader = NulsContext.getInstance().getBestBlock().getHeader();
  }
  return new BlockHeaderDto(blockHeader);
}

代码示例来源:origin: nuls-io/nuls

/**
 * CoinBase transaction & Punish transaction
 *
 * @param bestBlock local highest block
 * @param txList    all tx of block
 * @param self      agent meeting data
 */
private void addConsensusTx(Block bestBlock, List<Transaction> txList, MeetingMember self, MeetingRound round) throws NulsException, IOException {
  CoinBaseTransaction coinBaseTransaction = ConsensusTool.createCoinBaseTx(self, txList, round, bestBlock.getHeader().getHeight() + 1 + PocConsensusConstant.COINBASE_UNLOCK_HEIGHT);
  txList.add(0, coinBaseTransaction);
  punishTx(bestBlock, txList, self, round);
}

代码示例来源:origin: nuls-io/nuls

public boolean verifyCoinBaseTx(Block block, MeetingRound currentRound, MeetingMember member) {
  Transaction tx = block.getTxs().get(0);
  CoinBaseTransaction coinBaseTransaction = ConsensusTool.createCoinBaseTx(member, block.getTxs(), currentRound, block.getHeader().getHeight() + PocConsensusConstant.COINBASE_UNLOCK_HEIGHT);
  if (null == coinBaseTransaction || !tx.getHash().equals(coinBaseTransaction.getHash())) {
    BlockLog.debug("the coin base tx is wrong! height: " + block.getHeader().getHeight() + " , hash : " + block.getHeader().getHash());
    Log.error("the coin base tx is wrong! height: " + block.getHeader().getHeight() + " , hash : " + block.getHeader().getHash());
    return false;
  }
  return true;
}

代码示例来源:origin: nuls-io/nuls

/**
 * get the newest block header
 * @return
 * @throws IOException
 */
public BlockHeaderDto getNewestBlockHeader()  {
  return new BlockHeaderDto(NulsContext.getInstance().getBestBlock().getHeader());
}

代码示例来源:origin: nuls-io/nuls

public BlockHeaderDto(Block block) throws IOException {
  this(block.getHeader());
  this.size = block.getHeader().size();
  Na fee = Na.ZERO;
  for (Transaction tx : block.getTxs()) {
    fee = fee.add(tx.getFee());
    if (tx.getType() == ProtocolConstant.TX_TYPE_COINBASE) {
      setBlockReward(tx);
    }
  }
  this.fee = fee.getValue();
}

代码示例来源:origin: nuls-io/nuls

public static SmallBlock getSmallBlock(Block block) {
  SmallBlock smallBlock = new SmallBlock();
  smallBlock.setHeader(block.getHeader());
  List<NulsDigestData> txHashList = new ArrayList<>();
  for (Transaction tx : block.getTxs()) {
    txHashList.add(tx.getHash());
    if (tx.isSystemTx()) {
      smallBlock.addBaseTx(tx);
    }
  }
  smallBlock.setTxHashList(txHashList);
  return smallBlock;
}

代码示例来源:origin: nuls-io/nuls

public ProgramResult invokeViewMethod(byte[] contractAddressBytes, String methodName, String methodDesc, String[][] args) {
  // 当前区块高度
  BlockHeader blockHeader = NulsContext.getInstance().getBestBlock().getHeader();
  long blockHeight = blockHeader.getHeight();
  // 当前区块状态根
  byte[] currentStateRoot = ContractUtil.getStateRoot(blockHeader);
  return this.invokeViewMethod(null, currentStateRoot, blockHeight, contractAddressBytes, methodName, methodDesc, args);
}

代码示例来源:origin: nuls-io/nuls

@Override
public boolean save(Block block) {
  assert (block != null);
  Result result = null;
  try {
    result = dbService.put(DB_NAME, block.getHeader().getHash().getDigestBytes(), block.serialize());
  } catch (IOException e) {
    Log.error(e);
    return false;
  }
  return result.isSuccess();
}

代码示例来源:origin: nuls-io/nuls

public boolean checkIsAfterOrphanChainAndAdd(Block block) {
  BlockHeader header = block.getHeader();
  for(ChainContainer chainContainer : orphanChains) {
    Chain chain = chainContainer.getChain();
    if(header.getPreHash().equals(chain.getEndBlockHeader().getHash())) {
      chain.addBlock(block);
      return true;
    }
  }
  return false;
}

代码示例来源:origin: nuls-io/nuls

public boolean checkIsBeforeOrphanChainAndAdd(Block block) {
  BlockHeader header = block.getHeader();
  boolean success = false;
  for(ChainContainer chainContainer : orphanChains) {
    Chain chain = chainContainer.getChain();
    if(header.getHash().equals(chain.getStartBlockHeader().getPreHash())) {
      success = true;
      chain.addPreBlock(block);
    }
  }
  return success;
}

代码示例来源:origin: nuls-io/nuls

public ProgramMethod getMethodInfoByContractAddress(String methodName, String methodDesc, byte[] contractAddressBytes) {
  if(StringUtils.isBlank(methodName)) {
    return null;
  }
  BlockHeader header = NulsContext.getInstance().getBestBlock().getHeader();
  // 当前区块状态根
  byte[] currentStateRoot = ContractUtil.getStateRoot(header);
  ProgramExecutor track = programExecutor.begin(currentStateRoot);
  List<ProgramMethod> methods = track.method(contractAddressBytes);
  return this.getMethodInfo(methodName, methodDesc, methods);
}

代码示例来源:origin: nuls-io/nuls

private void sendBlock(Block block, Node fromNode) {
    BlockMessage blockMessage = new BlockMessage();
    blockMessage.setMsgBody(block);
    Result result = this.messageBusService.sendToNode(blockMessage, fromNode, true);
    if (result.isFailed()) {
      Log.warn("send block failed:" + fromNode.getId() + ",height:" + block.getHeader().getHeight());
    }
  }
}

代码示例来源:origin: nuls-io/nuls

private void sendBlock(Block block, Node fromNode) {
    BlockMessage blockMessage = new BlockMessage();
    blockMessage.setMsgBody(block);
    Result result = this.messageBusService.sendToNode(blockMessage, fromNode, true);
    if (result.isFailed()) {
      Log.warn("send block failed:" + fromNode.getId() + ",height:" + block.getHeader().getHeight());
    }
  }
}

代码示例来源:origin: nuls-io/nuls

private void sendHandshakeMessage(Node node, int type) {
  NetworkMessageBody body = new NetworkMessageBody(type, networkParam.getPort(),
      NulsContext.getInstance().getBestHeight(), NulsContext.getInstance().getBestBlock().getHeader().getHash(),
      node.getIp());
  broadcastHandler.broadcastToNode(new HandshakeMessage(body), node, true);
}

相关文章

微信公众号

最新文章

更多