diff --git a/.gitignore b/.gitignore index 425e2d8..d9a126d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ cabal-dev/ network-bitcoin-tests cabal.sandbox.config .cabal-sandbox/ +tags diff --git a/.hgignore b/.hgignore index c499dd6..ab86da2 100644 --- a/.hgignore +++ b/.hgignore @@ -16,3 +16,4 @@ dist-newstyle/ \.tfstate\.blank$ \.terraform/ \.stack-work/ +^tags$ diff --git a/src/Network/Bitcoin/BlockChain.hs b/src/Network/Bitcoin/BlockChain.hs index 7fa94de..709f651 100644 --- a/src/Network/Bitcoin/BlockChain.hs +++ b/src/Network/Bitcoin/BlockChain.hs @@ -152,7 +152,7 @@ data OutputInfo = -- | The public key of the sender. , oiScriptPubKey :: ScriptPubKey -- | The version of this transaction. - , oiVersion :: Integer + , oiVersion :: Maybe Integer -- | Is this transaction part of the coin base? , oiCoinBase :: Bool } @@ -163,7 +163,7 @@ instance FromJSON OutputInfo where <*> o .: "confirmations" <*> o .: "value" <*> o .: "scriptPubKey" - <*> o .: "version" + <*> o .:? "version" <*> o .: "coinbase" parseJSON _ = mzero diff --git a/src/Network/Bitcoin/RawTransaction.hs b/src/Network/Bitcoin/RawTransaction.hs index 00f38fc..0883759 100644 --- a/src/Network/Bitcoin/RawTransaction.hs +++ b/src/Network/Bitcoin/RawTransaction.hs @@ -241,9 +241,9 @@ instance FromJSON UnspentTransaction where -- Instance used in 'createRawTransaction'. instance ToJSON UnspentTransaction where - toJSON (UnspentTransaction{..}) = object [ "txid" .= unspentTransactionId - , "vout" .= outIdx - ] + toJSON UnspentTransaction{..} = object [ "txid" .= unspentTransactionId + , "vout" .= outIdx + ] -- | Returns an array of unspent transaction outputs with between minconf and -- maxconf (inclusive) confirmations. If addresses are given, the result will @@ -306,7 +306,7 @@ decodeRawTransaction client tx = callApi client "decoderawtransaction" [ tj tx ] newtype UnspentForSigning = UFS UnspentTransaction instance ToJSON UnspentForSigning where - toJSON (UFS (UnspentTransaction{..})) + toJSON (UFS UnspentTransaction{..}) | isNothing redeemScript = object [ "txid" .= unspentTransactionId , "vout" .= outIdx diff --git a/src/Network/Bitcoin/Wallet.hs b/src/Network/Bitcoin/Wallet.hs index 02908b6..f68f3db 100644 --- a/src/Network/Bitcoin/Wallet.hs +++ b/src/Network/Bitcoin/Wallet.hs @@ -65,7 +65,6 @@ module Network.Bitcoin.Wallet ( Client , isAddressValid ) where -import Control.Applicative (liftA2) import Control.Monad import Data.Aeson as A import Data.Aeson.Types (parseEither) @@ -78,7 +77,7 @@ import Data.Text import Data.Time.Clock.POSIX import Data.Vector as V hiding ((++)) import Data.Word -import Network.Bitcoin.BlockChain (BlockHash, BlockHeight) +import Network.Bitcoin.BlockChain (BlockHash) import Network.Bitcoin.Internal import Network.Bitcoin.RawTransaction (RawTransaction) @@ -770,7 +769,7 @@ instance ToJSON EstimationMode where -- | Estimate the fee per kb to send a transaction -estimateSmartFee :: Client -> Word32 -> Maybe EstimationMode -> IO (Either [String] (Double, BlockHeight)) +estimateSmartFee :: Client -> Word32 -> Maybe EstimationMode -> IO (Either [String] Double) estimateSmartFee client target mode = parse <$> callApi client "estimatesmartfee" (catMaybes [ Just $ tj target, tj <$> mode ]) where @@ -779,4 +778,4 @@ estimateSmartFee client target mode = merrs <- obj .:? "errors" flip (maybe (parseVals obj)) merrs $ \errs -> bool (pure $ Left errs) (parseVals obj) . List.null $ errs - parseVals = fmap Right . (liftA2 (,) <$> (.: "feerate") <*> (.: "blocks")) + parseVals = fmap Right . (.: "feerate")