guessTxSize :: Int         -- ^ Number of regular transaction inputs.
            -> [(Int,Int)]
               -- ^ For every multisig input in the transaction, provide
               -- the multisig parameters m of n (m,n) for that input.
            -> Int         -- ^ Number of pay to public key hash outputs.
            -> Int         -- ^ Number of pay to script hash outputs.
            -> Int         -- ^ Upper bound on the transaction size.
guessTxSize pki msi pkout msout =
    8 + inpLen + inp + outLen + out
  where
    inpLen = BS.length $ encode' $ VarInt $ fromIntegral $ (length msi) + pki
    outLen = BS.length $ encode' $ VarInt $ fromIntegral $ pkout + msout
    inp    = pki*148 + (sum $ map guessMSSize msi)
             -- (20: hash160) + (5: opcodes) +
             -- (1: script len) + (8: Word64)
    out    = pkout*34 +
             -- (20: hash160) + (3: opcodes) +
             -- (1: script len) + (8: Word64)
             msout*32

-- Size of a multisig pay2sh input
guessTxSize :: Int         -- ^ Number of regular transaction inputs.
            -> [(Int,Int)]
               -- ^ For every multisig input in the transaction, provide
               -- the multisig parameters m of n (m,n) for that input.
            -> Int         -- ^ Number of pay to public key hash outputs.
            -> Int         -- ^ Number of pay to script hash outputs.
            -> Int
guessTxSize pki msi pkout msout =
    8 + inpLen + inp + outLen + out
  where
    inpLen = BS.length $ encode' $ VarInt $ fromIntegral $ (length msi) + pki
    outLen = BS.length $ encode' $ VarInt $ fromIntegral $ pkout + msout
    inp    = pki*148 + (sum $ map guessMSSize msi)
             -- (20: hash160) + (5: opcodes) +
             -- (1: script len) + (8: Word64)
    out    = pkout*34 +
             -- (20: hash160) + (3: opcodes) +
             -- (1: script len) + (8: Word64)
             msout*32

-- Size of a multisig pay2sh input
guessTxSize pki msi pkout msout =
    8 + inpLen + inp + outLen + out
  where
    inpLen = BS.length $ encode' $ VarInt $ fromIntegral $ (length msi) + pki
    outLen = BS.length $ encode' $ VarInt $ fromIntegral $ pkout + msout
    inp    = pki*148 + (sum $ map guessMSSize msi)
             -- (20: hash160) + (5: opcodes) +
             -- (1: script len) + (8: Word64)
    out    = pkout*34 +
             -- (20: hash160) + (3: opcodes) +
             -- (1: script len) + (8: Word64)
             msout*32

-- Size of a multisig pay2sh input