Coverage Summary for Class: GetMergedMiningTags (co.rsk.pcc.blockheader)

Class Class, % Method, % Line, %
GetMergedMiningTags 0% (0/1) 0% (0/3) 0% (0/11)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2019 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package co.rsk.pcc.blockheader; 21  22 import co.rsk.config.RskMiningConstants; 23 import co.rsk.pcc.ExecutionEnvironment; 24 import org.apache.commons.lang3.ArrayUtils; 25 import org.ethereum.core.Block; 26 import org.ethereum.core.CallTransaction; 27 import org.ethereum.util.ByteUtil; 28  29 import java.util.Arrays; 30 import java.util.Collections; 31 import java.util.List; 32  33 /** 34  * This implements the "getMergedMiningTags" method 35  * that belongs to the BlockHeaderContract native contract. 36  * 37  * @author Diego Masini 38  */ 39 public class GetMergedMiningTags extends BlockHeaderContractMethod { 40  private final CallTransaction.Function function = CallTransaction.Function.fromSignature( 41  "getMergedMiningTags", 42  new String[]{"int256"}, 43  new String[]{"bytes"} 44  ); 45  46  public GetMergedMiningTags(ExecutionEnvironment executionEnvironment, BlockAccessor blockAccessor) { 47  super(executionEnvironment, blockAccessor); 48  } 49  50  @Override 51  public CallTransaction.Function getFunction() { 52  return function; 53  } 54  55  @Override 56  protected Object internalExecute(Block block, Object[] arguments) { 57  byte[] mergedMiningTx = block.getBitcoinMergedMiningCoinbaseTransaction(); 58  59  List<Byte> mergedMiningTxAsList = Arrays.asList(ArrayUtils.toObject(mergedMiningTx)); 60  List<Byte> rskTagBytesAsList = Arrays.asList(ArrayUtils.toObject(RskMiningConstants.RSK_TAG)); 61  62  int rskTagPosition = Collections.lastIndexOfSubList(mergedMiningTxAsList, rskTagBytesAsList); 63  64  // if RSK Tag not found, return an empty byte array 65  if (rskTagPosition == -1) { 66  return ByteUtil.EMPTY_BYTE_ARRAY; 67  } 68  69  int additionalTagsStartIndex = rskTagPosition + RskMiningConstants.RSK_TAG.length + RskMiningConstants.BLOCK_HEADER_HASH_SIZE; 70  return Arrays.copyOfRange(mergedMiningTx, additionalTagsStartIndex, mergedMiningTx.length); 71  } 72 }