Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move flyover methods from BridgeSupport to BridgeUtils #2733

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package co.rsk.peg;

import static co.rsk.peg.BridgeUtils.getFlyoverAddress;
import static co.rsk.peg.BridgeUtils.getRegularPegoutTxSize;
import static co.rsk.peg.ReleaseTransactionBuilder.BTC_TX_VERSION_2;
import static co.rsk.peg.bitcoin.UtxoUtils.extractOutpointValues;
Expand Down Expand Up @@ -996,7 +997,8 @@ private BtcTransaction createSvpFundTransaction(Federation proposedFederation, C
// add outputs to proposed fed and proposed fed with flyover prefix
svpFundTransaction.addOutput(spendableValueFromProposedFederation, proposedFederation.getAddress());

Address proposedFederationWithFlyoverPrefixAddress = getProposedFederationWithFlyoverPrefixAddress(proposedFederation.getRedeemScript());
Address proposedFederationWithFlyoverPrefixAddress =
getFlyoverAddress(networkParameters, bridgeConstants.getProposedFederationFlyoverPrefix(), proposedFederation.getRedeemScript());
svpFundTransaction.addOutput(spendableValueFromProposedFederation, proposedFederationWithFlyoverPrefixAddress);

// complete tx with input and change output
Expand All @@ -1006,14 +1008,6 @@ private BtcTransaction createSvpFundTransaction(Federation proposedFederation, C
return svpFundTransaction;
}

private Address getProposedFederationWithFlyoverPrefixAddress(Script federationRedeemScript) {
FlyoverRedeemScriptBuilder flyoverRedeemScriptBuilder = new FlyoverRedeemScriptBuilderImpl();
Script federationWithFlyoverPrefixRedeemScript = flyoverRedeemScriptBuilder.addFlyoverDerivationHashToRedeemScript(bridgeConstants.getProposedFederationFlyoverPrefix(), federationRedeemScript);
Script federationWithFlyoverPrefixP2SHScript = ScriptBuilder.createP2SHOutputScript(federationWithFlyoverPrefixRedeemScript);

return Address.fromP2SHScript(networkParameters, federationWithFlyoverPrefixP2SHScript);
}

private SendRequest createSvpFundTransactionSendRequest(BtcTransaction transaction) {
SendRequest sendRequest = SendRequest.forTx(transaction);
sendRequest.changeAddress = getActiveFederationAddress();
Expand Down
19 changes: 15 additions & 4 deletions rskj-core/src/main/java/co/rsk/peg/BridgeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

import co.rsk.bitcoinj.core.*;
import co.rsk.bitcoinj.crypto.TransactionSignature;
import co.rsk.bitcoinj.script.RedeemScriptParser;
import co.rsk.bitcoinj.script.*;
import co.rsk.bitcoinj.script.RedeemScriptParser.MultiSigType;
import co.rsk.bitcoinj.script.RedeemScriptParserFactory;
import co.rsk.bitcoinj.script.Script;
import co.rsk.bitcoinj.script.ScriptChunk;
import co.rsk.bitcoinj.wallet.Wallet;
import co.rsk.crypto.Keccak256;
import co.rsk.peg.bitcoin.FlyoverRedeemScriptBuilder;
import co.rsk.peg.bitcoin.FlyoverRedeemScriptBuilderImpl;
import co.rsk.peg.constants.BridgeConstants;
import co.rsk.core.RskAddress;
import co.rsk.peg.bitcoin.RskAllowUnconfirmedCoinSelector;
Expand Down Expand Up @@ -251,6 +251,17 @@ private static Coin getAmountSentToWallet(BtcTransaction btcTx, Wallet wallet) {
return btcTx.getValueSentToMe(wallet);
}

public static Address getFlyoverAddress(NetworkParameters networkParameters, Keccak256 flyoverDerivationHash, Script redeemScript) {
Script flyoverScriptPubKey = getFlyoverScriptPubKey(flyoverDerivationHash, redeemScript);
return Address.fromP2SHScript(networkParameters, flyoverScriptPubKey);
}

public static Script getFlyoverScriptPubKey(Keccak256 flyoverDerivationHash, Script redeemScript) {
FlyoverRedeemScriptBuilder flyoverRedeemScriptBuilder = new FlyoverRedeemScriptBuilderImpl();
Script flyoverRedeemScript = flyoverRedeemScriptBuilder.addFlyoverDerivationHashToRedeemScript(flyoverDerivationHash, redeemScript);
return ScriptBuilder.createP2SHOutputScript(flyoverRedeemScript);
}

public static List<UTXO> getUTXOsSentToAddresses(
ActivationConfig.ForBlock activations,
NetworkParameters networkParameters,
Expand Down
5 changes: 2 additions & 3 deletions rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,8 @@ private void assertOneOutputIsToProposedFederationWithExpectedAmount(List<Transa
}

private void assertOneOutputIsToProposedFederationWithFlyoverPrefixWithExpectedAmount(List<TransactionOutput> svpFundTransactionUnsignedOutputs) {
FlyoverRedeemScriptBuilder flyoverRedeemScriptBuilder = new FlyoverRedeemScriptBuilderImpl();
Script redeemScriptWithFlyoverPrefix = flyoverRedeemScriptBuilder.addFlyoverDerivationHashToRedeemScript(bridgeMainNetConstants.getProposedFederationFlyoverPrefix(), proposedFederation.getRedeemScript());
Script proposedFederationWithFlyoverPrefixScriptPubKey = ScriptBuilder.createP2SHOutputScript(redeemScriptWithFlyoverPrefix);
Script proposedFederationWithFlyoverPrefixScriptPubKey =
BridgeUtils.getFlyoverScriptPubKey(bridgeMainNetConstants.getProposedFederationFlyoverPrefix(), proposedFederation.getRedeemScript());

Optional<TransactionOutput> outputToProposedFederationWithFlyoverPrefixOpt = searchForOutput(svpFundTransactionUnsignedOutputs, proposedFederationWithFlyoverPrefixScriptPubKey);
assertTrue(outputToProposedFederationWithFlyoverPrefixOpt.isPresent());
Expand Down
Loading