-
Notifications
You must be signed in to change notification settings - Fork 51
/
Serialization.purs
51 lines (43 loc) · 1.05 KB
/
Serialization.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module Lib.Serialization
( Buffer
, Hex(..)
, utxoFromHex
, _addrFromBytes
, _hexToBytes
) where
import Prelude
import Undefined
import Data.Argonaut (Json)
import Data.BigInt (BigInt)
import Data.Maybe (Maybe(..))
import Types.Transaction
( Address
, TransactionUnspentOutput
, Value(..)
)
newtype Hex
= Hex String
utxoFromHex :: Hex -> TransactionUnspentOutput
utxoFromHex = _utxoFromBytes helper <<< _hexToBytes
where
helper =
{ just: Just
, nothing: Nothing
, fromString: undefined -- TODO
, decodeValue: undefined -- TODO
}
foreign import data Buffer :: Type
foreign import _hexToBytes :: Hex -> Buffer
foreign import _addrFromBytes :: Buffer -> Address
foreign import _utxoFromBytes ::
UtxoHelper ->
Buffer ->
TransactionUnspentOutput
-- Some functions to help convert from the serialization-lib
-- `UnspentTransactionOutput` to something we can use
type UtxoHelper
= { just :: String -> Maybe String
, nothing :: Maybe String
, fromString :: String -> BigInt
, decodeValue :: Json -> Value
}