module Data.Bitcoin.PaymentChannel.Internal.Types
(
module Data.Bitcoin.PaymentChannel.Internal.Types
, module Data.Bitcoin.PaymentChannel.Internal.Bitcoin.Amount
, module Data.Bitcoin.PaymentChannel.Internal.Bitcoin.LockTime
, module Network.Haskoin.Transaction
, module Network.Haskoin.Crypto
, module Network.Haskoin.Script
)
where
import Data.Bitcoin.PaymentChannel.Internal.Util
import Data.Bitcoin.PaymentChannel.Internal.Bitcoin.Amount
import Data.Bitcoin.PaymentChannel.Internal.Bitcoin.LockTime
import Network.Haskoin.Transaction
import Network.Haskoin.Crypto
import Network.Haskoin.Script
import qualified Network.Haskoin.Transaction as HT
import qualified Network.Haskoin.Crypto as HC
import qualified Network.Haskoin.Script as HS
import Data.Typeable
import Data.Word
import qualified Data.Tagged as Tag
defaultConfig = Config defaultDustLimit defaultSettlementPeriod
defaultDustLimit = 700 :: BitcoinAmount
defaultSettlementPeriod = 10 :: Hour
newtype UnsignedPaymentTx = CUnsignedPaymentTx { unsignedTx :: HT.Tx } deriving Show
type FinalTx = HT.Tx
data PaymentChannelState = CPaymentChannelState {
pcsConfig :: Config,
pcsParameters :: ChannelParameters,
pcsFundingTxInfo :: FundingTxInfo,
pcsPaymentConfig :: PaymentTxConfig,
pcsPaymentCount :: Word64,
pcsClientChangeVal :: BitcoinAmount,
pcsPaymentSignature :: PaymentSignature
} deriving (Eq, Show, Typeable)
data ChannelParameters = CChannelParameters {
cpSenderPubKey :: SendPubKey,
cpReceiverPubKey :: RecvPubKey,
cpLockTime :: BitcoinLockTime
} deriving (Eq, Show, Typeable)
data FundingTxInfo = CFundingTxInfo {
ftiHash :: HT.TxHash,
ftiOutIndex :: Word32,
ftiOutValue :: BitcoinAmount
} deriving (Eq, Show, Typeable)
data PaymentTxConfig = CPaymentTxConfig {
ptcSenderChangeAddress :: HC.Address
} deriving (Eq, Show, Typeable)
data Config = Config {
cDustLimit :: BitcoinAmount
, cSettlementPeriod :: Hour
} deriving (Eq, Show, Typeable)
data Payment = CPayment {
cpClientChange :: BitcoinAmount
, cpSignature :: PaymentSignature
} deriving (Eq, Typeable)
data FullPayment = CFullPayment {
fpPayment :: Payment
, fpOutPoint :: HT.OutPoint
, fpRedeemScript :: HS.Script
, fpChangeAddr :: HC.Address
} deriving (Eq, Typeable)
data PaymentSignature = CPaymentSignature {
psSig :: HC.Signature
,psSigHash :: HS.SigHash
} deriving (Eq, Show, Typeable)
newtype ChanScript = ChanScript { getScript :: HS.Script } deriving (Eq, Show)
newtype SendPubKey = MkSendPubKey {
getSenderPK :: HC.PubKey
} deriving (Eq, Show)
newtype RecvPubKey = MkRecvPubKey {
getReceiverPK :: HC.PubKey
} deriving (Eq, Show)
class IsPubKey a where
getPubKey :: a -> HC.PubKey
instance IsPubKey SendPubKey where
getPubKey = getSenderPK
instance IsPubKey RecvPubKey where
getPubKey = getReceiverPK
type Hour = Tag.Tagged "Hour" Word32
toSeconds :: Hour -> Integer
toSeconds = fromIntegral . (* 3600) . Tag.unTagged