jmcore.bitcoin
jmcore.bitcoin
Bitcoin utilities for JoinMarket.
This module provides consolidated Bitcoin operations: - Address encoding/decoding (bech32, base58) - Hash functions (hash160, hash256) - Transaction parsing/serialization - Varint encoding/decoding
Uses external libraries for security-critical operations: - bech32: BIP173 bech32 encoding - base58: Base58Check encoding
Attributes
HRP_MAP = {NetworkType.MAINNET: 'bc', NetworkType.TESTNET: 'tb', NetworkType.SIGNET: 'tb', NetworkType.REGTEST: 'bcrt'}
module-attribute
P2PKH_VERSION = {NetworkType.MAINNET: 0, NetworkType.TESTNET: 111, NetworkType.SIGNET: 111, NetworkType.REGTEST: 111}
module-attribute
P2SH_VERSION = {NetworkType.MAINNET: 5, NetworkType.TESTNET: 196, NetworkType.SIGNET: 196, NetworkType.REGTEST: 196}
module-attribute
PSBT_GLOBAL_UNSIGNED_TX = 0
module-attribute
PSBT_IN_BIP32_DERIVATION = 6
module-attribute
PSBT_IN_SIGHASH_TYPE = 3
module-attribute
PSBT_IN_WITNESS_SCRIPT = 5
module-attribute
PSBT_IN_WITNESS_UTXO = 1
module-attribute
PSBT_MAGIC = b'psbt\xff'
module-attribute
PSBT_SEPARATOR = b'\x00'
module-attribute
Classes
BIP32Derivation
BIP32 key origin information for a PSBT input/output.
Used to tell signing devices which key to use (PSBT_IN_BIP32_DERIVATION).
Attributes: pubkey: The compressed public key (33 bytes). fingerprint: Master key fingerprint (4 bytes). path: BIP32 derivation path as list of uint32 indices (e.g. [0x80000054, 0x80000000, 0x80000000, 0, 0] for m/84'/0'/0'/0/0).
Source code in jmcore/src/jmcore/bitcoin.py
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 | |
Attributes
fingerprint: bytes
instance-attribute
path: list[int]
instance-attribute
pubkey: bytes
instance-attribute
Functions
__post_init__() -> None
Source code in jmcore/src/jmcore/bitcoin.py
1250 1251 1252 1253 1254 | |
NetworkType
Bases: StrEnum
Bitcoin network types.
Source code in jmcore/src/jmcore/bitcoin.py
30 31 32 33 34 35 36 | |
Attributes
MAINNET = 'mainnet'
class-attribute
instance-attribute
REGTEST = 'regtest'
class-attribute
instance-attribute
SIGNET = 'signet'
class-attribute
instance-attribute
TESTNET = 'testnet'
class-attribute
instance-attribute
PSBTInput
Data needed for a PSBT per-input map.
Attributes: witness_utxo_value: Value of the UTXO in satoshis. witness_utxo_script: scriptPubKey of the UTXO (e.g. P2WSH 34-byte script). witness_script: The full witness script (redeem script) for P2WSH inputs. sighash_type: Sighash type (default SIGHASH_ALL = 0x01). bip32_derivations: Optional BIP32 key origin info for signing devices.
Source code in jmcore/src/jmcore/bitcoin.py
1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 | |
Attributes
bip32_derivations: list[BIP32Derivation] | None = None
class-attribute
instance-attribute
sighash_type: int = 1
class-attribute
instance-attribute
witness_script: bytes
instance-attribute
witness_utxo_script: bytes
instance-attribute
witness_utxo_value: int
instance-attribute
ParsedTransaction
Parsed Bitcoin transaction with typed inputs and outputs.
Provides dual accessors for int and bytes representations of version and locktime (needed by BIP-143 sighash construction).
Source code in jmcore/src/jmcore/bitcoin.py
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | |
Attributes
has_witness: bool
instance-attribute
inputs: list[TxInput]
instance-attribute
locktime: int
instance-attribute
locktime_bytes: bytes
property
Locktime as 4-byte little-endian bytes.
outputs: list[TxOutput]
instance-attribute
version: int
instance-attribute
version_bytes: bytes
property
Version as 4-byte little-endian bytes.
witnesses: list[list[bytes]]
instance-attribute
TxInput
Unified transaction input model.
Stores data in canonical byte form internally. Provides dual accessors for the two dominant usage patterns in the codebase:
- String pattern (RPC / human-readable):
txid(big-endian hex),scriptsig_hex,scriptpubkey_hex,sequence(int). - Bytes pattern (BIP-143 signing):
txid_le(little-endian bytes),scriptsig(bytes),sequence_bytes(4-byte LE bytes).
Construction helpers
TxInput.from_hex(txid_hex, vout, ...)— build from big-endian hex txid (the format returned by Bitcoin Core RPC).- Direct
TxInput(txid_le=..., vout=..., ...)— build from raw LE bytes (the format found inside serialised transactions).
Source code in jmcore/src/jmcore/bitcoin.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
Attributes
scriptpubkey: bytes = b''
class-attribute
instance-attribute
scriptpubkey_hex: str
property
ScriptPubKey of the prevout as hex string.
scriptsig: bytes = b''
class-attribute
instance-attribute
scriptsig_hex: str
property
ScriptSig as hex string.
sequence: int = 4294967295
class-attribute
instance-attribute
sequence_bytes: bytes
property
Sequence as 4-byte little-endian bytes (for BIP-143 preimage).
txid: str
property
Transaction ID as big-endian hex (RPC / display format).
txid_le: bytes
instance-attribute
value: int = 0
class-attribute
instance-attribute
vout: int
instance-attribute
Functions
__getitem__(key: str) -> Any
Allow inp["txid"] style access for backward compatibility.
Source code in jmcore/src/jmcore/bitcoin.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
from_hex(txid: str, vout: int, *, scriptsig: str = '', sequence: int = 4294967295, value: int = 0, scriptpubkey: str = '') -> TxInput
classmethod
Create from big-endian hex txid (the RPC / display format).
Args: txid: 64-char hex string (big-endian, as returned by RPC) vout: Output index scriptsig: ScriptSig hex (default empty) sequence: Sequence number (default 0xFFFFFFFF) value: UTXO value in satoshis (optional, for tx builder) scriptpubkey: Prevout scriptPubKey hex (optional)
Source code in jmcore/src/jmcore/bitcoin.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
get(key: str, default: Any = None) -> Any
Allow inp.get("key", default) for backward compatibility.
Source code in jmcore/src/jmcore/bitcoin.py
615 616 617 618 619 620 | |
TxOutput
Unified transaction output model.
Stores value and script (scriptPubKey) in canonical byte form.
Provides convenience accessors for hex and address representations.
Source code in jmcore/src/jmcore/bitcoin.py
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | |
Attributes
script: bytes
instance-attribute
scriptpubkey: str
property
ScriptPubKey as hex string (backward compat alias).
value: int
instance-attribute
Functions
__getitem__(key: str) -> Any
Allow out["value"] style access for backward compatibility.
Source code in jmcore/src/jmcore/bitcoin.py
689 690 691 692 693 694 695 | |
address(network: str | NetworkType = 'mainnet') -> str
Derive address from scriptPubKey.
Args: network: Network type for bech32/base58 encoding.
Returns: Address string.
Raises: ValueError: If scriptPubKey is an unsupported type.
Source code in jmcore/src/jmcore/bitcoin.py
673 674 675 676 677 678 679 680 681 682 683 684 685 | |
from_address(address: str, value: int) -> TxOutput
classmethod
Create from address string (resolves to scriptPubKey).
Args: address: Bitcoin address (any supported format) value: Output value in satoshis
Source code in jmcore/src/jmcore/bitcoin.py
706 707 708 709 710 711 712 713 714 715 716 717 718 | |
from_hex(scriptpubkey: str, value: int) -> TxOutput
classmethod
Create from hex scriptPubKey.
Args: scriptpubkey: ScriptPubKey as hex string value: Output value in satoshis
Source code in jmcore/src/jmcore/bitcoin.py
720 721 722 723 724 725 726 727 728 | |
get(key: str, default: Any = None) -> Any
Allow out.get("key", default) for backward compatibility.
Source code in jmcore/src/jmcore/bitcoin.py
697 698 699 700 701 702 | |
Functions
address_to_scriptpubkey(address: str) -> bytes
Convert Bitcoin address to scriptPubKey.
Supports: - P2WPKH (bc1q..., tb1q..., bcrt1q...) - P2WSH (bc1q... 62 chars) - P2TR (bc1p... taproot) - P2PKH (1..., m..., n...) - P2SH (3..., 2...)
Args: address: Bitcoin address string
Returns: scriptPubKey bytes
Source code in jmcore/src/jmcore/bitcoin.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
btc_to_sats(btc: float) -> int
Convert BTC to satoshis safely.
Uses round() instead of int() to avoid floating point precision errors that can truncate values (e.g. 0.0003 * 1e8 = 29999.999...).
Args: btc: Amount in BTC
Returns: Amount in satoshis
Source code in jmcore/src/jmcore/bitcoin.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
calculate_relative_fee(amount_sats: int, fee_rate: str) -> int
Calculate relative fee in satoshis from a fee rate string.
Uses Decimal arithmetic with banker's rounding (ROUND_HALF_EVEN) to match the reference JoinMarket implementation. This is critical for sweep mode where the maker expects the exact same fee calculation.
Args: amount_sats: Amount in satoshis fee_rate: Fee rate as decimal string (e.g., "0.001" = 0.1%)
Returns: Fee in satoshis (rounded to nearest integer)
Examples: >>> calculate_relative_fee(100_000_000, "0.001") 100000 # 0.1% of 1 BTC >>> calculate_relative_fee(50_000_000, "0.002") 100000 # 0.2% of 0.5 BTC >>> calculate_relative_fee(9994243, "0.000022") 220 # matches reference implementation's Decimal rounding
Source code in jmcore/src/jmcore/bitcoin.py
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 | |
calculate_sweep_amount(available_sats: int, relative_fees: list[str]) -> int
Calculate CoinJoin amount for a sweep (no change output).
The taker must pay maker fees from the swept amount: available = cj_amount + fees fees = sum(fee_rate * cj_amount for each maker)
Solving for cj_amount: available = cj_amount * (1 + sum(fee_rates)) cj_amount = available / (1 + sum(fee_rates))
Args: available_sats: Total available balance in satoshis relative_fees: List of relative fee strings (e.g., ["0.001", "0.002"])
Returns: CoinJoin amount in satoshis (maximum amount after paying all fees)
Source code in jmcore/src/jmcore/bitcoin.py
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 224 225 | |
calculate_tx_vsize(tx_bytes: bytes) -> int
Calculate actual virtual size (vbytes) from a signed transaction.
For SegWit transactions: vsize = ceil((3 * non_witness_size + total_size) / 4) For legacy transactions: vsize = total_size
Args: tx_bytes: Serialized transaction bytes
Returns: Virtual size in vbytes
Source code in jmcore/src/jmcore/bitcoin.py
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 | |
create_p2wpkh_script_code(pubkey: bytes | str) -> bytes
Create scriptCode for P2WPKH signing (BIP143).
For P2WPKH, the scriptCode is the P2PKH script: OP_DUP OP_HASH160 <20-byte-pubkeyhash> OP_EQUALVERIFY OP_CHECKSIG
Args: pubkey: Public key bytes or hex
Returns: 25-byte scriptCode
Source code in jmcore/src/jmcore/bitcoin.py
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | |
create_psbt(version: int, inputs: list[TxInput], outputs: list[TxOutput], locktime: int, psbt_inputs: list[PSBTInput]) -> bytes
Create a PSBT (BIP-174) from unsigned transaction components.
Builds a complete PSBT with: - Global map: the unsigned transaction (no witness data, empty scriptSigs) - Per-input maps: WITNESS_UTXO, WITNESS_SCRIPT, SIGHASH_TYPE - Per-output maps: empty (no metadata needed for spending)
The resulting PSBT can be imported into hardware wallet software (e.g. Sparrow, Coldcard) for signing.
Args: version: Transaction version (typically 2). inputs: Transaction inputs (empty scriptSigs, appropriate sequences). outputs: Transaction outputs. locktime: Transaction nLockTime. psbt_inputs: Per-input metadata for the PSBT.
Returns: Serialized PSBT bytes.
Raises: ValueError: If inputs and psbt_inputs lengths don't match.
Source code in jmcore/src/jmcore/bitcoin.py
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 | |
decode_varint(data: bytes, offset: int = 0) -> tuple[int, int]
Decode Bitcoin varint from bytes.
Args: data: Input bytes offset: Starting offset in data
Returns: (value, new_offset) tuple
Source code in jmcore/src/jmcore/bitcoin.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
encode_varint(n: int) -> bytes
Encode integer as Bitcoin varint.
Args: n: Integer to encode
Returns: Encoded bytes
Source code in jmcore/src/jmcore/bitcoin.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
estimate_vsize(input_types: list[str], output_types: list[str]) -> int
Estimate transaction virtual size (vbytes).
Based on JoinMarket reference implementation logic.
Args: input_types: List of input types (e.g. ["p2wpkh", "p2wsh"]) output_types: List of output types (e.g. ["p2wpkh", "p2wsh"])
Returns: Estimated vsize in bytes
Source code in jmcore/src/jmcore/bitcoin.py
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 | |
format_amount(sats: int, include_unit: bool = True) -> str
Format satoshi amount as string. Default: '1,000,000 sats (0.01000000 BTC)'
Args: sats: Amount in satoshis include_unit: Whether to include units and BTC conversion
Returns: Formatted string
Source code in jmcore/src/jmcore/bitcoin.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
get_address_type(address: str) -> str
Determine address type from string.
Args: address: Bitcoin address
Returns: Address type: "p2wpkh", "p2wsh", "p2tr", "p2pkh", "p2sh"
Raises: ValueError: If address is invalid or unknown type
Source code in jmcore/src/jmcore/bitcoin.py
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 | |
get_hrp(network: str | NetworkType) -> str
Get bech32 human-readable part for network.
Args: network: Network type (string or enum)
Returns: HRP string (bc, tb, bcrt)
Source code in jmcore/src/jmcore/bitcoin.py
324 325 326 327 328 329 330 331 332 333 334 335 336 | |
get_txid(tx_hex: str) -> str
Calculate transaction ID (double SHA256 of non-witness data).
Args: tx_hex: Transaction hex
Returns: Transaction ID as hex string
Source code in jmcore/src/jmcore/bitcoin.py
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 | |
hash160(data: bytes) -> bytes
RIPEMD160(SHA256(data)) - Used for Bitcoin addresses.
Args: data: Input data to hash
Returns: 20-byte hash
Source code in jmcore/src/jmcore/bitcoin.py
233 234 235 236 237 238 239 240 241 242 243 | |
hash256(data: bytes) -> bytes
SHA256(SHA256(data)) - Used for Bitcoin txids and block hashes.
Args: data: Input data to hash
Returns: 32-byte hash
Source code in jmcore/src/jmcore/bitcoin.py
246 247 248 249 250 251 252 253 254 255 256 | |
parse_derivation_path(path_str: str) -> list[int]
Parse a BIP32 derivation path string into a list of uint32 indices.
Handles hardened notation with ' or h suffix.
Examples: >>> parse_derivation_path("m/84'/0'/0'/0/0") [2147483732, 2147483648, 2147483648, 0, 0]
Args: path_str: Derivation path like "m/84'/0'/0'/0/0".
Returns: List of uint32 path indices (hardened indices have bit 31 set).
Raises: ValueError: If the path format is invalid.
Source code in jmcore/src/jmcore/bitcoin.py
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 | |
parse_transaction(tx_hex: str) -> ParsedTransaction
Parse a Bitcoin transaction from hex.
Handles both SegWit and non-SegWit formats.
Args: tx_hex: Transaction hex string
Returns: ParsedTransaction object with typed TxInput/TxOutput lists
Source code in jmcore/src/jmcore/bitcoin.py
817 818 819 820 821 822 823 824 825 826 827 828 829 830 | |
parse_transaction_bytes(tx_bytes: bytes) -> ParsedTransaction
Parse a Bitcoin transaction from raw bytes.
Handles both SegWit and non-SegWit formats.
Args: tx_bytes: Raw transaction bytes
Returns: ParsedTransaction object with typed TxInput/TxOutput lists
Source code in jmcore/src/jmcore/bitcoin.py
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 | |
psbt_to_base64(psbt_bytes: bytes) -> str
Encode PSBT bytes as base64 string (standard PSBT exchange format).
Args: psbt_bytes: Raw PSBT bytes.
Returns: Base64-encoded PSBT string.
Source code in jmcore/src/jmcore/bitcoin.py
1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 | |
pubkey_to_p2wpkh_address(pubkey: bytes | str, network: str | NetworkType = 'mainnet') -> str
Convert compressed public key to P2WPKH (native SegWit) address.
Args: pubkey: 33-byte compressed public key (bytes or hex string) network: Network type
Returns: Bech32 P2WPKH address
Source code in jmcore/src/jmcore/bitcoin.py
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 | |
pubkey_to_p2wpkh_script(pubkey: bytes | str) -> bytes
Create P2WPKH scriptPubKey from public key.
Args: pubkey: 33-byte compressed public key (bytes or hex string)
Returns: 22-byte P2WPKH scriptPubKey (OP_0 <20-byte-hash>)
Source code in jmcore/src/jmcore/bitcoin.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
sats_to_btc(sats: int) -> float
Convert satoshis to BTC. Only use for display/output.
Args: sats: Amount in satoshis
Returns: Amount in BTC
Source code in jmcore/src/jmcore/bitcoin.py
84 85 86 87 88 89 90 91 92 93 94 | |
script_to_p2wsh_address(script: bytes, network: str | NetworkType = 'mainnet') -> str
Convert witness script to P2WSH address.
Args: script: Witness script bytes network: Network type
Returns: Bech32 P2WSH address
Source code in jmcore/src/jmcore/bitcoin.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
script_to_p2wsh_scriptpubkey(script: bytes) -> bytes
Create P2WSH scriptPubKey from witness script.
Args: script: Witness script bytes
Returns: 34-byte P2WSH scriptPubKey (OP_0 <32-byte-hash>)
Source code in jmcore/src/jmcore/bitcoin.py
404 405 406 407 408 409 410 411 412 413 414 415 | |
scriptpubkey_to_address(scriptpubkey: bytes, network: str | NetworkType = 'mainnet') -> str
Convert scriptPubKey to address.
Supports P2WPKH, P2WSH, P2TR, P2PKH, P2SH.
Args: scriptpubkey: scriptPubKey bytes network: Network type
Returns: Bitcoin address string
Source code in jmcore/src/jmcore/bitcoin.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | |
serialize_input(inp: TxInput, include_scriptsig: bool = True) -> bytes
Serialize a transaction input.
Args: inp: TxInput instance include_scriptsig: Whether to include scriptSig
Returns: Serialized input bytes
Source code in jmcore/src/jmcore/bitcoin.py
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 | |
serialize_outpoint(txid: str, vout: int) -> bytes
Serialize outpoint (txid:vout).
Args: txid: Transaction ID in RPC format (big-endian hex) vout: Output index
Returns: 36-byte outpoint (little-endian txid + 4-byte vout)
Source code in jmcore/src/jmcore/bitcoin.py
764 765 766 767 768 769 770 771 772 773 774 775 776 | |
serialize_output(out: TxOutput) -> bytes
Serialize a transaction output.
Args: out: TxOutput instance
Returns: Serialized output bytes
Source code in jmcore/src/jmcore/bitcoin.py
801 802 803 804 805 806 807 808 809 810 811 812 813 814 | |
serialize_transaction(version: int, inputs: list[TxInput], outputs: list[TxOutput], locktime: int, witnesses: list[list[bytes]] | None = None) -> bytes
Serialize a Bitcoin transaction.
Args: version: Transaction version inputs: List of TxInput objects outputs: List of TxOutput objects locktime: Transaction locktime witnesses: Optional list of witness stacks
Returns: Serialized transaction bytes
Source code in jmcore/src/jmcore/bitcoin.py
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 | |
sha256(data: bytes) -> bytes
Single SHA256 hash.
Args: data: Input data to hash
Returns: 32-byte hash
Source code in jmcore/src/jmcore/bitcoin.py
259 260 261 262 263 264 265 266 267 268 269 | |
validate_satoshi_amount(sats: int) -> None
Validate that amount is a non-negative integer.
Args: sats: Amount to validate
Raises: TypeError: If amount is not an integer ValueError: If amount is negative
Source code in jmcore/src/jmcore/bitcoin.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |