This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.

ElmArk.Transaction

Handles building requests for the transaction endpoints and encoding/decoding their json.

Models

type alias GetTransaction = { success : Bool , transaction : Transaction }

Record representing the getTransaction response Sample JSON:

   {
       "success": true,
       "transaction": {
           "id": "a38dc6b9e6679be706d5b39eef7dd0a7a10011e63da7623082106d90834e23e1",
           "blockid": "6119254423291710282",
           "height": 2411892,
           "type": 0,
           "timestamp": 19468149,
           "amount": 1,
           "fee": 10000000,
           "vendorField": "turnip",
           "senderId": "Aasu14aTs9ipZdy1FMv7ay1Vqn3jPskA8t",
           "recipientId": "AFuNopRKj2VwhaTWQraZgPTT5nofXskBTN",
           "senderPublicKey": "02c7455bebeadde04728441e0f57f82f972155c088252bf7c1365eb0dc84fbf5de",
           "signature": "3044022030ded9cd7a1cf37f6ae85b35fd478502c916d493ecb1c6df8b1a8392323559d3022040a45aac97a6d915bc19f9ad3927395e3240dacb1b81ad00d871182e4fa130b7",
           "asset": {},
           "confirmations": 544505
       }
   }
type alias Transaction = { id : String , blockid : String , height : Int , transactionType : Int , timestamp : Int , amount : Int , fee : Int , vendorField : String , senderId : String , recipientId : String , senderPublicKey : String , signature : String , asset : Asset , confirmations : Int }

Transaction is the transaction field of the GetTransaction record Sample JSON:

{
           "id": "a38dc6b9e6679be706d5b39eef7dd0a7a10011e63da7623082106d90834e23e1",
           "blockid": "6119254423291710282",
           "height": 2411892,
           "type": 0,
           "timestamp": 19468149,
           "amount": 1,
           "fee": 10000000,
           "vendorField": "turnip",
           "senderId": "Aasu14aTs9ipZdy1FMv7ay1Vqn3jPskA8t",
           "recipientId": "AFuNopRKj2VwhaTWQraZgPTT5nofXskBTN",
           "senderPublicKey": "02c7455bebeadde04728441e0f57f82f972155c088252bf7c1365eb0dc84fbf5de",
           "signature": "3044022030ded9cd7a1cf37f6ae85b35fd478502c916d493ecb1c6df8b1a8392323559d3022040a45aac97a6d915bc19f9ad3927395e3240dacb1b81ad00d871182e4fa130b7",
           "asset": {},
           "confirmations": 544505
       }
type alias Asset = { votes : List String }

Asset portion of the transaction record JSON Sample:

{
    "votes": [
        "+03d9ed6e7f29daf12ef925d4ce5753aade23c8cfd52a0427240fb30ad6ec232fed"
    ]
}
type alias Transactions = { success : Bool , transactions : List Transaction , count : String }

The response returned by getTransactions call Sample JSON:

{
    "success": true,
    "transactions": [
        {
            "id": "02ae724d4192f703d8469ff9f260f7bb98bbe63f566f777fe9cd7a4c5f3908d1",
            "blockid": "6721080189078847369",
            "type": 3,
            "timestamp": 20075314,
            "amount": 0,
            "fee": 100000000,
            "senderId": "AKbQwaxiBAEpYKwQne9DJGoQETrYzSZ4ir",
            "recipientId": "AKbQwaxiBAEpYKwQne9DJGoQETrYzSZ4ir",
            "senderPublicKey": "02720f075a369d4b956fcfc2d2d712f8caeb0a1de77f6b768e6ae1c55432fd2d4d",
            "signature": "3045022100dc3fba3d44ddb42eacbac1c9a293066cc8232d3a6eea680984f0909401fdc00b02200f250d111042621c025de49f1b1e830eb6a766964f90ef9beaf044e6554e18ff",
            "asset": {
                "votes": [
                    "+03d9ed6e7f29daf12ef925d4ce5753aade23c8cfd52a0427240fb30ad6ec232fed"
                ]
            },
            "confirmations": 470431
        }
    ],
    "count": "475011"

}

Requests

getTransaction : String -> RequestHead -> ( RequestHead, RequestBody )

Get the current fee for generating a signature

mainNet
    |> getTransaction "a38dc6b9e6679be706d5b39eef7dd0a7a10011e63da7623082106d90834e23e1"
getTransactions : List (String, String) -> RequestHead -> ( RequestHead, RequestBody )

Get the current fee for generating a signature Available Parameters: blockId, limit, type, orderBy, offset, senderPublicKey, vendorField, ownerPublicKey, ownerADdress, senderId, recipientId, amount, fee

mainNet
    |> getTransactions [("limit", "10"), ("orderBy", "amount")]
getUnconfirmedTransactions : RequestHead -> ( RequestHead, RequestBody )

Get all unconfirmed transactions

mainNet
    |> getUnconfirmedTransactions
getUnconfirmedTransaction : String -> RequestHead -> ( RequestHead, RequestBody )

Get an unconfirmed transaction

