Skip to content

Commit

Permalink
more decodeTransaction reusage
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jan 17, 2022
1 parent 999f1fe commit 8d88f78
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Expand Up @@ -1944,9 +1944,9 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
]

it "TRANS_NEW_BALANCE_05/ADP-1286 - \
\I can balance correctly in case I need to spend my remaining ADA for fee" $
\I can balance correctly in case I need to spend my remaining ADA for fee" $
\ctx -> runResourceT $ do
liftIO $ pendingWith
liftIO $ pendingWith
"ADP-1286 - ValueNotConservedUTxO: Transaction seems balanced incorrectly \
\in case when less than minUtxOValue is left on the wallet"
wa <- fixtureWalletWith @n ctx [3_000_000]
Expand All @@ -1955,7 +1955,7 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
let expectedFee = 1_000_000
let balancePayload = Json PlutusScenario.pingPong_1
let hasExpectedFee = [expectField (#fee . #getQuantity) (`shouldBe` expectedFee)]

rTx <- request @ApiSerialisedTransaction ctx
(Link.balanceTransaction @'Shelley wa) Default balancePayload
verify rTx [ expectResponseCode HTTP.status202 ]
Expand Down Expand Up @@ -2158,7 +2158,7 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
{ "transaction": #{sealedTx}
, "passphrase": #{fixturePassphrase}
}|]
(_, signedTx) <- second Prelude.id <$>
(_, signedTx) <- Prelude.id <$>
unsafeRequest @ApiSerialisedTransaction ctx signEndpoint toSign

-- Submit
Expand All @@ -2178,7 +2178,7 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
{ "transaction": #{sealedTx'}
, "passphrase": #{fixturePassphrase}
}|]
(_, signedTx') <- second Prelude.id <$>
(_, signedTx') <- Prelude.id <$>
unsafeRequest @ApiSerialisedTransaction ctx signEndpoint toSign'

-- Submit
Expand Down
14 changes: 6 additions & 8 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -2351,9 +2351,6 @@ submitTransaction ctx apiw@(ApiT wid) apitx@(ApiSerialisedTransaction (ApiT seal
apiDecoded <- decodeTransaction @_ @s @k @n ctx apiw apitx
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 @@ -2362,17 +2359,18 @@ submitTransaction ctx apiw@(ApiT wid) apitx@(ApiSerialisedTransaction (ApiT seal
{ txTimeToLive = ttl
, txWithdrawal = wdrl
}
txMeta <- liftHandler $ W.constructTxMeta @_ @s @k wrk wid txCtx ourInpsWithAmt ourOuts
txMeta <- liftHandler $ W.constructTxMeta @_ @s @k wrk wid txCtx ourInps ourOuts
liftHandler
$ W.submitTx @_ @s @k wrk wid (tx, txMeta, sealedTx)
return $ ApiTxId (ApiT txId)
return $ ApiTxId (apiDecoded ^. #id)
where
txDecoded = decodeTx tl sealedTx
(tx,_,_,_) = decodeTx tl sealedTx
tl = ctx ^. W.transactionLayer @k
ti :: TimeInterpreter (ExceptT PastHorizonException IO)
nl = ctx ^. networkLayer
ti = timeInterpreter nl


isOutOurs (WalletOutput _) = True
isOutOurs _ = False
toTxOut (WalletOutput (ApiWalletOutput (ApiT addr, _) (Quantity amt) (ApiT tmap) _)) =
Expand All @@ -2394,8 +2392,8 @@ submitTransaction ctx apiw@(ApiT wid) apitx@(ApiSerialisedTransaction (ApiT seal

isInpOurs (WalletInput _) = True
isInpOurs _ = False
toTxInp (WalletInput (ApiWalletInput (ApiT txid) ix _ _ _ _)) =
TxIn txid ix
toTxInp (WalletInput (ApiWalletInput (ApiT txid) ix _ _ (Quantity _amt) _)) =
(TxIn txid ix, Coin 0) -- $ fromIntegral amt)
toTxInp _ = error "we should have only our inputs at this point"
getOurInps apiDecodedTx =
let generalInps = apiDecodedTx ^. #inputs
Expand Down

0 comments on commit 8d88f78

Please sign in to comment.