简体   繁体   English

从块 0 中获取密钥列表

[英]Getting a list of keys from block 0

Using a local blockchain, is it is possible to use the bitcoin-core rpc commands to query a block (such as the genesis block) and get a list of all the public keys used in that block?使用本地区块链,是否可以使用 bitcoin-core rpc 命令查询一个块(例如创世块)并获取该块中使用的所有公钥的列表? If it is possible, which commands do I need to use?如果可能,我需要使用哪些命令?

Not entirely.不是完全。 This is because modern outputs contain addresses (technically scriptPubkeys) which are encoded hashes of a public key, see Types of Transactions .这是因为现代输出包含地址(技术上是 scriptPubkeys),它们是公钥的编码散列,请参阅交易类型 Hashes cannot be reversed (or Bitcoin wouldn't work at all), so in order to reveal the public key, the spender must provide it.哈希不能被反转(或者比特币根本不起作用),所以为了揭示公钥,消费者必须提供它。 You can extract public keys from spent outputs (via the scriptSig ), but it is not straightforward.您可以从花费的输出中提取公钥(通过scriptSig ),但这并不简单。 With legacy outputs, however, (as in the genesis block), this is possible without spending because they use a deprecated transaction type (Pay-To-Pubkey).然而,对于遗留输出(如在创世块中),这无需花费即可实现,因为它们使用已弃用的交易类型(Pay-To-Pubkey)。

There are a few commands to use.有几个命令可以使用。 First, get the transactions in the block:首先,获取区块中的交易:

  1. getblockhash 获取块哈希
$ bitcoin-cli getblockhash 0
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

where 0 is the block index of the genesis block.其中 0 是创世区块的区块索引。

  1. getblock 获取块
$ bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f 2

{
  "hash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
  "confirmations": 600908,
  "strippedsize": 285,
  "size": 285,
  "weight": 1140,
  "height": 0,
  "version": 1,
  "versionHex": "00000001",
  "merkleroot": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
  "tx": [
    {
      "txid": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
      "hash": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
      "version": 1,
      "size": 204,
      "vsize": 204,
      "weight": 816,
      "locktime": 0,
      "vin": [
        {
          "coinbase": "04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73",
          "sequence": 4294967295
        }
      ],
      "vout": [
        {
          "value": 50.00000000,
          "n": 0,
          "scriptPubKey": {
            "asm": "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f OP_CHECKSIG",
            "hex": "4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac",
            "reqSigs": 1,
            "type": "pubkey",
            "addresses": [
              "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
            ]
          }
        }
      ],
      "hex": "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000"
    }
  ],
  "time": 1231006505,
  "mediantime": 1231006505,
  "nonce": 2083236893,
  "bits": "1d00ffff",
  "difficulty": 1,
  "chainwork": "0000000000000000000000000000000000000000000000000000000100010001",
  "nTx": 1,
  "nextblockhash": "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"
}

where the first argument is the block hash, and 2 is the verbosity (ie for json object with transaction data).其中第一个参数是块 hash,2 是详细程度(即对于 json object 与事务数据)。 Note that this is not much data for the genesis block, but for more recent blocks, this will be very large and slow.请注意,创世区块的数据不多,但对于最近的区块,这将非常大且缓慢。

  1. Extract the public key from the scriptPubkey Lucky for us, the genesis block uses a deprecated transaction type called Pay-to-Pubkey which gives us the public key and is of the form:scriptPubkey中提取公钥 幸运的是,创世块使用了一种已弃用的交易类型,称为 Pay-to-Pubkey,它为我们提供了公钥,其形式如下:

<pubkey> OP_CHECKSIG

In the first vout the scriptPubkey is 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f OP_CHECKSIG在第一个vout中, scriptPubkey04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f OP_CHECKSIG

So the public key is 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f .所以公钥是04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f Note that this is 65 bytes because early Bitcoin versions used uncompressed public keys.请注意,这是 65 字节,因为早期的比特币版本使用未压缩的公钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM