Skip to content

Commit

Permalink
use decodeTransaction to get our outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jan 18, 2022
1 parent 1aaead6 commit 84f4061
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2347,9 +2347,11 @@ submitTransaction
-> ApiT WalletId
-> ApiSerialisedTransaction
-> Handler ApiTxId
submitTransaction ctx (ApiT wid) (ApiSerialisedTransaction (ApiT sealedTx)) = do
submitTransaction ctx apiw@(ApiT wid) apitx@(ApiSerialisedTransaction (ApiT sealedTx)) = do
ttl <- liftIO $ W.getTxExpiry ti Nothing
let (tx@(Tx txId _ _ inps outs wdrlMap _ _),_,_,_) = txDecoded
apiDecoded <- decodeTransaction @_ @s @k @n ctx apiw apitx
let outs = getOurOuts apiDecoded
let (tx@(Tx txId _ _ inps _outs wdrlMap _ _),_,_,_) = txDecoded

_ <- withWorkerCtx ctx wid liftE liftE $ \wrk -> do
(acct, _, _) <- liftHandler $ W.readRewardAccount @_ @s @k @n wrk wid
Expand All @@ -2372,6 +2374,15 @@ submitTransaction ctx (ApiT wid) (ApiSerialisedTransaction (ApiT sealedTx)) = do
nl = ctx ^. networkLayer
ti = timeInterpreter nl

isOutOurs (WalletOutput _) = True
isOutOurs _ = False
toTxOut (WalletOutput (ApiWalletOutput (ApiT addr, _) (Quantity amt) (ApiT tmap) _)) =
TxOut addr (TokenBundle (Coin $ fromIntegral amt) tmap)
toTxOut _ = error "we should have only our outputs at this point"
getOurOuts apiDecodedTx =
let generalOuts = apiDecodedTx ^. #outputs
in map toTxOut $ filter isOutOurs generalOuts

joinStakePool
:: forall ctx s n k.
( ctx ~ ApiLayer s k
Expand Down

0 comments on commit 84f4061

Please sign in to comment.