target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test(expected = Exception.class) public void calculateMerkleRoot_invalid_pmt() { NetworkParameters networkParameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST); BridgeUtils.calculateMerkleRoot(networkParameters, Hex.decode("ab"), null); }
|
public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; }
|
BridgeUtils { public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; } }
|
BridgeUtils { public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; } }
|
BridgeUtils { public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void calculateMerkleRoot_hashes_not_in_pmt() { byte[] bits = new byte[1]; bits[0] = 0x01; List<Sha256Hash> hashes = new ArrayList<>(); hashes.add(PegTestUtils.createHash()); BridgeConstants bridgeConstants = BridgeRegTestConstants.getInstance(); NetworkParameters networkParameters = bridgeConstants.getBtcParams(); BtcTransaction tx = new BtcTransaction(networkParameters); PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, bits, hashes, 1); Assert.assertNull(BridgeUtils.calculateMerkleRoot(networkParameters, pmt.bitcoinSerialize(), tx.getHash())); }
|
public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; }
|
BridgeUtils { public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; } }
|
BridgeUtils { public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; } }
|
BridgeUtils { public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void testEncodeElementNull() { byte[] actuals = encodeElement((byte[]) null); assertArrayEquals(new byte[]{(byte) 0x80}, actuals); }
|
public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void calculateMerkleRoot_hashes_in_pmt() { BridgeConstants bridgeConstants = BridgeRegTestConstants.getInstance(); NetworkParameters networkParameters = bridgeConstants.getBtcParams(); BtcTransaction tx = new BtcTransaction(networkParameters); byte[] bits = new byte[1]; bits[0] = 0x01; List<Sha256Hash> hashes = new ArrayList<>(); hashes.add(tx.getHash()); PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, bits, hashes, 1); Assert.assertEquals(Sha256Hash.wrap("d21633ba23f70118185227be58a63527675641ad37967e2aa461559f577aec43"), BridgeUtils.calculateMerkleRoot(networkParameters, pmt.bitcoinSerialize(), tx.getHash())); }
|
public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; }
|
BridgeUtils { public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; } }
|
BridgeUtils { public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; } }
|
BridgeUtils { public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash) throws VerificationException{ PartialMerkleTree pmt = new PartialMerkleTree(networkParameters, pmtSerialized, 0); List<Sha256Hash> hashesInPmt = new ArrayList<>(); Sha256Hash merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt); if (!hashesInPmt.contains(btcTxHash)) { logger.warn("Supplied Btc Tx {} is not in the supplied partial merkle tree", btcTxHash); return null; } return merkleRoot; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test(expected = VerificationException.class) public void validateInputsCount_active_rskip() { BridgeUtils.validateInputsCount(Hex.decode("00000000000100"), true); }
|
public static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip) throws VerificationException.EmptyInputsOrOutputs { if (BtcTransactionFormatUtils.getInputsCount(btcTxSerialized) == 0) { if (isActiveRskip) { if (BtcTransactionFormatUtils.getInputsCountForSegwit(btcTxSerialized) == 0) { logger.warn("Provided btc segwit tx has no inputs"); throw new VerificationException.EmptyInputsOrOutputs(); } } else { logger.warn("Provided btc tx has no inputs "); throw new VerificationException.EmptyInputsOrOutputs(); } } }
|
BridgeUtils { public static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip) throws VerificationException.EmptyInputsOrOutputs { if (BtcTransactionFormatUtils.getInputsCount(btcTxSerialized) == 0) { if (isActiveRskip) { if (BtcTransactionFormatUtils.getInputsCountForSegwit(btcTxSerialized) == 0) { logger.warn("Provided btc segwit tx has no inputs"); throw new VerificationException.EmptyInputsOrOutputs(); } } else { logger.warn("Provided btc tx has no inputs "); throw new VerificationException.EmptyInputsOrOutputs(); } } } }
|
BridgeUtils { public static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip) throws VerificationException.EmptyInputsOrOutputs { if (BtcTransactionFormatUtils.getInputsCount(btcTxSerialized) == 0) { if (isActiveRskip) { if (BtcTransactionFormatUtils.getInputsCountForSegwit(btcTxSerialized) == 0) { logger.warn("Provided btc segwit tx has no inputs"); throw new VerificationException.EmptyInputsOrOutputs(); } } else { logger.warn("Provided btc tx has no inputs "); throw new VerificationException.EmptyInputsOrOutputs(); } } } }
|
BridgeUtils { public static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip) throws VerificationException.EmptyInputsOrOutputs { if (BtcTransactionFormatUtils.getInputsCount(btcTxSerialized) == 0) { if (isActiveRskip) { if (BtcTransactionFormatUtils.getInputsCountForSegwit(btcTxSerialized) == 0) { logger.warn("Provided btc segwit tx has no inputs"); throw new VerificationException.EmptyInputsOrOutputs(); } } else { logger.warn("Provided btc tx has no inputs "); throw new VerificationException.EmptyInputsOrOutputs(); } } } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip) throws VerificationException.EmptyInputsOrOutputs { if (BtcTransactionFormatUtils.getInputsCount(btcTxSerialized) == 0) { if (isActiveRskip) { if (BtcTransactionFormatUtils.getInputsCountForSegwit(btcTxSerialized) == 0) { logger.warn("Provided btc segwit tx has no inputs"); throw new VerificationException.EmptyInputsOrOutputs(); } } else { logger.warn("Provided btc tx has no inputs "); throw new VerificationException.EmptyInputsOrOutputs(); } } } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test(expected = VerificationException.class) public void validateInputsCount_inactive_rskip() { BridgeConstants bridgeConstants = BridgeRegTestConstants.getInstance(); NetworkParameters networkParameters = bridgeConstants.getBtcParams(); BtcTransaction tx = new BtcTransaction(networkParameters); BridgeUtils.validateInputsCount(tx.bitcoinSerialize(), false); }
|
public static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip) throws VerificationException.EmptyInputsOrOutputs { if (BtcTransactionFormatUtils.getInputsCount(btcTxSerialized) == 0) { if (isActiveRskip) { if (BtcTransactionFormatUtils.getInputsCountForSegwit(btcTxSerialized) == 0) { logger.warn("Provided btc segwit tx has no inputs"); throw new VerificationException.EmptyInputsOrOutputs(); } } else { logger.warn("Provided btc tx has no inputs "); throw new VerificationException.EmptyInputsOrOutputs(); } } }
|
BridgeUtils { public static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip) throws VerificationException.EmptyInputsOrOutputs { if (BtcTransactionFormatUtils.getInputsCount(btcTxSerialized) == 0) { if (isActiveRskip) { if (BtcTransactionFormatUtils.getInputsCountForSegwit(btcTxSerialized) == 0) { logger.warn("Provided btc segwit tx has no inputs"); throw new VerificationException.EmptyInputsOrOutputs(); } } else { logger.warn("Provided btc tx has no inputs "); throw new VerificationException.EmptyInputsOrOutputs(); } } } }
|
BridgeUtils { public static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip) throws VerificationException.EmptyInputsOrOutputs { if (BtcTransactionFormatUtils.getInputsCount(btcTxSerialized) == 0) { if (isActiveRskip) { if (BtcTransactionFormatUtils.getInputsCountForSegwit(btcTxSerialized) == 0) { logger.warn("Provided btc segwit tx has no inputs"); throw new VerificationException.EmptyInputsOrOutputs(); } } else { logger.warn("Provided btc tx has no inputs "); throw new VerificationException.EmptyInputsOrOutputs(); } } } }
|
BridgeUtils { public static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip) throws VerificationException.EmptyInputsOrOutputs { if (BtcTransactionFormatUtils.getInputsCount(btcTxSerialized) == 0) { if (isActiveRskip) { if (BtcTransactionFormatUtils.getInputsCountForSegwit(btcTxSerialized) == 0) { logger.warn("Provided btc segwit tx has no inputs"); throw new VerificationException.EmptyInputsOrOutputs(); } } else { logger.warn("Provided btc tx has no inputs "); throw new VerificationException.EmptyInputsOrOutputs(); } } } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip) throws VerificationException.EmptyInputsOrOutputs { if (BtcTransactionFormatUtils.getInputsCount(btcTxSerialized) == 0) { if (isActiveRskip) { if (BtcTransactionFormatUtils.getInputsCountForSegwit(btcTxSerialized) == 0) { logger.warn("Provided btc segwit tx has no inputs"); throw new VerificationException.EmptyInputsOrOutputs(); } } else { logger.warn("Provided btc tx has no inputs "); throw new VerificationException.EmptyInputsOrOutputs(); } } } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void isInputSignedByThisFederator_isSigned() { NetworkParameters params = RegTestParams.get(); BtcECKey federator1Key = new BtcECKey(); BtcECKey federator2Key = new BtcECKey(); Federation federation = new Federation( FederationMember.getFederationMembersFromKeys(Arrays.asList(federator1Key, federator2Key)), Instant.now(), 0, params ); BtcTransaction tx = new BtcTransaction(params); TransactionInput txInput = new TransactionInput( params, tx, new byte[]{}, new TransactionOutPoint(params, 0, Sha256Hash.ZERO_HASH) ); Script inputScript = createBaseInputScriptThatSpendsFromTheFederation(federation); txInput.setScriptSig(inputScript); tx.addInput(txInput); List<ScriptChunk> chunks = inputScript.getChunks(); byte[] program = chunks.get(chunks.size() - 1).data; Script redeemScript = new Script(program); Sha256Hash sighash = tx.hashForSignature(0, redeemScript, BtcTransaction.SigHash.ALL, false); BtcECKey.ECDSASignature sig = federator1Key.sign(sighash); TransactionSignature txSig = new TransactionSignature(sig, BtcTransaction.SigHash.ALL, false); byte[] txSigEncoded = txSig.encodeToBitcoin(); int sigIndex = inputScript.getSigInsertionIndex(sighash, federator1Key); inputScript = ScriptBuilder.updateScriptWithSignature(inputScript, txSigEncoded, sigIndex, 1, 1); txInput.setScriptSig(inputScript); boolean isSigned = BridgeUtils.isInputSignedByThisFederator(federator1Key, sighash, txInput); Assert.assertTrue(isSigned); }
|
public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; }
|
BridgeUtils { public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; } }
|
BridgeUtils { public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; } }
|
BridgeUtils { public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void isInputSignedByThisFederator_isSignedByAnotherFederator() { NetworkParameters params = RegTestParams.get(); BtcECKey federator1Key = new BtcECKey(); BtcECKey federator2Key = new BtcECKey(); Federation federation = new Federation( FederationMember.getFederationMembersFromKeys(Arrays.asList(federator1Key, federator2Key)), Instant.now(), 0, params ); BtcTransaction tx = new BtcTransaction(params); TransactionInput txInput = new TransactionInput( params, tx, new byte[]{}, new TransactionOutPoint(params, 0, Sha256Hash.ZERO_HASH) ); Script inputScript = createBaseInputScriptThatSpendsFromTheFederation(federation); txInput.setScriptSig(inputScript); tx.addInput(txInput); List<ScriptChunk> chunks = inputScript.getChunks(); byte[] program = chunks.get(chunks.size() - 1).data; Script redeemScript = new Script(program); Sha256Hash sighash = tx.hashForSignature(0, redeemScript, BtcTransaction.SigHash.ALL, false); BtcECKey.ECDSASignature sig = federator1Key.sign(sighash); TransactionSignature txSig = new TransactionSignature(sig, BtcTransaction.SigHash.ALL, false); byte[] txSigEncoded = txSig.encodeToBitcoin(); int sigIndex = inputScript.getSigInsertionIndex(sighash, federator1Key); inputScript = ScriptBuilder.updateScriptWithSignature(inputScript, txSigEncoded, sigIndex, 1, 1); txInput.setScriptSig(inputScript); boolean isSigned = BridgeUtils.isInputSignedByThisFederator(federator2Key, sighash, txInput); Assert.assertFalse(isSigned); }
|
public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; }
|
BridgeUtils { public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; } }
|
BridgeUtils { public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; } }
|
BridgeUtils { public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void isInputSignedByThisFederator_notSigned() { NetworkParameters params = RegTestParams.get(); BtcECKey federator1Key = new BtcECKey(); BtcECKey federator2Key = new BtcECKey(); Federation federation = new Federation( FederationMember.getFederationMembersFromKeys(Arrays.asList(federator1Key, federator2Key)), Instant.now(), 0, params ); BtcTransaction tx = new BtcTransaction(params); TransactionInput txInput = new TransactionInput( params, tx, new byte[]{}, new TransactionOutPoint(params, 0, Sha256Hash.ZERO_HASH) ); Script inputScript = createBaseInputScriptThatSpendsFromTheFederation(federation); txInput.setScriptSig(inputScript); tx.addInput(txInput); List<ScriptChunk> chunks = inputScript.getChunks(); byte[] program = chunks.get(chunks.size() - 1).data; Script redeemScript = new Script(program); Sha256Hash sighash = tx.hashForSignature(0, redeemScript, BtcTransaction.SigHash.ALL, false); boolean isSigned = BridgeUtils.isInputSignedByThisFederator(federator1Key, sighash, txInput); Assert.assertFalse(isSigned); }
|
public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; }
|
BridgeUtils { public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; } }
|
BridgeUtils { public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; } }
|
BridgeUtils { public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input) { List<ScriptChunk> chunks = input.getScriptSig().getChunks(); for (int j = 1; j < chunks.size() - 1; j++) { ScriptChunk chunk = chunks.get(j); if (chunk.data.length == 0) { continue; } TransactionSignature sig2 = TransactionSignature.decodeFromBitcoin(chunk.data, false, false); if (federatorPublicKey.verify(sighash, sig2)) { return true; } } return false; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void combineLeftRight() { Assert.assertEquals( Sha256Hash.wrap("ceea4835dd23fae1978a3f6f3f0aa0171e018360272dd5b98d37550fbc978d01"), MerkleTreeUtils.combineLeftRight( Sha256Hash.wrap("b945b008fbc3f357db745909958b570773fc14575a36af8bbc195b484e21f366"), Sha256Hash.wrap("9880f57b6735152a8c6d4c7e1b3bc6434ee75e459511a642bbb8cb71d3a6b6d8") ) ); Assert.assertEquals( Sha256Hash.wrap("107857d7233c41d4c37ecaa9ad9d9ab15371f643074866cd23d657e6e99676be"), MerkleTreeUtils.combineLeftRight( Sha256Hash.wrap("083eafdf670bb1bbc83b63262887e3cf519c3e252fac29adfb92c1e857b37f91"), Sha256Hash.wrap("5740915e973a211c71655d10e4c672301c27c287843dcfa97b7aafc04992ec5e") ) ); Assert.assertEquals( Sha256Hash.wrap("71a12c9bd54735864dd6e12640e6d00d60a42a2e92e4cd0bde3f9f268b7d4345"), MerkleTreeUtils.combineLeftRight( Sha256Hash.wrap("c960ed36a67318cd562d384bfbf41499db1312835e2bfe86805d9465afe9736f"), Sha256Hash.wrap("120196be3b0ca6ba07d3cfee53f8dc883781e82afdfba11181184f41a67b9898") ) ); }
|
public static Sha256Hash combineLeftRight(Sha256Hash left, Sha256Hash right) { byte[] leftBytes = left.getBytes(); byte[] rightBytes = right.getBytes(); checkNotAValid64ByteTransaction(leftBytes, rightBytes); return Sha256Hash.wrapReversed( Sha256Hash.hashTwice( reverseBytes(leftBytes), 0, 32, reverseBytes(rightBytes), 0, 32 ) ); }
|
MerkleTreeUtils { public static Sha256Hash combineLeftRight(Sha256Hash left, Sha256Hash right) { byte[] leftBytes = left.getBytes(); byte[] rightBytes = right.getBytes(); checkNotAValid64ByteTransaction(leftBytes, rightBytes); return Sha256Hash.wrapReversed( Sha256Hash.hashTwice( reverseBytes(leftBytes), 0, 32, reverseBytes(rightBytes), 0, 32 ) ); } }
|
MerkleTreeUtils { public static Sha256Hash combineLeftRight(Sha256Hash left, Sha256Hash right) { byte[] leftBytes = left.getBytes(); byte[] rightBytes = right.getBytes(); checkNotAValid64ByteTransaction(leftBytes, rightBytes); return Sha256Hash.wrapReversed( Sha256Hash.hashTwice( reverseBytes(leftBytes), 0, 32, reverseBytes(rightBytes), 0, 32 ) ); } private MerkleTreeUtils(); }
|
MerkleTreeUtils { public static Sha256Hash combineLeftRight(Sha256Hash left, Sha256Hash right) { byte[] leftBytes = left.getBytes(); byte[] rightBytes = right.getBytes(); checkNotAValid64ByteTransaction(leftBytes, rightBytes); return Sha256Hash.wrapReversed( Sha256Hash.hashTwice( reverseBytes(leftBytes), 0, 32, reverseBytes(rightBytes), 0, 32 ) ); } private MerkleTreeUtils(); static Sha256Hash combineLeftRight(Sha256Hash left, Sha256Hash right); }
|
MerkleTreeUtils { public static Sha256Hash combineLeftRight(Sha256Hash left, Sha256Hash right) { byte[] leftBytes = left.getBytes(); byte[] rightBytes = right.getBytes(); checkNotAValid64ByteTransaction(leftBytes, rightBytes); return Sha256Hash.wrapReversed( Sha256Hash.hashTwice( reverseBytes(leftBytes), 0, 32, reverseBytes(rightBytes), 0, 32 ) ); } private MerkleTreeUtils(); static Sha256Hash combineLeftRight(Sha256Hash left, Sha256Hash right); }
|
@Test public void calculateBtcTxHash() { BtcTransaction btcTransaction = new BtcTransaction(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); Assert.assertThat(BtcTransactionFormatUtils.calculateBtcTxHash(btcTransaction.bitcoinSerialize()), is(btcTransaction.getHash())); byte[] rawBtcTransaction = Hex.decode("020000000418bc858998739dbb7e7676435178dba5e71157b1537d415518d5c1fce6349018000000006a47304402204317903e40f8736858f87758e6" + "8bf18372bc075bc928fd82aa8e6c03ae8ce9fb022074a59d7449cc753c5a6b10e70db20469076e2a8b950aa44624ee7ff70633f73201210316101490" + "2a3984b695c41627f1403f56b0e631152ff265ddb42e36ba0d57b796feffffff6b853f36edb3a55c419792d3923790147b3c429bb6082d11846ff563" + "edcdae05010000006b483045022100e202a463722821875bcecea315041623b4f4b7c615bc63c85ddcb4185035cc0502201beb9c556c1a672d326e66" + "c4d4b44ac189b7f3296c5ce6128bf9e52f96cfcabc012103a6ba50eaba8d2fc9a638123cf3fe155610cf162253e8cf672f70945fe00fd317feffffff" + "ac932fbdbb882a3947652710b6c9117729962efb30f77779265436f804a5f4bc010000006b483045022100ddc4be4b2d61eb6bdecbb76002cc85c304" + "630465807039f7c9eaf5583d5c6cce02203bc3dc7429a17a92c63b6ec517d82f3964beda7f3c375a388c0326e3db3a455101210366d0e8c0c72ea7e8" + "a48ae9fe525fb51bcea39702b9ba2903758a582e26a7d0b9feffffffe89b208401d4eb6fc01deef1393fe00c1f56e2b86b77268629491894f560adb6" + "010000006b483045022100ac01733d947bf43ad97a5792864766c6c6d9963e359a6e0ab470b68565d679b6022003d4afeb917e7711e797b665f5a958" + "93dea2f53d07e2840b6441a72702f88412012102b005a7d4368c02dc8e5f171765db281f546b99b921eac18b2910c82d38f820f7feffffff02441427" + "010000000017a914056bce3306ec98a0247cebb654809943045d6b51877ff21500000000001976a914f7da7f0f7669bce303cfc48921bb7303e3918b" + "1288acdfdc0700"); Assert.assertThat(BtcTransactionFormatUtils.calculateBtcTxHash(rawBtcTransaction), is(Sha256Hash.wrap("4d63ac307e0daba3597a0d8075facb4e6cba3908a60920259b7447e28a151576"))); }
|
public static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized) { return Sha256Hash.wrapReversed(Sha256Hash.hashTwice(btcTxSerialized)); }
|
BtcTransactionFormatUtils { public static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized) { return Sha256Hash.wrapReversed(Sha256Hash.hashTwice(btcTxSerialized)); } }
|
BtcTransactionFormatUtils { public static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized) { return Sha256Hash.wrapReversed(Sha256Hash.hashTwice(btcTxSerialized)); } }
|
BtcTransactionFormatUtils { public static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized) { return Sha256Hash.wrapReversed(Sha256Hash.hashTwice(btcTxSerialized)); } static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized); static long getInputsCount(byte[] btcTxSerialized); static long getInputsCountForSegwit(byte[] btcTxSerialized); static boolean isBlockHeaderSize(int size, ActivationConfig.ForBlock activations); }
|
BtcTransactionFormatUtils { public static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized) { return Sha256Hash.wrapReversed(Sha256Hash.hashTwice(btcTxSerialized)); } static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized); static long getInputsCount(byte[] btcTxSerialized); static long getInputsCountForSegwit(byte[] btcTxSerialized); static boolean isBlockHeaderSize(int size, ActivationConfig.ForBlock activations); }
|
@Test public void getInputsCount() { BtcTransaction btcTransaction = new BtcTransaction(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); Assert.assertThat(BtcTransactionFormatUtils.getInputsCount(btcTransaction.bitcoinSerialize()), is(0L)); byte[] rawBtcTransaction = Hex.decode("020000000418bc858998739dbb7e7676435178dba5e71157b1537d415518d5c1fce6349018000000006a47304402204317903e40f8736858f87758e6" + "8bf18372bc075bc928fd82aa8e6c03ae8ce9fb022074a59d7449cc753c5a6b10e70db20469076e2a8b950aa44624ee7ff70633f73201210316101490" + "2a3984b695c41627f1403f56b0e631152ff265ddb42e36ba0d57b796feffffff6b853f36edb3a55c419792d3923790147b3c429bb6082d11846ff563" + "edcdae05010000006b483045022100e202a463722821875bcecea315041623b4f4b7c615bc63c85ddcb4185035cc0502201beb9c556c1a672d326e66" + "c4d4b44ac189b7f3296c5ce6128bf9e52f96cfcabc012103a6ba50eaba8d2fc9a638123cf3fe155610cf162253e8cf672f70945fe00fd317feffffff" + "ac932fbdbb882a3947652710b6c9117729962efb30f77779265436f804a5f4bc010000006b483045022100ddc4be4b2d61eb6bdecbb76002cc85c304" + "630465807039f7c9eaf5583d5c6cce02203bc3dc7429a17a92c63b6ec517d82f3964beda7f3c375a388c0326e3db3a455101210366d0e8c0c72ea7e8" + "a48ae9fe525fb51bcea39702b9ba2903758a582e26a7d0b9feffffffe89b208401d4eb6fc01deef1393fe00c1f56e2b86b77268629491894f560adb6" + "010000006b483045022100ac01733d947bf43ad97a5792864766c6c6d9963e359a6e0ab470b68565d679b6022003d4afeb917e7711e797b665f5a958" + "93dea2f53d07e2840b6441a72702f88412012102b005a7d4368c02dc8e5f171765db281f546b99b921eac18b2910c82d38f820f7feffffff02441427" + "010000000017a914056bce3306ec98a0247cebb654809943045d6b51877ff21500000000001976a914f7da7f0f7669bce303cfc48921bb7303e3918b" + "1288acdfdc0700"); Assert.assertThat(BtcTransactionFormatUtils.getInputsCount(rawBtcTransaction), is(4L)); }
|
public static long getInputsCount(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); return inputsCounter.value; }
|
BtcTransactionFormatUtils { public static long getInputsCount(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); return inputsCounter.value; } }
|
BtcTransactionFormatUtils { public static long getInputsCount(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); return inputsCounter.value; } }
|
BtcTransactionFormatUtils { public static long getInputsCount(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); return inputsCounter.value; } static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized); static long getInputsCount(byte[] btcTxSerialized); static long getInputsCountForSegwit(byte[] btcTxSerialized); static boolean isBlockHeaderSize(int size, ActivationConfig.ForBlock activations); }
|
BtcTransactionFormatUtils { public static long getInputsCount(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); return inputsCounter.value; } static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized); static long getInputsCount(byte[] btcTxSerialized); static long getInputsCountForSegwit(byte[] btcTxSerialized); static boolean isBlockHeaderSize(int size, ActivationConfig.ForBlock activations); }
|
@Test public void getInputsCountFromSegwitTx() { String rawTx = "020000000001017001d967a340069c0b169fcbeb9cb6e0d78a27c94a41acbce762abc695aefab10000000017160014c" + "fa63de9979e2a8005e6cb516b86202860ff3971ffffffff0200c2eb0b0000000017a914291a7ddc558810708149a731f39cd3c3" + "a8782cfd870896e1110000000017a91425a2e67511a0207c4387ce8d3eeef498a4782e64870247304402207e0615f440bbc5035" + "1fb5d8839b3fae6c74f652c9ffc9291008f4ea39f9565980220354c734511a0560367b300eecb1a7472317a995462622e06ee91" + "cbe0517c17e1012102e87cd90f3cb0d64eeba797fbb8f8ceaadc09e0128afbaefb0ee9535875ea395400000000"; BtcTransaction tx = new BtcTransaction(BridgeRegTestConstants.getInstance().getBtcParams(), Hex.decode(rawTx)); Assert.assertThat(tx.getInputs().size(), is(1)); Assert.assertThat(BtcTransactionFormatUtils.getInputsCountForSegwit(Hex.decode(rawTx)), is(1L)); }
|
public static long getInputsCountForSegwit(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); if (inputsCounter.value != 0) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 5); if (inputsCounter.value != 1) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 6); return inputsCounter.value; }
|
BtcTransactionFormatUtils { public static long getInputsCountForSegwit(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); if (inputsCounter.value != 0) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 5); if (inputsCounter.value != 1) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 6); return inputsCounter.value; } }
|
BtcTransactionFormatUtils { public static long getInputsCountForSegwit(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); if (inputsCounter.value != 0) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 5); if (inputsCounter.value != 1) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 6); return inputsCounter.value; } }
|
BtcTransactionFormatUtils { public static long getInputsCountForSegwit(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); if (inputsCounter.value != 0) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 5); if (inputsCounter.value != 1) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 6); return inputsCounter.value; } static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized); static long getInputsCount(byte[] btcTxSerialized); static long getInputsCountForSegwit(byte[] btcTxSerialized); static boolean isBlockHeaderSize(int size, ActivationConfig.ForBlock activations); }
|
BtcTransactionFormatUtils { public static long getInputsCountForSegwit(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); if (inputsCounter.value != 0) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 5); if (inputsCounter.value != 1) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 6); return inputsCounter.value; } static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized); static long getInputsCount(byte[] btcTxSerialized); static long getInputsCountForSegwit(byte[] btcTxSerialized); static boolean isBlockHeaderSize(int size, ActivationConfig.ForBlock activations); }
|
@Test public void testEncodeElementZero() { byte[] actuals = encodeElement(new byte[]{0x00}); assertArrayEquals(new byte[]{0x00}, actuals); }
|
public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void getInputsCountFromSegwitTxWithWitness() { String rawTx = "020000000001017001d967a340069c0b169fcbeb9cb6e0d78a27c94a41acbce762abc695aefab10000000017160014c" + "fa63de9979e2a8005e6cb516b86202860ff3971ffffffff0200c2eb0b0000000017a914291a7ddc558810708149a731f39cd3c3" + "a8782cfd870896e1110000000017a91425a2e67511a0207c4387ce8d3eeef498a4782e64870247304402207e0615f440bbc5035" + "1fb5d8839b3fae6c74f652c9ffc9291008f4ea39f9565980220354c734511a0560367b300eecb1a7472317a995462622e06ee91" + "cbe0517c17e1012102e87cd90f3cb0d64eeba797fbb8f8ceaadc09e0128afbaefb0ee9535875ea395400000000"; BtcTransaction otherTx = new BtcTransaction(BridgeRegTestConstants.getInstance().getBtcParams()); otherTx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); TransactionWitness txWit = new TransactionWitness(1); txWit.setPush(0, new byte[]{}); otherTx.setWitness(0, txWit); otherTx.addOutput(Coin.COIN, Address.fromBase58(BridgeRegTestConstants.getInstance().getBtcParams(), "mvbnrCX3bg1cDRUu8pkecrvP6vQkSLDSou")); BtcTransaction tx = new BtcTransaction(BridgeRegTestConstants.getInstance().getBtcParams(), Hex.decode(rawTx)); Assert.assertThat(tx.getInputs().size(), is(1)); Assert.assertThat(BtcTransactionFormatUtils.getInputsCountForSegwit(otherTx.bitcoinSerialize()), is(1L)); }
|
public static long getInputsCountForSegwit(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); if (inputsCounter.value != 0) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 5); if (inputsCounter.value != 1) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 6); return inputsCounter.value; }
|
BtcTransactionFormatUtils { public static long getInputsCountForSegwit(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); if (inputsCounter.value != 0) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 5); if (inputsCounter.value != 1) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 6); return inputsCounter.value; } }
|
BtcTransactionFormatUtils { public static long getInputsCountForSegwit(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); if (inputsCounter.value != 0) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 5); if (inputsCounter.value != 1) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 6); return inputsCounter.value; } }
|
BtcTransactionFormatUtils { public static long getInputsCountForSegwit(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); if (inputsCounter.value != 0) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 5); if (inputsCounter.value != 1) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 6); return inputsCounter.value; } static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized); static long getInputsCount(byte[] btcTxSerialized); static long getInputsCountForSegwit(byte[] btcTxSerialized); static boolean isBlockHeaderSize(int size, ActivationConfig.ForBlock activations); }
|
BtcTransactionFormatUtils { public static long getInputsCountForSegwit(byte[] btcTxSerialized) { VarInt inputsCounter = new VarInt(btcTxSerialized, 4); if (inputsCounter.value != 0) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 5); if (inputsCounter.value != 1) { return -1; } inputsCounter = new VarInt(btcTxSerialized, 6); return inputsCounter.value; } static Sha256Hash calculateBtcTxHash(byte[] btcTxSerialized); static long getInputsCount(byte[] btcTxSerialized); static long getInputsCountForSegwit(byte[] btcTxSerialized); static boolean isBlockHeaderSize(int size, ActivationConfig.ForBlock activations); }
|
@Test public void getHashesCount() { String pmtSerializedEncoded = "030000000279e7c0da739df8a00f12c0bff55e5438f530aa5859ff9874258cd7bad3fe709746aff89" + "7e6a851faa80120d6ae99db30883699ac0428fc7192d6c3fec0ca6409010d"; byte[] pmtSerialized = Hex.decode(pmtSerializedEncoded); Assert.assertThat(PartialMerkleTreeFormatUtils.getHashesCount(pmtSerialized).value, is(2L)); }
|
public static VarInt getHashesCount(byte[] pmtSerialized) { return new VarInt(pmtSerialized, BLOCK_TRANSACTION_COUNT_LENGTH); }
|
PartialMerkleTreeFormatUtils { public static VarInt getHashesCount(byte[] pmtSerialized) { return new VarInt(pmtSerialized, BLOCK_TRANSACTION_COUNT_LENGTH); } }
|
PartialMerkleTreeFormatUtils { public static VarInt getHashesCount(byte[] pmtSerialized) { return new VarInt(pmtSerialized, BLOCK_TRANSACTION_COUNT_LENGTH); } }
|
PartialMerkleTreeFormatUtils { public static VarInt getHashesCount(byte[] pmtSerialized) { return new VarInt(pmtSerialized, BLOCK_TRANSACTION_COUNT_LENGTH); } static VarInt getHashesCount(byte[] pmtSerialized); static VarInt getFlagBitsCount(byte[] pmtSerialized); static boolean hasExpectedSize(byte[] pmtSerialized); static Stream<Sha256Hash> streamIntermediateHashes(byte[] pmtSerialized); }
|
PartialMerkleTreeFormatUtils { public static VarInt getHashesCount(byte[] pmtSerialized) { return new VarInt(pmtSerialized, BLOCK_TRANSACTION_COUNT_LENGTH); } static VarInt getHashesCount(byte[] pmtSerialized); static VarInt getFlagBitsCount(byte[] pmtSerialized); static boolean hasExpectedSize(byte[] pmtSerialized); static Stream<Sha256Hash> streamIntermediateHashes(byte[] pmtSerialized); }
|
@Test public void getFlagBitsCount() { String pmtSerializedEncoded = "030000000279e7c0da739df8a00f12c0bff55e5438f530aa5859ff9874258cd7bad3fe709746aff89" + "7e6a851faa80120d6ae99db30883699ac0428fc7192d6c3fec0ca6409010d"; byte[] pmtSerialized = Hex.decode(pmtSerializedEncoded); Assert.assertThat(PartialMerkleTreeFormatUtils.getFlagBitsCount(pmtSerialized).value, is(1L)); }
|
public static VarInt getFlagBitsCount(byte[] pmtSerialized) { VarInt hashesCount = getHashesCount(pmtSerialized); return new VarInt( pmtSerialized, Math.addExact( BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes(), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ) ); }
|
PartialMerkleTreeFormatUtils { public static VarInt getFlagBitsCount(byte[] pmtSerialized) { VarInt hashesCount = getHashesCount(pmtSerialized); return new VarInt( pmtSerialized, Math.addExact( BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes(), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ) ); } }
|
PartialMerkleTreeFormatUtils { public static VarInt getFlagBitsCount(byte[] pmtSerialized) { VarInt hashesCount = getHashesCount(pmtSerialized); return new VarInt( pmtSerialized, Math.addExact( BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes(), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ) ); } }
|
PartialMerkleTreeFormatUtils { public static VarInt getFlagBitsCount(byte[] pmtSerialized) { VarInt hashesCount = getHashesCount(pmtSerialized); return new VarInt( pmtSerialized, Math.addExact( BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes(), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ) ); } static VarInt getHashesCount(byte[] pmtSerialized); static VarInt getFlagBitsCount(byte[] pmtSerialized); static boolean hasExpectedSize(byte[] pmtSerialized); static Stream<Sha256Hash> streamIntermediateHashes(byte[] pmtSerialized); }
|
PartialMerkleTreeFormatUtils { public static VarInt getFlagBitsCount(byte[] pmtSerialized) { VarInt hashesCount = getHashesCount(pmtSerialized); return new VarInt( pmtSerialized, Math.addExact( BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes(), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ) ); } static VarInt getHashesCount(byte[] pmtSerialized); static VarInt getFlagBitsCount(byte[] pmtSerialized); static boolean hasExpectedSize(byte[] pmtSerialized); static Stream<Sha256Hash> streamIntermediateHashes(byte[] pmtSerialized); }
|
@Test public void hasExpectedSize() { String pmtSerializedEncoded = "030000000279e7c0da739df8a00f12c0bff55e5438f530aa5859ff9874258cd7bad3fe709746aff89" + "7e6a851faa80120d6ae99db30883699ac0428fc7192d6c3fec0ca6409010d"; byte[] pmtSerialized = Hex.decode(pmtSerializedEncoded); Assert.assertThat(PartialMerkleTreeFormatUtils.hasExpectedSize(pmtSerialized), is(true)); }
|
public static boolean hasExpectedSize(byte[] pmtSerialized) { try { VarInt hashesCount = getHashesCount(pmtSerialized); VarInt flagBitsCount = getFlagBitsCount(pmtSerialized); int declaredSize = Math.addExact(Math.addExact(BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes() + flagBitsCount.getOriginalSizeInBytes(), Math.toIntExact(flagBitsCount.value)), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ); return pmtSerialized.length == declaredSize; } catch (RuntimeException e) { return false; } }
|
PartialMerkleTreeFormatUtils { public static boolean hasExpectedSize(byte[] pmtSerialized) { try { VarInt hashesCount = getHashesCount(pmtSerialized); VarInt flagBitsCount = getFlagBitsCount(pmtSerialized); int declaredSize = Math.addExact(Math.addExact(BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes() + flagBitsCount.getOriginalSizeInBytes(), Math.toIntExact(flagBitsCount.value)), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ); return pmtSerialized.length == declaredSize; } catch (RuntimeException e) { return false; } } }
|
PartialMerkleTreeFormatUtils { public static boolean hasExpectedSize(byte[] pmtSerialized) { try { VarInt hashesCount = getHashesCount(pmtSerialized); VarInt flagBitsCount = getFlagBitsCount(pmtSerialized); int declaredSize = Math.addExact(Math.addExact(BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes() + flagBitsCount.getOriginalSizeInBytes(), Math.toIntExact(flagBitsCount.value)), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ); return pmtSerialized.length == declaredSize; } catch (RuntimeException e) { return false; } } }
|
PartialMerkleTreeFormatUtils { public static boolean hasExpectedSize(byte[] pmtSerialized) { try { VarInt hashesCount = getHashesCount(pmtSerialized); VarInt flagBitsCount = getFlagBitsCount(pmtSerialized); int declaredSize = Math.addExact(Math.addExact(BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes() + flagBitsCount.getOriginalSizeInBytes(), Math.toIntExact(flagBitsCount.value)), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ); return pmtSerialized.length == declaredSize; } catch (RuntimeException e) { return false; } } static VarInt getHashesCount(byte[] pmtSerialized); static VarInt getFlagBitsCount(byte[] pmtSerialized); static boolean hasExpectedSize(byte[] pmtSerialized); static Stream<Sha256Hash> streamIntermediateHashes(byte[] pmtSerialized); }
|
PartialMerkleTreeFormatUtils { public static boolean hasExpectedSize(byte[] pmtSerialized) { try { VarInt hashesCount = getHashesCount(pmtSerialized); VarInt flagBitsCount = getFlagBitsCount(pmtSerialized); int declaredSize = Math.addExact(Math.addExact(BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes() + flagBitsCount.getOriginalSizeInBytes(), Math.toIntExact(flagBitsCount.value)), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ); return pmtSerialized.length == declaredSize; } catch (RuntimeException e) { return false; } } static VarInt getHashesCount(byte[] pmtSerialized); static VarInt getFlagBitsCount(byte[] pmtSerialized); static boolean hasExpectedSize(byte[] pmtSerialized); static Stream<Sha256Hash> streamIntermediateHashes(byte[] pmtSerialized); }
|
@Test public void doesntHaveExpectedSize() { String pmtSerializedEncoded = "030000000279e7c0da739df8a00f12c0bff55e5438f530aa5859ff9874258cd7bad3fe709746aff89" + "7e6a851faa80120d6ae99db30883699ac0428fc7192d6c3fec0ca64010d"; byte[] pmtSerialized = Hex.decode(pmtSerializedEncoded); Assert.assertThat(PartialMerkleTreeFormatUtils.hasExpectedSize(pmtSerialized), is(false)); }
|
public static boolean hasExpectedSize(byte[] pmtSerialized) { try { VarInt hashesCount = getHashesCount(pmtSerialized); VarInt flagBitsCount = getFlagBitsCount(pmtSerialized); int declaredSize = Math.addExact(Math.addExact(BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes() + flagBitsCount.getOriginalSizeInBytes(), Math.toIntExact(flagBitsCount.value)), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ); return pmtSerialized.length == declaredSize; } catch (RuntimeException e) { return false; } }
|
PartialMerkleTreeFormatUtils { public static boolean hasExpectedSize(byte[] pmtSerialized) { try { VarInt hashesCount = getHashesCount(pmtSerialized); VarInt flagBitsCount = getFlagBitsCount(pmtSerialized); int declaredSize = Math.addExact(Math.addExact(BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes() + flagBitsCount.getOriginalSizeInBytes(), Math.toIntExact(flagBitsCount.value)), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ); return pmtSerialized.length == declaredSize; } catch (RuntimeException e) { return false; } } }
|
PartialMerkleTreeFormatUtils { public static boolean hasExpectedSize(byte[] pmtSerialized) { try { VarInt hashesCount = getHashesCount(pmtSerialized); VarInt flagBitsCount = getFlagBitsCount(pmtSerialized); int declaredSize = Math.addExact(Math.addExact(BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes() + flagBitsCount.getOriginalSizeInBytes(), Math.toIntExact(flagBitsCount.value)), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ); return pmtSerialized.length == declaredSize; } catch (RuntimeException e) { return false; } } }
|
PartialMerkleTreeFormatUtils { public static boolean hasExpectedSize(byte[] pmtSerialized) { try { VarInt hashesCount = getHashesCount(pmtSerialized); VarInt flagBitsCount = getFlagBitsCount(pmtSerialized); int declaredSize = Math.addExact(Math.addExact(BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes() + flagBitsCount.getOriginalSizeInBytes(), Math.toIntExact(flagBitsCount.value)), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ); return pmtSerialized.length == declaredSize; } catch (RuntimeException e) { return false; } } static VarInt getHashesCount(byte[] pmtSerialized); static VarInt getFlagBitsCount(byte[] pmtSerialized); static boolean hasExpectedSize(byte[] pmtSerialized); static Stream<Sha256Hash> streamIntermediateHashes(byte[] pmtSerialized); }
|
PartialMerkleTreeFormatUtils { public static boolean hasExpectedSize(byte[] pmtSerialized) { try { VarInt hashesCount = getHashesCount(pmtSerialized); VarInt flagBitsCount = getFlagBitsCount(pmtSerialized); int declaredSize = Math.addExact(Math.addExact(BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes() + flagBitsCount.getOriginalSizeInBytes(), Math.toIntExact(flagBitsCount.value)), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ); return pmtSerialized.length == declaredSize; } catch (RuntimeException e) { return false; } } static VarInt getHashesCount(byte[] pmtSerialized); static VarInt getFlagBitsCount(byte[] pmtSerialized); static boolean hasExpectedSize(byte[] pmtSerialized); static Stream<Sha256Hash> streamIntermediateHashes(byte[] pmtSerialized); }
|
@Test(expected = ArithmeticException.class) public void overflowSize() { String pmtSerializedEncoded = "0300ffffff79e7c0da739df8a00f12c0bff55e5438f530aa5859ff9874258cd7bad3fe709746aff89" + "7e6a851faa80120d6ae99db30883699ac0428fc7192d6c3fec0ca6409010d"; byte[] pmtSerialized = Hex.decode(pmtSerializedEncoded); PartialMerkleTreeFormatUtils.getFlagBitsCount(pmtSerialized); }
|
public static VarInt getFlagBitsCount(byte[] pmtSerialized) { VarInt hashesCount = getHashesCount(pmtSerialized); return new VarInt( pmtSerialized, Math.addExact( BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes(), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ) ); }
|
PartialMerkleTreeFormatUtils { public static VarInt getFlagBitsCount(byte[] pmtSerialized) { VarInt hashesCount = getHashesCount(pmtSerialized); return new VarInt( pmtSerialized, Math.addExact( BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes(), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ) ); } }
|
PartialMerkleTreeFormatUtils { public static VarInt getFlagBitsCount(byte[] pmtSerialized) { VarInt hashesCount = getHashesCount(pmtSerialized); return new VarInt( pmtSerialized, Math.addExact( BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes(), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ) ); } }
|
PartialMerkleTreeFormatUtils { public static VarInt getFlagBitsCount(byte[] pmtSerialized) { VarInt hashesCount = getHashesCount(pmtSerialized); return new VarInt( pmtSerialized, Math.addExact( BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes(), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ) ); } static VarInt getHashesCount(byte[] pmtSerialized); static VarInt getFlagBitsCount(byte[] pmtSerialized); static boolean hasExpectedSize(byte[] pmtSerialized); static Stream<Sha256Hash> streamIntermediateHashes(byte[] pmtSerialized); }
|
PartialMerkleTreeFormatUtils { public static VarInt getFlagBitsCount(byte[] pmtSerialized) { VarInt hashesCount = getHashesCount(pmtSerialized); return new VarInt( pmtSerialized, Math.addExact( BLOCK_TRANSACTION_COUNT_LENGTH + hashesCount.getOriginalSizeInBytes(), Math.multiplyExact(Math.toIntExact(hashesCount.value), Sha256Hash.LENGTH) ) ); } static VarInt getHashesCount(byte[] pmtSerialized); static VarInt getFlagBitsCount(byte[] pmtSerialized); static boolean hasExpectedSize(byte[] pmtSerialized); static Stream<Sha256Hash> streamIntermediateHashes(byte[] pmtSerialized); }
|
@Test public void logLockBtc() { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); List<LogInfo> eventLogs = new LinkedList<>(); BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(null, activations, eventLogs); Address senderAddress = mock(Address.class); when(senderAddress.toString()).thenReturn("mixzLp4xx5bUsHuYUEyPpL42BzEDp8kSTv"); RskAddress rskAddress = mock(RskAddress.class); when(rskAddress.toString()).thenReturn("0x00000000000000000000000000000000000000"); BtcTransaction mockedTx = mock(BtcTransaction.class); when(mockedTx.getHash()).thenReturn(PegTestUtils.createHash(0)); Coin amount = Coin.SATOSHI; eventLogger.logLockBtc(rskAddress, mockedTx, senderAddress, amount); Assert.assertEquals(1, eventLogs.size()); LogInfo logResult = eventLogs.get(0); CallTransaction.Function event = BridgeEvents.LOCK_BTC.getEvent(); Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(logResult.getAddress())); Assert.assertEquals(2, logResult.getTopics().size()); byte[][] topics = event.encodeEventTopics(rskAddress.toString()); for (int i=0; i<topics.length; i++) { Assert.assertArrayEquals(topics[i], logResult.getTopics().get(i).getData()); } byte[] encodedData = event.encodeEventData(mockedTx.getHash().getBytes(), senderAddress.toString(), amount.getValue()); Assert.assertArrayEquals(encodedData, logResult.getData()); }
|
public void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount) { CallTransaction.Function event = BridgeEvents.LOCK_BTC.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(receiver.toString()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(btcTx.getHash().getBytes(), senderBtcAddress.toString(), amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount) { CallTransaction.Function event = BridgeEvents.LOCK_BTC.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(receiver.toString()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(btcTx.getHash().getBytes(), senderBtcAddress.toString(), amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount) { CallTransaction.Function event = BridgeEvents.LOCK_BTC.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(receiver.toString()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(btcTx.getHash().getBytes(), senderBtcAddress.toString(), amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount) { CallTransaction.Function event = BridgeEvents.LOCK_BTC.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(receiver.toString()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(btcTx.getHash().getBytes(), senderBtcAddress.toString(), amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount) { CallTransaction.Function event = BridgeEvents.LOCK_BTC.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(receiver.toString()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(btcTx.getHash().getBytes(), senderBtcAddress.toString(), amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
@Test public void logLockBtc_with_segwit_address() { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); List<LogInfo> eventLogs = new LinkedList<>(); BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(null, activations, eventLogs); BridgeConstants constants = BridgeRegTestConstants.getInstance(); Address senderAddress = new Address(constants.getBtcParams(), constants.getBtcParams().getP2SHHeader(), Hex.decode("c99a8f22127007255b4a9d8d57b0892ae2103f2d")); RskAddress rskAddress = mock(RskAddress.class); when(rskAddress.toString()).thenReturn("0x00000000000000000000000000000000000000"); BtcTransaction mockedTx = mock(BtcTransaction.class); when(mockedTx.getHash()).thenReturn(PegTestUtils.createHash(0)); Coin amount = Coin.SATOSHI; eventLogger.logLockBtc(rskAddress, mockedTx, senderAddress, amount); Assert.assertEquals(1, eventLogs.size()); LogInfo logResult = eventLogs.get(0); CallTransaction.Function event = BridgeEvents.LOCK_BTC.getEvent(); Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(logResult.getAddress())); Assert.assertEquals(2, logResult.getTopics().size()); byte[][] topics = event.encodeEventTopics(rskAddress.toString()); for (int i=0; i<topics.length; i++) { Assert.assertArrayEquals(topics[i], logResult.getTopics().get(i).getData()); } byte[] encodedData = event.encodeEventData(mockedTx.getHash().getBytes(), "2NBdCxoCY6wx1NHpwGWfJThHk9K2tVdNx1A", amount.getValue()); Assert.assertArrayEquals(encodedData, logResult.getData()); }
|
public void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount) { CallTransaction.Function event = BridgeEvents.LOCK_BTC.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(receiver.toString()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(btcTx.getHash().getBytes(), senderBtcAddress.toString(), amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount) { CallTransaction.Function event = BridgeEvents.LOCK_BTC.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(receiver.toString()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(btcTx.getHash().getBytes(), senderBtcAddress.toString(), amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount) { CallTransaction.Function event = BridgeEvents.LOCK_BTC.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(receiver.toString()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(btcTx.getHash().getBytes(), senderBtcAddress.toString(), amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount) { CallTransaction.Function event = BridgeEvents.LOCK_BTC.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(receiver.toString()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(btcTx.getHash().getBytes(), senderBtcAddress.toString(), amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount) { CallTransaction.Function event = BridgeEvents.LOCK_BTC.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(receiver.toString()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(btcTx.getHash().getBytes(), senderBtcAddress.toString(), amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
@Test public void logUpdateCollectionsBeforeRskip146HardFork() { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); List<LogInfo> eventLogs = new LinkedList<>(); when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(false); BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(null, activations, eventLogs); Transaction tx = mock(Transaction.class); RskAddress sender = mock(RskAddress.class); when(sender.toString()).thenReturn("0x0000000000000000000000000000000000000001"); when(tx.getSender()).thenReturn(sender); eventLogger.logUpdateCollections(tx); Assert.assertEquals(1, eventLogs.size()); LogInfo logResult = eventLogs.get(0); Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(logResult.getAddress())); Assert.assertEquals(1, logResult.getTopics().size()); List<DataWord> topics = Collections.singletonList(Bridge.UPDATE_COLLECTIONS_TOPIC); for (int i=0; i<topics.size(); i++) { Assert.assertEquals(topics.get(i), logResult.getTopics().get(i)); } byte[] encodedData = RLP.encodeElement(tx.getSender().getBytes()); Assert.assertArrayEquals(encodedData, logResult.getData()); }
|
public void logUpdateCollections(Transaction rskTx) { if (activations.isActive(ConsensusRule.RSKIP146)) { logUpdateCollectionsInSolidityFormat(rskTx); } else { logUpdateCollectionsInRLPFormat(rskTx); } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logUpdateCollections(Transaction rskTx) { if (activations.isActive(ConsensusRule.RSKIP146)) { logUpdateCollectionsInSolidityFormat(rskTx); } else { logUpdateCollectionsInRLPFormat(rskTx); } } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logUpdateCollections(Transaction rskTx) { if (activations.isActive(ConsensusRule.RSKIP146)) { logUpdateCollectionsInSolidityFormat(rskTx); } else { logUpdateCollectionsInRLPFormat(rskTx); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logUpdateCollections(Transaction rskTx) { if (activations.isActive(ConsensusRule.RSKIP146)) { logUpdateCollectionsInSolidityFormat(rskTx); } else { logUpdateCollectionsInRLPFormat(rskTx); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logUpdateCollections(Transaction rskTx) { if (activations.isActive(ConsensusRule.RSKIP146)) { logUpdateCollectionsInSolidityFormat(rskTx); } else { logUpdateCollectionsInRLPFormat(rskTx); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
@Test public void logUpdateCollectionsAfterRskip146HardFork() { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); List<LogInfo> eventLogs = new LinkedList<>(); when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(true); BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(null, activations, eventLogs); Transaction tx = mock(Transaction.class); RskAddress sender = mock(RskAddress.class); when(sender.toString()).thenReturn("0x0000000000000000000000000000000000000001"); when(tx.getSender()).thenReturn(sender); eventLogger.logUpdateCollections(tx); Assert.assertEquals(1, eventLogs.size()); LogInfo logResult = eventLogs.get(0); CallTransaction.Function event = BridgeEvents.UPDATE_COLLECTIONS.getEvent(); Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(logResult.getAddress())); Assert.assertEquals(1, logResult.getTopics().size()); byte[][] topics = event.encodeEventTopics(); for (int i=0; i<topics.length; i++) { Assert.assertArrayEquals(topics[i], logResult.getTopics().get(i).getData()); } byte[] encodedData = event.encodeEventData(tx.getSender().toString()); Assert.assertArrayEquals(encodedData, logResult.getData()); }
|
public void logUpdateCollections(Transaction rskTx) { if (activations.isActive(ConsensusRule.RSKIP146)) { logUpdateCollectionsInSolidityFormat(rskTx); } else { logUpdateCollectionsInRLPFormat(rskTx); } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logUpdateCollections(Transaction rskTx) { if (activations.isActive(ConsensusRule.RSKIP146)) { logUpdateCollectionsInSolidityFormat(rskTx); } else { logUpdateCollectionsInRLPFormat(rskTx); } } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logUpdateCollections(Transaction rskTx) { if (activations.isActive(ConsensusRule.RSKIP146)) { logUpdateCollectionsInSolidityFormat(rskTx); } else { logUpdateCollectionsInRLPFormat(rskTx); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logUpdateCollections(Transaction rskTx) { if (activations.isActive(ConsensusRule.RSKIP146)) { logUpdateCollectionsInSolidityFormat(rskTx); } else { logUpdateCollectionsInRLPFormat(rskTx); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logUpdateCollections(Transaction rskTx) { if (activations.isActive(ConsensusRule.RSKIP146)) { logUpdateCollectionsInSolidityFormat(rskTx); } else { logUpdateCollectionsInRLPFormat(rskTx); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
@Test public void testEncodeElementOne() { byte[] actuals = encodeElement(new byte[]{0x01}); assertArrayEquals(new byte[]{(byte) 0x01}, actuals); }
|
public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void logAddSignatureBeforeRskip146HardFork() { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); List<LogInfo> eventLogs = new LinkedList<>(); when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(false); BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(null, activations, eventLogs); BtcECKey federatorPubKey = BtcECKey.fromPrivate(BigInteger.valueOf(2L)); BtcTransaction btcTx = mock(BtcTransaction.class); Keccak256 rskTxHash = PegTestUtils.createHash3(1); when(btcTx.getHashAsString()).thenReturn("3e72fdbae7bbd103f08e876c765e3d5ba35db30ea46cb45ab52803f987ead9fb"); eventLogger.logAddSignature(federatorPubKey, btcTx, rskTxHash.getBytes()); Assert.assertEquals(1, eventLogs.size()); LogInfo logResult = eventLogs.get(0); Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(logResult.getAddress())); Assert.assertEquals(1, logResult.getTopics().size()); Assert.assertEquals(Bridge.ADD_SIGNATURE_TOPIC, logResult.getTopics().get(0)); Assert.assertNotNull(logResult.getData()); List<RLPElement> rlpData = RLP.decode2(logResult.getData()); Assert.assertEquals(1, rlpData.size()); RLPList dataList = (RLPList) rlpData.get(0); Assert.assertEquals(3, dataList.size()); Assert.assertArrayEquals(btcTx.getHashAsString().getBytes(), dataList.get(0).getRLPData()); Assert.assertArrayEquals(federatorPubKey.getPubKeyHash(), dataList.get(1).getRLPData()); Assert.assertArrayEquals(rskTxHash.getBytes(), dataList.get(2).getRLPData()); }
|
public void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { ECKey key = ECKey.fromPublicOnly(federatorPublicKey.getPubKey()); String federatorRskAddress = ByteUtil.toHexString(key.getAddress()); logAddSignatureInSolidityFormat(rskTxHash, federatorRskAddress, federatorPublicKey); } else { logAddSignatureInRLPFormat(federatorPublicKey, btcTx, rskTxHash); } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { ECKey key = ECKey.fromPublicOnly(federatorPublicKey.getPubKey()); String federatorRskAddress = ByteUtil.toHexString(key.getAddress()); logAddSignatureInSolidityFormat(rskTxHash, federatorRskAddress, federatorPublicKey); } else { logAddSignatureInRLPFormat(federatorPublicKey, btcTx, rskTxHash); } } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { ECKey key = ECKey.fromPublicOnly(federatorPublicKey.getPubKey()); String federatorRskAddress = ByteUtil.toHexString(key.getAddress()); logAddSignatureInSolidityFormat(rskTxHash, federatorRskAddress, federatorPublicKey); } else { logAddSignatureInRLPFormat(federatorPublicKey, btcTx, rskTxHash); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { ECKey key = ECKey.fromPublicOnly(federatorPublicKey.getPubKey()); String federatorRskAddress = ByteUtil.toHexString(key.getAddress()); logAddSignatureInSolidityFormat(rskTxHash, federatorRskAddress, federatorPublicKey); } else { logAddSignatureInRLPFormat(federatorPublicKey, btcTx, rskTxHash); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { ECKey key = ECKey.fromPublicOnly(federatorPublicKey.getPubKey()); String federatorRskAddress = ByteUtil.toHexString(key.getAddress()); logAddSignatureInSolidityFormat(rskTxHash, federatorRskAddress, federatorPublicKey); } else { logAddSignatureInRLPFormat(federatorPublicKey, btcTx, rskTxHash); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
@Test public void logAddSignatureAfterRskip146HardFork() { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); List<LogInfo> eventLogs = new LinkedList<>(); when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(true); BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(null, activations, eventLogs); BtcECKey federatorPubKey = BtcECKey.fromPrivate(BigInteger.valueOf(2L)); BtcTransaction btcTx = mock(BtcTransaction.class); Keccak256 rskTxHash = PegTestUtils.createHash3(1); when(btcTx.getHashAsString()).thenReturn("3e72fdbae7bbd103f08e876c765e3d5ba35db30ea46cb45ab52803f987ead9fb"); eventLogger.logAddSignature(federatorPubKey, btcTx, rskTxHash.getBytes()); Assert.assertEquals(1, eventLogs.size()); LogInfo logResult = eventLogs.get(0); CallTransaction.Function event = BridgeEvents.ADD_SIGNATURE.getEvent(); Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(logResult.getAddress())); Assert.assertEquals(3, logResult.getTopics().size()); ECKey key = ECKey.fromPublicOnly(federatorPubKey.getPubKey()); String federatorRskAddress = ByteUtil.toHexString(key.getAddress()); byte[][] topics = event.encodeEventTopics(rskTxHash.getBytes(), federatorRskAddress); for (int i=0; i<topics.length; i++) { Assert.assertArrayEquals(topics[i], logResult.getTopics().get(i).getData()); } byte[] encodedData = event.encodeEventData(federatorPubKey.getPubKey()); Assert.assertArrayEquals(encodedData, logResult.getData()); }
|
public void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { ECKey key = ECKey.fromPublicOnly(federatorPublicKey.getPubKey()); String federatorRskAddress = ByteUtil.toHexString(key.getAddress()); logAddSignatureInSolidityFormat(rskTxHash, federatorRskAddress, federatorPublicKey); } else { logAddSignatureInRLPFormat(federatorPublicKey, btcTx, rskTxHash); } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { ECKey key = ECKey.fromPublicOnly(federatorPublicKey.getPubKey()); String federatorRskAddress = ByteUtil.toHexString(key.getAddress()); logAddSignatureInSolidityFormat(rskTxHash, federatorRskAddress, federatorPublicKey); } else { logAddSignatureInRLPFormat(federatorPublicKey, btcTx, rskTxHash); } } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { ECKey key = ECKey.fromPublicOnly(federatorPublicKey.getPubKey()); String federatorRskAddress = ByteUtil.toHexString(key.getAddress()); logAddSignatureInSolidityFormat(rskTxHash, federatorRskAddress, federatorPublicKey); } else { logAddSignatureInRLPFormat(federatorPublicKey, btcTx, rskTxHash); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { ECKey key = ECKey.fromPublicOnly(federatorPublicKey.getPubKey()); String federatorRskAddress = ByteUtil.toHexString(key.getAddress()); logAddSignatureInSolidityFormat(rskTxHash, federatorRskAddress, federatorPublicKey); } else { logAddSignatureInRLPFormat(federatorPublicKey, btcTx, rskTxHash); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { ECKey key = ECKey.fromPublicOnly(federatorPublicKey.getPubKey()); String federatorRskAddress = ByteUtil.toHexString(key.getAddress()); logAddSignatureInSolidityFormat(rskTxHash, federatorRskAddress, federatorPublicKey); } else { logAddSignatureInRLPFormat(federatorPublicKey, btcTx, rskTxHash); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
@Test public void logReleaseBtcBeforeRskip146() { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); List<LogInfo> eventLogs = new LinkedList<>(); when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(false); BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(null, activations, eventLogs); BtcTransaction btcTx = new BtcTransaction(BridgeRegTestConstants.getInstance().getBtcParams()); Keccak256 rskTxHash = PegTestUtils.createHash3(1); eventLogger.logReleaseBtc(btcTx, rskTxHash.getBytes()); Assert.assertEquals(1, eventLogs.size()); LogInfo logResult = eventLogs.get(0); Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(logResult.getAddress())); Assert.assertEquals(1, logResult.getTopics().size()); List<DataWord> topics = Collections.singletonList(Bridge.RELEASE_BTC_TOPIC); for (int i=0; i<topics.size(); i++) { Assert.assertEquals(topics.get(i), logResult.getTopics().get(i)); } byte[] encodedData = RLP.encodeList(RLP.encodeString(btcTx.getHashAsString()), RLP.encodeElement(btcTx.bitcoinSerialize())); Assert.assertArrayEquals(encodedData, logResult.getData()); }
|
public void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { logReleaseBtcInSolidityFormat(btcTx, rskTxHash); } else { logReleaseBtcInRLPFormat(btcTx); } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { logReleaseBtcInSolidityFormat(btcTx, rskTxHash); } else { logReleaseBtcInRLPFormat(btcTx); } } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { logReleaseBtcInSolidityFormat(btcTx, rskTxHash); } else { logReleaseBtcInRLPFormat(btcTx); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { logReleaseBtcInSolidityFormat(btcTx, rskTxHash); } else { logReleaseBtcInRLPFormat(btcTx); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { logReleaseBtcInSolidityFormat(btcTx, rskTxHash); } else { logReleaseBtcInRLPFormat(btcTx); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
@Test public void logReleaseBtcAfterRskip146() { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); List<LogInfo> eventLogs = new LinkedList<>(); when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(true); BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(null, activations, eventLogs); BtcTransaction btcTx = new BtcTransaction(BridgeRegTestConstants.getInstance().getBtcParams()); Keccak256 rskTxHash = PegTestUtils.createHash3(1); eventLogger.logReleaseBtc(btcTx, rskTxHash.getBytes()); Assert.assertEquals(1, eventLogs.size()); LogInfo logResult = eventLogs.get(0); CallTransaction.Function event = BridgeEvents.RELEASE_BTC.getEvent(); Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(logResult.getAddress())); Assert.assertEquals(2, logResult.getTopics().size()); byte[][] topics = event.encodeEventTopics(rskTxHash.getBytes()); for (int i=0; i<topics.length; i++) { Assert.assertArrayEquals(topics[i], logResult.getTopics().get(i).getData()); } byte[] encodedData = event.encodeEventData(btcTx.bitcoinSerialize()); Assert.assertArrayEquals(encodedData, logResult.getData()); }
|
public void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { logReleaseBtcInSolidityFormat(btcTx, rskTxHash); } else { logReleaseBtcInRLPFormat(btcTx); } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { logReleaseBtcInSolidityFormat(btcTx, rskTxHash); } else { logReleaseBtcInRLPFormat(btcTx); } } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { logReleaseBtcInSolidityFormat(btcTx, rskTxHash); } else { logReleaseBtcInRLPFormat(btcTx); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { logReleaseBtcInSolidityFormat(btcTx, rskTxHash); } else { logReleaseBtcInRLPFormat(btcTx); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash) { if (activations.isActive(ConsensusRule.RSKIP146)) { logReleaseBtcInSolidityFormat(btcTx, rskTxHash); } else { logReleaseBtcInRLPFormat(btcTx); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
@Test public void logCommitFederationBeforeRskip146() { BridgeConstants constantsMock = mock(BridgeConstants.class); ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); List<LogInfo> eventLogs = new LinkedList<>(); when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(false); when(constantsMock.getFederationActivationAge()).thenReturn(BridgeRegTestConstants.getInstance().getFederationActivationAge()); BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(constantsMock, activations, eventLogs); Block executionBlock = mock(Block.class); when(executionBlock.getTimestamp()).thenReturn(15005L); when(executionBlock.getNumber()).thenReturn(15L); List<BtcECKey> oldFederationKeys = Arrays.asList( BtcECKey.fromPublicOnly(Hex.decode("036bb9eab797eadc8b697f0e82a01d01cabbfaaca37e5bafc06fdc6fdd38af894a")), BtcECKey.fromPublicOnly(Hex.decode("031da807c71c2f303b7f409dd2605b297ac494a563be3b9ca5f52d95a43d183cc5")), BtcECKey.fromPublicOnly(Hex.decode("025eefeeeed5cdc40822880c7db1d0a88b7b986945ed3fc05a0b45fe166fe85e12")), BtcECKey.fromPublicOnly(Hex.decode("03c67ad63527012fd4776ae892b5dc8c56f80f1be002dc65cd520a2efb64e37b49")) ); List<FederationMember> oldFederationMembers = FederationTestUtils.getFederationMembersWithBtcKeys(oldFederationKeys); Federation oldFederation = new Federation(oldFederationMembers, Instant.ofEpochMilli(15005L), 15L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); List<BtcECKey> newFederationKeys = Arrays.asList( BtcECKey.fromPublicOnly(Hex.decode("0346cb6b905e4dee49a862eeb2288217d06afcd4ace4b5ca77ebedfbc6afc1c19d")), BtcECKey.fromPublicOnly(Hex.decode("0269a0dbe7b8f84d1b399103c466fb20531a56b1ad3a7b44fe419e74aad8c46db7")), BtcECKey.fromPublicOnly(Hex.decode("026192d8ab41bd402eb0431457f6756a3f3ce15c955c534d2b87f1e0372d8ba338")) ); List<FederationMember> newFederationMembers = FederationTestUtils.getFederationMembersWithBtcKeys(newFederationKeys); Federation newFederation = new Federation( newFederationMembers, Instant.ofEpochMilli(5005L), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST) ); eventLogger.logCommitFederation(executionBlock, oldFederation, newFederation); Assert.assertEquals(1, eventLogs.size()); LogInfo logResult = eventLogs.get(0); Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(logResult.getAddress())); Assert.assertEquals(1, logResult.getTopics().size()); Assert.assertEquals(Bridge.COMMIT_FEDERATION_TOPIC, logResult.getTopics().get(0)); Assert.assertNotNull(logResult.getData()); List<RLPElement> rlpData = RLP.decode2(logResult.getData()); Assert.assertEquals(1 , rlpData.size()); RLPList dataList = (RLPList)rlpData.get(0); Assert.assertEquals(3, dataList.size()); RLPList oldFedData = (RLPList) dataList.get(0); Assert.assertEquals(2, oldFedData.size()); Assert.assertArrayEquals(oldFederation.getAddress().getHash160(), oldFedData.get(0).getRLPData()); RLPList oldFedPubKeys = (RLPList) oldFedData.get(1); Assert.assertEquals(4, oldFedPubKeys.size()); for(int i = 0; i < 4; i++) { Assert.assertEquals(oldFederation.getBtcPublicKeys().get(i), BtcECKey.fromPublicOnly(oldFedPubKeys.get(i).getRLPData())); } RLPList newFedData = (RLPList) dataList.get(1); Assert.assertEquals(2, newFedData.size()); Assert.assertArrayEquals(newFederation.getAddress().getHash160(), newFedData.get(0).getRLPData()); RLPList newFedPubKeys = (RLPList) newFedData.get(1); Assert.assertEquals(3, newFedPubKeys.size()); for(int i = 0; i < 3; i++) { Assert.assertEquals(newFederation.getBtcPublicKeys().get(i), BtcECKey.fromPublicOnly(newFedPubKeys.get(i).getRLPData())); } Assert.assertEquals(15L + BridgeRegTestConstants.getInstance().getFederationActivationAge(), Long.valueOf(new String(dataList.get(2).getRLPData(), StandardCharsets.UTF_8)).longValue()); }
|
public void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation) { if (activations.isActive(ConsensusRule.RSKIP146)) { logCommitFederationInSolidityFormat(executionBlock, oldFederation, newFederation); } else { logCommitFederationInRLPFormat(executionBlock, oldFederation, newFederation); } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation) { if (activations.isActive(ConsensusRule.RSKIP146)) { logCommitFederationInSolidityFormat(executionBlock, oldFederation, newFederation); } else { logCommitFederationInRLPFormat(executionBlock, oldFederation, newFederation); } } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation) { if (activations.isActive(ConsensusRule.RSKIP146)) { logCommitFederationInSolidityFormat(executionBlock, oldFederation, newFederation); } else { logCommitFederationInRLPFormat(executionBlock, oldFederation, newFederation); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation) { if (activations.isActive(ConsensusRule.RSKIP146)) { logCommitFederationInSolidityFormat(executionBlock, oldFederation, newFederation); } else { logCommitFederationInRLPFormat(executionBlock, oldFederation, newFederation); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation) { if (activations.isActive(ConsensusRule.RSKIP146)) { logCommitFederationInSolidityFormat(executionBlock, oldFederation, newFederation); } else { logCommitFederationInRLPFormat(executionBlock, oldFederation, newFederation); } } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
@Test public void logReleaseBtcRequested() { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); List<LogInfo> eventLogs = new LinkedList<>(); when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(true); BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(null, activations, eventLogs); Keccak256 rskTxHash = PegTestUtils.createHash3(0); BtcTransaction btcTx = new BtcTransaction(BridgeRegTestConstants.getInstance().getBtcParams()); Coin amount = Coin.SATOSHI; eventLogger.logReleaseBtcRequested(rskTxHash.getBytes(), btcTx, amount); Assert.assertEquals(1, eventLogs.size()); LogInfo entry = eventLogs.get(0); Assert.assertEquals(PrecompiledContracts.BRIDGE_ADDR, new RskAddress(entry.getAddress())); LogInfo result = eventLogs.get(0); Assert.assertArrayEquals(PrecompiledContracts.BRIDGE_ADDR.getBytes(), result.getAddress()); Assert.assertEquals(3, result.getTopics().size()); CallTransaction.Function event = BridgeEvents.RELEASE_REQUESTED.getEvent(); byte[][] topics = event.encodeEventTopics(rskTxHash.getBytes(), btcTx.getHash().getBytes()); for (int i=0; i<topics.length; i++) { Assert.assertArrayEquals(topics[i], result.getTopics().get(i).getData()); } Assert.assertArrayEquals(event.encodeEventData(amount.getValue()), result.getData()); }
|
public void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount) { CallTransaction.Function event = BridgeEvents.RELEASE_REQUESTED.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(rskTransactionHash, btcTx.getHash().getBytes()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount) { CallTransaction.Function event = BridgeEvents.RELEASE_REQUESTED.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(rskTransactionHash, btcTx.getHash().getBytes()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); } }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount) { CallTransaction.Function event = BridgeEvents.RELEASE_REQUESTED.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(rskTransactionHash, btcTx.getHash().getBytes()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount) { CallTransaction.Function event = BridgeEvents.RELEASE_REQUESTED.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(rskTransactionHash, btcTx.getHash().getBytes()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
BridgeEventLoggerImpl implements BridgeEventLogger { public void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount) { CallTransaction.Function event = BridgeEvents.RELEASE_REQUESTED.getEvent(); byte[][] encodedTopicsInBytes = event.encodeEventTopics(rskTransactionHash, btcTx.getHash().getBytes()); List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes); byte[] encodedData = event.encodeEventData(amount.getValue()); this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData)); } BridgeEventLoggerImpl(BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations, List<LogInfo> logs); void logUpdateCollections(Transaction rskTx); void logAddSignature(BtcECKey federatorPublicKey, BtcTransaction btcTx, byte[] rskTxHash); void logReleaseBtc(BtcTransaction btcTx, byte[] rskTxHash); void logCommitFederation(Block executionBlock, Federation oldFederation, Federation newFederation); void logLockBtc(RskAddress receiver, BtcTransaction btcTx, Address senderBtcAddress, Coin amount); void logReleaseBtcRequested(byte[] rskTransactionHash, BtcTransaction btcTx, Coin amount); }
|
@Test public void add() { Assert.assertFalse(queue.getEntries().contains(new ReleaseRequestQueue.Entry(mockAddress(10), Coin.valueOf(10)))); queue.add(mockAddress(10), Coin.valueOf(10), null); Assert.assertTrue(queue.getEntries().contains(new ReleaseRequestQueue.Entry(mockAddress(10), Coin.valueOf(10)))); }
|
public void add(Address destination, Coin amount, Keccak256 rskTxHash) { entries.add(new Entry(destination, amount, rskTxHash)); }
|
ReleaseRequestQueue { public void add(Address destination, Coin amount, Keccak256 rskTxHash) { entries.add(new Entry(destination, amount, rskTxHash)); } }
|
ReleaseRequestQueue { public void add(Address destination, Coin amount, Keccak256 rskTxHash) { entries.add(new Entry(destination, amount, rskTxHash)); } ReleaseRequestQueue(List<Entry> entries); }
|
ReleaseRequestQueue { public void add(Address destination, Coin amount, Keccak256 rskTxHash) { entries.add(new Entry(destination, amount, rskTxHash)); } ReleaseRequestQueue(List<Entry> entries); List<Entry> getEntriesWithoutHash(); List<Entry> getEntriesWithHash(); List<Entry> getEntries(); void add(Address destination, Coin amount, Keccak256 rskTxHash); void add(Address destination, Coin amount); void process(int maxIterations, Processor processor); }
|
ReleaseRequestQueue { public void add(Address destination, Coin amount, Keccak256 rskTxHash) { entries.add(new Entry(destination, amount, rskTxHash)); } ReleaseRequestQueue(List<Entry> entries); List<Entry> getEntriesWithoutHash(); List<Entry> getEntriesWithHash(); List<Entry> getEntries(); void add(Address destination, Coin amount, Keccak256 rskTxHash); void add(Address destination, Coin amount); void process(int maxIterations, Processor processor); }
|
@Test public void process() { class Indexer { public int index = 0; } Indexer idx = new Indexer(); queue.process(30, entry -> { assertEquals(entry, queueEntries.get(idx.index)); return idx.index++ % 2 == 0; }); assertEquals(5, idx.index); assertEquals(Arrays.asList( new ReleaseRequestQueue.Entry(mockAddress(5), Coin.COIN), new ReleaseRequestQueue.Entry(mockAddress(3), Coin.MILLICOIN) ), queue.getEntries()); }
|
public void process(int maxIterations, Processor processor) { ListIterator<Entry> iterator = entries.listIterator(); List<Entry> toRetry = new ArrayList<>(); int i = 0; while (iterator.hasNext() && i < maxIterations) { Entry entry = iterator.next(); iterator.remove(); ++i; if (!processor.process(entry)) { toRetry.add(entry); } } entries.addAll(toRetry); }
|
ReleaseRequestQueue { public void process(int maxIterations, Processor processor) { ListIterator<Entry> iterator = entries.listIterator(); List<Entry> toRetry = new ArrayList<>(); int i = 0; while (iterator.hasNext() && i < maxIterations) { Entry entry = iterator.next(); iterator.remove(); ++i; if (!processor.process(entry)) { toRetry.add(entry); } } entries.addAll(toRetry); } }
|
ReleaseRequestQueue { public void process(int maxIterations, Processor processor) { ListIterator<Entry> iterator = entries.listIterator(); List<Entry> toRetry = new ArrayList<>(); int i = 0; while (iterator.hasNext() && i < maxIterations) { Entry entry = iterator.next(); iterator.remove(); ++i; if (!processor.process(entry)) { toRetry.add(entry); } } entries.addAll(toRetry); } ReleaseRequestQueue(List<Entry> entries); }
|
ReleaseRequestQueue { public void process(int maxIterations, Processor processor) { ListIterator<Entry> iterator = entries.listIterator(); List<Entry> toRetry = new ArrayList<>(); int i = 0; while (iterator.hasNext() && i < maxIterations) { Entry entry = iterator.next(); iterator.remove(); ++i; if (!processor.process(entry)) { toRetry.add(entry); } } entries.addAll(toRetry); } ReleaseRequestQueue(List<Entry> entries); List<Entry> getEntriesWithoutHash(); List<Entry> getEntriesWithHash(); List<Entry> getEntries(); void add(Address destination, Coin amount, Keccak256 rskTxHash); void add(Address destination, Coin amount); void process(int maxIterations, Processor processor); }
|
ReleaseRequestQueue { public void process(int maxIterations, Processor processor) { ListIterator<Entry> iterator = entries.listIterator(); List<Entry> toRetry = new ArrayList<>(); int i = 0; while (iterator.hasNext() && i < maxIterations) { Entry entry = iterator.next(); iterator.remove(); ++i; if (!processor.process(entry)) { toRetry.add(entry); } } entries.addAll(toRetry); } ReleaseRequestQueue(List<Entry> entries); List<Entry> getEntriesWithoutHash(); List<Entry> getEntriesWithHash(); List<Entry> getEntries(); void add(Address destination, Coin amount, Keccak256 rskTxHash); void add(Address destination, Coin amount); void process(int maxIterations, Processor processor); }
|
@Test public void doesnt_parse_if_transaction_is_null() { BtcLockSender btcLockSender = new P2shP2wpkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(null)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_transaction_doesnt_have_witness() { BtcTransaction btcTx = new BtcTransaction(networkParameters); BtcLockSender btcLockSender = new P2shP2wpkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void test11() { String tx = "F86E12F86B80881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA0C52C114D4F5A3BA904A9B3036E5E118FE0DBB987FE3955DA20F2CD8F6C21AB9CA06BA4C2874299A55AD947DBC98A25EE895AABF6B625C26C435E84BFD70EDF2F69"; byte[] payload = Hex.decode(tx); Queue<Integer> index = new LinkedList<>(); fullTraverse(payload, 0, 0, payload.length, 1, index); }
|
public static void fullTraverse(byte[] msgData, int level, int startPos, int endPos, int levelToIndex, Queue<Integer> index) { try { if (msgData == null || msgData.length == 0) { return; } int pos = startPos; while (pos < endPos) { if (level == levelToIndex) { index.add(pos); } if ((msgData[pos] & 0xFF) >= OFFSET_LONG_LIST) { byte lengthOfLength = (byte) (msgData[pos] - OFFSET_LONG_LIST); int length = calcLength(lengthOfLength, msgData, pos); System.out.println("-- level: [" + level + "] Found big list length: " + length); fullTraverse(msgData, level + 1, pos + lengthOfLength + 1, pos + lengthOfLength + length, levelToIndex, index); pos += lengthOfLength + length + 1; continue; } if ((msgData[pos] & 0xFF) >= OFFSET_SHORT_LIST && (msgData[pos] & 0xFF) < OFFSET_LONG_LIST) { byte length = (byte) ((msgData[pos] & 0xFF) - OFFSET_SHORT_LIST); System.out.println("-- level: [" + level + "] Found small list length: " + length); fullTraverse(msgData, level + 1, pos + 1, pos + length + 1, levelToIndex, index); pos += 1 + length; continue; } if ((msgData[pos] & 0xFF) >= OFFSET_LONG_ITEM && (msgData[pos] & 0xFF) < OFFSET_SHORT_LIST) { byte lengthOfLength = (byte) (msgData[pos] - OFFSET_LONG_ITEM); int length = calcLength(lengthOfLength, msgData, pos); System.out.println("-- level: [" + level + "] Found big item length: " + length); pos += lengthOfLength + length + 1; continue; } if ((msgData[pos] & 0xFF) > OFFSET_SHORT_ITEM && (msgData[pos] & 0xFF) < OFFSET_LONG_ITEM) { byte length = (byte) ((msgData[pos] & 0xFF) - OFFSET_SHORT_ITEM); System.out.println("-- level: [" + level + "] Found small item length: " + length); pos += 1 + length; continue; } if ((msgData[pos] & 0xFF) == OFFSET_SHORT_ITEM) { System.out.println("-- level: [" + level + "] Found null item: "); pos += 1; continue; } if ((msgData[pos] & 0xFF) < OFFSET_SHORT_ITEM) { System.out.println("-- level: [" + level + "] Found single item: "); pos += 1; continue; } } } catch (Throwable th) { throw new RuntimeException("RLP wrong encoding", th.fillInStackTrace()); } }
|
RLP { public static void fullTraverse(byte[] msgData, int level, int startPos, int endPos, int levelToIndex, Queue<Integer> index) { try { if (msgData == null || msgData.length == 0) { return; } int pos = startPos; while (pos < endPos) { if (level == levelToIndex) { index.add(pos); } if ((msgData[pos] & 0xFF) >= OFFSET_LONG_LIST) { byte lengthOfLength = (byte) (msgData[pos] - OFFSET_LONG_LIST); int length = calcLength(lengthOfLength, msgData, pos); System.out.println("-- level: [" + level + "] Found big list length: " + length); fullTraverse(msgData, level + 1, pos + lengthOfLength + 1, pos + lengthOfLength + length, levelToIndex, index); pos += lengthOfLength + length + 1; continue; } if ((msgData[pos] & 0xFF) >= OFFSET_SHORT_LIST && (msgData[pos] & 0xFF) < OFFSET_LONG_LIST) { byte length = (byte) ((msgData[pos] & 0xFF) - OFFSET_SHORT_LIST); System.out.println("-- level: [" + level + "] Found small list length: " + length); fullTraverse(msgData, level + 1, pos + 1, pos + length + 1, levelToIndex, index); pos += 1 + length; continue; } if ((msgData[pos] & 0xFF) >= OFFSET_LONG_ITEM && (msgData[pos] & 0xFF) < OFFSET_SHORT_LIST) { byte lengthOfLength = (byte) (msgData[pos] - OFFSET_LONG_ITEM); int length = calcLength(lengthOfLength, msgData, pos); System.out.println("-- level: [" + level + "] Found big item length: " + length); pos += lengthOfLength + length + 1; continue; } if ((msgData[pos] & 0xFF) > OFFSET_SHORT_ITEM && (msgData[pos] & 0xFF) < OFFSET_LONG_ITEM) { byte length = (byte) ((msgData[pos] & 0xFF) - OFFSET_SHORT_ITEM); System.out.println("-- level: [" + level + "] Found small item length: " + length); pos += 1 + length; continue; } if ((msgData[pos] & 0xFF) == OFFSET_SHORT_ITEM) { System.out.println("-- level: [" + level + "] Found null item: "); pos += 1; continue; } if ((msgData[pos] & 0xFF) < OFFSET_SHORT_ITEM) { System.out.println("-- level: [" + level + "] Found single item: "); pos += 1; continue; } } } catch (Throwable th) { throw new RuntimeException("RLP wrong encoding", th.fillInStackTrace()); } } }
|
RLP { public static void fullTraverse(byte[] msgData, int level, int startPos, int endPos, int levelToIndex, Queue<Integer> index) { try { if (msgData == null || msgData.length == 0) { return; } int pos = startPos; while (pos < endPos) { if (level == levelToIndex) { index.add(pos); } if ((msgData[pos] & 0xFF) >= OFFSET_LONG_LIST) { byte lengthOfLength = (byte) (msgData[pos] - OFFSET_LONG_LIST); int length = calcLength(lengthOfLength, msgData, pos); System.out.println("-- level: [" + level + "] Found big list length: " + length); fullTraverse(msgData, level + 1, pos + lengthOfLength + 1, pos + lengthOfLength + length, levelToIndex, index); pos += lengthOfLength + length + 1; continue; } if ((msgData[pos] & 0xFF) >= OFFSET_SHORT_LIST && (msgData[pos] & 0xFF) < OFFSET_LONG_LIST) { byte length = (byte) ((msgData[pos] & 0xFF) - OFFSET_SHORT_LIST); System.out.println("-- level: [" + level + "] Found small list length: " + length); fullTraverse(msgData, level + 1, pos + 1, pos + length + 1, levelToIndex, index); pos += 1 + length; continue; } if ((msgData[pos] & 0xFF) >= OFFSET_LONG_ITEM && (msgData[pos] & 0xFF) < OFFSET_SHORT_LIST) { byte lengthOfLength = (byte) (msgData[pos] - OFFSET_LONG_ITEM); int length = calcLength(lengthOfLength, msgData, pos); System.out.println("-- level: [" + level + "] Found big item length: " + length); pos += lengthOfLength + length + 1; continue; } if ((msgData[pos] & 0xFF) > OFFSET_SHORT_ITEM && (msgData[pos] & 0xFF) < OFFSET_LONG_ITEM) { byte length = (byte) ((msgData[pos] & 0xFF) - OFFSET_SHORT_ITEM); System.out.println("-- level: [" + level + "] Found small item length: " + length); pos += 1 + length; continue; } if ((msgData[pos] & 0xFF) == OFFSET_SHORT_ITEM) { System.out.println("-- level: [" + level + "] Found null item: "); pos += 1; continue; } if ((msgData[pos] & 0xFF) < OFFSET_SHORT_ITEM) { System.out.println("-- level: [" + level + "] Found single item: "); pos += 1; continue; } } } catch (Throwable th) { throw new RuntimeException("RLP wrong encoding", th.fillInStackTrace()); } } }
|
RLP { public static void fullTraverse(byte[] msgData, int level, int startPos, int endPos, int levelToIndex, Queue<Integer> index) { try { if (msgData == null || msgData.length == 0) { return; } int pos = startPos; while (pos < endPos) { if (level == levelToIndex) { index.add(pos); } if ((msgData[pos] & 0xFF) >= OFFSET_LONG_LIST) { byte lengthOfLength = (byte) (msgData[pos] - OFFSET_LONG_LIST); int length = calcLength(lengthOfLength, msgData, pos); System.out.println("-- level: [" + level + "] Found big list length: " + length); fullTraverse(msgData, level + 1, pos + lengthOfLength + 1, pos + lengthOfLength + length, levelToIndex, index); pos += lengthOfLength + length + 1; continue; } if ((msgData[pos] & 0xFF) >= OFFSET_SHORT_LIST && (msgData[pos] & 0xFF) < OFFSET_LONG_LIST) { byte length = (byte) ((msgData[pos] & 0xFF) - OFFSET_SHORT_LIST); System.out.println("-- level: [" + level + "] Found small list length: " + length); fullTraverse(msgData, level + 1, pos + 1, pos + length + 1, levelToIndex, index); pos += 1 + length; continue; } if ((msgData[pos] & 0xFF) >= OFFSET_LONG_ITEM && (msgData[pos] & 0xFF) < OFFSET_SHORT_LIST) { byte lengthOfLength = (byte) (msgData[pos] - OFFSET_LONG_ITEM); int length = calcLength(lengthOfLength, msgData, pos); System.out.println("-- level: [" + level + "] Found big item length: " + length); pos += lengthOfLength + length + 1; continue; } if ((msgData[pos] & 0xFF) > OFFSET_SHORT_ITEM && (msgData[pos] & 0xFF) < OFFSET_LONG_ITEM) { byte length = (byte) ((msgData[pos] & 0xFF) - OFFSET_SHORT_ITEM); System.out.println("-- level: [" + level + "] Found small item length: " + length); pos += 1 + length; continue; } if ((msgData[pos] & 0xFF) == OFFSET_SHORT_ITEM) { System.out.println("-- level: [" + level + "] Found null item: "); pos += 1; continue; } if ((msgData[pos] & 0xFF) < OFFSET_SHORT_ITEM) { System.out.println("-- level: [" + level + "] Found single item: "); pos += 1; continue; } } } catch (Throwable th) { throw new RuntimeException("RLP wrong encoding", th.fillInStackTrace()); } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static void fullTraverse(byte[] msgData, int level, int startPos, int endPos, int levelToIndex, Queue<Integer> index) { try { if (msgData == null || msgData.length == 0) { return; } int pos = startPos; while (pos < endPos) { if (level == levelToIndex) { index.add(pos); } if ((msgData[pos] & 0xFF) >= OFFSET_LONG_LIST) { byte lengthOfLength = (byte) (msgData[pos] - OFFSET_LONG_LIST); int length = calcLength(lengthOfLength, msgData, pos); System.out.println("-- level: [" + level + "] Found big list length: " + length); fullTraverse(msgData, level + 1, pos + lengthOfLength + 1, pos + lengthOfLength + length, levelToIndex, index); pos += lengthOfLength + length + 1; continue; } if ((msgData[pos] & 0xFF) >= OFFSET_SHORT_LIST && (msgData[pos] & 0xFF) < OFFSET_LONG_LIST) { byte length = (byte) ((msgData[pos] & 0xFF) - OFFSET_SHORT_LIST); System.out.println("-- level: [" + level + "] Found small list length: " + length); fullTraverse(msgData, level + 1, pos + 1, pos + length + 1, levelToIndex, index); pos += 1 + length; continue; } if ((msgData[pos] & 0xFF) >= OFFSET_LONG_ITEM && (msgData[pos] & 0xFF) < OFFSET_SHORT_LIST) { byte lengthOfLength = (byte) (msgData[pos] - OFFSET_LONG_ITEM); int length = calcLength(lengthOfLength, msgData, pos); System.out.println("-- level: [" + level + "] Found big item length: " + length); pos += lengthOfLength + length + 1; continue; } if ((msgData[pos] & 0xFF) > OFFSET_SHORT_ITEM && (msgData[pos] & 0xFF) < OFFSET_LONG_ITEM) { byte length = (byte) ((msgData[pos] & 0xFF) - OFFSET_SHORT_ITEM); System.out.println("-- level: [" + level + "] Found small item length: " + length); pos += 1 + length; continue; } if ((msgData[pos] & 0xFF) == OFFSET_SHORT_ITEM) { System.out.println("-- level: [" + level + "] Found null item: "); pos += 1; continue; } if ((msgData[pos] & 0xFF) < OFFSET_SHORT_ITEM) { System.out.println("-- level: [" + level + "] Found single item: "); pos += 1; continue; } } } catch (Throwable th) { throw new RuntimeException("RLP wrong encoding", th.fillInStackTrace()); } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void doesnt_parse_if_transaction_has_scriptsig_with_more_than_one_chunk() { BtcTransaction btcTx = new BtcTransaction(networkParameters); btcTx.addInput(PegTestUtils.createHash(1), 0, ScriptBuilder.createInputScript(null, new BtcECKey())); BtcLockSender btcLockSender = new P2shP2wpkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_transaction_has_null_scriptsig() { BtcTransaction btcTx = new BtcTransaction(networkParameters); btcTx.addInput(new TransactionInput(btcTx.getParams(), null, null)); TransactionWitness witness = new TransactionWitness(1); witness.setPush(0, new byte[]{}); btcTx.setWitness(0, witness); BtcLockSender btcLockSender = new P2shP2wpkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_transaction_witness_doesnt_have_two_pushes() { BtcTransaction btcTx = new BtcTransaction(networkParameters); btcTx.addInput(PegTestUtils.createHash(1), 0, new Script(new byte[]{})); TransactionWitness witness = new TransactionWitness(1); witness.setPush(0, new byte[]{}); btcTx.setWitness(0, witness); BtcLockSender btcLockSender = new P2shP2wpkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void rejects_p2pkh_transaction() { String rawTx = RawTransactions.txs.get(BtcLockSender.TxType.P2PKH); BtcTransaction btcTx = new BtcTransaction(networkParameters, Hex.decode(rawTx)); BtcLockSender btcLockSender = new P2shP2wpkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void rejects_p2sh_multisig_transaction() { String rawTx = RawTransactions.txs.get(BtcLockSender.TxType.P2SHMULTISIG); BtcTransaction btcTx = new BtcTransaction(networkParameters, Hex.decode(rawTx)); BtcLockSender btcLockSender = new P2shP2wpkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void rejects_p2sh_p2wsh_transaction() { String rawTx = RawTransactions.txs.get(BtcLockSender.TxType.P2SHP2WSH); BtcTransaction btcTx = new BtcTransaction(networkParameters, Hex.decode(rawTx)); BtcLockSender btcLockSender = new P2shP2wpkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wpkhBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() != 2) { return false; } byte[] pubKey = btcTx.getWitness(0).getPush(1); BtcECKey key = BtcECKey.fromPublicOnly(btcTx.getWitness(0).getPush(1)); if (!key.isCompressed()) { return false; } try { byte[] keyHash = key.getPubKeyHash(); byte[] redeemScript = ByteUtil.merge(new byte[]{ 0x00, 0x14}, keyHash); byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); this.rskAddress = new RskAddress(org.ethereum.crypto.ECKey.fromPublicOnly(pubKey).getAddress()); } catch (Exception e) { return false; } return true; } P2shP2wpkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_transaction_is_null() { BtcLockSender btcLockSender = new P2shMultisigBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(null)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_tx_doesnt_have_inputs() { BtcTransaction btcTx = new BtcTransaction(networkParameters); BtcLockSender btcLockSender = new P2shMultisigBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_tx_doesnt_have_scriptsig() { BtcTransaction btcTx = new BtcTransaction(networkParameters); btcTx.addInput(new TransactionInput(networkParameters, null, null)); BtcLockSender btcLockSender = new P2shMultisigBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void rejects_p2pkh_transaction() { String rawTx = RawTransactions.txs.get(BtcLockSender.TxType.P2PKH); BtcTransaction btcTx = new BtcTransaction(networkParameters, Hex.decode(rawTx)); BtcLockSender btcLockSender = new P2shMultisigBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void test12() { String tx = "F86E12F86B80881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA0C52C114D4F5A3BA904A9B3036E5E118FE0DBB987FE3955DA20F2CD8F6C21AB9CA06BA4C2874299A55AD947DBC98A25EE895AABF6B625C26C435E84BFD70EDF2F69"; byte[] payload = Hex.decode(tx); ArrayList<RLPElement> rlpList = decode2(payload); }
|
@Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void rejects_p2sh_p2wpkh_transaction() { String rawTx = RawTransactions.txs.get(BtcLockSender.TxType.P2SHP2WPKH); BtcTransaction btcTx = new BtcTransaction(networkParameters, Hex.decode(rawTx)); BtcLockSender btcLockSender = new P2shMultisigBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void rejects_p2sh_p2wsh_transaction() { String rawTx = RawTransactions.txs.get(BtcLockSender.TxType.P2SHP2WSH); BtcTransaction btcTx = new BtcTransaction(networkParameters, Hex.decode(rawTx)); BtcLockSender btcLockSender = new P2shMultisigBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shMultisigBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() < 3) { return false; } int chunksLength = scriptSig.getChunks().size(); byte[] redeemScript = scriptSig.getChunks().get(chunksLength - 1).data; Script redeem = new Script(redeemScript); if(!redeem.isSentToMultiSig()) { return false; } try { byte[] scriptPubKey = HashUtil.ripemd160(Sha256Hash.hash(redeemScript)); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch(Exception e) { return false; } return true; } P2shMultisigBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_transaction_is_null() { BtcLockSender btcLockSender = new P2shP2wshBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(null)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_transaction_doesnt_have_witness() { BtcTransaction btcTx = new BtcTransaction(networkParameters); BtcLockSender btcLockSender = new P2shP2wshBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_tx_doesnt_have_scriptsig() { BtcTransaction btcTx = new BtcTransaction(networkParameters); btcTx.addInput(new TransactionInput(btcTx.getParams(), null, null)); TransactionWitness witness = new TransactionWitness(1); witness.setPush(0, new byte[]{}); btcTx.setWitness(0, witness); BtcLockSender btcLockSender = new P2shP2wshBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_transaction_witness_doesnt_have_at_least_three_pushes() { BtcTransaction btcTx = new BtcTransaction(networkParameters); btcTx.addInput(PegTestUtils.createHash(1), 0, ScriptBuilder.createInputScript(null, new BtcECKey())); TransactionWitness witness = new TransactionWitness(2); witness.setPush(0, new byte[]{}); witness.setPush(1, new byte[]{}); btcTx.setWitness(0, witness); BtcLockSender btcLockSender = new P2shP2wshBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void rejects_p2pkh_transaction() { String rawTx = RawTransactions.txs.get(BtcLockSender.TxType.P2PKH); BtcTransaction btcTx = new BtcTransaction(networkParameters, Hex.decode(rawTx)); BtcLockSender btcLockSender = new P2shP2wshBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void rejects_p2sh_p2wpkh_transaction() { String rawTx = RawTransactions.txs.get(BtcLockSender.TxType.P2SHP2WPKH); BtcTransaction btcTx = new BtcTransaction(networkParameters, Hex.decode(rawTx)); BtcLockSender btcLockSender = new P2shP2wshBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void rejects_p2sh_multisig_transaction() { String rawTx = RawTransactions.txs.get(BtcLockSender.TxType.P2SHMULTISIG); BtcTransaction btcTx = new BtcTransaction(networkParameters, Hex.decode(rawTx)); BtcLockSender btcLockSender = new P2shP2wshBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2shP2wshBtcLockSender implements BtcLockSender { public boolean tryParse(BtcTransaction btcTx) { if (btcTx == null) { return false; } if (!btcTx.hasWitness()) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } if (btcTx.getInput(0).getScriptSig().getChunks().size() != 1) { return false; } if (btcTx.getWitness(0).getPushCount() < 3) { return false; } int pushesLength = btcTx.getWitness(0).getPushCount(); byte[] redeemScript = btcTx.getWitness(0).getPush(pushesLength - 1); Script redeem = new Script(redeemScript); if (!redeem.isSentToMultiSig()) { return false; } try { byte[] redeemScriptHash = Sha256Hash.hash(redeemScript); byte[] merged = ByteUtil.merge(new byte[]{0x00, 0x20}, redeemScriptHash); byte[] hashedAgain = Sha256Hash.hash(merged); byte[] scriptPubKey = HashUtil.ripemd160(hashedAgain); this.btcAddress = new Address(btcTx.getParams(), btcTx.getParams().getP2SHHeader(), scriptPubKey); } catch (Exception e) { return false; } return true; } P2shP2wshBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_tx_is_null() { BtcLockSender btcLockSender = new P2pkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(null)); }
|
public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void test13() { String peers = "f9 14 90 11 f8 4c c6 81 83 68 81 fc 04 82 76 5f b8 40 07 7e 53 7a 8b 36 73 e8 f1 b6 25 db cc " + "90 2e a7 d4 ce d9 40 2e 46 64 e8 73 67 95 12 cc 23 60 69 8e 53 42 56 52 a0 46 24 fc f7 8c db a1 a3 " + "23 30 87 a9 19 a3 4d 11 ae da ce ee b7 d8 33 fc bf 26 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 40 0a " + "b2 cd e8 3a 09 84 03 dd c2 ea 54 14 74 0d 8a 01 93 e4 49 c9 6e 11 24 19 96 7a bc 62 eb 17 cd ce d7 " + "7a e0 ab 07 5e 04 f7 dd dc d4 3f b9 04 8b e5 32 06 a0 40 62 0b de 26 cb 74 3f a3 12 31 9f f8 4d c7 " + "81 cf 81 db 45 81 9a 82 76 5f b8 40 19 c3 3d a7 03 1c ff 17 7e fa 84 2f aa 3d 31 bd 83 e1 76 4e c6 " + "10 f2 36 94 4a 9f 8a 21 c1 c5 1a 04 f4 7f 6b 5f c3 ef e6 5c af 36 94 43 63 5a fc 58 d8 f5 d4 e2 f1 " + "2a f9 ee ec 3c 6e 30 bf 0a 2b f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 1e 59 c2 82 08 12 94 80 84 " + "97 ae 7a 7e 97 67 98 c4 2b 8b cc e1 3c 9d 8b 0e cf 8a fe cd b5 df d4 ef a8 77 0f c0 d1 f7 de 63 c9 " + "16 40 e7 e8 b4 35 8c 9e 3e d0 f3 d6 c9 86 20 ad 7e a4 24 18 c9 ec f8 4b c5 1f 12 81 9e 48 82 76 5f " + "b8 40 1f 68 c0 75 c1 d8 7b c0 47 65 43 0f df b1 e5 d0 0f 1b 78 4e d6 be 72 1e 4c af f7 be b5 7b 4b " + "21 7b 95 da 19 b5 ec 66 04 58 68 b3 9a ac 2e 08 76 cf 80 f0 b6 8d 0f a2 0b db 90 36 be aa 70 61 ea " + "f8 4c c6 81 bf 81 ea 39 37 82 76 5f b8 40 21 78 0c 55 b4 7d b4 b1 14 67 b5 f5 5b 0b 55 5e 08 87 ce " + "36 fb d9 75 e2 24 b1 c7 0e ac 7a b8 e8 c2 db 37 f0 a4 8b 90 ff dd 5a 37 9a da 99 b6 a0 f6 42 9c 4a " + "53 c2 55 58 19 1a 68 26 36 ae f4 f2 f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 23 15 cb 7c f4 9b 8e " + "ab 21 2c 5a 45 79 0b 50 79 77 39 73 8f 5f 73 34 39 b1 90 11 97 37 ee 8c 09 bc 72 37 94 71 2a a8 2f " + "26 70 bc 58 1a b0 75 7e f2 31 37 ac 0f df 0f 8c 89 65 e7 dd 6b a7 9f 8c f8 4e c8 81 bf 81 b1 81 d1 " + "81 9f 82 76 5f b8 40 24 9a 36 41 e5 a8 d0 8e 41 a5 cf c8 da e1 1f 17 61 25 4f 4f d4 7d 9b 13 33 8d " + "b8 e6 e3 72 9e 6f 2a c9 ec 09 7a 5c 80 96 84 d6 2a 41 e6 df c2 ff f7 2d c3 db d9 7e a2 61 32 bb 97 " + "64 05 65 bb 0c f8 4a c4 55 41 7e 2d 82 76 5f b8 40 2a 38 ea 5d 9a 7e fd 7f ff c0 a8 1d 8e a7 ed 28 " + "31 1c 40 12 bb ab 14 07 c8 da d2 68 51 29 e0 42 17 27 34 a3 28 e8 90 7f 90 54 b8 22 5f e7 70 41 d8 " + "a4 86 a9 79 76 d2 83 72 42 ab 6c 8c 59 05 e4 f8 4c c6 81 83 68 81 fc 04 82 76 5f b8 40 32 4d d9 36 " + "38 4d 8c 0d de fd e0 4b a7 40 29 98 ab bd 63 d7 9c 0b f8 58 6b 3d d2 c7 db f6 c9 1e b8 0a 7b 6d e8 " + "f1 6a 50 04 4f 14 9c 7b 39 aa fb 9c 3a d7 f2 ca a4 03 55 aa b0 98 88 18 6f cc a2 f8 4c c6 44 30 81 " + "ad 81 a3 82 76 5f b8 40 39 42 45 c0 99 16 33 ed 06 0b af b9 64 68 53 d3 44 18 8b 80 4f e3 7e 25 a5 " + "bc ac 44 ed 44 3a 84 a6 8b 3a af 15 5e fe 48 61 e8 4b 4b 51 5f 9a 5d ec db d7 da e9 81 92 d7 a3 20 " + "a7 92 c7 d4 df af f8 4d c7 56 81 b7 81 e7 81 cd 82 76 5f b8 40 39 86 50 f6 7b 22 92 93 9d e3 4c 0e " + "ae b9 14 1f 94 84 a0 fb 17 3f a3 3f 81 a1 f7 31 5d 0e b7 7b de 3a 76 c3 86 36 fa e6 6f a1 4b f2 af " + "df d6 3e 60 ab d4 0e 29 b0 2a 91 4e 65 de 57 89 98 3f d4 f8 4c c6 44 81 b9 81 ea 40 82 76 5f b8 40 " + "3a 15 58 7a 1c 3a da bf 02 91 b3 07 f7 1b 2c 04 d1 98 aa e3 6b 83 49 95 d3 30 5d ff 42 f1 ab 86 f4 " + "83 ae 12 9e 92 03 fb c6 ef 21 87 c8 62 1e dd 18 f6 1d 53 ea a5 b5 87 ff de a4 d9 26 48 90 38 f8 4d " + "c7 81 cf 81 db 45 81 9a 82 76 5f b8 40 3b 14 62 04 0e a7 78 e3 f7 5e 65 ce 24 53 41 8a 66 2e 62 12 " + "c9 f6 5b 02 ea b5 8d 22 b2 87 e4 50 53 bd e5 eb f0 60 96 0c bf a0 d9 dc 85 bf 51 ba 7a a1 f2 ca a2 " + "c1 36 82 d9 32 77 64 1d 60 db eb f8 4c c6 6a 81 a8 0e 81 f9 82 76 5f b8 40 3e cc 97 ab 15 d2 2f 7b " + "9e df 19 c0 4c e3 b6 09 5f a2 50 42 14 00 2b 35 98 9c 6f 81 ee 4b 96 1c c2 a8 99 c4 94 15 c9 14 e3 " + "13 90 83 40 04 7d 1d 3b 25 d7 4f 5b 9c 85 a0 6a fa 26 59 a5 39 99 2e f8 4b c5 2e 04 81 c1 09 82 76 " + "5f b8 40 40 7c 22 00 3f 3b ba a6 cb eb 8e 4b 0a b7 07 30 73 fe ab 85 18 2b 40 55 25 f8 bd 28 32 55 " + "04 3d 71 35 18 f7 47 48 d9 2c 43 fb b9 9e cc 7c 3f ba b9 5d 59 80 06 51 3a a8 e5 9c 48 04 1c 8b 41 " + "c2 f8 4b c5 32 7e 56 81 c2 82 76 5f b8 40 40 8c 93 24 20 3b d8 26 2f ce 65 06 ba 59 dc dd 56 70 89 " + "b0 eb 9a 5b b1 83 47 7b ab bf 61 63 91 4a cd c7 f4 95 f8 96 4d 8a c1 2f e2 40 18 87 b8 cd 8d 97 c0 " + "c9 dc cf ad db b2 0a 3c 31 47 a7 89 f8 4a c4 26 6c 4f 68 82 76 5f b8 40 42 3e 40 04 da 2f a7 50 0b " + "c0 12 c0 67 4a a6 57 15 02 c5 3a a4 d9 1e fa 6e 2b 5c b1 e4 68 c4 62 ca 31 14 a2 e2 eb 09 65 b7 04 " + "4f 9c 95 75 96 5b 47 e4 7a 41 f1 3f 1a dc 03 a2 a4 b3 42 d7 12 8d f8 4b c5 40 81 e7 08 2d 82 76 5f " + "b8 40 42 83 93 75 27 2c 2f 3d ea db 28 08 5d 06 05 5e 35 31 35 c6 c8 d8 96 09 7a 1b c4 80 c4 88 4f " + "d1 60 45 18 cb df 73 1a c1 8f 09 84 b7 f0 21 48 e8 82 90 d1 3c 22 4d 82 46 43 14 e2 b5 96 2e 3f 89 " + "f8 4d c7 32 81 aa 81 d8 81 c8 82 76 5f b8 40 44 cf 19 44 6c a4 65 01 8e 4d e6 c6 0f c0 df 52 9e ba " + "25 02 92 ef 74 41 e1 db 59 84 1c 69 f0 22 f6 09 28 10 c9 a5 a7 f2 74 f2 f9 7c 4b d6 c7 6e ad c0 64 " + "c7 d6 59 7c ae b1 7e d8 7c b2 57 73 5f f8 4b c5 32 81 9c 5a 53 82 76 5f b8 40 46 1c 9b 54 e9 19 53 " + "c5 bb c3 1c 67 12 a9 17 38 2b e6 7d 60 f7 5e b7 f5 06 51 be a3 e5 94 d0 d1 9c 22 29 d8 f6 6a db 3f " + "20 3f 60 00 38 e7 cc 93 4d c9 27 87 fa c4 39 2b 9b fa 7c bc 78 6f d0 5b f8 4b c5 81 86 64 7d 29 82 " + "76 5f b8 40 48 35 3a 00 58 e2 64 48 d9 4e 59 33 6c ca 9d 28 a9 37 41 20 de f7 6c 4b cc fe e1 8b 01 " + "23 e5 91 92 39 3a 2e e3 04 4d 80 e0 ee cb b0 94 76 be 62 fd e1 e8 74 f9 3d 05 ea 5c 4a 9a 45 c0 6e " + "8f e1 f8 4b c5 4e 08 05 81 bb 82 76 5f b8 40 48 e8 95 09 49 d4 c0 0b cd bb e9 39 c5 bf 07 8f 2c bf " + "f1 08 84 af 16 60 b1 c3 22 b9 ca a3 ba 35 7b b4 15 7f c6 b0 03 9a f9 43 8d fe 51 ec 27 8a 47 fc d3 " + "b7 26 fa 0a 08 7d 4c 3c 01 a6 2f 33 5e f8 4a c6 58 45 81 c6 81 c6 07 b8 40 4a 02 55 fa 46 73 fa a3 " + "0f c5 ab fd 3c 55 0b fd bc 0d 3c 97 3d 35 f7 26 46 3a f8 1c 54 a0 32 81 cf ff 22 c5 f5 96 5b 38 ac " + "63 01 52 98 77 57 a3 17 82 47 85 49 c3 6f 7c 84 cb 44 36 ba 79 d6 d9 f8 4b c5 40 81 e7 08 2d 82 76 " + "5f b8 40 4c 75 47 ab 4d 54 1e 10 16 4c d3 74 1f 34 76 ed 19 4b 0a b9 a1 36 df ca c3 94 3f 97 35 8c " + "9b 05 14 14 27 36 ca 2f 17 0f 12 52 29 05 7b 47 32 44 a6 23 0b f5 47 1a d1 68 18 85 24 b2 b5 cd 8b " + "7b f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 4d 5e 48 75 d6 0e b4 ee af b6 b2 a7 d3 93 6e d3 c9 bc " + "58 ac aa de 6a 7f 3c 5f 25 59 8c 20 b3 64 f1 2b ea 2f b1 db 3b 2c 2e f6 47 85 a4 7d 6b 6b 5b 10 34 " + "27 cb ac 0c 88 b1 8f e9 2a 9f 53 93 f8 f8 4b c5 52 0c 81 e3 54 82 76 5f b8 40 4f d8 98 62 75 74 d3 " + "e8 6b 3f 5a 65 c3 ed c2 e5 da 84 53 59 26 e4 a2 88 20 b0 03 8b 19 63 6e 07 db 5e b0 04 d7 91 f8 04 " + "1a 00 6e 33 e1 08 e4 ec 53 54 99 d1 28 d8 d9 c5 ca f6 bb dc 22 04 f7 6a f8 4b c5 81 b4 20 2b 08 82 " + "76 5f b8 40 53 cc f2 5a b5 94 09 ec bb 90 3d 2e c3 a9 aa 2e b3 9d 7c c4 c7 db 7e 6f 68 fd 71 1a 7c " + "eb c6 06 21 6d e7 37 82 6d a4 20 93 e3 e6 52 1e e4 77 0e b2 d6 69 dc 4b f3 54 6c c7 57 c3 40 12 69 " + "6e ae f8 4c c6 6a 81 a8 0e 81 f9 82 76 5f b8 40 54 b3 93 15 69 91 39 87 80 50 2f a8 f4 14 13 79 bc " + "e2 69 31 be 87 ba 8e 0b 74 9b a9 05 a9 e9 76 e5 de 6d 39 c9 8c f0 48 f2 5c 3c bb b8 c7 f3 02 c4 e6 " + "04 ad 5b f7 2c db 06 10 0f 50 0d e3 a6 86 f8 4a c4 4c 67 37 47 82 76 5f b8 40 60 0a 77 fb 14 e7 92 " + "c0 c7 0d c4 ad e3 82 ed 60 43 62 b9 78 b1 9b 94 c4 ed 18 83 38 a1 79 5d 2d b4 5f 7f 22 3b 66 ba eb " + "a3 91 c5 9b 55 88 b4 4e ba f7 1c 7e b3 97 55 c2 72 29 c7 fd e6 41 be ce f8 4b c5 6d 2b 81 9a 42 82 " + "76 5f b8 40 69 dd 44 5f 67 c3 be f3 94 f9 54 9f da e1 62 3d bc 20 88 4a 62 fd 56 16 dd bb 49 f8 4b " + "a8 7e 14 7c b8 a5 0b a9 71 d7 30 c4 62 1d 0e b6 51 33 49 4e 94 fa 5e a2 e6 9c 66 1f 6b 12 e7 ed 2a " + "8d 4e f8 4b c5 18 09 3d 81 9b 82 76 5f b8 40 6b 5d 4c 35 ff d1 f5 a1 98 03 8a 90 83 4d 29 a1 b8 8b " + "e0 d5 ef ca 08 bc 8a 2d 58 81 18 0b 0b 41 6b e0 06 29 aa be 45 0a 50 82 8b 8d 1e e8 2d 98 f5 52 81 " + "87 ee 67 ed 6e 07 3b ce ef cd fb 2b c9 f8 4a c4 55 41 7e 2d 82 76 5f b8 40 6c bb 1e d5 36 dc 38 58 " + "c1 f0 63 42 9b d3 95 2a 5d 32 ef 8e 11 52 6c df e7 2f 41 fe a1 ac e9 60 18 7c 99 75 ab bc 23 78 35 " + "11 c0 0f 26 98 35 47 47 f9 05 aa ac 11 dc d2 b7 47 8b 3e af 32 7a c6 f8 4b c5 40 81 e7 08 2d 82 76 " + "5f b8 40 6e a2 8f 64 ea 1c c3 b6 57 25 44 fd 5b f7 43 b0 ea ab e0 17 f5 14 73 0c 89 7d a3 c7 7f 03 " + "c5 16 f1 e5 f3 1d 79 3b 4b ce 3c aa 1d ed 56 35 6d 20 b2 eb b5 5a 70 66 f4 1c 25 b7 c3 d5 66 14 e0 " + "6b f8 4a c4 55 41 7e 2d 82 76 5f b8 40 72 53 24 08 e8 be 6d 5e 2c 9f 65 0f b9 c9 f9 96 50 cc 1f a0 " + "62 a4 a4 f2 cf e4 e6 ae 69 cd d2 e8 b2 3e d1 4a fe 66 95 5c 23 fa 04 8f 3a 97 6e 3c e8 16 9e 50 5b " + "6a 89 cc 53 d4 fa c2 0c 2a 11 bf f8 4c c6 52 81 d9 48 81 a9 82 76 5f b8 40 7a ee a4 33 60 b9 36 8b " + "30 e7 f4 82 86 61 3f d1 e3 b0 20 7f b7 1f 03 08 d5 04 12 11 44 63 e7 7a b8 30 27 c0 d4 0c ad aa b8 " + "bb f6 12 fc 5b 69 67 fa 1c 40 73 29 d4 7e c6 1f b0 dc 3d a1 08 68 32 f8 4c c6 81 a6 81 93 53 4f 82 " + "76 5f b8 40 7b 3c dd e0 58 d5 b4 5d 8d b2 24 36 60 cf ea 02 e0 74 ec 21 31 14 c2 51 d7 c0 c3 2d 04 " + "03 bb 7a b4 77 13 d2 49 2f f6 c8 81 cf c2 aa c3 f5 2c b2 69 76 8c 89 68 f3 b6 b1 8b ac 97 22 d0 53 " + "31 f6 f8 4c c6 6a 81 a8 0e 81 f9 82 76 5f b8 40 87 ab 58 1b b9 7c 21 2a 2d a7 ef 0d 6e 10 5e 41 b5 " + "5e 4e 42 cb b6 a1 af 9a 76 1a 01 ca 8c 65 06 9a b4 b5 82 7e 32 2c f2 c5 f5 9e 7f 59 2b e2 a8 17 c4 " + "5a b6 41 f5 a9 dd 36 89 63 c7 3f 9e e6 88 f8 4c c6 52 81 d9 48 81 a9 82 76 5f b8 40 8c 66 0d bc 6d " + "3d b0 18 6a d1 0f 05 fd 4f 2f 06 43 77 8e c5 14 e8 45 2a 75 50 c6 30 da 21 17 1a 29 b1 bb 67 c2 e8 " + "e1 01 ea 1d b3 97 43 f3 e7 8c 4d 26 76 a1 3d 15 51 51 21 51 5f c3 8b 04 8f 37 f8 4c c6 63 81 e7 58 " + "81 af 82 76 5f b8 40 94 fe 3d 52 a2 89 4c ed c6 b1 54 24 15 6e b8 73 8a 84 41 dd 74 ba 9c ed 66 64 " + "ed 30 a3 32 a9 5b 57 4d 89 26 2e a3 67 fa 90 0a e9 70 6f b8 1a 40 82 87 bd de f3 a9 dd 9f f4 4e 3a " + "41 bc 09 0f dc f8 4d c7 81 d5 81 81 81 e6 0a 82 76 5f b8 40 95 21 14 f1 10 e8 ac 00 df ea 5f 05 0d " + "95 5e 76 4c 7c ba 8f b2 07 c0 5a 7a a5 ae 84 91 68 64 0a 2b 4e 31 43 91 fc 3a 76 79 5b 38 27 05 54 " + "62 63 9c ff 4a e2 d6 4a b8 0e 95 27 44 28 31 3e 36 6a f8 4c c6 58 45 81 c6 81 c6 82 76 5f b8 40 96 " + "f3 47 b0 96 ed 16 30 f4 74 b9 76 23 e4 5e 8d 47 1b 1d 43 c2 2f 59 96 07 c8 b2 e3 ed 0d 7b 79 05 d8 " + "55 4a d3 99 db d7 39 c7 61 26 40 44 24 d8 db 0d c7 d2 b0 47 c1 a3 28 ae 27 d4 09 06 c5 83 f8 4c c6 " + "81 83 68 81 fc 04 82 76 5f b8 40 9a 22 c8 fb 1b d8 bb d0 2f 0e 74 ed 9d 3d 55 b0 f5 b0 96 72 bc 43 " + "a2 d4 7b 1e d0 42 38 c1 c3 2b 6a 65 74 26 52 5b 15 51 82 36 e9 78 9b 54 6a 4a 07 2a 60 5e 13 73 fe " + "5b 99 6b ae dc 30 35 94 28 f8 4b c5 52 0c 81 e3 54 82 76 5f b8 40 9b 1a 3a 8d 77 1b 3d 94 9c a3 94 " + "a8 8e b5 dc 29 a9 53 b0 2c 81 f0 17 36 1f fc 0a fe 09 ab ce 30 69 17 1a 87 d4 74 52 36 87 fc c9 a9 " + "d3 2c c0 2c fa b4 13 22 56 fe aa bf e0 5f 7a c7 47 19 4e 88 f8 4b c5 42 81 d7 78 1c 82 76 5f b8 40 " + "9f a7 e5 5b 2d 98 f1 d7 44 c7 62 32 e4 fd a2 42 fe 9f d3 d5 74 3d 16 d3 ca d2 e5 48 a0 7c b5 af 06 " + "fe 60 eb ae b8 c6 09 50 28 17 92 34 dc dd d3 cd cf 1f cf e6 ed aa 2a 53 30 7f d1 03 da 4a f0 f8 4a " + "c4 55 41 7e 2d 82 76 5f b8 40 a0 1f 83 4e 9d 1a 61 3c 3c 74 7e 56 1c ac 19 cb 12 d8 79 c1 a5 74 20 " + "a4 9c 23 65 2b 8f 51 28 8c 8b 11 1a a3 88 89 98 b0 5e 32 7f 47 a2 35 c6 a4 a3 77 f8 88 e3 00 5a 2d " + "4b 03 ec b7 26 86 08 d3 f8 4c c6 44 30 81 ad 81 a3 82 7a 51 b8 40 a5 fd 77 c0 d4 32 fb fa 33 17 08 " + "49 14 c2 e8 a8 82 1e 4b a1 dc ba 44 96 1f f7 48 0e 6d b6 08 78 9c ab 62 91 41 63 60 ea 8c dc 26 b0 " + "d2 f0 87 7c 50 e8 9a 70 c1 bc f5 d6 dd 8b 18 2e 0a 9e 37 d3 f8 4d c7 81 88 81 a0 81 98 31 82 76 5f " + "b8 40 ae 31 bd 02 54 ee 7d 10 b8 0f c9 0e 74 ba 06 ba 76 11 87 df 31 38 a9 79 9d e5 82 8d 01 63 52 " + "4c 44 ba c7 d2 a9 b5 c4 1b e5 be 82 89 a1 72 36 1f 0b a9 04 10 c9 4f 57 9b f7 eb d2 8f 18 aa a1 cd " + "f8 4a c4 55 41 7e 2d 82 76 5f b8 40 ba 3d 21 67 72 cd c7 45 58 d2 54 56 24 a2 d6 2d cb cf d2 72 30 " + "57 30 c7 46 43 c7 a7 e8 19 af a6 cd d8 22 23 e2 b5 50 1e b6 d4 ea e5 db f2 1e 55 8c 76 8a ca ec 2c " + "1c a1 0e 74 c4 c8 7a 57 4b 53 f8 4a c4 55 41 7e 2d 82 76 5f b8 40 bd b4 9c 01 87 2d 91 bd 1e a9 90 " + "bd 2e df 16 c4 81 71 a6 06 7f 9a 6f 7f 48 bf b1 94 63 0b 5a e9 03 1b 5d c2 63 f5 9c 66 ad a4 44 cb " + "4e 6f 9d f6 2b 30 17 ce 61 2c ab 7b 53 da 08 d3 56 f7 8d 30 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 " + "40 c1 2b a9 1f 95 04 4d 78 ee d1 d3 a9 53 5e bd 64 71 52 44 18 13 5e eb 46 ad 5d 5c 6e cc 2f 51 68 " + "b4 ab 3a 06 2b b0 74 2a ea 65 ff ea 76 7f ab 8d cc 21 78 3c b2 9b f3 2e 2c d6 22 22 09 fa 71 fd f8 " + "4c c6 44 30 81 ad 81 a3 82 7a 51 b8 40 c2 e2 69 e6 4a a8 c9 be 2d 41 81 2a 48 af a2 34 6b d4 1a 1a " + "b2 e4 64 62 41 ae 3b 8d 0c cd 41 f2 d6 82 b1 5a 02 5f 75 9c 0d 95 5a 60 71 d4 e8 ea 7d 4d e3 97 d6 " + "e0 52 23 09 20 11 3b 6e b7 4c 09 f8 4a c4 4a 4f 17 77 82 76 5f b8 40 c3 03 b8 3f 6a 16 1f 99 67 36 " + "34 44 80 ae 9d 88 fd c1 d9 c6 75 bf ac a8 88 f7 0f 24 89 72 65 62 82 09 da 53 74 1e 03 c0 f6 59 21 " + "f6 8f 60 2d c9 f3 34 a3 c4 5b cb 92 af 85 44 a6 fb 11 9b d8 87 f8 4b c5 0c 81 fa 61 1a 82 76 5f b8 " + "40 c7 6e 7c 15 7b 77 35 51 11 53 d1 f9 50 81 a1 44 e0 88 a9 89 17 1f 3d 43 2c c5 d8 29 3e ce 9c fa " + "a4 83 c0 32 15 5d 7b 53 65 6a 6e 33 a3 d7 5c d0 62 4e 09 a2 f9 49 c1 56 09 3d ba a8 3f 11 11 f2 f8 " + "4b c5 52 0c 81 e3 54 82 76 5f b8 40 c7 d5 a3 69 1a 59 59 9d e3 33 48 9c bf 8a 47 a7 43 3e 92 c7 27 " + "06 e1 3d 94 ed 21 12 96 d3 5c 97 d8 35 7d 7e 07 b3 85 85 64 d7 26 8e d7 aa 09 7f 37 58 9c 27 77 0f " + "90 dd 0b 07 63 5b e3 f5 33 64 f8 4c c6 4e 09 81 92 81 b2 82 76 5f b8 40 c8 81 97 a8 2b 0a cf 0a 87 " + "24 94 d1 df ac 9d e8 46 da a7 de 08 b2 40 64 7a 96 ba 72 fb e0 8f d5 2b 55 c6 c9 45 14 a4 7e c5 1b " + "a4 9a 97 54 89 eb c9 38 3b 48 f5 e2 40 93 90 68 ce 58 36 ff 24 f1 f8 4b c5 81 b4 20 2b 08 82 76 5f " + "b8 40 c9 e0 39 d8 a8 b9 e4 35 be f2 f4 5f c7 cb 7e 78 87 16 e8 c7 af c1 ba cc 64 e1 24 6d 2a b5 06 " + "d3 60 73 79 2a e6 96 e4 1a d6 ba 0c 8a bd 2e c0 d5 45 b0 75 7f 94 a9 f3 53 82 80 e5 6d b5 f5 d8 ec " + "f8 4b c5 4e 68 81 a3 51 82 76 5f b8 40 ca 27 68 37 02 a8 e9 bf 32 01 65 6f f8 4a 60 d5 b1 dd 81 42 " + "73 99 3c f1 a0 25 b0 54 45 4e 40 d5 30 92 f4 85 18 ee 05 be ad 4f 18 02 1f 4f 54 0c 0b 7c 7d 26 eb " + "a5 0e a4 89 0b 9e 5e 49 a7 6c 5f f8 4a c4 55 41 7e 2d 82 76 5f b8 40 cb 72 be 9e 2e 5d 4a 1f 25 72 " + "96 c7 39 39 10 4e ce 80 31 32 15 26 5a f0 6b c7 ea f4 42 ab ff 4f 0b 48 fc fc 6f 43 f4 df 46 30 c7 " + "12 b5 e7 ef db 75 4a 86 e4 0c f2 02 16 6e b6 9e ea a6 ad 3a 2d f8 4a c4 36 48 1f 37 82 76 5f b8 40 " + "ce 73 66 0a 06 62 6c 1b 3f da 7b 18 ef 7b a3 ce 17 b6 bf 60 4f 95 41 d3 c6 c6 54 b7 ae 88 b2 39 40 " + "7f 65 9c 78 f4 19 02 5d 78 57 27 ed 01 7b 6a dd 21 95 2d 7e 12 00 73 73 e3 21 db c3 18 24 ba f8 4a " + "c4 55 41 7e 2d 82 76 5f b8 40 ce 73 f1 f1 f1 f1 6c 1b 3f da 7b 18 ef 7b a3 ce 17 b6 f1 f1 f1 f1 41 " + "d3 c6 c6 54 b7 ae 88 b2 39 40 7f f1 f1 f1 f1 19 02 5d 78 57 27 ed 01 7b 6a dd 21 f1 f1 f1 f1 00 00 " + "01 e3 21 db c3 18 24 ba f8 4c c6 81 bf 81 ea 39 37 82 76 5f b8 40 d2 30 30 60 35 99 b7 6f 64 0b 8f " + "7c 11 99 12 bb 04 66 e7 ee f3 38 cd 9d e5 67 d2 b6 df ba 81 72 8d b2 e9 8f 29 38 25 bb 00 a9 a6 ac " + "93 66 83 fc 82 c8 bc 38 7a df 3a 4a 5f e1 cc ca dd 1a 74 59 f8 4c c6 6b 81 aa 39 81 f7 82 76 5f b8 " + "40 e0 2b 18 fb a6 b8 87 fb 92 58 46 9c 3a f8 e4 45 cc 9a e2 b5 38 6c ac 5f 60 c4 17 0f 82 20 86 22 " + "4e 38 76 55 5c 74 5a 7e c8 ac 18 1c 7f 97 01 77 6d 94 a7 79 60 4e a1 26 51 de 5f 4a 74 8d 29 e1 f8 " + "4c c6 40 81 e7 0a 81 d0 82 76 5f b8 40 e3 11 15 a7 6f a7 fb 2e fd 3c fa f4 6a d0 0b 05 fc 34 98 e1 " + "ba f1 78 5d ff e6 ca 69 91 3d 25 65 31 d1 80 56 42 35 fd 3d 3c 10 40 9c d1 1f c2 59 cf 7c fd a9 b6 " + "bb 25 33 40 41 2d 82 87 8f 3b d3 f8 4b c5 41 5e 31 81 97 82 76 5f b8 40 e5 e8 d8 c2 d7 62 d2 1c a1 " + "e9 bc ee 8a dc 53 60 0f 2d 89 40 97 54 26 66 d6 b5 f4 1b 23 58 4b 07 f6 09 01 ab 40 9d df 91 e0 cd " + "25 62 da ff f2 cb 0f 22 1e b9 f1 15 6f 78 1a 5d 99 31 a0 2a 2e 07 f8 4a c4 55 41 7e 2d 82 76 5f b8 " + "40 ea 99 2c 13 68 7c 20 e7 90 a9 ff a6 df 8b 1a 16 86 88 e2 a8 87 36 5d 7a 50 21 86 fa 0d 62 20 e8 " + "3e 11 3a 1f e7 7d c0 68 9d 55 ba 2e 8a 83 aa 8e 20 42 18 f4 d8 e7 32 82 5b d7 80 cf 94 ed 5c c3 f8 " + "4b c5 56 7c 52 81 fe 82 76 5f b8 40 f6 15 5f 1a 60 14 3b 7d 9d 5d 1a 44 0d 7d 52 fe 68 09 f6 9e 0c " + "6f 1e 00 24 45 7e 0d 71 dd 88 ad e3 b1 3a aa 94 0c 89 ac 06 10 95 2b 48 bd 83 2c 42 e3 43 a1 3e 61 " + "ff db 06 01 0c ff c3 45 e0 53 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 40 fa 56 85 61 b7 d5 28 8d f7 " + "a5 06 c9 bc 1c 95 12 ab 39 6e 68 c4 6f 0e 62 c2 1d c1 aa 58 4b 84 4a 8a 7e 94 4f 69 71 30 36 65 fd " + "37 b1 38 d9 a5 f6 37 e6 72 ed b9 89 69 66 4c 4e 7f d1 c4 12 6d ef"; byte[] payload = Hex.decode(peers); ArrayList<RLPElement> rlpList = decode2(payload); }
|
@Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void doesnt_parse_if_tx_doesnt_have_inputs() { BtcTransaction btcTx = new BtcTransaction(networkParameters); BtcLockSender btcLockSender = new P2pkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_tx_doesnt_have_scriptsig() { BtcTransaction btcTx = new BtcTransaction(networkParameters); btcTx.addInput(new TransactionInput(networkParameters, null, null)); BtcLockSender btcLockSender = new P2pkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void doesnt_parse_if_tx_scriptsig_doesnt_have_two_chunks() { BtcTransaction btcTx = new BtcTransaction(networkParameters); btcTx.addInput(new TransactionInput(networkParameters, null, new byte[]{0x00})); BtcLockSender btcLockSender = new P2pkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void rejects_p2sh_p2wpkh_transaction() { String rawTx = RawTransactions.txs.get(BtcLockSender.TxType.P2SHP2WPKH); BtcTransaction btcTx = new BtcTransaction(networkParameters, Hex.decode(rawTx)); BtcLockSender btcLockSender = new P2pkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void rejects_p2sh_multisig_transaction() { String rawTx = RawTransactions.txs.get(BtcLockSender.TxType.P2SHMULTISIG); BtcTransaction btcTx = new BtcTransaction(networkParameters, Hex.decode(rawTx)); BtcLockSender btcLockSender = new P2pkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void rejects_p2sh_p2wsh_transaction() { String rawTx = RawTransactions.txs.get(BtcLockSender.TxType.P2SHP2WSH); BtcTransaction btcTx = new BtcTransaction(networkParameters, Hex.decode(rawTx)); BtcLockSender btcLockSender = new P2pkhBtcLockSender(); Assert.assertFalse(btcLockSender.tryParse(btcTx)); }
|
public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
P2pkhBtcLockSender implements BtcLockSender { public boolean tryParse (BtcTransaction btcTx) { if (btcTx == null) { return false; } if (btcTx.getInputs().size() == 0) { return false; } if (btcTx.getInput(0).getScriptBytes() == null) { return false; } Script scriptSig = btcTx.getInput(0).getScriptSig(); if (scriptSig.getChunks().size() != 2) { return false; } try { byte[] data = scriptSig.getChunks().get(1).data; BtcECKey senderBtcKey = BtcECKey.fromPublicOnly(data); this.btcAddress = new Address(btcTx.getParams(), senderBtcKey.getPubKeyHash()); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(data); this.rskAddress = new RskAddress(key.getAddress()); } catch(Exception e) { return false; } return true; } P2pkhBtcLockSender(); BtcLockSender.TxType getType(); Address getBTCAddress(); RskAddress getRskAddress(); boolean tryParse(BtcTransaction btcTx); }
|
@Test public void gets_null_if_btc_transaction_is_not_valid() { BtcLockSenderProvider provider = new BtcLockSenderProvider(); assertFalse(provider.tryGetBtcLockSender(null).isPresent()); assertFalse(provider.tryGetBtcLockSender(new BtcTransaction(params)).isPresent()); }
|
public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); }
|
BtcLockSenderProvider { public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); } }
|
BtcLockSenderProvider { public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); } }
|
BtcLockSenderProvider { public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); } Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx); }
|
BtcLockSenderProvider { public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); } Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx); }
|
@Test public void gets_valid_sender_from_p2pkh_btc_transaction() { BtcLockSenderProvider provider = new BtcLockSenderProvider(); String rawTx = "02000000028f7efa7cf43fe0d7e557327f02fbebf72049a28715f3c0747b902b061a464c2f010000006a47304402201c1c7ee" + "58d152768e7d71010856e501a979c35ab97168dd2b15d155dbe60b8fe022027c8c7c0d16398df212b3997ac67220bbb0abdacfd89be7020b" + "25731c9d401af0121027bb07922f9266efc9eb650d94133b995bfcfa80d49011d52807c81ab700247acffffffff3e185adee7df6eeb167d1eaeed" + "3869d6a6e1c72f79fcc9c4c5b9a326961267790000000048473044022027b97e40c064014c08decfe7b0c6111df52c392a96409b6ce45b665255ba2" + "97e022067901051359d85760a2649c08c5a230e712c5ba6a7d89be0cd65f52ff352e2bd01feffffff0200e1f505000000001976a9149a81fd1d49be2ee5" + "ada2bc96c2e0363f27f2e1dd88ac6c3d7d010000000017a914d7f3aadae6afc7b55c75675a42010c7c67450c6c8700000000"; BtcTransaction tx = new BtcTransaction(BridgeRegTestConstants.getInstance().getBtcParams(), Hex.decode(rawTx)); org.ethereum.crypto.ECKey key = org.ethereum.crypto.ECKey.fromPublicOnly(Hex.decode("027bb07922f9266efc9eb650d94133b995bfcfa80d49011d52807c81ab700247ac")); RskAddress senderAddress = new RskAddress(key.getAddress()); Optional<BtcLockSender> result = provider.tryGetBtcLockSender(tx); assertTrue(result.isPresent()); BtcLockSender btcLockSender = result.get(); Assert.assertEquals(BtcLockSender.TxType.P2PKH, btcLockSender.getType()); Assert.assertEquals(senderAddress, btcLockSender.getRskAddress()); Assert.assertEquals("mpgJ8n2NUf23NHcJs59LgEqQ4yCv7MYGU6", btcLockSender.getBTCAddress().toBase58()); }
|
public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); }
|
BtcLockSenderProvider { public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); } }
|
BtcLockSenderProvider { public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); } }
|
BtcLockSenderProvider { public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); } Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx); }
|
BtcLockSenderProvider { public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); } Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx); }
|
@Test public void gets_valid_sender_from_p2sh_p2wpkh_btc_transaction() { BtcLockSenderProvider provider = new BtcLockSenderProvider(); String rawTx = "020000000001017001d967a340069c0b169fcbeb9cb6e0d78a27c94a41acbce762abc695aefab10000000017160014cfa63de9979e2a8005e6cb516b86202860ff3971ffffffff0200c2eb0b0000000017a914291a7ddc558810708149a731f39cd3c3a8782cfd870896e1110000000017a91425a2e67511a0207c4387ce8d3eeef498a4782e64870247304402207e0615f440bbc50351fb5d8839b3fae6c74f652c9ffc9291008f4ea39f9565980220354c734511a0560367b300eecb1a7472317a995462622e06ee91cbe0517c17e1012102e87cd90f3cb0d64eeba797fbb8f8ceaadc09e0128afbaefb0ee9535875ea395400000000"; BtcTransaction tx = new BtcTransaction(BridgeRegTestConstants.getInstance().getBtcParams(), Hex.decode(rawTx)); Optional<BtcLockSender> result = provider.tryGetBtcLockSender(tx); assertTrue(result.isPresent()); BtcLockSender btcLockSender = result.get(); BtcECKey key = BtcECKey.fromPublicOnly(Hex.decode("02e87cd90f3cb0d64eeba797fbb8f8ceaadc09e0128afbaefb0ee9535875ea3954")); byte[] scriptHash = Hex.decode("bf79dcd97426a127d4ed39385fa58feeb7272387"); Assert.assertEquals(new Address(tx.getParams(), tx.getParams().getP2SHHeader(), scriptHash), btcLockSender.getBTCAddress()); Assert.assertEquals(new RskAddress(ECKey.fromPublicOnly(key.getPubKey()).getAddress()), btcLockSender.getRskAddress()); Assert.assertEquals(BtcLockSender.TxType.P2SHP2WPKH, btcLockSender.getType()); }
|
public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); }
|
BtcLockSenderProvider { public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); } }
|
BtcLockSenderProvider { public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); } }
|
BtcLockSenderProvider { public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); } Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx); }
|
BtcLockSenderProvider { public Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx) { if (tx == null) { return Optional.empty(); } BtcLockSender result; result = new P2pkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wpkhBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shMultisigBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } result = new P2shP2wshBtcLockSender(); if (result.tryParse(tx)) { return Optional.of(result); } return Optional.empty(); } Optional<BtcLockSender> tryGetBtcLockSender(BtcTransaction tx); }
|
@Test public void getChainHead_Test() throws BlockStoreException { BtcBlockStoreWithCache btcBlockStore = createBlockStore(); assertEquals(networkParameters.getGenesisBlock(), btcBlockStore.getChainHead().getHeader()); }
|
@Override public synchronized StoredBlock getChainHead() { byte[] ba = repository.getStorageBytes(contractAddress, DataWord.fromString(BLOCK_STORE_CHAIN_HEAD_KEY)); if (ba == null) { return null; } return byteArrayToStoredBlock(ba); }
|
RepositoryBtcBlockStoreWithCache implements BtcBlockStoreWithCache { @Override public synchronized StoredBlock getChainHead() { byte[] ba = repository.getStorageBytes(contractAddress, DataWord.fromString(BLOCK_STORE_CHAIN_HEAD_KEY)); if (ba == null) { return null; } return byteArrayToStoredBlock(ba); } }
|
RepositoryBtcBlockStoreWithCache implements BtcBlockStoreWithCache { @Override public synchronized StoredBlock getChainHead() { byte[] ba = repository.getStorageBytes(contractAddress, DataWord.fromString(BLOCK_STORE_CHAIN_HEAD_KEY)); if (ba == null) { return null; } return byteArrayToStoredBlock(ba); } RepositoryBtcBlockStoreWithCache(NetworkParameters btcNetworkParams, Repository repository, Map<Sha256Hash, StoredBlock> cacheBlocks, RskAddress contractAddress); }
|
RepositoryBtcBlockStoreWithCache implements BtcBlockStoreWithCache { @Override public synchronized StoredBlock getChainHead() { byte[] ba = repository.getStorageBytes(contractAddress, DataWord.fromString(BLOCK_STORE_CHAIN_HEAD_KEY)); if (ba == null) { return null; } return byteArrayToStoredBlock(ba); } RepositoryBtcBlockStoreWithCache(NetworkParameters btcNetworkParams, Repository repository, Map<Sha256Hash, StoredBlock> cacheBlocks, RskAddress contractAddress); @Override synchronized void put(StoredBlock storedBlock); @Override synchronized StoredBlock get(Sha256Hash hash); @Override synchronized StoredBlock getChainHead(); @Override synchronized void setChainHead(StoredBlock newChainHead); @Override void close(); @Override NetworkParameters getParams(); @Override StoredBlock getFromCache(Sha256Hash branchBlockHash); @Override StoredBlock getStoredBlockAtMainChainHeight(int height); @Override StoredBlock getStoredBlockAtMainChainDepth(int depth); }
|
RepositoryBtcBlockStoreWithCache implements BtcBlockStoreWithCache { @Override public synchronized StoredBlock getChainHead() { byte[] ba = repository.getStorageBytes(contractAddress, DataWord.fromString(BLOCK_STORE_CHAIN_HEAD_KEY)); if (ba == null) { return null; } return byteArrayToStoredBlock(ba); } RepositoryBtcBlockStoreWithCache(NetworkParameters btcNetworkParams, Repository repository, Map<Sha256Hash, StoredBlock> cacheBlocks, RskAddress contractAddress); @Override synchronized void put(StoredBlock storedBlock); @Override synchronized StoredBlock get(Sha256Hash hash); @Override synchronized StoredBlock getChainHead(); @Override synchronized void setChainHead(StoredBlock newChainHead); @Override void close(); @Override NetworkParameters getParams(); @Override StoredBlock getFromCache(Sha256Hash branchBlockHash); @Override StoredBlock getStoredBlockAtMainChainHeight(int height); @Override StoredBlock getStoredBlockAtMainChainDepth(int depth); static final String BLOCK_STORE_CHAIN_HEAD_KEY; static final int MAX_DEPTH_STORED_BLOCKS; static final int MAX_SIZE_MAP_STORED_BLOCKS; }
|
@Test public void test14() { String blocksMsg = "f91c1c13f90150f8c4a07df3d35d4df0a56fcf1d6344d5315cb56b9bf83bb96ad17c7b96a9cd14133c5da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a064afb6284fa35f26d7b2c5a26afaa5483072fbcb575221b34ce002a991b7a223a04a8abe6d802797dc80b497584f898c2d4fd561cc185828cfa1b92f6f38ee348e833fbfe484533f201c80a000000000000000000000000000000000000000000000000000cfccb5cfd4667cf887f8850380942d0aceee7e5ab874e22ccf8d1a649f59106d74e88609184e72a000822710a047617600000000000000000000000000000000000000000000000000000000001ca08691ab40e258de3c4f55c868c0c34e780e747158a1d96ca50186dfd3305abd78a042269c981d048a7b791aafc8f4e644232740c1a1cceb5b6d05568827a64c0664c0f8c8f8c4a0637c8a6cdb907fac6f752334ab79065bcc4e46cd4f4358dbc2a653544a20eb31a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a022a36c1a1e807e6afc22e6bb53a31111f56e7ee7dbb2ee571cefb152b514db4da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fcfd784533f1cf980a0000000000000000000000000000000000000000000000000e153d743fa040b18c0c0f8c8f8c4a07b2536237cbf114a043b0f9b27c76f84ac160ea5b87b53e42c7e76148964d450a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07a3be0ee10ece4b03097bf74aabac628aa0fae617377d30ab1b97376ee31f41aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fbfe884533f1ce880a0000000000000000000000000000000000000000000000000f3deea84969b6e95c0c0f8c8f8c4a0d2ae3f5dd931926de428d99611980e7cdd7c1b838273e43fcad1b94da987cfb8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a00b5b11fcf4ee12c6812f9d01cf0dff07c72cd7e02e48b35682f67c595407be14a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833faffd84533f1ce280a00000000000000000000000000000000000000000000000005fcbc97b2eb8ffb3c0c0f8c8f8c4a094d615d3cb4b306d20985028c78f0c8413d509a75e8bb84eda95f734debad2a0a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a04b8fd1b98cf5758bd303ff86393eb6d944c1058124bddce5d4e04b5395254d5ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fbfec84533f1c7680a000000000000000000000000000000000000000000000000079fe3710116b32aac0c0f8c8f8c4a09424a07a0e4c05bb872906c40844a75b76f6517467b79c12fa9cc6d79ae09934a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a02dbe9ff9cbbc4c5a6ff26971f75b405891141f4e9bce3c2dc4200a305138e584a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fcfdf84533f1c3b80a0000000000000000000000000000000000000000000000000e0a6f8cf1d56031bc0c0f8c8f8c4a009aabea60cf7eaa9df4afdf4e1b5f3e684dab34fc9a9180a050085a4131ceedfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0436da067f9683029e717edf92da46c3443e8c342974f47a563302a0678efe702a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdfd684533f1bfc80a00000000000000000000000000000000000000000000000005bc88c041662ffdac0c0f8c8f8c4a0f8b104093483b7c0182e1bba2ce3340d14469d3a3ee7646821223a676c680ac1a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0d482e71cde61190a33ca5aeb88b6b06276984e5a14253a98df232e8767167221a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefd184533f1bce80a00000000000000000000000000000000000000000000000004aeb31823f6a1950c0c0f8c8f8c4a0dd1f0aba02c2bb3b5a2b6cb1cc907ea70912bd46dc7a78577f2cae6cdbcbe5f3a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a058ab6df33d7cbeb6a735a7e4ccf4f28143e6a1742e45dda8f8cf48af43cb66c0a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffd084533f1b9f80a0000000000000000000000000000000000000000000000000577042b0858b510bc0c0f8c8f8c4a0a287bb7da30f04344976abe569bd719f69c1cbea65533e5311ca5862e6eaa504a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07e0537009c23cb1152caf84a52272431f74b6140866b15805622b7bcb607cd42a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934783400fd384533f1b6180a000000000000000000000000000000000000000000000000083d31378a0993e1ac0c0f8c8f8c4a063483cff8fbd489e6ce273326d8dc1d54a31c67f936ca84bf500e5419d3e9805a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07737d08564819d51f8f834a6ee4278c23a0c2f29a3f485b21002c1f24f04d8e4a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffd484533f1b5780a0000000000000000000000000000000000000000000000000bb586fe6de016e14c0c0f8c8f8c4a0975c8ed0c9197b7c018e02e1c95f315acf82b25e4a812140f4515e8bc827650ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ad51229abead59e93c80db5ba160f0939bc49dcee65d1c081f6eb040ff1f571fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefd984533f1b4e80a0000000000000000000000000000000000000000000000000548f02c6ceb26fd4c0c0f8c8f8c4a05844082e41f7c1f34485c7902afa0aa0979a6a849100fc553cd946f4a663929ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a01bc726443437c4c062be18d052278e4ef735b8fe84387c8a4fc85fb70d5078e0a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffd884533f1b1080a0000000000000000000000000000000000000000000000000cc1e528f54f22bdac0c0f8c8f8c4a0ba06ba81c93faaf98ea2d83cbdc0788958d938b29a9eb2a92ffbd4a628b3d52ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a05053bfe1c0f1f0dd341c6df35e5a659989be041e8521027cc90f7605eb15fbb9a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefdd84533f1b0380a0000000000000000000000000000000000000000000000000bcf9df2fec615ecac0c0f8c8f8c4a083732d997db15109e90464c24b7c959a78881d827c55a0d668a66a2736be5d87a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a054f4012cba33a2b80b0dca9dd52f56b2c588133bd71700863f8cb95127176634a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffdc84533f1a4680a00000000000000000000000000000000000000000000000006920a1dc9d915d0ec0c0f8c8f8c4a052e2fba761c2d0643170ef041c017391e781190fe715ae87cdae8eee1d45d95ba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ee2c82f77d7afd1f8dbe4f791df8477496c23e5504b9d66814172077f65f81f2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefe184533f1a3880a0000000000000000000000000000000000000000000000000ae86da9012398fc4c0c0f8c8f8c4a055703ba09544f386966b6d63bfc31033b761a4d1a6bb86b0cf49b4bb0526744ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a01684c03a675b53786f0077d1651c3d169a009b13a6ee2b5047be6dbbe6d957ffa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdfea84533f1a2f80a00000000000000000000000000000000000000000000000003247320d0eb639dfc0c0f8c8f8c4a05109a79b33d81f4ee4814b550fb0002f03368d67570f6d4e6105fce2874d8b72a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ae72e8c60a3dcfd53deecdb2790d18f0cc710f77cf2c1ed76e7da829bde619dca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fcff784533f1a1d80a000000000000000000000000000000000000000000000000040e0bc9bc9bcf295c0c0f8c8f8c4a03961e4bbba5c95fad3db0cffa3a16b9106f9ea3e8957993eab576b683c22f416a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0e9c6cf457bbe64d6bda67852a276cdbadb4f384a36d496e81801a496cfd9b7b5a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdfee84533f19df80a0000000000000000000000000000000000000000000000000dbb3fd6c816776d8c0c0f8c8f8c4a06b8265a357cb3ad744e19f04eb15377f660c10c900cc352d24f9b09073a363d6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07ba07e1bc6a20ffa44ae6080d30982b9faa148faf6b1ec15e32d89ac853ac291a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefe984533f198d80a00000000000000000000000000000000000000000000000005171325b6a2f17f1c0c0f8c8f8c4a0dcdc0347bb87ce72d49ac2e4e11f89069509b129a2536bf3d57c6bca30894032a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ca24447aa0cedb4b561c7810461eef19b16a827c27352e5e01f914e9d7c78247a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffe884533f194680a0000000000000000000000000000000000000000000000000da4714cfed9d8bbcc0c0f8c8f8c4a047f2dd6c15ea4082b3e11e5cf6b925b27e51d9de68051a093e52ef465cffbb8ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a05a7206edddf50fcfeeaa97348a7112fc6edd0b5eacb44cf43d6a6c6b6609b459a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefed84533f193e80a0000000000000000000000000000000000000000000000000ffafba4bf8dc944ec0c0f8c8f8c4a04d5ad6d860772145872f6660ecefcb0b0b2056e0aa3509a48bf4c175459e5121a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a00f4659d09bb2ced56e7fd9c4d3d90daca8b4f471307b7c4385fd34a41016b0b2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdff684533f192580a000000000000000000000000000000000000000000000000090620e5e59a39fe5c0c0f8c8f8c4a0c1725c58d1bf023af468e0088db3cf642ae097cf2c58c2ece2fc746980acc7e6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0be19a182ea1584050deb0a79abdc11be896ce8d00a282bcfaf9ffcd65fd64d6aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833feff184533f189080a000000000000000000000000000000000000000000000000076f17f4199bccd12c0c0f8c8f8c4a0bd521a20a18ca6ca7115065065a1aa20067ee580fb11e2963d1e3a681e8302afa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a011be45633350e39475a1a07712ba72de4602d9eebf639ccd5422a389095ccaf1a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdffa84533f187b80a00000000000000000000000000000000000000000000000000c71b81c4a4cb82cc0c0f8c8f8c4a07c6d2d56e9c87f1553e4d06705af61a7c19a6046d2c39f8ed1417988783d3b1da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a012f5f0668063509e33a45a64eb6a072b2d84aa19f430f49f159be5008a786b2ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fd00684533f186080a0000000000000000000000000000000000000000000000000b3f962892cfec9e6c0c0f8c8f8c4a07154f0f8ecc7f791d22eec06ec86d87a44b2704f015b3d2cff3571a3d01ae0f6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a079536abf8e163cf8aa97f0d52866d04363902d591fd7c36aa35fc983d45fefd6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdffd84533f182f80a0000000000000000000000000000000000000000000000000736716e42499890fc0c0f8c8f8c4a0bf2fb1ee988ac4e17eae221a24176649774333fab25b6fc96c6081527fb6f121a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a041578daae7bcccd4976340aeb19e4132d2fe4193a0d92f87744c82bfe113502fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fd00984533f182b80a00000000000000000000000000000000000000000000000001c62fa76645942c6c0c0f8c8f8c4a07f84873e2679d40458b9dda9900478a78871044e08f6b47dad659b9b60ff8d48a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0597d3f4160770c0492333f90bad739dc05117d0e478a91f09573742e432904e8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fe00184533f17f680a0000000000000000000000000000000000000000000000000e24d8b1140fb34d5c0c0f8c8f8c4a0fd77bd13a8cde1766537febe751a27a2a31310a04638a1afcd5e8ad3c5485453a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0473b2b248d91010ba9aec2696ffc93c11c415ed132832be0fd0578f184862e13a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833feffc84533f17ca80a0000000000000000000000000000000000000000000000000fb5b65bac3f0d947c0c0f8c8f8c4a0518916dfb79c390bd7bff75712174512c2f96bec42a3f573355507ad1588ce0ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a08599d2ec9e95ec62f41a4975b655d8445d6767035f94eb235ed5ebea976fb9eaa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fe00484533f17b880a0000000000000000000000000000000000000000000000000bc27f4b8a201476bc0c0f90319f8c4a0ab6b9a5613970faa771b12d449b2e9bb925ab7a369f0a4b86b286e9d540099cfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0990dc3b5acbee04124361d958fe51acb582593613fc290683940a0769549d3eda09bfe4817d274ea3eb8672e9fe848c3885b53bbbd1d7c26e6039f90fb96b942b0833ff00084533f16b780a000000000000000000000000000000000000000000000000077377adff6c227dbf9024ff89d80809400000000000000000000000000000000000000008609184e72a000822710b3606956330c0d630000003359366000530a0d630000003359602060005301356000533557604060005301600054630000000c5884336069571ca07f6eb94576346488c6253197bde6a7e59ddc36f2773672c849402aa9c402c3c4a06d254e662bf7450dd8d835160cbb053463fed0b53f2cdd7f3ea8731919c8e8ccf9010501809400000000000000000000000000000000000000008609184e72a000822710b85336630000002e59606956330c0d63000000155933ff33560d63000000275960003356576000335700630000005358600035560d630000003a590033560d63000000485960003356573360003557600035335700b84a7f4e616d65526567000000000000000000000000000000000000000000000000003057307f4e616d655265670000000000000000000000000000000000000000000000000057336069571ba04af15a0ec494aeac5b243c8a2690833faa74c0f73db1f439d521c49c381513e9a05802e64939be5a1f9d4d614038fbd5479538c48795614ef9c551477ecbdb49d2f8a6028094ccdeac59d35627b7de09332e819d5159e7bb72508609184e72a000822710b84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d0aceee7e5ab874e22ccf8d1a649f59106d74e81ba0d05887574456c6de8f7a0d172342c2cbdd4cf7afe15d9dbb8b75b748ba6791c9a01e87172a861f6c37b5a9e3a5d0d7393152a7fbe41530e5bb8ac8f35433e5931bc0"; byte[] payload = Hex.decode(blocksMsg); ArrayList<RLPElement> rlpList = decode2(payload); }
|
@Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void getParams_Test() { BtcBlockStoreWithCache btcBlockStore = createBlockStore(); assertEquals(networkParameters, btcBlockStore.getParams()); }
|
@Override public NetworkParameters getParams() { return btcNetworkParams; }
|
RepositoryBtcBlockStoreWithCache implements BtcBlockStoreWithCache { @Override public NetworkParameters getParams() { return btcNetworkParams; } }
|
RepositoryBtcBlockStoreWithCache implements BtcBlockStoreWithCache { @Override public NetworkParameters getParams() { return btcNetworkParams; } RepositoryBtcBlockStoreWithCache(NetworkParameters btcNetworkParams, Repository repository, Map<Sha256Hash, StoredBlock> cacheBlocks, RskAddress contractAddress); }
|
RepositoryBtcBlockStoreWithCache implements BtcBlockStoreWithCache { @Override public NetworkParameters getParams() { return btcNetworkParams; } RepositoryBtcBlockStoreWithCache(NetworkParameters btcNetworkParams, Repository repository, Map<Sha256Hash, StoredBlock> cacheBlocks, RskAddress contractAddress); @Override synchronized void put(StoredBlock storedBlock); @Override synchronized StoredBlock get(Sha256Hash hash); @Override synchronized StoredBlock getChainHead(); @Override synchronized void setChainHead(StoredBlock newChainHead); @Override void close(); @Override NetworkParameters getParams(); @Override StoredBlock getFromCache(Sha256Hash branchBlockHash); @Override StoredBlock getStoredBlockAtMainChainHeight(int height); @Override StoredBlock getStoredBlockAtMainChainDepth(int depth); }
|
RepositoryBtcBlockStoreWithCache implements BtcBlockStoreWithCache { @Override public NetworkParameters getParams() { return btcNetworkParams; } RepositoryBtcBlockStoreWithCache(NetworkParameters btcNetworkParams, Repository repository, Map<Sha256Hash, StoredBlock> cacheBlocks, RskAddress contractAddress); @Override synchronized void put(StoredBlock storedBlock); @Override synchronized StoredBlock get(Sha256Hash hash); @Override synchronized StoredBlock getChainHead(); @Override synchronized void setChainHead(StoredBlock newChainHead); @Override void close(); @Override NetworkParameters getParams(); @Override StoredBlock getFromCache(Sha256Hash branchBlockHash); @Override StoredBlock getStoredBlockAtMainChainHeight(int height); @Override StoredBlock getStoredBlockAtMainChainDepth(int depth); static final String BLOCK_STORE_CHAIN_HEAD_KEY; static final int MAX_DEPTH_STORED_BLOCKS; static final int MAX_SIZE_MAP_STORED_BLOCKS; }
|
@Test public void whenNewFederationIsNullThenActiveFederationIsGenesisFederation() { Federation genesisFederation = getNewFakeFederation(0); when(provider.getNewFederation()) .thenReturn(null); when(bridgeConstants.getGenesisFederation()) .thenReturn(genesisFederation); assertThat(federationSupport.getActiveFederation(), is(genesisFederation)); }
|
public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); int getFederationSize(); byte[] getFederatorBtcPublicKey(int index); byte[] getFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix); Federation getActiveFederation(); @Nullable Federation getRetiringFederation(); List<UTXO> getActiveFederationBtcUTXOs(); List<UTXO> getRetiringFederationBtcUTXOs(); boolean amAwaitingFederationActivation(); }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); int getFederationSize(); byte[] getFederatorBtcPublicKey(int index); byte[] getFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix); Federation getActiveFederation(); @Nullable Federation getRetiringFederation(); List<UTXO> getActiveFederationBtcUTXOs(); List<UTXO> getRetiringFederationBtcUTXOs(); boolean amAwaitingFederationActivation(); }
|
@Test public void whenOldFederationIsNullThenActiveFederationIsNewFederation() { Federation newFederation = getNewFakeFederation(100); when(provider.getNewFederation()) .thenReturn(newFederation); when(provider.getOldFederation()) .thenReturn(null); assertThat(federationSupport.getActiveFederation(), is(newFederation)); }
|
public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); int getFederationSize(); byte[] getFederatorBtcPublicKey(int index); byte[] getFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix); Federation getActiveFederation(); @Nullable Federation getRetiringFederation(); List<UTXO> getActiveFederationBtcUTXOs(); List<UTXO> getRetiringFederationBtcUTXOs(); boolean amAwaitingFederationActivation(); }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); int getFederationSize(); byte[] getFederatorBtcPublicKey(int index); byte[] getFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix); Federation getActiveFederation(); @Nullable Federation getRetiringFederation(); List<UTXO> getActiveFederationBtcUTXOs(); List<UTXO> getRetiringFederationBtcUTXOs(); boolean amAwaitingFederationActivation(); }
|
@Test public void whenOldAndNewFederationArePresentReturnOldFederationByActivationAge() { Federation newFederation = getNewFakeFederation(75); Federation oldFederation = getNewFakeFederation(0); when(provider.getNewFederation()) .thenReturn(newFederation); when(provider.getOldFederation()) .thenReturn(oldFederation); when(executionBlock.getNumber()) .thenReturn(80L); when(bridgeConstants.getFederationActivationAge()) .thenReturn(10L); assertThat(federationSupport.getActiveFederation(), is(oldFederation)); }
|
public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); int getFederationSize(); byte[] getFederatorBtcPublicKey(int index); byte[] getFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix); Federation getActiveFederation(); @Nullable Federation getRetiringFederation(); List<UTXO> getActiveFederationBtcUTXOs(); List<UTXO> getRetiringFederationBtcUTXOs(); boolean amAwaitingFederationActivation(); }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); int getFederationSize(); byte[] getFederatorBtcPublicKey(int index); byte[] getFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix); Federation getActiveFederation(); @Nullable Federation getRetiringFederation(); List<UTXO> getActiveFederationBtcUTXOs(); List<UTXO> getRetiringFederationBtcUTXOs(); boolean amAwaitingFederationActivation(); }
|
@Test public void whenOldAndNewFederationArePresentReturnNewFederationByActivationAge() { Federation newFederation = getNewFakeFederation(65); Federation oldFederation = getNewFakeFederation(0); when(provider.getNewFederation()) .thenReturn(newFederation); when(provider.getOldFederation()) .thenReturn(oldFederation); when(executionBlock.getNumber()) .thenReturn(80L); when(bridgeConstants.getFederationActivationAge()) .thenReturn(10L); assertThat(federationSupport.getActiveFederation(), is(newFederation)); }
|
public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); int getFederationSize(); byte[] getFederatorBtcPublicKey(int index); byte[] getFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix); Federation getActiveFederation(); @Nullable Federation getRetiringFederation(); List<UTXO> getActiveFederationBtcUTXOs(); List<UTXO> getRetiringFederationBtcUTXOs(); boolean amAwaitingFederationActivation(); }
|
FederationSupport { public Federation getActiveFederation() { switch (getActiveFederationReference()) { case NEW: return provider.getNewFederation(); case OLD: return provider.getOldFederation(); case GENESIS: default: return bridgeConstants.getGenesisFederation(); } } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); int getFederationSize(); byte[] getFederatorBtcPublicKey(int index); byte[] getFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix); Federation getActiveFederation(); @Nullable Federation getRetiringFederation(); List<UTXO> getActiveFederationBtcUTXOs(); List<UTXO> getRetiringFederationBtcUTXOs(); boolean amAwaitingFederationActivation(); }
|
@Test public void getMemberPublicKeyOfType() { BtcECKey btcKey0 = new BtcECKey(); ECKey rskKey0 = new ECKey(); ECKey mstKey0 = new ECKey(); BtcECKey btcKey1 = new BtcECKey(); ECKey rskKey1 = new ECKey(); ECKey mstKey1 = new ECKey(); List<FederationMember> members = Arrays.asList( new FederationMember(btcKey0, rskKey0, mstKey0), new FederationMember(btcKey1, rskKey1, mstKey1) ); Assert.assertTrue(Arrays.equals(federationSupport.getMemberPublicKeyOfType(members, 0, FederationMember.KeyType.BTC, "a prefix"), btcKey0.getPubKey())); Assert.assertTrue(Arrays.equals(federationSupport.getMemberPublicKeyOfType(members, 1, FederationMember.KeyType.BTC, "a prefix"), btcKey1.getPubKey())); Assert.assertTrue(Arrays.equals(federationSupport.getMemberPublicKeyOfType(members, 0, FederationMember.KeyType.RSK, "a prefix"), rskKey0.getPubKey(true))); Assert.assertTrue(Arrays.equals(federationSupport.getMemberPublicKeyOfType(members, 1, FederationMember.KeyType.RSK, "a prefix"), rskKey1.getPubKey(true))); Assert.assertTrue(Arrays.equals(federationSupport.getMemberPublicKeyOfType(members, 0, FederationMember.KeyType.MST, "a prefix"), mstKey0.getPubKey(true))); Assert.assertTrue(Arrays.equals(federationSupport.getMemberPublicKeyOfType(members, 1, FederationMember.KeyType.MST, "a prefix"), mstKey1.getPubKey(true))); }
|
public byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix) { if (index < 0 || index >= members.size()) { throw new IndexOutOfBoundsException(String.format("%s index must be between 0 and %d", errorPrefix, members.size() - 1)); } return members.get(index).getPublicKey(keyType).getPubKey(true); }
|
FederationSupport { public byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix) { if (index < 0 || index >= members.size()) { throw new IndexOutOfBoundsException(String.format("%s index must be between 0 and %d", errorPrefix, members.size() - 1)); } return members.get(index).getPublicKey(keyType).getPubKey(true); } }
|
FederationSupport { public byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix) { if (index < 0 || index >= members.size()) { throw new IndexOutOfBoundsException(String.format("%s index must be between 0 and %d", errorPrefix, members.size() - 1)); } return members.get(index).getPublicKey(keyType).getPubKey(true); } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); }
|
FederationSupport { public byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix) { if (index < 0 || index >= members.size()) { throw new IndexOutOfBoundsException(String.format("%s index must be between 0 and %d", errorPrefix, members.size() - 1)); } return members.get(index).getPublicKey(keyType).getPubKey(true); } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); int getFederationSize(); byte[] getFederatorBtcPublicKey(int index); byte[] getFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix); Federation getActiveFederation(); @Nullable Federation getRetiringFederation(); List<UTXO> getActiveFederationBtcUTXOs(); List<UTXO> getRetiringFederationBtcUTXOs(); boolean amAwaitingFederationActivation(); }
|
FederationSupport { public byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix) { if (index < 0 || index >= members.size()) { throw new IndexOutOfBoundsException(String.format("%s index must be between 0 and %d", errorPrefix, members.size() - 1)); } return members.get(index).getPublicKey(keyType).getPubKey(true); } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); int getFederationSize(); byte[] getFederatorBtcPublicKey(int index); byte[] getFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix); Federation getActiveFederation(); @Nullable Federation getRetiringFederation(); List<UTXO> getActiveFederationBtcUTXOs(); List<UTXO> getRetiringFederationBtcUTXOs(); boolean amAwaitingFederationActivation(); }
|
@Test public void getMemberPublicKeyOfType_OutOfBounds() { List<FederationMember> members = Arrays.asList( new FederationMember(new BtcECKey(), new ECKey(), new ECKey()), new FederationMember(new BtcECKey(), new ECKey(), new ECKey()) ); try { federationSupport.getMemberPublicKeyOfType(members,2, FederationMember.KeyType.BTC, "a prefix"); Assert.fail(); } catch (IndexOutOfBoundsException e) { Assert.assertTrue(e.getMessage().startsWith("a prefix")); } try { federationSupport.getMemberPublicKeyOfType(members,-1, FederationMember.KeyType.MST, "another prefix"); Assert.fail(); } catch (IndexOutOfBoundsException e) { Assert.assertTrue(e.getMessage().startsWith("another prefix")); } }
|
public byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix) { if (index < 0 || index >= members.size()) { throw new IndexOutOfBoundsException(String.format("%s index must be between 0 and %d", errorPrefix, members.size() - 1)); } return members.get(index).getPublicKey(keyType).getPubKey(true); }
|
FederationSupport { public byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix) { if (index < 0 || index >= members.size()) { throw new IndexOutOfBoundsException(String.format("%s index must be between 0 and %d", errorPrefix, members.size() - 1)); } return members.get(index).getPublicKey(keyType).getPubKey(true); } }
|
FederationSupport { public byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix) { if (index < 0 || index >= members.size()) { throw new IndexOutOfBoundsException(String.format("%s index must be between 0 and %d", errorPrefix, members.size() - 1)); } return members.get(index).getPublicKey(keyType).getPubKey(true); } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); }
|
FederationSupport { public byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix) { if (index < 0 || index >= members.size()) { throw new IndexOutOfBoundsException(String.format("%s index must be between 0 and %d", errorPrefix, members.size() - 1)); } return members.get(index).getPublicKey(keyType).getPubKey(true); } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); int getFederationSize(); byte[] getFederatorBtcPublicKey(int index); byte[] getFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix); Federation getActiveFederation(); @Nullable Federation getRetiringFederation(); List<UTXO> getActiveFederationBtcUTXOs(); List<UTXO> getRetiringFederationBtcUTXOs(); boolean amAwaitingFederationActivation(); }
|
FederationSupport { public byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix) { if (index < 0 || index >= members.size()) { throw new IndexOutOfBoundsException(String.format("%s index must be between 0 and %d", errorPrefix, members.size() - 1)); } return members.get(index).getPublicKey(keyType).getPubKey(true); } FederationSupport(BridgeConstants bridgeConstants, BridgeStorageProvider provider, Block executionBlock); int getFederationSize(); byte[] getFederatorBtcPublicKey(int index); byte[] getFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); byte[] getMemberPublicKeyOfType(List<FederationMember> members, int index, FederationMember.KeyType keyType, String errorPrefix); Federation getActiveFederation(); @Nullable Federation getRetiringFederation(); List<UTXO> getActiveFederationBtcUTXOs(); List<UTXO> getRetiringFederationBtcUTXOs(); boolean amAwaitingFederationActivation(); }
|
@Test public void getLockingCap_before_RSKIP134_activation() { doReturn(false).when(activationConfig).isActive(eq(RSKIP134), anyLong()); BridgeSupport bridgeSupportMock = mock(BridgeSupport.class); Bridge bridge = getBridgeInstance(bridgeSupportMock); byte[] data = BridgeMethods.GET_LOCKING_CAP.getFunction().encode(new Object[]{}); Assert.assertNull(bridge.execute(data)); }
|
@Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); @Override long getGasForData(byte[] data); @Override void init(Transaction rskTx, Block rskExecutionBlock, Repository repository, BlockStore rskBlockStore, ReceiptStore rskReceiptStore, List<LogInfo> logs); @Override List<ProgramSubtrace> getSubtraces(); @Override byte[] execute(byte[] data); void updateCollections(Object[] args); boolean receiveHeadersIsPublic(); long receiveHeadersGetCost(Object[] args); void receiveHeaders(Object[] args); void registerBtcTransaction(Object[] args); void releaseBtc(Object[] args); void addSignature(Object[] args); byte[] getStateForBtcReleaseClient(Object[] args); byte[] getStateForDebugging(Object[] args); Integer getBtcBlockchainBestChainHeight(Object[] args); Integer getBtcBlockchainInitialBlockHeight(Object[] args); @Deprecated Object[] getBtcBlockchainBlockLocator(Object[] args); byte[] getBtcBlockchainBlockHashAtDepth(Object[] args); long getBtcTransactionConfirmationsGetCost(Object[] args); int getBtcTransactionConfirmations(Object[] args); Long getMinimumLockTxValue(Object[] args); Boolean isBtcTxHashAlreadyProcessed(Object[] args); Long getBtcTxHashProcessedHeight(Object[] args); String getFederationAddress(Object[] args); Integer getFederationSize(Object[] args); Integer getFederationThreshold(Object[] args); byte[] getFederatorPublicKey(Object[] args); byte[] getFederatorPublicKeyOfType(Object[] args); Long getFederationCreationTime(Object[] args); long getFederationCreationBlockNumber(Object[] args); String getRetiringFederationAddress(Object[] args); Integer getRetiringFederationSize(Object[] args); Integer getRetiringFederationThreshold(Object[] args); byte[] getRetiringFederatorPublicKey(Object[] args); byte[] getRetiringFederatorPublicKeyOfType(Object[] args); Long getRetiringFederationCreationTime(Object[] args); long getRetiringFederationCreationBlockNumber(Object[] args); Integer createFederation(Object[] args); Integer addFederatorPublicKey(Object[] args); Integer addFederatorPublicKeyMultikey(Object[] args); Integer commitFederation(Object[] args); Integer rollbackFederation(Object[] args); byte[] getPendingFederationHash(Object[] args); Integer getPendingFederationSize(Object[] args); byte[] getPendingFederatorPublicKey(Object[] args); byte[] getPendingFederatorPublicKeyOfType(Object[] args); Integer getLockWhitelistSize(Object[] args); String getLockWhitelistAddress(Object[] args); long getLockWhitelistEntryByAddress(Object[] args); Integer addOneOffLockWhitelistAddress(Object[] args); Integer addUnlimitedLockWhitelistAddress(Object[] args); Integer removeLockWhitelistAddress(Object[] args); Integer setLockWhitelistDisableBlockDelay(Object[] args); Integer voteFeePerKbChange(Object[] args); long getFeePerKb(Object[] args); long getLockingCap(Object[] args); boolean increaseLockingCap(Object[] args); void registerBtcCoinbaseTransaction(Object[] args); boolean hasBtcBlockCoinbaseTransactionInformation(Object[] args); static BridgeMethods.BridgeMethodExecutor activeAndRetiringFederationOnly(BridgeMethods.BridgeMethodExecutor decoratee, String funcName); static BridgeMethods.BridgeMethodExecutor executeIfElse(
BridgeMethods.BridgeCondition condition,
BridgeMethods.BridgeMethodExecutor ifTrue,
BridgeMethods.BridgeMethodExecutor ifFalse); }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); @Override long getGasForData(byte[] data); @Override void init(Transaction rskTx, Block rskExecutionBlock, Repository repository, BlockStore rskBlockStore, ReceiptStore rskReceiptStore, List<LogInfo> logs); @Override List<ProgramSubtrace> getSubtraces(); @Override byte[] execute(byte[] data); void updateCollections(Object[] args); boolean receiveHeadersIsPublic(); long receiveHeadersGetCost(Object[] args); void receiveHeaders(Object[] args); void registerBtcTransaction(Object[] args); void releaseBtc(Object[] args); void addSignature(Object[] args); byte[] getStateForBtcReleaseClient(Object[] args); byte[] getStateForDebugging(Object[] args); Integer getBtcBlockchainBestChainHeight(Object[] args); Integer getBtcBlockchainInitialBlockHeight(Object[] args); @Deprecated Object[] getBtcBlockchainBlockLocator(Object[] args); byte[] getBtcBlockchainBlockHashAtDepth(Object[] args); long getBtcTransactionConfirmationsGetCost(Object[] args); int getBtcTransactionConfirmations(Object[] args); Long getMinimumLockTxValue(Object[] args); Boolean isBtcTxHashAlreadyProcessed(Object[] args); Long getBtcTxHashProcessedHeight(Object[] args); String getFederationAddress(Object[] args); Integer getFederationSize(Object[] args); Integer getFederationThreshold(Object[] args); byte[] getFederatorPublicKey(Object[] args); byte[] getFederatorPublicKeyOfType(Object[] args); Long getFederationCreationTime(Object[] args); long getFederationCreationBlockNumber(Object[] args); String getRetiringFederationAddress(Object[] args); Integer getRetiringFederationSize(Object[] args); Integer getRetiringFederationThreshold(Object[] args); byte[] getRetiringFederatorPublicKey(Object[] args); byte[] getRetiringFederatorPublicKeyOfType(Object[] args); Long getRetiringFederationCreationTime(Object[] args); long getRetiringFederationCreationBlockNumber(Object[] args); Integer createFederation(Object[] args); Integer addFederatorPublicKey(Object[] args); Integer addFederatorPublicKeyMultikey(Object[] args); Integer commitFederation(Object[] args); Integer rollbackFederation(Object[] args); byte[] getPendingFederationHash(Object[] args); Integer getPendingFederationSize(Object[] args); byte[] getPendingFederatorPublicKey(Object[] args); byte[] getPendingFederatorPublicKeyOfType(Object[] args); Integer getLockWhitelistSize(Object[] args); String getLockWhitelistAddress(Object[] args); long getLockWhitelistEntryByAddress(Object[] args); Integer addOneOffLockWhitelistAddress(Object[] args); Integer addUnlimitedLockWhitelistAddress(Object[] args); Integer removeLockWhitelistAddress(Object[] args); Integer setLockWhitelistDisableBlockDelay(Object[] args); Integer voteFeePerKbChange(Object[] args); long getFeePerKb(Object[] args); long getLockingCap(Object[] args); boolean increaseLockingCap(Object[] args); void registerBtcCoinbaseTransaction(Object[] args); boolean hasBtcBlockCoinbaseTransactionInformation(Object[] args); static BridgeMethods.BridgeMethodExecutor activeAndRetiringFederationOnly(BridgeMethods.BridgeMethodExecutor decoratee, String funcName); static BridgeMethods.BridgeMethodExecutor executeIfElse(
BridgeMethods.BridgeCondition condition,
BridgeMethods.BridgeMethodExecutor ifTrue,
BridgeMethods.BridgeMethodExecutor ifFalse); static final CallTransaction.Function UPDATE_COLLECTIONS; static final CallTransaction.Function RECEIVE_HEADERS; static final CallTransaction.Function REGISTER_BTC_TRANSACTION; static final CallTransaction.Function RELEASE_BTC; static final CallTransaction.Function ADD_SIGNATURE; static final CallTransaction.Function GET_STATE_FOR_BTC_RELEASE_CLIENT; static final CallTransaction.Function GET_STATE_FOR_DEBUGGING; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BEST_CHAIN_HEIGHT; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BLOCK_LOCATOR; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_INITIAL_BLOCK_HEIGHT; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BLOCK_HASH_AT_DEPTH; static final CallTransaction.Function GET_BTC_TRANSACTION_CONFIRMATIONS; static final CallTransaction.Function GET_MINIMUM_LOCK_TX_VALUE; static final CallTransaction.Function IS_BTC_TX_HASH_ALREADY_PROCESSED; static final CallTransaction.Function GET_BTC_TX_HASH_PROCESSED_HEIGHT; static final CallTransaction.Function GET_FEDERATION_ADDRESS; static final CallTransaction.Function GET_FEDERATION_SIZE; static final CallTransaction.Function GET_FEDERATION_THRESHOLD; static final CallTransaction.Function GET_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_FEDERATION_CREATION_TIME; static final CallTransaction.Function GET_FEDERATION_CREATION_BLOCK_NUMBER; static final CallTransaction.Function GET_RETIRING_FEDERATION_ADDRESS; static final CallTransaction.Function GET_RETIRING_FEDERATION_SIZE; static final CallTransaction.Function GET_RETIRING_FEDERATION_THRESHOLD; static final CallTransaction.Function GET_RETIRING_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_RETIRING_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_RETIRING_FEDERATION_CREATION_TIME; static final CallTransaction.Function GET_RETIRING_FEDERATION_CREATION_BLOCK_NUMBER; static final CallTransaction.Function CREATE_FEDERATION; static final CallTransaction.Function ADD_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function ADD_FEDERATOR_PUBLIC_KEY_MULTIKEY; static final CallTransaction.Function COMMIT_FEDERATION; static final CallTransaction.Function ROLLBACK_FEDERATION; static final CallTransaction.Function GET_PENDING_FEDERATION_HASH; static final CallTransaction.Function GET_PENDING_FEDERATION_SIZE; static final CallTransaction.Function GET_PENDING_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_PENDING_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_LOCK_WHITELIST_SIZE; static final CallTransaction.Function GET_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function GET_LOCK_WHITELIST_ENTRY_BY_ADDRESS; static final CallTransaction.Function ADD_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function ADD_ONE_OFF_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function ADD_UNLIMITED_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function REMOVE_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function SET_LOCK_WHITELIST_DISABLE_BLOCK_DELAY; static final CallTransaction.Function GET_FEE_PER_KB; static final CallTransaction.Function VOTE_FEE_PER_KB; static final CallTransaction.Function INCREASE_LOCKING_CAP; static final CallTransaction.Function GET_LOCKING_CAP; static final CallTransaction.Function REGISTER_BTC_COINBASE_TRANSACTION; static final CallTransaction.Function HAS_BTC_BLOCK_COINBASE_TRANSACTION_INFORMATION; static final int LOCK_WHITELIST_UNLIMITED_MODE_CODE; static final int LOCK_WHITELIST_ENTRY_NOT_FOUND_CODE; static final int LOCK_WHITELIST_INVALID_ADDRESS_FORMAT_ERROR_CODE; static final DataWord RELEASE_BTC_TOPIC; static final DataWord UPDATE_COLLECTIONS_TOPIC; static final DataWord ADD_SIGNATURE_TOPIC; static final DataWord COMMIT_FEDERATION_TOPIC; }
|
@Test public void increaseLockingCap_before_RSKIP134_activation() { doReturn(false).when(activationConfig).isActive(eq(RSKIP134), anyLong()); BridgeSupport bridgeSupportMock = mock(BridgeSupport.class); Bridge bridge = getBridgeInstance(bridgeSupportMock); byte[] data = BridgeMethods.INCREASE_LOCKING_CAP.getFunction().encode(new Object[]{}); Assert.assertNull(bridge.execute(data)); }
|
@Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); @Override long getGasForData(byte[] data); @Override void init(Transaction rskTx, Block rskExecutionBlock, Repository repository, BlockStore rskBlockStore, ReceiptStore rskReceiptStore, List<LogInfo> logs); @Override List<ProgramSubtrace> getSubtraces(); @Override byte[] execute(byte[] data); void updateCollections(Object[] args); boolean receiveHeadersIsPublic(); long receiveHeadersGetCost(Object[] args); void receiveHeaders(Object[] args); void registerBtcTransaction(Object[] args); void releaseBtc(Object[] args); void addSignature(Object[] args); byte[] getStateForBtcReleaseClient(Object[] args); byte[] getStateForDebugging(Object[] args); Integer getBtcBlockchainBestChainHeight(Object[] args); Integer getBtcBlockchainInitialBlockHeight(Object[] args); @Deprecated Object[] getBtcBlockchainBlockLocator(Object[] args); byte[] getBtcBlockchainBlockHashAtDepth(Object[] args); long getBtcTransactionConfirmationsGetCost(Object[] args); int getBtcTransactionConfirmations(Object[] args); Long getMinimumLockTxValue(Object[] args); Boolean isBtcTxHashAlreadyProcessed(Object[] args); Long getBtcTxHashProcessedHeight(Object[] args); String getFederationAddress(Object[] args); Integer getFederationSize(Object[] args); Integer getFederationThreshold(Object[] args); byte[] getFederatorPublicKey(Object[] args); byte[] getFederatorPublicKeyOfType(Object[] args); Long getFederationCreationTime(Object[] args); long getFederationCreationBlockNumber(Object[] args); String getRetiringFederationAddress(Object[] args); Integer getRetiringFederationSize(Object[] args); Integer getRetiringFederationThreshold(Object[] args); byte[] getRetiringFederatorPublicKey(Object[] args); byte[] getRetiringFederatorPublicKeyOfType(Object[] args); Long getRetiringFederationCreationTime(Object[] args); long getRetiringFederationCreationBlockNumber(Object[] args); Integer createFederation(Object[] args); Integer addFederatorPublicKey(Object[] args); Integer addFederatorPublicKeyMultikey(Object[] args); Integer commitFederation(Object[] args); Integer rollbackFederation(Object[] args); byte[] getPendingFederationHash(Object[] args); Integer getPendingFederationSize(Object[] args); byte[] getPendingFederatorPublicKey(Object[] args); byte[] getPendingFederatorPublicKeyOfType(Object[] args); Integer getLockWhitelistSize(Object[] args); String getLockWhitelistAddress(Object[] args); long getLockWhitelistEntryByAddress(Object[] args); Integer addOneOffLockWhitelistAddress(Object[] args); Integer addUnlimitedLockWhitelistAddress(Object[] args); Integer removeLockWhitelistAddress(Object[] args); Integer setLockWhitelistDisableBlockDelay(Object[] args); Integer voteFeePerKbChange(Object[] args); long getFeePerKb(Object[] args); long getLockingCap(Object[] args); boolean increaseLockingCap(Object[] args); void registerBtcCoinbaseTransaction(Object[] args); boolean hasBtcBlockCoinbaseTransactionInformation(Object[] args); static BridgeMethods.BridgeMethodExecutor activeAndRetiringFederationOnly(BridgeMethods.BridgeMethodExecutor decoratee, String funcName); static BridgeMethods.BridgeMethodExecutor executeIfElse(
BridgeMethods.BridgeCondition condition,
BridgeMethods.BridgeMethodExecutor ifTrue,
BridgeMethods.BridgeMethodExecutor ifFalse); }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); @Override long getGasForData(byte[] data); @Override void init(Transaction rskTx, Block rskExecutionBlock, Repository repository, BlockStore rskBlockStore, ReceiptStore rskReceiptStore, List<LogInfo> logs); @Override List<ProgramSubtrace> getSubtraces(); @Override byte[] execute(byte[] data); void updateCollections(Object[] args); boolean receiveHeadersIsPublic(); long receiveHeadersGetCost(Object[] args); void receiveHeaders(Object[] args); void registerBtcTransaction(Object[] args); void releaseBtc(Object[] args); void addSignature(Object[] args); byte[] getStateForBtcReleaseClient(Object[] args); byte[] getStateForDebugging(Object[] args); Integer getBtcBlockchainBestChainHeight(Object[] args); Integer getBtcBlockchainInitialBlockHeight(Object[] args); @Deprecated Object[] getBtcBlockchainBlockLocator(Object[] args); byte[] getBtcBlockchainBlockHashAtDepth(Object[] args); long getBtcTransactionConfirmationsGetCost(Object[] args); int getBtcTransactionConfirmations(Object[] args); Long getMinimumLockTxValue(Object[] args); Boolean isBtcTxHashAlreadyProcessed(Object[] args); Long getBtcTxHashProcessedHeight(Object[] args); String getFederationAddress(Object[] args); Integer getFederationSize(Object[] args); Integer getFederationThreshold(Object[] args); byte[] getFederatorPublicKey(Object[] args); byte[] getFederatorPublicKeyOfType(Object[] args); Long getFederationCreationTime(Object[] args); long getFederationCreationBlockNumber(Object[] args); String getRetiringFederationAddress(Object[] args); Integer getRetiringFederationSize(Object[] args); Integer getRetiringFederationThreshold(Object[] args); byte[] getRetiringFederatorPublicKey(Object[] args); byte[] getRetiringFederatorPublicKeyOfType(Object[] args); Long getRetiringFederationCreationTime(Object[] args); long getRetiringFederationCreationBlockNumber(Object[] args); Integer createFederation(Object[] args); Integer addFederatorPublicKey(Object[] args); Integer addFederatorPublicKeyMultikey(Object[] args); Integer commitFederation(Object[] args); Integer rollbackFederation(Object[] args); byte[] getPendingFederationHash(Object[] args); Integer getPendingFederationSize(Object[] args); byte[] getPendingFederatorPublicKey(Object[] args); byte[] getPendingFederatorPublicKeyOfType(Object[] args); Integer getLockWhitelistSize(Object[] args); String getLockWhitelistAddress(Object[] args); long getLockWhitelistEntryByAddress(Object[] args); Integer addOneOffLockWhitelistAddress(Object[] args); Integer addUnlimitedLockWhitelistAddress(Object[] args); Integer removeLockWhitelistAddress(Object[] args); Integer setLockWhitelistDisableBlockDelay(Object[] args); Integer voteFeePerKbChange(Object[] args); long getFeePerKb(Object[] args); long getLockingCap(Object[] args); boolean increaseLockingCap(Object[] args); void registerBtcCoinbaseTransaction(Object[] args); boolean hasBtcBlockCoinbaseTransactionInformation(Object[] args); static BridgeMethods.BridgeMethodExecutor activeAndRetiringFederationOnly(BridgeMethods.BridgeMethodExecutor decoratee, String funcName); static BridgeMethods.BridgeMethodExecutor executeIfElse(
BridgeMethods.BridgeCondition condition,
BridgeMethods.BridgeMethodExecutor ifTrue,
BridgeMethods.BridgeMethodExecutor ifFalse); static final CallTransaction.Function UPDATE_COLLECTIONS; static final CallTransaction.Function RECEIVE_HEADERS; static final CallTransaction.Function REGISTER_BTC_TRANSACTION; static final CallTransaction.Function RELEASE_BTC; static final CallTransaction.Function ADD_SIGNATURE; static final CallTransaction.Function GET_STATE_FOR_BTC_RELEASE_CLIENT; static final CallTransaction.Function GET_STATE_FOR_DEBUGGING; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BEST_CHAIN_HEIGHT; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BLOCK_LOCATOR; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_INITIAL_BLOCK_HEIGHT; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BLOCK_HASH_AT_DEPTH; static final CallTransaction.Function GET_BTC_TRANSACTION_CONFIRMATIONS; static final CallTransaction.Function GET_MINIMUM_LOCK_TX_VALUE; static final CallTransaction.Function IS_BTC_TX_HASH_ALREADY_PROCESSED; static final CallTransaction.Function GET_BTC_TX_HASH_PROCESSED_HEIGHT; static final CallTransaction.Function GET_FEDERATION_ADDRESS; static final CallTransaction.Function GET_FEDERATION_SIZE; static final CallTransaction.Function GET_FEDERATION_THRESHOLD; static final CallTransaction.Function GET_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_FEDERATION_CREATION_TIME; static final CallTransaction.Function GET_FEDERATION_CREATION_BLOCK_NUMBER; static final CallTransaction.Function GET_RETIRING_FEDERATION_ADDRESS; static final CallTransaction.Function GET_RETIRING_FEDERATION_SIZE; static final CallTransaction.Function GET_RETIRING_FEDERATION_THRESHOLD; static final CallTransaction.Function GET_RETIRING_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_RETIRING_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_RETIRING_FEDERATION_CREATION_TIME; static final CallTransaction.Function GET_RETIRING_FEDERATION_CREATION_BLOCK_NUMBER; static final CallTransaction.Function CREATE_FEDERATION; static final CallTransaction.Function ADD_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function ADD_FEDERATOR_PUBLIC_KEY_MULTIKEY; static final CallTransaction.Function COMMIT_FEDERATION; static final CallTransaction.Function ROLLBACK_FEDERATION; static final CallTransaction.Function GET_PENDING_FEDERATION_HASH; static final CallTransaction.Function GET_PENDING_FEDERATION_SIZE; static final CallTransaction.Function GET_PENDING_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_PENDING_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_LOCK_WHITELIST_SIZE; static final CallTransaction.Function GET_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function GET_LOCK_WHITELIST_ENTRY_BY_ADDRESS; static final CallTransaction.Function ADD_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function ADD_ONE_OFF_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function ADD_UNLIMITED_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function REMOVE_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function SET_LOCK_WHITELIST_DISABLE_BLOCK_DELAY; static final CallTransaction.Function GET_FEE_PER_KB; static final CallTransaction.Function VOTE_FEE_PER_KB; static final CallTransaction.Function INCREASE_LOCKING_CAP; static final CallTransaction.Function GET_LOCKING_CAP; static final CallTransaction.Function REGISTER_BTC_COINBASE_TRANSACTION; static final CallTransaction.Function HAS_BTC_BLOCK_COINBASE_TRANSACTION_INFORMATION; static final int LOCK_WHITELIST_UNLIMITED_MODE_CODE; static final int LOCK_WHITELIST_ENTRY_NOT_FOUND_CODE; static final int LOCK_WHITELIST_INVALID_ADDRESS_FORMAT_ERROR_CODE; static final DataWord RELEASE_BTC_TOPIC; static final DataWord UPDATE_COLLECTIONS_TOPIC; static final DataWord ADD_SIGNATURE_TOPIC; static final DataWord COMMIT_FEDERATION_TOPIC; }
|
@Test public void increaseLockingCap_invalidParameter() { doReturn(true).when(activationConfig).isActive(eq(RSKIP134), anyLong()); BridgeSupport bridgeSupportMock = mock(BridgeSupport.class); Bridge bridge = getBridgeInstance(bridgeSupportMock); byte[] data = Bridge.INCREASE_LOCKING_CAP.encodeSignature(); byte[] result = bridge.execute(data); Assert.assertNull(result); data = ByteUtil.merge(Bridge.INCREASE_LOCKING_CAP.encodeSignature(), Hex.decode("ab")); result = bridge.execute(data); Assert.assertNull(result); data = Bridge.INCREASE_LOCKING_CAP.encode(new Object[]{ -1 }); result = bridge.execute(data); Assert.assertNull(result); data = ByteUtil.merge(Bridge.INCREASE_LOCKING_CAP.encodeSignature(), Hex.decode("0000000000000000000000000000000000000000000000080000000000000000")); result = bridge.execute(data); Assert.assertNull(result); }
|
@Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); @Override long getGasForData(byte[] data); @Override void init(Transaction rskTx, Block rskExecutionBlock, Repository repository, BlockStore rskBlockStore, ReceiptStore rskReceiptStore, List<LogInfo> logs); @Override List<ProgramSubtrace> getSubtraces(); @Override byte[] execute(byte[] data); void updateCollections(Object[] args); boolean receiveHeadersIsPublic(); long receiveHeadersGetCost(Object[] args); void receiveHeaders(Object[] args); void registerBtcTransaction(Object[] args); void releaseBtc(Object[] args); void addSignature(Object[] args); byte[] getStateForBtcReleaseClient(Object[] args); byte[] getStateForDebugging(Object[] args); Integer getBtcBlockchainBestChainHeight(Object[] args); Integer getBtcBlockchainInitialBlockHeight(Object[] args); @Deprecated Object[] getBtcBlockchainBlockLocator(Object[] args); byte[] getBtcBlockchainBlockHashAtDepth(Object[] args); long getBtcTransactionConfirmationsGetCost(Object[] args); int getBtcTransactionConfirmations(Object[] args); Long getMinimumLockTxValue(Object[] args); Boolean isBtcTxHashAlreadyProcessed(Object[] args); Long getBtcTxHashProcessedHeight(Object[] args); String getFederationAddress(Object[] args); Integer getFederationSize(Object[] args); Integer getFederationThreshold(Object[] args); byte[] getFederatorPublicKey(Object[] args); byte[] getFederatorPublicKeyOfType(Object[] args); Long getFederationCreationTime(Object[] args); long getFederationCreationBlockNumber(Object[] args); String getRetiringFederationAddress(Object[] args); Integer getRetiringFederationSize(Object[] args); Integer getRetiringFederationThreshold(Object[] args); byte[] getRetiringFederatorPublicKey(Object[] args); byte[] getRetiringFederatorPublicKeyOfType(Object[] args); Long getRetiringFederationCreationTime(Object[] args); long getRetiringFederationCreationBlockNumber(Object[] args); Integer createFederation(Object[] args); Integer addFederatorPublicKey(Object[] args); Integer addFederatorPublicKeyMultikey(Object[] args); Integer commitFederation(Object[] args); Integer rollbackFederation(Object[] args); byte[] getPendingFederationHash(Object[] args); Integer getPendingFederationSize(Object[] args); byte[] getPendingFederatorPublicKey(Object[] args); byte[] getPendingFederatorPublicKeyOfType(Object[] args); Integer getLockWhitelistSize(Object[] args); String getLockWhitelistAddress(Object[] args); long getLockWhitelistEntryByAddress(Object[] args); Integer addOneOffLockWhitelistAddress(Object[] args); Integer addUnlimitedLockWhitelistAddress(Object[] args); Integer removeLockWhitelistAddress(Object[] args); Integer setLockWhitelistDisableBlockDelay(Object[] args); Integer voteFeePerKbChange(Object[] args); long getFeePerKb(Object[] args); long getLockingCap(Object[] args); boolean increaseLockingCap(Object[] args); void registerBtcCoinbaseTransaction(Object[] args); boolean hasBtcBlockCoinbaseTransactionInformation(Object[] args); static BridgeMethods.BridgeMethodExecutor activeAndRetiringFederationOnly(BridgeMethods.BridgeMethodExecutor decoratee, String funcName); static BridgeMethods.BridgeMethodExecutor executeIfElse(
BridgeMethods.BridgeCondition condition,
BridgeMethods.BridgeMethodExecutor ifTrue,
BridgeMethods.BridgeMethodExecutor ifFalse); }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); @Override long getGasForData(byte[] data); @Override void init(Transaction rskTx, Block rskExecutionBlock, Repository repository, BlockStore rskBlockStore, ReceiptStore rskReceiptStore, List<LogInfo> logs); @Override List<ProgramSubtrace> getSubtraces(); @Override byte[] execute(byte[] data); void updateCollections(Object[] args); boolean receiveHeadersIsPublic(); long receiveHeadersGetCost(Object[] args); void receiveHeaders(Object[] args); void registerBtcTransaction(Object[] args); void releaseBtc(Object[] args); void addSignature(Object[] args); byte[] getStateForBtcReleaseClient(Object[] args); byte[] getStateForDebugging(Object[] args); Integer getBtcBlockchainBestChainHeight(Object[] args); Integer getBtcBlockchainInitialBlockHeight(Object[] args); @Deprecated Object[] getBtcBlockchainBlockLocator(Object[] args); byte[] getBtcBlockchainBlockHashAtDepth(Object[] args); long getBtcTransactionConfirmationsGetCost(Object[] args); int getBtcTransactionConfirmations(Object[] args); Long getMinimumLockTxValue(Object[] args); Boolean isBtcTxHashAlreadyProcessed(Object[] args); Long getBtcTxHashProcessedHeight(Object[] args); String getFederationAddress(Object[] args); Integer getFederationSize(Object[] args); Integer getFederationThreshold(Object[] args); byte[] getFederatorPublicKey(Object[] args); byte[] getFederatorPublicKeyOfType(Object[] args); Long getFederationCreationTime(Object[] args); long getFederationCreationBlockNumber(Object[] args); String getRetiringFederationAddress(Object[] args); Integer getRetiringFederationSize(Object[] args); Integer getRetiringFederationThreshold(Object[] args); byte[] getRetiringFederatorPublicKey(Object[] args); byte[] getRetiringFederatorPublicKeyOfType(Object[] args); Long getRetiringFederationCreationTime(Object[] args); long getRetiringFederationCreationBlockNumber(Object[] args); Integer createFederation(Object[] args); Integer addFederatorPublicKey(Object[] args); Integer addFederatorPublicKeyMultikey(Object[] args); Integer commitFederation(Object[] args); Integer rollbackFederation(Object[] args); byte[] getPendingFederationHash(Object[] args); Integer getPendingFederationSize(Object[] args); byte[] getPendingFederatorPublicKey(Object[] args); byte[] getPendingFederatorPublicKeyOfType(Object[] args); Integer getLockWhitelistSize(Object[] args); String getLockWhitelistAddress(Object[] args); long getLockWhitelistEntryByAddress(Object[] args); Integer addOneOffLockWhitelistAddress(Object[] args); Integer addUnlimitedLockWhitelistAddress(Object[] args); Integer removeLockWhitelistAddress(Object[] args); Integer setLockWhitelistDisableBlockDelay(Object[] args); Integer voteFeePerKbChange(Object[] args); long getFeePerKb(Object[] args); long getLockingCap(Object[] args); boolean increaseLockingCap(Object[] args); void registerBtcCoinbaseTransaction(Object[] args); boolean hasBtcBlockCoinbaseTransactionInformation(Object[] args); static BridgeMethods.BridgeMethodExecutor activeAndRetiringFederationOnly(BridgeMethods.BridgeMethodExecutor decoratee, String funcName); static BridgeMethods.BridgeMethodExecutor executeIfElse(
BridgeMethods.BridgeCondition condition,
BridgeMethods.BridgeMethodExecutor ifTrue,
BridgeMethods.BridgeMethodExecutor ifFalse); static final CallTransaction.Function UPDATE_COLLECTIONS; static final CallTransaction.Function RECEIVE_HEADERS; static final CallTransaction.Function REGISTER_BTC_TRANSACTION; static final CallTransaction.Function RELEASE_BTC; static final CallTransaction.Function ADD_SIGNATURE; static final CallTransaction.Function GET_STATE_FOR_BTC_RELEASE_CLIENT; static final CallTransaction.Function GET_STATE_FOR_DEBUGGING; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BEST_CHAIN_HEIGHT; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BLOCK_LOCATOR; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_INITIAL_BLOCK_HEIGHT; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BLOCK_HASH_AT_DEPTH; static final CallTransaction.Function GET_BTC_TRANSACTION_CONFIRMATIONS; static final CallTransaction.Function GET_MINIMUM_LOCK_TX_VALUE; static final CallTransaction.Function IS_BTC_TX_HASH_ALREADY_PROCESSED; static final CallTransaction.Function GET_BTC_TX_HASH_PROCESSED_HEIGHT; static final CallTransaction.Function GET_FEDERATION_ADDRESS; static final CallTransaction.Function GET_FEDERATION_SIZE; static final CallTransaction.Function GET_FEDERATION_THRESHOLD; static final CallTransaction.Function GET_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_FEDERATION_CREATION_TIME; static final CallTransaction.Function GET_FEDERATION_CREATION_BLOCK_NUMBER; static final CallTransaction.Function GET_RETIRING_FEDERATION_ADDRESS; static final CallTransaction.Function GET_RETIRING_FEDERATION_SIZE; static final CallTransaction.Function GET_RETIRING_FEDERATION_THRESHOLD; static final CallTransaction.Function GET_RETIRING_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_RETIRING_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_RETIRING_FEDERATION_CREATION_TIME; static final CallTransaction.Function GET_RETIRING_FEDERATION_CREATION_BLOCK_NUMBER; static final CallTransaction.Function CREATE_FEDERATION; static final CallTransaction.Function ADD_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function ADD_FEDERATOR_PUBLIC_KEY_MULTIKEY; static final CallTransaction.Function COMMIT_FEDERATION; static final CallTransaction.Function ROLLBACK_FEDERATION; static final CallTransaction.Function GET_PENDING_FEDERATION_HASH; static final CallTransaction.Function GET_PENDING_FEDERATION_SIZE; static final CallTransaction.Function GET_PENDING_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_PENDING_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_LOCK_WHITELIST_SIZE; static final CallTransaction.Function GET_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function GET_LOCK_WHITELIST_ENTRY_BY_ADDRESS; static final CallTransaction.Function ADD_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function ADD_ONE_OFF_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function ADD_UNLIMITED_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function REMOVE_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function SET_LOCK_WHITELIST_DISABLE_BLOCK_DELAY; static final CallTransaction.Function GET_FEE_PER_KB; static final CallTransaction.Function VOTE_FEE_PER_KB; static final CallTransaction.Function INCREASE_LOCKING_CAP; static final CallTransaction.Function GET_LOCKING_CAP; static final CallTransaction.Function REGISTER_BTC_COINBASE_TRANSACTION; static final CallTransaction.Function HAS_BTC_BLOCK_COINBASE_TRANSACTION_INFORMATION; static final int LOCK_WHITELIST_UNLIMITED_MODE_CODE; static final int LOCK_WHITELIST_ENTRY_NOT_FOUND_CODE; static final int LOCK_WHITELIST_INVALID_ADDRESS_FORMAT_ERROR_CODE; static final DataWord RELEASE_BTC_TOPIC; static final DataWord UPDATE_COLLECTIONS_TOPIC; static final DataWord ADD_SIGNATURE_TOPIC; static final DataWord COMMIT_FEDERATION_TOPIC; }
|
@Test public void test15() { String helloMsg = "f8 91 80 0b 80 b8 46 45 74 68 65 72 65 75 6d 28 2b 2b 29 2f 5a 65 72 6f 47 6f 78 2e 70 72 " + "69 63 6b 6c 79 5f 6d 6f 72 73 65 2f 76 30 2e 34 2e 32 2f 52 65 6c 65 61 73 65 2d 57 69 6e 33 32 2f " + "57 69 6e 64 6f 77 73 2f 56 53 32 30 31 33 07 82 76 5f b8 40 ea 99 2c 13 68 7c 20 e7 90 a9 ff a6 df " + "8b 1a 16 86 88 e2 a8 87 36 5d 7a 50 21 86 fa 0d 62 20 e8 3e 11 3a 1f e7 7d c0 68 9d 55 ba 2e 8a 83 " + "aa 8e 20 42 18 f4 d8 e7 32 82 5b d7 80 cf 94 ed 5c c3"; byte[] payload = Hex.decode(helloMsg); ArrayList<RLPElement> rlpList = decode2(payload); }
|
@Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { @Nonnull public static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData) { ArrayList<RLPElement> elements = new ArrayList<>(); if (msgData == null) { return elements; } int tlength = msgData.length; int position = 0; while (position < tlength) { Pair<RLPElement, Integer> next = decodeElement(msgData, position); elements.add(next.getKey()); position = next.getValue(); } return elements; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void registerBtcCoinbaseTransaction_before_RSKIP143_activation() { ActivationConfig activations = spy(ActivationConfigsForTest.genesis()); doReturn(false).when(activations).isActive(eq(RSKIP143), anyLong()); BridgeSupport bridgeSupportMock = mock(BridgeSupport.class); Bridge bridge = getBridgeInstance(bridgeSupportMock, activations); byte[] value = Sha256Hash.ZERO_HASH.getBytes(); Integer zero = new Integer(0); byte[] data = Bridge.REGISTER_BTC_COINBASE_TRANSACTION.encode(new Object[]{ value, zero, value, zero, zero }); Assert.assertNull(bridge.execute(data)); }
|
@Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); @Override long getGasForData(byte[] data); @Override void init(Transaction rskTx, Block rskExecutionBlock, Repository repository, BlockStore rskBlockStore, ReceiptStore rskReceiptStore, List<LogInfo> logs); @Override List<ProgramSubtrace> getSubtraces(); @Override byte[] execute(byte[] data); void updateCollections(Object[] args); boolean receiveHeadersIsPublic(); long receiveHeadersGetCost(Object[] args); void receiveHeaders(Object[] args); void registerBtcTransaction(Object[] args); void releaseBtc(Object[] args); void addSignature(Object[] args); byte[] getStateForBtcReleaseClient(Object[] args); byte[] getStateForDebugging(Object[] args); Integer getBtcBlockchainBestChainHeight(Object[] args); Integer getBtcBlockchainInitialBlockHeight(Object[] args); @Deprecated Object[] getBtcBlockchainBlockLocator(Object[] args); byte[] getBtcBlockchainBlockHashAtDepth(Object[] args); long getBtcTransactionConfirmationsGetCost(Object[] args); int getBtcTransactionConfirmations(Object[] args); Long getMinimumLockTxValue(Object[] args); Boolean isBtcTxHashAlreadyProcessed(Object[] args); Long getBtcTxHashProcessedHeight(Object[] args); String getFederationAddress(Object[] args); Integer getFederationSize(Object[] args); Integer getFederationThreshold(Object[] args); byte[] getFederatorPublicKey(Object[] args); byte[] getFederatorPublicKeyOfType(Object[] args); Long getFederationCreationTime(Object[] args); long getFederationCreationBlockNumber(Object[] args); String getRetiringFederationAddress(Object[] args); Integer getRetiringFederationSize(Object[] args); Integer getRetiringFederationThreshold(Object[] args); byte[] getRetiringFederatorPublicKey(Object[] args); byte[] getRetiringFederatorPublicKeyOfType(Object[] args); Long getRetiringFederationCreationTime(Object[] args); long getRetiringFederationCreationBlockNumber(Object[] args); Integer createFederation(Object[] args); Integer addFederatorPublicKey(Object[] args); Integer addFederatorPublicKeyMultikey(Object[] args); Integer commitFederation(Object[] args); Integer rollbackFederation(Object[] args); byte[] getPendingFederationHash(Object[] args); Integer getPendingFederationSize(Object[] args); byte[] getPendingFederatorPublicKey(Object[] args); byte[] getPendingFederatorPublicKeyOfType(Object[] args); Integer getLockWhitelistSize(Object[] args); String getLockWhitelistAddress(Object[] args); long getLockWhitelistEntryByAddress(Object[] args); Integer addOneOffLockWhitelistAddress(Object[] args); Integer addUnlimitedLockWhitelistAddress(Object[] args); Integer removeLockWhitelistAddress(Object[] args); Integer setLockWhitelistDisableBlockDelay(Object[] args); Integer voteFeePerKbChange(Object[] args); long getFeePerKb(Object[] args); long getLockingCap(Object[] args); boolean increaseLockingCap(Object[] args); void registerBtcCoinbaseTransaction(Object[] args); boolean hasBtcBlockCoinbaseTransactionInformation(Object[] args); static BridgeMethods.BridgeMethodExecutor activeAndRetiringFederationOnly(BridgeMethods.BridgeMethodExecutor decoratee, String funcName); static BridgeMethods.BridgeMethodExecutor executeIfElse(
BridgeMethods.BridgeCondition condition,
BridgeMethods.BridgeMethodExecutor ifTrue,
BridgeMethods.BridgeMethodExecutor ifFalse); }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); @Override long getGasForData(byte[] data); @Override void init(Transaction rskTx, Block rskExecutionBlock, Repository repository, BlockStore rskBlockStore, ReceiptStore rskReceiptStore, List<LogInfo> logs); @Override List<ProgramSubtrace> getSubtraces(); @Override byte[] execute(byte[] data); void updateCollections(Object[] args); boolean receiveHeadersIsPublic(); long receiveHeadersGetCost(Object[] args); void receiveHeaders(Object[] args); void registerBtcTransaction(Object[] args); void releaseBtc(Object[] args); void addSignature(Object[] args); byte[] getStateForBtcReleaseClient(Object[] args); byte[] getStateForDebugging(Object[] args); Integer getBtcBlockchainBestChainHeight(Object[] args); Integer getBtcBlockchainInitialBlockHeight(Object[] args); @Deprecated Object[] getBtcBlockchainBlockLocator(Object[] args); byte[] getBtcBlockchainBlockHashAtDepth(Object[] args); long getBtcTransactionConfirmationsGetCost(Object[] args); int getBtcTransactionConfirmations(Object[] args); Long getMinimumLockTxValue(Object[] args); Boolean isBtcTxHashAlreadyProcessed(Object[] args); Long getBtcTxHashProcessedHeight(Object[] args); String getFederationAddress(Object[] args); Integer getFederationSize(Object[] args); Integer getFederationThreshold(Object[] args); byte[] getFederatorPublicKey(Object[] args); byte[] getFederatorPublicKeyOfType(Object[] args); Long getFederationCreationTime(Object[] args); long getFederationCreationBlockNumber(Object[] args); String getRetiringFederationAddress(Object[] args); Integer getRetiringFederationSize(Object[] args); Integer getRetiringFederationThreshold(Object[] args); byte[] getRetiringFederatorPublicKey(Object[] args); byte[] getRetiringFederatorPublicKeyOfType(Object[] args); Long getRetiringFederationCreationTime(Object[] args); long getRetiringFederationCreationBlockNumber(Object[] args); Integer createFederation(Object[] args); Integer addFederatorPublicKey(Object[] args); Integer addFederatorPublicKeyMultikey(Object[] args); Integer commitFederation(Object[] args); Integer rollbackFederation(Object[] args); byte[] getPendingFederationHash(Object[] args); Integer getPendingFederationSize(Object[] args); byte[] getPendingFederatorPublicKey(Object[] args); byte[] getPendingFederatorPublicKeyOfType(Object[] args); Integer getLockWhitelistSize(Object[] args); String getLockWhitelistAddress(Object[] args); long getLockWhitelistEntryByAddress(Object[] args); Integer addOneOffLockWhitelistAddress(Object[] args); Integer addUnlimitedLockWhitelistAddress(Object[] args); Integer removeLockWhitelistAddress(Object[] args); Integer setLockWhitelistDisableBlockDelay(Object[] args); Integer voteFeePerKbChange(Object[] args); long getFeePerKb(Object[] args); long getLockingCap(Object[] args); boolean increaseLockingCap(Object[] args); void registerBtcCoinbaseTransaction(Object[] args); boolean hasBtcBlockCoinbaseTransactionInformation(Object[] args); static BridgeMethods.BridgeMethodExecutor activeAndRetiringFederationOnly(BridgeMethods.BridgeMethodExecutor decoratee, String funcName); static BridgeMethods.BridgeMethodExecutor executeIfElse(
BridgeMethods.BridgeCondition condition,
BridgeMethods.BridgeMethodExecutor ifTrue,
BridgeMethods.BridgeMethodExecutor ifFalse); static final CallTransaction.Function UPDATE_COLLECTIONS; static final CallTransaction.Function RECEIVE_HEADERS; static final CallTransaction.Function REGISTER_BTC_TRANSACTION; static final CallTransaction.Function RELEASE_BTC; static final CallTransaction.Function ADD_SIGNATURE; static final CallTransaction.Function GET_STATE_FOR_BTC_RELEASE_CLIENT; static final CallTransaction.Function GET_STATE_FOR_DEBUGGING; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BEST_CHAIN_HEIGHT; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BLOCK_LOCATOR; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_INITIAL_BLOCK_HEIGHT; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BLOCK_HASH_AT_DEPTH; static final CallTransaction.Function GET_BTC_TRANSACTION_CONFIRMATIONS; static final CallTransaction.Function GET_MINIMUM_LOCK_TX_VALUE; static final CallTransaction.Function IS_BTC_TX_HASH_ALREADY_PROCESSED; static final CallTransaction.Function GET_BTC_TX_HASH_PROCESSED_HEIGHT; static final CallTransaction.Function GET_FEDERATION_ADDRESS; static final CallTransaction.Function GET_FEDERATION_SIZE; static final CallTransaction.Function GET_FEDERATION_THRESHOLD; static final CallTransaction.Function GET_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_FEDERATION_CREATION_TIME; static final CallTransaction.Function GET_FEDERATION_CREATION_BLOCK_NUMBER; static final CallTransaction.Function GET_RETIRING_FEDERATION_ADDRESS; static final CallTransaction.Function GET_RETIRING_FEDERATION_SIZE; static final CallTransaction.Function GET_RETIRING_FEDERATION_THRESHOLD; static final CallTransaction.Function GET_RETIRING_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_RETIRING_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_RETIRING_FEDERATION_CREATION_TIME; static final CallTransaction.Function GET_RETIRING_FEDERATION_CREATION_BLOCK_NUMBER; static final CallTransaction.Function CREATE_FEDERATION; static final CallTransaction.Function ADD_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function ADD_FEDERATOR_PUBLIC_KEY_MULTIKEY; static final CallTransaction.Function COMMIT_FEDERATION; static final CallTransaction.Function ROLLBACK_FEDERATION; static final CallTransaction.Function GET_PENDING_FEDERATION_HASH; static final CallTransaction.Function GET_PENDING_FEDERATION_SIZE; static final CallTransaction.Function GET_PENDING_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_PENDING_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_LOCK_WHITELIST_SIZE; static final CallTransaction.Function GET_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function GET_LOCK_WHITELIST_ENTRY_BY_ADDRESS; static final CallTransaction.Function ADD_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function ADD_ONE_OFF_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function ADD_UNLIMITED_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function REMOVE_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function SET_LOCK_WHITELIST_DISABLE_BLOCK_DELAY; static final CallTransaction.Function GET_FEE_PER_KB; static final CallTransaction.Function VOTE_FEE_PER_KB; static final CallTransaction.Function INCREASE_LOCKING_CAP; static final CallTransaction.Function GET_LOCKING_CAP; static final CallTransaction.Function REGISTER_BTC_COINBASE_TRANSACTION; static final CallTransaction.Function HAS_BTC_BLOCK_COINBASE_TRANSACTION_INFORMATION; static final int LOCK_WHITELIST_UNLIMITED_MODE_CODE; static final int LOCK_WHITELIST_ENTRY_NOT_FOUND_CODE; static final int LOCK_WHITELIST_INVALID_ADDRESS_FORMAT_ERROR_CODE; static final DataWord RELEASE_BTC_TOPIC; static final DataWord UPDATE_COLLECTIONS_TOPIC; static final DataWord ADD_SIGNATURE_TOPIC; static final DataWord COMMIT_FEDERATION_TOPIC; }
|
@Test public void registerBtcCoinbaseTransaction_after_RSKIP143_activation_null_data() { ActivationConfig activations = spy(ActivationConfigsForTest.genesis()); doReturn(true).when(activations).isActive(eq(RSKIP143), anyLong()); BridgeSupport bridgeSupportMock = mock(BridgeSupport.class); Bridge bridge = getBridgeInstance(bridgeSupportMock, activations); byte[] data = Bridge.REGISTER_BTC_COINBASE_TRANSACTION.encodeSignature(); byte[] result = bridge.execute(data); Assert.assertNull(result); data = ByteUtil.merge(Bridge.REGISTER_BTC_COINBASE_TRANSACTION.encodeSignature(), Hex.decode("ab")); result = bridge.execute(data); Assert.assertNull(result); data = ByteUtil.merge(Bridge.REGISTER_BTC_COINBASE_TRANSACTION.encodeSignature(), Hex.decode("0000000000000000000000000000000000000000000000080000000000000000")); result = bridge.execute(data); Assert.assertNull(result); }
|
@Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); @Override long getGasForData(byte[] data); @Override void init(Transaction rskTx, Block rskExecutionBlock, Repository repository, BlockStore rskBlockStore, ReceiptStore rskReceiptStore, List<LogInfo> logs); @Override List<ProgramSubtrace> getSubtraces(); @Override byte[] execute(byte[] data); void updateCollections(Object[] args); boolean receiveHeadersIsPublic(); long receiveHeadersGetCost(Object[] args); void receiveHeaders(Object[] args); void registerBtcTransaction(Object[] args); void releaseBtc(Object[] args); void addSignature(Object[] args); byte[] getStateForBtcReleaseClient(Object[] args); byte[] getStateForDebugging(Object[] args); Integer getBtcBlockchainBestChainHeight(Object[] args); Integer getBtcBlockchainInitialBlockHeight(Object[] args); @Deprecated Object[] getBtcBlockchainBlockLocator(Object[] args); byte[] getBtcBlockchainBlockHashAtDepth(Object[] args); long getBtcTransactionConfirmationsGetCost(Object[] args); int getBtcTransactionConfirmations(Object[] args); Long getMinimumLockTxValue(Object[] args); Boolean isBtcTxHashAlreadyProcessed(Object[] args); Long getBtcTxHashProcessedHeight(Object[] args); String getFederationAddress(Object[] args); Integer getFederationSize(Object[] args); Integer getFederationThreshold(Object[] args); byte[] getFederatorPublicKey(Object[] args); byte[] getFederatorPublicKeyOfType(Object[] args); Long getFederationCreationTime(Object[] args); long getFederationCreationBlockNumber(Object[] args); String getRetiringFederationAddress(Object[] args); Integer getRetiringFederationSize(Object[] args); Integer getRetiringFederationThreshold(Object[] args); byte[] getRetiringFederatorPublicKey(Object[] args); byte[] getRetiringFederatorPublicKeyOfType(Object[] args); Long getRetiringFederationCreationTime(Object[] args); long getRetiringFederationCreationBlockNumber(Object[] args); Integer createFederation(Object[] args); Integer addFederatorPublicKey(Object[] args); Integer addFederatorPublicKeyMultikey(Object[] args); Integer commitFederation(Object[] args); Integer rollbackFederation(Object[] args); byte[] getPendingFederationHash(Object[] args); Integer getPendingFederationSize(Object[] args); byte[] getPendingFederatorPublicKey(Object[] args); byte[] getPendingFederatorPublicKeyOfType(Object[] args); Integer getLockWhitelistSize(Object[] args); String getLockWhitelistAddress(Object[] args); long getLockWhitelistEntryByAddress(Object[] args); Integer addOneOffLockWhitelistAddress(Object[] args); Integer addUnlimitedLockWhitelistAddress(Object[] args); Integer removeLockWhitelistAddress(Object[] args); Integer setLockWhitelistDisableBlockDelay(Object[] args); Integer voteFeePerKbChange(Object[] args); long getFeePerKb(Object[] args); long getLockingCap(Object[] args); boolean increaseLockingCap(Object[] args); void registerBtcCoinbaseTransaction(Object[] args); boolean hasBtcBlockCoinbaseTransactionInformation(Object[] args); static BridgeMethods.BridgeMethodExecutor activeAndRetiringFederationOnly(BridgeMethods.BridgeMethodExecutor decoratee, String funcName); static BridgeMethods.BridgeMethodExecutor executeIfElse(
BridgeMethods.BridgeCondition condition,
BridgeMethods.BridgeMethodExecutor ifTrue,
BridgeMethods.BridgeMethodExecutor ifFalse); }
|
Bridge extends PrecompiledContracts.PrecompiledContract { @Override public byte[] execute(byte[] data) { try { if (rskTx == null) { throw new RuntimeException("Rsk Transaction is null"); } BridgeParsedData bridgeParsedData = parseData(data); if (bridgeParsedData == null) { String errorMessage = String.format("Invalid data given: %s.", ByteUtil.toHexString(data)); logger.info(errorMessage); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } if (activations.isActive(ConsensusRule.RSKIP88) && !isLocalCall() && bridgeParsedData.bridgeMethod.onlyAllowsLocalCalls()) { String errorMessage = String.format("Non-local-call to %s. Returning without execution.", bridgeParsedData.bridgeMethod.getFunction().name); logger.info(errorMessage); throw new BridgeIllegalArgumentException(errorMessage); } Optional<?> result; try { result = bridgeParsedData.bridgeMethod.getExecutor().execute(this, bridgeParsedData.args); } catch (BridgeIllegalArgumentException ex) { String errorMessage = String.format("Error executing: %s", bridgeParsedData.bridgeMethod); logger.warn(errorMessage, ex); if (activations.isActive(ConsensusRule.RSKIP88)) { throw new BridgeIllegalArgumentException(errorMessage); } return null; } teardown(); return result.map(bridgeParsedData.bridgeMethod.getFunction()::encodeOutputs).orElse(null); } catch(Exception ex) { logger.error(ex.getMessage(), ex); panicProcessor.panic("bridgeexecute", ex.getMessage()); throw new RuntimeException(String.format("Exception executing bridge: %s", ex.getMessage()), ex); } } Bridge(RskAddress contractAddress, Constants constants, ActivationConfig activationConfig,
BridgeSupportFactory bridgeSupportFactory); @Override long getGasForData(byte[] data); @Override void init(Transaction rskTx, Block rskExecutionBlock, Repository repository, BlockStore rskBlockStore, ReceiptStore rskReceiptStore, List<LogInfo> logs); @Override List<ProgramSubtrace> getSubtraces(); @Override byte[] execute(byte[] data); void updateCollections(Object[] args); boolean receiveHeadersIsPublic(); long receiveHeadersGetCost(Object[] args); void receiveHeaders(Object[] args); void registerBtcTransaction(Object[] args); void releaseBtc(Object[] args); void addSignature(Object[] args); byte[] getStateForBtcReleaseClient(Object[] args); byte[] getStateForDebugging(Object[] args); Integer getBtcBlockchainBestChainHeight(Object[] args); Integer getBtcBlockchainInitialBlockHeight(Object[] args); @Deprecated Object[] getBtcBlockchainBlockLocator(Object[] args); byte[] getBtcBlockchainBlockHashAtDepth(Object[] args); long getBtcTransactionConfirmationsGetCost(Object[] args); int getBtcTransactionConfirmations(Object[] args); Long getMinimumLockTxValue(Object[] args); Boolean isBtcTxHashAlreadyProcessed(Object[] args); Long getBtcTxHashProcessedHeight(Object[] args); String getFederationAddress(Object[] args); Integer getFederationSize(Object[] args); Integer getFederationThreshold(Object[] args); byte[] getFederatorPublicKey(Object[] args); byte[] getFederatorPublicKeyOfType(Object[] args); Long getFederationCreationTime(Object[] args); long getFederationCreationBlockNumber(Object[] args); String getRetiringFederationAddress(Object[] args); Integer getRetiringFederationSize(Object[] args); Integer getRetiringFederationThreshold(Object[] args); byte[] getRetiringFederatorPublicKey(Object[] args); byte[] getRetiringFederatorPublicKeyOfType(Object[] args); Long getRetiringFederationCreationTime(Object[] args); long getRetiringFederationCreationBlockNumber(Object[] args); Integer createFederation(Object[] args); Integer addFederatorPublicKey(Object[] args); Integer addFederatorPublicKeyMultikey(Object[] args); Integer commitFederation(Object[] args); Integer rollbackFederation(Object[] args); byte[] getPendingFederationHash(Object[] args); Integer getPendingFederationSize(Object[] args); byte[] getPendingFederatorPublicKey(Object[] args); byte[] getPendingFederatorPublicKeyOfType(Object[] args); Integer getLockWhitelistSize(Object[] args); String getLockWhitelistAddress(Object[] args); long getLockWhitelistEntryByAddress(Object[] args); Integer addOneOffLockWhitelistAddress(Object[] args); Integer addUnlimitedLockWhitelistAddress(Object[] args); Integer removeLockWhitelistAddress(Object[] args); Integer setLockWhitelistDisableBlockDelay(Object[] args); Integer voteFeePerKbChange(Object[] args); long getFeePerKb(Object[] args); long getLockingCap(Object[] args); boolean increaseLockingCap(Object[] args); void registerBtcCoinbaseTransaction(Object[] args); boolean hasBtcBlockCoinbaseTransactionInformation(Object[] args); static BridgeMethods.BridgeMethodExecutor activeAndRetiringFederationOnly(BridgeMethods.BridgeMethodExecutor decoratee, String funcName); static BridgeMethods.BridgeMethodExecutor executeIfElse(
BridgeMethods.BridgeCondition condition,
BridgeMethods.BridgeMethodExecutor ifTrue,
BridgeMethods.BridgeMethodExecutor ifFalse); static final CallTransaction.Function UPDATE_COLLECTIONS; static final CallTransaction.Function RECEIVE_HEADERS; static final CallTransaction.Function REGISTER_BTC_TRANSACTION; static final CallTransaction.Function RELEASE_BTC; static final CallTransaction.Function ADD_SIGNATURE; static final CallTransaction.Function GET_STATE_FOR_BTC_RELEASE_CLIENT; static final CallTransaction.Function GET_STATE_FOR_DEBUGGING; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BEST_CHAIN_HEIGHT; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BLOCK_LOCATOR; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_INITIAL_BLOCK_HEIGHT; static final CallTransaction.Function GET_BTC_BLOCKCHAIN_BLOCK_HASH_AT_DEPTH; static final CallTransaction.Function GET_BTC_TRANSACTION_CONFIRMATIONS; static final CallTransaction.Function GET_MINIMUM_LOCK_TX_VALUE; static final CallTransaction.Function IS_BTC_TX_HASH_ALREADY_PROCESSED; static final CallTransaction.Function GET_BTC_TX_HASH_PROCESSED_HEIGHT; static final CallTransaction.Function GET_FEDERATION_ADDRESS; static final CallTransaction.Function GET_FEDERATION_SIZE; static final CallTransaction.Function GET_FEDERATION_THRESHOLD; static final CallTransaction.Function GET_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_FEDERATION_CREATION_TIME; static final CallTransaction.Function GET_FEDERATION_CREATION_BLOCK_NUMBER; static final CallTransaction.Function GET_RETIRING_FEDERATION_ADDRESS; static final CallTransaction.Function GET_RETIRING_FEDERATION_SIZE; static final CallTransaction.Function GET_RETIRING_FEDERATION_THRESHOLD; static final CallTransaction.Function GET_RETIRING_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_RETIRING_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_RETIRING_FEDERATION_CREATION_TIME; static final CallTransaction.Function GET_RETIRING_FEDERATION_CREATION_BLOCK_NUMBER; static final CallTransaction.Function CREATE_FEDERATION; static final CallTransaction.Function ADD_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function ADD_FEDERATOR_PUBLIC_KEY_MULTIKEY; static final CallTransaction.Function COMMIT_FEDERATION; static final CallTransaction.Function ROLLBACK_FEDERATION; static final CallTransaction.Function GET_PENDING_FEDERATION_HASH; static final CallTransaction.Function GET_PENDING_FEDERATION_SIZE; static final CallTransaction.Function GET_PENDING_FEDERATOR_PUBLIC_KEY; static final CallTransaction.Function GET_PENDING_FEDERATOR_PUBLIC_KEY_OF_TYPE; static final CallTransaction.Function GET_LOCK_WHITELIST_SIZE; static final CallTransaction.Function GET_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function GET_LOCK_WHITELIST_ENTRY_BY_ADDRESS; static final CallTransaction.Function ADD_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function ADD_ONE_OFF_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function ADD_UNLIMITED_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function REMOVE_LOCK_WHITELIST_ADDRESS; static final CallTransaction.Function SET_LOCK_WHITELIST_DISABLE_BLOCK_DELAY; static final CallTransaction.Function GET_FEE_PER_KB; static final CallTransaction.Function VOTE_FEE_PER_KB; static final CallTransaction.Function INCREASE_LOCKING_CAP; static final CallTransaction.Function GET_LOCKING_CAP; static final CallTransaction.Function REGISTER_BTC_COINBASE_TRANSACTION; static final CallTransaction.Function HAS_BTC_BLOCK_COINBASE_TRANSACTION_INFORMATION; static final int LOCK_WHITELIST_UNLIMITED_MODE_CODE; static final int LOCK_WHITELIST_ENTRY_NOT_FOUND_CODE; static final int LOCK_WHITELIST_INVALID_ADDRESS_FORMAT_ERROR_CODE; static final DataWord RELEASE_BTC_TOPIC; static final DataWord UPDATE_COLLECTIONS_TOPIC; static final DataWord ADD_SIGNATURE_TOPIC; static final DataWord COMMIT_FEDERATION_TOPIC; }
|
@Test public void testEquals_basic() { Assert.assertTrue(member.equals(member)); Assert.assertFalse(member.equals(null)); Assert.assertFalse(member.equals(new Object())); Assert.assertFalse(member.equals("something else")); }
|
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); static FederationMember getFederationMemberFromKey(BtcECKey pk); static List<FederationMember> getFederationMembersFromKeys(List<BtcECKey> pks); BtcECKey getBtcPublicKey(); ECKey getRskPublicKey(); ECKey getMstPublicKey(); ECKey getPublicKey(KeyType keyType); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); static FederationMember getFederationMemberFromKey(BtcECKey pk); static List<FederationMember> getFederationMembersFromKeys(List<BtcECKey> pks); BtcECKey getBtcPublicKey(); ECKey getRskPublicKey(); ECKey getMstPublicKey(); ECKey getPublicKey(KeyType keyType); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); static final Comparator<FederationMember> BTC_RSK_MST_PUBKEYS_COMPARATOR; }
|
@Test public void testEquals_sameKeys() { FederationMember otherMember = new FederationMember(btcKey, rskKey, mstKey); Assert.assertTrue(member.equals(otherMember)); }
|
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); static FederationMember getFederationMemberFromKey(BtcECKey pk); static List<FederationMember> getFederationMembersFromKeys(List<BtcECKey> pks); BtcECKey getBtcPublicKey(); ECKey getRskPublicKey(); ECKey getMstPublicKey(); ECKey getPublicKey(KeyType keyType); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); static FederationMember getFederationMemberFromKey(BtcECKey pk); static List<FederationMember> getFederationMembersFromKeys(List<BtcECKey> pks); BtcECKey getBtcPublicKey(); ECKey getRskPublicKey(); ECKey getMstPublicKey(); ECKey getPublicKey(KeyType keyType); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); static final Comparator<FederationMember> BTC_RSK_MST_PUBKEYS_COMPARATOR; }
|
@Test public void testEquals_sameKeysDifferentCompression() { FederationMember uncompressedMember = new FederationMember( BtcECKey.fromPublicOnly(btcKey.getPubKeyPoint().getEncoded(false)), ECKey.fromPublicOnly(rskKey.getPubKey(false)), ECKey.fromPublicOnly(mstKey.getPubKey(false)) ); FederationMember compressedMember = new FederationMember( BtcECKey.fromPublicOnly(btcKey.getPubKeyPoint().getEncoded(true)), ECKey.fromPublicOnly(rskKey.getPubKey(true)), ECKey.fromPublicOnly(mstKey.getPubKey(true)) ); Assert.assertTrue(compressedMember.equals(uncompressedMember)); Assert.assertTrue(uncompressedMember.equals(compressedMember)); }
|
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); static FederationMember getFederationMemberFromKey(BtcECKey pk); static List<FederationMember> getFederationMembersFromKeys(List<BtcECKey> pks); BtcECKey getBtcPublicKey(); ECKey getRskPublicKey(); ECKey getMstPublicKey(); ECKey getPublicKey(KeyType keyType); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); static FederationMember getFederationMemberFromKey(BtcECKey pk); static List<FederationMember> getFederationMembersFromKeys(List<BtcECKey> pks); BtcECKey getBtcPublicKey(); ECKey getRskPublicKey(); ECKey getMstPublicKey(); ECKey getPublicKey(KeyType keyType); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); static final Comparator<FederationMember> BTC_RSK_MST_PUBKEYS_COMPARATOR; }
|
@Test public void testEquals_differentBtcKey() { FederationMember otherMember = new FederationMember(new BtcECKey(), rskKey, mstKey); Assert.assertFalse(member.equals(otherMember)); }
|
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); static FederationMember getFederationMemberFromKey(BtcECKey pk); static List<FederationMember> getFederationMembersFromKeys(List<BtcECKey> pks); BtcECKey getBtcPublicKey(); ECKey getRskPublicKey(); ECKey getMstPublicKey(); ECKey getPublicKey(KeyType keyType); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); static FederationMember getFederationMemberFromKey(BtcECKey pk); static List<FederationMember> getFederationMembersFromKeys(List<BtcECKey> pks); BtcECKey getBtcPublicKey(); ECKey getRskPublicKey(); ECKey getMstPublicKey(); ECKey getPublicKey(KeyType keyType); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); static final Comparator<FederationMember> BTC_RSK_MST_PUBKEYS_COMPARATOR; }
|
@Test public void testEquals_differentRskKey() { FederationMember otherMember = new FederationMember(btcKey, new ECKey(), mstKey); Assert.assertFalse(member.equals(otherMember)); }
|
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); static FederationMember getFederationMemberFromKey(BtcECKey pk); static List<FederationMember> getFederationMembersFromKeys(List<BtcECKey> pks); BtcECKey getBtcPublicKey(); ECKey getRskPublicKey(); ECKey getMstPublicKey(); ECKey getPublicKey(KeyType keyType); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); static FederationMember getFederationMemberFromKey(BtcECKey pk); static List<FederationMember> getFederationMembersFromKeys(List<BtcECKey> pks); BtcECKey getBtcPublicKey(); ECKey getRskPublicKey(); ECKey getMstPublicKey(); ECKey getPublicKey(KeyType keyType); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); static final Comparator<FederationMember> BTC_RSK_MST_PUBKEYS_COMPARATOR; }
|
@Test public void testEquals_differentMstKey() { FederationMember otherMember = new FederationMember(btcKey, rskKey, new ECKey()); Assert.assertFalse(member.equals(otherMember)); }
|
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); static FederationMember getFederationMemberFromKey(BtcECKey pk); static List<FederationMember> getFederationMembersFromKeys(List<BtcECKey> pks); BtcECKey getBtcPublicKey(); ECKey getRskPublicKey(); ECKey getMstPublicKey(); ECKey getPublicKey(KeyType keyType); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
FederationMember { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } FederationMember otherFederationMember = (FederationMember) other; return Arrays.equals(btcPublicKey.getPubKey(), otherFederationMember.btcPublicKey.getPubKey()) && Arrays.equals(rskPublicKey.getPubKey(), otherFederationMember.rskPublicKey.getPubKey()) && Arrays.equals(mstPublicKey.getPubKey(), otherFederationMember.mstPublicKey.getPubKey()); } FederationMember(BtcECKey btcPublicKey, ECKey rskPublicKey, ECKey mstPublicKey); static FederationMember getFederationMemberFromKey(BtcECKey pk); static List<FederationMember> getFederationMembersFromKeys(List<BtcECKey> pks); BtcECKey getBtcPublicKey(); ECKey getRskPublicKey(); ECKey getMstPublicKey(); ECKey getPublicKey(KeyType keyType); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); static final Comparator<FederationMember> BTC_RSK_MST_PUBKEYS_COMPARATOR; }
|
@Test public void payMiningFees() { Repository repositoryMock = Mockito.mock(Repository.class); RemascFeesPayer feesPayer = new RemascFeesPayer(repositoryMock, PrecompiledContracts.REMASC_ADDR); byte[] blockHash = { 0x1, 0x2 }; Coin value = Coin.valueOf(7L); RskAddress toAddress = new RskAddress("6c386a4b26f73c802f34673f7248bb118f97424a"); List<LogInfo> logs = new ArrayList<>(); feesPayer.payMiningFees(blockHash, value, toAddress, logs); Assert.assertEquals(1, feesPayer.getSubtraces().size()); ProgramSubtrace subtrace = feesPayer.getSubtraces().get(0); Assert.assertEquals(DataWord.valueOf(PrecompiledContracts.REMASC_ADDR.getBytes()), subtrace.getInvokeData().getCallerAddress()); Assert.assertEquals(DataWord.valueOf(toAddress.getBytes()), subtrace.getInvokeData().getOwnerAddress()); Assert.assertEquals(DataWord.valueOf(value.getBytes()), subtrace.getInvokeData().getCallValue()); Assert.assertEquals(1, logs.size()); LogInfo result = logs.get(0); Assert.assertArrayEquals(PrecompiledContracts.REMASC_ADDR.getBytes(), result.getAddress()); Assert.assertEquals(2, result.getTopics().size()); Assert.assertEquals("000000000000000000000000000000006d696e696e675f6665655f746f706963", result.getTopics().get(0).toString()); Assert.assertEquals("0000000000000000000000006c386a4b26f73c802f34673f7248bb118f97424a", result.getTopics().get(1).toString()); Assert.assertNotNull(result.getData()); List<RLPElement> rlpData = RLP.decode2(result.getData()); Assert.assertEquals(1 , rlpData.size()); RLPList dataList = (RLPList)rlpData.get(0); Assert.assertEquals(2, dataList.size()); Assert.assertArrayEquals(blockHash, dataList.get(0).getRLPData()); Assert.assertEquals(value, RLP.parseCoin(dataList.get(1).getRLPData())); verify(repositoryMock, times(1)).addBalance(PrecompiledContracts.REMASC_ADDR, value.negate()); verify(repositoryMock, times(1)).addBalance(toAddress, value); }
|
public void payMiningFees(byte[] blockHash, Coin value, RskAddress toAddress, List<LogInfo> logs) { this.transferPayment(value, toAddress); this.logPayment(blockHash, value, toAddress, logs); }
|
RemascFeesPayer { public void payMiningFees(byte[] blockHash, Coin value, RskAddress toAddress, List<LogInfo> logs) { this.transferPayment(value, toAddress); this.logPayment(blockHash, value, toAddress, logs); } }
|
RemascFeesPayer { public void payMiningFees(byte[] blockHash, Coin value, RskAddress toAddress, List<LogInfo> logs) { this.transferPayment(value, toAddress); this.logPayment(blockHash, value, toAddress, logs); } RemascFeesPayer(Repository repository, RskAddress contractAddress); }
|
RemascFeesPayer { public void payMiningFees(byte[] blockHash, Coin value, RskAddress toAddress, List<LogInfo> logs) { this.transferPayment(value, toAddress); this.logPayment(blockHash, value, toAddress, logs); } RemascFeesPayer(Repository repository, RskAddress contractAddress); List<ProgramSubtrace> getSubtraces(); void payMiningFees(byte[] blockHash, Coin value, RskAddress toAddress, List<LogInfo> logs); }
|
RemascFeesPayer { public void payMiningFees(byte[] blockHash, Coin value, RskAddress toAddress, List<LogInfo> logs) { this.transferPayment(value, toAddress); this.logPayment(blockHash, value, toAddress, logs); } RemascFeesPayer(Repository repository, RskAddress contractAddress); List<ProgramSubtrace> getSubtraces(); void payMiningFees(byte[] blockHash, Coin value, RskAddress toAddress, List<LogInfo> logs); }
|
@Test public void getDefautRewardBalance() { RskAddress accountAddress = randomAddress(); Repository repository = createRepository(); RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress); Assert.assertEquals(Coin.ZERO, provider.getRewardBalance()); }
|
public Coin getRewardBalance() { if (rewardBalance != null) { return rewardBalance; } DataWord address = DataWord.fromString(REWARD_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); }
|
RemascStorageProvider { public Coin getRewardBalance() { if (rewardBalance != null) { return rewardBalance; } DataWord address = DataWord.fromString(REWARD_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } }
|
RemascStorageProvider { public Coin getRewardBalance() { if (rewardBalance != null) { return rewardBalance; } DataWord address = DataWord.fromString(REWARD_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); }
|
RemascStorageProvider { public Coin getRewardBalance() { if (rewardBalance != null) { return rewardBalance; } DataWord address = DataWord.fromString(REWARD_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); Coin getFederationBalance(); Coin getRewardBalance(); void setFederationBalance(Coin federationBalance); void setRewardBalance(Coin rewardBalance); Coin getBurnedBalance(); void setBurnedBalance(Coin burnedBalance); void addToBurnBalance(Coin amountToBurn); Boolean getBrokenSelectionRule(); void setBrokenSelectionRule(Boolean brokenSelectionRule); void save(); }
|
RemascStorageProvider { public Coin getRewardBalance() { if (rewardBalance != null) { return rewardBalance; } DataWord address = DataWord.fromString(REWARD_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); Coin getFederationBalance(); Coin getRewardBalance(); void setFederationBalance(Coin federationBalance); void setRewardBalance(Coin rewardBalance); Coin getBurnedBalance(); void setBurnedBalance(Coin burnedBalance); void addToBurnBalance(Coin amountToBurn); Boolean getBrokenSelectionRule(); void setBrokenSelectionRule(Boolean brokenSelectionRule); void save(); }
|
@Test(expected = RuntimeException.class) public void testEncodeNull() { encode(null); }
|
public static byte[] encode(Object input) { Value val = new Value(input); if (val.isList()) { List<Object> inputArray = val.asList(); if (inputArray.isEmpty()) { return encodeLength(inputArray.size(), OFFSET_SHORT_LIST); } byte[] output = ByteUtil.EMPTY_BYTE_ARRAY; for (Object object : inputArray) { output = concatenate(output, encode(object)); } byte[] prefix = encodeLength(output.length, OFFSET_SHORT_LIST); return concatenate(prefix, output); } else { byte[] inputAsBytes = toBytes(input); if (inputAsBytes.length == 1 && (inputAsBytes[0] & 0xff) < 0x80) { return inputAsBytes; } else { byte[] firstByte = encodeLength(inputAsBytes.length, OFFSET_SHORT_ITEM); return concatenate(firstByte, inputAsBytes); } } }
|
RLP { public static byte[] encode(Object input) { Value val = new Value(input); if (val.isList()) { List<Object> inputArray = val.asList(); if (inputArray.isEmpty()) { return encodeLength(inputArray.size(), OFFSET_SHORT_LIST); } byte[] output = ByteUtil.EMPTY_BYTE_ARRAY; for (Object object : inputArray) { output = concatenate(output, encode(object)); } byte[] prefix = encodeLength(output.length, OFFSET_SHORT_LIST); return concatenate(prefix, output); } else { byte[] inputAsBytes = toBytes(input); if (inputAsBytes.length == 1 && (inputAsBytes[0] & 0xff) < 0x80) { return inputAsBytes; } else { byte[] firstByte = encodeLength(inputAsBytes.length, OFFSET_SHORT_ITEM); return concatenate(firstByte, inputAsBytes); } } } }
|
RLP { public static byte[] encode(Object input) { Value val = new Value(input); if (val.isList()) { List<Object> inputArray = val.asList(); if (inputArray.isEmpty()) { return encodeLength(inputArray.size(), OFFSET_SHORT_LIST); } byte[] output = ByteUtil.EMPTY_BYTE_ARRAY; for (Object object : inputArray) { output = concatenate(output, encode(object)); } byte[] prefix = encodeLength(output.length, OFFSET_SHORT_LIST); return concatenate(prefix, output); } else { byte[] inputAsBytes = toBytes(input); if (inputAsBytes.length == 1 && (inputAsBytes[0] & 0xff) < 0x80) { return inputAsBytes; } else { byte[] firstByte = encodeLength(inputAsBytes.length, OFFSET_SHORT_ITEM); return concatenate(firstByte, inputAsBytes); } } } }
|
RLP { public static byte[] encode(Object input) { Value val = new Value(input); if (val.isList()) { List<Object> inputArray = val.asList(); if (inputArray.isEmpty()) { return encodeLength(inputArray.size(), OFFSET_SHORT_LIST); } byte[] output = ByteUtil.EMPTY_BYTE_ARRAY; for (Object object : inputArray) { output = concatenate(output, encode(object)); } byte[] prefix = encodeLength(output.length, OFFSET_SHORT_LIST); return concatenate(prefix, output); } else { byte[] inputAsBytes = toBytes(input); if (inputAsBytes.length == 1 && (inputAsBytes[0] & 0xff) < 0x80) { return inputAsBytes; } else { byte[] firstByte = encodeLength(inputAsBytes.length, OFFSET_SHORT_ITEM); return concatenate(firstByte, inputAsBytes); } } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static byte[] encode(Object input) { Value val = new Value(input); if (val.isList()) { List<Object> inputArray = val.asList(); if (inputArray.isEmpty()) { return encodeLength(inputArray.size(), OFFSET_SHORT_LIST); } byte[] output = ByteUtil.EMPTY_BYTE_ARRAY; for (Object object : inputArray) { output = concatenate(output, encode(object)); } byte[] prefix = encodeLength(output.length, OFFSET_SHORT_LIST); return concatenate(prefix, output); } else { byte[] inputAsBytes = toBytes(input); if (inputAsBytes.length == 1 && (inputAsBytes[0] & 0xff) < 0x80) { return inputAsBytes; } else { byte[] firstByte = encodeLength(inputAsBytes.length, OFFSET_SHORT_ITEM); return concatenate(firstByte, inputAsBytes); } } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void getDefautBurnedBalance() { RskAddress accountAddress = randomAddress(); Repository repository = createRepository(); RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress); Assert.assertEquals(Coin.ZERO, provider.getBurnedBalance()); }
|
public Coin getBurnedBalance() { if (burnedBalance != null) { return burnedBalance; } DataWord address = DataWord.fromString(BURNED_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); }
|
RemascStorageProvider { public Coin getBurnedBalance() { if (burnedBalance != null) { return burnedBalance; } DataWord address = DataWord.fromString(BURNED_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } }
|
RemascStorageProvider { public Coin getBurnedBalance() { if (burnedBalance != null) { return burnedBalance; } DataWord address = DataWord.fromString(BURNED_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); }
|
RemascStorageProvider { public Coin getBurnedBalance() { if (burnedBalance != null) { return burnedBalance; } DataWord address = DataWord.fromString(BURNED_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); Coin getFederationBalance(); Coin getRewardBalance(); void setFederationBalance(Coin federationBalance); void setRewardBalance(Coin rewardBalance); Coin getBurnedBalance(); void setBurnedBalance(Coin burnedBalance); void addToBurnBalance(Coin amountToBurn); Boolean getBrokenSelectionRule(); void setBrokenSelectionRule(Boolean brokenSelectionRule); void save(); }
|
RemascStorageProvider { public Coin getBurnedBalance() { if (burnedBalance != null) { return burnedBalance; } DataWord address = DataWord.fromString(BURNED_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); Coin getFederationBalance(); Coin getRewardBalance(); void setFederationBalance(Coin federationBalance); void setRewardBalance(Coin rewardBalance); Coin getBurnedBalance(); void setBurnedBalance(Coin burnedBalance); void addToBurnBalance(Coin amountToBurn); Boolean getBrokenSelectionRule(); void setBrokenSelectionRule(Boolean brokenSelectionRule); void save(); }
|
@Test public void getDefaultBrokenSelectionRule() { RskAddress accountAddress = randomAddress(); Repository repository = createRepository(); RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress); Assert.assertEquals(Boolean.FALSE, provider.getBrokenSelectionRule()); }
|
public Boolean getBrokenSelectionRule() { if (brokenSelectionRule!= null) { return brokenSelectionRule; } DataWord address = DataWord.fromString(BROKEN_SELECTION_RULE_KEY); byte[] bytes = this.repository.getStorageBytes(this.contractAddress, address); if (bytes == null || bytes.length == 0) { return Boolean.FALSE; } if (bytes[0] == 0) { return Boolean.FALSE; } else { return Boolean.TRUE; } }
|
RemascStorageProvider { public Boolean getBrokenSelectionRule() { if (brokenSelectionRule!= null) { return brokenSelectionRule; } DataWord address = DataWord.fromString(BROKEN_SELECTION_RULE_KEY); byte[] bytes = this.repository.getStorageBytes(this.contractAddress, address); if (bytes == null || bytes.length == 0) { return Boolean.FALSE; } if (bytes[0] == 0) { return Boolean.FALSE; } else { return Boolean.TRUE; } } }
|
RemascStorageProvider { public Boolean getBrokenSelectionRule() { if (brokenSelectionRule!= null) { return brokenSelectionRule; } DataWord address = DataWord.fromString(BROKEN_SELECTION_RULE_KEY); byte[] bytes = this.repository.getStorageBytes(this.contractAddress, address); if (bytes == null || bytes.length == 0) { return Boolean.FALSE; } if (bytes[0] == 0) { return Boolean.FALSE; } else { return Boolean.TRUE; } } RemascStorageProvider(Repository repository, RskAddress contractAddress); }
|
RemascStorageProvider { public Boolean getBrokenSelectionRule() { if (brokenSelectionRule!= null) { return brokenSelectionRule; } DataWord address = DataWord.fromString(BROKEN_SELECTION_RULE_KEY); byte[] bytes = this.repository.getStorageBytes(this.contractAddress, address); if (bytes == null || bytes.length == 0) { return Boolean.FALSE; } if (bytes[0] == 0) { return Boolean.FALSE; } else { return Boolean.TRUE; } } RemascStorageProvider(Repository repository, RskAddress contractAddress); Coin getFederationBalance(); Coin getRewardBalance(); void setFederationBalance(Coin federationBalance); void setRewardBalance(Coin rewardBalance); Coin getBurnedBalance(); void setBurnedBalance(Coin burnedBalance); void addToBurnBalance(Coin amountToBurn); Boolean getBrokenSelectionRule(); void setBrokenSelectionRule(Boolean brokenSelectionRule); void save(); }
|
RemascStorageProvider { public Boolean getBrokenSelectionRule() { if (brokenSelectionRule!= null) { return brokenSelectionRule; } DataWord address = DataWord.fromString(BROKEN_SELECTION_RULE_KEY); byte[] bytes = this.repository.getStorageBytes(this.contractAddress, address); if (bytes == null || bytes.length == 0) { return Boolean.FALSE; } if (bytes[0] == 0) { return Boolean.FALSE; } else { return Boolean.TRUE; } } RemascStorageProvider(Repository repository, RskAddress contractAddress); Coin getFederationBalance(); Coin getRewardBalance(); void setFederationBalance(Coin federationBalance); void setRewardBalance(Coin rewardBalance); Coin getBurnedBalance(); void setBurnedBalance(Coin burnedBalance); void addToBurnBalance(Coin amountToBurn); Boolean getBrokenSelectionRule(); void setBrokenSelectionRule(Boolean brokenSelectionRule); void save(); }
|
@Test public void alwaysPaysFedBeforeRFS() throws IOException { RskSystemProperties config = spy(new TestSystemProperties()); when(config.getActivationConfig()).thenReturn(ActivationConfigsForTest.allBut(ConsensusRule.RSKIP85)); long minerFee = 21000; long txValue = 10000; long gasPrice = 1L; BlockChainBuilder builder = new BlockChainBuilder().setTesting(true).setGenesis(genesisBlock).setConfig(config); RemascTestRunner testRunner = new RemascTestRunner(builder, this.genesisBlock).txValue(txValue).minerFee(minerFee) .initialHeight(15).siblingElements(new ArrayList<>()).txSigningKey(this.cowKey).gasPrice(gasPrice); testRunner.start(); Blockchain blockchain = testRunner.getBlockChain(); RepositoryLocator repositoryLocator = builder.getRepositoryLocator(); RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader()); RemascFederationProvider federationProvider = new RemascFederationProvider(config.getActivationConfig(), config.getNetworkConstants().getBridgeConstants(), repository.startTracking(), testRunner.getBlockChain().getBestBlock()); assertEquals(Coin.valueOf(0), this.getRemascStorageProvider(repository).getFederationBalance()); long federatorBalance = (168 / federationProvider.getFederationSize()) * 2; assertEquals(Coin.valueOf(federatorBalance), RemascTestRunner.getAccountBalance(repository, federationProvider.getFederatorAddress(0))); }
|
public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); }
|
RemascStorageProvider { public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } }
|
RemascStorageProvider { public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); }
|
RemascStorageProvider { public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); Coin getFederationBalance(); Coin getRewardBalance(); void setFederationBalance(Coin federationBalance); void setRewardBalance(Coin rewardBalance); Coin getBurnedBalance(); void setBurnedBalance(Coin burnedBalance); void addToBurnBalance(Coin amountToBurn); Boolean getBrokenSelectionRule(); void setBrokenSelectionRule(Boolean brokenSelectionRule); void save(); }
|
RemascStorageProvider { public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); Coin getFederationBalance(); Coin getRewardBalance(); void setFederationBalance(Coin federationBalance); void setRewardBalance(Coin rewardBalance); Coin getBurnedBalance(); void setBurnedBalance(Coin burnedBalance); void addToBurnBalance(Coin amountToBurn); Boolean getBrokenSelectionRule(); void setBrokenSelectionRule(Boolean brokenSelectionRule); void save(); }
|
@Test public void doesntPayFedBelowMinimumRewardAfterRFS() throws IOException { Constants constants = spy(Constants.testnet()); when(constants.getChainId()).thenReturn(Constants.REGTEST_CHAIN_ID); when(constants.getMinimumPayableGas()).thenReturn(BigInteger.valueOf(0)); when(constants.getFederatorMinimumPayableGas()).thenReturn(BigInteger.valueOf(10000L)); RskSystemProperties config = spy(new TestSystemProperties()); when(config.getNetworkConstants()).thenReturn(constants); long minerFee = 21000; long txValue = 10000; long gasPrice = 1L; BlockChainBuilder builder = new BlockChainBuilder().setTesting(true).setGenesis(genesisBlock).setConfig(config); RemascTestRunner testRunner = new RemascTestRunner(builder, this.genesisBlock).txValue(txValue).minerFee(minerFee) .initialHeight(15).siblingElements(new ArrayList<>()).txSigningKey(this.cowKey).gasPrice(gasPrice); testRunner.start(); Blockchain blockchain = testRunner.getBlockChain(); RepositoryLocator repositoryLocator = builder.getRepositoryLocator(); RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader()); RemascFederationProvider federationProvider = new RemascFederationProvider(config.getActivationConfig(), config.getNetworkConstants().getBridgeConstants(), repository.startTracking(), testRunner.getBlockChain().getBestBlock()); assertEquals(Coin.valueOf(336), this.getRemascStorageProvider(repository).getFederationBalance()); assertEquals(null, RemascTestRunner.getAccountBalance(repository, federationProvider.getFederatorAddress(0))); }
|
public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); }
|
RemascStorageProvider { public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } }
|
RemascStorageProvider { public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); }
|
RemascStorageProvider { public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); Coin getFederationBalance(); Coin getRewardBalance(); void setFederationBalance(Coin federationBalance); void setRewardBalance(Coin rewardBalance); Coin getBurnedBalance(); void setBurnedBalance(Coin burnedBalance); void addToBurnBalance(Coin amountToBurn); Boolean getBrokenSelectionRule(); void setBrokenSelectionRule(Boolean brokenSelectionRule); void save(); }
|
RemascStorageProvider { public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); Coin getFederationBalance(); Coin getRewardBalance(); void setFederationBalance(Coin federationBalance); void setRewardBalance(Coin rewardBalance); Coin getBurnedBalance(); void setBurnedBalance(Coin burnedBalance); void addToBurnBalance(Coin amountToBurn); Boolean getBrokenSelectionRule(); void setBrokenSelectionRule(Boolean brokenSelectionRule); void save(); }
|
@Test public void paysFedWhenHigherThanMinimumRewardAfterRFS() throws IOException { Constants constants = spy(Constants.testnet()); when(constants.getChainId()).thenReturn(Constants.REGTEST_CHAIN_ID); when(constants.getMinimumPayableGas()).thenReturn(BigInteger.valueOf(0)); when(constants.getFederatorMinimumPayableGas()).thenReturn(BigInteger.valueOf(10L)); RskSystemProperties config = spy(new TestSystemProperties()); when(config.getNetworkConstants()).thenReturn(constants); long minerFee = 21000; long txValue = 10000; long gasPrice = 10L; BlockChainBuilder builder = new BlockChainBuilder().setTesting(true).setGenesis(genesisBlock).setConfig(config); RemascTestRunner testRunner = new RemascTestRunner(builder, this.genesisBlock).txValue(txValue).minerFee(minerFee) .initialHeight(15).siblingElements(new ArrayList<>()).txSigningKey(this.cowKey).gasPrice(gasPrice); testRunner.start(); Blockchain blockchain = testRunner.getBlockChain(); RepositoryLocator repositoryLocator = builder.getRepositoryLocator(); RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader()); RemascFederationProvider federationProvider = new RemascFederationProvider(config.getActivationConfig(), config.getNetworkConstants().getBridgeConstants(), repository.startTracking(), testRunner.getBlockChain().getBestBlock()); long federatorBalance = (1680 / federationProvider.getFederationSize()) * 2; assertEquals(Coin.valueOf(0), this.getRemascStorageProvider(repository).getFederationBalance()); assertEquals(Coin.valueOf(federatorBalance), RemascTestRunner.getAccountBalance(repository, federationProvider.getFederatorAddress(0))); }
|
public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); }
|
RemascStorageProvider { public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } }
|
RemascStorageProvider { public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); }
|
RemascStorageProvider { public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); Coin getFederationBalance(); Coin getRewardBalance(); void setFederationBalance(Coin federationBalance); void setRewardBalance(Coin rewardBalance); Coin getBurnedBalance(); void setBurnedBalance(Coin burnedBalance); void addToBurnBalance(Coin amountToBurn); Boolean getBrokenSelectionRule(); void setBrokenSelectionRule(Boolean brokenSelectionRule); void save(); }
|
RemascStorageProvider { public Coin getFederationBalance() { if (federationBalance != null) { return federationBalance ; } DataWord address = DataWord.fromString(FEDERATION_BALANCE_KEY); DataWord value = this.repository.getStorageValue(this.contractAddress, address); if (value == null) { return Coin.ZERO; } return new Coin(value.getData()); } RemascStorageProvider(Repository repository, RskAddress contractAddress); Coin getFederationBalance(); Coin getRewardBalance(); void setFederationBalance(Coin federationBalance); void setRewardBalance(Coin rewardBalance); Coin getBurnedBalance(); void setBurnedBalance(Coin burnedBalance); void addToBurnBalance(Coin amountToBurn); Boolean getBrokenSelectionRule(); void setBrokenSelectionRule(Boolean brokenSelectionRule); void save(); }
|
@Test public void getDefaultFederationSize() { RemascFederationProvider provider = getRemascFederationProvider(); Assert.assertEquals(3, provider.getFederationSize()); }
|
public int getFederationSize() { return this.federationSupport.getFederationSize(); }
|
RemascFederationProvider { public int getFederationSize() { return this.federationSupport.getFederationSize(); } }
|
RemascFederationProvider { public int getFederationSize() { return this.federationSupport.getFederationSize(); } RemascFederationProvider(
ActivationConfig activationConfig,
BridgeConstants bridgeConstants,
Repository repository,
Block processingBlock); }
|
RemascFederationProvider { public int getFederationSize() { return this.federationSupport.getFederationSize(); } RemascFederationProvider(
ActivationConfig activationConfig,
BridgeConstants bridgeConstants,
Repository repository,
Block processingBlock); int getFederationSize(); RskAddress getFederatorAddress(int n); }
|
RemascFederationProvider { public int getFederationSize() { return this.federationSupport.getFederationSize(); } RemascFederationProvider(
ActivationConfig activationConfig,
BridgeConstants bridgeConstants,
Repository repository,
Block processingBlock); int getFederationSize(); RskAddress getFederatorAddress(int n); }
|
@Test public void getFederatorAddress() { RemascFederationProvider provider = getRemascFederationProvider(); byte[] address = provider.getFederatorAddress(0).getBytes(); Assert.assertNotNull(address); Assert.assertEquals(20, address.length); }
|
public RskAddress getFederatorAddress(int n) { byte[] publicKey = this.federationSupport.getFederatorBtcPublicKey(n); return new RskAddress(ECKey.fromPublicOnly(publicKey).getAddress()); }
|
RemascFederationProvider { public RskAddress getFederatorAddress(int n) { byte[] publicKey = this.federationSupport.getFederatorBtcPublicKey(n); return new RskAddress(ECKey.fromPublicOnly(publicKey).getAddress()); } }
|
RemascFederationProvider { public RskAddress getFederatorAddress(int n) { byte[] publicKey = this.federationSupport.getFederatorBtcPublicKey(n); return new RskAddress(ECKey.fromPublicOnly(publicKey).getAddress()); } RemascFederationProvider(
ActivationConfig activationConfig,
BridgeConstants bridgeConstants,
Repository repository,
Block processingBlock); }
|
RemascFederationProvider { public RskAddress getFederatorAddress(int n) { byte[] publicKey = this.federationSupport.getFederatorBtcPublicKey(n); return new RskAddress(ECKey.fromPublicOnly(publicKey).getAddress()); } RemascFederationProvider(
ActivationConfig activationConfig,
BridgeConstants bridgeConstants,
Repository repository,
Block processingBlock); int getFederationSize(); RskAddress getFederatorAddress(int n); }
|
RemascFederationProvider { public RskAddress getFederatorAddress(int n) { byte[] publicKey = this.federationSupport.getFederatorBtcPublicKey(n); return new RskAddress(ECKey.fromPublicOnly(publicKey).getAddress()); } RemascFederationProvider(
ActivationConfig activationConfig,
BridgeConstants bridgeConstants,
Repository repository,
Block processingBlock); int getFederationSize(); RskAddress getFederatorAddress(int n); }
|
@Test public void addOneToZero() { BlockDifficulty d1 = new BlockDifficulty(BigInteger.ZERO); BlockDifficulty d2 = new BlockDifficulty(BigInteger.ONE); assertThat(d1.add(d2), is(d2)); }
|
public BlockDifficulty add(BlockDifficulty other) { return new BlockDifficulty(value.add(other.value)); }
|
BlockDifficulty implements Comparable<BlockDifficulty>, Serializable { public BlockDifficulty add(BlockDifficulty other) { return new BlockDifficulty(value.add(other.value)); } }
|
BlockDifficulty implements Comparable<BlockDifficulty>, Serializable { public BlockDifficulty add(BlockDifficulty other) { return new BlockDifficulty(value.add(other.value)); } BlockDifficulty(BigInteger value); }
|
BlockDifficulty implements Comparable<BlockDifficulty>, Serializable { public BlockDifficulty add(BlockDifficulty other) { return new BlockDifficulty(value.add(other.value)); } BlockDifficulty(BigInteger value); byte[] getBytes(); BigInteger asBigInteger(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); BlockDifficulty add(BlockDifficulty other); BlockDifficulty subtract(BlockDifficulty other); @Override int compareTo(@Nonnull BlockDifficulty other); }
|
BlockDifficulty implements Comparable<BlockDifficulty>, Serializable { public BlockDifficulty add(BlockDifficulty other) { return new BlockDifficulty(value.add(other.value)); } BlockDifficulty(BigInteger value); byte[] getBytes(); BigInteger asBigInteger(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); BlockDifficulty add(BlockDifficulty other); BlockDifficulty subtract(BlockDifficulty other); @Override int compareTo(@Nonnull BlockDifficulty other); static final BlockDifficulty ZERO; static final BlockDifficulty ONE; }
|
@Test public void addOneToOne() { BlockDifficulty d1 = new BlockDifficulty(BigInteger.ONE); BlockDifficulty d2 = new BlockDifficulty(BigInteger.ONE); assertThat(d1.add(d2), is(new BlockDifficulty(BigInteger.valueOf(2)))); }
|
public BlockDifficulty add(BlockDifficulty other) { return new BlockDifficulty(value.add(other.value)); }
|
BlockDifficulty implements Comparable<BlockDifficulty>, Serializable { public BlockDifficulty add(BlockDifficulty other) { return new BlockDifficulty(value.add(other.value)); } }
|
BlockDifficulty implements Comparable<BlockDifficulty>, Serializable { public BlockDifficulty add(BlockDifficulty other) { return new BlockDifficulty(value.add(other.value)); } BlockDifficulty(BigInteger value); }
|
BlockDifficulty implements Comparable<BlockDifficulty>, Serializable { public BlockDifficulty add(BlockDifficulty other) { return new BlockDifficulty(value.add(other.value)); } BlockDifficulty(BigInteger value); byte[] getBytes(); BigInteger asBigInteger(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); BlockDifficulty add(BlockDifficulty other); BlockDifficulty subtract(BlockDifficulty other); @Override int compareTo(@Nonnull BlockDifficulty other); }
|
BlockDifficulty implements Comparable<BlockDifficulty>, Serializable { public BlockDifficulty add(BlockDifficulty other) { return new BlockDifficulty(value.add(other.value)); } BlockDifficulty(BigInteger value); byte[] getBytes(); BigInteger asBigInteger(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); BlockDifficulty add(BlockDifficulty other); BlockDifficulty subtract(BlockDifficulty other); @Override int compareTo(@Nonnull BlockDifficulty other); static final BlockDifficulty ZERO; static final BlockDifficulty ONE; }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.