dnd 5e – Does the Hexblade warlock’s Hex Warrior feature let me add my Cha bonus to attack/damage rolls with a two-handed pact weapon?

Yes, you can use any pact weapon and still use your CHA modifier.

A note on phrasing:

You highlight “type” in the feature definition. Unfortunately, the rules don’t seem to explicitly define what “weapon type” means, so I’m going to use Medix2’s logic from their answer here with a small adjustment: the rules do happen to define weapon categories as “Simple” or “Martial” on p 146 of the PHB. (This super doesn’t really matter in the grand scheme of things but since we’re getting into the nitty-gritty about phrasing I figured I’d point it out.) But, of note, “Simple” and “Martial” can both apply to a pretty long list of weapons, both melee and ranged, single-handed and two-handed.

If we go with this logic, saying something applies “no matter the weapon’s type” would indeed mean any relevant weapon. So, if you’ve chosen Hexblade and you choose the Pact of the Blade at level 3, you do indeed get to use your CHA modifier for attacks with your pact weapon.

Private key (hex) from public key

It is practically impossible. The idea of a public/private key pair is that you can publish your public key without anyone being able to efficiently deduce your private key from it. That’s why you can only spend bitcoin from addresses that you have the private key for.

There are two ways that come to my mind how to obtain a private key given the public key, however both are (currently) unfeasible:

  1. Brute force: generate random private keys and test if they are by chance the one private keys for your public key. But this process will take unimaginably long.
  2. Shor’s algorithm: which is a quantum computer algorithm for integer factorization that allows you to calculate the private key given the public key, however we don’t have quantum computers with the required number of qubits yet.

dnd 5e – Does the Hex Warrior feature allow a Hexblade warlock to create a ranged pact weapon?

A Hexblade can choose a ranged weapon, but that doesn’t make it a pact weapon

The Hexblade patron allows a Warlock to select a weapon to grant it a variety of benefits, many of which are fairly similar to the benefits that the pact weapon of a Pact of the Blade Warlock receives.

However, there are a variety of differences. Most importantly, the Hexblade’s chosen weapon is not (automatically) called a pact weapon. It might be similar, but it is distinct—and anything that refers to “pact weapon” refers only to the weapon chosen with Pact of the Blade—which isn’t (necessarily) the Hexblade weapon.

Part of the confusion here is that many Warlocks often choose the same weapon for both Hexblade and Pact of the Blade. If you do that, then your Hexblade chosen weapon gets all the benefits of being a pact weapon—because it is one. But you could choose to keep them separate if you want, to have two weapons with similar benefits. And for that matter, a Hexblade doesn’t even have to choose Pact of the Blade in the first place.

But with that cleared up, the answer to this question becomes clear: a Hexblade can choose a ranged weapon for their Hexblade features, but that doesn’t make it a pact weapon. To make it a pact weapon, they have to choose it with Pact of the Blade—and they can’t unless they have the Improved Pact Weapon invocation.

transactions – Missing Witness field in p2wpkh decoded tx hex

I have placed together a raw tx hex but when it’s unable to be broadcasted as I keep getting an error below

sendrawtransaction RPC error: {"code":-25,"message":"bad-txns-inputs-missingorspent"}

I then decoded the tx hex using https://live.blockcypher.com/btc/decodetx/ to see that I seem to be missing the Witness field as I am using native segwit addresses:

{
    "addresses": (
        "bc1qj3rjxzhlqm6fqesd5fwphjnf457zkww3s5qrv5",
        "bc1qjp3cch0hdvdr0hy99cs76kl9kekmuxv3k9nr6l"
    ),
    "block_height": -1,
    "block_index": -1,
    "confirmations": 0,
    "double_spend": false,
    "fees": 200,
    "hash": "88420211f5ea53174fc6a708c00ca2e840d687591573d0ecd2464fae20d139a7",
    "inputs": (
        {
            "addresses": (
                "bc1qj3rjxzhlqm6fqesd5fwphjnf457zkww3s5qrv5"
            ),
            "age": 696993,
            "output_index": 0,
            "output_value": 60200,
            "prev_hash": "74e24a2d50ba64abc099126c1c208b5f7156e3ad515b86f3edcca3f3d4291f66",
            "script": "4730440220516e15b6354f17e3f02711107624005e6ccd26cf61ef21b35e91315dfbd33e9f022049dadb73ca3e814de9da0b35ff20a8ca82147dda138ede948ccac5621a5bc1bb01210384485d43e938f8c68c4ac903d4d5a97fe842f66c12b860d8d2e1242d2b01fc1f",
            "script_type": "pay-to-witness-pubkey-hash",
            "sequence": 4294967295
        }
    ),
    "outputs": (
        {
            "addresses": (
                "bc1qjp3cch0hdvdr0hy99cs76kl9kekmuxv3k9nr6l"
            ),
            "script": "001490638c5df76b1a37dc852e21ed5be5b66dbe1991",
            "script_type": "pay-to-witness-pubkey-hash",
            "value": 60000
        }
    ),
    "preference": "low",
    "received": "2021-09-05T10:17:14.395062568Z",
    "relayed_by": "3.82.154.159",
    "size": 188,
    "total": 60000,
    "ver": 2,
    "vin_sz": 1,
    "vout_sz": 1,
    "vsize": 188
}

