quietgarden/elm-web3/1.0.0

NOTE: the latest version is 2.0.1

Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/quietgarden/elm-web3 is gone (deleted or private); Software Heritage not asked yet (this run's --swh-calls were used up); no fork with tag 1.0.0 found (5 same-name repos checked); no cached copy. Use another version.

Details

Web3.Transaction

Transaction lifecycle state machine.

Every transaction goes through explicit states. Pattern matching forces you to handle every case — no "transaction failed silently" bugs.

case tx.status of
    Idle ->
        viewBuyButton


    AwaitingSignature ->
        viewSigningSpinner


    Submitted hash ->
        viewPendingWithHash hash


    Confirmed receipt ->
        viewSuccess receipt


    Failed err ->
        viewError err
type Status
= Idle
| AwaitingSignature
| Submitted TxHash
| Confirming TxHash Int
| Confirmed Receipt
| Failed String
| Rejected

Transaction lifecycle status. Cannot be in an invalid state.

type Msg
= TxSubmitted String
| TxConfirmation String Int
| TxConfirmed ReceiptJson
| TxFailed String
| TxRejected

Messages from the JS transaction port.

type alias Receipt =
{ txHash : TxHash
, blockNumber : Int
, gasUsed : String
, status : Bool
, logs : List EventLog
}

A confirmed transaction receipt, including emitted logs.

type alias EventLog =
{ address : Address
, topics : List String
, data : String
, blockNumber : Int
, logIndex : Int
}

A single log entry emitted during a transaction.

Update transaction status from a port message.

Transitions are guarded to match the TLA+ GuardedNext specification:

  • Terminal states (Confirmed, Failed, Rejected) never transition out.
  • TxSubmitted is only accepted from AwaitingSignature.
  • TxConfirmation is only accepted from Submitted or Confirming.
  • TxFailed and TxRejected are accepted from any non-terminal state.
isTerminal : Status -> Bool

Is this status terminal (no more updates expected)?

isPending : Status -> Bool

Is this status still pending?

decoder : Decoder Msg

Decode transaction messages from JS port.

parseReceiptEvents : List (EventLog -> Maybe a) -> Receipt -> List a

Apply a list of event decoders to the logs in a receipt, collecting all successfully decoded events.

type MyEvent
    = Transfer { from : Address, to : Address, amount : BigInt }
    | Approval { owner : Address, spender : Address, amount : BigInt }


decodeTransfer : EventLog -> Maybe MyEvent
decodeTransfer log =
    -- match topic[0] to Transfer signature, then decode
    ...


events : List MyEvent
events =
    parseReceiptEvents [ decodeTransfer, decodeApproval ] receipt