module Data.Bitcoin.PaymentChannel.Types
(
SenderPaymentChannel(..),
ReceiverPaymentChannel(..),
Payment,
FundingTxInfo(..),
ChannelParameters(..),
PayChanError,
BitcoinAmount, toWord64,
PaymentChannel(..),
BitcoinLockTime, fromDate
)
where
import Data.Bitcoin.PaymentChannel.Internal.Types
(PaymentChannelState(..), Payment(..)
,FundingTxInfo(..), ChannelParameters(..))
import Data.Bitcoin.PaymentChannel.Internal.Serialization
import Data.Bitcoin.PaymentChannel.Internal.Util
(BitcoinAmount, toWord64,
BitcoinLockTime, fromDate)
import Data.Bitcoin.PaymentChannel.Internal.State (pcsChannelID, pcsChannelTotalValue)
import Data.Bitcoin.PaymentChannel.Internal.Error (PayChanError(..))
import qualified Network.Haskoin.Crypto as HC
import qualified Network.Haskoin.Transaction as HT
data SenderPaymentChannel = CSenderPaymentChannel {
spcState :: PaymentChannelState,
spcSignFunc :: HC.Hash256 -> HC.Signature
}
data ReceiverPaymentChannel = CReceiverPaymentChannel {
rpcState :: PaymentChannelState,
rpcVerifyFunc :: HC.Hash256 -> HC.PubKey -> HC.Signature -> Bool,
rpcSignFunc :: HC.Hash256 -> HC.Signature
}
class PaymentChannel a where
valueToMe :: a -> BitcoinAmount
getChannelState :: a -> PaymentChannelState
getChannelID :: a -> HT.TxHash
channelIsExhausted :: a -> Bool
getChannelID = pcsChannelID . getChannelState
channelIsExhausted pch = pcsValueLeft (getChannelState pch) == 0
instance PaymentChannel SenderPaymentChannel where
valueToMe (CSenderPaymentChannel s _) =
pcsValueLeft s
getChannelState = spcState
instance PaymentChannel ReceiverPaymentChannel where
valueToMe (CReceiverPaymentChannel s _ _) =
pcsChannelTotalValue s pcsValueLeft s
getChannelState = rpcState
instance Show SenderPaymentChannel where
show (CSenderPaymentChannel s _) =
"<SenderPaymentChannel:\n\t" ++ show s ++ ">"
instance Show ReceiverPaymentChannel where
show (CReceiverPaymentChannel s _ _) =
"<ReceiverPaymentChannel:\n\t" ++ show s ++ ">"