I then thought perhaps I didn’t add a scriptPubKey into the addInput but this code didn’t seem to work for me:

let keypairSpend = bitcoin.ECPair.fromWIF(WIF, MAINNET)

var scriptPubkey = bitcoin.script.witnessPubKeyHash.output.encode(bitcoin.crypto.hash160(keypairSpend.getPublicKeyBuffer()))

txb.addInput(txid, outn, null, scriptPubkey)

Any suggestions as to how I can add the Witness field into the tx? Is it because I am improperly adding the scriptPubKey?

transactions – Error 400 when pushing tx hex to mempool.space’s API

  1. Create a transaction and get hex:
0200000000010119335721e24061cab07c9caf3a9ed331b85511af3d6be38ef37bda93ddce49880100000000fdffffff02a086010000000000160014243588dda3d0560986069a55b386c1d3417ecc2e19a903000000000016001469577cafbaa617f64cd468ff51a578aeb85cfcf202473044022066c1314f71f05cf1c2e27298dc056d7b66cbc2bab0b3d536ad084fa577d9a0650220349102e2d151309b7820ff848d39ba28c6763f972e90359300dbfd3131ff4fa1012102cc2868604a6db586db0d72654f71835a3d6c20e465eea4597509963f47bd3c65dbe91f00
  1. Use Postman to send a POST request with:

    URL: https://mempool.space/testnet/api/tx

    Body: Transaction hex

  2. It will return transaction id:

23b0c4ce54e13a846e6a9f50f11019071f98c53f1d82ea9c674de1c7a94af45a

postman

Doing same thing using JavaScript:

  1. Click on </>

postman-code

  1. Select one of the options for JavaScript. I used JavaScript-Fetch:
var myHeaders = new Headers();
myHeaders.append("Content-Type", "text/plain");

var raw = "020000000001015af44aa9c7e14d679cea821d3fc5981f071910f1509f6a6e843ae154cec4b0230100000000fdffffff02a0860100000000001600141c97aee9cf15d8a9016c3a98c5a503ed49d012caec2102000000000016001463924d833ecc676de6dec0cf6c72c6c94bc1c5350247304402206fbb992ce8f8e35b5c229dae731709c7d82de404d882e62271ce6e7551e103ff02203e94d589766db4e583d862b6ad3951fe62c498b11fdeae85bfc37ef61e2af13a0121039072d28be7d83a8f4b1983da7a74d2bd28e80ee79d4ee2bf603e101865099378dce91f00";

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://mempool.space/testnet/api/tx", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

  1. Run this on https://jsfiddle.net/ and you will get the transaction id in response:

fiddle

bd0306a1fa6e262949c9856ebcea61c0857067e1d2c856d0216a9cf871e4a377

python – Struggling to Decode Raw Hex Data of a Block

I am trying to Decode the Raw hex data of a Coinbase Block to check my understanding of the DS but I am facing some difficulties in decoding marked by a ? below:

Q1. Can someone please check the existing understanding/interpratation and help explain and fill the gaps (marked by ?)

Q2. Is there a simple standalone program/library in to do the same? I have seen few parsers (though haven’t used) but they require the complete blockchain .dat files that i cannot afford to download for this task.

The block is: https://www.blockchain.com/btc/block/485300


0000002053f7ebc735f54ac8d4ebcc1eeb3d3bdea89603bdd27431000000000000000000ff964ec70ea5a5356a04fdb044ca6c59ffda2dd6be02c63d9ea58fb6d46e01991a22bb590b310118f6df26f801010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff3103b46707244d696e656420627920416e74506f6f6c6b2f4542312f4144362f4e59412f332059bb221ab8080000615c0300ffffffff02807c814a000000001976a914660371326d3a2e064c278b20107a65dad847e8a988ac0000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf90120000000000000000000000000000000000000000000000000000000000000000000000000

