BytomDAO/bytom

通过txid查询区块上的数据

ljaixx opened this issue · 1 comments

调用get-transaction只能获取到txpool中的数据、不能获取区块上的交易数据,有没有什么办法可以通过txid获取区块上的交易数据

get-transaction 是可以获取交易数据的,入块的数据和未确认的交易都能查询到。

例如,使用 bytomcli 的 get-transaction 可以查询特定交易哈希,如:6bd8151565ba1c0095ed45cad38e1772c227f01c6c9085e70119ab44361f4412

$ bytomcli get-transaction 6bd8151565ba1c0095ed45cad38e1772c227f01c6c9085e70119ab44361f4412
{
  "block_hash": "b5613de5455bb2d4785420874f2dc69c62acfb437712360255e905e8243bccb5",
  "block_height": 119736,
  "block_index": 1,
  "block_time": 1547796272,
  "block_transactions_count": 2,
  "inputs": [
    {
      "account_alias": "account_1",
      "account_id": "0LR2KGD300A02",
      "address": "tm1qq5nzpwr2d40qwvga2qval73cvnxv3f4aczd8h6",
      "amount": 1000000000,
      "asset_alias": "BTM",
      "asset_definition": {
        "decimals": 8,
        "description": "Bytom Official Issue",
        "name": "BTM",
        "symbol": "BTM"
      },
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "control_program": "0014052620b86a6d5e07311d5019dffa3864ccc8a6bd",
      "input_id": "12e3b40a2831f9057581f56d10aadc9d27e606d5777200497ba7c2181b889693",
      "spent_output_id": "a207b8fbabbbaf12aeb80f4d7f8af6ca38e5947d8637eee85720993536a48f4e",
      "type": "spend",
      "witness_arguments": [
        "1380979137ab48f28b4eea1c78e8130f4872b8d1916ce444605ee1ebabbdc01e828bd721fb38e05de95d4bec5889345c0d0980c93e4fb6fab0e9df2d8b59ad0d",
        "e87ca3acdebdcad9a1d0f2caecf8ce0dbfc73d060807a210c6f2254883479614"
      ]
    }
  ],
  "outputs": [
    {
      "account_alias": "account_1",
      "account_id": "0LR2KGD300A02",
      "address": "tm1qr7t689k6yktjpuujcrw7vdg6630njuwfurf5lp",
      "amount": 80000000,
      "asset_alias": "BTM",
      "asset_definition": {
        "decimals": 8,
        "description": "Bytom Official Issue",
        "name": "BTM",
        "symbol": "BTM"
      },
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "control_program": "00141f97a396da259720f392c0dde6351ad45f3971c9",
      "id": "649fbfc86166e01132f9ebb50afc7c2bce52e78ef1db76f49e4c5ab2610dece4",
      "position": 0,
      "type": "control"
    },
    {
      "account_alias": "account_4",
      "account_id": "0N5N8C5L00A02",
      "address": "tm1q9y67fp5aqvtajuquszszanugs9puh8wj3awdt4",
      "amount": 900000000,
      "asset_alias": "BTM",
      "asset_definition": {
        "decimals": 8,
        "description": "Bytom Official Issue",
        "name": "BTM",
        "symbol": "BTM"
      },
      "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
      "control_program": "00142935e4869d0317d9701c80a02ecf888143cb9dd2",
      "id": "254a2dabbd41ad0a77419513257726fd64f3e209d4fc64eae23cf2c61fc54b45",
      "position": 1,
      "type": "control"
    }
  ],
  "size": 330,
  "status_fail": false,
  "tx_id": "6bd8151565ba1c0095ed45cad38e1772c227f01c6c9085e70119ab44361f4412"
}

或者使用 api ,这个需要打开钱包,利用 postman 向地址 http://127.0.0.1:9888/get-transaction 发送 json:

{
  "tx_id":"6bd8151565ba1c0095ed45cad38e1772c227f01c6c9085e70119ab44361f4412" 
}

返回消息:

{
    "status": "success",
    "data": {
        "tx_id": "6bd8151565ba1c0095ed45cad38e1772c227f01c6c9085e70119ab44361f4412",
        "block_time": 1547796272,
        "block_hash": "b5613de5455bb2d4785420874f2dc69c62acfb437712360255e905e8243bccb5",
        "block_height": 119736,
        "block_index": 1,
        "block_transactions_count": 2,
        "inputs": [
            {
                "type": "spend",
                "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
                "asset_alias": "BTM",
                "asset_definition": {
                    "decimals": 8,
                    "description": "Bytom Official Issue",
                    "name": "BTM",
                    "symbol": "BTM"
                },
                "amount": 1000000000,
                "control_program": "0014052620b86a6d5e07311d5019dffa3864ccc8a6bd",
                "address": "tm1qq5nzpwr2d40qwvga2qval73cvnxv3f4aczd8h6",
                "spent_output_id": "a207b8fbabbbaf12aeb80f4d7f8af6ca38e5947d8637eee85720993536a48f4e",
                "account_id": "0LR2KGD300A02",
                "account_alias": "account_1",
                "input_id": "12e3b40a2831f9057581f56d10aadc9d27e606d5777200497ba7c2181b889693",
                "witness_arguments": [
                    "1380979137ab48f28b4eea1c78e8130f4872b8d1916ce444605ee1ebabbdc01e828bd721fb38e05de95d4bec5889345c0d0980c93e4fb6fab0e9df2d8b59ad0d",
                    "e87ca3acdebdcad9a1d0f2caecf8ce0dbfc73d060807a210c6f2254883479614"
                ]
            }
        ],
        "outputs": [
            {
                "type": "control",
                "id": "649fbfc86166e01132f9ebb50afc7c2bce52e78ef1db76f49e4c5ab2610dece4",
                "position": 0,
                "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
                "asset_alias": "BTM",
                "asset_definition": {
                    "decimals": 8,
                    "description": "Bytom Official Issue",
                    "name": "BTM",
                    "symbol": "BTM"
                },
                "amount": 80000000,
                "account_id": "0LR2KGD300A02",
                "account_alias": "account_1",
                "control_program": "00141f97a396da259720f392c0dde6351ad45f3971c9",
                "address": "tm1qr7t689k6yktjpuujcrw7vdg6630njuwfurf5lp"
            },
            {
                "type": "control",
                "id": "254a2dabbd41ad0a77419513257726fd64f3e209d4fc64eae23cf2c61fc54b45",
                "position": 1,
                "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
                "asset_alias": "BTM",
                "asset_definition": {
                    "decimals": 8,
                    "description": "Bytom Official Issue",
                    "name": "BTM",
                    "symbol": "BTM"
                },
                "amount": 900000000,
                "account_id": "0N5N8C5L00A02",
                "account_alias": "account_4",
                "control_program": "00142935e4869d0317d9701c80a02ecf888143cb9dd2",
                "address": "tm1q9y67fp5aqvtajuquszszanugs9puh8wj3awdt4"
            }
        ],
        "status_fail": false,
        "size": 330
    }
}