diff --git a/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java b/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java index 6fc152e6..6670ff38 100644 --- a/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java +++ b/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java @@ -17,7 +17,6 @@ package com.google.bitcoin.core; import com.google.common.base.Objects; -import com.google.common.collect.Lists; import org.spongycastle.util.encoders.Hex; import java.io.ByteArrayOutputStream; @@ -261,7 +260,7 @@ public class NetworkParameters implements Serializable { ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream(); Script.writeBytes(scriptPubKeyBytes, Hex.decode ("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")); - scriptPubKeyBytes.write(Script.OP_CHECKSIG); + scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG); t.addOutput(new TransactionOutput(n, t, Utils.toNanoCoins(50, 0), scriptPubKeyBytes.toByteArray())); } catch (Exception e) { // Cannot happen. diff --git a/core/src/main/java/com/google/bitcoin/core/Script.java b/core/src/main/java/com/google/bitcoin/core/Script.java index 02926117..1603fce3 100644 --- a/core/src/main/java/com/google/bitcoin/core/Script.java +++ b/core/src/main/java/com/google/bitcoin/core/Script.java @@ -29,6 +29,7 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.*; +import static com.google.bitcoin.core.ScriptOpCodes.*; import static com.google.bitcoin.core.Utils.bytesToHexString; import static com.google.common.base.Preconditions.checkArgument; @@ -65,141 +66,6 @@ class ScriptChunk { public class Script { private static final Logger log = LoggerFactory.getLogger(Script.class); - // Some constants used for decoding the scripts, copied from the reference client - // push value - public static final int OP_0 = 0x00; - public static final int OP_FALSE = OP_0; - public static final int OP_PUSHDATA1 = 0x4c; - public static final int OP_PUSHDATA2 = 0x4d; - public static final int OP_PUSHDATA4 = 0x4e; - public static final int OP_1NEGATE = 0x4f; - public static final int OP_RESERVED = 0x50; - public static final int OP_1 = 0x51; - public static final int OP_TRUE=OP_1; - public static final int OP_2 = 0x52; - public static final int OP_3 = 0x53; - public static final int OP_4 = 0x54; - public static final int OP_5 = 0x55; - public static final int OP_6 = 0x56; - public static final int OP_7 = 0x57; - public static final int OP_8 = 0x58; - public static final int OP_9 = 0x59; - public static final int OP_10 = 0x5a; - public static final int OP_11 = 0x5b; - public static final int OP_12 = 0x5c; - public static final int OP_13 = 0x5d; - public static final int OP_14 = 0x5e; - public static final int OP_15 = 0x5f; - public static final int OP_16 = 0x60; - - // control - public static final int OP_NOP = 0x61; - public static final int OP_VER = 0x62; - public static final int OP_IF = 0x63; - public static final int OP_NOTIF = 0x64; - public static final int OP_VERIF = 0x65; - public static final int OP_VERNOTIF = 0x66; - public static final int OP_ELSE = 0x67; - public static final int OP_ENDIF = 0x68; - public static final int OP_VERIFY = 0x69; - public static final int OP_RETURN = 0x6a; - - // stack ops - public static final int OP_TOALTSTACK = 0x6b; - public static final int OP_FROMALTSTACK = 0x6c; - public static final int OP_2DROP = 0x6d; - public static final int OP_2DUP = 0x6e; - public static final int OP_3DUP = 0x6f; - public static final int OP_2OVER = 0x70; - public static final int OP_2ROT = 0x71; - public static final int OP_2SWAP = 0x72; - public static final int OP_IFDUP = 0x73; - public static final int OP_DEPTH = 0x74; - public static final int OP_DROP = 0x75; - public static final int OP_DUP = 0x76; - public static final int OP_NIP = 0x77; - public static final int OP_OVER = 0x78; - public static final int OP_PICK = 0x79; - public static final int OP_ROLL = 0x7a; - public static final int OP_ROT = 0x7b; - public static final int OP_SWAP = 0x7c; - public static final int OP_TUCK = 0x7d; - - // splice ops - public static final int OP_CAT = 0x7e; - public static final int OP_SUBSTR = 0x7f; - public static final int OP_LEFT = 0x80; - public static final int OP_RIGHT = 0x81; - public static final int OP_SIZE = 0x82; - - // bit logic - public static final int OP_INVERT = 0x83; - public static final int OP_AND = 0x84; - public static final int OP_OR = 0x85; - public static final int OP_XOR = 0x86; - public static final int OP_EQUAL = 0x87; - public static final int OP_EQUALVERIFY = 0x88; - public static final int OP_RESERVED1 = 0x89; - public static final int OP_RESERVED2 = 0x8a; - - // numeric - public static final int OP_1ADD = 0x8b; - public static final int OP_1SUB = 0x8c; - public static final int OP_2MUL = 0x8d; - public static final int OP_2DIV = 0x8e; - public static final int OP_NEGATE = 0x8f; - public static final int OP_ABS = 0x90; - public static final int OP_NOT = 0x91; - public static final int OP_0NOTEQUAL = 0x92; - - public static final int OP_ADD = 0x93; - public static final int OP_SUB = 0x94; - public static final int OP_MUL = 0x95; - public static final int OP_DIV = 0x96; - public static final int OP_MOD = 0x97; - public static final int OP_LSHIFT = 0x98; - public static final int OP_RSHIFT = 0x99; - - public static final int OP_BOOLAND = 0x9a; - public static final int OP_BOOLOR = 0x9b; - public static final int OP_NUMEQUAL = 0x9c; - public static final int OP_NUMEQUALVERIFY = 0x9d; - public static final int OP_NUMNOTEQUAL = 0x9e; - public static final int OP_LESSTHAN = 0x9f; - public static final int OP_GREATERTHAN = 0xa0; - public static final int OP_LESSTHANOREQUAL = 0xa1; - public static final int OP_GREATERTHANOREQUAL = 0xa2; - public static final int OP_MIN = 0xa3; - public static final int OP_MAX = 0xa4; - - public static final int OP_WITHIN = 0xa5; - - // crypto - public static final int OP_RIPEMD160 = 0xa6; - public static final int OP_SHA1 = 0xa7; - public static final int OP_SHA256 = 0xa8; - public static final int OP_HASH160 = 0xa9; - public static final int OP_HASH256 = 0xaa; - public static final int OP_CODESEPARATOR = 0xab; - public static final int OP_CHECKSIG = 0xac; - public static final int OP_CHECKSIGVERIFY = 0xad; - public static final int OP_CHECKMULTISIG = 0xae; - public static final int OP_CHECKMULTISIGVERIFY = 0xaf; - - // expansion - public static final int OP_NOP1 = 0xb0; - public static final int OP_NOP2 = 0xb1; - public static final int OP_NOP3 = 0xb2; - public static final int OP_NOP4 = 0xb3; - public static final int OP_NOP5 = 0xb4; - public static final int OP_NOP6 = 0xb5; - public static final int OP_NOP7 = 0xb6; - public static final int OP_NOP8 = 0xb7; - public static final int OP_NOP9 = 0xb8; - public static final int OP_NOP10 = 0xb9; - - public static final int OP_INVALIDOPCODE = 0xff; - private byte[] program; private int cursor; @@ -241,239 +107,6 @@ public class Script { public byte[] getProgram() { return Arrays.copyOf(program, program.length); } - - /** - * Converts the given OpCode into a string (eg "0", "PUSHDATA", or "NON_OP(10)") - */ - public static String getOpCodeName(byte opCode) { - int opcode = opCode & 0xff; - switch (opcode) { - case OP_0: - return "0"; - case OP_PUSHDATA1: - return "PUSHDATA1"; - case OP_PUSHDATA2: - return "PUSHDATA1"; - case OP_PUSHDATA4: - return "PUSHDATA4"; - case OP_1NEGATE: - return "1NEGATE"; - case OP_RESERVED: - return "RESERVED"; - case OP_1: - return "1"; - case OP_2: - return "2"; - case OP_3: - return "3"; - case OP_4: - return "4"; - case OP_5: - return "5"; - case OP_6: - return "6"; - case OP_7: - return "7"; - case OP_8: - return "8"; - case OP_9: - return "9"; - case OP_10: - return "10"; - case OP_11: - return "11"; - case OP_12: - return "12"; - case OP_13: - return "13"; - case OP_14: - return "14"; - case OP_15: - return "15"; - case OP_16: - return "16"; - case OP_NOP: - return "NOP"; - case OP_VER: - return "VER"; - case OP_IF: - return "IF"; - case OP_NOTIF: - return "NOTIF"; - case OP_VERIF: - return "VERIF"; - case OP_VERNOTIF: - return "VERNOTIF"; - case OP_ELSE: - return "ELSE"; - case OP_ENDIF: - return "ENDIF"; - case OP_VERIFY: - return "VERIFY"; - case OP_RETURN: - return "RETURN"; - case OP_TOALTSTACK: - return "TOALTSTACK"; - case OP_FROMALTSTACK: - return "FROMALTSTACK"; - case OP_2DROP: - return "2DROP"; - case OP_2DUP: - return "2DUP"; - case OP_3DUP: - return "3DUP"; - case OP_2OVER: - return "2OVER"; - case OP_2ROT: - return "2ROT"; - case OP_2SWAP: - return "2SWAP"; - case OP_IFDUP: - return "IFDUP"; - case OP_DEPTH: - return "DEPTH"; - case OP_DROP: - return "DROP"; - case OP_DUP: - return "DUP"; - case OP_NIP: - return "NIP"; - case OP_OVER: - return "OVER"; - case OP_PICK: - return "PICK"; - case OP_ROLL: - return "ROLL"; - case OP_ROT: - return "ROT"; - case OP_SWAP: - return "SWAP"; - case OP_TUCK: - return "TUCK"; - case OP_CAT: - return "CAT"; - case OP_SUBSTR: - return "SUBSTR"; - case OP_LEFT: - return "LEFT"; - case OP_RIGHT: - return "RIGHT"; - case OP_SIZE: - return "SIZE"; - case OP_INVERT: - return "INVERT"; - case OP_AND: - return "AND"; - case OP_OR: - return "OR"; - case OP_XOR: - return "XOR"; - case OP_EQUAL: - return "EQUAL"; - case OP_EQUALVERIFY: - return "EQUALVERIFY"; - case OP_RESERVED1: - return "RESERVED1"; - case OP_RESERVED2: - return "RESERVED2"; - case OP_1ADD: - return "1ADD"; - case OP_1SUB: - return "1SUB"; - case OP_2MUL: - return "2MUL"; - case OP_2DIV: - return "2DIV"; - case OP_NEGATE: - return "NEGATE"; - case OP_ABS: - return "ABS"; - case OP_NOT: - return "NOT"; - case OP_0NOTEQUAL: - return "0NOTEQUAL"; - case OP_ADD: - return "ADD"; - case OP_SUB: - return "SUB"; - case OP_MUL: - return "MUL"; - case OP_DIV: - return "DIV"; - case OP_MOD: - return "MOD"; - case OP_LSHIFT: - return "LSHIFT"; - case OP_RSHIFT: - return "RSHIFT"; - case OP_BOOLAND: - return "BOOLAND"; - case OP_BOOLOR: - return "BOOLOR"; - case OP_NUMEQUAL: - return "NUMEQUAL"; - case OP_NUMEQUALVERIFY: - return "NUMEQUALVERIFY"; - case OP_NUMNOTEQUAL: - return "NUMNOTEQUAL"; - case OP_LESSTHAN: - return "LESSTHAN"; - case OP_GREATERTHAN: - return "GREATERTHAN"; - case OP_LESSTHANOREQUAL: - return "LESSTHANOREQUAL"; - case OP_GREATERTHANOREQUAL: - return "GREATERTHANOREQUAL"; - case OP_MIN: - return "MIN"; - case OP_MAX: - return "MAX"; - case OP_WITHIN: - return "WITHIN"; - case OP_RIPEMD160: - return "RIPEMD160"; - case OP_SHA1: - return "SHA1"; - case OP_SHA256: - return "SHA256"; - case OP_HASH160: - return "HASH160"; - case OP_HASH256: - return "HASH256"; - case OP_CODESEPARATOR: - return "CODESEPARATOR"; - case OP_CHECKSIG: - return "CHECKSIG"; - case OP_CHECKSIGVERIFY: - return "CHECKSIGVERIFY"; - case OP_CHECKMULTISIG: - return "CHECKMULTISIG"; - case OP_CHECKMULTISIGVERIFY: - return "CHECKMULTISIGVERIFY"; - case OP_NOP1: - return "NOP1"; - case OP_NOP2: - return "NOP2"; - case OP_NOP3: - return "NOP3"; - case OP_NOP4: - return "NOP4"; - case OP_NOP5: - return "NOP5"; - case OP_NOP6: - return "NOP6"; - case OP_NOP7: - return "NOP7"; - case OP_NOP8: - return "NOP8"; - case OP_NOP9: - return "NOP9"; - case OP_NOP10: - return "NOP10"; - default: - return "NON_OP(" + opcode + ")"; - } - } private byte[] getData(int len) throws ScriptException { diff --git a/core/src/main/java/com/google/bitcoin/core/ScriptOpCodes.java b/core/src/main/java/com/google/bitcoin/core/ScriptOpCodes.java new file mode 100644 index 00000000..99d767e7 --- /dev/null +++ b/core/src/main/java/com/google/bitcoin/core/ScriptOpCodes.java @@ -0,0 +1,386 @@ +/* + * Copyright 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.bitcoin.core; + +/** + * Various constants that define the assembly-like scripting language that forms part of the Bitcoin protocol. + * See {@link Script} for details. Also provides a method to convert them to a string. + */ +public class ScriptOpCodes { + // push value + public static final int OP_0 = 0x00; + public static final int OP_FALSE = OP_0; + public static final int OP_PUSHDATA1 = 0x4c; + public static final int OP_PUSHDATA2 = 0x4d; + public static final int OP_PUSHDATA4 = 0x4e; + public static final int OP_1NEGATE = 0x4f; + public static final int OP_RESERVED = 0x50; + public static final int OP_1 = 0x51; + public static final int OP_TRUE = OP_1; + public static final int OP_2 = 0x52; + public static final int OP_3 = 0x53; + public static final int OP_4 = 0x54; + public static final int OP_5 = 0x55; + public static final int OP_6 = 0x56; + public static final int OP_7 = 0x57; + public static final int OP_8 = 0x58; + public static final int OP_9 = 0x59; + public static final int OP_10 = 0x5a; + public static final int OP_11 = 0x5b; + public static final int OP_12 = 0x5c; + public static final int OP_13 = 0x5d; + public static final int OP_14 = 0x5e; + public static final int OP_15 = 0x5f; + public static final int OP_16 = 0x60; + + // control + public static final int OP_NOP = 0x61; + public static final int OP_VER = 0x62; + public static final int OP_IF = 0x63; + public static final int OP_NOTIF = 0x64; + public static final int OP_VERIF = 0x65; + public static final int OP_VERNOTIF = 0x66; + public static final int OP_ELSE = 0x67; + public static final int OP_ENDIF = 0x68; + public static final int OP_VERIFY = 0x69; + public static final int OP_RETURN = 0x6a; + + // stack ops + public static final int OP_TOALTSTACK = 0x6b; + public static final int OP_FROMALTSTACK = 0x6c; + public static final int OP_2DROP = 0x6d; + public static final int OP_2DUP = 0x6e; + public static final int OP_3DUP = 0x6f; + public static final int OP_2OVER = 0x70; + public static final int OP_2ROT = 0x71; + public static final int OP_2SWAP = 0x72; + public static final int OP_IFDUP = 0x73; + public static final int OP_DEPTH = 0x74; + public static final int OP_DROP = 0x75; + public static final int OP_DUP = 0x76; + public static final int OP_NIP = 0x77; + public static final int OP_OVER = 0x78; + public static final int OP_PICK = 0x79; + public static final int OP_ROLL = 0x7a; + public static final int OP_ROT = 0x7b; + public static final int OP_SWAP = 0x7c; + public static final int OP_TUCK = 0x7d; + + // splice ops + public static final int OP_CAT = 0x7e; + public static final int OP_SUBSTR = 0x7f; + public static final int OP_LEFT = 0x80; + public static final int OP_RIGHT = 0x81; + public static final int OP_SIZE = 0x82; + + // bit logic + public static final int OP_INVERT = 0x83; + public static final int OP_AND = 0x84; + public static final int OP_OR = 0x85; + public static final int OP_XOR = 0x86; + public static final int OP_EQUAL = 0x87; + public static final int OP_EQUALVERIFY = 0x88; + public static final int OP_RESERVED1 = 0x89; + public static final int OP_RESERVED2 = 0x8a; + + // numeric + public static final int OP_1ADD = 0x8b; + public static final int OP_1SUB = 0x8c; + public static final int OP_2MUL = 0x8d; + public static final int OP_2DIV = 0x8e; + public static final int OP_NEGATE = 0x8f; + public static final int OP_ABS = 0x90; + public static final int OP_NOT = 0x91; + public static final int OP_0NOTEQUAL = 0x92; + public static final int OP_ADD = 0x93; + public static final int OP_SUB = 0x94; + public static final int OP_MUL = 0x95; + public static final int OP_DIV = 0x96; + public static final int OP_MOD = 0x97; + public static final int OP_LSHIFT = 0x98; + public static final int OP_RSHIFT = 0x99; + public static final int OP_BOOLAND = 0x9a; + public static final int OP_BOOLOR = 0x9b; + public static final int OP_NUMEQUAL = 0x9c; + public static final int OP_NUMEQUALVERIFY = 0x9d; + public static final int OP_NUMNOTEQUAL = 0x9e; + public static final int OP_LESSTHAN = 0x9f; + public static final int OP_GREATERTHAN = 0xa0; + public static final int OP_LESSTHANOREQUAL = 0xa1; + public static final int OP_GREATERTHANOREQUAL = 0xa2; + public static final int OP_MIN = 0xa3; + public static final int OP_MAX = 0xa4; + public static final int OP_WITHIN = 0xa5; + + // crypto + public static final int OP_RIPEMD160 = 0xa6; + public static final int OP_SHA1 = 0xa7; + public static final int OP_SHA256 = 0xa8; + public static final int OP_HASH160 = 0xa9; + public static final int OP_HASH256 = 0xaa; + public static final int OP_CODESEPARATOR = 0xab; + public static final int OP_CHECKSIG = 0xac; + public static final int OP_CHECKSIGVERIFY = 0xad; + public static final int OP_CHECKMULTISIG = 0xae; + public static final int OP_CHECKMULTISIGVERIFY = 0xaf; + + // expansion + public static final int OP_NOP1 = 0xb0; + public static final int OP_NOP2 = 0xb1; + public static final int OP_NOP3 = 0xb2; + public static final int OP_NOP4 = 0xb3; + public static final int OP_NOP5 = 0xb4; + public static final int OP_NOP6 = 0xb5; + public static final int OP_NOP7 = 0xb6; + public static final int OP_NOP8 = 0xb7; + public static final int OP_NOP9 = 0xb8; + public static final int OP_NOP10 = 0xb9; + public static final int OP_INVALIDOPCODE = 0xff; + + /** + * Converts the given OpCode into a string (eg "0", "PUSHDATA", or "NON_OP(10)") + */ + public static String getOpCodeName(byte opCode) { + int opcode = opCode & 0xff; + switch (opcode) { + case OP_0: + return "0"; + case OP_PUSHDATA1: + return "PUSHDATA1"; + case OP_PUSHDATA2: + return "PUSHDATA1"; + case OP_PUSHDATA4: + return "PUSHDATA4"; + case OP_1NEGATE: + return "1NEGATE"; + case OP_RESERVED: + return "RESERVED"; + case OP_1: + return "1"; + case OP_2: + return "2"; + case OP_3: + return "3"; + case OP_4: + return "4"; + case OP_5: + return "5"; + case OP_6: + return "6"; + case OP_7: + return "7"; + case OP_8: + return "8"; + case OP_9: + return "9"; + case OP_10: + return "10"; + case OP_11: + return "11"; + case OP_12: + return "12"; + case OP_13: + return "13"; + case OP_14: + return "14"; + case OP_15: + return "15"; + case OP_16: + return "16"; + case OP_NOP: + return "NOP"; + case OP_VER: + return "VER"; + case OP_IF: + return "IF"; + case OP_NOTIF: + return "NOTIF"; + case OP_VERIF: + return "VERIF"; + case OP_VERNOTIF: + return "VERNOTIF"; + case OP_ELSE: + return "ELSE"; + case OP_ENDIF: + return "ENDIF"; + case OP_VERIFY: + return "VERIFY"; + case OP_RETURN: + return "RETURN"; + case OP_TOALTSTACK: + return "TOALTSTACK"; + case OP_FROMALTSTACK: + return "FROMALTSTACK"; + case OP_2DROP: + return "2DROP"; + case OP_2DUP: + return "2DUP"; + case OP_3DUP: + return "3DUP"; + case OP_2OVER: + return "2OVER"; + case OP_2ROT: + return "2ROT"; + case OP_2SWAP: + return "2SWAP"; + case OP_IFDUP: + return "IFDUP"; + case OP_DEPTH: + return "DEPTH"; + case OP_DROP: + return "DROP"; + case OP_DUP: + return "DUP"; + case OP_NIP: + return "NIP"; + case OP_OVER: + return "OVER"; + case OP_PICK: + return "PICK"; + case OP_ROLL: + return "ROLL"; + case OP_ROT: + return "ROT"; + case OP_SWAP: + return "SWAP"; + case OP_TUCK: + return "TUCK"; + case OP_CAT: + return "CAT"; + case OP_SUBSTR: + return "SUBSTR"; + case OP_LEFT: + return "LEFT"; + case OP_RIGHT: + return "RIGHT"; + case OP_SIZE: + return "SIZE"; + case OP_INVERT: + return "INVERT"; + case OP_AND: + return "AND"; + case OP_OR: + return "OR"; + case OP_XOR: + return "XOR"; + case OP_EQUAL: + return "EQUAL"; + case OP_EQUALVERIFY: + return "EQUALVERIFY"; + case OP_RESERVED1: + return "RESERVED1"; + case OP_RESERVED2: + return "RESERVED2"; + case OP_1ADD: + return "1ADD"; + case OP_1SUB: + return "1SUB"; + case OP_2MUL: + return "2MUL"; + case OP_2DIV: + return "2DIV"; + case OP_NEGATE: + return "NEGATE"; + case OP_ABS: + return "ABS"; + case OP_NOT: + return "NOT"; + case OP_0NOTEQUAL: + return "0NOTEQUAL"; + case OP_ADD: + return "ADD"; + case OP_SUB: + return "SUB"; + case OP_MUL: + return "MUL"; + case OP_DIV: + return "DIV"; + case OP_MOD: + return "MOD"; + case OP_LSHIFT: + return "LSHIFT"; + case OP_RSHIFT: + return "RSHIFT"; + case OP_BOOLAND: + return "BOOLAND"; + case OP_BOOLOR: + return "BOOLOR"; + case OP_NUMEQUAL: + return "NUMEQUAL"; + case OP_NUMEQUALVERIFY: + return "NUMEQUALVERIFY"; + case OP_NUMNOTEQUAL: + return "NUMNOTEQUAL"; + case OP_LESSTHAN: + return "LESSTHAN"; + case OP_GREATERTHAN: + return "GREATERTHAN"; + case OP_LESSTHANOREQUAL: + return "LESSTHANOREQUAL"; + case OP_GREATERTHANOREQUAL: + return "GREATERTHANOREQUAL"; + case OP_MIN: + return "MIN"; + case OP_MAX: + return "MAX"; + case OP_WITHIN: + return "WITHIN"; + case OP_RIPEMD160: + return "RIPEMD160"; + case OP_SHA1: + return "SHA1"; + case OP_SHA256: + return "SHA256"; + case OP_HASH160: + return "HASH160"; + case OP_HASH256: + return "HASH256"; + case OP_CODESEPARATOR: + return "CODESEPARATOR"; + case OP_CHECKSIG: + return "CHECKSIG"; + case OP_CHECKSIGVERIFY: + return "CHECKSIGVERIFY"; + case OP_CHECKMULTISIG: + return "CHECKMULTISIG"; + case OP_CHECKMULTISIGVERIFY: + return "CHECKMULTISIGVERIFY"; + case OP_NOP1: + return "NOP1"; + case OP_NOP2: + return "NOP2"; + case OP_NOP3: + return "NOP3"; + case OP_NOP4: + return "NOP4"; + case OP_NOP5: + return "NOP5"; + case OP_NOP6: + return "NOP6"; + case OP_NOP7: + return "NOP7"; + case OP_NOP8: + return "NOP8"; + case OP_NOP9: + return "NOP9"; + case OP_NOP10: + return "NOP10"; + default: + return "NON_OP(" + opcode + ")"; + } + } +} diff --git a/core/src/main/java/com/google/bitcoin/core/Transaction.java b/core/src/main/java/com/google/bitcoin/core/Transaction.java index 1d94bdf7..9b2d5f9c 100644 --- a/core/src/main/java/com/google/bitcoin/core/Transaction.java +++ b/core/src/main/java/com/google/bitcoin/core/Transaction.java @@ -843,7 +843,7 @@ public class Transaction extends ChildMessage implements Serializable { // OP_CODESEPARATOR instruction having no purpose as it was only meant to be used internally, not actually // ever put into scripts. Deleting OP_CODESEPARATOR is a step that should never be required but if we don't // do it, we could split off the main chain. - connectedScript = Script.removeAllInstancesOfOp(connectedScript, Script.OP_CODESEPARATOR); + connectedScript = Script.removeAllInstancesOfOp(connectedScript, ScriptOpCodes.OP_CODESEPARATOR); // Set the input to the script of its output. Satoshi does this but the step has no obvious purpose as // the signature covers the hash of the prevout transaction which obviously includes the output script @@ -934,7 +934,10 @@ public class Transaction extends ChildMessage implements Serializable { /** - * @return the lockTime + * Transactions can have an associated lock time, specified either as a block height or in seconds since the + * UNIX epoch. A transaction is not allowed to be confirmed by miners until the lock time is reached, and + * since Bitcoin 0.8+ a transaction that did not end its lock period (non final) is considered to be non + * standard and won't be relayed or included in the memory pool either. */ public long getLockTime() { maybeParse(); @@ -942,7 +945,10 @@ public class Transaction extends ChildMessage implements Serializable { } /** - * @param lockTime the lockTime to set + * Transactions can have an associated lock time, specified either as a block height or in seconds since the + * UNIX epoch. A transaction is not allowed to be confirmed by miners until the lock time is reached, and + * since Bitcoin 0.8+ a transaction that did not end its lock period (non final) is considered to be non + * standard and won't be relayed or included in the memory pool either. */ public void setLockTime(long lockTime) { unCache(); diff --git a/core/src/test/java/com/google/bitcoin/core/BlockTest.java b/core/src/test/java/com/google/bitcoin/core/BlockTest.java index c491f082..74b5d5af 100644 --- a/core/src/test/java/com/google/bitcoin/core/BlockTest.java +++ b/core/src/test/java/com/google/bitcoin/core/BlockTest.java @@ -160,9 +160,9 @@ public class BlockTest { // this is broken until the transaction has > 1 input + output (which is required anyway...) //assertTrue(tx.length == tx.bitcoinSerialize().length && tx.length == 8); byte[] outputScript = new byte[10]; - Arrays.fill(outputScript, (byte)Script.OP_FALSE); + Arrays.fill(outputScript, (byte) ScriptOpCodes.OP_FALSE); tx.addOutput(new TransactionOutput(params, null, BigInteger.valueOf(1), outputScript)); - tx.addInput(new TransactionInput(params, null, new byte[] {(byte)Script.OP_FALSE}, + tx.addInput(new TransactionInput(params, null, new byte[] {(byte) ScriptOpCodes.OP_FALSE}, new TransactionOutPoint(params, 0, Sha256Hash.create(new byte[] {1})))); int origTxLength = 8 + 2 + 8 + 1 + 10 + 40 + 1 + 1; assertEquals(tx.bitcoinSerialize().length, tx.length); @@ -170,14 +170,14 @@ public class BlockTest { block.addTransaction(tx); assertEquals(block.bitcoinSerialize().length, block.length); assertEquals(origBlockLen + tx.length, block.length); - block.getTransactions().get(1).getInputs().get(0).setScriptBytes(new byte[] {(byte)Script.OP_FALSE, (byte)Script.OP_FALSE}); + block.getTransactions().get(1).getInputs().get(0).setScriptBytes(new byte[] {(byte) ScriptOpCodes.OP_FALSE, (byte) ScriptOpCodes.OP_FALSE}); assertEquals(block.length, origBlockLen + tx.length); assertEquals(tx.length, origTxLength + 1); block.getTransactions().get(1).getInputs().get(0).setScriptBytes(new byte[] {}); assertEquals(block.length, block.bitcoinSerialize().length); assertEquals(block.length, origBlockLen + tx.length); assertEquals(tx.length, origTxLength - 1); - block.getTransactions().get(1).addInput(new TransactionInput(params, null, new byte[] {(byte)Script.OP_FALSE}, + block.getTransactions().get(1).addInput(new TransactionInput(params, null, new byte[] {(byte) ScriptOpCodes.OP_FALSE}, new TransactionOutPoint(params, 0, Sha256Hash.create(new byte[] {1})))); assertEquals(block.length, origBlockLen + tx.length); assertEquals(tx.length, origTxLength + 41); // - 1 + 40 + 1 + 1 diff --git a/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java b/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java index 857d93bd..3891e961 100644 --- a/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java +++ b/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java @@ -8,6 +8,8 @@ import java.io.IOException; import java.math.BigInteger; import java.util.*; +import static com.google.bitcoin.core.ScriptOpCodes.*; + class BlockAndValidity { Block block; boolean connects; @@ -203,7 +205,7 @@ public class FullBlockTestGenerator { } Transaction tx = new Transaction(params); byte[] outputScript = new byte[Block.MAX_BLOCK_SIGOPS - sigOps]; - Arrays.fill(outputScript, (byte)Script.OP_CHECKSIG); + Arrays.fill(outputScript, (byte) OP_CHECKSIG); tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), outputScript)); addOnlyInputToTransaction(tx, new TransactionOutPointWithValue( new TransactionOutPoint(params, 1, b15.getTransactions().get(1).getHash()), @@ -228,7 +230,7 @@ public class FullBlockTestGenerator { } Transaction tx = new Transaction(params); byte[] outputScript = new byte[Block.MAX_BLOCK_SIGOPS - sigOps + 1]; - Arrays.fill(outputScript, (byte)Script.OP_CHECKSIG); + Arrays.fill(outputScript, (byte) OP_CHECKSIG); tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), outputScript)); addOnlyInputToTransaction(tx, new TransactionOutPointWithValue( new TransactionOutPoint(params, 1, b16.getTransactions().get(1).getHash()), @@ -309,7 +311,7 @@ public class FullBlockTestGenerator { Transaction tx = new Transaction(params); // Signature size is non-deterministic, so it may take several runs before finding any off-by-one errors byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - b23.getMessageSize() - 138]; - Arrays.fill(outputScript, (byte)Script.OP_FALSE); + Arrays.fill(outputScript, (byte) OP_FALSE); tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), outputScript)); addOnlyInputToTransaction(tx, new TransactionOutPointWithValue( new TransactionOutPoint(params, 1, b23.getTransactions().get(1).getHash()), @@ -328,7 +330,7 @@ public class FullBlockTestGenerator { Transaction tx = new Transaction(params); // Signature size is non-deterministic, so it may take several runs before finding any off-by-one errors byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - b24.getMessageSize() - 135]; - Arrays.fill(outputScript, (byte)Script.OP_FALSE); + Arrays.fill(outputScript, (byte) OP_FALSE); tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), outputScript)); addOnlyInputToTransaction(tx, new TransactionOutPointWithValue( new TransactionOutPoint(params, 1, b24.getTransactions().get(1).getHash()), @@ -404,7 +406,7 @@ public class FullBlockTestGenerator { } Transaction tx = new Transaction(params); byte[] outputScript = new byte[(Block.MAX_BLOCK_SIGOPS - sigOps)/20]; - Arrays.fill(outputScript, (byte)Script.OP_CHECKMULTISIG); + Arrays.fill(outputScript, (byte) OP_CHECKMULTISIG); tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), outputScript)); addOnlyInputToTransaction(tx, new TransactionOutPointWithValue( new TransactionOutPoint(params, 1, b31.getTransactions().get(1).getHash()), @@ -429,9 +431,9 @@ public class FullBlockTestGenerator { } Transaction tx = new Transaction(params); byte[] outputScript = new byte[(Block.MAX_BLOCK_SIGOPS - sigOps)/20 + (Block.MAX_BLOCK_SIGOPS - sigOps)%20 + 1]; - Arrays.fill(outputScript, (byte)Script.OP_CHECKMULTISIG); + Arrays.fill(outputScript, (byte) OP_CHECKMULTISIG); for (int i = 0; i < (Block.MAX_BLOCK_SIGOPS - sigOps)%20; i++) - outputScript[i] = (byte)Script.OP_CHECKSIG; + outputScript[i] = (byte) OP_CHECKSIG; tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), outputScript)); addOnlyInputToTransaction(tx, new TransactionOutPointWithValue( new TransactionOutPoint(params, 1, b32.getTransactions().get(1).getHash()), @@ -451,7 +453,7 @@ public class FullBlockTestGenerator { } Transaction tx = new Transaction(params); byte[] outputScript = new byte[(Block.MAX_BLOCK_SIGOPS - sigOps)/20]; - Arrays.fill(outputScript, (byte)Script.OP_CHECKMULTISIGVERIFY); + Arrays.fill(outputScript, (byte) OP_CHECKMULTISIGVERIFY); tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), outputScript)); addOnlyInputToTransaction(tx, new TransactionOutPointWithValue( new TransactionOutPoint(params, 1, b33.getTransactions().get(1).getHash()), @@ -476,9 +478,9 @@ public class FullBlockTestGenerator { } Transaction tx = new Transaction(params); byte[] outputScript = new byte[(Block.MAX_BLOCK_SIGOPS - sigOps)/20 + (Block.MAX_BLOCK_SIGOPS - sigOps)%20 + 1]; - Arrays.fill(outputScript, (byte)Script.OP_CHECKMULTISIGVERIFY); + Arrays.fill(outputScript, (byte) OP_CHECKMULTISIGVERIFY); for (int i = 0; i < (Block.MAX_BLOCK_SIGOPS - sigOps)%20; i++) - outputScript[i] = (byte)Script.OP_CHECKSIG; + outputScript[i] = (byte) OP_CHECKSIG; tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), outputScript)); addOnlyInputToTransaction(tx, new TransactionOutPointWithValue( new TransactionOutPoint(params, 1, b34.getTransactions().get(1).getHash()), @@ -498,7 +500,7 @@ public class FullBlockTestGenerator { } Transaction tx = new Transaction(params); byte[] outputScript = new byte[Block.MAX_BLOCK_SIGOPS - sigOps]; - Arrays.fill(outputScript, (byte)Script.OP_CHECKSIGVERIFY); + Arrays.fill(outputScript, (byte) OP_CHECKSIGVERIFY); tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), outputScript)); addOnlyInputToTransaction(tx, new TransactionOutPointWithValue( new TransactionOutPoint(params, 1, b35.getTransactions().get(1).getHash()), @@ -523,7 +525,7 @@ public class FullBlockTestGenerator { } Transaction tx = new Transaction(params); byte[] outputScript = new byte[Block.MAX_BLOCK_SIGOPS - sigOps + 1]; - Arrays.fill(outputScript, (byte)Script.OP_CHECKSIGVERIFY); + Arrays.fill(outputScript, (byte) OP_CHECKSIGVERIFY); tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), outputScript)); addOnlyInputToTransaction(tx, new TransactionOutPointWithValue( new TransactionOutPoint(params, 1, b36.getTransactions().get(1).getHash()), @@ -576,17 +578,17 @@ public class FullBlockTestGenerator { ByteArrayOutputStream p2shScriptPubKey = new UnsafeByteArrayOutputStream(); try { Script.writeBytes(p2shScriptPubKey, coinbaseOutKeyPubKey); - p2shScriptPubKey.write(Script.OP_2DUP); - p2shScriptPubKey.write(Script.OP_CHECKSIGVERIFY); - p2shScriptPubKey.write(Script.OP_2DUP); - p2shScriptPubKey.write(Script.OP_CHECKSIGVERIFY); - p2shScriptPubKey.write(Script.OP_2DUP); - p2shScriptPubKey.write(Script.OP_CHECKSIGVERIFY); - p2shScriptPubKey.write(Script.OP_2DUP); - p2shScriptPubKey.write(Script.OP_CHECKSIGVERIFY); - p2shScriptPubKey.write(Script.OP_2DUP); - p2shScriptPubKey.write(Script.OP_CHECKSIGVERIFY); - p2shScriptPubKey.write(Script.OP_CHECKSIG); + p2shScriptPubKey.write(OP_2DUP); + p2shScriptPubKey.write(OP_CHECKSIGVERIFY); + p2shScriptPubKey.write(OP_2DUP); + p2shScriptPubKey.write(OP_CHECKSIGVERIFY); + p2shScriptPubKey.write(OP_2DUP); + p2shScriptPubKey.write(OP_CHECKSIGVERIFY); + p2shScriptPubKey.write(OP_2DUP); + p2shScriptPubKey.write(OP_CHECKSIGVERIFY); + p2shScriptPubKey.write(OP_2DUP); + p2shScriptPubKey.write(OP_CHECKSIGVERIFY); + p2shScriptPubKey.write(OP_CHECKSIG); } catch (IOException e) { throw new RuntimeException(e); // Cannot happen. } @@ -594,20 +596,20 @@ public class FullBlockTestGenerator { byte[] scriptHash = Utils.sha256hash160(b39p2shScriptPubKey); UnsafeByteArrayOutputStream scriptPubKey = new UnsafeByteArrayOutputStream(scriptHash.length + 3); - scriptPubKey.write(Script.OP_HASH160); + scriptPubKey.write(OP_HASH160); try { Script.writeBytes(scriptPubKey, scriptHash); } catch (IOException e) { throw new RuntimeException(e); // Cannot happen. } - scriptPubKey.write(Script.OP_EQUAL); + scriptPubKey.write(OP_EQUAL); BigInteger lastOutputValue = out11.value.subtract(BigInteger.valueOf(1)); TransactionOutPoint lastOutPoint; { Transaction tx = new Transaction(params); tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), scriptPubKey.toByteArray())); - tx.addOutput(new TransactionOutput(params, tx, lastOutputValue, new byte[]{Script.OP_1})); + tx.addOutput(new TransactionOutput(params, tx, lastOutputValue, new byte[]{OP_1})); addOnlyInputToTransaction(tx, out11); lastOutPoint = new TransactionOutPoint(params, 1, tx.getHash()); b39.addTransaction(tx); @@ -620,8 +622,8 @@ public class FullBlockTestGenerator { lastOutputValue = lastOutputValue.subtract(BigInteger.valueOf(1)); tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), scriptPubKey.toByteArray())); - tx.addOutput(new TransactionOutput(params, tx, lastOutputValue, new byte[]{Script.OP_1})); - tx.addInput(new TransactionInput(params, tx, new byte[]{Script.OP_1}, lastOutPoint)); + tx.addOutput(new TransactionOutput(params, tx, lastOutputValue, new byte[]{OP_1})); + tx.addInput(new TransactionInput(params, tx, new byte[]{OP_1}, lastOutPoint)); lastOutPoint = new TransactionOutPoint(params, 1, tx.getHash()); if (b39.getMessageSize() + tx.getMessageSize() < Block.MAX_BLOCK_SIZE) { @@ -655,8 +657,8 @@ public class FullBlockTestGenerator { byte[] scriptSig = null; for (int i = 1; i <= numTxes; i++) { Transaction tx = new Transaction(params); - tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), new byte[] {Script.OP_1})); - tx.addInput(new TransactionInput(params, tx, new byte[]{Script.OP_1}, lastOutPoint)); + tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), new byte[] {OP_1})); + tx.addInput(new TransactionInput(params, tx, new byte[]{OP_1}, lastOutPoint)); TransactionInput input = new TransactionInput(params, tx, new byte[]{}, new TransactionOutPoint(params, 0, b39.getTransactions().get(i).getHash())); @@ -674,7 +676,7 @@ public class FullBlockTestGenerator { byte[] signature = bos.toByteArray(); ByteArrayOutputStream scriptSigBos = new UnsafeByteArrayOutputStream(signature.length + b39p2shScriptPubKey.length + 3); - Script.writeBytes(scriptSigBos, new byte[] {(byte) Script.OP_CHECKSIG}); + Script.writeBytes(scriptSigBos, new byte[] {(byte) OP_CHECKSIG}); scriptSigBos.write(Script.createInputScript(signature)); Script.writeBytes(scriptSigBos, b39p2shScriptPubKey); @@ -693,9 +695,9 @@ public class FullBlockTestGenerator { sigOps += numTxes * b39sigOpsPerOutput; Transaction tx = new Transaction(params); - tx.addInput(new TransactionInput(params, tx, new byte[]{Script.OP_1}, lastOutPoint)); + tx.addInput(new TransactionInput(params, tx, new byte[]{OP_1}, lastOutPoint)); byte[] scriptPubKey = new byte[Block.MAX_BLOCK_SIGOPS - sigOps + 1]; - Arrays.fill(scriptPubKey, (byte)Script.OP_CHECKSIG); + Arrays.fill(scriptPubKey, (byte) OP_CHECKSIG); tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, scriptPubKey)); b40.addTransaction(tx); } @@ -722,9 +724,9 @@ public class FullBlockTestGenerator { for (int i = 1; i <= numTxes; i++) { Transaction tx = new Transaction(params); tx.addOutput(new TransactionOutput(params, tx, BigInteger - .valueOf(1), new byte[] { Script.OP_1 })); + .valueOf(1), new byte[] {OP_1})); tx.addInput(new TransactionInput(params, tx, - new byte[] { Script.OP_1 }, lastOutPoint)); + new byte[] {OP_1}, lastOutPoint)); TransactionInput input = new TransactionInput(params, tx, new byte[] {}, new TransactionOutPoint(params, 0, @@ -748,7 +750,7 @@ public class FullBlockTestGenerator { signature.length + b39p2shScriptPubKey.length + 3); Script.writeBytes(scriptSigBos, - new byte[] { (byte) Script.OP_CHECKSIG }); + new byte[] { (byte) OP_CHECKSIG}); scriptSigBos.write(Script .createInputScript(signature)); Script.writeBytes(scriptSigBos, b39p2shScriptPubKey); @@ -770,9 +772,9 @@ public class FullBlockTestGenerator { sigOps += numTxes * b39sigOpsPerOutput; Transaction tx = new Transaction(params); tx.addInput(new TransactionInput(params, tx, - new byte[] { Script.OP_1 }, lastOutPoint)); + new byte[] {OP_1}, lastOutPoint)); byte[] scriptPubKey = new byte[Block.MAX_BLOCK_SIGOPS - sigOps]; - Arrays.fill(scriptPubKey, (byte) Script.OP_CHECKSIG); + Arrays.fill(scriptPubKey, (byte) OP_CHECKSIG); tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, scriptPubKey)); b41.addTransaction(tx); } @@ -814,10 +816,10 @@ public class FullBlockTestGenerator { Transaction t = new Transaction(params); // Entirely invalid scriptPubKey to ensure we aren't pre-verifying too much - t.addOutput(new TransactionOutput(params, t, BigInteger.valueOf(0), new byte[] { Script.OP_PUSHDATA1 - 1 })); + t.addOutput(new TransactionOutput(params, t, BigInteger.valueOf(0), new byte[] {OP_PUSHDATA1 - 1 })); t.addOutput(new TransactionOutput(params, t, BigInteger.valueOf(1), Script.createOutputScript(coinbaseOutKeyPubKey))); // Spendable output - t.addOutput(new TransactionOutput(params, t, BigInteger.ZERO, new byte[] {Script.OP_1})); + t.addOutput(new TransactionOutput(params, t, BigInteger.ZERO, new byte[] {OP_1})); addOnlyInputToTransaction(t, out14); b44.addTransaction(t); @@ -837,10 +839,10 @@ public class FullBlockTestGenerator { Transaction t = new Transaction(params); // Entirely invalid scriptPubKey to ensure we aren't pre-verifying too much - t.addOutput(new TransactionOutput(params, t, BigInteger.valueOf(0), new byte[] { Script.OP_PUSHDATA1 - 1 })); + t.addOutput(new TransactionOutput(params, t, BigInteger.valueOf(0), new byte[] {OP_PUSHDATA1 - 1 })); t.addOutput(new TransactionOutput(params, t, BigInteger.valueOf(1), Script.createOutputScript(coinbaseOutKeyPubKey))); // Spendable output - t.addOutput(new TransactionOutput(params, t, BigInteger.ZERO, new byte[] {Script.OP_1})); + t.addOutput(new TransactionOutput(params, t, BigInteger.ZERO, new byte[] {OP_1})); addOnlyInputToTransaction(t, out15); try { b45.addTransaction(t); @@ -1007,7 +1009,7 @@ public class FullBlockTestGenerator { { Transaction tx = new Transaction(params); tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[] {})); - tx.addInput(new TransactionInput(params, tx, new byte[] { Script.OP_1 }, + tx.addInput(new TransactionInput(params, tx, new byte[] {OP_1}, new TransactionOutPoint(params, 3, b58.getTransactions().get(1).getHash()))); b58.addTransaction(tx); } @@ -1020,7 +1022,7 @@ public class FullBlockTestGenerator { Transaction tx = new Transaction(params); tx.addOutput(new TransactionOutput(params, tx, b59.getTransactions().get(1).getOutputs().get(2).getValue().add(BigInteger.ONE), new byte[] {})); - tx.addInput(new TransactionInput(params, tx, new byte[] { Script.OP_1 }, + tx.addInput(new TransactionInput(params, tx, new byte[] {OP_1}, new TransactionOutPoint(params, 2, b59.getTransactions().get(1).getHash()))); b59.addTransaction(tx); } @@ -1058,7 +1060,7 @@ public class FullBlockTestGenerator { { Transaction tx = new Transaction(params); tx.setLockTime(0xffffffffL); - tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[] { Script.OP_TRUE })); + tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[] {OP_TRUE})); addOnlyInputToTransaction(tx, out18, 0); b62.addTransaction(tx); Preconditions.checkState(!tx.isFinal(chainHeadHeight + 17, b62.getTimeSeconds())); @@ -1089,7 +1091,7 @@ public class FullBlockTestGenerator { Transaction tx = new Transaction(params); // Signature size is non-deterministic, so it may take several runs before finding any off-by-one errors byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - b64Created.getMessageSize() - 138]; - Arrays.fill(outputScript, (byte)Script.OP_FALSE); + Arrays.fill(outputScript, (byte) OP_FALSE); tx.addOutput(new TransactionOutput(params, tx, BigInteger.valueOf(1), outputScript)); addOnlyInputToTransaction(tx, new TransactionOutPointWithValue( new TransactionOutPoint(params, 1, b64Created.getTransactions().get(1).getHash()), @@ -1132,12 +1134,12 @@ public class FullBlockTestGenerator { Block b65 = createNextBlock(b64, chainHeadHeight + 18, null, null); { Transaction tx1 = new Transaction(params); - tx1.addOutput(new TransactionOutput(params, tx1, out19.value, new byte[]{ Script.OP_TRUE })); + tx1.addOutput(new TransactionOutput(params, tx1, out19.value, new byte[]{OP_TRUE})); addOnlyInputToTransaction(tx1, out19, 0); b65.addTransaction(tx1); Transaction tx2 = new Transaction(params); - tx2.addOutput(new TransactionOutput(params, tx2, BigInteger.ZERO, new byte[]{ Script.OP_TRUE })); - tx2.addInput(new TransactionInput(params, tx2, new byte[]{ Script.OP_TRUE }, + tx2.addOutput(new TransactionOutput(params, tx2, BigInteger.ZERO, new byte[]{OP_TRUE})); + tx2.addInput(new TransactionInput(params, tx2, new byte[]{OP_TRUE}, new TransactionOutPoint(params, 0, tx1.getHash()))); b65.addTransaction(tx2); } @@ -1157,11 +1159,11 @@ public class FullBlockTestGenerator { Block b66 = createNextBlock(b65, chainHeadHeight + 19, null, null); { Transaction tx1 = new Transaction(params); - tx1.addOutput(new TransactionOutput(params, tx1, out20.value, new byte[]{ Script.OP_TRUE })); + tx1.addOutput(new TransactionOutput(params, tx1, out20.value, new byte[]{OP_TRUE})); addOnlyInputToTransaction(tx1, out20, 0); Transaction tx2 = new Transaction(params); - tx2.addOutput(new TransactionOutput(params, tx2, BigInteger.ZERO, new byte[]{ Script.OP_TRUE })); - tx2.addInput(new TransactionInput(params, tx2, new byte[]{ Script.OP_TRUE }, + tx2.addOutput(new TransactionOutput(params, tx2, BigInteger.ZERO, new byte[]{OP_TRUE})); + tx2.addInput(new TransactionInput(params, tx2, new byte[]{OP_TRUE}, new TransactionOutPoint(params, 0, tx1.getHash()))); b66.addTransaction(tx2); b66.addTransaction(tx1); @@ -1176,17 +1178,17 @@ public class FullBlockTestGenerator { Block b67 = createNextBlock(b65, chainHeadHeight + 19, null, null); { Transaction tx1 = new Transaction(params); - tx1.addOutput(new TransactionOutput(params, tx1, out20.value, new byte[]{ Script.OP_TRUE })); + tx1.addOutput(new TransactionOutput(params, tx1, out20.value, new byte[]{OP_TRUE})); addOnlyInputToTransaction(tx1, out20, 0); b67.addTransaction(tx1); Transaction tx2 = new Transaction(params); - tx2.addOutput(new TransactionOutput(params, tx2, BigInteger.ZERO, new byte[]{ Script.OP_TRUE })); - tx2.addInput(new TransactionInput(params, tx2, new byte[]{ Script.OP_TRUE }, + tx2.addOutput(new TransactionOutput(params, tx2, BigInteger.ZERO, new byte[]{OP_TRUE})); + tx2.addInput(new TransactionInput(params, tx2, new byte[]{OP_TRUE}, new TransactionOutPoint(params, 0, tx1.getHash()))); b67.addTransaction(tx2); Transaction tx3 = new Transaction(params); - tx3.addOutput(new TransactionOutput(params, tx3, out20.value, new byte[]{ Script.OP_TRUE })); - tx3.addInput(new TransactionInput(params, tx3, new byte[]{ Script.OP_TRUE }, + tx3.addOutput(new TransactionOutput(params, tx3, out20.value, new byte[]{OP_TRUE})); + tx3.addInput(new TransactionInput(params, tx3, new byte[]{OP_TRUE}, new TransactionOutPoint(params, 0, tx1.getHash()))); b67.addTransaction(tx3); } @@ -1200,7 +1202,7 @@ public class FullBlockTestGenerator { Block b68 = createNextBlock(b65, chainHeadHeight + 19, null, BigInteger.TEN); { Transaction tx = new Transaction(params); - tx.addOutput(new TransactionOutput(params, tx, out20.value.subtract(BigInteger.valueOf(9)), new byte[]{ Script.OP_TRUE })); + tx.addOutput(new TransactionOutput(params, tx, out20.value.subtract(BigInteger.valueOf(9)), new byte[]{OP_TRUE})); addOnlyInputToTransaction(tx, out20, 0); b68.addTransaction(tx); } @@ -1210,7 +1212,7 @@ public class FullBlockTestGenerator { Block b69 = createNextBlock(b65, chainHeadHeight + 19, null, BigInteger.TEN); { Transaction tx = new Transaction(params); - tx.addOutput(new TransactionOutput(params, tx, out20.value.subtract(BigInteger.TEN), new byte[]{ Script.OP_TRUE })); + tx.addOutput(new TransactionOutput(params, tx, out20.value.subtract(BigInteger.TEN), new byte[]{OP_TRUE})); addOnlyInputToTransaction(tx, out20, 0); b69.addTransaction(tx); } @@ -1225,8 +1227,8 @@ public class FullBlockTestGenerator { Block b70 = createNextBlock(b69, chainHeadHeight + 20, out21, null); { Transaction tx = new Transaction(params); - tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[]{ Script.OP_TRUE })); - tx.addInput(new TransactionInput(params, tx, new byte[]{ Script.OP_TRUE }, + tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[]{OP_TRUE})); + tx.addInput(new TransactionInput(params, tx, new byte[]{OP_TRUE}, new TransactionOutPoint(params, 0, new Sha256Hash("23c70ed7c0506e9178fc1a987f40a33946d4ad4c962b5ae3a52546da53af0c5c")))); b70.addTransaction(tx); } @@ -1240,7 +1242,7 @@ public class FullBlockTestGenerator { Block b72 = createNextBlock(b69, chainHeadHeight + 20, out21, null); { Transaction tx = new Transaction(params); - tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[]{ Script.OP_TRUE })); + tx.addOutput(new TransactionOutput(params, tx, BigInteger.ZERO, new byte[]{OP_TRUE})); addOnlyInputToTransaction(tx, new TransactionOutPointWithValue( new TransactionOutPoint(params, 1, b72.getTransactions().get(1).getHash()), BigInteger.valueOf(1), b72.getTransactions().get(1).getOutputs().get(1).getScriptPubKey())); @@ -1269,10 +1271,10 @@ public class FullBlockTestGenerator { if (prevOut != null) { Transaction t = new Transaction(params); // Entirely invalid scriptPubKey to ensure we aren't pre-verifying too much - t.addOutput(new TransactionOutput(params, t, BigInteger.valueOf(0), new byte[] { Script.OP_PUSHDATA1 - 1 })); + t.addOutput(new TransactionOutput(params, t, BigInteger.valueOf(0), new byte[] {OP_PUSHDATA1 - 1 })); t.addOutput(new TransactionOutput(params, t, BigInteger.valueOf(1), Script.createOutputScript(coinbaseOutKeyPubKey))); // Spendable output - t.addOutput(new TransactionOutput(params, t, BigInteger.ZERO, new byte[] {Script.OP_1})); + t.addOutput(new TransactionOutput(params, t, BigInteger.ZERO, new byte[] {OP_1})); addOnlyInputToTransaction(t, prevOut); block.addTransaction(t); block.solve(); diff --git a/core/src/test/java/com/google/bitcoin/core/ScriptTest.java b/core/src/test/java/com/google/bitcoin/core/ScriptTest.java index 7d982cde..d6e87c36 100644 --- a/core/src/test/java/com/google/bitcoin/core/ScriptTest.java +++ b/core/src/test/java/com/google/bitcoin/core/ScriptTest.java @@ -93,8 +93,8 @@ public class ScriptTest { private synchronized static void initMapOpNames() { if (mapOpNames == null) { mapOpNames = new HashMap(); - for (int op = Script.OP_NOP; op <= Script.OP_NOP10; op++) { - String name = Script.getOpCodeName((byte)op); + for (int op = ScriptOpCodes.OP_NOP; op <= ScriptOpCodes.OP_NOP10; op++) { + String name = ScriptOpCodes.getOpCodeName((byte) op); if (name.startsWith("NON_OP(")) continue; // The reference client's implementation supports OP_*, but we only support * @@ -116,7 +116,7 @@ public class ScriptTest { // Number long val = Long.parseLong(w); if (val == -1 || (val >= 1 && val <= 16)) - out.write((int)val + Script.OP_1 - 1); + out.write((int)val + ScriptOpCodes.OP_1 - 1); else Script.writeBytes(out, Utils.reverseBytes(Utils.encodeMPI(BigInteger.valueOf(val), false))); } else if (w.matches("^0x[0-9a-fA-F]*$")) {