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

ElmArk.Loader

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

Models

type alias BlockStatus = { success : Bool , loaded : Bool , now : Int , blocksCount : Int }

Record for the block status response Sample JSON:

{
    "success": true,
    "loaded": false,
    "now": 2951259,
    "blocksCount": 0
}
type alias SyncStatus = { success : Bool , syncing : Bool , blocks : Int , height : Int , id : String }

Record for the syncStatus response Sample JSON:

{
    "success": true,
    "syncing": false,
    "blocks": 0,
    "height": 2955799,
    "id": "14925783039630880151"
}
type alias AutoConfigure = { success : Bool , network : Network }

Response from the autoconfigure loader call Sample JSON:

{
    "success": true,
    "network": {
        "nethash": "6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988",
        "token": "ARK",
        "symbol": "Ѧ",
        "explorer": "https://explorer.ark.io",
        "version": 23
    }
}
type alias Network = { nethash : String , token : String , symbol : String , explorer : String , version : Int }

Network portion of the autoconfigure loader respnose

{
    "nethash": "6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988",
    "token": "ARK",
    "symbol": "Ѧ",
    "explorer": "https://explorer.ark.io",
    "version": 23
}

Requests

getBlockStatus : RequestHead -> ( RequestHead, RequestBody )

Get the blockchain status

mainNet
    |> getBlockStatus
getSyncStatus : RequestHead -> ( RequestHead, RequestBody )

Get the syncronization status

mainNet
    |> getSyncStatus
autoconfigure : RequestHead -> ( RequestHead, RequestBody )

Autoconfigure the client

mainNet
    |> autoconfigure

JSON

decodeBlockStatus : Json.Decode.Decoder BlockStatus

Parse JSON into BlockStatus record

encodeBlockStatus : BlockStatus -> Json.Encode.Value

Turn BlockStatus into JSON string

decodeSyncStatus : Json.Decode.Decoder SyncStatus

Parse JSON into SyncStatus

encodeSyncStatus : SyncStatus -> Json.Encode.Value

Turn SyncStatus record into JSON string

decodeAutoConfigure : Json.Decode.Decoder AutoConfigure

Parses JSON into AutoConfigure record

encodeAutoConfigure : AutoConfigure -> Json.Encode.Value

Turn AutoConfigure record into JSON string

decodeNetwork : Json.Decode.Decoder Network

Parses JSON into Network record

encodeNetwork : Network -> Json.Encode.Value

Turn Network record into JSON string

module ElmArk.Loader exposing (..)

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


# Models

@docs BlockStatus, SyncStatus, AutoConfigure, Network


# Requests

@docs getBlockStatus, getSyncStatus, autoconfigure


# JSON

@docs decodeBlockStatus, encodeBlockStatus, decodeSyncStatus, encodeSyncStatus, decodeAutoConfigure, encodeAutoConfigure, decodeNetwork, encodeNetwork

-}

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


{-| Get the blockchain status

    mainNet
        |> getBlockStatus

-}
getBlockStatus : RequestHead -> ( RequestHead, RequestBody )
getBlockStatus heads =
    ( heads, GetRequest (heads.url ++ "api/loader/status") [] )


{-| Record for the block status response
Sample JSON:

    {
        "success": true,
        "loaded": false,
        "now": 2951259,
        "blocksCount": 0
    }

-}
type alias BlockStatus =
    { success : Bool
    , loaded : Bool
    , now : Int
    , blocksCount : Int
    }


{-| Parse JSON into BlockStatus record
-}
decodeBlockStatus : Json.Decode.Decoder BlockStatus
decodeBlockStatus =
    Json.Decode.Pipeline.decode BlockStatus
        |> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
        |> Json.Decode.Pipeline.required "loaded" (Json.Decode.bool)
        |> Json.Decode.Pipeline.required "now" (Json.Decode.int)
        |> Json.Decode.Pipeline.required "blocksCount" (Json.Decode.int)


