Skip to content

Commit

Permalink
[refactor] minor
Browse files Browse the repository at this point in the history
  • Loading branch information
np committed Nov 19, 2014
1 parent 8f19181 commit c45c3a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Utils where

import qualified Prelude as Prelude
import Prelude hiding (interact, putStr)
import Control.Monad (unless)
import Data.Binary
import Data.Char (isSpace,isDigit,toLower)
import Data.Functor ((<$>))
Expand Down
14 changes: 8 additions & 6 deletions hx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import DetailedTx (txDetailedJSON)
import Utils
import Electrum

readTxFile :: FilePath -> IO Tx
type TxFile = FilePath

readTxFile :: TxFile -> IO Tx
readTxFile file = getHex "transaction" <$> BS.readFile file

one_btc_in_satoshi :: Num a => a
Expand Down Expand Up @@ -157,7 +159,7 @@ mktx_args ( "--input":input :args) = Left (readOutPoint input) : mktx_args args
mktx_args ( "-i":input :args) = Left (readOutPoint input) : mktx_args args
mktx_args ("--output":output:args) = Right (readOutput output) : mktx_args args
mktx_args ( "-o":output:args) = Right (readOutput output) : mktx_args args
mktx_args _ = error "mktx_args: unexpected argument"
mktx_args (arg:_) = error $ "mktx_args: unexpected argument " ++ show arg

putTxSig :: Hex s => TxSignature -> s
putTxSig = encodeHex . encodeSig
Expand Down Expand Up @@ -355,7 +357,7 @@ hx_signmsg_modn [msg,prv] = putHex $ detSignMsg (fromIntegral $ getDecStrictN ms
hx_signmsg_modn _ = error "Usage: hx signmsg-modn <MESSAGE-DECIMAL-INTEGER> <PRIVKEY>"

-- set-input FILENAME N SIGNATURE_AND_PUBKEY_SCRIPT
hx_set_input :: FilePath -> String -> String -> IO ()
hx_set_input :: TxFile -> String -> String -> IO ()
hx_set_input file index script =
do tx <- readTxFile file
B8.putStrLn . putHex $ hx_set_input' (parseInt "input index" index) (decodeHex "script" script) tx
Expand All @@ -369,14 +371,14 @@ hx_validsig' tx i out (TxSignature sig sh) pub =
pubKeyAddr pub == a && verifySig (txSigHash tx out i sh) sig pub
where a = getOutputAddress (either error id (decodeOutput out))

hx_validsig :: FilePath -> String -> String -> String -> IO ()
hx_validsig :: TxFile -> String -> String -> String -> IO ()
hx_validsig file i s sig =
do tx <- readTxFile file
interactLn $ putSuccess'
. hx_validsig' tx (parseInt "input index" i) (getHex "script" s) (getTxSig sig)
. getPubKey

hx_sign_input :: FilePath -> String -> String -> IO ()
hx_sign_input :: TxFile -> String -> String -> IO ()
hx_sign_input file index script_code =
do tx <- readTxFile file
interactLn $ putTxSig . hx_sign_input' tx (parseInt "input index" index) (getHex "script" script_code) . fromWIFE
Expand Down Expand Up @@ -684,4 +686,4 @@ mainArgs _ = error $ unlines ["Unexpected arguments."
]

main :: IO ()
main = getArgs >>= mainArgs
main = mainArgs =<< getArgs

0 comments on commit c45c3a8

Please sign in to comment.