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

ElmArk.MultiSignature

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

Models

type alias PendingMultiSignature = { success : Bool , transactions : List Transaction }

Record for the response from getPending

type alias Transaction = { id : String , transactionType : String , subtype : String , timestamp : String , senderPublicKey : String , senderId : String , recipientId : String , amount : String , fee : String , signature : String , signSignature : String , companyGeneratorPublicKey : String , confirmations : String }

Transaction record for the list of transactions returned by getPendingMultiSignatureTransactions

Requests

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

Get pending multi signature transactions for an account

mainNet
    |> getPending "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181"

JSON

decodePendingMultiSignature : Json.Decode.Decoder PendingMultiSignature

Parse JSON into PendingMultiSignature record

encodePendingMultiSignature : PendingMultiSignature -> Json.Encode.Value

Turn PendingMultiSignature into JSON string

decodeTransaction : Json.Decode.Decoder Transaction

Parse JSON into Transaction record

encodeTransaction : Transaction -> Json.Encode.Value

Turn Tranasction record into JSON string

module ElmArk.MultiSignature exposing (..)

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


# Models

@docs PendingMultiSignature, Transaction


# Requests

@docs getPending


# JSON

@docs decodePendingMultiSignature, encodePendingMultiSignature, decodeTransaction, encodeTransaction

-}

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


{-| Get pending multi signature transactions for an account

    mainNet
        |> getPending "02c0b645f19ab304d25aae3add139edd9f6ca9fd0d98e57a808100de0e93832181"

-}
getPending : String -> RequestHead -> ( RequestHead, RequestBody )
getPending publicKey heads =
    ( heads, GetRequest (heads.url ++ "api/multisignatures/pending") [ ( "publicKey", publicKey ) ] )


{-| Record for the response from getPending
-}
type alias PendingMultiSignature =
    { success : Bool
    , transactions : List Transaction
    }


{-| Parse JSON into PendingMultiSignature record
-}
decodePendingMultiSignature : Json.Decode.Decoder PendingMultiSignature
decodePendingMultiSignature =
    Json.Decode.Pipeline.decode PendingMultiSignature
        |> Json.Decode.Pipeline.required "success" (Json.Decode.bool)
        |> Json.Decode.Pipeline.required "transactions" (Json.Decode.list decodeTransaction)


{-| Turn PendingMultiSignature into JSON string
-}
encodePendingMultiSignature : PendingMultiSignature -> Json.Encode.Value
encodePendingMultiSignature record =
    Json.Encode.object
        [ ( "success", Json.Encode.bool <| record.success )
        , ( "transactions", Json.Encode.list <| List.map encodeTransaction <| record.transactions )
        ]


{-| Transaction record for the list of transactions returned by getPendingMultiSignatureTransactions
-}
type alias Transaction =
    { id : String
    , transactionType : String
    , subtype : String
    , timestamp : String
    , senderPublicKey : String
    , senderId : String
    , recipientId : String
    , amount : String
    , fee : String
    , signature : String
    , signSignature : String
    , companyGeneratorPublicKey : String
    , confirmations : String
    }


{-| 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 "type" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "subtype" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "timestamp" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "senderPublicKey" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "senderId" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "recipientId" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "amount" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "fee" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "signature" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "signSignature" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "companyGeneratorPublicKey" (Json.Decode.string)
        |> Json.Decode.Pipeline.required "confirmations" (Json.Decode.string)


{-| Turn Tranasction record into JSON string
-}
encodeTransaction : Transaction -> Json.Encode.Value
encodeTransaction record =
    Json.Encode.object
        [ ( "id", Json.Encode.string <| record.id )
        , ( "type", Json.Encode.string <| record.transactionType )
        , ( "subtype", Json.Encode.string <| record.subtype )
        , ( "timestamp", Json.Encode.string <| record.timestamp )
        , ( "senderPublicKey", Json.Encode.string <| record.senderPublicKey )
        , ( "senderId", Json.Encode.string <| record.senderId )
        , ( "recipientId", Json.Encode.string <| record.recipientId )
        , ( "amount", Json.Encode.string <| record.amount )
        , ( "fee", Json.Encode.string <| record.fee )
        , ( "signature", Json.Encode.string <| record.signature )
        , ( "signSignature", Json.Encode.string <| record.signSignature )
        , ( "companyGeneratorPublicKey", Json.Encode.string <| record.companyGeneratorPublicKey )
        , ( "confirmations", Json.Encode.string <| record.confirmations )
        ]