Coverage Summary for Class: P2shMultisigBtcLockSender (co.rsk.peg.btcLockSender)

Class Class, % Method, % Line, %
P2shMultisigBtcLockSender 0% (0/1) 0% (0/5) 0% (0/25)


1 package co.rsk.peg.btcLockSender; 2  3 import co.rsk.bitcoinj.core.Address; 4 import co.rsk.bitcoinj.core.BtcTransaction; 5 import co.rsk.bitcoinj.core.Sha256Hash; 6 import co.rsk.bitcoinj.script.Script; 7 import co.rsk.core.RskAddress; 8 import org.ethereum.crypto.HashUtil; 9  10 public class P2shMultisigBtcLockSender implements BtcLockSender { 11  12  private TxSenderAddressType txSenderAddressType; 13  private Address btcAddress; 14  15  public P2shMultisigBtcLockSender() { 16  this.txSenderAddressType = TxSenderAddressType.P2SHMULTISIG; 17  } 18  19  @Override 20  public TxSenderAddressType getTxSenderAddressType() { 21  return txSenderAddressType; 22  } 23  24  @Override 25  public Address getBTCAddress() { 26  return this.btcAddress; 27  } 28  29  @Override 30  public RskAddress getRskAddress() { 31  return null; 32  } 33  34  @Override 35  public boolean tryParse(BtcTransaction btcTx) { 36  if (btcTx == null) { 37  return false; 38  } 39  if (btcTx.getInputs().size() == 0) { 40  return false; 41  } 42  if (btcTx.getInput(0).getScriptBytes() == null) { 43  return false; 44  } 45  46  Script scriptSig = btcTx.getInput(0).getScriptSig(); 47  if (scriptSig.getChunks().size() < 3) { //At least 3 chunks: a 0, at least 1 signature, and redeem script 48  return false; 49  } 50  51  int chunksLength = scriptSig.getChunks().size(); 52  byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; //Redeem script is the last chunk of the scriptSig 53  54  Script redeem = new Script(redeemScript); 55  if(!redeem.isSentToMultiSig()) { 56  return false; 57  } 58  59  try { 60  // Get btc address 61  byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); 62  this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); 63  64  } catch(Exception e) { 65  return false; 66  } 67  68  return true; 69  } 70 }