bitcoin-payment-channel 0.1.1.3 → 0.2.0.0
raw patch · 5 files changed
+41/−20 lines, 5 filesdep +errorsPVP ok
version bump matches the API change (PVP)
Dependencies added: errors
API changes (from Hackage documentation)
+ Data.Bitcoin.PaymentChannel.Types: LockTimeBlockHeight :: Word32 -> BitcoinLockTime
+ Data.Bitcoin.PaymentChannel.Types: LockTimeDate :: UTCTime -> BitcoinLockTime
+ Data.Bitcoin.PaymentChannel.Types: getExpirationDate :: PaymentChannel a => a -> BitcoinLockTime
+ Data.Bitcoin.PaymentChannel.Types: instance Data.Aeson.Types.Class.FromJSON Data.Bitcoin.PaymentChannel.Types.ReceiverPaymentChannel
+ Data.Bitcoin.PaymentChannel.Types: instance Data.Aeson.Types.Class.ToJSON Data.Bitcoin.PaymentChannel.Types.ReceiverPaymentChannel
- Data.Bitcoin.PaymentChannel.Types: class PaymentChannel a where getChannelID = pcsChannelID . getChannelState channelValueLeft = channelValueLeft . getChannelState channelIsExhausted = channelIsExhausted . getChannelState
+ Data.Bitcoin.PaymentChannel.Types: class PaymentChannel a where getChannelID = pcsChannelID . getChannelState getExpirationDate = pcsExpirationDate . getChannelState channelValueLeft = channelValueLeft . getChannelState channelIsExhausted = channelIsExhausted . getChannelState
- Data.Bitcoin.PaymentChannel.Types: getChannelID :: PaymentChannel a => a -> TxHash
+ Data.Bitcoin.PaymentChannel.Types: getChannelID :: PaymentChannel a => a -> OutPoint
Files
- bitcoin-payment-channel.cabal +2/−1
- src/Data/Bitcoin/PaymentChannel/Internal/Serialization.hs +25/−11
- src/Data/Bitcoin/PaymentChannel/Internal/State.hs +5/−1
- src/Data/Bitcoin/PaymentChannel/Internal/Util.hs +0/−1
- src/Data/Bitcoin/PaymentChannel/Types.hs +9/−6
bitcoin-payment-channel.cabal view
@@ -1,5 +1,5 @@ name: bitcoin-payment-channel-version: 0.1.1.3+version: 0.2.0.0 synopsis: Library for working with Bitcoin payment channels description: A Bitcoin payment channel allows secure and instant transfer of bitcoins from one@@ -54,6 +54,7 @@ bytestring, text, base16-bytestring, base58string, hexstring, base64-bytestring, time,+ errors, cereal, binary, aeson, scientific hs-source-dirs: src
src/Data/Bitcoin/PaymentChannel/Internal/Serialization.hs view
@@ -17,9 +17,8 @@ import qualified Data.Binary.Get as BinGet import qualified Data.ByteString.Base64.URL as B64 import qualified Data.ByteString as B--import Debug.Trace-+import qualified Data.Text as T+import Data.EitherR (fmapL) instance Show Payment where@@ -29,6 +28,7 @@ -------JSON-------- + padToMod4 :: B.ByteString -> B.ByteString padToMod4 bs = let@@ -40,17 +40,25 @@ b64Encode :: Bin.Binary a => a -> B.ByteString b64Encode = B64.encode . toStrict . Bin.encode +b64Decode :: Bin.Binary a => B.ByteString -> Either String a+b64Decode b64 =+ concatErr "failed to deserialize parsed base64 data: " . deserEither =<<+ (concatErr "failed to parse base64 data: ") (b64Decode b64)+ where+ b64Decode = B64.decode . padToMod4+ concatErr e = fmapL (e ++)++txtB64Encode :: Bin.Binary a => a -> T.Text+txtB64Encode = decodeLatin1 . b64Encode++txtB64Decode :: Bin.Binary a => T.Text -> Parser a+txtB64Decode = either fail return . b64Decode . encodeUtf8+ instance ToJSON Payment where- toJSON = toJSON . decodeLatin1 . b64Encode+ toJSON = toJSON . txtB64Encode instance FromJSON Payment where- parseJSON = withText "Payment" $- \b64 ->- failOnLeftWith "failed to deserialize binary data: " . deserEither =<<- (failOnLeftWith "failed to parse base64 data: " . b64Decode) b64- where- b64Decode = B64.decode . padToMod4 . encodeUtf8- failOnLeftWith e = either (fail . (e ++)) return+ parseJSON = withText "Payment" txtB64Decode instance ToJSON BitcoinAmount where toJSON amt = Number $ scientific@@ -59,6 +67,12 @@ instance FromJSON BitcoinAmount where parseJSON = withScientific "BitcoinAmount" $ fmap fromIntegral . parseJSONInt++instance ToJSON PaymentChannelState where+ toJSON = toJSON . txtB64Encode++instance FromJSON PaymentChannelState where+ parseJSON = withText "PaychanState" txtB64Decode -- Needed to convert from Scientific instance Bounded BitcoinAmount where
src/Data/Bitcoin/PaymentChannel/Internal/State.hs view
@@ -15,10 +15,14 @@ pcsChannelValueLeft = pcsValueLeft pcsClientPubKey = cpSenderPubKey . pcsParameters pcsServerPubKey = cpReceiverPubKey . pcsParameters+pcsExpirationDate = cpLockTime . pcsParameters pcsClientChangeAddress = ptcSenderChangeAddress . pcsPaymentConfig pcsClientChange = addressToScriptPubKeyBS . pcsClientChangeAddress pcsLockTime = cpLockTime . pcsParameters-pcsChannelID = ftiHash . pcsFundingTxInfo++pcsChannelID :: PaymentChannelState -> HT.OutPoint+pcsChannelID pcs = HT.OutPoint (ftiHash fti) (ftiOutIndex fti)+ where fti = pcsFundingTxInfo pcs -- |Set new client/sender change address. -- Use this function if the client wishes to change its change address.
src/Data/Bitcoin/PaymentChannel/Internal/Util.hs view
@@ -136,7 +136,6 @@ parseBitcoinLocktime i | i < 500000000 = LockTimeBlockHeight i | i >= 500000000 = LockTimeDate $ posixSecondsToUTCTime (fromIntegral i)- | otherwise = error "BUG (in GHC?)" -- | Convert to Bitcoin format ('Word32') toWord32 :: BitcoinLockTime -> Word32
src/Data/Bitcoin/PaymentChannel/Types.hs view
@@ -22,7 +22,7 @@ PaymentChannelState, BitcoinAmount, toWord64,-BitcoinLockTime, fromDate,+BitcoinLockTime(..), fromDate, -- Util b64Encode,@@ -41,13 +41,14 @@ -- () import Data.Bitcoin.PaymentChannel.Internal.Util (BitcoinAmount(..), toWord64,- BitcoinLockTime, fromDate)+ BitcoinLockTime(..), fromDate) import qualified Data.Bitcoin.PaymentChannel.Internal.State as S (pcsChannelID, pcsChannelTotalValue, setClientChangeAddress,- channelValueLeft, channelIsExhausted)+ channelValueLeft, channelIsExhausted, pcsExpirationDate) import Data.Bitcoin.PaymentChannel.Internal.Error (PayChanError(..)) -- import Data.Bitcoin.PaymentChannel.Internal.Types () import qualified Data.Binary as Bin+import Data.Aeson as JSON -- (FromJSON, ToJSON) import qualified Network.Haskoin.Crypto as HC import qualified Network.Haskoin.Transaction as HT import qualified Network.Haskoin.Script as HS@@ -58,8 +59,8 @@ valueToMe :: a -> BitcoinAmount -- |Retrieve internal state object getChannelState :: a -> PaymentChannelState- -- |Get channel ID- getChannelID :: a -> HT.TxHash+ getChannelID :: a -> HT.OutPoint+ getExpirationDate :: a -> BitcoinLockTime -- |For internal use _setChannelState :: a -> PaymentChannelState -> a @@ -68,10 +69,12 @@ channelIsExhausted :: a -> Bool getChannelID = S.pcsChannelID . getChannelState+ getExpirationDate = S.pcsExpirationDate . getChannelState channelValueLeft = S.channelValueLeft . getChannelState channelIsExhausted = S.channelIsExhausted . getChannelState + -- |State object for the value sender data SenderPaymentChannel = CSenderPaymentChannel { -- |Internal state object@@ -86,7 +89,7 @@ newtype ReceiverPaymentChannel = CReceiverPaymentChannel { -- |Internal state object rpcState :: PaymentChannelState-} deriving (Eq, Bin.Binary)+} deriving (Eq, Bin.Binary, FromJSON, ToJSON) instance PaymentChannel SenderPaymentChannel where valueToMe = channelValueLeft