mainNet
    |> getUnconfirmedTransaction "a38dc6b9e6679be706d5b39eef7dd0a7a10011e63da7623082106d90834e23e1"

JSON

decodeGetTransaction : Json.Decode.Decoder GetTransaction

Parse JSON into GetTransaction record

encodeGetTransaction : GetTransaction -> Json.Encode.Value

Turn GetTransaction into JSON string

decodeTransaction : Json.Decode.Decoder Transaction

Parse JSON into Transaction record

encodeTransaction : Transaction -> Json.Encode.Value

Turn Transaction into JSON string

encodeAsset : Asset -> Json.Encode.Value

Turn Asset record into JSON

decodeAsset : Json.Decode.Decoder Asset

Parse JSON into Asset record

module ElmArk.Transaction exposing (..)

{-| Handles building requests for the transaction endpoints
and encoding/decoding their json.


# Models

@docs GetTransaction, Transaction, Asset, Transactions


# Requests

@docs getTransaction, getTransactions, getUnconfirmedTransactions, getUnconfirmedTransaction


# JSON

@docs decodeGetTransaction, encodeGetTransaction, decodeTransaction, encodeTransaction, encodeAsset, decodeAsset

-}

import ElmArk.Api.Model exposing (RequestBody(..), RequestHead)
import Json.Encode
import Json.Decode
import Json.Decode.Pipeline


{-| Get the current fee for generating a signature

    mainNet
        |> getTransaction "a38dc6b9e6679be706d5b39eef7dd0a7a10011e63da7623082106d90834e23e1"

-}
getTransaction : String -> RequestHead -> ( RequestHead, RequestBody )
getTransaction id heads =
    ( heads, GetRequest (heads.url ++ "api/transactions/get") [ ( "id", id ) ] )


{-| Record representing the getTransaction response
Sample JSON:

       {
           "success": true,
           "transaction": {
               "id": "a38dc6b9e6679be706d5b39eef7dd0a7a10011e63da7623082106d90834e23e1",
               "blockid": "6119254423291710282",
               "height": 2411892,
               "type": 0,
               "timestamp": 19468149,
               "amount": 1,
               "fee": 10000000,
               "vendorField": "turnip",
               "senderId": "Aasu14aTs9ipZdy1FMv7ay1Vqn3jPskA8t",
               "recipientId": "AFuNopRKj2VwhaTWQraZgPTT5nofXskBTN",
               "senderPublicKey": "02c7455bebeadde04728441e0f57f82f972155c088252bf7c1365eb0dc84fbf5de",
               "signature": "3044022030ded9cd7a1cf37f6ae85b35fd478502c916d493ecb1c6df8b1a8392323559d3022040a45aac97a6d915bc19f9ad3927395e3240dacb1b81ad00d871182e4fa130b7",
               "asset": {},
               "confirmations": 544505
           }
       }

-}
type alias GetTransaction =
    { success : Bool
    , transaction : Transaction
    }


{-| Transaction is the transaction field of the GetTransaction record
Sample JSON:

    {
               "id": "a38dc6b9e6679be706d5b39eef7dd0a7a10011e63da7623082106d90834e23e1",
               "blockid": "6119254423291710282",
               "height": 2411892,
               "type": 0,
               "timestamp": 19468149,
               "amount": 1,
               "fee": 10000000,
               "vendorField": "turnip",
               "senderId": "Aasu14aTs9ipZdy1FMv7ay1Vqn3jPskA8t",
               "recipientId": "AFuNopRKj2VwhaTWQraZgPTT5nofXskBTN",
               "senderPublicKey": "02c7455bebeadde04728441e0f57f82f972155c088252bf7c1365eb0dc84fbf5de",
               "signature": "3044022030ded9cd7a1cf37f6ae85b35fd478502c916d493ecb1c6df8b1a8392323559d3022040a45aac97a6d915bc19f9ad3927395e3240dacb1b81ad00d871182e4fa130b7",
               "asset": {},
               "confirmations": 544505
           }

-}
type alias Transaction =
    { id : String
    , blockid : String
    , height : Int
    , transactionType : Int
    , timestamp : Int
    , amount : Int
    , fee : Int
    , vendorField : String
    , senderId : String
    , recipientId : String
    , senderPublicKey : String
    , signature : String
    , asset : Asset
    , confirmations : Int
    }


{-| Parse JSON into GetTransaction record
-}
decodeGetTransaction : Json.Decode.Decoder GetTransaction
decodeGetTransaction =
    Json.Decode.Pipeline.decode GetTransaction
        |> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
        |> Json.Decode.Pipeline.required "transaction" (decodeTransaction)


{-| Parse JSON into Transaction record
-}
decodeTransaction : Json.Decode.Decoder Transaction
decodeTransaction =
    Json.Decode.Pipeline.decode Transaction
        |> Json.Decode.Pipeline.required "id" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "blockid" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "height" (Json.Decode.int)
        |> Json.Decode.Pipeline.required "type" (Json.Decode.int)
        |> Json.Decode.Pipeline.required "timestamp" (Json.Decode.int)
        |> Json.Decode.Pipeline.required "amount" (Json.Decode.int)
        |> Json.Decode.Pipeline.required "fee" (Json.Decode.int)
        |> Json.Decode.Pipeline.required "vendorField" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "senderId" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "recipientId" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "senderPublicKey" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "signature" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "asset" (decodeAsset)
        |> Json.Decode.Pipeline.required "confirmations" (Json.Decode.int)


