Skip to content

Commit

Permalink
use decodeTransaction for inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jan 18, 2022
1 parent 1919f3d commit ee954e8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -2349,8 +2349,11 @@ submitTransaction
submitTransaction ctx apiw@(ApiT wid) apitx@(ApiSerialisedTransaction (ApiT sealedTx)) = do
ttl <- liftIO $ W.getTxExpiry ti Nothing
apiDecoded <- decodeTransaction @_ @s @k @n ctx apiw apitx
let outs = getOurOuts apiDecoded
let ourOuts = getOurOuts apiDecoded
let ourInps = getOurInps apiDecoded
let (tx@(Tx txId _ _ inps _ _ _ _),_,_,_) = txDecoded
let ourInpsWithAmt = filter (\(i,_) -> i `elem` ourInps) inps


_ <- withWorkerCtx ctx wid liftE liftE $ \wrk -> do
(acct, _, path) <- liftHandler $ W.readRewardAccount @_ @s @k @n wrk wid
Expand All @@ -2359,7 +2362,7 @@ submitTransaction ctx apiw@(ApiT wid) apitx@(ApiSerialisedTransaction (ApiT seal
{ txTimeToLive = ttl
, txWithdrawal = wdrl
}
txMeta <- liftHandler $ W.constructTxMeta @_ @s @k wrk wid txCtx inps outs
txMeta <- liftHandler $ W.constructTxMeta @_ @s @k wrk wid txCtx ourInpsWithAmt ourOuts
liftHandler
$ W.submitTx @_ @s @k wrk wid (tx, txMeta, sealedTx)
return $ ApiTxId (ApiT txId)
Expand Down Expand Up @@ -2389,6 +2392,15 @@ submitTransaction ctx apiw@(ApiT wid) apitx@(ApiSerialisedTransaction (ApiT seal
_ ->
NoWithdrawal

isInpOurs (WalletInput _) = True
isInpOurs _ = False
toTxInp (WalletInput (ApiWalletInput (ApiT txid) ix _ _ _ _)) =
TxIn txid ix
toTxInp _ = error "we should have only our inputs at this point"
getOurInps apiDecodedTx =
let generalInps = apiDecodedTx ^. #inputs
in map toTxInp $ filter isInpOurs generalInps

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

0 comments on commit ee954e8

Please sign in to comment.