Handles building requests for the delegate endpoints and encoding/decoding their json.
Represents the delegates count Sample JSON:
{
"success": true,
"count": 618
}
Result of searching for delegates Sample JSON:
{
"success": true,
"delegates": [
{
"username": "bioly",
"address": "AbUdMhk96FbzxH7vDYAwdyqUELmLopZV5x",
"publicKey": "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181",
"vote": "178069299134995",
"producedblocks": 57658,
"missedblocks": 254
}
]
}
Makes up the array of delegates in the delegate search Sample JSON:
{
"username": "bioly",
"address": "AbUdMhk96FbzxH7vDYAwdyqUELmLopZV5x",
"publicKey": "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181",
"vote": "178069299134995",
"producedblocks": 57658,
"missedblocks": 254
}
List of voters for a delegate Sample JSON:
{
"success": true,
"accounts": [
{
"username": null,
"address": "AUT1eGmsHkRrAt2Lvfp6j4ShmBZifzvMK9",
"publicKey": "0358a9d50272413bcf94314ca89745a6324aed911bd949b0fb6105fdfd0e291376",
"balance": "0"
},
{
"username": null,
"address": "AcU8ARQjwn6foUwP4NG2zEL6KLHFWmHcRq",
"publicKey": "02819a37539757154ef83036cb7f5c6d2a1731bef39c3733d7dca6393be0add747",
"balance": "0"
}
]
}
A single item in the accounts list returned by the getVoters call Sample JSON:
{
"username": null,
"address": "AUT1eGmsHkRrAt2Lvfp6j4ShmBZifzvMK9",
"publicKey": "0358a9d50272413bcf94314ca89745a6324aed911bd949b0fb6105fdfd0e291376",
"balance": "0"
}
Information about a delegate Sample JSON:
{
"success": true,
"delegate": {
"username": "bioly",
"address": "AbUdMhk96FbzxH7vDYAwdyqUELmLopZV5x",
"publicKey": "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181",
"vote": "178070099134995",
"producedblocks": 57662,
"missedblocks": 254,
"rate": 2,
"approval": 1.36,
"productivity": 99.56
}
}
A delegate object inside the delegate response Sample JSON:
{
"username": "bioly",
"address": "AbUdMhk96FbzxH7vDYAwdyqUELmLopZV5x",
"publicKey": "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181",
"vote": "178070099134995",
"producedblocks": 57662,
"missedblocks": 254,
"rate": 2,
"approval": 1.36,
"productivity": 99.56
}
Response from getting delegates Sample JSON:
{
"success": true,
"delegates": [
{
"username": "arknet",
"address": "AXzEMF7TC1aH3ax1Luxk6XdyKXDRxnBj4f",
"publicKey": "0217ff1ec656f2354a899bde097bb3131a9730fe491bb87dedb96489120be9154f",
"vote": "140295948126587",
"producedblocks": 39615,
"missedblocks": 31,
"rate": 25,
"approval": 1.07,
"productivity": 99.92
},
{
"username": "digitron",
"address": "APVpLtN9NxsNMyhLucP4vmFHHyyV2QKx4t",
"publicKey": "0339a6bb2aff249cd13b55fce2442703a1d488bae343a22fa09bbff46a6a64c5e2",
"vote": "135880318033725",
"producedblocks": 57905,
"missedblocks": 146,
"rate": 45,
"approval": 1.04,
"productivity": 99.75
}
],
"totalCount": 618
}
Item in the array returned by the getDelegates request Sample JSON:
{
"username": "digitron",
"address": "APVpLtN9NxsNMyhLucP4vmFHHyyV2QKx4t",
"publicKey": "0339a6bb2aff249cd13b55fce2442703a1d488bae343a22fa09bbff46a6a64c5e2",
"vote": "135880318033725",
"producedblocks": 57905,
"missedblocks": 146,
"rate": 45,
"approval": 1.04,
"productivity": 99.75
}
Response for getting the fees for becoming a delegate Sample JSON:
{
"success": true,
"fee": 2500000000
}
Blocks forged by an account Sample JSON:
{
"success": true,
"fees": "201040000000",
"rewards": "11258400000000",
"forged": "11459440000000"
}
List of the next forgers as returned by getNextForgers Sample JSON:
{
"success": true,
"currentBlock": 2955411,
"currentSlot": 2996756,
"delegates": [
"020431436cf94f3c6a6ba566fe9e42678db8486590c732ca6c3803a10a86f50b92",
"03ca4edbdc4e83eb6f1b8780a532c74a3708d51f281b6bfb9a308d49c47d3ac90d",
"02c44cc9787fae3ce5c8873ff541deadb86cd8ddb56a90dba37049ca6506d022f5",
"028f9f37a1fbf95bfa5b302032806116b27fd74996df7bcd6188c982f75e894ca4",
"02a0ed5604868461a87639f58bd3a55f661774c3cbb705a735f58c50087f942c3d",
"02a6b88567f86fa22d3c958f470c1645b3f65aa555e00c5bb0eecd2886eab80d34",
"035a0302ddd571bb821f6b069450814cb29fc927f14f146491fd5c9b3ab57d8ca8",
"02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181",
"027acdf24b004a7b1e6be2adf746e3233ce034dbb7e83d4a900f367efc4abd0f21",
"027c550ecc71e4d9b832cf83c1c5c4d7c22dc43e3a451fea887c82a6ef55bf52fa"
]
}
Get info about a block
mainNet
|> getDelegatesCount "AUexKjGtgsSpVzPLs6jNMM6vJ6znEVTQWK"
Search for specific delegates. Available parameters: limit
mainNet
|> searchDelegates "biol" [("limit", "10")]
Gets all the voters for a given public key
mainNet
|> getVoters "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181"
Gets info for a delegate by their username
mainNet
|> getDelegateByUsername "bioly"
Gets info for a delegate by their public key
mainNet
|> getDelegateByPublicKey "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181"
Gets all delegates filtered by optoinal parameters Available params: orderBy, limit, offset
mainNet
|> getDelegates [("limit", "2"), ("orderBy", "productivity")]
Gets the current fee to become a delegate
mainNet
|> getDelegateFee
Gets forged blocks by a given public key
mainNet
|> getForgedByAccount "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181"
Gets the next forgers
mainNet
|> getNextForgers
Parses JSON into DelegatesCount record
Turns DelegatesCount record into JSON string
Parses JSON into Delegates record
Turns Delegates record into JSON string
Parses JSON into Delegate record
Turns Delegate record into JSON string
Parses JSON into Voters record
Turns Voters record into JSON string
Parses JSON into Voter record
Turns Voter record into JSON string
Parse JSON into a DelegateResponse
Turn DelegateResponse into JSON
Parse JSON into a Delegate
Turn Delegate into JSON
Parses JSON into GetDelegates record
Parses JSON into GetDelegatesResponse
Turns GetDelegates into JSON string
Turns GetDelegatesResponse into JSON string
Parse JSON into DelegateFee record
Turn DelegateFee into JSON
Parses JSON into ForgedBlocks record
Turns ForgedBlocks record into JSON
Parse JSON into NextForgers record
Turn NextForgers record into JSON
module ElmArk.Delegate exposing (..)
{-| Handles building requests for the delegate endpoints
and encoding/decoding their json.
# Models
@docs DelegatesCount, Delegates, DelegateSearch, Voters, Voter, DelegateResponse, Delegate, GetDelegatesResponse, GetDelegates, DelegateFee, ForgedBlocks, NextForgers
# Requests
@docs getDelegatesCount, searchDelegates, getVoters, getDelegateByUsername, getDelegateByPublicKey, getDelegates, getDelegateFee, getForgedByAccount, getNextForgers
# JSON
@docs decodeDelegatesCount, encodeDelegatesCount, decodeDelegates, encodeDelegates, decodeDelegateSearch, encodeDelegateSearch, decodeVoters, encodeVoters, decodeVoter, encodeVoter, decodeDelegateResponse, encodeDelegateResponse, decodeDelegate, encodeDelegate, decodeGetDelegates, decodeGetDelegatesResponse, encodeGetDelegates, encodeGetDelegatesResponse, decodeDelegateFee, encodeDelegateFee, decodeForgedBlocks, encodeForgedBlocks, decodeNextForgers, encodeNextForgers
-}
import ElmArk.Api.Model exposing (RequestBody(..), RequestHead)
import Json.Encode
import Json.Encode.Extra
import Json.Decode
import Json.Decode.Pipeline
{-| Get info about a block
mainNet
|> getDelegatesCount "AUexKjGtgsSpVzPLs6jNMM6vJ6znEVTQWK"
-}
getDelegatesCount : String -> RequestHead -> ( RequestHead, RequestBody )
getDelegatesCount address heads =
( heads, GetRequest (heads.url ++ "api/delegates/count") [ ( "address", address ) ] )
{-| Represents the delegates count
Sample JSON:
{
"success": true,
"count": 618
}
-}
type alias DelegatesCount =
{ success : Bool
, count : Int
}
{-| Parses JSON into DelegatesCount record
-}
decodeDelegatesCount : Json.Decode.Decoder DelegatesCount
decodeDelegatesCount =
Json.Decode.Pipeline.decode DelegatesCount
|> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
|> Json.Decode.Pipeline.required "count" (Json.Decode.int)
{-| Turns DelegatesCount record into JSON string
-}
encodeDelegatesCount : DelegatesCount -> Json.Encode.Value
encodeDelegatesCount record =
Json.Encode.object
[ ( "success", Json.Encode.bool <| record.success )
, ( "count", Json.Encode.int <| record.count )
]
{-| Search for specific delegates.
Available parameters: limit
mainNet
|> searchDelegates "biol" [("limit", "10")]
-}
searchDelegates : String -> List ( String, String ) -> RequestHead -> ( RequestHead, RequestBody )
searchDelegates query params heads =
( heads, GetRequest (heads.url ++ "api/delegates/search") (( "q", query ) :: params) )
{-| Result of searching for delegates
Sample JSON:
{
"success": true,
"delegates": [
{
"username": "bioly",
"address": "AbUdMhk96FbzxH7vDYAwdyqUELmLopZV5x",
"publicKey": "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181",
"vote": "178069299134995",
"producedblocks": 57658,
"missedblocks": 254
}
]
}
-}
type alias Delegates =
{ success : Bool
, delegates : List Delegate
}
{-| Parses JSON into Delegates record
-}
decodeDelegates : Json.Decode.Decoder Delegates
decodeDelegates =
Json.Decode.Pipeline.decode Delegates
|> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
|> Json.Decode.Pipeline.required "delegates" (Json.Decode.list decodeDelegate)
{-| Turns Delegates record into JSON string
-}
encodeDelegates : Delegates -> Json.Encode.Value
encodeDelegates record =
Json.Encode.object
[ ( "success", Json.Encode.bool <| record.success )
, ( "delegates", Json.Encode.list <| List.map encodeDelegate <| record.delegates )
]
{-| Makes up the array of delegates in the delegate search
Sample JSON:
{
"username": "bioly",
"address": "AbUdMhk96FbzxH7vDYAwdyqUELmLopZV5x",
"publicKey": "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181",
"vote": "178069299134995",
"producedblocks": 57658,
"missedblocks": 254
}
-}
type alias DelegateSearch =
{ username : String
, address : String
, publicKey : String
, vote : String
, producedblocks : Int
, missedblocks : Int
}
{-| Parses JSON into Delegate record
-}
decodeDelegateSearch : Json.Decode.Decoder DelegateSearch
decodeDelegateSearch =
Json.Decode.Pipeline.decode DelegateSearch
|> Json.Decode.Pipeline.required "username" (Json.Decode.string)
|> Json.Decode.Pipeline.required "address" (Json.Decode.string)
|> Json.Decode.Pipeline.required "publicKey" (Json.Decode.string)
|> Json.Decode.Pipeline.required "vote" (Json.Decode.string)
|> Json.Decode.Pipeline.required "producedblocks" (Json.Decode.int)
|> Json.Decode.Pipeline.required "missedblocks" (Json.Decode.int)
{-| Turns Delegate record into JSON string
-}
encodeDelegateSearch : DelegateSearch -> Json.Encode.Value
encodeDelegateSearch record =
Json.Encode.object
[ ( "username", Json.Encode.string <| record.username )
, ( "address", Json.Encode.string <| record.address )
, ( "publicKey", Json.Encode.string <| record.publicKey )
, ( "vote", Json.Encode.string <| record.vote )
, ( "producedblocks", Json.Encode.int <| record.producedblocks )
, ( "missedblocks", Json.Encode.int <| record.missedblocks )
]
{-| Gets all the voters for a given public key
mainNet
|> getVoters "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181"
-}
getVoters : String -> RequestHead -> ( RequestHead, RequestBody )
getVoters publicKey heads =
( heads, GetRequest (heads.url ++ "api/delegates/voters") [ ( "publicKey", publicKey ) ] )
{-| List of voters for a delegate
Sample JSON:
{
"success": true,
"accounts": [
{
"username": null,
"address": "AUT1eGmsHkRrAt2Lvfp6j4ShmBZifzvMK9",
"publicKey": "0358a9d50272413bcf94314ca89745a6324aed911bd949b0fb6105fdfd0e291376",
"balance": "0"
},
{
"username": null,
"address": "AcU8ARQjwn6foUwP4NG2zEL6KLHFWmHcRq",
"publicKey": "02819a37539757154ef83036cb7f5c6d2a1731bef39c3733d7dca6393be0add747",
"balance": "0"
}
]
}
-}
type alias Voters =
{ success : Bool
, accounts : List Voter
}
{-| Parses JSON into Voters record
-}
decodeVoters : Json.Decode.Decoder Voters
decodeVoters =
Json.Decode.Pipeline.decode Voters
|> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
|> Json.Decode.Pipeline.required "accounts" (Json.Decode.list decodeVoter)
{-| Turns Voters record into JSON string
-}
encodeVoters : Voters -> Json.Encode.Value
encodeVoters record =
Json.Encode.object
[ ( "success", Json.Encode.bool <| record.success )
, ( "accounts", Json.Encode.list <| List.map encodeVoter <| record.accounts )
]
{-| A single item in the accounts list returned by the getVoters call
Sample JSON:
{
"username": null,
"address": "AUT1eGmsHkRrAt2Lvfp6j4ShmBZifzvMK9",
"publicKey": "0358a9d50272413bcf94314ca89745a6324aed911bd949b0fb6105fdfd0e291376",
"balance": "0"
}
-}
type alias Voter =
{ username : Maybe String
, address : String
, publicKey : String
, balance : String
}
{-| Parses JSON into Voter record
-}
decodeVoter : Json.Decode.Decoder Voter
decodeVoter =
Json.Decode.Pipeline.decode Voter
|> Json.Decode.Pipeline.required "username" (Json.Decode.nullable Json.Decode.string)
|> Json.Decode.Pipeline.required "address" (Json.Decode.string)
|> Json.Decode.Pipeline.required "publicKey" (Json.Decode.string)
|> Json.Decode.Pipeline.required "balance" (Json.Decode.string)
{-| Turns Voter record into JSON string
-}
encodeVoter : Voter -> Json.Encode.Value
encodeVoter record =
Json.Encode.object
[ ( "username", Json.Encode.Extra.maybe Json.Encode.string record.username )
, ( "address", Json.Encode.string <| record.address )
, ( "publicKey", Json.Encode.string <| record.publicKey )
, ( "balance", Json.Encode.string <| record.balance )
]
{-| Gets info for a delegate by their username
mainNet
|> getDelegateByUsername "bioly"
-}
getDelegateByUsername : String -> RequestHead -> ( RequestHead, RequestBody )
getDelegateByUsername username heads =
( heads, GetRequest (heads.url ++ "api/delegates/get") [ ( "username", username ) ] )
{-| Gets info for a delegate by their public key
mainNet
|> getDelegateByPublicKey "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181"
-}
getDelegateByPublicKey : String -> RequestHead -> ( RequestHead, RequestBody )
getDelegateByPublicKey publicKey heads =
( heads, GetRequest (heads.url ++ "api/delegates/get") [ ( "publicKey", publicKey ) ] )
{-| Information about a delegate
Sample JSON:
{
"success": true,
"delegate": {
"username": "bioly",
"address": "AbUdMhk96FbzxH7vDYAwdyqUELmLopZV5x",
"publicKey": "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181",
"vote": "178070099134995",
"producedblocks": 57662,
"missedblocks": 254,
"rate": 2,
"approval": 1.36,
"productivity": 99.56
}
}
-}
type alias DelegateResponse =
{ success : Bool
, delegate : Delegate
}
{-| A delegate object inside the delegate response
Sample JSON:
{
"username": "bioly",
"address": "AbUdMhk96FbzxH7vDYAwdyqUELmLopZV5x",
"publicKey": "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181",
"vote": "178070099134995",
"producedblocks": 57662,
"missedblocks": 254,
"rate": 2,
"approval": 1.36,
"productivity": 99.56
}
-}
type alias Delegate =
{ username : String
, address : String
, publicKey : String
, vote : String
, producedblocks : Int
, missedblocks : Int
, rate : Int
, approval : Float
, productivity : Float
}
{-| Parse JSON into a DelegateResponse
-}
decodeDelegateResponse : Json.Decode.Decoder DelegateResponse
decodeDelegateResponse =
Json.Decode.Pipeline.decode DelegateResponse
|> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
|> Json.Decode.Pipeline.required "delegate" (decodeDelegate)
{-| Parse JSON into a Delegate
-}
decodeDelegate : Json.Decode.Decoder Delegate
decodeDelegate =
Json.Decode.Pipeline.decode Delegate
|> Json.Decode.Pipeline.required "username" (Json.Decode.string)
|> Json.Decode.Pipeline.required "address" (Json.Decode.string)
|> Json.Decode.Pipeline.required "publicKey" (Json.Decode.string)
|> Json.Decode.Pipeline.required "vote" (Json.Decode.string)
|> Json.Decode.Pipeline.required "producedblocks" (Json.Decode.int)
|> Json.Decode.Pipeline.required "missedblocks" (Json.Decode.int)
|> Json.Decode.Pipeline.required "rate" (Json.Decode.int)
|> Json.Decode.Pipeline.required "approval" (Json.Decode.float)
|> Json.Decode.Pipeline.required "productivity" (Json.Decode.float)
{-| Turn DelegateResponse into JSON
-}
encodeDelegateResponse : DelegateResponse -> Json.Encode.Value
encodeDelegateResponse record =
Json.Encode.object
[ ( "success", Json.Encode.bool <| record.success )
, ( "delegate", encodeDelegate <| record.delegate )
]
{-| Turn Delegate into JSON
-}
encodeDelegate : Delegate -> Json.Encode.Value
encodeDelegate record =
Json.Encode.object
[ ( "username", Json.Encode.string <| record.username )
, ( "address", Json.Encode.string <| record.address )
, ( "publicKey", Json.Encode.string <| record.publicKey )
, ( "vote", Json.Encode.string <| record.vote )
, ( "producedblocks", Json.Encode.int <| record.producedblocks )
, ( "missedblocks", Json.Encode.int <| record.missedblocks )
, ( "rate", Json.Encode.int <| record.rate )
, ( "approval", Json.Encode.float <| record.approval )
, ( "productivity", Json.Encode.float <| record.productivity )
]
{-| Gets all delegates filtered by optoinal parameters
Available params: orderBy, limit, offset
mainNet
|> getDelegates [("limit", "2"), ("orderBy", "productivity")]
-}
getDelegates : List ( String, String ) -> RequestHead -> ( RequestHead, RequestBody )
getDelegates params heads =
( heads, GetRequest (heads.url ++ "api/delegates") params )
{-| Response from getting delegates
Sample JSON:
{
"success": true,
"delegates": [
{
"username": "arknet",
"address": "AXzEMF7TC1aH3ax1Luxk6XdyKXDRxnBj4f",
"publicKey": "0217ff1ec656f2354a899bde097bb3131a9730fe491bb87dedb96489120be9154f",
"vote": "140295948126587",
"producedblocks": 39615,
"missedblocks": 31,
"rate": 25,
"approval": 1.07,
"productivity": 99.92
},
{
"username": "digitron",
"address": "APVpLtN9NxsNMyhLucP4vmFHHyyV2QKx4t",
"publicKey": "0339a6bb2aff249cd13b55fce2442703a1d488bae343a22fa09bbff46a6a64c5e2",
"vote": "135880318033725",
"producedblocks": 57905,
"missedblocks": 146,
"rate": 45,
"approval": 1.04,
"productivity": 99.75
}
],
"totalCount": 618
}
-}
type alias GetDelegatesResponse =
{ success : Bool
, delegates : List GetDelegates
, totalCount : Int
}
{-| Parses JSON into GetDelegatesResponse
-}
decodeGetDelegatesResponse : Json.Decode.Decoder GetDelegatesResponse
decodeGetDelegatesResponse =
Json.Decode.Pipeline.decode GetDelegatesResponse
|> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
|> Json.Decode.Pipeline.required "delegates" (Json.Decode.list decodeGetDelegates)
|> Json.Decode.Pipeline.required "totalCount" (Json.Decode.int)
{-| Turns GetDelegatesResponse into JSON string
-}
encodeGetDelegatesResponse : GetDelegatesResponse -> Json.Encode.Value
encodeGetDelegatesResponse record =
Json.Encode.object
[ ( "success", Json.Encode.bool <| record.success )
, ( "delegates", Json.Encode.list <| List.map encodeGetDelegates <| record.delegates )
, ( "totalCount", Json.Encode.int <| record.totalCount )
]
{-| Item in the array returned by the getDelegates request
Sample JSON:
{
"username": "digitron",
"address": "APVpLtN9NxsNMyhLucP4vmFHHyyV2QKx4t",
"publicKey": "0339a6bb2aff249cd13b55fce2442703a1d488bae343a22fa09bbff46a6a64c5e2",
"vote": "135880318033725",
"producedblocks": 57905,
"missedblocks": 146,
"rate": 45,
"approval": 1.04,
"productivity": 99.75
}
-}
type alias GetDelegates =
{ username : String
, address : String
, publicKey : String
, vote : String
, producedblocks : Int
, missedblocks : Int
, rate : Int
, approval : Float
, productivity : Float
}
{-| Parses JSON into GetDelegates record
-}
decodeGetDelegates : Json.Decode.Decoder GetDelegates
decodeGetDelegates =
Json.Decode.Pipeline.decode GetDelegates
|> Json.Decode.Pipeline.required "username" (Json.Decode.string)
|> Json.Decode.Pipeline.required "address" (Json.Decode.string)
|> Json.Decode.Pipeline.required "publicKey" (Json.Decode.string)
|> Json.Decode.Pipeline.required "vote" (Json.Decode.string)
|> Json.Decode.Pipeline.required "producedblocks" (Json.Decode.int)
|> Json.Decode.Pipeline.required "missedblocks" (Json.Decode.int)
|> Json.Decode.Pipeline.required "rate" (Json.Decode.int)
|> Json.Decode.Pipeline.required "approval" (Json.Decode.float)
|> Json.Decode.Pipeline.required "productivity" (Json.Decode.float)
{-| Turns GetDelegates into JSON string
-}
encodeGetDelegates : GetDelegates -> Json.Encode.Value
encodeGetDelegates record =
Json.Encode.object
[ ( "username", Json.Encode.string <| record.username )
, ( "address", Json.Encode.string <| record.address )
, ( "publicKey", Json.Encode.string <| record.publicKey )
, ( "vote", Json.Encode.string <| record.vote )
, ( "producedblocks", Json.Encode.int <| record.producedblocks )
, ( "missedblocks", Json.Encode.int <| record.missedblocks )
, ( "rate", Json.Encode.int <| record.rate )
, ( "approval", Json.Encode.float <| record.approval )
, ( "productivity", Json.Encode.float <| record.productivity )
]
{-| Gets the current fee to become a delegate
mainNet
|> getDelegateFee
-}
getDelegateFee : RequestHead -> ( RequestHead, RequestBody )
getDelegateFee heads =
( heads, GetRequest (heads.url ++ "api/delegates/fee") [] )
{-| Response for getting the fees for becoming a delegate
Sample JSON:
{
"success": true,
"fee": 2500000000
}
-}
type alias DelegateFee =
{ success : Bool
, fee : Int
}
{-| Parse JSON into DelegateFee record
-}
decodeDelegateFee : Json.Decode.Decoder DelegateFee
decodeDelegateFee =
Json.Decode.Pipeline.decode DelegateFee
|> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
|> Json.Decode.Pipeline.required "fee" (Json.Decode.int)
{-| Turn DelegateFee into JSON
-}
encodeDelegateFee : DelegateFee -> Json.Encode.Value
encodeDelegateFee record =
Json.Encode.object
[ ( "success", Json.Encode.bool <| record.success )
, ( "fee", Json.Encode.int <| record.fee )
]
{-| Gets forged blocks by a given public key
mainNet
|> getForgedByAccount "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181"
-}
getForgedByAccount : String -> RequestHead -> ( RequestHead, RequestBody )
getForgedByAccount publicKey heads =
( heads, GetRequest (heads.url ++ "api/delegates/forging/getForgedByAccount") [ ( "generatorPublicKey", publicKey ) ] )
{-| Blocks forged by an account
Sample JSON:
{
"success": true,
"fees": "201040000000",
"rewards": "11258400000000",
"forged": "11459440000000"
}
-}
type alias ForgedBlocks =
{ success : Bool
, fees : String
, rewards : String
, forged : String
}
{-| Parses JSON into ForgedBlocks record
-}
decodeForgedBlocks : Json.Decode.Decoder ForgedBlocks
decodeForgedBlocks =
Json.Decode.Pipeline.decode ForgedBlocks
|> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
|> Json.Decode.Pipeline.required "fees" (Json.Decode.string)
|> Json.Decode.Pipeline.required "rewards" (Json.Decode.string)
|> Json.Decode.Pipeline.required "forged" (Json.Decode.string)
{-| Turns ForgedBlocks record into JSON
-}
encodeForgedBlocks : ForgedBlocks -> Json.Encode.Value
encodeForgedBlocks record =
Json.Encode.object
[ ( "success", Json.Encode.bool <| record.success )
, ( "fees", Json.Encode.string <| record.fees )
, ( "rewards", Json.Encode.string <| record.rewards )
, ( "forged", Json.Encode.string <| record.forged )
]
{-| Gets the next forgers
mainNet
|> getNextForgers
-}
getNextForgers : RequestHead -> ( RequestHead, RequestBody )
getNextForgers heads =
( heads, GetRequest (heads.url ++ "api/delegates/getNextForgers") [] )
{-| List of the next forgers as returned by getNextForgers
Sample JSON:
{
"success": true,
"currentBlock": 2955411,
"currentSlot": 2996756,
"delegates": [
"020431436cf94f3c6a6ba566fe9e42678db8486590c732ca6c3803a10a86f50b92",
"03ca4edbdc4e83eb6f1b8780a532c74a3708d51f281b6bfb9a308d49c47d3ac90d",
"02c44cc9787fae3ce5c8873ff541deadb86cd8ddb56a90dba37049ca6506d022f5",
"028f9f37a1fbf95bfa5b302032806116b27fd74996df7bcd6188c982f75e894ca4",
"02a0ed5604868461a87639f58bd3a55f661774c3cbb705a735f58c50087f942c3d",
"02a6b88567f86fa22d3c958f470c1645b3f65aa555e00c5bb0eecd2886eab80d34",
"035a0302ddd571bb821f6b069450814cb29fc927f14f146491fd5c9b3ab57d8ca8",
"02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181",
"027acdf24b004a7b1e6be2adf746e3233ce034dbb7e83d4a900f367efc4abd0f21",
"027c550ecc71e4d9b832cf83c1c5c4d7c22dc43e3a451fea887c82a6ef55bf52fa"
]
}
-}
type alias NextForgers =
{ success : Bool
, currentBlock : Int
, currentSlot : Int
, delegates : List String
}
{-| Parse JSON into NextForgers record
-}
decodeNextForgers : Json.Decode.Decoder NextForgers
decodeNextForgers =
Json.Decode.Pipeline.decode NextForgers
|> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
|> Json.Decode.Pipeline.required "currentBlock" (Json.Decode.int)
|> Json.Decode.Pipeline.required "currentSlot" (Json.Decode.int)
|> Json.Decode.Pipeline.required "delegates" (Json.Decode.list Json.Decode.string)
{-| Turn NextForgers record into JSON
-}
encodeNextForgers : NextForgers -> Json.Encode.Value
encodeNextForgers record =
Json.Encode.object
[ ( "success", Json.Encode.bool <| record.success )
, ( "currentBlock", Json.Encode.int <| record.currentBlock )
, ( "currentSlot", Json.Encode.int <| record.currentSlot )
, ( "delegates", Json.Encode.list <| List.map Json.Encode.string <| record.delegates )
]