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 Data.Bitcoin.PaymentChannel.Internal.Crypto.PubKey
, 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 Data.Bitcoin.PaymentChannel.Internal.Crypto.PubKey
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
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)
type PayChanState = PaymentChannelState
type ChanParams = ChannelParameters
type ReceiverPaymentChannel = ReceiverPaymentChannelI ()
type ReceiverPaymentChannelX = ReceiverPaymentChannelI HC.XPubKey
data ReceiverPaymentChannelI pkInfo = CReceiverPaymentChannel {
rpcState :: PaymentChannelState
, rpcPubKeyInfo :: pkInfo
} deriving (Eq, Typeable)
instance Show ReceiverPaymentChannel where
show (CReceiverPaymentChannel s _) =
"<ReceiverPaymentChannel:\n\t" ++ show s ++ ">"
instance Show ReceiverPaymentChannelX where
show (CReceiverPaymentChannel s _) =
"<ReceiverPaymentChannelX:\n\t" ++ show s ++ ">"
rpcGetXPub = rpcPubKeyInfo
type Hour = Tag.Tagged "Hour" Word32
toSeconds :: Hour -> Integer
toSeconds = fromIntegral . (* 3600) . Tag.unTagged
defaultConfig = Config defaultDustLimit defaultSettlementPeriod
defaultDustLimit = 700 :: BitcoinAmount
defaultSettlementPeriod = 10 :: Hour