{-| Turn GetTransaction into JSON string
-}
encodeGetTransaction : GetTransaction -> Json.Encode.Value
encodeGetTransaction record =
    Json.Encode.object
        [ ( "success", Json.Encode.bool <| record.success )
        , ( "transaction", encodeTransaction <| record.transaction )
        ]


{-| Turn Transaction into JSON string
-}
encodeTransaction : Transaction -> Json.Encode.Value
encodeTransaction record =
    Json.Encode.object
        [ ( "id", Json.Encode.string <| record.id )
        , ( "blockid", Json.Encode.string <| record.blockid )
        , ( "height", Json.Encode.int <| record.height )
        , ( "type", Json.Encode.int <| record.transactionType )
        , ( "timestamp", Json.Encode.int <| record.timestamp )
        , ( "amount", Json.Encode.int <| record.amount )
        , ( "fee", Json.Encode.int <| record.fee )
        , ( "vendorField", Json.Encode.string <| record.vendorField )
        , ( "senderId", Json.Encode.string <| record.senderId )
        , ( "recipientId", Json.Encode.string <| record.recipientId )
        , ( "senderPublicKey", Json.Encode.string <| record.senderPublicKey )
        , ( "signature", Json.Encode.string <| record.signature )
        , ( "asset", encodeAsset <| record.asset )
        , ( "confirmations", Json.Encode.int <| record.confirmations )
        ]
{-| Asset portion of the transaction record
JSON Sample:
```
{
    "votes": [
        "+03d9ed6e7f29daf12ef925d4ce5753aade23c8cfd52a0427240fb30ad6ec232fed"
    ]
}
```
-}
type alias Asset =
    { votes : List String
    }

{-| Parse JSON into Asset record
-}
decodeAsset : Json.Decode.Decoder Asset
decodeAsset =
    Json.Decode.Pipeline.decode Asset
        |> Json.Decode.Pipeline.required "votes" (Json.Decode.list Json.Decode.string)

{-| Turn Asset record into JSON
-}
encodeAsset : Asset -> Json.Encode.Value
encodeAsset record =
    Json.Encode.object
        [ ("votes",  Json.Encode.list <| List.map Json.Encode.string <| record.votes)
        ]

{-| Get the current fee for generating a signature
  Available Parameters: blockId, limit, type, orderBy, offset, senderPublicKey,
    vendorField, ownerPublicKey, ownerADdress, senderId, recipientId, amount, fee

    mainNet
        |> getTransactions [("limit", "10"), ("orderBy", "amount")]

-}
getTransactions : List (String, String) -> RequestHead -> ( RequestHead, RequestBody )
getTransactions params heads =
    ( heads, GetRequest (heads.url ++ "api/transactions") params )


{-| The response returned by getTransactions call
Sample JSON:
```
{
    "success": true,
    "transactions": [
        {
            "id": "02ae724d4192f703d8469ff9f260f7bb98bbe63f566f777fe9cd7a4c5f3908d1",
            "blockid": "6721080189078847369",
            "type": 3,
            "timestamp": 20075314,
            "amount": 0,
            "fee": 100000000,
            "senderId": "AKbQwaxiBAEpYKwQne9DJGoQETrYzSZ4ir",
            "recipientId": "AKbQwaxiBAEpYKwQne9DJGoQETrYzSZ4ir",
            "senderPublicKey": "02720f075a369d4b956fcfc2d2d712f8caeb0a1de77f6b768e6ae1c55432fd2d4d",
            "signature": "3045022100dc3fba3d44ddb42eacbac1c9a293066cc8232d3a6eea680984f0909401fdc00b02200f250d111042621c025de49f1b1e830eb6a766964f90ef9beaf044e6554e18ff",
            "asset": {
                "votes": [
                    "+03d9ed6e7f29daf12ef925d4ce5753aade23c8cfd52a0427240fb30ad6ec232fed"
                ]
            },
            "confirmations": 470431
        }
    ],
    "count": "475011"

}
```
-}
type alias Transactions =
    { success : Bool
    , transactions : List Transaction
    , count : String
    }

{-| Get an unconfirmed transaction

    mainNet
        |> getUnconfirmedTransaction "a38dc6b9e6679be706d5b39eef7dd0a7a10011e63da7623082106d90834e23e1"

-}
getUnconfirmedTransaction : String -> RequestHead -> ( RequestHead, RequestBody )
getUnconfirmedTransaction id heads =
    ( heads, GetRequest (heads.url ++ "api/transactions/unconfirmed/get") [("id", id)] )

{-| Get all unconfirmed transactions

    mainNet
        |> getUnconfirmedTransactions

-}
getUnconfirmedTransactions : RequestHead -> ( RequestHead, RequestBody )
getUnconfirmedTransactions heads =
    ( heads, GetRequest (heads.url ++ "api/transactions/unconfirmed") [] )