From d231bade1f9f4455ed2c2895830c277c6d5ffdae Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Mon, 5 Mar 2018 22:04:00 +0100 Subject: [PATCH] Script.ScriptType: Use stable id for persistence, rather than ordinal(). --- .../main/java/org/bitcoinj/script/Script.java | 19 ++++++++++++------- .../store/DatabaseFullPrunedBlockStore.java | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/script/Script.java b/core/src/main/java/org/bitcoinj/script/Script.java index 616c6b36..c64a4f31 100644 --- a/core/src/main/java/org/bitcoinj/script/Script.java +++ b/core/src/main/java/org/bitcoinj/script/Script.java @@ -56,13 +56,18 @@ public class Script { /** Enumeration to encapsulate the type of this script. */ public enum ScriptType { - // Do NOT change the ordering of the following definitions because their ordinals are stored in databases. - NO_TYPE, - P2PKH, // pay to pubkey hash (aka pay to address) - P2PK, // pay to pubkey - P2SH, // pay to script hash - P2WPKH, // pay to witness pubkey hash - P2WSH, // pay to witness script hash + NO_TYPE(0), + P2PKH(1), // pay to pubkey hash (aka pay to address) + P2PK(2), // pay to pubkey + P2SH(3), // pay to script hash + P2WPKH(4), // pay to witness pubkey hash + P2WSH(5); // pay to witness script hash + + public final int id; + + private ScriptType(int id) { + this.id = id; + } } /** Flags to pass to {@link Script#correctlySpends(Transaction, long, Script, Set)}. diff --git a/core/src/main/java/org/bitcoinj/store/DatabaseFullPrunedBlockStore.java b/core/src/main/java/org/bitcoinj/store/DatabaseFullPrunedBlockStore.java index 2b001859..025b516c 100644 --- a/core/src/main/java/org/bitcoinj/store/DatabaseFullPrunedBlockStore.java +++ b/core/src/main/java/org/bitcoinj/store/DatabaseFullPrunedBlockStore.java @@ -959,7 +959,7 @@ public abstract class DatabaseFullPrunedBlockStore implements FullPrunedBlockSto s.setLong(4, out.getValue().value); s.setBytes(5, out.getScript().getProgram()); s.setString(6, out.getAddress()); - s.setInt(7, out.getScript().getScriptType().ordinal()); + s.setInt(7, out.getScript().getScriptType().id); s.setBoolean(8, out.isCoinbase()); s.executeUpdate(); s.close();