@@ -25,31 +25,8 @@ module Bitcoin.Transaction.Builder (
25
25
mergeTxInput ,
26
26
findSigInput ,
27
27
verifyStdInput ,
28
-
29
- -- * Coin Selection
30
- Coin (.. ),
31
- countMulSig ,
32
- guessTxFee ,
33
- guessMSTxFee ,
34
- guessTxSize ,
35
- guessMSSize ,
36
28
) where
37
29
38
- import Control.Applicative ((<|>) )
39
- import Control.Arrow (first )
40
- import Control.Monad (foldM , unless )
41
- import Control.Monad.Identity (runIdentity )
42
- import Crypto.Secp256k1
43
- import qualified Data.ByteString as B
44
- import Data.Bytes.Get
45
- import Data.Bytes.Put
46
- import Data.Bytes.Serial
47
- import Data.Either (fromRight )
48
- import Data.List (nub )
49
- import Data.Maybe (catMaybes , fromJust , isJust )
50
- import Data.String.Conversions (cs )
51
- import Data.Text (Text )
52
- import Data.Word (Word64 )
53
30
import Bitcoin.Address
54
31
import Bitcoin.Crypto.Hash (Hash256 , addressHash )
55
32
import Bitcoin.Crypto.Signature
@@ -71,86 +48,21 @@ import Bitcoin.Transaction.Segwit (
71
48
viewWitnessProgram ,
72
49
)
73
50
import Bitcoin.Util
74
-
75
-
76
- -- | Any type can be used as a Coin if it can provide a value in Satoshi.
77
- -- The value is used in coin selection algorithms.
78
- class Coin c where
79
- coinValue :: c -> Word64
80
-
81
-
82
- -- | Estimate tranasction fee to pay based on transaction size estimation.
83
- guessTxFee :: Word64 -> Int -> Int -> Word64
84
- guessTxFee byteFee nOut nIn =
85
- byteFee * fromIntegral (guessTxSize nIn [] nOut 0 )
86
-
87
-
88
- -- | Same as 'guessTxFee' but for multisig transactions.
89
- guessMSTxFee :: Word64 -> (Int , Int ) -> Int -> Int -> Word64
90
- guessMSTxFee byteFee ms nOut nIn =
91
- byteFee * fromIntegral (guessTxSize 0 (replicate nIn ms) nOut 0 )
92
-
93
-
94
- -- | Computes an upper bound on the size of a transaction based on some known
95
- -- properties of the transaction.
96
- guessTxSize ::
97
- -- | number of regular transaction inputs
98
- Int ->
99
- -- | multisig m of n for each input
100
- [(Int , Int )] ->
101
- -- | number of P2PKH outputs
102
- Int ->
103
- -- | number of P2SH outputs
104
- Int ->
105
- -- | upper bound on transaction size
106
- Int
107
- guessTxSize pki msi pkout msout =
108
- 8 + inpLen + inp + outLen + out
109
- where
110
- inpLen =
111
- B. length
112
- . runPutS
113
- . serialize
114
- . VarInt
115
- . fromIntegral
116
- $ length msi + pki
117
- outLen =
118
- B. length
119
- . runPutS
120
- . serialize
121
- . VarInt
122
- . fromIntegral
123
- $ pkout + msout
124
- inp = pki * 148 + sum (map guessMSSize msi)
125
- -- (20: hash160) + (5: opcodes) +
126
- -- (1: script len) + (8: Word64)
127
- out =
128
- pkout * 34
129
- +
130
- -- (20: hash160) + (3: opcodes) +
131
- -- (1: script len) + (8: Word64)
132
- msout * 32
133
-
134
-
135
- -- | Size of a multisig P2SH input.
136
- guessMSSize :: (Int , Int ) -> Int
137
- guessMSSize (m, n) =
138
- -- OutPoint (36) + Sequence (4) + Script
139
- 40
140
- + fromIntegral (B. length $ runPutS . serialize $ VarInt $ fromIntegral scp)
141
- + scp
142
- where
143
- -- OP_M + n*PubKey + OP_N + OP_CHECKMULTISIG
144
-
145
- rdm =
146
- fromIntegral
147
- . B. length
148
- . runPutS
149
- . serialize
150
- . opPushData
151
- $ B. replicate (n * 34 + 3 ) 0
152
- -- Redeem + m*sig + OP_0
153
- scp = rdm + m * 73 + 1
51
+ import Control.Applicative ((<|>) )
52
+ import Control.Arrow (first )
53
+ import Control.Monad (foldM , unless )
54
+ import Control.Monad.Identity (runIdentity )
55
+ import Crypto.Secp256k1
56
+ import qualified Data.ByteString as B
57
+ import Data.Bytes.Get
58
+ import Data.Bytes.Put
59
+ import Data.Bytes.Serial
60
+ import Data.Either (fromRight )
61
+ import Data.List (nub )
62
+ import Data.Maybe (catMaybes , fromJust , isJust )
63
+ import Data.String.Conversions (cs )
64
+ import Data.Text (Text )
65
+ import Data.Word (Word64 )
154
66
155
67
156
68
{- Build a new Tx -}
0 commit comments