From 999f1fed773e123589f4da6c307f6f38106c0947 Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Mon, 10 Jan 2022 16:16:28 +0100 Subject: [PATCH] use decodeTransaction for inputs --- lib/core/src/Cardano/Wallet/Api/Server.hs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/core/src/Cardano/Wallet/Api/Server.hs b/lib/core/src/Cardano/Wallet/Api/Server.hs index c36ac81bc67..7f73c7a1adc 100644 --- a/lib/core/src/Cardano/Wallet/Api/Server.hs +++ b/lib/core/src/Cardano/Wallet/Api/Server.hs @@ -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 @@ -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) @@ -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