use of co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType in project rskj by rsksmart.
the class BridgeSupport method processPegInVersionLegacy.
private void processPegInVersionLegacy(BtcTransaction btcTx, Transaction rskTx, int height, PeginInformation peginInformation, Coin totalAmount) throws IOException, RegisterBtcTransactionException {
Address senderBtcAddress = peginInformation.getSenderBtcAddress();
TxSenderAddressType senderBtcAddressType = peginInformation.getSenderBtcAddressType();
if (!BridgeUtils.txIsProcessableInLegacyVersion(senderBtcAddressType, activations)) {
logger.warn("[processPeginVersionLegacy] [btcTx:{}] Could not get BtcLockSender from Btc tx", btcTx.getHash());
if (activations.isActive(ConsensusRule.RSKIP181)) {
eventLogger.logRejectedPegin(btcTx, RejectedPeginReason.LEGACY_PEGIN_UNDETERMINED_SENDER);
}
throw new RegisterBtcTransactionException("Could not get BtcLockSender from Btc tx");
}
// Confirm we should process this lock
if (shouldProcessPegInVersionLegacy(senderBtcAddressType, btcTx, senderBtcAddress, totalAmount, height)) {
executePegIn(btcTx, peginInformation, totalAmount);
} else {
if (activations.isActive(ConsensusRule.RSKIP181)) {
if (!isTxLockableForLegacyVersion(senderBtcAddressType, btcTx, senderBtcAddress)) {
eventLogger.logRejectedPegin(btcTx, RejectedPeginReason.LEGACY_PEGIN_MULTISIG_SENDER);
} else if (!verifyLockDoesNotSurpassLockingCap(btcTx, totalAmount)) {
eventLogger.logRejectedPegin(btcTx, RejectedPeginReason.PEGIN_CAP_SURPASSED);
}
}
generateRejectionRelease(btcTx, senderBtcAddress, rskTx, totalAmount);
}
}
use of co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType in project rskj by rsksmart.
the class BridgeSupport method executePegIn.
private void executePegIn(BtcTransaction btcTx, PeginInformation peginInformation, Coin amount) throws IOException {
RskAddress rskDestinationAddress = peginInformation.getRskDestinationAddress();
Address senderBtcAddress = peginInformation.getSenderBtcAddress();
TxSenderAddressType senderBtcAddressType = peginInformation.getSenderBtcAddressType();
int protocolVersion = peginInformation.getProtocolVersion();
co.rsk.core.Coin amountInWeis = co.rsk.core.Coin.fromBitcoin(amount);
logger.debug("[executePegIn] [btcTx:{}] Is a lock from a {} sender", btcTx.getHash(), senderBtcAddressType);
this.transferTo(peginInformation.getRskDestinationAddress(), amountInWeis);
logger.info("[executePegIn] Transferring from BTC Address {}. RSK Address: {}. Amount: {}", senderBtcAddress, rskDestinationAddress, amountInWeis);
if (activations.isActive(ConsensusRule.RSKIP146)) {
if (activations.isActive(ConsensusRule.RSKIP170)) {
eventLogger.logPeginBtc(rskDestinationAddress, btcTx, amount, protocolVersion);
} else {
eventLogger.logLockBtc(rskDestinationAddress, btcTx, senderBtcAddress, amount);
}
}
// Save UTXOs from the federation(s) only if we actually locked the funds
saveNewUTXOs(btcTx);
}
use of co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType in project rskj by rsksmart.
the class PeginInformationTest method parse_fromPeginInstructions.
@Test
public void parse_fromPeginInstructions() throws PeginInstructionsException {
// Arrange
BtcECKey address1Key = new BtcECKey();
RskAddress rskDestinationAddressFromBtcLockSender = new RskAddress(ECKey.fromPublicOnly(address1Key.getPubKey()).getAddress());
Address btcRefundAddressFromBtcLockSender = address1Key.toAddress(networkParameters);
TxSenderAddressType senderBtcAddressType = TxSenderAddressType.P2PKH;
BtcTransaction btcTx = new BtcTransaction(networkParameters);
BtcLockSender btcLockSenderMock = mock(P2pkhBtcLockSender.class);
when(btcLockSenderMock.getRskAddress()).thenReturn(rskDestinationAddressFromBtcLockSender);
when(btcLockSenderMock.getBTCAddress()).thenReturn(btcRefundAddressFromBtcLockSender);
when(btcLockSenderMock.getTxSenderAddressType()).thenReturn(senderBtcAddressType);
BtcLockSenderProvider btcLockSenderProviderMock = mock(BtcLockSenderProvider.class);
when(btcLockSenderProviderMock.tryGetBtcLockSender(btcTx)).thenReturn(Optional.of(btcLockSenderMock));
BtcECKey address2Key = new BtcECKey();
RskAddress rskDestinationAddressFromPeginInstructions = new RskAddress(ECKey.fromPublicOnly(address2Key.getPubKey()).getAddress());
Address btcRefundAddressFromPeginInstructions = address2Key.toAddress(networkParameters);
PeginInstructionsVersion1 peginInstructionsMock = mock(PeginInstructionsVersion1.class);
when(peginInstructionsMock.getProtocolVersion()).thenReturn(1);
when(peginInstructionsMock.getRskDestinationAddress()).thenReturn(rskDestinationAddressFromPeginInstructions);
when(peginInstructionsMock.getBtcRefundAddress()).thenReturn(Optional.of(btcRefundAddressFromPeginInstructions));
PeginInstructionsProvider peginInstructionsProviderMock = mock(PeginInstructionsProvider.class);
when(peginInstructionsProviderMock.buildPeginInstructions(btcTx)).thenReturn(Optional.of(peginInstructionsMock));
ActivationConfig.ForBlock activationsMock = mock(ActivationConfig.ForBlock.class);
when(activationsMock.isActive(ConsensusRule.RSKIP170)).thenReturn(true);
// Act
PeginInformation peginInformation = new PeginInformation(btcLockSenderProviderMock, peginInstructionsProviderMock, activationsMock);
peginInformation.parse(btcTx);
// Assert
Assert.assertEquals(1, peginInformation.getProtocolVersion());
Assert.assertEquals(rskDestinationAddressFromPeginInstructions, peginInformation.getRskDestinationAddress());
Assert.assertEquals(btcRefundAddressFromPeginInstructions, peginInformation.getBtcRefundAddress());
Assert.assertEquals(btcRefundAddressFromBtcLockSender, peginInformation.getSenderBtcAddress());
Assert.assertEquals(senderBtcAddressType, peginInformation.getSenderBtcAddressType());
Assert.assertNotEquals(rskDestinationAddressFromBtcLockSender, peginInformation.getRskDestinationAddress());
Assert.assertNotEquals(btcRefundAddressFromBtcLockSender, peginInformation.getBtcRefundAddress());
}
use of co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType in project rskj by rsksmart.
the class PeginInformationTest method parse_withBtcLockSender_withPeginInstructions_preIris.
@Test
public void parse_withBtcLockSender_withPeginInstructions_preIris() throws PeginInstructionsException {
// Arrange
BtcECKey address1Key = new BtcECKey();
RskAddress rskDestinationAddressFromBtcLockSender = new RskAddress(ECKey.fromPublicOnly(address1Key.getPubKey()).getAddress());
Address btcRefundAddressFromBtcLockSender = address1Key.toAddress(networkParameters);
TxSenderAddressType senderBtcAddressType = TxSenderAddressType.P2PKH;
BtcTransaction btcTx = new BtcTransaction(networkParameters);
BtcLockSender btcLockSenderMock = mock(P2pkhBtcLockSender.class);
when(btcLockSenderMock.getRskAddress()).thenReturn(rskDestinationAddressFromBtcLockSender);
when(btcLockSenderMock.getBTCAddress()).thenReturn(btcRefundAddressFromBtcLockSender);
when(btcLockSenderMock.getTxSenderAddressType()).thenReturn(senderBtcAddressType);
BtcLockSenderProvider btcLockSenderProviderMock = mock(BtcLockSenderProvider.class);
when(btcLockSenderProviderMock.tryGetBtcLockSender(btcTx)).thenReturn(Optional.of(btcLockSenderMock));
BtcECKey address2Key = new BtcECKey();
RskAddress rskDestinationAddressFromPeginInstructions = new RskAddress(ECKey.fromPublicOnly(address2Key.getPubKey()).getAddress());
Address btcRefundAddressFromPeginInstructions = address2Key.toAddress(networkParameters);
PeginInstructionsVersion1 peginInstructionsMock = mock(PeginInstructionsVersion1.class);
when(peginInstructionsMock.getProtocolVersion()).thenReturn(1);
when(peginInstructionsMock.getRskDestinationAddress()).thenReturn(rskDestinationAddressFromPeginInstructions);
when(peginInstructionsMock.getBtcRefundAddress()).thenReturn(Optional.of(btcRefundAddressFromPeginInstructions));
PeginInstructionsProvider peginInstructionsProviderMock = mock(PeginInstructionsProvider.class);
when(peginInstructionsProviderMock.buildPeginInstructions(btcTx)).thenReturn(Optional.of(peginInstructionsMock));
ActivationConfig.ForBlock activationsMock = mock(ActivationConfig.ForBlock.class);
when(activationsMock.isActive(ConsensusRule.RSKIP170)).thenReturn(false);
// Act
PeginInformation peginInformation = new PeginInformation(btcLockSenderProviderMock, peginInstructionsProviderMock, activationsMock);
peginInformation.parse(btcTx);
// Assert
Assert.assertEquals(0, peginInformation.getProtocolVersion());
Assert.assertEquals(rskDestinationAddressFromBtcLockSender, peginInformation.getRskDestinationAddress());
Assert.assertEquals(btcRefundAddressFromBtcLockSender, peginInformation.getBtcRefundAddress());
Assert.assertEquals(btcRefundAddressFromBtcLockSender, peginInformation.getSenderBtcAddress());
Assert.assertEquals(senderBtcAddressType, peginInformation.getSenderBtcAddressType());
Assert.assertNotEquals(rskDestinationAddressFromPeginInstructions, peginInformation.getRskDestinationAddress());
Assert.assertNotEquals(btcRefundAddressFromPeginInstructions, peginInformation.getBtcRefundAddress());
}
use of co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType in project rskj by rsksmart.
the class PeginInformationTest method parse_fromBtcLockSender.
@Test
public void parse_fromBtcLockSender() throws PeginInstructionsException {
// Arrange
BtcECKey key = new BtcECKey();
RskAddress rskDestinationAddressFromBtcLockSender = new RskAddress(ECKey.fromPublicOnly(key.getPubKey()).getAddress());
Address btcRefundAddressFromBtcLockSender = key.toAddress(networkParameters);
TxSenderAddressType senderBtcAddressType = TxSenderAddressType.P2PKH;
BtcTransaction btcTx = new BtcTransaction(networkParameters);
BtcLockSender btcLockSenderMock = mock(P2pkhBtcLockSender.class);
when(btcLockSenderMock.getRskAddress()).thenReturn(rskDestinationAddressFromBtcLockSender);
when(btcLockSenderMock.getBTCAddress()).thenReturn(btcRefundAddressFromBtcLockSender);
when(btcLockSenderMock.getTxSenderAddressType()).thenReturn(senderBtcAddressType);
BtcLockSenderProvider btcLockSenderProviderMock = mock(BtcLockSenderProvider.class);
when(btcLockSenderProviderMock.tryGetBtcLockSender(btcTx)).thenReturn(Optional.of(btcLockSenderMock));
PeginInstructionsProvider peginInstructionsProviderMock = mock(PeginInstructionsProvider.class);
ActivationConfig.ForBlock activationsMock = mock(ActivationConfig.ForBlock.class);
// Act
PeginInformation peginInformation = new PeginInformation(btcLockSenderProviderMock, peginInstructionsProviderMock, activationsMock);
peginInformation.parse(btcTx);
// Assert
Assert.assertEquals(0, peginInformation.getProtocolVersion());
Assert.assertEquals(rskDestinationAddressFromBtcLockSender, peginInformation.getRskDestinationAddress());
Assert.assertEquals(btcRefundAddressFromBtcLockSender, peginInformation.getBtcRefundAddress());
Assert.assertEquals(btcRefundAddressFromBtcLockSender, peginInformation.getSenderBtcAddress());
Assert.assertEquals(senderBtcAddressType, peginInformation.getSenderBtcAddressType());
}
Aggregations