Sends API calls to the ark network
Contains the URL and required headers for making a request to the Ark mainnet
Ark main net, refers to this IP "http://37.59.129.164:4001/"
mainNet == { url = "https://api.arknode.net/"
, headers =
[ (header "nethash" "6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988")
, (header "version" "1.0.1")
, (header "port" "4001")
]
}
Contains the URL and required headers for making a request to the Ark dev/test network
devNet == { url = "http://167.114.29.52:4002/"
, headers =
[ (header "nethash" "578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23")
, (header "version" "1.1.1")
, (header "port" "4002")
]
}
Sends the HTTP request
mainNet
|> getBalance "AUexKjGtgsSpVzPLs6jNMM6vJ6znEVTQWK"
|> send ReceiveAccountBalance decodeBalance
module ElmArk.Api exposing (mainNet, devNet, send)
{-| Sends API calls to the ark network
# Environments
@docs mainNet, devNet
# Requests
@docs send
-}
import Http exposing (header)
import QueryString
import Json.Decode
import ElmArk.Api.Model exposing (RequestHead, RequestBody(..))
{-| Contains the URL and required headers for making
a request to the Ark mainnet
Ark main net, refers to this IP
"http://37.59.129.164:4001/"
mainNet == { url = "https://api.arknode.net/"
, headers =
[ (header "nethash" "6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988")
, (header "version" "1.0.1")
, (header "port" "4001")
]
}
-}
mainNet : RequestHead
mainNet =
{ url = "https://api.arknode.net/"
, headers =
[ (header "nethash" "6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988")
, (header "version" "1.0.1")
, (header "port" "4001")
]
}
{-| Contains the URL and required headers for making
a request to the Ark dev/test network
devNet == { url = "http://167.114.29.52:4002/"
, headers =
[ (header "nethash" "578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23")
, (header "version" "1.1.1")
, (header "port" "4002")
]
}
-}
devNet : RequestHead
devNet =
{ url = "http://167.114.29.52:4002/"
, headers =
[ (header "nethash" "578e820911f24e039733b45e4882b73e301f813a0d2c31330dafda84534ffa23")
, (header "version" "1.1.1")
, (header "port" "4002")
]
}
buildRequest : RequestHead -> RequestBody -> Json.Decode.Decoder a -> Http.Request a
buildRequest reqHead body decoder =
let
{ url, headers } =
reqHead
in
case body of
GetRequest url params ->
let
q =
List.foldl (\( key, param ) acc -> QueryString.add key param acc) QueryString.empty params
|> QueryString.render
in
Http.request
{ method = "GET"
, headers = headers
, url = url ++ q
, body = Http.emptyBody
, expect = Http.expectJson decoder
, timeout = Nothing
, withCredentials = False
}
{-| Sends the HTTP request
mainNet
|> getBalance "AUexKjGtgsSpVzPLs6jNMM6vJ6znEVTQWK"
|> send ReceiveAccountBalance decodeBalance
-}
send : (Result Http.Error a -> msg) -> Json.Decode.Decoder a -> ( RequestHead, RequestBody ) -> Cmd msg
send msg decoder ( headers, body ) =
let
request =
buildRequest headers body decoder
in
Http.send msg request