mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-07-31 20:11:23 +00:00
Script: Deprecate the script data extraction methods for CLTV payment channels.
Create and make sure to only use equivalents in ScriptPattern.
This commit is contained in:
@@ -257,35 +257,25 @@ public class Script {
|
|||||||
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Script not in the standard scriptPubKey form");
|
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Script not in the standard scriptPubKey form");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Deprecated
|
||||||
* Retrieves the sender public key from a LOCKTIMEVERIFY transaction
|
|
||||||
* @return the sender public key
|
|
||||||
* @throws ScriptException
|
|
||||||
*/
|
|
||||||
public byte[] getCLTVPaymentChannelSenderPubKey() throws ScriptException {
|
public byte[] getCLTVPaymentChannelSenderPubKey() throws ScriptException {
|
||||||
if (!ScriptPattern.isSentToCltvPaymentChannel(this)) {
|
if (!ScriptPattern.isSentToCltvPaymentChannel(this))
|
||||||
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Script not a standard CHECKLOCKTIMVERIFY transaction: " + this);
|
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Script not a standard CHECKLOCKTIMVERIFY transaction: " + this);
|
||||||
}
|
return ScriptPattern.extractSenderPubKeyFromCltvPaymentChannel(this);
|
||||||
return chunks.get(8).data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Deprecated
|
||||||
* Retrieves the recipient public key from a LOCKTIMEVERIFY transaction
|
|
||||||
* @return the recipient public key
|
|
||||||
* @throws ScriptException
|
|
||||||
*/
|
|
||||||
public byte[] getCLTVPaymentChannelRecipientPubKey() throws ScriptException {
|
public byte[] getCLTVPaymentChannelRecipientPubKey() throws ScriptException {
|
||||||
if (!ScriptPattern.isSentToCltvPaymentChannel(this)) {
|
if (!ScriptPattern.isSentToCltvPaymentChannel(this))
|
||||||
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Script not a standard CHECKLOCKTIMVERIFY transaction: " + this);
|
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Script not a standard CHECKLOCKTIMVERIFY transaction: " + this);
|
||||||
}
|
return ScriptPattern.extractRecipientPubKeyFromCltvPaymentChannel(this);
|
||||||
return chunks.get(1).data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigInteger getCLTVPaymentChannelExpiry() {
|
@Deprecated
|
||||||
if (!ScriptPattern.isSentToCltvPaymentChannel(this)) {
|
public BigInteger getCLTVPaymentChannelExpiry() throws ScriptException {
|
||||||
|
if (!ScriptPattern.isSentToCltvPaymentChannel(this))
|
||||||
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Script not a standard CHECKLOCKTIMEVERIFY transaction: " + this);
|
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Script not a standard CHECKLOCKTIMEVERIFY transaction: " + this);
|
||||||
}
|
return ScriptPattern.extractExpiryFromCltvPaymentChannel(this);
|
||||||
return castToBigInteger(chunks.get(4).data, 5, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -709,7 +699,7 @@ public class Script {
|
|||||||
* @param requireMinimal check if the number is encoded with the minimum possible number of bytes
|
* @param requireMinimal check if the number is encoded with the minimum possible number of bytes
|
||||||
* @throws ScriptException if the chunk is longer than the specified maximum.
|
* @throws ScriptException if the chunk is longer than the specified maximum.
|
||||||
*/
|
*/
|
||||||
private static BigInteger castToBigInteger(final byte[] chunk, final int maxLength, final boolean requireMinimal) throws ScriptException {
|
/* package private */ static BigInteger castToBigInteger(final byte[] chunk, final int maxLength, final boolean requireMinimal) throws ScriptException {
|
||||||
if (chunk.length > maxLength)
|
if (chunk.length > maxLength)
|
||||||
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Script attempted to use an integer larger than " + maxLength + " bytes");
|
throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Script attempted to use an integer larger than " + maxLength + " bytes");
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@ package org.bitcoinj.script;
|
|||||||
|
|
||||||
import org.bitcoinj.core.Address;
|
import org.bitcoinj.core.Address;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.bitcoinj.script.Script.decodeFromOpN;
|
import static org.bitcoinj.script.Script.decodeFromOpN;
|
||||||
@@ -136,6 +137,27 @@ public class ScriptPattern {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the public key of the sender from a LOCKTIMEVERIFY transaction.
|
||||||
|
*/
|
||||||
|
public static byte[] extractSenderPubKeyFromCltvPaymentChannel(Script script) {
|
||||||
|
return script.chunks.get(8).data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the public key of the recipient from a LOCKTIMEVERIFY transaction.
|
||||||
|
*/
|
||||||
|
public static byte[] extractRecipientPubKeyFromCltvPaymentChannel(Script script) {
|
||||||
|
return script.chunks.get(1).data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the locktime from a LOCKTIMEVERIFY transaction.
|
||||||
|
*/
|
||||||
|
public static BigInteger extractExpiryFromCltvPaymentChannel(Script script) {
|
||||||
|
return Script.castToBigInteger(script.chunks.get(4).data, 5, false);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isOpReturn(Script script) {
|
public static boolean isOpReturn(Script script) {
|
||||||
List<ScriptChunk> chunks = script.chunks;
|
List<ScriptChunk> chunks = script.chunks;
|
||||||
return chunks.size() > 0 && chunks.get(0).equalsOpCode(ScriptOpCodes.OP_RETURN);
|
return chunks.size() > 0 && chunks.get(0).equalsOpCode(ScriptOpCodes.OP_RETURN);
|
||||||
|
@@ -4205,12 +4205,12 @@ public class Wallet extends BaseTaggableObject
|
|||||||
}
|
}
|
||||||
} else if (ScriptPattern.isSentToCltvPaymentChannel(script)) {
|
} else if (ScriptPattern.isSentToCltvPaymentChannel(script)) {
|
||||||
// Any script for which we are the recipient or sender counts.
|
// Any script for which we are the recipient or sender counts.
|
||||||
byte[] sender = script.getCLTVPaymentChannelSenderPubKey();
|
byte[] sender = ScriptPattern.extractSenderPubKeyFromCltvPaymentChannel(script);
|
||||||
ECKey senderKey = findKeyFromPubKey(sender);
|
ECKey senderKey = findKeyFromPubKey(sender);
|
||||||
if (senderKey != null && (senderKey.isEncrypted() || senderKey.hasPrivKey())) {
|
if (senderKey != null && (senderKey.isEncrypted() || senderKey.hasPrivKey())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
byte[] recipient = script.getCLTVPaymentChannelRecipientPubKey();
|
byte[] recipient = ScriptPattern.extractRecipientPubKeyFromCltvPaymentChannel(script);
|
||||||
ECKey recipientKey = findKeyFromPubKey(sender);
|
ECKey recipientKey = findKeyFromPubKey(sender);
|
||||||
if (recipientKey != null && (recipientKey.isEncrypted() || recipientKey.hasPrivKey())) {
|
if (recipientKey != null && (recipientKey.isEncrypted() || recipientKey.hasPrivKey())) {
|
||||||
return true;
|
return true;
|
||||||
|
@@ -855,9 +855,9 @@ public class WalletTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ECKey key1 = wallet.findKeyFromPubKey(
|
ECKey key1 = wallet.findKeyFromPubKey(
|
||||||
lockTimeVerifyOutput.getScriptPubKey().getCLTVPaymentChannelSenderPubKey());
|
ScriptPattern.extractSenderPubKeyFromCltvPaymentChannel(lockTimeVerifyOutput.getScriptPubKey()));
|
||||||
ECKey key2 = wallet.findKeyFromPubKey(
|
ECKey key2 = wallet.findKeyFromPubKey(
|
||||||
lockTimeVerifyOutput.getScriptPubKey().getCLTVPaymentChannelRecipientPubKey());
|
ScriptPattern.extractRecipientPubKeyFromCltvPaymentChannel(lockTimeVerifyOutput.getScriptPubKey()));
|
||||||
if (key1 == null || key2 == null) {
|
if (key1 == null || key2 == null) {
|
||||||
System.err.println("Don't own private keys for both pubkeys");
|
System.err.println("Don't own private keys for both pubkeys");
|
||||||
return;
|
return;
|
||||||
@@ -945,7 +945,7 @@ public class WalletTool {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
req.tx.setLockTime(lockTimeVerifyOutput.getScriptPubKey().getCLTVPaymentChannelExpiry().longValue());
|
req.tx.setLockTime(ScriptPattern.extractExpiryFromCltvPaymentChannel(lockTimeVerifyOutput.getScriptPubKey()).longValue());
|
||||||
|
|
||||||
if (!value.equals(lockTimeVerifyOutput.getValue())) {
|
if (!value.equals(lockTimeVerifyOutput.getValue())) {
|
||||||
System.err.println("You must spend all the money in the input transaction");
|
System.err.println("You must spend all the money in the input transaction");
|
||||||
@@ -961,7 +961,7 @@ public class WalletTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ECKey key = wallet.findKeyFromPubKey(
|
ECKey key = wallet.findKeyFromPubKey(
|
||||||
lockTimeVerifyOutput.getScriptPubKey().getCLTVPaymentChannelSenderPubKey());
|
ScriptPattern.extractSenderPubKeyFromCltvPaymentChannel(lockTimeVerifyOutput.getScriptPubKey()));
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
System.err.println("Don't own private key for pubkey");
|
System.err.println("Don't own private key for pubkey");
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user