aboutsummaryrefslogtreecommitdiff
path: root/src/script.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2013-09-24 00:48:00 +0200
committerPieter Wuille <sipa@ulyssis.org>2014-02-11 21:11:59 +0100
commit87fe71e1fc810ee120a10063fdd26c3245686d54 (patch)
tree193f73d99ddbd70a67b5aafdcf353174f2cf4a96 /src/script.cpp
parent9aea601b05b3541fcc7e0c45cba8fd2178224809 (diff)
Add HasCanonicalPushes(), and use it in IsStandardTx
Diffstat (limited to 'src/script.cpp')
-rw-r--r--src/script.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/script.cpp b/src/script.cpp
index b2d8a67f96..83fc91956c 100644
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -1881,6 +1881,33 @@ bool CScript::IsPushOnly() const
return true;
}
+bool CScript::HasCanonicalPushes() const
+{
+ const_iterator pc = begin();
+ while (pc < end())
+ {
+ opcodetype opcode;
+ std::vector<unsigned char> data;
+ if (!GetOp(pc, opcode, data))
+ return false;
+ if (opcode > OP_16)
+ continue;
+ if (opcode < OP_PUSHDATA1 && opcode > OP_0 && (data.size() == 1 && data[0] <= 16))
+ // Could have used an OP_n code, rather than a 1-byte push.
+ return false;
+ if (opcode == OP_PUSHDATA1 && data.size() < OP_PUSHDATA1)
+ // Could have used a normal n-byte push, rather than OP_PUSHDATA1.
+ return false;
+ if (opcode == OP_PUSHDATA2 && data.size() <= 0xFF)
+ // Could have used an OP_PUSHDATA1.
+ return false;
+ if (opcode == OP_PUSHDATA4 && data.size() <= 0xFFFF)
+ // Could have used an OP_PUSHDATA2.
+ return false;
+ }
+ return true;
+}
+
class CScriptVisitor : public boost::static_visitor<bool>
{
private: