Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moved boolean conversion to utils

  • Loading branch information...
commit 5b82749fb7ca944d7cda90e50c69cd98715b8f7d 1 parent 498c441
Alexander Bernauer authored
View
8 TODO
@@ -0,0 +1,8 @@
+openssl - bignum über FFI verwenden
+ es gibt vlt. schon ein Haskell-Paket dafür
+
+ByteStream strict verwenden.
+ [Word8] vermeiden
+ attoParsc Library
+
+QuickCheck mit Referenzimplementierung zum Testen verwenden.
View
8 questions
@@ -0,0 +1,8 @@
+== IFDUP
+wiki says: If the input is true or false, duplicate it
+code says: if (CastToBool(vch)) stack.push_back(vch)
+ and CastToBool casts the byte string to a bool
+report bug?
+
+== Encoding of numbers as byte strings
+check openssl bignum implementation
View
9 src/Language/Bitcoin/Interpreter.hs
@@ -6,7 +6,7 @@ module Language.Bitcoin.Interpreter
import Control.Arrow ((***), Arrow)
import Language.Bitcoin.Types
-import Language.Bitcoin.Utils (b2i, i2b)
+import Language.Bitcoin.Utils (b2i, i2b, bsIsTrue)
import Language.Bitcoin.Text (print_result)
import qualified Data.ByteString.Lazy as B
@@ -38,10 +38,7 @@ run_interpreter' machine@(Machine (op:rest) keyring stack altStack) =
Right (stack') -> run_interpreter' (Machine rest keyring stack' altStack)
topIsTrue :: [B.ByteString] -> Bool
-topIsTrue (x:_) =
- case b2i x of
- Left _ -> False
- Right value -> value == 1
+topIsTrue (x:_) = bsIsTrue x
topIsTrue _ = False
simpleOp :: Opcode -> Stack -> Either ResultCode Stack
@@ -73,7 +70,7 @@ simpleOp OP_VERIFY stack =
then Right $ tail stack
else Left $ Failure $ "OP_VERIFY failed because top stack value is not True."
-simpleOp OP_IFDUP _ = Left $ Error "OP_IFDUP is broken, so it's not supported."
+simpleOp OP_IFDUP stack = stackOp stack 1 (\(x:xs) -> Right (if bsIsTrue x then x:x:xs else x:xs))
simpleOp OP_DEPTH stack = Right $ ((i2b . fromIntegral . length) stack) : stack
simpleOp OP_DROP stack = stackOp stack 1 (\(_:xs) -> Right xs)
simpleOp OP_DUP stack = stackOp stack 1 (\(x:xs) -> Right $ x:x:xs)
View
7 src/Language/Bitcoin/Utils.hs
@@ -1,6 +1,6 @@
module Language.Bitcoin.Utils
(
- b2i, b2i', i2b, bsLength, pad, unpad, bs
+ b2i, b2i', i2b, bsLength, pad, unpad, bs, bsIsTrue
) where
import qualified Data.ByteString.Lazy as B
@@ -73,3 +73,8 @@ extractSign string = assert (B.length string == 4) $
then (-1, (msb - 0x70) `B.cons` rest)
else (1, msb `B.cons` rest)
+bsIsTrue :: B.ByteString -> Bool
+bsIsTrue string =
+ case b2i string of
+ Left _ -> False
+ Right value -> value == 1
Please sign in to comment.
Something went wrong with that request. Please try again.