Skip to content

Commit

Permalink
implement witness detection in submitTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jan 17, 2022
1 parent 40ff288 commit 9e5870a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
Expand Up @@ -102,6 +102,7 @@ module Test.Integration.Framework.TestData
, errMsg403TemplateInvalidScript
, errMsg403InvalidConstructTx
, errMsg403ForeignTransaction
, errMsg403MissingWitsInTransaction
) where

import Prelude
Expand Down Expand Up @@ -645,6 +646,13 @@ errMsg403ForeignTransaction = mconcat
, "or withdrawal belonging to the wallet."
]

errMsg403MissingWitsInTransaction :: Int -> Int -> String
errMsg403MissingWitsInTransaction expected got = mconcat
[ "The transaction has ", show expected
, " inputs and ", show got, " witnesses included."
, " Submit fully-signed transaction."
]

--------------------------------------------------------------------------------
-- Transaction metadata
--------------------------------------------------------------------------------
Expand Down
Expand Up @@ -177,6 +177,7 @@ import Test.Integration.Framework.TestData
, errMsg403ForeignTransaction
, errMsg403InvalidConstructTx
, errMsg403MinUTxOValue
, errMsg403MissingWitsInTransaction
, errMsg403NotDelegating
, errMsg403NotEnoughMoney
, errMsg404NoSuchPool
Expand Down Expand Up @@ -2077,7 +2078,8 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
-- Submit tx
submittedTx <- submitTxWithWid ctx w (ApiSerialisedTransaction sealedTx)
verify submittedTx
[ expectResponseCode HTTP.status500
[ expectResponseCode HTTP.status403
, expectErrorMessage (errMsg403MissingWitsInTransaction 1 0)
]

it "TRANS_NEW_SIGN_03 - Sign withdrawals" $ \ctx -> runResourceT $ do
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet.hs
Expand Up @@ -3069,7 +3069,7 @@ data BalanceTxNotSupportedReason
data ErrSubmitTransaction
= ErrSubmitTransactionNoSuchWallet ErrNoSuchWallet
| ErrSubmitTransactionForeignWallet
| ErrSubmitTransactionPartiallySignedOrNoSignedTx Word8 Word8
| ErrSubmitTransactionPartiallySignedOrNoSignedTx Int Int
deriving (Show, Eq)

-- | Errors that can occur when constructing an unsigned transaction.
Expand Down
9 changes: 8 additions & 1 deletion lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -446,6 +446,7 @@ import Cardano.Wallet.Primitive.Types.Tx
, TxOut (..)
, TxStatus (..)
, UnsignedTx (..)
, getSealedTxWitnesses
, txOutCoin
)
import Cardano.Wallet.Registry
Expand Down Expand Up @@ -2354,6 +2355,12 @@ submitTransaction ctx apiw@(ApiT wid) apitx@(ApiSerialisedTransaction (ApiT seal
let ourOuts = getOurOuts apiDecoded
let ourInps = getOurInps apiDecoded

let allInpsNum = length $ apiDecoded ^. #inputs
let witsNum = length $ getSealedTxWitnesses sealedTx
when (allInpsNum > witsNum) $
liftHandler $ throwE $
ErrSubmitTransactionPartiallySignedOrNoSignedTx allInpsNum witsNum

_ <- withWorkerCtx ctx wid liftE liftE $ \wrk -> do
(acct, _, path) <- liftHandler $ W.readRewardAccount @_ @s @k @n wrk wid
let wdrl = getOurWdrl acct path apiDecoded
Expand Down Expand Up @@ -3940,7 +3947,7 @@ instance IsServerError ErrSubmitTransaction where
]
ErrSubmitTransactionPartiallySignedOrNoSignedTx expectedWitsNo foundWitsNo ->
apiError err403 MissingWitnessesInTransaction $ mconcat $
[ "The transaction has ", toText expectedWitsNo,
[ "The transaction has ", toText expectedWitsNo
, " inputs and ", toText foundWitsNo, " witnesses included."
, " Submit fully-signed transaction."
]
Expand Down

0 comments on commit 9e5870a

Please sign in to comment.