packages feed

network-bitcoin 0.1.5 → 1.0.0

raw patch · 13 files changed

+1714/−362 lines, 13 filesdep +unordered-containersdep +vectordep −containersdep ~aesondep ~attoparsecdep ~bytestringsetup-changednew-uploaderPVP ok

version bump matches the API change (PVP)

Dependencies added: unordered-containers, vector

Dependencies removed: containers

Dependency ranges changed: aeson, attoparsec, bytestring

API changes (from Hackage documentation)

- Network.Bitcoin: account :: AddressValidation -> Account
- Network.Bitcoin: callApi :: Auth -> String -> [Value] -> IO Value
- Network.Bitcoin: class FromNumber a
- Network.Bitcoin: data Address
- Network.Bitcoin: data AddressValidation
- Network.Bitcoin: fromNumber :: FromNumber a => Number -> a
- Network.Bitcoin: instance Exception BitcoinException
- Network.Bitcoin: instance FromJSON BitcoinRpcResponse
- Network.Bitcoin: instance FromNumber Amount
- Network.Bitcoin: instance FromNumber Double
- Network.Bitcoin: instance FromNumber Integer
- Network.Bitcoin: instance HasResolution Satoshi
- Network.Bitcoin: instance Show AddressValidation
- Network.Bitcoin: instance Show Auth
- Network.Bitcoin: instance Show BitcoinException
- Network.Bitcoin: instance Show BitcoinRpcResponse
- Network.Bitcoin: instance ToValue Account
- Network.Bitcoin: instance ToValue Address
- Network.Bitcoin: instance ToValue MinConf
- Network.Bitcoin: instance Typeable BitcoinException
- Network.Bitcoin: isMine :: AddressValidation -> Bool
- Network.Bitcoin: isValid :: AddressValidation -> Bool
- Network.Bitcoin: isValidAddress :: Auth -> Address -> IO Bool
- Network.Bitcoin: mkAddress :: String -> Maybe Address
- Network.Bitcoin: type Amount = Fixed Satoshi
- Network.Bitcoin: type MinConf = Integer
- Network.Bitcoin: validateAddress :: Auth -> Address -> IO AddressValidation
- Network.Bitcoin.Address: data Address
- Network.Bitcoin.Address: instance Show Address
- Network.Bitcoin.Address: mkAddress :: String -> Maybe Address
+ Network.Bitcoin: AddressInfo :: Address -> BTC -> Maybe Account -> AddressInfo
+ Network.Bitcoin: All :: WhoCanPay
+ Network.Bitcoin: AllOrAnyoneCanPay :: WhoCanPay
+ Network.Bitcoin: BitcoinResultTypeError :: ByteString -> BitcoinException
+ Network.Bitcoin: BitcoindInfo :: Integer -> Integer -> Integer -> BTC -> Integer -> Integer -> Text -> Double -> Bool -> Integer -> Integer -> BTC -> Maybe Integer -> Text -> BitcoindInfo
+ Network.Bitcoin: Block :: BlockHash -> Integer -> Integer -> Integer -> Integer -> BlockHash -> Vector TransactionID -> Integer -> Integer -> HexString -> Integer -> Maybe BlockHash -> Maybe BlockHash -> Block
+ Network.Bitcoin: BlockTemplate :: Integer -> HexString -> Vector Transaction -> CoinBaseAux -> Integer -> HexString -> Integer -> HexString -> Integer -> Integer -> Integer -> HexString -> Integer -> BlockTemplate
+ Network.Bitcoin: CoinBaseAux :: HexString -> CoinBaseAux
+ Network.Bitcoin: ConfirmedBlock :: Integer -> Integer -> Integer -> BlockInfo
+ Network.Bitcoin: DecodedRawTransaction :: RawTransaction -> Integer -> Integer -> Vector TxIn -> Vector TxOut -> DecodedRawTransaction
+ Network.Bitcoin: HashData :: HexString -> HexString -> HashData
+ Network.Bitcoin: MiningInfo :: Integer -> Integer -> Integer -> Double -> Text -> Bool -> Integer -> Integer -> Integer -> Bool -> MiningInfo
+ Network.Bitcoin: NonStandardScriptPubKey :: HexString -> HexString -> ScriptPubKey
+ Network.Bitcoin: None :: WhoCanPay
+ Network.Bitcoin: NoneOrAnyoneCanPay :: WhoCanPay
+ Network.Bitcoin: OutputInfo :: BlockHash -> Integer -> BTC -> ScriptSig -> Integer -> Bool -> OutputInfo
+ Network.Bitcoin: OutputSetInfo :: BlockHash -> Integer -> Integer -> Integer -> OutputSetInfo
+ Network.Bitcoin: PeerInfo :: Text -> Text -> Integer -> Integer -> Integer -> Integer -> Integer -> Bool -> Integer -> Integer -> Integer -> PeerInfo
+ Network.Bitcoin: RawSignedTransaction :: HexString -> Bool -> RawSignedTransaction
+ Network.Bitcoin: RawTransactionInfo :: RawTransaction -> Integer -> Integer -> Vector TxIn -> Vector TxOut -> HexString -> BlockInfo -> RawTransactionInfo
+ Network.Bitcoin: ReceivedByAccount :: Account -> BTC -> Integer -> ReceivedByAccount
+ Network.Bitcoin: ReceivedByAddress :: Address -> Account -> BTC -> Integer -> ReceivedByAddress
+ Network.Bitcoin: Single :: WhoCanPay
+ Network.Bitcoin: SingleOrAnyoneCanPay :: WhoCanPay
+ Network.Bitcoin: StandardScriptPubKey :: HexString -> HexString -> Integer -> TxnOutputType -> Vector Address -> ScriptPubKey
+ Network.Bitcoin: Transaction :: HexString -> HexString -> Vector Integer -> Maybe Integer -> Integer -> Transaction
+ Network.Bitcoin: TxCoinbase :: HexString -> TxIn
+ Network.Bitcoin: TxIn :: TransactionID -> Integer -> ScriptSig -> Integer -> TxIn
+ Network.Bitcoin: TxOut :: BTC -> ScriptPubKey -> TxOut
+ Network.Bitcoin: TxnMultisig :: TxnOutputType
+ Network.Bitcoin: TxnPubKey :: TxnOutputType
+ Network.Bitcoin: TxnPubKeyHash :: TxnOutputType
+ Network.Bitcoin: TxnScriptHash :: TxnOutputType
+ Network.Bitcoin: UnconfirmedBlock :: BlockInfo
+ Network.Bitcoin: UnspentTransaction :: TransactionID -> Integer -> HexString -> Maybe HexString -> BTC -> Integer -> UnspentTransaction
+ Network.Bitcoin: addressName :: PeerInfo -> Text
+ Network.Bitcoin: aiAccount :: AddressInfo -> Maybe Account
+ Network.Bitcoin: aiAddress :: AddressInfo -> Address
+ Network.Bitcoin: aiAmount :: AddressInfo -> BTC
+ Network.Bitcoin: backupWallet :: Auth -> FilePath -> IO ()
+ Network.Bitcoin: balance :: BitcoindInfo -> BTC
+ Network.Bitcoin: banScore :: PeerInfo -> Integer
+ Network.Bitcoin: bitcoinVersion :: BitcoindInfo -> Integer
+ Network.Bitcoin: bitcoindErrors :: BitcoindInfo -> Text
+ Network.Bitcoin: blkBits :: Block -> HexString
+ Network.Bitcoin: blkConfirmations :: Block -> Integer
+ Network.Bitcoin: blkDifficulty :: Block -> Integer
+ Network.Bitcoin: blkHeight :: Block -> Integer
+ Network.Bitcoin: blkNonce :: Block -> Integer
+ Network.Bitcoin: blkSize :: Block -> Integer
+ Network.Bitcoin: blkTime :: Block -> Integer
+ Network.Bitcoin: blkVersion :: Block -> Integer
+ Network.Bitcoin: blockData :: HashData -> HexString
+ Network.Bitcoin: blockHash :: Block -> BlockHash
+ Network.Bitcoin: blockTime :: BlockInfo -> Integer
+ Network.Bitcoin: blockVersion :: BlockTemplate -> Integer
+ Network.Bitcoin: btBits :: BlockTemplate -> HexString
+ Network.Bitcoin: btHeight :: BlockTemplate -> Integer
+ Network.Bitcoin: btTarget :: BlockTemplate -> HexString
+ Network.Bitcoin: cbFlags :: CoinBaseAux -> HexString
+ Network.Bitcoin: cbTime :: BlockInfo -> Integer
+ Network.Bitcoin: changePassword :: Auth -> Text -> Text -> IO ()
+ Network.Bitcoin: coinBaseAux :: BlockTemplate -> CoinBaseAux
+ Network.Bitcoin: coinBaseValue :: BlockTemplate -> Integer
+ Network.Bitcoin: confirmations :: BlockInfo -> Integer
+ Network.Bitcoin: connectionTime :: PeerInfo -> Integer
+ Network.Bitcoin: createRawTransaction :: Auth -> Vector UnspentTransaction -> Vector (Address, BTC) -> IO HexString
+ Network.Bitcoin: curTime :: BlockTemplate -> Integer
+ Network.Bitcoin: currentBlockSize :: MiningInfo -> Integer
+ Network.Bitcoin: currentBlockTransaction :: MiningInfo -> Integer
+ Network.Bitcoin: data AddressInfo
+ Network.Bitcoin: data BitcoindInfo
+ Network.Bitcoin: data Block
+ Network.Bitcoin: data BlockInfo
+ Network.Bitcoin: data BlockTemplate
+ Network.Bitcoin: data CoinBaseAux
+ Network.Bitcoin: data DecodedRawTransaction
+ Network.Bitcoin: data HashData
+ Network.Bitcoin: data MiningInfo
+ Network.Bitcoin: data OutputInfo
+ Network.Bitcoin: data OutputSetInfo
+ Network.Bitcoin: data PeerInfo
+ Network.Bitcoin: data RawSignedTransaction
+ Network.Bitcoin: data RawTransactionInfo
+ Network.Bitcoin: data ReceivedByAccount
+ Network.Bitcoin: data ReceivedByAddress
+ Network.Bitcoin: data ScriptPubKey
+ Network.Bitcoin: data ScriptSig
+ Network.Bitcoin: data Transaction
+ Network.Bitcoin: data TxIn
+ Network.Bitcoin: data TxOut
+ Network.Bitcoin: data TxnOutputType
+ Network.Bitcoin: data UnspentTransaction
+ Network.Bitcoin: data WhoCanPay
+ Network.Bitcoin: decRaw :: DecodedRawTransaction -> RawTransaction
+ Network.Bitcoin: decTxnLockTime :: DecodedRawTransaction -> Integer
+ Network.Bitcoin: decTxnVersion :: DecodedRawTransaction -> Integer
+ Network.Bitcoin: decVin :: DecodedRawTransaction -> Vector TxIn
+ Network.Bitcoin: decVout :: DecodedRawTransaction -> Vector TxOut
+ Network.Bitcoin: decodeRawTransaction :: Auth -> RawTransaction -> IO DecodedRawTransaction
+ Network.Bitcoin: depends :: Transaction -> Vector Integer
+ Network.Bitcoin: difficulty :: MiningInfo -> Double
+ Network.Bitcoin: dumpPrivateKey :: Auth -> Address -> IO PrivateKey
+ Network.Bitcoin: encryptWallet :: Auth -> Text -> IO ()
+ Network.Bitcoin: generationDifficulty :: BitcoindInfo -> Double
+ Network.Bitcoin: generationProcessorLimit :: MiningInfo -> Integer
+ Network.Bitcoin: getAccount :: Auth -> Address -> IO Account
+ Network.Bitcoin: getAccountAddress :: Auth -> Account -> IO Address
+ Network.Bitcoin: getAddressByAccount :: Auth -> Account -> IO (Vector Address)
+ Network.Bitcoin: getBalance' :: Auth -> Account -> IO BTC
+ Network.Bitcoin: getBalance'' :: Auth -> Account -> Int -> IO BTC
+ Network.Bitcoin: getBitcoindInfo :: Auth -> IO BitcoindInfo
+ Network.Bitcoin: getBlock :: Auth -> BlockHash -> IO Block
+ Network.Bitcoin: getBlockHash :: Auth -> Integer -> IO BlockHash
+ Network.Bitcoin: getBlockTemplate :: Auth -> IO BlockTemplate
+ Network.Bitcoin: getMiningInfo :: Auth -> IO MiningInfo
+ Network.Bitcoin: getNewAddress :: Auth -> Maybe Account -> IO Address
+ Network.Bitcoin: getOutputInfo :: Auth -> TransactionID -> Integer -> IO OutputInfo
+ Network.Bitcoin: getOutputSetInfo :: Auth -> IO OutputSetInfo
+ Network.Bitcoin: getPeerInfo :: Auth -> IO PeerInfo
+ Network.Bitcoin: getRawMemoryPool :: Auth -> IO (Vector TransactionID)
+ Network.Bitcoin: getRawTransaction :: Auth -> TransactionID -> IO RawTransaction
+ Network.Bitcoin: getRawTransactionInfo :: Auth -> TransactionID -> IO RawTransactionInfo
+ Network.Bitcoin: getReceivedByAccount' :: Auth -> Account -> Int -> IO BTC
+ Network.Bitcoin: getReceivedByAddress' :: Auth -> Address -> Int -> IO BTC
+ Network.Bitcoin: getWork :: Auth -> IO HashData
+ Network.Bitcoin: hasCompleteSigSet :: RawSignedTransaction -> Bool
+ Network.Bitcoin: hashesPerSecond :: MiningInfo -> Integer
+ Network.Bitcoin: hdTarget :: HashData -> HexString
+ Network.Bitcoin: importPrivateKey :: Auth -> PrivateKey -> Maybe Account -> IO ()
+ Network.Bitcoin: inbound :: PeerInfo -> Bool
+ Network.Bitcoin: isAddressValid :: Auth -> Address -> IO Bool
+ Network.Bitcoin: isGenerating :: MiningInfo -> Bool
+ Network.Bitcoin: keyPoolOldest :: BitcoindInfo -> Integer
+ Network.Bitcoin: keyPoolRefill :: Auth -> IO ()
+ Network.Bitcoin: keyPoolSize :: BitcoindInfo -> Integer
+ Network.Bitcoin: lastRecv :: PeerInfo -> Integer
+ Network.Bitcoin: lastSend :: PeerInfo -> Integer
+ Network.Bitcoin: listAddressGroupings :: Auth -> IO (Vector (Vector AddressInfo))
+ Network.Bitcoin: listReceivedByAccount :: Auth -> IO (Vector ReceivedByAccount)
+ Network.Bitcoin: listReceivedByAccount' :: Auth -> Int -> Bool -> IO (Vector ReceivedByAccount)
+ Network.Bitcoin: listReceivedByAddress :: Auth -> IO (Vector ReceivedByAddress)
+ Network.Bitcoin: listReceivedByAddress' :: Auth -> Int -> Bool -> IO (Vector ReceivedByAddress)
+ Network.Bitcoin: listUnspent :: Auth -> Maybe Int -> Maybe Int -> Vector Address -> IO (Vector UnspentTransaction)
+ Network.Bitcoin: lockWallet :: Auth -> IO ()
+ Network.Bitcoin: merkleRoot :: Block -> BlockHash
+ Network.Bitcoin: minTime :: BlockTemplate -> Integer
+ Network.Bitcoin: miningErrors :: MiningInfo -> Text
+ Network.Bitcoin: miningOnTestNetwork :: MiningInfo -> Bool
+ Network.Bitcoin: moveBitcoins :: Auth -> Account -> Account -> BTC -> Text -> IO ()
+ Network.Bitcoin: nBlocks :: MiningInfo -> Integer
+ Network.Bitcoin: nextBlock :: Block -> Maybe BlockHash
+ Network.Bitcoin: nonceRange :: BlockTemplate -> HexString
+ Network.Bitcoin: nspkAsm :: ScriptPubKey -> HexString
+ Network.Bitcoin: nspkHex :: ScriptPubKey -> HexString
+ Network.Bitcoin: numBlocks :: BitcoindInfo -> Integer
+ Network.Bitcoin: numConnections :: BitcoindInfo -> Integer
+ Network.Bitcoin: numOut :: TxIn -> Integer
+ Network.Bitcoin: numTransactions :: OutputSetInfo -> Integer
+ Network.Bitcoin: oiAmount :: OutputInfo -> BTC
+ Network.Bitcoin: oiBestBlock :: OutputInfo -> BlockHash
+ Network.Bitcoin: oiCoinBase :: OutputInfo -> Bool
+ Network.Bitcoin: oiConfirmations :: OutputInfo -> Integer
+ Network.Bitcoin: oiScriptPubKey :: OutputInfo -> ScriptSig
+ Network.Bitcoin: oiVersion :: OutputInfo -> Integer
+ Network.Bitcoin: onTestNetwork :: BitcoindInfo -> Bool
+ Network.Bitcoin: osiBestBlock :: OutputSetInfo -> BlockHash
+ Network.Bitcoin: outIdx :: UnspentTransaction -> Integer
+ Network.Bitcoin: peerSubversion :: PeerInfo -> Integer
+ Network.Bitcoin: peerVersion :: PeerInfo -> Integer
+ Network.Bitcoin: pooledTransactions :: MiningInfo -> Integer
+ Network.Bitcoin: prevBlock :: Block -> Maybe BlockHash
+ Network.Bitcoin: previousBlockHash :: BlockTemplate -> HexString
+ Network.Bitcoin: protocolVersion :: BitcoindInfo -> Integer
+ Network.Bitcoin: proxy :: BitcoindInfo -> Text
+ Network.Bitcoin: raccAccount :: ReceivedByAccount -> Account
+ Network.Bitcoin: raccAmount :: ReceivedByAccount -> BTC
+ Network.Bitcoin: raccNumConfirmations :: ReceivedByAccount -> Integer
+ Network.Bitcoin: raw :: RawTransactionInfo -> RawTransaction
+ Network.Bitcoin: rawBlockInfo :: RawTransactionInfo -> BlockInfo
+ Network.Bitcoin: rawSigned :: RawSignedTransaction -> HexString
+ Network.Bitcoin: rawTxBlockHash :: RawTransactionInfo -> HexString
+ Network.Bitcoin: recvAccount :: ReceivedByAddress -> Account
+ Network.Bitcoin: recvAddress :: ReceivedByAddress -> Address
+ Network.Bitcoin: recvAmount :: ReceivedByAddress -> BTC
+ Network.Bitcoin: recvNumConfirmations :: ReceivedByAddress -> Integer
+ Network.Bitcoin: redeemScript :: UnspentTransaction -> Maybe HexString
+ Network.Bitcoin: releaseTime :: PeerInfo -> Integer
+ Network.Bitcoin: requiredSigs :: ScriptPubKey -> Integer
+ Network.Bitcoin: scriptPubKey :: TxOut -> ScriptPubKey
+ Network.Bitcoin: scriptSig :: TxIn -> ScriptSig
+ Network.Bitcoin: sendFromAccount :: Auth -> Account -> Address -> BTC -> Maybe Text -> Maybe Text -> IO TransactionID
+ Network.Bitcoin: sendMany :: Auth -> Account -> Vector (Address, BTC) -> Maybe Text -> IO TransactionID
+ Network.Bitcoin: sendRawTransaction :: Auth -> RawTransaction -> IO TransactionID
+ Network.Bitcoin: sendToAddress :: Auth -> Address -> BTC -> Maybe Text -> Maybe Text -> IO TransactionID
+ Network.Bitcoin: serializedSize :: OutputSetInfo -> Integer
+ Network.Bitcoin: services :: PeerInfo -> Text
+ Network.Bitcoin: setAccount :: Auth -> Address -> Account -> IO ()
+ Network.Bitcoin: setGenerate :: Auth -> Bool -> Maybe Int -> IO ()
+ Network.Bitcoin: setTransactionFee :: Auth -> BTC -> IO ()
+ Network.Bitcoin: sigOps :: Transaction -> Integer
+ Network.Bitcoin: signMessage :: Auth -> Address -> Text -> IO Signature
+ Network.Bitcoin: signRawTransaction :: Auth -> RawTransaction -> Maybe (Vector UnspentTransaction) -> Maybe (Vector HexString) -> Maybe WhoCanPay -> IO RawSignedTransaction
+ Network.Bitcoin: sigopLimit :: BlockTemplate -> Integer
+ Network.Bitcoin: sizeLimit :: BlockTemplate -> Integer
+ Network.Bitcoin: solveBlock :: Auth -> HexString -> IO Bool
+ Network.Bitcoin: sspkAddresses :: ScriptPubKey -> Vector Address
+ Network.Bitcoin: sspkAsm :: ScriptPubKey -> HexString
+ Network.Bitcoin: sspkHex :: ScriptPubKey -> HexString
+ Network.Bitcoin: sspkType :: ScriptPubKey -> TxnOutputType
+ Network.Bitcoin: startingHeight :: PeerInfo -> Integer
+ Network.Bitcoin: subTransactions :: Block -> Vector TransactionID
+ Network.Bitcoin: submitBlock :: Auth -> HexString -> IO Bool
+ Network.Bitcoin: transactionFeePaid :: BitcoindInfo -> BTC
+ Network.Bitcoin: transactionOutputs :: OutputSetInfo -> Integer
+ Network.Bitcoin: transactionsToInclude :: BlockTemplate -> Vector Transaction
+ Network.Bitcoin: txCoinbase :: TxIn -> HexString
+ Network.Bitcoin: txInId :: TxIn -> TransactionID
+ Network.Bitcoin: txSequence :: TxIn -> Integer
+ Network.Bitcoin: txnData :: Transaction -> HexString
+ Network.Bitcoin: txnFee :: Transaction -> Maybe Integer
+ Network.Bitcoin: txnHash :: Transaction -> HexString
+ Network.Bitcoin: txnLockTime :: RawTransactionInfo -> Integer
+ Network.Bitcoin: txnVersion :: RawTransactionInfo -> Integer
+ Network.Bitcoin: txoutVal :: TxOut -> BTC
+ Network.Bitcoin: type Address = HexString
+ Network.Bitcoin: type BTC = Fixed Satoshi
+ Network.Bitcoin: type BlockHash = HexString
+ Network.Bitcoin: type HexString = Text
+ Network.Bitcoin: type RawTransaction = HexString
+ Network.Bitcoin: type Signature = HexString
+ Network.Bitcoin: type TransactionID = HexString
+ Network.Bitcoin: unlockWallet :: Auth -> Text -> Integer -> IO ()
+ Network.Bitcoin: unlockedUntil :: BitcoindInfo -> Maybe Integer
+ Network.Bitcoin: unspentAmount :: UnspentTransaction -> BTC
+ Network.Bitcoin: unspentScriptPubKey :: UnspentTransaction -> HexString
+ Network.Bitcoin: unspentTransactionId :: UnspentTransaction -> TransactionID
+ Network.Bitcoin: usConfirmations :: UnspentTransaction -> Integer
+ Network.Bitcoin: verifyMessage :: Auth -> Address -> Signature -> Text -> IO Bool
+ Network.Bitcoin: vin :: RawTransactionInfo -> Vector TxIn
+ Network.Bitcoin: vout :: RawTransactionInfo -> Vector TxOut
+ Network.Bitcoin: walletVersion :: BitcoindInfo -> Integer
+ Network.Bitcoin.BlockChain: Auth :: Text -> Text -> Text -> Auth
+ Network.Bitcoin.BlockChain: Block :: BlockHash -> Integer -> Integer -> Integer -> Integer -> BlockHash -> Vector TransactionID -> Integer -> Integer -> HexString -> Integer -> Maybe BlockHash -> Maybe BlockHash -> Block
+ Network.Bitcoin.BlockChain: OutputInfo :: BlockHash -> Integer -> BTC -> ScriptSig -> Integer -> Bool -> OutputInfo
+ Network.Bitcoin.BlockChain: OutputSetInfo :: BlockHash -> Integer -> Integer -> Integer -> OutputSetInfo
+ Network.Bitcoin.BlockChain: ScriptSig :: HexString -> HexString -> ScriptSig
+ Network.Bitcoin.BlockChain: blkBits :: Block -> HexString
+ Network.Bitcoin.BlockChain: blkConfirmations :: Block -> Integer
+ Network.Bitcoin.BlockChain: blkDifficulty :: Block -> Integer
+ Network.Bitcoin.BlockChain: blkHeight :: Block -> Integer
+ Network.Bitcoin.BlockChain: blkNonce :: Block -> Integer
+ Network.Bitcoin.BlockChain: blkSize :: Block -> Integer
+ Network.Bitcoin.BlockChain: blkTime :: Block -> Integer
+ Network.Bitcoin.BlockChain: blkVersion :: Block -> Integer
+ Network.Bitcoin.BlockChain: blockHash :: Block -> BlockHash
+ Network.Bitcoin.BlockChain: data Auth
+ Network.Bitcoin.BlockChain: data Block
+ Network.Bitcoin.BlockChain: data OutputInfo
+ Network.Bitcoin.BlockChain: data OutputSetInfo
+ Network.Bitcoin.BlockChain: data ScriptSig
+ Network.Bitcoin.BlockChain: getBlock :: Auth -> BlockHash -> IO Block
+ Network.Bitcoin.BlockChain: getBlockCount :: Auth -> IO Integer
+ Network.Bitcoin.BlockChain: getBlockHash :: Auth -> Integer -> IO BlockHash
+ Network.Bitcoin.BlockChain: getDifficulty :: Auth -> IO Integer
+ Network.Bitcoin.BlockChain: getOutputInfo :: Auth -> TransactionID -> Integer -> IO OutputInfo
+ Network.Bitcoin.BlockChain: getOutputSetInfo :: Auth -> IO OutputSetInfo
+ Network.Bitcoin.BlockChain: getRawMemoryPool :: Auth -> IO (Vector TransactionID)
+ Network.Bitcoin.BlockChain: instance Eq Block
+ Network.Bitcoin.BlockChain: instance Eq OutputInfo
+ Network.Bitcoin.BlockChain: instance Eq OutputSetInfo
+ Network.Bitcoin.BlockChain: instance FromJSON Block
+ Network.Bitcoin.BlockChain: instance FromJSON OutputInfo
+ Network.Bitcoin.BlockChain: instance FromJSON OutputSetInfo
+ Network.Bitcoin.BlockChain: instance Ord Block
+ Network.Bitcoin.BlockChain: instance Ord OutputInfo
+ Network.Bitcoin.BlockChain: instance Ord OutputSetInfo
+ Network.Bitcoin.BlockChain: instance Read Block
+ Network.Bitcoin.BlockChain: instance Read OutputInfo
+ Network.Bitcoin.BlockChain: instance Read OutputSetInfo
+ Network.Bitcoin.BlockChain: instance Show Block
+ Network.Bitcoin.BlockChain: instance Show OutputInfo
+ Network.Bitcoin.BlockChain: instance Show OutputSetInfo
+ Network.Bitcoin.BlockChain: merkleRoot :: Block -> BlockHash
+ Network.Bitcoin.BlockChain: nextBlock :: Block -> Maybe BlockHash
+ Network.Bitcoin.BlockChain: numTransactions :: OutputSetInfo -> Integer
+ Network.Bitcoin.BlockChain: oiAmount :: OutputInfo -> BTC
+ Network.Bitcoin.BlockChain: oiBestBlock :: OutputInfo -> BlockHash
+ Network.Bitcoin.BlockChain: oiCoinBase :: OutputInfo -> Bool
+ Network.Bitcoin.BlockChain: oiConfirmations :: OutputInfo -> Integer
+ Network.Bitcoin.BlockChain: oiScriptPubKey :: OutputInfo -> ScriptSig
+ Network.Bitcoin.BlockChain: oiVersion :: OutputInfo -> Integer
+ Network.Bitcoin.BlockChain: osiBestBlock :: OutputSetInfo -> BlockHash
+ Network.Bitcoin.BlockChain: prevBlock :: Block -> Maybe BlockHash
+ Network.Bitcoin.BlockChain: rpcPassword :: Auth -> Text
+ Network.Bitcoin.BlockChain: rpcUrl :: Auth -> Text
+ Network.Bitcoin.BlockChain: rpcUser :: Auth -> Text
+ Network.Bitcoin.BlockChain: serializedSize :: OutputSetInfo -> Integer
+ Network.Bitcoin.BlockChain: setTransactionFee :: Auth -> BTC -> IO ()
+ Network.Bitcoin.BlockChain: sigAsm :: ScriptSig -> HexString
+ Network.Bitcoin.BlockChain: sigHex :: ScriptSig -> HexString
+ Network.Bitcoin.BlockChain: subTransactions :: Block -> Vector TransactionID
+ Network.Bitcoin.BlockChain: transactionOutputs :: OutputSetInfo -> Integer
+ Network.Bitcoin.BlockChain: type BTC = Fixed Satoshi
+ Network.Bitcoin.BlockChain: type BlockHash = HexString
+ Network.Bitcoin.BlockChain: type TransactionID = HexString
+ Network.Bitcoin.Dump: dumpPrivateKey :: Auth -> Address -> IO PrivateKey
+ Network.Bitcoin.Dump: importPrivateKey :: Auth -> PrivateKey -> Maybe Account -> IO ()
+ Network.Bitcoin.Dump: type PrivateKey = Text
+ Network.Bitcoin.Internal: AA :: (Vector (Address, BTC)) -> AddrAddress
+ Network.Bitcoin.Internal: WBTC :: BTC -> WrappedBTC
+ Network.Bitcoin.Internal: callApi :: FromJSON v => Auth -> Text -> [Value] -> IO v
+ Network.Bitcoin.Internal: callApi' :: Auth -> ByteString -> IO ByteString
+ Network.Bitcoin.Internal: class FromJSON a
+ Network.Bitcoin.Internal: data Text :: *
+ Network.Bitcoin.Internal: data Vector a :: * -> *
+ Network.Bitcoin.Internal: data WrappedBTC
+ Network.Bitcoin.Internal: instance Eq BitcoinRpcError
+ Network.Bitcoin.Internal: instance Eq a => Eq (BitcoinRpcResponse a)
+ Network.Bitcoin.Internal: instance FromJSON BitcoinRpcError
+ Network.Bitcoin.Internal: instance FromJSON WrappedBTC
+ Network.Bitcoin.Internal: instance FromJSON a => FromJSON (BitcoinRpcResponse a)
+ Network.Bitcoin.Internal: instance Ord BitcoinRpcError
+ Network.Bitcoin.Internal: instance Ord a => Ord (BitcoinRpcResponse a)
+ Network.Bitcoin.Internal: instance Read BitcoinRpcError
+ Network.Bitcoin.Internal: instance Read a => Read (BitcoinRpcResponse a)
+ Network.Bitcoin.Internal: instance Show BitcoinRpcError
+ Network.Bitcoin.Internal: instance Show a => Show (BitcoinRpcResponse a)
+ Network.Bitcoin.Internal: instance ToJSON AddrAddress
+ Network.Bitcoin.Internal: instance ToJSON WrappedBTC
+ Network.Bitcoin.Internal: newtype AddrAddress
+ Network.Bitcoin.Internal: parseJSON :: FromJSON a => Value -> Parser a
+ Network.Bitcoin.Internal: tj :: ToJSON a => a -> Value
+ Network.Bitcoin.Internal: unwrapBTC :: WrappedBTC -> BTC
+ Network.Bitcoin.Mining: Auth :: Text -> Text -> Text -> Auth
+ Network.Bitcoin.Mining: BlockTemplate :: Integer -> HexString -> Vector Transaction -> CoinBaseAux -> Integer -> HexString -> Integer -> HexString -> Integer -> Integer -> Integer -> HexString -> Integer -> BlockTemplate
+ Network.Bitcoin.Mining: CoinBaseAux :: HexString -> CoinBaseAux
+ Network.Bitcoin.Mining: HashData :: HexString -> HexString -> HashData
+ Network.Bitcoin.Mining: MiningInfo :: Integer -> Integer -> Integer -> Double -> Text -> Bool -> Integer -> Integer -> Integer -> Bool -> MiningInfo
+ Network.Bitcoin.Mining: Transaction :: HexString -> HexString -> Vector Integer -> Maybe Integer -> Integer -> Transaction
+ Network.Bitcoin.Mining: blockData :: HashData -> HexString
+ Network.Bitcoin.Mining: blockVersion :: BlockTemplate -> Integer
+ Network.Bitcoin.Mining: btBits :: BlockTemplate -> HexString
+ Network.Bitcoin.Mining: btHeight :: BlockTemplate -> Integer
+ Network.Bitcoin.Mining: btTarget :: BlockTemplate -> HexString
+ Network.Bitcoin.Mining: cbFlags :: CoinBaseAux -> HexString
+ Network.Bitcoin.Mining: coinBaseAux :: BlockTemplate -> CoinBaseAux
+ Network.Bitcoin.Mining: coinBaseValue :: BlockTemplate -> Integer
+ Network.Bitcoin.Mining: curTime :: BlockTemplate -> Integer
+ Network.Bitcoin.Mining: currentBlockSize :: MiningInfo -> Integer
+ Network.Bitcoin.Mining: currentBlockTransaction :: MiningInfo -> Integer
+ Network.Bitcoin.Mining: data Auth
+ Network.Bitcoin.Mining: data BlockTemplate
+ Network.Bitcoin.Mining: data CoinBaseAux
+ Network.Bitcoin.Mining: data HashData
+ Network.Bitcoin.Mining: data MiningInfo
+ Network.Bitcoin.Mining: data Transaction
+ Network.Bitcoin.Mining: depends :: Transaction -> Vector Integer
+ Network.Bitcoin.Mining: difficulty :: MiningInfo -> Double
+ Network.Bitcoin.Mining: generationProcessorLimit :: MiningInfo -> Integer
+ Network.Bitcoin.Mining: getBlockTemplate :: Auth -> IO BlockTemplate
+ Network.Bitcoin.Mining: getGenerate :: Auth -> IO Bool
+ Network.Bitcoin.Mining: getHashesPerSec :: Auth -> IO Integer
+ Network.Bitcoin.Mining: getMiningInfo :: Auth -> IO MiningInfo
+ Network.Bitcoin.Mining: getWork :: Auth -> IO HashData
+ Network.Bitcoin.Mining: hashesPerSecond :: MiningInfo -> Integer
+ Network.Bitcoin.Mining: hdTarget :: HashData -> HexString
+ Network.Bitcoin.Mining: instance Eq BlockTemplate
+ Network.Bitcoin.Mining: instance Eq CoinBaseAux
+ Network.Bitcoin.Mining: instance Eq HashData
+ Network.Bitcoin.Mining: instance Eq MiningInfo
+ Network.Bitcoin.Mining: instance Eq Transaction
+ Network.Bitcoin.Mining: instance FromJSON BlockTemplate
+ Network.Bitcoin.Mining: instance FromJSON CoinBaseAux
+ Network.Bitcoin.Mining: instance FromJSON HashData
+ Network.Bitcoin.Mining: instance FromJSON MiningInfo
+ Network.Bitcoin.Mining: instance FromJSON StupidReturnValue
+ Network.Bitcoin.Mining: instance FromJSON Transaction
+ Network.Bitcoin.Mining: instance Ord BlockTemplate
+ Network.Bitcoin.Mining: instance Ord CoinBaseAux
+ Network.Bitcoin.Mining: instance Ord HashData
+ Network.Bitcoin.Mining: instance Ord MiningInfo
+ Network.Bitcoin.Mining: instance Ord Transaction
+ Network.Bitcoin.Mining: instance Read BlockTemplate
+ Network.Bitcoin.Mining: instance Read CoinBaseAux
+ Network.Bitcoin.Mining: instance Read HashData
+ Network.Bitcoin.Mining: instance Read MiningInfo
+ Network.Bitcoin.Mining: instance Read Transaction
+ Network.Bitcoin.Mining: instance Show BlockTemplate
+ Network.Bitcoin.Mining: instance Show CoinBaseAux
+ Network.Bitcoin.Mining: instance Show HashData
+ Network.Bitcoin.Mining: instance Show MiningInfo
+ Network.Bitcoin.Mining: instance Show Transaction
+ Network.Bitcoin.Mining: isGenerating :: MiningInfo -> Bool
+ Network.Bitcoin.Mining: minTime :: BlockTemplate -> Integer
+ Network.Bitcoin.Mining: miningErrors :: MiningInfo -> Text
+ Network.Bitcoin.Mining: miningOnTestNetwork :: MiningInfo -> Bool
+ Network.Bitcoin.Mining: nBlocks :: MiningInfo -> Integer
+ Network.Bitcoin.Mining: nonceRange :: BlockTemplate -> HexString
+ Network.Bitcoin.Mining: pooledTransactions :: MiningInfo -> Integer
+ Network.Bitcoin.Mining: previousBlockHash :: BlockTemplate -> HexString
+ Network.Bitcoin.Mining: rpcPassword :: Auth -> Text
+ Network.Bitcoin.Mining: rpcUrl :: Auth -> Text
+ Network.Bitcoin.Mining: rpcUser :: Auth -> Text
+ Network.Bitcoin.Mining: setGenerate :: Auth -> Bool -> Maybe Int -> IO ()
+ Network.Bitcoin.Mining: sigOps :: Transaction -> Integer
+ Network.Bitcoin.Mining: sigopLimit :: BlockTemplate -> Integer
+ Network.Bitcoin.Mining: sizeLimit :: BlockTemplate -> Integer
+ Network.Bitcoin.Mining: solveBlock :: Auth -> HexString -> IO Bool
+ Network.Bitcoin.Mining: submitBlock :: Auth -> HexString -> IO Bool
+ Network.Bitcoin.Mining: transactionsToInclude :: BlockTemplate -> Vector Transaction
+ Network.Bitcoin.Mining: txnData :: Transaction -> HexString
+ Network.Bitcoin.Mining: txnFee :: Transaction -> Maybe Integer
+ Network.Bitcoin.Mining: txnHash :: Transaction -> HexString
+ Network.Bitcoin.Net: Auth :: Text -> Text -> Text -> Auth
+ Network.Bitcoin.Net: PeerInfo :: Text -> Text -> Integer -> Integer -> Integer -> Integer -> Integer -> Bool -> Integer -> Integer -> Integer -> PeerInfo
+ Network.Bitcoin.Net: addressName :: PeerInfo -> Text
+ Network.Bitcoin.Net: banScore :: PeerInfo -> Integer
+ Network.Bitcoin.Net: connectionTime :: PeerInfo -> Integer
+ Network.Bitcoin.Net: data Auth
+ Network.Bitcoin.Net: data PeerInfo
+ Network.Bitcoin.Net: getConnectionCount :: Auth -> IO Integer
+ Network.Bitcoin.Net: getPeerInfo :: Auth -> IO PeerInfo
+ Network.Bitcoin.Net: inbound :: PeerInfo -> Bool
+ Network.Bitcoin.Net: instance Eq PeerInfo
+ Network.Bitcoin.Net: instance FromJSON PeerInfo
+ Network.Bitcoin.Net: instance Ord PeerInfo
+ Network.Bitcoin.Net: instance Read PeerInfo
+ Network.Bitcoin.Net: instance Show PeerInfo
+ Network.Bitcoin.Net: lastRecv :: PeerInfo -> Integer
+ Network.Bitcoin.Net: lastSend :: PeerInfo -> Integer
+ Network.Bitcoin.Net: peerSubversion :: PeerInfo -> Integer
+ Network.Bitcoin.Net: peerVersion :: PeerInfo -> Integer
+ Network.Bitcoin.Net: releaseTime :: PeerInfo -> Integer
+ Network.Bitcoin.Net: rpcPassword :: Auth -> Text
+ Network.Bitcoin.Net: rpcUrl :: Auth -> Text
+ Network.Bitcoin.Net: rpcUser :: Auth -> Text
+ Network.Bitcoin.Net: services :: PeerInfo -> Text
+ Network.Bitcoin.Net: startingHeight :: PeerInfo -> Integer
+ Network.Bitcoin.RawTransaction: All :: WhoCanPay
+ Network.Bitcoin.RawTransaction: AllOrAnyoneCanPay :: WhoCanPay
+ Network.Bitcoin.RawTransaction: Auth :: Text -> Text -> Text -> Auth
+ Network.Bitcoin.RawTransaction: ConfirmedBlock :: Integer -> Integer -> Integer -> BlockInfo
+ Network.Bitcoin.RawTransaction: DecodedRawTransaction :: RawTransaction -> Integer -> Integer -> Vector TxIn -> Vector TxOut -> DecodedRawTransaction
+ Network.Bitcoin.RawTransaction: NonStandardScriptPubKey :: HexString -> HexString -> ScriptPubKey
+ Network.Bitcoin.RawTransaction: None :: WhoCanPay
+ Network.Bitcoin.RawTransaction: NoneOrAnyoneCanPay :: WhoCanPay
+ Network.Bitcoin.RawTransaction: RawSignedTransaction :: HexString -> Bool -> RawSignedTransaction
+ Network.Bitcoin.RawTransaction: RawTransactionInfo :: RawTransaction -> Integer -> Integer -> Vector TxIn -> Vector TxOut -> HexString -> BlockInfo -> RawTransactionInfo
+ Network.Bitcoin.RawTransaction: ScriptSig :: HexString -> HexString -> ScriptSig
+ Network.Bitcoin.RawTransaction: Single :: WhoCanPay
+ Network.Bitcoin.RawTransaction: SingleOrAnyoneCanPay :: WhoCanPay
+ Network.Bitcoin.RawTransaction: StandardScriptPubKey :: HexString -> HexString -> Integer -> TxnOutputType -> Vector Address -> ScriptPubKey
+ Network.Bitcoin.RawTransaction: TxCoinbase :: HexString -> TxIn
+ Network.Bitcoin.RawTransaction: TxIn :: TransactionID -> Integer -> ScriptSig -> Integer -> TxIn
+ Network.Bitcoin.RawTransaction: TxOut :: BTC -> ScriptPubKey -> TxOut
+ Network.Bitcoin.RawTransaction: TxnMultisig :: TxnOutputType
+ Network.Bitcoin.RawTransaction: TxnPubKey :: TxnOutputType
+ Network.Bitcoin.RawTransaction: TxnPubKeyHash :: TxnOutputType
+ Network.Bitcoin.RawTransaction: TxnScriptHash :: TxnOutputType
+ Network.Bitcoin.RawTransaction: UnconfirmedBlock :: BlockInfo
+ Network.Bitcoin.RawTransaction: UnspentTransaction :: TransactionID -> Integer -> HexString -> Maybe HexString -> BTC -> Integer -> UnspentTransaction
+ Network.Bitcoin.RawTransaction: blockTime :: BlockInfo -> Integer
+ Network.Bitcoin.RawTransaction: cbTime :: BlockInfo -> Integer
+ Network.Bitcoin.RawTransaction: confirmations :: BlockInfo -> Integer
+ Network.Bitcoin.RawTransaction: createRawTransaction :: Auth -> Vector UnspentTransaction -> Vector (Address, BTC) -> IO HexString
+ Network.Bitcoin.RawTransaction: data Auth
+ Network.Bitcoin.RawTransaction: data BlockInfo
+ Network.Bitcoin.RawTransaction: data DecodedRawTransaction
+ Network.Bitcoin.RawTransaction: data RawSignedTransaction
+ Network.Bitcoin.RawTransaction: data RawTransactionInfo
+ Network.Bitcoin.RawTransaction: data ScriptPubKey
+ Network.Bitcoin.RawTransaction: data ScriptSig
+ Network.Bitcoin.RawTransaction: data TxIn
+ Network.Bitcoin.RawTransaction: data TxOut
+ Network.Bitcoin.RawTransaction: data TxnOutputType
+ Network.Bitcoin.RawTransaction: data UnspentTransaction
+ Network.Bitcoin.RawTransaction: data WhoCanPay
+ Network.Bitcoin.RawTransaction: decRaw :: DecodedRawTransaction -> RawTransaction
+ Network.Bitcoin.RawTransaction: decTxnLockTime :: DecodedRawTransaction -> Integer
+ Network.Bitcoin.RawTransaction: decTxnVersion :: DecodedRawTransaction -> Integer
+ Network.Bitcoin.RawTransaction: decVin :: DecodedRawTransaction -> Vector TxIn
+ Network.Bitcoin.RawTransaction: decVout :: DecodedRawTransaction -> Vector TxOut
+ Network.Bitcoin.RawTransaction: decodeRawTransaction :: Auth -> RawTransaction -> IO DecodedRawTransaction
+ Network.Bitcoin.RawTransaction: getRawTransaction :: Auth -> TransactionID -> IO RawTransaction
+ Network.Bitcoin.RawTransaction: getRawTransactionInfo :: Auth -> TransactionID -> IO RawTransactionInfo
+ Network.Bitcoin.RawTransaction: hasCompleteSigSet :: RawSignedTransaction -> Bool
+ Network.Bitcoin.RawTransaction: instance Eq BlockInfo
+ Network.Bitcoin.RawTransaction: instance Eq RawTransactionInfo
+ Network.Bitcoin.RawTransaction: instance Eq ScriptPubKey
+ Network.Bitcoin.RawTransaction: instance Eq TxIn
+ Network.Bitcoin.RawTransaction: instance Eq TxOut
+ Network.Bitcoin.RawTransaction: instance Eq TxnOutputType
+ Network.Bitcoin.RawTransaction: instance FromJSON BlockInfo
+ Network.Bitcoin.RawTransaction: instance FromJSON DecodedRawTransaction
+ Network.Bitcoin.RawTransaction: instance FromJSON RawSignedTransaction
+ Network.Bitcoin.RawTransaction: instance FromJSON RawTransactionInfo
+ Network.Bitcoin.RawTransaction: instance FromJSON ScriptPubKey
+ Network.Bitcoin.RawTransaction: instance FromJSON TxIn
+ Network.Bitcoin.RawTransaction: instance FromJSON TxOut
+ Network.Bitcoin.RawTransaction: instance FromJSON TxnOutputType
+ Network.Bitcoin.RawTransaction: instance FromJSON UnspentTransaction
+ Network.Bitcoin.RawTransaction: instance Ord BlockInfo
+ Network.Bitcoin.RawTransaction: instance Ord RawTransactionInfo
+ Network.Bitcoin.RawTransaction: instance Ord ScriptPubKey
+ Network.Bitcoin.RawTransaction: instance Ord TxIn
+ Network.Bitcoin.RawTransaction: instance Ord TxOut
+ Network.Bitcoin.RawTransaction: instance Ord TxnOutputType
+ Network.Bitcoin.RawTransaction: instance Read BlockInfo
+ Network.Bitcoin.RawTransaction: instance Read RawTransactionInfo
+ Network.Bitcoin.RawTransaction: instance Read ScriptPubKey
+ Network.Bitcoin.RawTransaction: instance Read TxIn
+ Network.Bitcoin.RawTransaction: instance Read TxOut
+ Network.Bitcoin.RawTransaction: instance Read TxnOutputType
+ Network.Bitcoin.RawTransaction: instance Show BlockInfo
+ Network.Bitcoin.RawTransaction: instance Show RawTransactionInfo
+ Network.Bitcoin.RawTransaction: instance Show ScriptPubKey
+ Network.Bitcoin.RawTransaction: instance Show TxIn
+ Network.Bitcoin.RawTransaction: instance Show TxOut
+ Network.Bitcoin.RawTransaction: instance Show TxnOutputType
+ Network.Bitcoin.RawTransaction: instance ToJSON UnspentForSigning
+ Network.Bitcoin.RawTransaction: instance ToJSON UnspentTransaction
+ Network.Bitcoin.RawTransaction: listUnspent :: Auth -> Maybe Int -> Maybe Int -> Vector Address -> IO (Vector UnspentTransaction)
+ Network.Bitcoin.RawTransaction: nspkAsm :: ScriptPubKey -> HexString
+ Network.Bitcoin.RawTransaction: nspkHex :: ScriptPubKey -> HexString
+ Network.Bitcoin.RawTransaction: numOut :: TxIn -> Integer
+ Network.Bitcoin.RawTransaction: outIdx :: UnspentTransaction -> Integer
+ Network.Bitcoin.RawTransaction: raw :: RawTransactionInfo -> RawTransaction
+ Network.Bitcoin.RawTransaction: rawBlockInfo :: RawTransactionInfo -> BlockInfo
+ Network.Bitcoin.RawTransaction: rawSigned :: RawSignedTransaction -> HexString
+ Network.Bitcoin.RawTransaction: rawTxBlockHash :: RawTransactionInfo -> HexString
+ Network.Bitcoin.RawTransaction: redeemScript :: UnspentTransaction -> Maybe HexString
+ Network.Bitcoin.RawTransaction: requiredSigs :: ScriptPubKey -> Integer
+ Network.Bitcoin.RawTransaction: rpcPassword :: Auth -> Text
+ Network.Bitcoin.RawTransaction: rpcUrl :: Auth -> Text
+ Network.Bitcoin.RawTransaction: rpcUser :: Auth -> Text
+ Network.Bitcoin.RawTransaction: scriptPubKey :: TxOut -> ScriptPubKey
+ Network.Bitcoin.RawTransaction: scriptSig :: TxIn -> ScriptSig
+ Network.Bitcoin.RawTransaction: sendRawTransaction :: Auth -> RawTransaction -> IO TransactionID
+ Network.Bitcoin.RawTransaction: sigAsm :: ScriptSig -> HexString
+ Network.Bitcoin.RawTransaction: sigHex :: ScriptSig -> HexString
+ Network.Bitcoin.RawTransaction: signRawTransaction :: Auth -> RawTransaction -> Maybe (Vector UnspentTransaction) -> Maybe (Vector HexString) -> Maybe WhoCanPay -> IO RawSignedTransaction
+ Network.Bitcoin.RawTransaction: sspkAddresses :: ScriptPubKey -> Vector Address
+ Network.Bitcoin.RawTransaction: sspkAsm :: ScriptPubKey -> HexString
+ Network.Bitcoin.RawTransaction: sspkHex :: ScriptPubKey -> HexString
+ Network.Bitcoin.RawTransaction: sspkType :: ScriptPubKey -> TxnOutputType
+ Network.Bitcoin.RawTransaction: txCoinbase :: TxIn -> HexString
+ Network.Bitcoin.RawTransaction: txInId :: TxIn -> TransactionID
+ Network.Bitcoin.RawTransaction: txSequence :: TxIn -> Integer
+ Network.Bitcoin.RawTransaction: txnLockTime :: RawTransactionInfo -> Integer
+ Network.Bitcoin.RawTransaction: txnVersion :: RawTransactionInfo -> Integer
+ Network.Bitcoin.RawTransaction: txoutVal :: TxOut -> BTC
+ Network.Bitcoin.RawTransaction: type RawTransaction = HexString
+ Network.Bitcoin.RawTransaction: unspentAmount :: UnspentTransaction -> BTC
+ Network.Bitcoin.RawTransaction: unspentScriptPubKey :: UnspentTransaction -> HexString
+ Network.Bitcoin.RawTransaction: unspentTransactionId :: UnspentTransaction -> TransactionID
+ Network.Bitcoin.RawTransaction: usConfirmations :: UnspentTransaction -> Integer
+ Network.Bitcoin.RawTransaction: vin :: RawTransactionInfo -> Vector TxIn
+ Network.Bitcoin.RawTransaction: vout :: RawTransactionInfo -> Vector TxOut
+ Network.Bitcoin.Types: Auth :: Text -> Text -> Text -> Auth
+ Network.Bitcoin.Types: BitcoinApiError :: Int -> Text -> BitcoinException
+ Network.Bitcoin.Types: BitcoinResultTypeError :: ByteString -> BitcoinException
+ Network.Bitcoin.Types: Satoshi :: Satoshi
+ Network.Bitcoin.Types: ScriptSig :: HexString -> HexString -> ScriptSig
+ Network.Bitcoin.Types: data Auth
+ Network.Bitcoin.Types: data BitcoinException
+ Network.Bitcoin.Types: data Satoshi
+ Network.Bitcoin.Types: data ScriptSig
+ Network.Bitcoin.Types: instance Eq Auth
+ Network.Bitcoin.Types: instance Eq BitcoinException
+ Network.Bitcoin.Types: instance Eq ScriptSig
+ Network.Bitcoin.Types: instance Exception BitcoinException
+ Network.Bitcoin.Types: instance FromJSON ScriptSig
+ Network.Bitcoin.Types: instance HasResolution Satoshi
+ Network.Bitcoin.Types: instance Ord Auth
+ Network.Bitcoin.Types: instance Ord BitcoinException
+ Network.Bitcoin.Types: instance Ord ScriptSig
+ Network.Bitcoin.Types: instance Read Auth
+ Network.Bitcoin.Types: instance Read BitcoinException
+ Network.Bitcoin.Types: instance Read ScriptSig
+ Network.Bitcoin.Types: instance Show Auth
+ Network.Bitcoin.Types: instance Show BitcoinException
+ Network.Bitcoin.Types: instance Show ScriptSig
+ Network.Bitcoin.Types: instance Typeable BitcoinException
+ Network.Bitcoin.Types: rpcPassword :: Auth -> Text
+ Network.Bitcoin.Types: rpcUrl :: Auth -> Text
+ Network.Bitcoin.Types: rpcUser :: Auth -> Text
+ Network.Bitcoin.Types: sigAsm :: ScriptSig -> HexString
+ Network.Bitcoin.Types: sigHex :: ScriptSig -> HexString
+ Network.Bitcoin.Types: type Account = Text
+ Network.Bitcoin.Types: type Address = HexString
+ Network.Bitcoin.Types: type BTC = Fixed Satoshi
+ Network.Bitcoin.Types: type HexString = Text
+ Network.Bitcoin.Types: type TransactionID = HexString
+ Network.Bitcoin.Wallet: AddressInfo :: Address -> BTC -> Maybe Account -> AddressInfo
+ Network.Bitcoin.Wallet: Auth :: Text -> Text -> Text -> Auth
+ Network.Bitcoin.Wallet: BitcoindInfo :: Integer -> Integer -> Integer -> BTC -> Integer -> Integer -> Text -> Double -> Bool -> Integer -> Integer -> BTC -> Maybe Integer -> Text -> BitcoindInfo
+ Network.Bitcoin.Wallet: ReceivedByAccount :: Account -> BTC -> Integer -> ReceivedByAccount
+ Network.Bitcoin.Wallet: ReceivedByAddress :: Address -> Account -> BTC -> Integer -> ReceivedByAddress
+ Network.Bitcoin.Wallet: aiAccount :: AddressInfo -> Maybe Account
+ Network.Bitcoin.Wallet: aiAddress :: AddressInfo -> Address
+ Network.Bitcoin.Wallet: aiAmount :: AddressInfo -> BTC
+ Network.Bitcoin.Wallet: backupWallet :: Auth -> FilePath -> IO ()
+ Network.Bitcoin.Wallet: balance :: BitcoindInfo -> BTC
+ Network.Bitcoin.Wallet: bitcoinVersion :: BitcoindInfo -> Integer
+ Network.Bitcoin.Wallet: bitcoindErrors :: BitcoindInfo -> Text
+ Network.Bitcoin.Wallet: changePassword :: Auth -> Text -> Text -> IO ()
+ Network.Bitcoin.Wallet: data AddressInfo
+ Network.Bitcoin.Wallet: data Auth
+ Network.Bitcoin.Wallet: data BitcoindInfo
+ Network.Bitcoin.Wallet: data ReceivedByAccount
+ Network.Bitcoin.Wallet: data ReceivedByAddress
+ Network.Bitcoin.Wallet: encryptWallet :: Auth -> Text -> IO ()
+ Network.Bitcoin.Wallet: generationDifficulty :: BitcoindInfo -> Double
+ Network.Bitcoin.Wallet: getAccount :: Auth -> Address -> IO Account
+ Network.Bitcoin.Wallet: getAccountAddress :: Auth -> Account -> IO Address
+ Network.Bitcoin.Wallet: getAddressByAccount :: Auth -> Account -> IO (Vector Address)
+ Network.Bitcoin.Wallet: getBalance :: Auth -> IO BTC
+ Network.Bitcoin.Wallet: getBalance' :: Auth -> Account -> IO BTC
+ Network.Bitcoin.Wallet: getBalance'' :: Auth -> Account -> Int -> IO BTC
+ Network.Bitcoin.Wallet: getBitcoindInfo :: Auth -> IO BitcoindInfo
+ Network.Bitcoin.Wallet: getNewAddress :: Auth -> Maybe Account -> IO Address
+ Network.Bitcoin.Wallet: getReceivedByAccount :: Auth -> Account -> IO BTC
+ Network.Bitcoin.Wallet: getReceivedByAccount' :: Auth -> Account -> Int -> IO BTC
+ Network.Bitcoin.Wallet: getReceivedByAddress :: Auth -> Address -> IO BTC
+ Network.Bitcoin.Wallet: getReceivedByAddress' :: Auth -> Address -> Int -> IO BTC
+ Network.Bitcoin.Wallet: instance Eq AddressInfo
+ Network.Bitcoin.Wallet: instance Eq BitcoindInfo
+ Network.Bitcoin.Wallet: instance Eq ReceivedByAccount
+ Network.Bitcoin.Wallet: instance Eq ReceivedByAddress
+ Network.Bitcoin.Wallet: instance FromJSON AddressInfo
+ Network.Bitcoin.Wallet: instance FromJSON BitcoindInfo
+ Network.Bitcoin.Wallet: instance FromJSON IsValid
+ Network.Bitcoin.Wallet: instance FromJSON ReceivedByAccount
+ Network.Bitcoin.Wallet: instance FromJSON ReceivedByAddress
+ Network.Bitcoin.Wallet: instance Ord AddressInfo
+ Network.Bitcoin.Wallet: instance Ord BitcoindInfo
+ Network.Bitcoin.Wallet: instance Ord ReceivedByAccount
+ Network.Bitcoin.Wallet: instance Ord ReceivedByAddress
+ Network.Bitcoin.Wallet: instance Read AddressInfo
+ Network.Bitcoin.Wallet: instance Read BitcoindInfo
+ Network.Bitcoin.Wallet: instance Read ReceivedByAccount
+ Network.Bitcoin.Wallet: instance Read ReceivedByAddress
+ Network.Bitcoin.Wallet: instance Show AddressInfo
+ Network.Bitcoin.Wallet: instance Show BitcoindInfo
+ Network.Bitcoin.Wallet: instance Show ReceivedByAccount
+ Network.Bitcoin.Wallet: instance Show ReceivedByAddress
+ Network.Bitcoin.Wallet: isAddressValid :: Auth -> Address -> IO Bool
+ Network.Bitcoin.Wallet: keyPoolOldest :: BitcoindInfo -> Integer
+ Network.Bitcoin.Wallet: keyPoolRefill :: Auth -> IO ()
+ Network.Bitcoin.Wallet: keyPoolSize :: BitcoindInfo -> Integer
+ Network.Bitcoin.Wallet: listAddressGroupings :: Auth -> IO (Vector (Vector AddressInfo))
+ Network.Bitcoin.Wallet: listReceivedByAccount :: Auth -> IO (Vector ReceivedByAccount)
+ Network.Bitcoin.Wallet: listReceivedByAccount' :: Auth -> Int -> Bool -> IO (Vector ReceivedByAccount)
+ Network.Bitcoin.Wallet: listReceivedByAddress :: Auth -> IO (Vector ReceivedByAddress)
+ Network.Bitcoin.Wallet: listReceivedByAddress' :: Auth -> Int -> Bool -> IO (Vector ReceivedByAddress)
+ Network.Bitcoin.Wallet: lockWallet :: Auth -> IO ()
+ Network.Bitcoin.Wallet: moveBitcoins :: Auth -> Account -> Account -> BTC -> Text -> IO ()
+ Network.Bitcoin.Wallet: numBlocks :: BitcoindInfo -> Integer
+ Network.Bitcoin.Wallet: numConnections :: BitcoindInfo -> Integer
+ Network.Bitcoin.Wallet: onTestNetwork :: BitcoindInfo -> Bool
+ Network.Bitcoin.Wallet: protocolVersion :: BitcoindInfo -> Integer
+ Network.Bitcoin.Wallet: proxy :: BitcoindInfo -> Text
+ Network.Bitcoin.Wallet: raccAccount :: ReceivedByAccount -> Account
+ Network.Bitcoin.Wallet: raccAmount :: ReceivedByAccount -> BTC
+ Network.Bitcoin.Wallet: raccNumConfirmations :: ReceivedByAccount -> Integer
+ Network.Bitcoin.Wallet: recvAccount :: ReceivedByAddress -> Account
+ Network.Bitcoin.Wallet: recvAddress :: ReceivedByAddress -> Address
+ Network.Bitcoin.Wallet: recvAmount :: ReceivedByAddress -> BTC
+ Network.Bitcoin.Wallet: recvNumConfirmations :: ReceivedByAddress -> Integer
+ Network.Bitcoin.Wallet: rpcPassword :: Auth -> Text
+ Network.Bitcoin.Wallet: rpcUrl :: Auth -> Text
+ Network.Bitcoin.Wallet: rpcUser :: Auth -> Text
+ Network.Bitcoin.Wallet: sendFromAccount :: Auth -> Account -> Address -> BTC -> Maybe Text -> Maybe Text -> IO TransactionID
+ Network.Bitcoin.Wallet: sendMany :: Auth -> Account -> Vector (Address, BTC) -> Maybe Text -> IO TransactionID
+ Network.Bitcoin.Wallet: sendToAddress :: Auth -> Address -> BTC -> Maybe Text -> Maybe Text -> IO TransactionID
+ Network.Bitcoin.Wallet: setAccount :: Auth -> Address -> Account -> IO ()
+ Network.Bitcoin.Wallet: signMessage :: Auth -> Address -> Text -> IO Signature
+ Network.Bitcoin.Wallet: transactionFeePaid :: BitcoindInfo -> BTC
+ Network.Bitcoin.Wallet: type Signature = HexString
+ Network.Bitcoin.Wallet: unlockWallet :: Auth -> Text -> Integer -> IO ()
+ Network.Bitcoin.Wallet: unlockedUntil :: BitcoindInfo -> Maybe Integer
+ Network.Bitcoin.Wallet: verifyMessage :: Auth -> Address -> Signature -> Text -> IO Bool
+ Network.Bitcoin.Wallet: walletVersion :: BitcoindInfo -> Integer
- Network.Bitcoin: Auth :: String -> String -> String -> Auth
+ Network.Bitcoin: Auth :: Text -> Text -> Text -> Auth
- Network.Bitcoin: BitcoinApiError :: Int -> String -> BitcoinException
+ Network.Bitcoin: BitcoinApiError :: Int -> Text -> BitcoinException
- Network.Bitcoin: getBalance :: Auth -> Account -> MinConf -> IO Amount
+ Network.Bitcoin: getBalance :: Auth -> IO BTC
- Network.Bitcoin: getDifficulty :: Auth -> IO Double
+ Network.Bitcoin: getDifficulty :: Auth -> IO Integer
- Network.Bitcoin: getReceivedByAccount :: Auth -> Account -> MinConf -> IO Amount
+ Network.Bitcoin: getReceivedByAccount :: Auth -> Account -> IO BTC
- Network.Bitcoin: getReceivedByAddress :: Auth -> Address -> MinConf -> IO Amount
+ Network.Bitcoin: getReceivedByAddress :: Auth -> Address -> IO BTC
- Network.Bitcoin: rpcPassword :: Auth -> String
+ Network.Bitcoin: rpcPassword :: Auth -> Text
- Network.Bitcoin: rpcUrl :: Auth -> String
+ Network.Bitcoin: rpcUrl :: Auth -> Text
- Network.Bitcoin: rpcUser :: Auth -> String
+ Network.Bitcoin: rpcUser :: Auth -> Text
- Network.Bitcoin: type Account = String
+ Network.Bitcoin: type Account = Text

