Commit 9320c2b2 authored by Cédric F.'s avatar Cédric F.

Decode prevOut

parent f641a6ca
Pipeline #13952971 (#) passed with stage
in 1 minute and 4 seconds
......@@ -83,12 +83,7 @@ view model =
[ td [] [ a [ href tx.hash ] [ text <| shortHash tx.hash ] ]
, td [] [ text tx.type_ ]
, td []
[ (Transaction.sentToAddress model.address tx
|> Maybe.map formatAmount
|> Maybe.withDefault
(span [] [ text "?" ])
)
]
[ Transaction.vInToAddress model.address tx |> formatAmount ]
, td [] [ text <| Transaction.formatTime tx ]
, td [] [ text <| toString tx.confirmations ]
]
......@@ -242,27 +237,13 @@ totalReceived model =
totalSent : Model -> Maybe Float
totalSent model =
let
amounts =
List.map (\tx -> Transaction.sentToAddress model.address tx)
model.transactions
unkown =
amounts |> List.any (\amount -> amount == Nothing)
in
if missingTransactions model then
Nothing
else if unkown then
Nothing
else
amounts
|> List.map (\amount -> Maybe.withDefault 0 amount)
|> List.sum
|> Just
--- FIXME: should not be a Maybe
if missingTransactions model then
Nothing
else
model.transactions
|> List.map (\tx -> Transaction.vInToAddress model.address tx)
|> List.sum
|> Just
balance : Model -> Maybe Float
......
......@@ -80,6 +80,13 @@ type alias VIn =
, coinbase : Maybe String
, amountIn : Float
, blockHeight : Maybe Int
, prevOut : Maybe PrevOut
}
type alias PrevOut =
{ addresses : List String
, value : Float
}
......@@ -315,6 +322,14 @@ decodeVIn =
|> Pipeline.optionalAt [ "coinbase" ] (Decode.maybe Decode.string) Nothing
|> Pipeline.optionalAt [ "amountin" ] Decode.float -1
|> Pipeline.optionalAt [ "blockheight" ] (Decode.maybe Decode.int) Nothing
|> Pipeline.optionalAt [ "prevOut" ] (Decode.maybe decodePrevOut) Nothing
decodePrevOut : Decode.Decoder PrevOut
decodePrevOut =
Pipeline.decode PrevOut
|> Pipeline.requiredAt [ "addresses" ] (Decode.list Decode.string)
|> Pipeline.requiredAt [ "value" ] Decode.float
decodeVOut : Decode.Decoder VOut
......@@ -413,8 +428,15 @@ formatTime model =
vInToAddress : String -> Model -> Float
vInToAddress address model =
model.vIn
|> List.filter (\vIn -> vIn.txId /= Nothing)
-- FIXME: txId or coinbase?
|> List.filter
(\vIn ->
case vIn.prevOut of
Nothing ->
False
Just prevOut ->
List.head prevOut.addresses == Just address
)
|> List.map .amountIn
|> List.sum
|> negate
......@@ -429,18 +451,6 @@ vOutToAddress address model =
|> List.sum
sentToAddress : String -> Model -> Maybe Float
sentToAddress address model =
let
outpoint =
model.vIn |> List.any (\vIn -> vIn.txId /= Nothing)
in
if outpoint then
Nothing
else
Just <| vOutToAddress address model
totalVIn : Model -> Float
totalVIn model =
List.map .amountIn model.vIn |> List.sum
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment