Debugging bitcoind

How do you attach a gdb to a bitcoind daemon. I wish to step through the functions. Here is what i have tried.

gdb --args bitcoind -regtest -daemon

This however exists when the daemon starts. So i tried attaching via the pid after the fork.

gdb -p 841
(gdb) file /usr/local/bin/bitcoind
Reading symbols from /usr/local/bin/bitcoind...done.
(gdb) b sendtoaddress
Breakpoint 1 at 0x4b4d34: file wallet/rpcwallet.cpp, line 379.    
r
starting program...    

This however does not work , when i invoke a transaction using the bitcoin-cli client. Is there anything i am missing. I have used –enable debug on configure.

Thanks.

How do i loop through all the related address in a given wallet address

I am using bitcoin block chain API, it is possible to get amount sent in a transaction id and the addresses it was sent to. My problem is getting the RELATED ADDRESSES to the address that sent the payment.. The only fact is that I want to be able to validate who sent the money and who it was sent to.. eg. my site involve users sending bitcoin to other users and submitting transaction ID. Each user register and input their wallet address. if User A sends to USer B and submits transaction ID, I want to be able to find out if the transaction is coming from the Sender User and is going to the Receiver Address. Validating for the receiver address is simple with my lines of code:

$requesturl='https://blockchain.info/tx-index/'.$comment.'? format=json';
$ch=curl_init($requesturl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$cexecute=curl_exec($ch);
curl_close($ch);
$result = json_decode($cexecute,true);
for($i=0; $i<count($result['out']); $i++) {
$result['out'][$i]["addr"];
}

I can get the receiver addresses from the loop above and validate, and if want to get the sending addresses it is also possible with:

for($i=0; $i<count($result['inputs']); $i++) {
// the addr is in the input
}   

Now my problem is if the wallet Address the User A submitted on our website is not in the sending address list, how do I know his address is there in the list.?

What is “version” used for in Bitcoin transactions? Does it have any meaning?

Some bitcoin transaction have version 2. For example, this transaction

https://blockchain.info/tx/b7022124bc7f31af9342d2f7af98ad9f60f2fd4fa544bf1affca8a436aadda41

if you request a hex (by adding ?format=hex for example) and putting it into https://blockchain.info/decode-tx , you get "version":2.

What does this mean? There are more transactions with version 2 out in the wild, but not that many.

In zcash transactions, version 2 means that the transaction has joinsplits. But I cannot find what it means in bitcoin.

I have found examples of version 2 transactions here and here

How does Bitcoin read from/write to LevelDB

I know that Bitcoin Core uses LevelDB since 0.8 version. However, I couldn’t find detailed explanation about how Bitcoin stores and retrieves from LevelDB. E.g. If B transaction uses an output from previous transaction A as input, how does Bitcoin lookup this transaction and see if it’s spent? After transaction B is spent, how does this transaction get updated?

What are the hex and asm field values in the JSON decoded from a raw transactions?

I used the command line bitcoin-cli decoderawtransaction <hex-value> and got back a JSON output (see below). However, I noticed there are hex and asm fields that are themselves hex values (at times). I am thinking these are metadata that can further be decoded. Is that right?

Is there any more documentation on the structure and meaning of the JSON passed back for these 2 fields (or more)?

I read this SO post which referred to this out-dated article.

Also, I checked the transaction on bitcoin block explorer. They seem to have a few metadata that I don’t see in the JSON (e.g. received time, confirmations, relayed ip, etc…). Where are these values coming from?

{
  "txid": "2514161c059ac18bf2eff1e05c4628e322d846e930fd6dd4b24805ea59dc4913",
  "hash": "2514161c059ac18bf2eff1e05c4628e322d846e930fd6dd4b24805ea59dc4913",
  "size": 259,
  "vsize": 259,
  "version": 1,
  "locktime": 0,
  "vin": [
    {
      "txid": "4f40655c4ab1a029bc41bc547f79556a0dc48d22df7202778fad592791c77fcd",
      "vout": 0,
      "scriptSig": {
        "asm": "3046022100cd6795ebcd1b6b87833a4ad812733d3804065d34bafee24da181a770892272b902210088cd2484952ad2572f9bfb2874643dbb4b3c492b749e79d8177a14eb4a3bc61a[ALL] 04bbf2b84900b6f898548687aefba86cc06da6f4656a71e45fa55128b501455b5486cb09705cfa23c1899fe46d4355c9058bb2de4f1a7f1a01ff27e00b306f7356",
        "hex": "493046022100cd6795ebcd1b6b87833a4ad812733d3804065d34bafee24da181a770892272b902210088cd2484952ad2572f9bfb2874643dbb4b3c492b749e79d8177a14eb4a3bc61a014104bbf2b84900b6f898548687aefba86cc06da6f4656a71e45fa55128b501455b5486cb09705cfa23c1899fe46d4355c9058bb2de4f1a7f1a01ff27e00b306f7356"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 889.94500000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 f9d49c5cf3e120ad1be60b67d868603a8fc945d2 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914f9d49c5cf3e120ad1be60b67d868603a8fc945d288ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1PmyxDv5VvGoSAKMr1DQcWB6sHPx1ZbgWe"
        ]
      }
    }, 
    {
      "value": 10.00000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 088465c1f0c8b3b3da06f7073a921d6b95b22f49 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914088465c1f0c8b3b3da06f7073a921d6b95b22f4988ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1n31g4rKiEeXnZEZR6VZwm3LggLicEqEC"
        ]
      }
    }
  ]
}

