@@ -11,13 +11,16 @@ module Cardano.Wallet.WalletLayer.Kernel.Active (
11
11
import qualified Serokell.Util.Base16 as B16
12
12
import Universum
13
13
14
+ import Control.Monad.Except (throwError )
14
15
import Data.Coerce (coerce )
15
16
import qualified Data.List.NonEmpty as NE
16
17
import Data.Time.Units (Second )
17
18
18
19
import Pos.Binary.Class (decodeFull' )
19
20
import Pos.Chain.Txp (Tx (.. ), TxSigData (.. ))
20
- import Pos.Core (Address , Coin , TxFeePolicy )
21
+ import Pos.Core (AddrAttributes (.. ), Address (.. ), Coin , TxFeePolicy )
22
+ import Pos.Core.Attributes (Attributes (.. ))
23
+ import Pos.Core.NetworkMagic (NetworkMagic , makeNetworkMagic )
21
24
import Pos.Crypto (PassPhrase , PublicKey , Signature (.. ))
22
25
23
26
import Cardano.Crypto.Wallet (xsignature )
@@ -29,6 +32,7 @@ import Cardano.Wallet.Kernel.CoinSelection.FromGeneric
29
32
InputGrouping , newOptions )
30
33
import qualified Cardano.Wallet.Kernel.DB.HdWallet as HD
31
34
import Cardano.Wallet.Kernel.DB.TxMeta.Types
35
+ import Cardano.Wallet.Kernel.Internal (walletProtocolMagic )
32
36
import qualified Cardano.Wallet.Kernel.NodeStateAdaptor as Node
33
37
import qualified Cardano.Wallet.Kernel.Transactions as Kernel
34
38
import Cardano.Wallet.WalletLayer (EstimateFeesError (.. ),
@@ -52,8 +56,35 @@ pay activeWallet pw grouping regulation payment = liftIO $ do
52
56
runExceptT $ do
53
57
(opts, accId, payees) <- withExceptT NewPaymentWalletIdDecodingFailed $
54
58
setupPayment policy grouping regulation payment
59
+
60
+ -- Verify that all payee addresses are of the same `NetworkMagic`
61
+ -- as our `ActiveWallet`.
62
+ let nm = makeNetworkMagic $ Kernel. walletPassive activeWallet ^. walletProtocolMagic
63
+ verifyPayeesNM nm payees
64
+
65
+ -- Pay the payees
55
66
withExceptT NewPaymentError $ ExceptT $
56
- Kernel. pay activeWallet pw opts accId payees
67
+ Kernel. pay activeWallet pw opts accId payees
68
+
69
+ -- | Verifies that the `NetworkMagic` of each payee address matches the
70
+ -- provided `NetworkMagic`.
71
+ verifyPayeesNM
72
+ :: Monad m
73
+ => NetworkMagic
74
+ -> NonEmpty (Address , Coin )
75
+ -> ExceptT NewPaymentError m ()
76
+ verifyPayeesNM nm payees = mapM_ verifyPayeeNM payees
77
+ where
78
+ addressHasValidMagic :: AddrAttributes -> Bool
79
+ addressHasValidMagic addrAttrs = nm == (aaNetworkMagic addrAttrs)
80
+ --
81
+ verifyPayeeNM
82
+ :: Monad m
83
+ => (Address , Coin )
84
+ -> ExceptT NewPaymentError m ()
85
+ verifyPayeeNM (addr, _) =
86
+ unless (addressHasValidMagic ((attrData . addrAttributes) addr)) $
87
+ throwError (NewPaymentAddressBadNetworkMagic addr nm )
57
88
58
89
-- | Estimates the fees for a payment.
59
90
estimateFees :: MonadIO m
0 commit comments