cmditch / elm-ethereum / Eth.Sentry.Tx

Core


type TxSentry msg


type Msg

update : Msg -> TxSentry msg -> ( TxSentry msg, Platform.Cmd.Cmd msg )

init : ( OutPort, InPort ) -> (Msg -> msg) -> Eth.Types.HttpProvider -> TxSentry msg


type alias OutPort =
Json.Decode.Value -> Platform.Cmd.Cmd Msg

The txOut port. Where information from your elm app is sent OUT to javascript land. Used for sending Send Tx parameters to Metamask, or other wallets.

port txOut : Value -> Cmd msg


type alias InPort =
(Json.Decode.Value -> Msg) -> Platform.Sub.Sub Msg

The txIn subscription. Where information from the outside comes IN to your elm app. Used for getting the TxHash response from Metamask, or other wallets.

 port txIn : (Value -> msg) -> Sub msg

listen : TxSentry msg -> Platform.Sub.Sub msg

Send Txs

send : (Result String Eth.Types.Tx -> msg) -> TxSentry msg -> Eth.Types.Send -> ( TxSentry msg, Platform.Cmd.Cmd msg )

sendWithReceipt : (Result String Eth.Types.Tx -> msg) -> (Result String Eth.Types.TxReceipt -> msg) -> TxSentry msg -> Eth.Types.Send -> ( TxSentry msg, Platform.Cmd.Cmd msg )

Custom Send


type alias CustomSend msg =
{ onSign : Maybe (Result String Eth.Types.TxHash -> msg)
, onBroadcast : Maybe (Result String Eth.Types.Tx -> msg)
, onMined : Maybe ( Result String Eth.Types.TxReceipt -> msg
, Maybe { confirmations : Basics.Int
, toMsg : TxTracker -> msg } ) 
}



onSign : Message after metamask/wallet has signed tx and returned tx hash
onBroadcast : Message after tx is confirmed sitting in tx queue on the node
onMined : ( message after tx is mined,
            (number of blocks deep to watch tx, message on each mined block after tx is sent - stops sending messages when first tuple value is reached)
          )


type alias TxTracker =
{ currentDepth : Basics.Int
, minedInBlock : Basics.Int
, stopWatchingAtBlock : Basics.Int
, lastCheckedBlock : Basics.Int
, txHash : Eth.Types.TxHash
, doneWatching : Basics.Bool
, reOrg : Basics.Bool 
}

For checking whether a tx has reached a certain block depth (# of confirmations) in a customSend

customSend : TxSentry msg -> CustomSend msg -> Eth.Types.Send -> ( TxSentry msg, Platform.Cmd.Cmd msg )

Utils

changeNode : Eth.Types.HttpProvider -> TxSentry msg -> TxSentry msg

Look into the errors this might cause, some kind of cleanup process should probably occur on changing a node.