Files

− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
+ Setup.lhs view
@@ -0,0 +1,4 @@+#!/usr/bin/env runhaskell+ +> import Distribution.Simple+> main = defaultMain
network-bitcoin.cabal view
@@ -1,18 +1,6 @@--- network-bitcoin.cabal auto-generated by cabal init. For additional--- options, see--- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.--- The name of the package. Name:                network-bitcoin---- The package version. See the Haskell package versioning policy--- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for--- standards guiding when and how versions should be incremented.-Version:             0.1.5---- A short (one-line) description of the package.-Synopsis:            Interface with Bitcoin RPC---- A longer description of the package.+Version:             1.0.0+Synopsis:            An interface to bitcoind. Description:     This can be used to send Bitcoins, query balances, etc.  It     requires the Bitcoin daemon to be running and accessible via@@ -28,6 +16,12 @@     .     To learn more about Bitcoin, see <http://www.bitcoin.org>.     .+    Changes in v1.0+    .+    - Total overhaul of the library, with almost the complete bitcoin RPC API+      covered.+    - Dependencies upgraded, and library modernized.+    .     Changes in v0.1.5     .     - Correct aeson dependency@@ -35,68 +29,50 @@     Changes in v0.1.4     .     - More accurate conversion of Bitcoin amounts from floating point---- The license under which the package is released. License:             BSD3---- The file containing the license text. License-file:        LICENSE---- The package author(s). Author:              Michael Hendricks <michael@ndrix.org>---- An email address to which users can send suggestions, bug reports,--- and patches.-Maintainer:          Michael Hendricks <michael@ndrix.org>-+Maintainer:          Clark Gaebel <cgaebel@uwaterloo.ca>+Stability:           experimental+Homepage:            http://github.com/wowus/network-bitcoin+Bug-reports:         http://github.com/wowus/network-bitcoin/issues+Copyright:           Copyright 2012, Michael Hendricks+                     Copyright 2012, Clark Gaebel Stability: experimental Homepage: http://github.com/mndrix/network-bitcoin Bug-reports: http://github.com/mndrix/network-bitcoin/issues---- A copyright notice.-Copyright:           Copyright 2011, Michael Hendricks- Category:            Network- Build-type:          Simple---- Extra files to be distributed with the package, such as examples or--- a README.--- Extra-source-files:  ---- Constraint on the version of Cabal needed to build this package. Cabal-version:       >=1.8-+tested-with: GHC ==7.4.1, GHC ==7.6.1  Library   hs-source-dirs: src-  ghc-options: -Wall -fno-warn-unused-binds -fno-warn-incomplete-patterns+  ghc-options: -Wall    -- Modules exported by the library.   Exposed-modules:     Network.Bitcoin-    Network.Bitcoin.Address+    Network.Bitcoin.BlockChain+    Network.Bitcoin.Dump+    Network.Bitcoin.Internal+    Network.Bitcoin.Mining+    Network.Bitcoin.Net+    Network.Bitcoin.RawTransaction+    Network.Bitcoin.Types+    Network.Bitcoin.Wallet      -- Packages needed in order to build this package.   Build-depends:       -    aeson == 0.3.*,-    attoparsec >= 0.7,-    bytestring >= 0.9,-    containers >= 0.4,+    aeson == 0.6.*,+    bytestring >= 0.10,+    attoparsec == 0.10.*,+    unordered-containers >= 0.2,     HTTP >= 4000,     network >= 2.3,     text >= 0.11,+    vector >= 0.10,     base == 4.*-  -  -- Modules not exported by this package.-  -- Other-modules:       -  -  -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.-  -- Build-tools:         --Test-suite test-main-    type: exitcode-stdio-1.0-    main-is: test-main.hs    Source-repository head     type: git
src/Network/Bitcoin.hs view
@@ -1,287 +1,118 @@-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE TypeSynonymInstances #-}-{-# LANGUAGE FlexibleInstances #-}--- | Communicate with a Bitcoin daemon over JSON RPC+{-# OPTIONS_GHC -Wall #-}+-- | A Haskell binding to the bitcoind server. module Network.Bitcoin     (-    -- * Types+    -- * Common Types       Auth(..)-    , Address-    , mkAddress-    , Amount-    , Account-    , MinConf-    , AddressValidation-    , isValid-    , isMine-    , account     , BitcoinException(..)+    , HexString+    , TransactionID     , Satoshi(..)--    -- * Individual API methods-    , getBalance+    , BTC+    , Account+    , Address+    , ScriptSig+    -- * Block Chain Operations     , getBlockCount-    , getConnectionCount     , getDifficulty+    , setTransactionFee+    , getRawMemoryPool+    , BlockHash+    , getBlockHash+    , Block(..)+    , getBlock+    , OutputSetInfo(..)+    , getOutputSetInfo+    , OutputInfo(..)+    , getOutputInfo+    -- * Private Key Operations+    , importPrivateKey+    , dumpPrivateKey+    -- * Mining Operations     , getGenerate+    , setGenerate     , getHashesPerSec-    , getReceivedByAccount+    , MiningInfo(..)+    , getMiningInfo+    , HashData(..)+    , getWork+    , solveBlock+    , Transaction(..)+    , CoinBaseAux(..)+    , BlockTemplate(..)+    , getBlockTemplate+    , submitBlock+    -- * Network Operations+    , getConnectionCount+    , PeerInfo(..)+    , getPeerInfo+    -- * Raw Transaction Operations+    , RawTransaction+    , getRawTransaction+    , TxIn(..)+    , TxnOutputType(..)+    , ScriptPubKey(..)+    , TxOut(..)+    , BlockInfo(..)+    , RawTransactionInfo(..)+    , getRawTransactionInfo+    , UnspentTransaction(..)+    , listUnspent+    , createRawTransaction+    , DecodedRawTransaction(..)+    , decodeRawTransaction+    , WhoCanPay(..)+    , RawSignedTransaction(..)+    , signRawTransaction+    , sendRawTransaction+    -- * Wallet Operations+    , BitcoindInfo(..)+    , getBitcoindInfo+    , getNewAddress+    , getAccountAddress+    , getAccount+    , setAccount+    , getAddressByAccount+    , sendToAddress+    , AddressInfo(..)+    , listAddressGroupings+    , Signature+    , signMessage+    , verifyMessage     , getReceivedByAddress-    , validateAddress-    , isValidAddress--    -- * Low-level API-    , callApi-    , FromNumber-    , fromNumber+    , getReceivedByAddress'+    , getReceivedByAccount+    , getReceivedByAccount'+    , getBalance+    , getBalance'+    , getBalance''+    , moveBitcoins+    , sendFromAccount+    , sendMany+    -- , createMultiSig+    , ReceivedByAddress(..)+    , listReceivedByAddress+    , listReceivedByAddress'+    , ReceivedByAccount(..)+    , listReceivedByAccount+    , listReceivedByAccount'+    -- , listTransactions+    -- , listAccounts+    -- , listSinceBlock+    -- , getTransaction+    , backupWallet+    , keyPoolRefill+    , unlockWallet+    , lockWallet+    , changePassword+    , encryptWallet+    , isAddressValid     ) where-import Network.Bitcoin.Address -import Control.Applicative-import Control.Exception-import Control.Monad-import Data.Aeson-import Data.Attoparsec-import Data.Attoparsec.Number-import Data.Fixed-import Data.Maybe (fromJust)-import Data.Ratio ((%))-import Data.String (fromString)-import Data.Typeable-import Network.Browser-import Network.HTTP hiding (password)-import Network.URI (parseURI)-import qualified Data.ByteString as B-import qualified Data.ByteString.Lazy as BL-import qualified Data.Map as M-import qualified Data.Text as T---- | Defines Bitcoin's internal precision-satoshis :: Integer-satoshis = 10^(8::Integer)-data Satoshi = Satoshi-instance HasResolution Satoshi where-    resolution _ = satoshis---- | Fixed precision Bitcoin amount (to avoid floating point errors)-type Amount = Fixed Satoshi---- | Name of a Bitcoin wallet account-type Account = String---- | Minimum number of confirmations for a payment-type MinConf     = Integer---- | 'Auth' describes authentication credentials for--- making API requests to the Bitcoin daemon-data Auth = Auth-    { rpcUrl :: String      -- ^ URL, with port, where bitcoind listens-    , rpcUser :: String     -- ^ same as bitcoind's 'rpcuser' config-    , rpcPassword :: String -- ^ same as bitcoind's 'rpcpassword' config-    }-    deriving (Show)--data BitcoinRpcResponse = BitcoinRpcResponse {-        btcResult  :: Value,-        btcError   :: Value-    }-    deriving (Show)-instance FromJSON BitcoinRpcResponse where-    parseJSON (Object v) = BitcoinRpcResponse <$> v .: "result"-                                          <*> v .: "error"-    parseJSON _ = mzero---- |A 'BitcoinException' is thrown when 'callApi' encounters an--- error.  The API error code is represented as an @Int@, the message as--- a @String@.-data BitcoinException-    = BitcoinApiError Int String-    deriving (Show,Typeable)-instance Exception BitcoinException---- encodes an RPC request into a ByteString containing JSON-jsonRpcReqBody :: String -> [Value] -> BL.ByteString-jsonRpcReqBody cmd params = encode $ object [-                "jsonrpc" .= ("2.0"::String),-                "method"  .= cmd,-                "params"  .= params,-                "id"      .= (1::Int)-              ]---- |'callApi' is a low-level interface for making authenticated API--- calls to a Bitcoin daemon.  The first argument specifies--- authentication details (URL, username, password) and is often--- curried for convenience:------ > callBtc = callApi $ Auth "http://127.0.0.1:8332" "user" "password"------ The second argument is the command name.  The third argument provides--- parameters for the API call.------ > let result = callBtc "getbalance" ["account-name", Number 6]------ On error, throws a 'BitcoinException'-callApi :: Auth  -- ^ authentication credentials for bitcoind-               -> String  -- ^ command name-               -> [Value] -- ^ command arguments-               -> IO Value-callApi auth command params = do-    (_,httpRes) <- browse $ do-        setOutHandler $ const $ return ()-        addAuthority authority-        setAllowBasicAuth True-        request $ httpRequest urlString $ jsonRpcReqBody command params-    let res = fromSuccess $ fromJSON $ toVal $ rspBody httpRes-    case res of-        BitcoinRpcResponse {btcError=Null} -> return $ btcResult res-        BitcoinRpcResponse {btcError=e}    -> throw $ buildBtcError e-    where authority     = httpAuthority auth-          urlString     = rpcUrl auth-          toStrict      = B.concat . BL.toChunks-          justParseJSON = fromJust . maybeResult . parse json-          toVal         = justParseJSON . toStrict---- Internal helper functions to make callApi more readable-httpAuthority :: Auth -> Authority-httpAuthority (Auth urlString username password) =-    AuthBasic {-        auRealm    = "jsonrpc",-        auUsername = username,-        auPassword = password,-        auSite     = uri-    }-    where uri = fromJust $ parseURI urlString-httpRequest :: String -> BL.ByteString -> Request BL.ByteString-httpRequest urlString jsonBody =-    (postRequest urlString){-        rqBody = jsonBody,-        rqHeaders = [-            mkHeader HdrContentType "application/json",-            mkHeader HdrContentLength (show $ BL.length jsonBody)-        ]-    }--fromSuccess :: Data.Aeson.Result t -> t-fromSuccess (Success a) = a-fromSuccess (Error   s) = error s--buildBtcError :: Value -> BitcoinException-buildBtcError (Object o) = BitcoinApiError code msg-    where find k = fromSuccess . fromJSON . fromJust . M.lookup k-          code = find "code" o-          msg  = find "message" o-buildBtcError _ = error "Need an object to buildBtcError"---- | Convert JSON numeric values to more specific numeric types-class FromNumber a where-    fromNumber :: Number -> a-instance FromNumber Amount where-    fromNumber (I i) = fromInteger i-    fromNumber (D d) = fromRational $ numerator % satoshis-      where-        numerator = round $ d * (fromInteger satoshis)-instance FromNumber Integer where-    fromNumber (I i) = i-    fromNumber (D d) = round d-instance FromNumber Double where-    fromNumber (I i) = fromInteger i-    fromNumber (D d) = d---- Class of types that can be converted to a JSON representation-class ToValue a where-    toValue :: a -> Value-instance ToValue Address where-    toValue addr = String $ fromString $ show addr-instance ToValue MinConf where-    toValue conf = Number $ fromInteger conf-instance ToValue Account where-    toValue acct = String $ fromString acct--callNumber :: FromNumber a => String -> [Value] -> Auth -> IO a-callNumber cmd args auth = do-    (Number n) <- callApi auth cmd args-    return $ fromNumber n--callBool :: String -> [Value] -> Auth -> IO Bool-callBool cmd args auth = do-    (Bool b) <- callApi auth cmd args-    return b---- | Returns the balance of a specific Bitcoin account-getBalance :: Auth-           -> Account-           -> MinConf-           -> IO Amount-getBalance auth acct minconf = callNumber "getbalance" args auth-  where-    args = [ String $ fromString acct, Number $ fromInteger minconf ]---- | Returns the number of blocks in the longest block chain-getBlockCount :: Auth -> IO Integer-getBlockCount = callNumber "getblockcount" []---- | Returns the number of connections to other nodes-getConnectionCount :: Auth -> IO Integer-getConnectionCount = callNumber "getconnectioncount" []---- | Returns the proof-of-work difficulty as a multiple of the minimum--- difficulty-getDifficulty :: Auth -> IO Double-getDifficulty = callNumber "getdifficulty" []---- | Indicates whether the node is generating or not-getGenerate :: Auth -> IO Bool-getGenerate = callBool "getgenerate" []---- | Returns a recent hashes per second performance measurement while--- generating-getHashesPerSec :: Auth -> IO Integer-getHashesPerSec = callNumber "gethashespersec" []---- | Returns the total amount received by addresses with--- @account@ in transactions with at least @minconf@ confirmations-getReceivedByAccount :: Auth-                     -> Account-                     -> MinConf-                     -> IO Amount-getReceivedByAccount auth acct conf =-    callNumber "getreceivedbyaccount" [toValue acct,toValue conf] auth---- | Returns the total amount received by an address in transactions--- with at least 'minconf' confirmations.-getReceivedByAddress :: Auth-                     -> Address-                     -> MinConf-                     -> IO Amount-getReceivedByAddress auth addr conf =-    callNumber "getreceivedbyaddress" [toValue addr,toValue conf] auth---- | Encapsulates address validation results from 'validateAddress'-data AddressValidation = AddressValidation-    { isValid :: Bool    -- ^ Is the address valid?-    , isMine  :: Bool    -- ^ Does the address belong to my wallet?-    , account :: Account -- ^ To which account does this address belong?-    } deriving (Show)---- | Return information about an address.--- If the address is invalid or doesn't belong to us, the account name--- is the empty string.-validateAddress :: Auth-                -> Address-                -> IO AddressValidation-validateAddress auth addr = do-    (Object result) <- callApi auth "validateaddress" [toValue addr]-    return AddressValidation-        { isValid = bool False "isvalid" result-        , isMine  = bool False "ismine"  result-        , account = str  ""    "account" result-        }-  where-    bool d k r = maybe d (\(Bool b)->b) $ M.lookup k r-    str  d k r = maybe d (\(String t)->T.unpack t) $ M.lookup k r---- | Returns true if the RPC says the address is valid.--- Use this function until 'mkAddress' verifies address checksums-isValidAddress :: Auth -> Address -> IO Bool-isValidAddress auth addr = validateAddress auth addr >>= return . isValid+import Network.Bitcoin.Types+import Network.Bitcoin.BlockChain+import Network.Bitcoin.Dump+import Network.Bitcoin.Mining+import Network.Bitcoin.Net+import Network.Bitcoin.RawTransaction+import Network.Bitcoin.Wallet
− src/Network/Bitcoin/Address.hs
@@ -1,32 +0,0 @@-module Network.Bitcoin.Address-    (-    -- * Types-      Address--    -- * Functions-    , mkAddress-    )-where---- | Represents a Bitcoin receiving address.  Construct one with--- 'mkAddress'.-data Address = Address String-instance Show Address where-    show (Address s) = s---- | Construct an 'Address' from a 'String'.--- Returns 'Nothing' if the string is not a valid Bitcoin address.------ Only validates approximate address format.--- /Does not/ validate address checksum.--- Until full validation is done, use 'isValidAddress' RPC call instead-mkAddress :: String -> Maybe Address-mkAddress s =-    if isOK s-        then Just $ Address s-        else Nothing-  where -- TODO validate address checksum (write base58 module first)-    isOK ('1':_) = (length s >= 25) && (length s <= 34)-    isOK ('m':_) = (length s >= 26) && (length s <= 34)-    isOK ('n':_) = (length s >= 26) && (length s <= 34)-    isOK _       = False
+ src/Network/Bitcoin/BlockChain.hs view
@@ -0,0 +1,164 @@+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_GHC -Wall #-}+-- | An interface to bitcoind's available block-chain-related RPC calls. The+--   implementation of these functions can be found at+--   <https://github.com/bitcoin/bitcoin/blob/master/src/rpcblockchain.cpp>.+--+--   If any APIs are missing, patches are always welcome. If you look at the+--   source of this module, you'll see that the interface code is trivial.+module Network.Bitcoin.BlockChain ( Auth(..)+                                  , TransactionID+                                  , BTC+                                  , ScriptSig(..)+                                  , getBlockCount+                                  , getDifficulty+                                  , setTransactionFee+                                  , getRawMemoryPool+                                  , BlockHash+                                  , getBlockHash+                                  , Block(..)+                                  , getBlock+                                  , OutputSetInfo(..)+                                  , getOutputSetInfo+                                  , OutputInfo(..)+                                  , getOutputInfo+                                  ) where++import Control.Applicative+import Control.Monad+import Data.Aeson+import Network.Bitcoin.Internal++-- | Returns the number of blocks in the longest block chain.+getBlockCount :: Auth -> IO Integer+getBlockCount auth = callApi auth "getblockcount" []++-- | Returns the proof-of-work difficulty as a multiple of the minimum+--   difficulty.+getDifficulty :: Auth -> IO Integer+getDifficulty auth = callApi auth "getdifficulty" []++-- | Sets the transaction fee will will pay to the network. Values of 0 are+--   rejected.+setTransactionFee :: Auth -> BTC -> IO ()+setTransactionFee auth fee =+    stupidAPI <$> callApi auth "settxfee" [ tj $ WBTC fee ]+        where stupidAPI :: Bool -> ()+              stupidAPI = const ()++-- | Returns all transaction identifiers in the memory pool.+getRawMemoryPool :: Auth -> IO (Vector TransactionID)+getRawMemoryPool auth = callApi auth "getrawmempool" []++-- | The hash of a given block.+type BlockHash = HexString++-- | Returns the hash of the block in best-block-chain at the given index.+getBlockHash :: Auth+             -> Integer -- ^ Block index.+             -> IO BlockHash+getBlockHash auth idx = callApi auth "getblockhash" [ tj idx ]++-- | Information about a given block in the block chain.+data Block = Block { blockHash :: BlockHash+                   -- | The number of confirmations the block has.+                   , blkConfirmations :: Integer+                   -- | The size of the block.+                   , blkSize :: Integer+                   -- | The "height" of the block. TODO: Clarify this.+                   , blkHeight :: Integer+                   -- | The version of the block.+                   , blkVersion :: Integer+                   -- | The hash of the block at the root of the merkle tree+                   --   which this block belongs to.+                   , merkleRoot :: BlockHash+                   -- | Should this be a transaction, or transaction id?+                   , subTransactions :: Vector TransactionID+                   -- | The time it was mined.+                   , blkTime :: Integer+                   -- | The block's nonce.+                   , blkNonce :: Integer+                   , blkBits :: HexString+                   -- | How hard was this block to mine?+                   , blkDifficulty :: Integer+                   -- | A pointer to the next block in the chain.+                   , nextBlock :: Maybe BlockHash+                   -- | A pointer to the previous block in the chain.+                   , prevBlock :: Maybe BlockHash+                   }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON Block where+    parseJSON (Object o) = Block <$> o .:  "hash"+                                 <*> o .:  "confirmations"+                                 <*> o .:  "size"+                                 <*> o .:  "height"+                                 <*> o .:  "version"+                                 <*> o .:  "merkleroot"+                                 <*> o .:  "tx"+                                 <*> o .:  "time"+                                 <*> o .:  "nonce"+                                 <*> o .:  "bits"+                                 <*> o .:  "difficulty"+                                 <*> o .:? "nextblockhash"+                                 <*> o .:? "previousblockhash"+    parseJSON _ = mzero++-- | Returns details of a block with given block-hash.+getBlock :: Auth -> BlockHash -> IO Block+getBlock auth bh = callApi auth "getblock" [ tj bh ]++-- | Information on the unspent transaction in the output set.+data OutputSetInfo =+    OutputSetInfo { osiBestBlock :: BlockHash+                  -- | The number of transactions in the output set.+                  , numTransactions :: Integer+                  -- | The number of outputs for the transactions.+                  , transactionOutputs :: Integer+                  -- | The serialized size of the output set.+                  , serializedSize :: Integer+                  }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON OutputSetInfo where+    parseJSON (Object o) = OutputSetInfo <$> o .: "bestblock"+                                         <*> o .: "transactions"+                                         <*> o .: "txouts"+                                         <*> o .: "bytes_serialized"+    parseJSON _ = mzero++-- | Returns statistics about the unspent transaction output set.+getOutputSetInfo :: Auth -> IO OutputSetInfo+getOutputSetInfo auth = callApi auth "gettxoutsetinfo" []++-- | Details about an unspent transaction output.+data OutputInfo =+    OutputInfo { oiBestBlock :: BlockHash+               -- | The number of times this transaction has been confirmed.+               , oiConfirmations :: Integer+               -- | The amount transferred.+               , oiAmount :: BTC+               -- | The public key of the sender.+               , oiScriptPubKey :: ScriptSig+               -- | The version of this transaction.+               , oiVersion :: Integer+               -- | Is this transaction part of the coin base?+               , oiCoinBase :: Bool+               }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON OutputInfo where+    parseJSON (Object o) = OutputInfo <$> o .: "bestblock"+                                      <*> o .: "confirmations"+                                      <*> (unwrapBTC <$> o .: "amount")+                                      <*> o .: "scriptPubKey"+                                      <*> o .: "version"+                                      <*> o .: "coinbase"+    parseJSON _ = mzero++-- | Returns details about an unspent transaction output.+getOutputInfo :: Auth+              -> TransactionID+              -> Integer -- ^ The index we're looking at.+              -> IO OutputInfo+getOutputInfo auth txid n = callApi auth "gettxout" [ tj txid, tj n ]
+ src/Network/Bitcoin/Dump.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_GHC -Wall #-}+-- | An interface to bitcoind's available private key calls. The implementation+--   of these functions can be found at <https://github.com/bitcoin/bitcoin/blob/master/src/rpcdump.cpp>.+--+--   If any APIs are missing, patches are always welcome. If you look at the+--   source of this module, you'll see that the interface code is trivial.+module Network.Bitcoin.Dump ( PrivateKey+                            , importPrivateKey+                            , dumpPrivateKey+                            ) where++import Network.Bitcoin.Internal++-- | A textual representation of a bitcoin private key.+type PrivateKey = Text++-- | Adds a private key (as returned by dumpprivkey) to your wallet.+importPrivateKey :: Auth+                 -> PrivateKey+                 -> Maybe Account+                 -- ^ An optional label for the key.+                 -> IO ()+importPrivateKey auth pk Nothing =+    callApi auth "importprivkey" [ tj pk ]+importPrivateKey auth pk (Just label) =+    callApi auth "importprivkey" [ tj pk, tj label ]++-- | Reveals the private key corresponding to the given address.+dumpPrivateKey :: Auth+               -> Address+               -> IO PrivateKey+dumpPrivateKey auth addr = callApi auth "dumpprivkey" [ tj addr ]
+ src/Network/Bitcoin/Internal.hs view
@@ -0,0 +1,163 @@+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_GHC -Wall #-}+-- | The API exposed in this module should be considered unstable, and is+--   subject to change between minor revisions.+--+--   If the version number is a.b.c.d, and either a or b changes, then the+--   module's whole API may have changed (if only b changes, then it was+--   probably a minor change).+--+--   If c changed, then only the internal API may change. The rest of the+--   module is guaranteed to be stable.+--+--   If only d changes, then there were no user-facing code changes made.+module Network.Bitcoin.Internal ( module Network.Bitcoin.Types+                                , Text, Vector+                                , FromJSON(..)+                                , 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+import           Network.Bitcoin.Types+import           Network.Browser+import           Network.HTTP hiding ( password )+import           Network.URI ( parseURI )+import qualified Data.ByteString.Lazy as BL+import           Data.Text ( Text )+import qualified Data.Text            as T++-- | RPC calls return an error object. It can either be empty; or have an+--   error message + error code.+data BitcoinRpcError = NoError -- ^ All good.+                     | BitcoinRpcError Int Text -- ^ Error code + error message.+    deriving ( Show, Read, Ord, Eq )++instance FromJSON BitcoinRpcError where+    parseJSON (Object v) = BitcoinRpcError <$> v .: "code"+                                           <*> v .: "message"+    parseJSON Null       = return NoError+    parseJSON _ = mzero++-- | A response from bitcoind will contain the result of the JSON-RPC call, and+--   an error. The error should be null if a valid response was received.+data BitcoinRpcResponse a = BitcoinRpcResponse { btcResult  :: a+                                               , btcError   :: BitcoinRpcError+                                               }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON a => FromJSON (BitcoinRpcResponse a) where+    parseJSON (Object v) = BitcoinRpcResponse <$> v .: "result"+                                              <*> v .: "error"+    parseJSON _          = mzero++-- | The "no conversion needed" implementation of callApi. THis lets us inline+--   and specialize callApi for its parameters, while keeping the bulk of the+--   work in this function shared.+callApi' :: Auth -> BL.ByteString -> IO BL.ByteString+callApi' auth rpcReqBody = do+    (_, httpRes) <- browse $ do+        setOutHandler . const $ return ()+        addAuthority authority+        setAllowBasicAuth True+        request $ httpRequest (T.unpack urlString) rpcReqBody+    return $ rspBody httpRes+    where+        authority = httpAuthority auth+        urlString = rpcUrl auth++-- | 'callApi' is a low-level interface for making authenticated API+--   calls to a Bitcoin daemon. The first argument specifies+--   authentication details (URL, username, password) and is often+--   curried for convenience:+--+--   > callBtc = callApi $ Auth "http://127.0.0.1:8332" "user" "password"+--+--   The second argument is the command name.  The third argument provides+--   parameters for the API call.+--+--   > let result = callBtc "getbalance" [ tj "account-name", tj 6 ]+--+--   On error, throws a 'BitcoinException'.+callApi :: FromJSON v+        => Auth    -- ^ authentication credentials for bitcoind+        -> Text    -- ^ command name+        -> [Value] -- ^ command arguments+        -> IO v+callApi auth cmd params = readVal =<< callApi' auth jsonRpcReqBody+    where+        readVal bs = case decode' bs of+                        Just r@(BitcoinRpcResponse {btcError=NoError})+                            -> return $ btcResult r+                        Just (BitcoinRpcResponse {btcError=BitcoinRpcError code msg})+                            -> throw $ BitcoinApiError code msg+                        Nothing+                            -> throw $ BitcoinResultTypeError bs+        jsonRpcReqBody =+            encode $ object [ "jsonrpc" .= ("2.0" :: Text)+                            , "method"  .= cmd+                            , "params"  .= params+                            , "id"      .= (1 :: Int)+                            ]+{-# INLINE callApi #-}++-- | Internal helper functions to make callApi more readable+httpAuthority :: Auth -> Authority+httpAuthority (Auth urlString username password) =+    AuthBasic { auRealm    = "jsonrpc"+              , auUsername = T.unpack username+              , auPassword = T.unpack password+              , auSite     = uri+              }+    where+        uri = fromJust . parseURI $ T.unpack urlString++-- | Builds the JSON HTTP request.+httpRequest :: String -> BL.ByteString -> Request BL.ByteString+httpRequest urlString jsonBody =+    (postRequest urlString){+        rqBody = jsonBody,+        rqHeaders = [+            mkHeader HdrContentType "application/json",+            mkHeader HdrContentLength (show $ BL.length jsonBody)+        ]+    }++-- | A handy shortcut for toJSON, because I'm lazy.+tj :: ToJSON a => a -> Value+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+
+ src/Network/Bitcoin/Mining.hs view
@@ -0,0 +1,220 @@+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_GHC -Wall #-}+-- | An interface to bitcoind's available mining RPC calls. The implementation+--   of these functions can be found at <https://github.com/bitcoin/bitcoin/blob/master/src/rpcmining.cpp>.+--+--   If any APIs are missing, patches are always welcome. If you look at the+--   source of this module, you'll see that the interface code is trivial.+--+--   Note that it is highly discouraged to use bitcoind for actual bitcoin+--   mining. It uses the CPU for mining, which is much, much less power+--   efficient than GPU mining. If you're paying for power, you will not come+--   out ahead.+--+--   Instead, consider using a GPU miner listed at <https://en.bitcoin.it/wiki/Software#Mining_apps>.+module Network.Bitcoin.Mining ( Auth(..)+                              , getGenerate+                              , setGenerate+                              , getHashesPerSec+                              , MiningInfo(..)+                              , getMiningInfo+                              , HashData(..)+                              , getWork+                              , solveBlock+                              , Transaction(..)+                              , CoinBaseAux(..)+                              , BlockTemplate(..)+                              , getBlockTemplate+                              , submitBlock+                              ) where++import Data.Aeson as A+import Control.Applicative+import Control.Monad+import Network.Bitcoin.Internal++-- | Returns whether or not bitcoind is generating bitcoins.+getGenerate :: Auth -- ^ bitcoind RPC authorization+            -> IO Bool+getGenerate auth = callApi auth "getgenerate" []++-- | Controls whether or not bitcoind is generating bitcoins.+setGenerate :: Auth -- ^ bitcoind RPC authorization+            -> Bool -- ^ Turn it on, or turn it off?+            -> Maybe Int -- ^ Generation is limited to this number of+                         --   processors. Set it to Nothing to keep the value+                         --   at what it was before, Just -1 to use all+                         --   available cores, and any other value to limit it.+            -> IO ()+setGenerate auth onOff Nothing =+    callApi auth "setgenerate" [ tj onOff ]+setGenerate auth onOff (Just limit) =+    callApi auth "setgenerate" [ tj onOff, tj limit ]++-- | Returns a recent hashes per second performance measurement while+--   generating.+getHashesPerSec :: Auth -> IO Integer+getHashesPerSec auth = callApi auth "gethashespersec" []++-- | Information related to the current bitcoind mining operation.+--+--   If a field is undocumented here, it's because I don't know what it means.+--   If you DO know what it means, I'd love it if you would submit a patch to+--   help complete this documentation.+data MiningInfo =+    MiningInfo {+               -- | The number of blocks in our block-chain.+                 nBlocks :: Integer+               -- | The size of the current block we're mining.+               , currentBlockSize :: Integer+               , currentBlockTransaction :: Integer+               -- | How difficult mining currently is.+               , difficulty :: Double+               -- | Any mining errors that may have come up.+               , miningErrors :: Text+               -- | Are we currently generating bitcoins?+               , isGenerating :: Bool+               -- | How many processors have we limited bitcoin mining to?+               , generationProcessorLimit :: Integer+               -- | How fast is the mining going?+               , hashesPerSecond :: Integer+               , pooledTransactions :: Integer+               -- | Are we on the bitcoin test network (as opposed to the real+               --   thing)?+               , miningOnTestNetwork :: Bool+               }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON MiningInfo where+    parseJSON (Object o) = MiningInfo <$> o .: "blocks"+                                      <*> o .: "currentblocksize"+                                      <*> o .: "currentblocktx"+                                      <*> o .: "difficulty"+                                      <*> o .: "errors"+                                      <*> o .: "generate"+                                      <*> o .: "genproclimit"+                                      <*> o .: "hashespersec"+                                      <*> o .: "pooledtx"+                                      <*> o .: "testnet"+    parseJSON _ = mzero++-- | Returns an object containing mining-related information.+getMiningInfo :: Auth -> IO MiningInfo+getMiningInfo auth = callApi auth "getmininginfo" []++-- | The hash data returned from 'getWork'.+data HashData =+    HashData { blockData :: HexString+             -- | Little-endian hash target, formatted as a hexadecimal string.+             , hdTarget :: HexString+             }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON HashData where+    parseJSON (Object o) = HashData <$> o .: "data"+                                    <*> o .: "target"+    parseJSON _ = mzero++-- | Returns formatted hash data to work on.+getWork :: Auth -> IO HashData+getWork auth = callApi auth "getwork" []++-- | Tries to solve the given block, and returns true if it was successful.+solveBlock :: Auth -> HexString -> IO Bool+solveBlock auth data_ = callApi auth "getwork" [ tj data_ ]++-- | A transaction to be included in the next block.+data Transaction =+    Transaction { txnData :: HexString+                , txnHash :: HexString+                , depends :: Vector Integer+                , txnFee  :: Maybe Integer+                , sigOps  :: Integer+                }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON Transaction where+    parseJSON (Object o) = Transaction <$> o .:  "data"+                                       <*> o .:  "hash"+                                       <*> o .:  "depends"+                                       <*> o .:? "fee"+                                       <*> o .:  "sigops"+    parseJSON _ = mzero++data CoinBaseAux = CoinBaseAux { cbFlags :: HexString+                               }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON CoinBaseAux where+    parseJSON (Object o) = CoinBaseAux <$> o .: "flags"+    parseJSON _ = mzero++-- | A template for constructing a block to work on.+--+--   See <https://en.bitcoin.it/wiki/BIP_0022> for the full specification.+data BlockTemplate =+    BlockTemplate { blockVersion :: Integer+                  -- | Hash of current highest block.+                  , previousBlockHash :: HexString+                  -- | Contents of non-coinbase transactions that should be+                  --   included in the next block.+                  , transactionsToInclude :: Vector Transaction+                  -- | Data that should be included in coinbase.+                  , coinBaseAux :: CoinBaseAux+                  -- | Maximum allowable input to coinbase transaction,+                  --   including the generation award and transaction fees.+                  , coinBaseValue :: Integer+                  -- | Hash target.+                  , btTarget :: HexString+                  -- | Minimum timestamp appropriate for next block.+                  , minTime :: Integer+                  -- | Range of valid nonces.+                  , nonceRange :: HexString+                  -- | Limit of sigops in blocks.+                  , sigopLimit :: Integer+                  -- | Limit of block size.+                  , sizeLimit :: Integer+                  -- | Current timestamp.+                  , curTime :: Integer+                  -- | Compressed target of the next block.+                  , btBits :: HexString+                  -- | Height of the next block.+                  , btHeight :: Integer+                  }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON BlockTemplate where+    parseJSON (Object o) = BlockTemplate <$> o .: "version"+                                         <*> o .: "previousblockhash"+                                         <*> o .: "transactions"+                                         <*> o .: "coinbaseaux"+                                         <*> o .: "coinbasevalue"+                                         <*> o .: "target"+                                         <*> o .: "mintime"+                                         <*> o .: "noncerange"+                                         <*> o .: "sigoplimit"+                                         <*> o .: "sizelimit"+                                         <*> o .: "curtime"+                                         <*> o .: "bits"+                                         <*> o .: "height"+    parseJSON _ = mzero++-- | Returns data needed to construct a block to work on.+getBlockTemplate :: Auth -> IO BlockTemplate+getBlockTemplate auth = callApi auth "getblocktemplate" []++-- | Unfortunately, the submitblock API call returns null on success, and+--   the string "rejected" on failure.+--+--   We use 'StupidReturnValue' to parse this ridiculous API.+data StupidReturnValue = SRV { unStupid :: Bool }++instance FromJSON StupidReturnValue where+    parseJSON Null = return $ SRV True+    parseJSON _ = return $ SRV False++-- | Attempts to submit a new block to the network.+submitBlock :: Auth+            -> HexString -- ^ The block to submit.+            -> IO Bool -- ^ Was the block accepted by the network?+submitBlock auth block = unStupid <$> callApi auth "submitblock" [ tj block ]
+ src/Network/Bitcoin/Net.hs view
@@ -0,0 +1,71 @@+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_GHC -Wall #-}+-- | An interface to bitcoind's available network-related RPC calls.+--   The implementation of these functions can be found at+--   <https://github.com/bitcoin/bitcoin/blob/master/src/rpcnet.cpp>.+--+--   If any APIs are missing, patches are always welcome. If you look at the+--   source of this module, you'll see that the interface code is trivial.+module Network.Bitcoin.Net ( Auth(..)+                           , getConnectionCount+                           , PeerInfo(..)+                           , getPeerInfo+                           ) where++import Control.Applicative+import Control.Monad+import Data.Aeson+import Network.Bitcoin.Internal++-- | Returns the number of connections to other nodes.+getConnectionCount :: Auth -> IO Integer+getConnectionCount auth = callApi auth "getconnectioncount" []++-- | Information on a given connected node in the network.+--+--   The documentation for this data structure is incomplete, as I honestly+--   don't know what some of these fields are for. Patches are welcome!+data PeerInfo =+    PeerInfo { -- | The ip:port of this peer, as a string.+               addressName :: Text+             , services :: Text+             -- | Relative to when we first time we conected with this peer+             --   (and in milliseconds), the last time we sent this peer any+             --   data.+             , lastSend :: Integer+             -- | Relative to the first time we connected with this peer+             --   (and in milliseconds), the last time we sent this peer any+             --   data.+             , lastRecv :: Integer+              -- | How long have we been connected to this peer (in+              --   milliseconds).+             , connectionTime :: Integer+             -- | The version of bitcoind the peer is running.+             , peerVersion :: Integer+             -- | The sub-version of bitcoind the peer is running.+             , peerSubversion :: Integer+             , inbound :: Bool+             , releaseTime :: Integer+             , startingHeight :: Integer+             -- | How many times has this peer behaved badly?+             , banScore :: Integer+             }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON PeerInfo where+    parseJSON (Object o) = PeerInfo <$> o .: "addr"+                                    <*> o .: "services"+                                    <*> o .: "lastsend"+                                    <*> o .: "lastrecv"+                                    <*> o .: "conntime"+                                    <*> o .: "version"+                                    <*> o .: "subver"+                                    <*> o .: "inbound"+                                    <*> o .: "releasetime"+                                    <*> o .: "startingheight"+                                    <*> o .: "banscore"+    parseJSON _ = mzero++-- | Returns data about each connected network node.+getPeerInfo :: Auth -> IO PeerInfo+getPeerInfo auth = callApi auth "getpeerinfo" []
+ src/Network/Bitcoin/RawTransaction.hs view
@@ -0,0 +1,354 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}+{-# OPTIONS_GHC -Wall #-}+-- | An interface to bitcoind's available raw transaction-related RPC calls.+--   The implementation of these functions can be found at+--   <https://github.com/bitcoin/bitcoin/blob/master/src/rpcrawtransaction.cpp>.+--+--   If any APIs are missing, patches are always welcome. If you look at the+--   source of this module, you'll see that the interface code is trivial.+--+--   Also, documentation for this module is scarce. I would love the addition+--   of more documentation by anyone who knows what these things are.+module Network.Bitcoin.RawTransaction ( Auth(..)+                                      , ScriptSig(..)+                                      , RawTransaction+                                      , getRawTransaction+                                      , TxIn(..)+                                      , TxnOutputType(..)+                                      , ScriptPubKey(..)+                                      , TxOut(..)+                                      , BlockInfo(..)+                                      , RawTransactionInfo(..)+                                      , getRawTransactionInfo+                                      , UnspentTransaction(..)+                                      , listUnspent+                                      , createRawTransaction+                                      , DecodedRawTransaction(..)+                                      , decodeRawTransaction+                                      , WhoCanPay(..)+                                      , RawSignedTransaction(..)+                                      , signRawTransaction+                                      , sendRawTransaction+                                      ) where++import           Control.Applicative+import           Control.Monad+import           Data.Aeson               as A+import           Data.Aeson.Types         as AT+import           Data.Maybe+import qualified Data.Vector              as V+import           Network.Bitcoin.Internal++-- | Just like most binary data retrieved from bitcoind, a raw transaction is+--   represented by a hexstring.+--+--   This is a serialized, hex-encoded transaction.+type RawTransaction = HexString++-- | Get a raw transaction from its unique ID.+getRawTransaction :: Auth -> TransactionID -> IO RawTransaction+getRawTransaction auth txid =+    callApi auth "getrawtransaction" [ tj txid, tj verbose ]+        where verbose = 0 :: Int++-- | A transaction into an account. This can either be a coinbase transaction,+--   or a standard transaction with another account.+data TxIn = TxCoinbase { txCoinbase :: HexString+                       }+          | TxIn { -- | This transaction's ID.+                   txInId :: TransactionID+                 , numOut :: Integer+                 , scriptSig :: ScriptSig+                 -- | A transaction sequence number.+                 , txSequence :: Integer+                 }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON TxIn where+    parseJSON (Object o) = parseCB <|> parseTxIn+        where+            parseCB = TxCoinbase <$> o .: "coinbase"+            parseTxIn = TxIn <$> o .: "txid"+                             <*> o .: "vout"+                             <*> o .: "scriptSig"+                             <*> o .: "sequence"+    parseJSON _ = mzero++-- | The type of a transaction out.+--+--   More documentation is needed here. Submit a patch if you know what this is+--   about!+data TxnOutputType = TxnPubKey     -- ^ JSON of "pubkey" received.+                   | TxnPubKeyHash -- ^ JSON of "pubkeyhash" received.+                   | TxnScriptHash -- ^ JSON of "scripthash" received.+                   | TxnMultisig   -- ^ JSON of "multisig" received.+    deriving ( Show, Read, Ord, Eq )++instance FromJSON TxnOutputType where+    parseJSON (A.String s) | s == "pubkey"     = return TxnPubKey+                           | s == "pubkeyhash" = return TxnPubKeyHash+                           | s == "scripthash" = return TxnScriptHash+                           | s == "multisig"   = return TxnMultisig+                           | otherwise         = mzero+    parseJSON _ = mzero++-- | A public key of someone we sent money to.+data ScriptPubKey = NonStandardScriptPubKey { -- | The JSON "asm" field.+                                              nspkAsm :: HexString+                                              -- | The JSON "hex" field.+                                            , nspkHex :: HexString+                                            }+                  | StandardScriptPubKey { -- | The JSON "asm" field.+                                           sspkAsm :: HexString+                                         -- | The JSON "hex" field.+                                         , sspkHex :: HexString+                                         -- | The number of required signatures.+                                         , requiredSigs :: Integer+                                         -- | The type of the transaction.+                                         , sspkType :: TxnOutputType+                                         -- | The addresses associated with this key.+                                         , sspkAddresses :: Vector Address+                                         }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON ScriptPubKey where+    parseJSON (Object o) = parseStandard <|> parseNonstandard+        where+            parseStandard = StandardScriptPubKey <$> o .: "asm"+                                                 <*> o .: "hex"+                                                 <*> o .: "reqSigs"+                                                 <*> o .: "type"+                                                 <*> o .: "addresses"+            parseNonstandard = NonStandardScriptPubKey <$> o .: "asm"+                                                       <*> o .: "hex"+    parseJSON _ = mzero++-- | A transaction out of an account.+data TxOut =+    TxOut { -- | The amount of bitcoin transferred out.+            txoutVal :: BTC+          -- | The public key of the account we sent the money to.+          , scriptPubKey :: ScriptPubKey+          }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON TxOut where+    parseJSON (Object o) = TxOut <$> (unwrapBTC <$> o .: "value")+                                 <*> o .: "scriptPubKey"+    parseJSON _ = mzero++-- | Information on a single block.+data BlockInfo = ConfirmedBlock { -- | The number of confirmations a block has.+                                  --   This will always be >= 1.+                                  confirmations :: Integer+                                --   The JSON "time" field".+                                , cbTime :: Integer+                                -- | The JSON "blocktime" field.+                                , blockTime :: Integer+                                }+               | UnconfirmedBlock+               -- ^ An unconfirmed block is boring, but a possibility.+    deriving ( Show, Read, Ord, Eq )++instance FromJSON BlockInfo where+    parseJSON (Object o) = parseConfirmed <|> parseUnconfirmed+        where+            parseConfirmed = ConfirmedBlock <$> o .: "confirmations"+                                            <*> o .: "time"+                                            <*> o .: "blocktime"+            parseUnconfirmed = do c <- o .: "confirmations" :: AT.Parser Integer+                                  guard $ c == 0+                                  return UnconfirmedBlock+    parseJSON _ = mzero++-- | The raw transaction info for a given transaction ID.+data RawTransactionInfo =+    RawTransactionInfo { -- | The raw transaction.+                         raw :: RawTransaction+                       -- | The transaction version number.+                       , txnVersion :: Integer+                       , txnLockTime :: Integer+                       -- | The vector of transactions in.+                       , vin :: Vector TxIn+                       -- | The vector of transactions out.+                       , vout :: Vector TxOut+                       -- | The hash of the block that was used for this+                       --   transaction.+                       , rawTxBlockHash :: HexString+                       -- | The transaction's block's info.+                       , rawBlockInfo :: BlockInfo+                       }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON RawTransactionInfo where+    parseJSON v@(Object o) = RawTransactionInfo <$> o .: "hex"+                                                <*> o .: "version"+                                                <*> o .: "locktime"+                                                <*> o .: "vin"+                                                <*> o .: "vout"+                                                <*> o .: "blockhash"+                                                <*> parseJSON v+    parseJSON _ = mzero++-- | Get raw transaction info for a given transaction ID. The data structure+--   returned is quite sprawling and undocumented, so any patches to help+--   simplify things would be greatly appreciated.+getRawTransactionInfo :: Auth -> TransactionID -> IO RawTransactionInfo+getRawTransactionInfo auth txid =+    callApi auth "getrawtransaction" [ tj txid, tj verbose ]+        where verbose = 1 :: Int++data UnspentTransaction =+    UnspentTransaction { unspentTransactionId :: TransactionID+                       , outIdx :: Integer+                       , unspentScriptPubKey :: HexString+                       , redeemScript :: Maybe HexString+                       , unspentAmount :: BTC+                       , usConfirmations :: Integer+                       }++instance FromJSON UnspentTransaction where+    parseJSON (Object o) = UnspentTransaction <$> o .:  "txid"+                                              <*> o .:  "vout"+                                              <*> o .:  "scriptPubKey"+                                              <*> o .:? "redeemScript"+                                              <*> (unwrapBTC <$> o .:  "amount")+                                              <*> o .:  "confirmations"+    parseJSON _ = mzero++-- Instance used in 'createRawTransaction'.+instance ToJSON UnspentTransaction where+    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+--   be filtered to include only those addresses.+listUnspent :: Auth+            -> Maybe Int -- ^ minconf. Defaults to 1 if 'Nothing'.+            -> Maybe Int -- ^ maxconf. Defaults to 9999999 if 'Nothing'.+            -> Vector Address -- ^ Use 'Data.Vector.empty' for no filtering.+            -> IO (Vector UnspentTransaction)+listUnspent auth mmin mmax vaddrs =+    let min' = fromMaybe 1 mmin+        max' = fromMaybe 9999999 mmax+     in callApi auth "listunspent" [ tj min', tj max', tj vaddrs ]++-- | Create a transaction spending given inputs, sending to given addresses.+--+--   Note that the transaction's inputs are not signed, and it is not stored+--   in the wallet or transmitted to the network.+--+--   Also, there is no checking to see if it's possible to send that much to+--   the targets specified. In the future, such a scenario might throw an+--   exception.+createRawTransaction :: Auth+                     -> Vector UnspentTransaction+                     -- ^ The unspent transactions we'll be using as our output.+                     -> Vector (Address, BTC)+                     -- ^ The addresses we're sending money to, along with how+                     --   much each of them gets.+                     -> IO HexString+createRawTransaction auth us tgts =+    callApi auth "createrawtransaction" [ tj us, tj $ AA tgts ]++-- | A successfully decoded raw transaction, from a given serialized,+--   hex-encoded transaction.+data DecodedRawTransaction =+    DecodedRawTransaction { -- | The raw transaction.+                            decRaw :: RawTransaction+                          -- | The transaction version number.+                          , decTxnVersion :: Integer+                          , decTxnLockTime :: Integer+                          -- | The vector of transactions in.+                          , decVin :: Vector TxIn+                          -- | The vector of transactions out.+                          , decVout :: Vector TxOut+                          }++instance FromJSON DecodedRawTransaction where+    parseJSON (Object o) = DecodedRawTransaction <$> o .: "hex"+                                                 <*> o .: "version"+                                                 <*> o .: "locktime"+                                                 <*> o .: "vin"+                                                 <*> o .: "vout"+    parseJSON _ = mzero++-- | Decodes a raw transaction into a more accessible data structure.+decodeRawTransaction :: Auth -> RawTransaction -> IO DecodedRawTransaction+decodeRawTransaction auth tx = callApi auth "decoderawtransaction" [ tj tx ]++-- | Used internally to give a new 'ToJSON' instance for 'UnspentTransaction'.+newtype UnspentForSigning = UFS UnspentTransaction++instance ToJSON UnspentForSigning where+    toJSON (UFS (UnspentTransaction{..}))+        | isNothing redeemScript =+            object [ "txid" .= unspentTransactionId+                   , "vout" .= outIdx+                   , "scriptPubKey" .= unspentScriptPubKey+                   ]+        | otherwise =+            object [ "txid" .= unspentTransactionId+                   , "vout" .= outIdx+                   , "scriptPubKey" .= unspentScriptPubKey+                   , "redeemScript" .= fromJust redeemScript+                   ]++-- | Who can pay for a given transaction.+data WhoCanPay = All+               | AllOrAnyoneCanPay+               | None+               | NoneOrAnyoneCanPay+               | Single+               | SingleOrAnyoneCanPay++toString :: WhoCanPay -> Text+toString All = "ALL"+toString AllOrAnyoneCanPay = "ALL|ANYONECANPAY"+toString None = "NONE"+toString NoneOrAnyoneCanPay = "NONE|ANYONECANPAY"+toString Single = "SINGLE"+toString SingleOrAnyoneCanPay = "SINGLE|ANYONECANPAY"++-- | A raw signed transaction contains the raw, signed hexstring and whether or+--   not this transaction has a complete signature set.+data RawSignedTransaction =+    RawSignedTransaction { rawSigned :: HexString+                         , hasCompleteSigSet :: Bool+                         }++-- I have no idea why they use a 1/0 to represent a boolean.+instance FromJSON RawSignedTransaction where+    parseJSON (Object o) = RawSignedTransaction <$> o .: "hex"+                                                <*> (toEnum <$> o .: "complete")+    parseJSON _ = mzero++-- | Sign inputs for a raw transaction.+signRawTransaction :: Auth+                   -> RawTransaction+                   -- ^ The raw transaction whose inputs we're signing.+                   -> Maybe (Vector UnspentTransaction)+                   -- ^ An optional list of previous transaction outputs that+                   --   this transaction depends on but may not yet be in the+                   --   block chain.+                   -> Maybe (Vector HexString)+                   -- ^ An array of base58-encoded private keys that, if given,+                   --   will be the only keys used to sign the transaction.+                   -> Maybe WhoCanPay+                   -- ^ Who can pay for this transaction? 'All' by default.+                   -> IO RawSignedTransaction+                   -- ^ Returns 'Nothing' if the transaction has a complete set+                   --   of signatures, and the raw signed transa+signRawTransaction auth rt us' privkeys wcp =+    let us = V.map UFS <$> us' :: Maybe (Vector UnspentForSigning)+     in callApi auth "signrawtransaction" [ tj rt+                                          , tj us+                                          , tj privkeys+                                          , tj . toString $ fromMaybe All wcp+                                          ]++sendRawTransaction :: Auth -> RawTransaction -> IO TransactionID+sendRawTransaction auth rt = callApi auth "sendrawtransaction" [ tj rt ]
+ src/Network/Bitcoin/Types.hs view
@@ -0,0 +1,94 @@+{-# LANGUAGE OverloadedStrings, DeriveDataTypeable #-}+{-# OPTIONS_GHC -Wall #-}+-- | Contains the common types used through bitcoin RPC calls, that aren't+--   specific to a single submodule.+module Network.Bitcoin.Types ( Auth(..)+                             , BitcoinException(..)+                             , HexString+                             , TransactionID+                             , Satoshi(..)+                             , BTC+                             , Account+                             , Address+                             , ScriptSig(..)+                             ) where++import Control.Applicative+import Control.Exception+import Control.Monad+import Data.Aeson+import Data.Fixed+import Data.Text ( Text )+import Data.Typeable+import qualified Data.ByteString.Lazy as BL++-- | 'Auth' describes authentication credentials for+-- making API requests to the Bitcoin daemon.+data Auth = Auth+    { rpcUrl      :: Text -- ^ URL, with port, where bitcoind listens+    , rpcUser     :: Text -- ^ same as bitcoind's 'rpcuser' config+    , rpcPassword :: Text -- ^ same as bitcoind's 'rpcpassword' config+    }+    deriving ( Show, Read, Ord, Eq )++-- | A 'BitcoinException' is thrown when 'callApi encounters an+--   error.  The API error code is represented as an @Int@, the message as+--   a @String@.+--+--   It may also be thrown when the value returned by the bitcoin API wasn't+--   what we expected.+--+--   WARNING: Any of the functions in this module's public API may throw this+--            exception. You should plan on handling it.+data BitcoinException = BitcoinApiError Int Text+                      -- ^ A 'BitcoinApiError' has an error code error+                      --   message, as returned by bitcoind's JSON-RPC+                      --   response.+                      | BitcoinResultTypeError BL.ByteString+                      -- ^ The raw JSON returned, if we can't figure out what+                      --   actually went wrong.+    deriving ( Show, Read, Ord, Eq, Typeable )++instance Exception BitcoinException++-- | A string returned by the bitcoind API, representing data as hex.+--+--   What that data represents depends on the API call, but should be+--   dcumented accordingly.+type HexString = Text++-- | A hexadecimal string representation of a 256-bit unsigned integer.+--+--   This integer is a unique transaction identifier.+type TransactionID = HexString++-- | A satoshi is the smallest subdivision of bitcoins. For the resolution,+--   use 'resolution' from 'Data.Fixed'.+data Satoshi = Satoshi++instance HasResolution Satoshi where+    resolution = const $ 10^(8::Integer)+    {-# INLINE resolution #-}++-- | The type of bitcoin money, represented with a fixed-point number.+type BTC = Fixed Satoshi++-- | An address for sending or receiving money.+type Address = HexString++-- | I don't know what this is. A signature of some sort? If you know, please+--   submit a patch documenting this properly!+data ScriptSig = ScriptSig { sigAsm :: HexString+                           , sigHex :: HexString+                           }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON ScriptSig where+    parseJSON (Object o) = ScriptSig <$> o .: "asm"+                                     <*> o .: "hex"+    parseJSON _ = mzero++-- | An account on the wallet is just a label to easily specify private keys.+--+--   The default account is an empty string.+type Account = Text
+ src/Network/Bitcoin/Wallet.hs view
@@ -0,0 +1,476 @@+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_GHC -Wall #-}+-- | An interface to bitcoind's available wallet-related RPC calls.+--   The implementation of these functions can be found at+--   <https://github.com/bitcoin/bitcoin/blob/master/src/rpcwallet.cpp>.+--+--   If any APIs are missing, patches are always welcome. If you look at the+--   source of this module, you'll see that the interface code is trivial.+--+--   Certain APIs were too complicated for me to write an interface for. If+--   you figure them out, then patches are always welcome! They're left in+--   the source as comments.+module Network.Bitcoin.Wallet ( Auth(..)+                              , BitcoindInfo(..)+                              , getBitcoindInfo+                              , getNewAddress+                              , getAccountAddress+                              , getAccount+                              , setAccount+                              , getAddressByAccount+                              , sendToAddress+                              , AddressInfo(..)+                              , listAddressGroupings+                              , Signature+                              , signMessage+                              , verifyMessage+                              , getReceivedByAddress+                              , getReceivedByAddress'+                              , getReceivedByAccount+                              , getReceivedByAccount'+                              , getBalance+                              , getBalance'+                              , getBalance''+                              , moveBitcoins+                              , sendFromAccount+                              , sendMany+                              -- , createMultiSig+                              , ReceivedByAddress(..)+                              , listReceivedByAddress+                              , listReceivedByAddress'+                              , ReceivedByAccount(..)+                              , listReceivedByAccount+                              , listReceivedByAccount'+                              -- , listTransactions+                              -- , listAccounts+                              -- , listSinceBlock+                              -- , getTransaction+                              , backupWallet+                              , keyPoolRefill+                              , unlockWallet+                              , lockWallet+                              , changePassword+                              , encryptWallet+                              , isAddressValid+                              ) where++import Control.Applicative+import Control.Monad+import Data.Aeson as A+import Data.Maybe+import Data.Vector as V+import Network.Bitcoin.Internal++-- | A plethora of information about a bitcoind instance.+data BitcoindInfo =+    BitcoindInfo {+                 -- | What version of bitcoind are we running?+                   bitcoinVersion :: Integer+                 -- | What is bitcoind's current protocol number?+                 , protocolVersion :: Integer+                 -- | What version is the wallet?+                 , walletVersion :: Integer+                 -- | How much money is currently in the wallet?+                 , balance :: BTC+                 -- | The number of blocks in our chain.+                 , numBlocks :: Integer+                 -- | How many peers are we connected to?+                 , numConnections :: Integer+                 -- | A blank string if we're not using a proxy.+                 , proxy :: Text+                 -- | The difficulty multiplier for bitcoin mining operations.+                 , generationDifficulty :: Double+                 -- | Are we on the test network (as opposed to the primary+                 --   bitcoin network)?+                 , onTestNetwork :: Bool+                 -- | The timestamp of the oldest key in the key pool.+                 , keyPoolOldest :: Integer+                 -- | The size of the key pool.+                 , keyPoolSize :: Integer+                 -- | How much do we currently pay as a transaction fee?+                 , transactionFeePaid :: BTC+                 -- | If the wallet is unlocked, the number of seconds until a+                 --   re-lock is needed.+                 , unlockedUntil :: Maybe Integer+                 -- | Any alerts will show up here. This should normally be an+                 --   empty string.+                 , bitcoindErrors :: Text+                 }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON BitcoindInfo where+    parseJSON (Object o) = BitcoindInfo <$> o .:  "version"+                                        <*> o .:  "protocolversion"+                                        <*> o .:  "walletversion"+                                        <*> (unwrapBTC <$> o .: "balance")+                                        <*> o .:  "blocks"+                                        <*> o .:  "connections"+                                        <*> o .:  "proxy"+                                        <*> o .:  "difficulty"+                                        <*> o .:  "testnet"+                                        <*> o .:  "keypoololddest"+                                        <*> o .:  "keypoolsize"+                                        <*> (unwrapBTC <$> o .: "paytxfee")+                                        <*> o .:? "unlocked_until"+                                        <*> o .:  "errors"+    parseJSON _ = mzero++-- | Returns an object containing various state info.+getBitcoindInfo :: Auth -> IO BitcoindInfo+getBitcoindInfo auth = callApi auth "getinfo" []++-- | Returns a new bitcoin address for receiving payments.+--+--   If an account is specified (recommended), the new address is added to the+--   address book so payments received with the address will be credited to the+--   given account.+--+--   If no account is specified, the address will be credited to the account+--   whose name is the empty string. i.e. the default account.+getNewAddress :: Auth -> Maybe Account -> IO Address+getNewAddress auth ma = let acc = fromMaybe "" ma+                         in callApi auth "getnewaddress" [ tj acc ]++-- | Returns the current Bitcoin address for receiving payments to the given+--   account.+getAccountAddress :: Auth -> Account -> IO Address+getAccountAddress auth acc = callApi auth "getaccountaddress" [ tj acc ]++-- | Sets the account associated with the given address.+setAccount :: Auth -> Address -> Account -> IO ()+setAccount auth addr acc = callApi auth "setaccount" [ tj addr, tj acc ]++-- | Returns the account associated with the given address.+getAccount :: Auth -> Address -> IO Account+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 ]++-- | Sends some bitcoins to an address.+sendToAddress :: Auth+              -> Address+              -- ^ Who we're sending to.+              -> BTC+              -- ^ The amount to send.+              -> Maybe Text+              -- ^ An optional comment for the transaction.+              -> Maybe Text+              -- ^ An optional comment-to (who did we sent this to?) for the+              --   transaction.+              -> IO TransactionID+sendToAddress auth addr amount comm comm2 =+    callApi auth "sendtoaddress" [ tj addr, tj $ WBTC amount, tj comm, tj comm2 ]++-- | Information on a given address.+data AddressInfo = AddressInfo { -- | The address in question.+                                 aiAddress :: Address+                               -- | The address' balance.+                               , aiAmount  :: BTC+                               -- | The address' linked account.+                               , aiAccount :: Maybe Account+                               }+    deriving ( Show, Read, Eq, Ord )++-- | What a silly API.+instance FromJSON AddressInfo where+    parseJSON (A.Array a) | V.length a == 2 = AddressInfo <$> parseJSON (a ! 0)+                                                          <*> (unwrapBTC <$> parseJSON (a ! 1))+                                                          <*> pure Nothing+                          | V.length a == 3 = AddressInfo <$> parseJSON (a ! 0)+                                                          <*> (unwrapBTC <$> parseJSON (a ! 1))+                                                          <*> (Just <$> parseJSON (a ! 2))+                          | otherwise       = mzero+    parseJSON _ = mzero++-- | Lists groups of addresses which have had their common ownership made+--   public by common use as inputs or as the resulting change in past+--   transactions.+listAddressGroupings :: Auth+                     -> IO (Vector (Vector AddressInfo))+listAddressGroupings auth =+    callApi auth "listaddressgroupings" []++-- | A signature is a base-64 encoded string.+type Signature = HexString++-- | Sign a message with the private key of an address.+signMessage :: Auth+            -> Address+            -- ^ The address whose private key we'll use.+            -> Text+            -- ^ The message to sign.+            -> IO Signature+signMessage auth addr msg = callApi auth "signmessage" [ tj addr, tj msg ]++-- | Verifies a signed message.+verifyMessage :: Auth+              -> Address+              -- ^ The address of the original signer.+              -> Signature+              -- ^ The message's signature.+              -> Text+              -- ^ The message.+              -> IO Bool+              -- ^ Was the signature valid?+verifyMessage auth addr sig msg =+    callApi auth "verifymessage" [ tj addr, tj sig, tj msg ]++-- | Returns the total amount received by the given address with at least one+--   confirmation.+getReceivedByAddress :: Auth -> Address -> IO BTC+getReceivedByAddress auth addr =+    unwrapBTC <$> callApi auth "getreceivedbyaddress" [ tj addr ]++-- | Returns the total amount received by the given address, with at least the+--   give number of confirmations.+getReceivedByAddress' :: Auth+                      -> Address+                      -> Int -- ^ The minimum number of confirmations needed+                             --   for a transaction to to count towards the+                             --   total.+                      -> IO BTC+getReceivedByAddress' auth addr minconf =+    unwrapBTC <$> 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 ]++-- | Returns the total amount received by addresses with the given account,+--   counting only transactions with the given minimum number of confirmations.+getReceivedByAccount' :: Auth+                      -> Account+                      -- ^ The account in question.+                      -> Int+                      -- ^ The minimum number of confirmations needed for a+                      --   transaction to count towards the total.+                      -> IO BTC+getReceivedByAccount' auth acc minconf =+    unwrapBTC <$> callApi auth "getreceivedbyaccount" [ tj acc, tj minconf ]++-- | Returns the server's total available balance.+getBalance :: Auth+           -> IO BTC+getBalance auth =+    unwrapBTC <$> callApi auth "getbalance" []++-- | Returns the balance in the given account, counting only transactions with+--   at least one confirmation.+getBalance' :: Auth+            -> Account+            -> IO BTC+getBalance' auth acc =+    unwrapBTC <$> callApi auth "getbalance" [ tj acc ]++-- | Returns the balance in the given account, counting only transactions with+--   at least the given number of confirmations.+getBalance'' :: Auth+             -> Account+             -> Int+             -- ^ The minimum number of confirmations needed for a transaction+             --   to cuont towards the total.+             -> IO BTC+getBalance'' auth acc minconf =+    unwrapBTC <$> callApi auth "getbalance" [ tj acc, tj minconf ]++-- | Move bitcoins from one account in your wallet to another.+--+--   If you want to send bitcoins to an address not in your wallet, use+--   'sendFromAccount'.+moveBitcoins :: Auth+             -> Account -- ^ From.+             -> Account -- ^ To.+             -> BTC     -- ^ The amount to transfer.+             -> 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 ]+        where one = 1 :: Int -- needs a type, else default-integer warnings.+              stupidAPI :: Bool -> ()+              stupidAPI = const ()++-- | Sends bitcoins from a given account in our wallet to a given address.+--+--   A transaction and sender comment may be optionally provided.+sendFromAccount :: Auth+                -> Account+                -- ^ The account to send from.+                -> Address+                -- ^ The address to send to.+                -> BTC+                -- ^ The amount to send.+                -> Maybe Text+                -- ^ An optional transaction comment.+                -> Maybe Text+                -- ^ 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 ]+        where one = 1 :: Int -- needs a type, else default-integer warnings.++-- | Send to a whole bunch of address at once.+sendMany :: Auth+         -> Account+         -- ^ The account to send from.+         -> Vector (Address, BTC)+         -- ^ The address, and how much to send to each one.+         -> Maybe Text+         -- ^ An optional transaction comment.+         -> IO TransactionID+sendMany auth acc amounts comm =+    callApi auth "sendmany" [ tj acc, tj $ AA amounts, tj comm ]++-- TODO: createmultisig.+--+--       I have no idea what this is doing. Patches adding this function are+--       always welcome!++-- | Information on how much was received by a given address.+data ReceivedByAddress =+    ReceivedByAddress { -- | The address which the money was deposited to.+                        recvAddress :: Address+                      -- | The account which this address belongs to.+                      , recvAccount :: Account+                      -- | The amount received.+                      , recvAmount  :: BTC+                      -- | The number of confirmations of the most recent+                      --   included transaction.+                      , recvNumConfirmations :: Integer+                      }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON ReceivedByAddress where+    parseJSON (Object o) = ReceivedByAddress <$> o .: "address"+                                             <*> o .: "account"+                                             <*> (unwrapBTC <$> o .: "amount")+                                             <*> o .: "confirmations"+    parseJSON _ = mzero++-- | Lists the amount received by each address which has received money at some+--   point, counting only transactions with at least one confirmation.+listReceivedByAddress :: Auth -> IO (Vector ReceivedByAddress)+listReceivedByAddress auth = listReceivedByAddress' auth 1 False++-- | List the amount received by each of our addresses, counting only+--   transactions with the given minimum number of confirmations.+listReceivedByAddress' :: Auth+                       -> Int+                       -- ^ The minimum number of confirmations before a+                       --   transaction counts toward the total amount+                       --   received.+                       -> Bool+                       -- ^ Should we include addresses with no money+                       --   received?+                       -> IO (Vector ReceivedByAddress)+listReceivedByAddress' auth minconf includeEmpty =+    callApi auth "listreceivedbyaddress" [ tj minconf, tj includeEmpty ]++data ReceivedByAccount =+    ReceivedByAccount { raccAccount :: Account+                      -- ^ The account we received into.+                      , raccAmount  :: BTC+                      -- ^ The mount received.+                      -- ^ The number of confirmations of the most recent+                      --   included transaction.+                      , raccNumConfirmations :: Integer+                      }+    deriving ( Show, Read, Ord, Eq )++instance FromJSON ReceivedByAccount where+    parseJSON (Object o) = ReceivedByAccount <$> o .: "account"+                                             <*> (unwrapBTC <$> o .: "amount")+                                             <*> o .: "confirmations"+    parseJSON _ = mzero++-- | Lists the amount received by each account which has received money at some+--   point, counting only transactions with at leaset one confirmation.+listReceivedByAccount :: Auth -> IO (Vector ReceivedByAccount)+listReceivedByAccount auth = listReceivedByAccount' auth 1 False++-- | List the amount received by each of our accounts, counting only+--   transactions with the given minimum number of confirmations.+listReceivedByAccount' :: Auth+                       -> Int+                       -- ^ The minimum number of confirmations before a+                       --   transaction counts toward the total received.+                       -> Bool+                       -- ^ Should we include the accounts with no money+                       --   received?+                       -> IO (Vector ReceivedByAccount)+listReceivedByAccount' auth minconf includeEmpty =+    callApi auth "listreceivedbyaccount" [ tj minconf, tj includeEmpty ]++-- TODO: listtransactions+--       listaccounts+--       listsinceblock+--       gettransaction+--+--       These functions are just way too complicated for me to write.+--       Patches welcome!++-- | Safely copies wallet.dat to the given destination, which can be either a+--   directory, or a path with filename.+backupWallet :: Auth+             -> FilePath+             -> IO ()+backupWallet auth fp =+    callApi auth "backupwallet" [ tj fp ]++-- | Fills the keypool.+keyPoolRefill :: Auth -> IO ()+keyPoolRefill auth = callApi auth "keypoolrefill" []++-- | Stores the wallet decryption key in memory for the given amount of time.+unlockWallet :: Auth+             -> Text+             -- ^ The decryption key.+             -> Integer+             -- ^ How long to store the key in memory (in seconds).+             -> IO ()+unlockWallet auth pass timeout =+    callApi auth "walletpassphrase" [ tj pass, tj timeout ]++-- | Changes the wallet passphrase.+changePassword :: Auth+               -> Text+               -- ^ The old password.+               -> Text+               -- ^ The new password.+               -> IO ()+changePassword auth old new =+    callApi auth "walletpassphrase" [ tj old, tj new ]++-- | Removes the wallet encryption key from memory, locking the wallet.+--+--   After calling this function, you will need to call 'unlockWallet' again+--   before being able to call methods which require the wallet to be unlocked.+--+--   Note: In future releases, we might introduce an "unlocked" monad, so+--         locking and unlocking is automatic.+lockWallet :: Auth -> IO ()+lockWallet auth = callApi auth "walletlock" []++-- | Encrypts the wallet with the given passphrase.+--+--   WARNING: bitcoind will shut down after calling this method. Don't say I+--            didn't warn you.+encryptWallet :: Auth -> Text -> IO ()+encryptWallet auth pass = stupidAPI <$> callApi auth "encryptwallet" [ tj pass ]+    where+        stupidAPI :: Text -> ()+        stupidAPI = const ()++-- | Just a handy wrapper to help us get only the "isvalid" field of the JSON.+--   The structure is much too complicated for what it needs to do.+data IsValid = IsValid { getValid :: Bool }++instance FromJSON IsValid where+    parseJSON (Object o) = IsValid <$> o .: "isvalid"+    parseJSON _ = mzero++-- | Checks if a given address is a valid one.+isAddressValid :: Auth -> Address -> IO Bool+isAddressValid auth addr = getValid <$> callApi auth "validateaddress" [ tj addr ]