Skip to content

Commit fab9e6f

Browse files
Fix build, READMEs and ChangeLog
1 parent 4fdd3d4 commit fab9e6f

File tree

8 files changed

+83
-59
lines changed

8 files changed

+83
-59
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# hydra-invoices
2+
3+
Invoice types and functions for the hydra lightning protocol.
4+
5+
This contains the following projects:
6+
* [hydra-invoices](hydra-invoices/)
7+
8+
## Building
9+
10+
```
11+
nix build
12+
````
13+
14+
## Development
15+
16+
```
17+
nix develop
18+
```
19+
20+
## Testing
21+
22+
```
23+
om ci run
24+
```

hydra-invoices/ChangeLog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
# Changelog for hydra-invoices
22

3-
## v0.1.0.0
3+
## v0.0.1.0
4+
5+
* Initial commit of `hydra-invoices`.
6+
* Add `Invoice` type with parameterisable fields.
7+
* Add `StandardInvoice` type with typical field types for use with `cardano-api`.
8+
* Add `generateStandardInvoice` function.

hydra-invoices/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# hydra-invoices
22

3-
This template is a barebones haskell template using
4-
[horizon-platform](https://gitlab.horizon-haskell.net/package-sets/horizon-platform).
5-
Just add things to the dependencies in the cabal file.
3+
Invoice types and functions for use with Hydra Lightning payments.
64

7-
To change the package set, just alter the `horizon` input field in the `flake.nix` to
8-
a different url and ref.
5+
An `Invoice` is a request for payment of a certain amount.
96

7+
You can use the `Hydra.Invoice.StandardInvoice` type for the most common use case - which
8+
uses standard types from `cardano-api` for its fields.

hydra-invoices/app/Main.hs

Lines changed: 0 additions & 6 deletions
This file was deleted.

hydra-invoices/hydra-invoices.cabal

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,10 @@ library
3131
build-depends:
3232
, bytestring
3333
, cardano-api
34-
, crypton
34+
, cardano-binary
35+
, cardano-crypto-class
3536
, random
3637
, time
3738

3839
exposed-modules: Hydra.Invoice
3940
hs-source-dirs: src
40-
41-
executable hydra-invoices
42-
import: lang
43-
main-is: Main.hs
44-
hs-source-dirs: app
45-
build-depends: hydra-invoices
46-
47-
test-suite hydra-invoices-tests
48-
import: lang
49-
type: exitcode-stdio-1.0
50-
main-is: Main.hs
51-
hs-source-dirs: test
52-
build-depends: hydra-invoices
Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
module Hydra.Invoice (
2-
Invoice (MkInvoice),
3-
PreImage,
4-
PaymentId,
5-
StandardInvoice,
6-
generatePreImage,
7-
hashPaymentId,
2+
Invoice (MkInvoice),
3+
PreImage (..),
4+
PaymentId (..),
5+
StandardInvoice,
6+
generatePreImage,
7+
hashPaymentId,
8+
generateStandardInvoice,
89
) where
910

10-
import Cardano.Api (Address, Hash, ShelleyAddr, Value)
11+
import Cardano.Api (Address, ShelleyAddr, Value)
12+
import Cardano.Binary qualified as CBOR
13+
import Cardano.Crypto.Hash qualified as Crypto
1114
import Control.Monad (replicateM)
12-
import Crypto.Hash qualified as CH
1315
import Data.ByteString qualified as BS
14-
import Data.ByteString.Lazy qualified as BSL
1516
import Data.Kind (Type)
1617
import Data.Time (UTCTime)
1718
import System.Random (randomRIO)
1819

1920
type Invoice :: Type -> Type -> Type -> Type -> Type
2021
data Invoice paymentIdType addressType amountType datetimeType = MkInvoice
21-
{ paymentId :: paymentIdType
22-
, recipient :: addressType
23-
, amount :: amountType
24-
, date :: datetimeType
25-
}
26-
deriving stock (Eq, Show)
22+
{ paymentId :: paymentIdType
23+
, recipient :: addressType
24+
, amount :: amountType
25+
, date :: datetimeType
26+
}
27+
deriving stock (Eq, Show)
2728

2829
type PreImage :: Type
2930
newtype PreImage = UnsafePreImage {fromPreImage :: BS.ByteString}
30-
deriving stock (Show, Eq)
31+
deriving stock (Show, Eq)
3132

3233
type PaymentId :: Type
33-
newtype PaymentId = UnsafePaymentId {fromPaymentId :: Hash BS.ByteString}
34+
newtype PaymentId = UnsafePaymentId {fromPaymentId :: Crypto.Hash Crypto.SHA256 BS.ByteString}
3435

3536
type StandardInvoice :: Type
3637
type StandardInvoice = Invoice PaymentId (Address ShelleyAddr) Value UTCTime
@@ -39,16 +40,17 @@ generatePreImage :: IO PreImage
3940
generatePreImage = UnsafePreImage . BS.pack <$> replicateM 32 (randomRIO (0, 255))
4041

4142
hashPaymentId :: PreImage -> PaymentId
42-
hashPaymentId (UnsafePreImage preimage) = UnsafePaymentId (CH.hashlazy $ BSL.fromStrict preimage)
43+
hashPaymentId (UnsafePreImage preimage) =
44+
UnsafePaymentId $ Crypto.hashWith CBOR.serialize' preimage
4345

4446
generateStandardInvoice :: Address ShelleyAddr -> Value -> UTCTime -> IO (StandardInvoice, PreImage)
4547
generateStandardInvoice recipient amount date = do
46-
preImage <- generatePreImage
47-
let invoice =
48-
MkInvoice
49-
{ paymentId = hashPaymentId preImage
50-
, recipient
51-
, amount
52-
, date
53-
}
54-
pure (invoice, preImage)
48+
preImage <- generatePreImage
49+
let invoice =
50+
MkInvoice
51+
{ paymentId = hashPaymentId preImage
52+
, recipient
53+
, amount
54+
, date
55+
}
56+
pure (invoice, preImage)

hydra-invoices/test/Main.hs

Lines changed: 0 additions & 6 deletions
This file was deleted.

weeder.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
roots = [
2+
"^Main.main$"
3+
, "^Spec.main$"
4+
, "^Paths_.*"
5+
]
6+
7+
root-instances = [
8+
{ class = '\.Eq$' }
9+
, { class = '\.Show$' }
10+
, { class = '\.Read$' }
11+
, { class = '\.Enum$' }
12+
, { class = '\.Bounded$' }
13+
, { class = '\.Generic$' }
14+
, { class = '\.Ord$' }
15+
, { class = '\.Num$' }
16+
, { class = '\.Real$' }
17+
, { class = '\.Integral$' }
18+
]

0 commit comments

Comments
 (0)