taker.tx_builder
taker.tx_builder
Transaction builder for CoinJoin transactions.
Builds the unsigned CoinJoin transaction from: - Taker's UTXOs and change address - Maker UTXOs, CJ addresses, and change addresses - CoinJoin amount and fees
Attributes
logger = logging.getLogger(__name__)
module-attribute
varint = encode_varint
module-attribute
Classes
CoinJoinTxBuilder
Builds CoinJoin transactions.
The transaction structure: - Inputs: Taker inputs + Maker inputs (shuffled) - Outputs: Equal CJ outputs + Change outputs (shuffled)
Source code in taker/src/taker/tx_builder.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
Attributes
network = network
instance-attribute
Functions
__init__(network: str = 'mainnet')
Source code in taker/src/taker/tx_builder.py
61 62 | |
add_signatures(tx_bytes: bytes, signatures: dict[str, list[dict[str, Any]]], metadata: dict[str, Any]) -> bytes
Add signatures to transaction.
Every input must have a matching signature. A CoinJoin transaction with any unsigned input is invalid and must never be broadcast.
Args: tx_bytes: Unsigned transaction signatures: Dict of nick -> list of signature info metadata: Transaction metadata with input owners
Returns: Signed transaction bytes
Raises: ValueError: If any input is missing a signature
Source code in taker/src/taker/tx_builder.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
build_unsigned_tx(tx_data: CoinJoinTxData) -> tuple[bytes, dict[str, Any]]
Build an unsigned CoinJoin transaction.
Args: tx_data: Transaction data with all inputs and outputs
Returns: (tx_bytes, metadata) where metadata maps inputs/outputs to owners
Source code in taker/src/taker/tx_builder.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
get_txid(tx_bytes: bytes) -> str
Calculate txid (double SHA256 of non-witness data).
Source code in taker/src/taker/tx_builder.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
CoinJoinTxData
Data for building a CoinJoin transaction.
Source code in taker/src/taker/tx_builder.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
Attributes
cj_amount: int
instance-attribute
maker_change_outputs: dict[str, TxOutput]
instance-attribute
maker_cj_outputs: dict[str, TxOutput]
instance-attribute
maker_inputs: dict[str, list[TxInput]]
instance-attribute
taker_change_output: TxOutput | None
instance-attribute
taker_cj_output: TxOutput
instance-attribute
taker_inputs: list[TxInput]
instance-attribute
total_maker_fee: int
instance-attribute
tx_fee: int
instance-attribute
Functions
build_coinjoin_tx(taker_utxos: list[dict[str, Any]], taker_cj_address: str, taker_change_address: str, taker_total_input: int, maker_data: dict[str, dict[str, Any]], cj_amount: int, tx_fee: int, network: str = 'mainnet', dust_threshold: int = 27300) -> tuple[bytes, dict[str, Any]]
Build a complete CoinJoin transaction.
Args: taker_utxos: List of taker's UTXOs taker_cj_address: Taker's CJ output address taker_change_address: Taker's change address (empty string if no change needed) taker_total_input: Total value of taker's inputs maker_data: Dict of maker nick -> {utxos, cj_addr, change_addr, cjfee, txfee} cj_amount: Equal CoinJoin output amount tx_fee: Total transaction fee network: Network name dust_threshold: Minimum output value in satoshis (default: 27300)
Returns: (tx_bytes, metadata)
Source code in taker/src/taker/tx_builder.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
calculate_tx_fee(num_taker_inputs: int, num_maker_inputs: int, num_outputs: int, fee_rate: float) -> int
Calculate transaction fee based on estimated vsize.
SegWit P2WPKH inputs: ~68 vbytes each P2WPKH outputs: 31 vbytes each Overhead: ~11 vbytes
Args: fee_rate: Fee rate in sat/vB (can be fractional, e.g. 0.5)
Returns: Fee in satoshis (rounded up to ensure minimum relay fee)
Source code in taker/src/taker/tx_builder.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |