-
Notifications
You must be signed in to change notification settings - Fork 267
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
Create a flyover redeem script builder #2727
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8e0604a
Create flyover redeem script builder
julia-zack 0e71532
Delete FlyoverRedeemScriptCreationException and move flyover reason t…
julia-zack e90a050
Change call to P2shErpFederationBuilder
marcos-iov 2be66e4
Add @Override annotation
marcos-iov 7719ed1
Refactor redeem script builders to use 'of' method name
marcos-iov 08b28eb
Add a static 'builder' method to the redeem sript builders
marcos-iov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
rskj-core/src/main/java/co/rsk/peg/bitcoin/FlyoverRedeemScriptBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package co.rsk.peg.bitcoin; | ||
|
||
import co.rsk.bitcoinj.script.Script; | ||
import co.rsk.crypto.Keccak256; | ||
|
||
public interface FlyoverRedeemScriptBuilder { | ||
Script of(Keccak256 flyoverDerivationHash, Script redeemScript); | ||
} |
43 changes: 43 additions & 0 deletions
43
rskj-core/src/main/java/co/rsk/peg/bitcoin/FlyoverRedeemScriptBuilderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package co.rsk.peg.bitcoin; | ||
|
||
import static co.rsk.peg.bitcoin.RedeemScriptCreationException.Reason.INVALID_FLYOVER_DERIVATION_HASH; | ||
import static java.util.Objects.isNull; | ||
|
||
import co.rsk.bitcoinj.script.Script; | ||
import co.rsk.bitcoinj.script.ScriptBuilder; | ||
import co.rsk.bitcoinj.script.ScriptOpCodes; | ||
import co.rsk.crypto.Keccak256; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class FlyoverRedeemScriptBuilderImpl implements FlyoverRedeemScriptBuilder { | ||
private static final Logger logger = LoggerFactory.getLogger(FlyoverRedeemScriptBuilderImpl.class); | ||
|
||
private FlyoverRedeemScriptBuilderImpl() {} | ||
|
||
public static FlyoverRedeemScriptBuilderImpl builder() { | ||
return new FlyoverRedeemScriptBuilderImpl(); | ||
} | ||
|
||
@Override | ||
public Script of(Keccak256 flyoverDerivationHash, Script redeemScript) { | ||
validateFlyoverDerivationHash(flyoverDerivationHash); | ||
|
||
ScriptBuilder scriptBuilder = new ScriptBuilder(); | ||
byte[] flyoverDerivationHashSerialized = flyoverDerivationHash.getBytes(); | ||
|
||
return scriptBuilder | ||
.data(flyoverDerivationHashSerialized) | ||
.op(ScriptOpCodes.OP_DROP) | ||
.addChunks(redeemScript.getChunks()) | ||
.build(); | ||
} | ||
|
||
private void validateFlyoverDerivationHash(Keccak256 flyoverDerivationHash) { | ||
if (isNull(flyoverDerivationHash) || flyoverDerivationHash.equals(Keccak256.ZERO_HASH)) { | ||
String message = String.format("Provided flyover derivation hash %s is invalid.", flyoverDerivationHash); | ||
logger.warn("[validateFlyoverDerivationHash] {}", message); | ||
throw new RedeemScriptCreationException(message, INVALID_FLYOVER_DERIVATION_HASH); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why merge it into the
master
branch instead of the integration branch,wip/fed-scripts-refactors-integration
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes it easier to integrate all the changes we are working on in different branches