Furthermore, I decoded the raw transaction using https://blockchain.info/decode-tx and got something different.

{
   "lock_time":0,
   "size":259,
   "inputs":[
      {
         "prev_out":{
            "index":0,
            "hash":"4f40655c4ab1a029bc41bc547f79556a0dc48d22df7202778fad592791c77fcd"
         },
         "script":"493046022100cd6795ebcd1b6b87833a4ad812733d3804065d34bafee24da181a770892272b902210088cd2484952ad2572f9bfb2874643dbb4b3c492b749e79d8177a14eb4a3bc61a014104bbf2b84900b6f898548687aefba86cc06da6f4656a71e45fa55128b501455b5486cb09705cfa23c1899fe46d4355c9058bb2de4f1a7f1a01ff27e00b306f7356"
      }
   ],
   "version":1,
   "vin_sz":1,
   "hash":"2514161c059ac18bf2eff1e05c4628e322d846e930fd6dd4b24805ea59dc4913",
   "vout_sz":2,
   "out":[
      {
         "script_string":"OP_DUP OP_HASH160 f9d49c5cf3e120ad1be60b67d868603a8fc945d2 OP_EQUALVERIFY OP_CHECKSIG",
         "address":"1PmyxDv5VvGoSAKMr1DQcWB6sHPx1ZbgWe",
         "value":88994500000,
         "script":"76a914f9d49c5cf3e120ad1be60b67d868603a8fc945d288ac"
      },
      {
         "script_string":"OP_DUP OP_HASH160 088465c1f0c8b3b3da06f7073a921d6b95b22f49 OP_EQUALVERIFY OP_CHECKSIG",
         "address":"1n31g4rKiEeXnZEZR6VZwm3LggLicEqEC",
         "value":1000000000,
         "script":"76a914088465c1f0c8b3b3da06f7073a921d6b95b22f4988ac"
      }
   ]
}

Why are some transactions found on some chain explorers but not on others?

This is something that has puzzled me for a while and I cannot think of a rational reason for it.
The transaction 3361d2484f0566ab13d32f2ab321319945f48eaea1ac2cc9f5a79b40528359c3 shows properly on blockchain.info and tradeblock.

However, I cannot find it either on blockr.io nor blocktrail.com.— I am also running a server to watch transactions and I cannot find this transaction either. Sometimes I can find transactions that do not appear on blockchain so it’s quite random.

All servers have many connections so I wonder what could be the issue? Slow network?

I forgot the index of my BIP32 key

I had chosen at random an index for storing some bitcoins. My key derivation path is Bip32 m/0h/1

How would I go about generating all 2 billion keys and check which one has the funds I stored?

The bip32gen software is too slow for this to happen anytime soon.

Any ideas?

Bitcoin Volatility

I am a French student in a Business School and currently working on a Bitcoin study.

I have 2 questions to you:

  • Are there means, for companies or states, to limit or at least to curb on the volatility of Bitcoin?
  • If not, can a company adopt measures to protect itself from a drastic slump of the Bitcoin price? If so, what are those?