network-bitcoin 1.0.1 → 1.0.2
raw patch · 6 files changed
+28/−47 lines, 6 filesdep −attoparsecdep −unordered-containersdep ~aeson
Dependencies removed: attoparsec, unordered-containers
Dependency ranges changed: aeson
Files
- network-bitcoin.cabal +2/−4
- src/Network/Bitcoin.hs +1/−1
- src/Network/Bitcoin/BlockChain.hs +2/−2
- src/Network/Bitcoin/Internal.hs +1/−18
- src/Network/Bitcoin/RawTransaction.hs +2/−2
- src/Network/Bitcoin/Wallet.hs +20/−20
network-bitcoin.cabal view
@@ -1,5 +1,5 @@ Name: network-bitcoin-Version: 1.0.1+Version: 1.0.2 Synopsis: An interface to bitcoind. Description: This can be used to send Bitcoins, query balances, etc. It@@ -66,10 +66,8 @@ -- Packages needed in order to build this package. Build-depends: - aeson == 0.6.*,+ aeson >= 0.6.1, bytestring >= 0.10,- attoparsec == 0.10.*,- unordered-containers >= 0.2, HTTP >= 4000, network >= 2.3, text >= 0.11,
src/Network/Bitcoin.hs view
@@ -72,7 +72,7 @@ , getAccountAddress , getAccount , setAccount- , getAddressByAccount+ , getAddressesByAccount , sendToAddress , AddressInfo(..) , listAddressGroupings
src/Network/Bitcoin/BlockChain.hs view
@@ -42,7 +42,7 @@ -- rejected. setTransactionFee :: Auth -> BTC -> IO () setTransactionFee auth fee =- stupidAPI <$> callApi auth "settxfee" [ tj $ WBTC fee ]+ stupidAPI <$> callApi auth "settxfee" [ tj fee ] where stupidAPI :: Bool -> () stupidAPI = const () @@ -150,7 +150,7 @@ instance FromJSON OutputInfo where parseJSON (Object o) = OutputInfo <$> o .: "bestblock" <*> o .: "confirmations"- <*> (unwrapBTC <$> o .: "amount")+ <*> o .: "amount" <*> o .: "scriptPubKey" <*> o .: "version" <*> o .: "coinbase"
src/Network/Bitcoin/Internal.hs view
@@ -17,16 +17,13 @@ , callApi , callApi' , tj- , WrappedBTC(..) , AddrAddress(..) ) where import Control.Applicative-import Control.Arrow import Control.Exception import Control.Monad import Data.Aeson-import Data.Attoparsec.Number import Data.Maybe import Data.Vector ( Vector ) import qualified Data.Vector as V@@ -139,25 +136,11 @@ tj = toJSON {-# INLINE tj #-} --- | Used to provide a FromJSON instance for fixed-point bitcoins.--- This can be removed after <https://github.com/bos/aeson/pull/89> gets--- merged into master, and is released on Hackage.-data WrappedBTC = WBTC { unwrapBTC :: BTC }--instance FromJSON WrappedBTC where- parseJSON (Number n) = pure . WBTC $ case n of- D d -> realToFrac d- I i -> fromIntegral i- parseJSON _ = mzero--instance ToJSON WrappedBTC where- toJSON (WBTC btc) = toJSON $ toRational btc- -- | A wrapper for a vector of address:amount pairs. The RPC expects that as -- an object of "address":"amount" pairs, instead of a vector. So that's what -- we give them with AddrAddress's ToJSON. newtype AddrAddress = AA (Vector (Address, BTC)) instance ToJSON AddrAddress where- toJSON (AA vec) = object . V.toList $ uncurry (.=) . second WBTC <$> vec+ toJSON (AA vec) = object . V.toList $ uncurry (.=) <$> vec
src/Network/Bitcoin/RawTransaction.hs view
@@ -134,7 +134,7 @@ deriving ( Show, Read, Ord, Eq ) instance FromJSON TxOut where- parseJSON (Object o) = TxOut <$> (unwrapBTC <$> o .: "value")+ parseJSON (Object o) = TxOut <$> o .: "value" <*> o .: "scriptPubKey" parseJSON _ = mzero @@ -213,7 +213,7 @@ <*> o .: "vout" <*> o .: "scriptPubKey" <*> o .:? "redeemScript"- <*> (unwrapBTC <$> o .: "amount")+ <*> o .: "amount" <*> o .: "confirmations" parseJSON _ = mzero
src/Network/Bitcoin/Wallet.hs view
@@ -17,7 +17,7 @@ , getAccountAddress , getAccount , setAccount- , getAddressByAccount+ , getAddressesByAccount , sendToAddress , AddressInfo(..) , listAddressGroupings@@ -102,7 +102,7 @@ parseJSON (Object o) = BitcoindInfo <$> o .: "version" <*> o .: "protocolversion" <*> o .: "walletversion"- <*> (unwrapBTC <$> o .: "balance")+ <*> o .: "balance" <*> o .: "blocks" <*> o .: "connections" <*> o .: "proxy"@@ -110,7 +110,7 @@ <*> o .: "testnet" <*> o .: "keypoololddest" <*> o .: "keypoolsize"- <*> (unwrapBTC <$> o .: "paytxfee")+ <*> o .: "paytxfee" <*> o .:? "unlocked_until" <*> o .: "errors" parseJSON _ = mzero@@ -145,8 +145,8 @@ getAccount auth addr = callApi auth "getaccount" [ tj addr ] -- | Returns the list of addresses for the given address.-getAddressByAccount :: Auth -> Account -> IO (Vector Address)-getAddressByAccount auth acc = callApi auth "getaddressbyaccount" [ tj acc ]+getAddressesByAccount :: Auth -> Account -> IO (Vector Address)+getAddressesByAccount auth acc = callApi auth "getAddressesByAccount" [ tj acc ] -- | Sends some bitcoins to an address. sendToAddress :: Auth@@ -161,7 +161,7 @@ -- transaction. -> IO TransactionID sendToAddress auth addr amount comm comm2 =- callApi auth "sendtoaddress" [ tj addr, tj $ WBTC amount, tj comm, tj comm2 ]+ callApi auth "sendtoaddress" [ tj addr, tj amount, tj comm, tj comm2 ] -- | Information on a given address. data AddressInfo = AddressInfo { -- | The address in question.@@ -176,10 +176,10 @@ -- | What a silly API. instance FromJSON AddressInfo where parseJSON (A.Array a) | V.length a == 2 = AddressInfo <$> parseJSON (a ! 0)- <*> (unwrapBTC <$> parseJSON (a ! 1))+ <*> parseJSON (a ! 1) <*> pure Nothing | V.length a == 3 = AddressInfo <$> parseJSON (a ! 0)- <*> (unwrapBTC <$> parseJSON (a ! 1))+ <*> parseJSON (a ! 1) <*> (Just <$> parseJSON (a ! 2)) | otherwise = mzero parseJSON _ = mzero@@ -221,7 +221,7 @@ -- confirmation. getReceivedByAddress :: Auth -> Address -> IO BTC getReceivedByAddress auth addr =- unwrapBTC <$> callApi auth "getreceivedbyaddress" [ tj addr ]+ callApi auth "getreceivedbyaddress" [ tj addr ] -- | Returns the total amount received by the given address, with at least the -- give number of confirmations.@@ -232,12 +232,12 @@ -- total. -> IO BTC getReceivedByAddress' auth addr minconf =- unwrapBTC <$> callApi auth "getreceivedbyaddress" [ tj addr, tj minconf ]+ callApi auth "getreceivedbyaddress" [ tj addr, tj minconf ] -- | Returns the total amount received by address with the given account. getReceivedByAccount :: Auth -> Account -> IO BTC getReceivedByAccount auth acc =- unwrapBTC <$> callApi auth "getreceivedbyaccount" [ tj acc ]+ callApi auth "getreceivedbyaccount" [ tj acc ] -- | Returns the total amount received by addresses with the given account, -- counting only transactions with the given minimum number of confirmations.@@ -249,13 +249,13 @@ -- transaction to count towards the total. -> IO BTC getReceivedByAccount' auth acc minconf =- unwrapBTC <$> callApi auth "getreceivedbyaccount" [ tj acc, tj minconf ]+ callApi auth "getreceivedbyaccount" [ tj acc, tj minconf ] -- | Returns the server's total available balance. getBalance :: Auth -> IO BTC getBalance auth =- unwrapBTC <$> callApi auth "getbalance" []+ callApi auth "getbalance" [] -- | Returns the balance in the given account, counting only transactions with -- at least one confirmation.@@ -263,7 +263,7 @@ -> Account -> IO BTC getBalance' auth acc =- unwrapBTC <$> callApi auth "getbalance" [ tj acc ]+ callApi auth "getbalance" [ tj acc ] -- | Returns the balance in the given account, counting only transactions with -- at least the given number of confirmations.@@ -271,10 +271,10 @@ -> Account -> Int -- ^ The minimum number of confirmations needed for a transaction- -- to cuont towards the total.+ -- to count towards the total. -> IO BTC getBalance'' auth acc minconf =- unwrapBTC <$> callApi auth "getbalance" [ tj acc, tj minconf ]+ callApi auth "getbalance" [ tj acc, tj minconf ] -- | Move bitcoins from one account in your wallet to another. --@@ -287,7 +287,7 @@ -> Text -- ^ A comment to record for the transaction. -> IO () moveBitcoins auth from to amt comm =- stupidAPI <$> callApi auth "move" [ tj from, tj to, tj $ WBTC amt, tj one, tj comm ]+ stupidAPI <$> callApi auth "move" [ tj from, tj to, tj amt, tj one, tj comm ] where one = 1 :: Int -- needs a type, else default-integer warnings. stupidAPI :: Bool -> () stupidAPI = const ()@@ -308,7 +308,7 @@ -- ^ An optional comment on who the money is going to. -> IO TransactionID sendFromAccount auth from to amount comm comm2 =- callApi auth "sendfrom" [ tj from, tj to, tj $ WBTC amount, tj one, tj comm, tj comm2 ]+ callApi auth "sendfrom" [ tj from, tj to, tj amount, tj one, tj comm, tj comm2 ] where one = 1 :: Int -- needs a type, else default-integer warnings. -- | Send to a whole bunch of address at once.@@ -345,7 +345,7 @@ instance FromJSON ReceivedByAddress where parseJSON (Object o) = ReceivedByAddress <$> o .: "address" <*> o .: "account"- <*> (unwrapBTC <$> o .: "amount")+ <*> o .: "amount" <*> o .: "confirmations" parseJSON _ = mzero @@ -381,7 +381,7 @@ instance FromJSON ReceivedByAccount where parseJSON (Object o) = ReceivedByAccount <$> o .: "account"- <*> (unwrapBTC <$> o .: "amount")+ <*> o .: "amount" <*> o .: "confirmations" parseJSON _ = mzero