(PARAMETER)           (VALUE)

(Block Header)
version             - 00000020
Previous Block hash - 53f7ebc735f54ac8d4ebcc1eeb3d3bdea89603bdd27431000000000000000000
Merkel Root         - ff964ec70ea5a5356a04fdb044ca6c59ffda2dd6be02c63d9ea58fb6d46e0199
time                - 1a22bb59
bits                - 1801310B
nonce               - f6df26f8

01 - transaction count

(Tx List)
<?>                     - 010000000001
input ct                - 01
prev tx                 - 0000000000000000000000000000000000000000000000000000000000000000
prev out n              - ffffffff
coinbase script length  - 31
coinbase script         - 03b46707244d696e656420627920416e74506f6f6c6b2f4542312f4144362f4e59412f332059bb221ab8080000615c0300
sequence                - ffffffff
Output count            - 02
value 1                 - 807c814a00000000
Script 1 length         - 19
Script 1                - 76a914660371326d3a2e064c278b20107a65dad847e8a988ac
value 2                 - 0000000000000000
Script 2 length         - 26
Script 2                - 6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9
<?>                     - 0120000000000000000000000000000000000000000000000000000000000000000000000000

mining theory – Help regrading validating a raw Hex Block on desktop?

Is there a desktop C++/Python library to take a raw hex bitcoin block as input and then break it down to various parameters and print it.

Moreover it should be able to validate the structure of a bitcoin block based on all the latest protocols and rules. I don’t have the bitcoin core and can’t afford to download 400GB but what i want to achieve is the following:

  1. Get the latest block number, its hash and bits from online. – this part is not difficult.
  2. Manually lower the bits/difficulty so that mining is much easier (for testing sake).
  3. Create a coinbase transaction in hex (by hand) using some existing wallet address.
  4. Using the coinbase transaction above create a block header and get the valid hash for lowered bits.
  5. Completely create a new Coinbase Block in hex.
  6. Validate using the library if the Coinbase Block created is structurally sound according to all the rules and protocols. In other words, if the difficulty was the lower one as we assumed, the block would have been valid and mined on the ‘mainnet’.

python – Convert the last column of a data frame from hex to decimal

I have a data frame that I want to filter. I would like to convert the values in the last column from hex to decimal. Is there a way to do it without specifying the name of the column because name may change over time for this document. See examples below.

Input:

begin{table}[]
begin{tabular}{lllll}
Name & Class & Color & Count &
Ron & G3 & Pink & 0002 &
Jos & G2 & Green & 000A &
Pam & G5 & Blue & 000F &
end{tabular}
end{table}

Output:

begin{table}[]
begin{tabular}{lllll}
Name & Class & Color & Count &
Ron & G3 & Pink & 2 &
Jos & G2 & Green & 10 &
Pam & G5 & Blue & 15 &
end{tabular}
end{table}

signature – How can I sign transaction hex with Python library

I have a unsigned transaction hex. Now I want to sign this transaction input with my private key in Python. Are there any Python libraries?

Transaction Hex

010000000414ae2264cdbe754b9ae4be18d84bfeb4f578af553b9b9e4f9cb2303d04ee9e45000000001976a91458b6e991b45487df810f4d96d5315da739637f1788acffffffffec15d27b74516fefd921cecbe043ea63124d28a3903aef8fb1682ccc926b1c62000000001976a91458b6e991b45487df810f4d96d5315da739637f1788acffffffff9878f76e1424c1d1eeb6b15d06902dd8f0c78f9bdb61263e4ca3ae68c571a292000000001976a91458b6e991b45487df810f4d96d5315da739637f1788acfffffffffdac7f1c83b01a8924a8965d356b804c2608bc261fc18041116ddb4a143bc499000000001976a91458b6e991b45487df810f4d96d5315da739637f1788acffffffff0336150000000000001976a9141485d9d03b41aaa9dca7d70d7f63ff4a0826100e88ac00000000000000001e6a1c246698efc5d81b78ceadf3179316b5eb6cc5c2c347c0b7b42121a94e92180000000000001976a91458b6e991b45487df810f4d96d5315da739637f1788ac00000000

Decoded Transaction