{-| Turn BlockStatus into JSON string
-}
encodeBlockStatus : BlockStatus -> Json.Encode.Value
encodeBlockStatus record =
    Json.Encode.object
        [ ( "success", Json.Encode.bool <| record.success )
        , ( "loaded", Json.Encode.bool <| record.loaded )
        , ( "now", Json.Encode.int <| record.now )
        , ( "blocksCount", Json.Encode.int <| record.blocksCount )
        ]


{-| Get the syncronization status

    mainNet
        |> getSyncStatus

-}
getSyncStatus : RequestHead -> ( RequestHead, RequestBody )
getSyncStatus heads =
    ( heads, GetRequest (heads.url ++ "api/loader/status/sync") [] )


{-| Record for the syncStatus response
Sample JSON:

    {
        "success": true,
        "syncing": false,
        "blocks": 0,
        "height": 2955799,
        "id": "14925783039630880151"
    }

-}
type alias SyncStatus =
    { success : Bool
    , syncing : Bool
    , blocks : Int
    , height : Int
    , id : String
    }


{-| Parse JSON into SyncStatus
-}
decodeSyncStatus : Json.Decode.Decoder SyncStatus
decodeSyncStatus =
    Json.Decode.Pipeline.decode SyncStatus
        |> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
        |> Json.Decode.Pipeline.required "syncing" (Json.Decode.bool)
        |> Json.Decode.Pipeline.required "blocks" (Json.Decode.int)
        |> Json.Decode.Pipeline.required "height" (Json.Decode.int)
        |> Json.Decode.Pipeline.required "id" (Json.Decode.string)


{-| Turn SyncStatus record into JSON string
-}
encodeSyncStatus : SyncStatus -> Json.Encode.Value
encodeSyncStatus record =
    Json.Encode.object
        [ ( "success", Json.Encode.bool <| record.success )
        , ( "syncing", Json.Encode.bool <| record.syncing )
        , ( "blocks", Json.Encode.int <| record.blocks )
        , ( "height", Json.Encode.int <| record.height )
        , ( "id", Json.Encode.string <| record.id )
        ]


{-| Autoconfigure the client

    mainNet
        |> autoconfigure

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


{-| Response from the autoconfigure loader call
Sample JSON:

    {
        "success": true,
        "network": {
            "nethash": "6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988",
            "token": "ARK",
            "symbol": "Ѧ",
            "explorer": "https://explorer.ark.io",
            "version": 23
        }
    }

-}
type alias AutoConfigure =
    { success : Bool
    , network : Network
    }


{-| Network portion of the autoconfigure loader respnose

    {
        "nethash": "6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988",
        "token": "ARK",
        "symbol": "Ѧ",
        "explorer": "https://explorer.ark.io",
        "version": 23
    }

-}
type alias Network =
    { nethash : String
    , token : String
    , symbol : String
    , explorer : String
    , version : Int
    }


{-| Parses JSON into AutoConfigure record
-}
decodeAutoConfigure : Json.Decode.Decoder AutoConfigure
decodeAutoConfigure =
    Json.Decode.Pipeline.decode AutoConfigure
        |> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
        |> Json.Decode.Pipeline.required "network" (decodeNetwork)


{-| Parses JSON into Network record
-}
decodeNetwork : Json.Decode.Decoder Network
decodeNetwork =
    Json.Decode.Pipeline.decode Network
        |> Json.Decode.Pipeline.required "nethash" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "token" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "symbol" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "explorer" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "version" (Json.Decode.int)


{-| Turn AutoConfigure record into JSON string
-}
encodeAutoConfigure : AutoConfigure -> Json.Encode.Value
encodeAutoConfigure record =
    Json.Encode.object
        [ ( "success", Json.Encode.bool <| record.success )
        , ( "network", encodeNetwork <| record.network )
        ]


{-| Turn Network record into JSON string
-}
encodeNetwork : Network -> Json.Encode.Value
encodeNetwork record =
    Json.Encode.object
        [ ( "nethash", Json.Encode.string <| record.nethash )
        , ( "token", Json.Encode.string <| record.token )
        , ( "symbol", Json.Encode.string <| record.symbol )
        , ( "explorer", Json.Encode.string <| record.explorer )
        , ( "version", Json.Encode.int <| record.version )
        ]