diff --git a/wallet-api/src/Wallet/API.hs b/wallet-api/src/Wallet/API.hs index f1fb77b8796..ba11a61f431 100644 --- a/wallet-api/src/Wallet/API.hs +++ b/wallet-api/src/Wallet/API.hs @@ -22,6 +22,8 @@ module Wallet.API( payToScript_, payToPublicKey, payToPublicKey_, + payToScripts, + payToScripts_, collectFromScript, collectFromScriptTxn, ownPubKeyTxOut, @@ -275,13 +277,25 @@ throwOtherError = throwError . OtherError createPayment :: (Functor m, WalletAPI m) => Value -> m (Set.Set TxIn') createPayment vl = fst <$> createPaymentWithChange vl +-- | Transfer some funds to a number of script addresses, returning the +-- transaction that was submitted. +payToScripts :: (Monad m, WalletAPI m) => [(Address', Value, DataScript)] -> m Tx +payToScripts ins = do + let + totalVal = getSum $ foldMap (Sum . view _2) ins + otherOutputs = fmap (\(addr, vl, ds) -> TxOut addr vl (PayToScript ds)) ins + (i, ownChange) <- createPaymentWithChange totalVal + signAndSubmit i (maybe otherOutputs (:otherOutputs) ownChange) + +-- | Transfer some funds to a number of script addresses, returning the +-- transaction that was submitted. +payToScripts_ :: (Monad m, WalletAPI m) => [(Address', Value, DataScript)] -> m () +payToScripts_ = void . payToScripts + -- | Transfer some funds to an address locked by a script, returning the -- transaction that was submitted. payToScript :: (Monad m, WalletAPI m) => Address' -> Value -> DataScript -> m Tx -payToScript addr v ds = do - (i, own) <- createPaymentWithChange v - let other = TxOut addr v (PayToScript ds) - signAndSubmit i (other : maybeToList own) +payToScript addr v ds = payToScripts [(addr, v, ds)] -- | Transfer some funds to an address locked by a script. payToScript_ :: (Monad m, WalletAPI m) => Address' -> Value -> DataScript -> m ()