{
   "txid":"6c521937d8fa889d71609ebed2e23b694cbca89778c8b8d967167e5a4c9d5b78",
   "size":381,
   "version":1,
   "locktime":0,
   "vin":(
      {
         "txid":"459eee043d30b29c4f9e9b3b55af78f5b4fe4bd818bee49a4b75becd6422ae14",
         "vout":0,
         "scriptSig":{
            "asm":"OP_DUP OP_HASH160 58b6e991b45487df810f4d96d5315da739637f17 OP_EQUALVERIFY OP_CHECKSIG",
            "hex":"76a91458b6e991b45487df810f4d96d5315da739637f1788ac"
         },
         "sequence":4294967295
      },
      {
         "txid":"621c6b92cc2c68b18fef3a90a3284d1263ea43e0cbce21d9ef6f51747bd215ec",
         "vout":0,
         "scriptSig":{
            "asm":"OP_DUP OP_HASH160 58b6e991b45487df810f4d96d5315da739637f17 OP_EQUALVERIFY OP_CHECKSIG",
            "hex":"76a91458b6e991b45487df810f4d96d5315da739637f1788ac"
         },
         "sequence":4294967295
      },
      {
         "txid":"92a271c568aea34c3e2661db9b8fc7f0d82d90065db1b6eed1c124146ef77898",
         "vout":0,
         "scriptSig":{
            "asm":"OP_DUP OP_HASH160 58b6e991b45487df810f4d96d5315da739637f17 OP_EQUALVERIFY OP_CHECKSIG",
            "hex":"76a91458b6e991b45487df810f4d96d5315da739637f1788ac"
         },
         "sequence":4294967295
      },
      {
         "txid":"99c43b144adb6d114180c11f26bc08264c806b355d96a824891ab0831c7facfd",
         "vout":0,
         "scriptSig":{
            "asm":"OP_DUP OP_HASH160 58b6e991b45487df810f4d96d5315da739637f17 OP_EQUALVERIFY OP_CHECKSIG",
            "hex":"76a91458b6e991b45487df810f4d96d5315da739637f1788ac"
         },
         "sequence":4294967295
      }
   ),
   "vout":(
      {
         "value":5.43e-5,
         "n":0,
         "scriptPubKey":{
            "asm":"OP_DUP OP_HASH160 1485d9d03b41aaa9dca7d70d7f63ff4a0826100e OP_EQUALVERIFY OP_CHECKSIG",
            "hex":"76a9141485d9d03b41aaa9dca7d70d7f63ff4a0826100e88ac",
            "reqSigs":1,
            "type":"pubkeyhash",
            "addresses":(
               "12sWrxRY7E7Nhmuyjbz4TtGE9jRewGqEZD"
            )
         }
      },
      {
         "value":0,
         "n":1,
         "scriptPubKey":{
            "asm":"OP_RETURN 246698efc5d81b78ceadf3179316b5eb6cc5c2c347c0b7b42121a94e",
            "hex":"6a1c246698efc5d81b78ceadf3179316b5eb6cc5c2c347c0b7b42121a94e",
            "type":"nulldata"
         }
      },
      {
         "value":6.29e-5,
         "n":2,
         "scriptPubKey":{
            "asm":"OP_DUP OP_HASH160 58b6e991b45487df810f4d96d5315da739637f17 OP_EQUALVERIFY OP_CHECKSIG",
            "hex":"76a91458b6e991b45487df810f4d96d5315da739637f1788ac",
            "reqSigs":1,
            "type":"pubkeyhash",
            "addresses":(
               "1965areciqapsuL2hsia2yKkRLfAsH1smG"
            )
         }
      }
   )
}

Update 1

Solved thanks to hartmut.

1 Install pybitcointools

git clone https://github.com/vbuterin/pybitcointools.git
cd pybitcointools
sudo python setup.py # I got an error in Python3. So I used Python2.

2 Sign by using pybitcointools

import bitcoin

def signAllIns(aTx, priv, nbIns=None):
    signedTx = aTx
    utxo = nbIns
    if utxo == None:
        utxo = len(bitcoin.unspent(bitcoin.privtoaddr(priv)))
    for i in range(utxo):
        signedTx = bitcoin.sign(signedTx, i, priv)
    return signedTx

deserializeHex = bitcoin.deserialize(HEX)
ins = deserializeHex('ins')
signedTx = signAllIns(HEX, PRIVATE_KEY, len(ins))

# Broadcast signedTx here