Skip to content

Commit

Permalink
Merge pull request #66 from rsksmart/add_reedem_with_flyover
Browse files Browse the repository at this point in the history
Add reedem with flyover
  • Loading branch information
marcos-iov authored Aug 11, 2023
2 parents c94b9e6 + 25f6d80 commit a70f5ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.rsk.bitcoinj.script;

import co.rsk.bitcoinj.core.Sha256Hash;
import co.rsk.bitcoinj.core.Utils;
import co.rsk.bitcoinj.core.VerificationException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -106,6 +107,32 @@ public static Script createP2shP2wshErpRedeemScript(
return erpP2shP2wshRedeemScript;
}

public static Script createP2shP2wshErpRedeemScriptWithFlyover(
Script defaultFederationRedeemScript,
Script erpFederationRedeemScript,
Sha256Hash derivationPath,
Long csvValue
) {
byte[] serializedCsvValue = Utils.signedLongToByteArrayLE(csvValue);

ScriptBuilder scriptBuilder = new ScriptBuilder();

Script erpP2shP2wshRedeemScript = scriptBuilder
.data(derivationPath.getBytes())
.op(ScriptOpCodes.OP_DROP)
.op(ScriptOpCodes.OP_NOTIF)
.addChunks(defaultFederationRedeemScript.getChunks())
.op(ScriptOpCodes.OP_ELSE)
.data(serializedCsvValue)
.op(ScriptOpCodes.OP_CHECKSEQUENCEVERIFY)
.op(ScriptOpCodes.OP_DROP)
.addChunks(erpFederationRedeemScript.getChunks())
.op(ScriptOpCodes.OP_ENDIF)
.build();

return erpP2shP2wshRedeemScript;
}

public static boolean isP2shErpFed(List<ScriptChunk> chunks) {
return RedeemScriptValidator.hasP2shErpRedeemScriptStructure(chunks);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/co/rsk/bitcoinj/script/ScriptBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,13 @@ public static Script createInputScript(@Nullable TransactionSignature signature)
public static Script createMultiSigOutputScript(int threshold, List<BtcECKey> pubkeys) {
checkArgument(threshold > 0);
checkArgument(threshold <= pubkeys.size());
checkArgument(pubkeys.size() <= 16); // That's the max we can represent with a single opcode.
// checkArgument(pubkeys.size() <= 16); // That's the max we can represent with a single opcode.
ScriptBuilder builder = new ScriptBuilder();
builder.smallNum(threshold);
builder.number(threshold);
for (BtcECKey key : pubkeys) {
builder.data(key.getPubKey());
}
builder.smallNum(pubkeys.size());
builder.number(pubkeys.size());
builder.op(OP_CHECKMULTISIG);
return builder.build();
}
Expand Down

0 comments on commit a70f5ee

Please sign in to comment.