Coverage Summary for Class: CallArgumentsToByteArray (org.ethereum.rpc.converters)

Class Class, % Method, % Line, %
CallArgumentsToByteArray 100% (1/1) 100% (7/7) 88.9% (24/27)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * 5  * This program is free software: you can redistribute it and/or modify 6  * it under the terms of the GNU Lesser General Public License as published by 7  * the Free Software Foundation, either version 3 of the License, or 8  * (at your option) any later version. 9  * 10  * This program is distributed in the hope that it will be useful, 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13  * GNU Lesser General Public License for more details. 14  * 15  * You should have received a copy of the GNU Lesser General Public License 16  * along with this program. If not, see <http://www.gnu.org/licenses/>. 17  */ 18  19 package org.ethereum.rpc.converters; 20  21 import co.rsk.core.RskAddress; 22 import org.ethereum.rpc.Web3; 23  24 import static org.ethereum.rpc.TypeConverter.stringHexToByteArray; 25  26 /** 27  * Created by martin.medina on 3/7/17. 28  */ 29 public class CallArgumentsToByteArray { 30  31  private Web3.CallArguments args; 32  33  public CallArgumentsToByteArray(Web3.CallArguments args) { 34  this.args = args; 35  } 36  37  public byte[] getGasPrice() { 38  byte[] gasPrice = new byte[] {0}; 39  if (args.gasPrice != null && args.gasPrice.length() != 0) { 40  gasPrice = stringHexToByteArray(args.gasPrice); 41  } 42  43  return gasPrice; 44  } 45  46  public byte[] getGasLimit() { 47  // maxGasLimit value is 100000000000000 48  String maxGasLimit = "0x5AF3107A4000"; 49  byte[] gasLimit = stringHexToByteArray(maxGasLimit); 50  if (args.gas != null && args.gas.length() != 0) { 51  gasLimit = stringHexToByteArray(args.gas); 52  } 53  54  return gasLimit; 55  } 56  57  public byte[] getToAddress() { 58  byte[] toAddress = null; 59  if (args.to != null) { 60  toAddress = stringHexToByteArray(args.to); 61  } 62  63  return toAddress; 64  } 65  66  public byte[] getValue() { 67  byte[] value = new byte[] { 0 }; 68  if (args.value != null && args.value.length() != 0) { 69  value = stringHexToByteArray(args.value); 70  } 71  72  return value; 73  } 74  75  public byte[] getData() { 76  byte[] data = null; 77  78  if (args.data != null && args.data.length() != 0) { 79  data = stringHexToByteArray(args.data); 80  } 81  82  return data; 83  } 84  85  public RskAddress getFromAddress() { 86  if (args.from == null || args.from.isEmpty()) { 87  return RskAddress.nullAddress(); 88  } 89  90  return new RskAddress(stringHexToByteArray(args.from)); 91  } 92 }