Bitcoin Forum
July 05, 2024, 09:38:22 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoin or Litecoin Core: return payment to sender  (Read 44 times)
Knight Hider (OP)
Member
**
Offline Offline

Activity: 290
Merit: 68

a young loner on a crusade


View Profile
Today at 02:59:07 AM
Last edit: Today at 02:55:20 PM by Knight Hider
 #1

How to get a transaction input address, like block explorers do, directly from Core client? I need it to return a payment to one of the sending addresses.

litecoin-cli gettransaction:
Code:
{
  "amount": 0.00005851,
  "confirmations": 2,
  "blockhash": "1ee0005f20625b4dda47cff35a0214940d5c0e8f33cc42054a9ffa3e1370583d",
  "blockheight": 2714382,
  "blockindex": 318,
  "blocktime": 1720098028,
  "txid": "5c4dcff65ed69060f84005fcfc9c9cccd1d2eed38d30d2df95f4524ce1075576",
  "walletconflicts": [
  ],
  "time": 1720097921,
  "timereceived": 1720097921,
  "bip125-replaceable": "no",
  "details": [
    {
      "address": "ltc1qevgc8uymrxd3vq3vztmqhz0tq2y3jpx8twn2qt",
      "category": "receive",
      "amount": 0.00005851,
      "label": "",
      "vout": 1
    }
  ],
  "hex": "020000000001015ed7d1b7f75e3e3c0901b97fa96095d8e3a2d8fdaad07ff5b2e0d0bbd7e12ecf0100000000feffffff02327d030000000000160014ce295448dda30f95852504b78071b3dd23b68232db16000000000000160014cb1183f09b199b16022c12f60b89eb02891904c70247304402201b4a01969140b75d66b797718819d0fcc6538962d666298b9d020db3a9e47b8e022020dea3ec9ecbdb244c3c745555e7e0a553f81785292fa3233209b5bce8009b2801210276771913879beb7efe864f26486987637d06649c01d362dbc3a8d94a35556f7d0d6b2900"
}

I use Litecoin for testing because it works better than Testnet

https://live.blockcypher.com/ltc/decodetx/ shows "inputs" address when decoding "hex":
Code:
{
    "addresses": [
        "ltc1qevgc8uymrxd3vq3vztmqhz0tq2y3jpx8twn2qt",
        "ltc1q70uam3y0hrg3uypsupteldu4dw2385kmks8yqs",
        "ltc1qec54gjxa5v8etpf9qjmcqudnm53mdq3jze7y5s"
    ],
    "block_height": -1,
    "block_index": -1,
    "confirmations": 0,
    "double_spend": false,
    "fees": 155,
    "hash": "5c4dcff65ed69060f84005fcfc9c9cccd1d2eed38d30d2df95f4524ce1075576",
    "inputs": [
        {
            "addresses": [
                "ltc1q70uam3y0hrg3uypsupteldu4dw2385kmks8yqs"
            ],
            "age": 2714381,
            "output_index": 1,
            "output_value": 234664,
            "prev_hash": "cf2ee1d7bbd0e0b2f57fd0aafdd8a2e3d89560a97fb901093c3e5ef7b7d1d75e",
            "script_type": "pay-to-witness-pubkey-hash",
            "sequence": 4294967294,
            "witness": [
                "304402201b4a01969140b75d66b797718819d0fcc6538962d666298b9d020db3a9e47b8e022020dea3ec9ecbdb244c3c745555e7e0a553f81785292fa3233209b5bce8009b2801",
                "0276771913879beb7efe864f26486987637d06649c01d362dbc3a8d94a35556f7d"
            ]
        }
    ],
    "lock_time": 2714381,
    "outputs": [
        {
            "addresses": [
                "ltc1qec54gjxa5v8etpf9qjmcqudnm53mdq3jze7y5s"
            ],
            "script": "0014ce295448dda30f95852504b78071b3dd23b68232",
            "script_type": "pay-to-witness-pubkey-hash",
            "value": 228658
        },
        {
            "addresses": [
                "ltc1qevgc8uymrxd3vq3vztmqhz0tq2y3jpx8twn2qt"
            ],
            "script": "0014cb1183f09b199b16022c12f60b89eb02891904c7",
            "script_type": "pay-to-witness-pubkey-hash",
            "value": 5851
        }
    ],
    "preference": "low",
    "received": "2024-07-04T13:13:34.80374529Z",
    "relayed_by": "50.17.116.247",
    "size": 222,
    "total": 234509,
    "ver": 2,
    "vin_sz": 1,
    "vout_sz": 2,
    "vsize": 141
}

My own Core installation does not show the sending address:
Code:
{
  "txid": "5c4dcff65ed69060f84005fcfc9c9cccd1d2eed38d30d2df95f4524ce1075576",
  "hash": "94af7b95225412fe812b24dc64c9a027b204b7ccef14cde38212c860fa129e9f",
  "version": 2,
  "size": 222,
  "vsize": 141,
  "weight": 561,
  "locktime": 2714381,
  "vin": [
    {
      "ismweb": false,
      "txid": "cf2ee1d7bbd0e0b2f57fd0aafdd8a2e3d89560a97fb901093c3e5ef7b7d1d75e",
      "vout": 1,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402201b4a01969140b75d66b797718819d0fcc6538962d666298b9d020db3a9e47b8e022020dea3ec9ecbdb244c3c745555e7e0a553f81785292fa3233209b5bce8009b2801",
        "0276771913879beb7efe864f26486987637d06649c01d362dbc3a8d94a35556f7d"
      ],
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "ismweb": false,
      "value": 0.00228658,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 ce295448dda30f95852504b78071b3dd23b68232",
        "hex": "0014ce295448dda30f95852504b78071b3dd23b68232",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "ltc1qec54gjxa5v8etpf9qjmcqudnm53mdq3jze7y5s"
        ]
      }
    },
    {
      "ismweb": false,
      "value": 0.00005851,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 cb1183f09b199b16022c12f60b89eb02891904c7",
        "hex": "0014cb1183f09b199b16022c12f60b89eb02891904c7",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "ltc1qevgc8uymrxd3vq3vztmqhz0tq2y3jpx8twn2qt"
        ]
      }
    }
  ]
}

Is this possible without txindex=1?I use a pruned node.

in a world of criminals who operate above the law
one man can make a difference and you are going to be that man
nc50lc
Legendary
*
Offline Offline

Activity: 2464
Merit: 5776


Self-proclaimed Genius


View Profile
Today at 04:19:36 AM
Merited by ABCbits (1), Knight Hider (1)
 #2

Is this possible without txindex=1?I use a pruned node.
Quite possible, if the block where the transaction is still not pruned or if it's still in your mempool,
You can use getrawtransaction in your Bitcoin Core node even without txindex by providing the hash of the block where the transaction is included.
Then use verbosity "2" to include "prevout" to each of the inputs in the result.

For example, test the first non-coinbase transaction in current latest block height 850758 with the block hash 00000000000000000000a8e2c7fcd3b21caa2da453d956f86ec1e77ff39fd0b8.
That block should still be available in your Bitcoin Core's blocksdir I suppose, command:
Code:
getrawtransaction "cfb247517f143c0bf5b1ffeca8789f29000c64881e3ed992976a954b58b024d0" (2, "00000000000000000000a8e2c7fcd3b21caa2da453d956f86ec1e77ff39fd0b8")
Result:
Code:
{
  "in_active_chain": true,
  "txid": "cfb247517f143c0bf5b1ffeca8789f29000c64881e3ed992976a954b58b024d0",
  "hash": "9fbe051c4ecc33a306156b489f71eb160fc4179eb0a991c6930b7a294cea74e9",
  "version": 2,
  "size": 394,
  "vsize": 232,
  "weight": 928,
  "locktime": 0,
  "vin": [
    {
      "txid": "1e00b133c90fe8d43039d2cc62df138ed1ac60a39f4dac356a0f9b57f7274db3",
      "vout": 1,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402203339a2d122b03d7afd1f19f2afcda93e3d2d4e996e032b6d7cf2c1dcca97052e02205012f1f8ad6b6cb89b7a2f13a1e8c4fa6c78760da9f0931b08b994ab0533446e01",
        "0363dca8904864aa8aef426b6253b3665909ca4fc3b24cd43e5f05150511825b0c"
      ],
      "prevout": {
        "generated": false,
        "height": 850753,
        "value": 0.00000546,
        "scriptPubKey": {
          "asm": "0 527500fb3b5b7cdd522524287c9a0cd09ed0508d",
          "desc": "addr(bc1q2f6sp7emtd7d6539ys58exsv6z0dq5ydu2xnhq)#4w8k5ahs",
          "hex": "0014527500fb3b5b7cdd522524287c9a0cd09ed0508d",
          "address": "bc1q2f6sp7emtd7d6539ys58exsv6z0dq5ydu2xnhq",
          "type": "witness_v0_keyhash"
        }
      },
      "sequence": 4294967295
    },
    {
      "txid": "e3cf7ba33137218105be5eb8740ca41887c3ce830cf9a2017c7fa1e4738546d1",
      "vout": 2,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402205131daeef0baa06660c5be9984ba0255b9fa46d960fadbe06908e3e20a6e927d0220660b06b940af97346220a11266d7a1631619c1717315b1d9eadfabc1275bf85f01",
        "03497a874c3412319689cc435756a820c3cf4cbb22d88ccafa29a8dc5e74eaa538"
      ],
      "prevout": {
        "generated": false,
        "height": 850738,
        "value": 0.00705938,
        "scriptPubKey": {
          "asm": "0 d58d2895ae676864b28af1d980c797d83f4d781f",
          "desc": "addr(bc1q6kxj39dwva5xfv5278vcp3uhmql567qlpldtcr)#afxt7ysj",
          "hex": "0014d58d2895ae676864b28af1d980c797d83f4d781f",
          "address": "bc1q6kxj39dwva5xfv5278vcp3uhmql567qlpldtcr",
          "type": "witness_v0_keyhash"
        }
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_RETURN 13 00c0a233038097b7e0ae0101",
        "desc": "raw(6a5d0c00c0a233038097b7e0ae0101)#m6f8ms85",
        "hex": "6a5d0c00c0a233038097b7e0ae0101",
        "type": "nulldata"
      }
    },
    {
      "value": 0.00000546,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 979bdd94f2d5972c062a7839ef114c193eca970a",
        "desc": "addr(bc1qj7dam98j6ktjcp320qu77y2vrylv49c2k2hkmu)#0ms2gq9q",
        "hex": "0014979bdd94f2d5972c062a7839ef114c193eca970a",
        "address": "bc1qj7dam98j6ktjcp320qu77y2vrylv49c2k2hkmu",
        "type": "witness_v0_keyhash"
      }
    },
    {
      "value": 0.00697938,
      "n": 2,
      "scriptPubKey": {
        "asm": "0 d58d2895ae676864b28af1d980c797d83f4d781f",
        "desc": "addr(bc1q6kxj39dwva5xfv5278vcp3uhmql567qlpldtcr)#afxt7ysj",
        "hex": "0014d58d2895ae676864b28af1d980c797d83f4d781f",
        "address": "bc1q6kxj39dwva5xfv5278vcp3uhmql567qlpldtcr",
        "type": "witness_v0_keyhash"
      }
    }
  ],
  "fee": 0.00008000,
  "hex": "02000000000102b34d27f7579b0f6a35ac4d9fa360acd18e13df62ccd23930d4e80fc933b1001e0100000000ffffffffd1468573e4a17f7c01a2f90c83cec38718a40c74b85ebe0581213731a37bcfe30200000000ffffffff0300000000000000000f6a5d0c00c0a233038097b7e0ae01012202000000000000160014979bdd94f2d5972c062a7839ef114c193eca970a52a60a0000000000160014d58d2895ae676864b28af1d980c797d83f4d781f0247304402203339a2d122b03d7afd1f19f2afcda93e3d2d4e996e032b6d7cf2c1dcca97052e02205012f1f8ad6b6cb89b7a2f13a1e8c4fa6c78760da9f0931b08b994ab0533446e01210363dca8904864aa8aef426b6253b3665909ca4fc3b24cd43e5f05150511825b0c0247304402205131daeef0baa06660c5be9984ba0255b9fa46d960fadbe06908e3e20a6e927d0220660b06b940af97346220a11266d7a1631619c1717315b1d9eadfabc1275bf85f012103497a874c3412319689cc435756a820c3cf4cbb22d88ccafa29a8dc5e74eaa53800000000",
  "blockhash": "00000000000000000000a8e2c7fcd3b21caa2da453d956f86ec1e77ff39fd0b8",
  "confirmations": 1,
  "time": 1720151784,
  "blocktime": 1720151784
}

But if the block is already pruned, it wont work. You'll have to use txindex and intact blockchain.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Knight Hider (OP)
Member
**
Offline Offline

Activity: 290
Merit: 68

a young loner on a crusade


View Profile
Today at 02:57:47 PM
Last edit: Today at 08:53:47 PM by Knight Hider
 #3

Quite possible, if the block where the transaction is still not pruned or if it's still in your mempool,
You can use getrawtransaction in your Bitcoin Core node even without txindex by providing the hash of the block where the transaction is included.
Then use verbosity "2" to include "prevout" to each of the inputs in the result.

This works in Bitcoin Core but not in Litecoin Core. Github issue: https://github.com/litecoin-project/litecoin/issues/948
The block is not pruned yet when I need this.

Code:
getrawtransaction 75c83da6ddf052405b5629fd30609783bd002ba80db3a947c52e13b8779022b5 2 9a03b9c095c170b270073b54da293be64dec9a90ed065cce562cf065ff6a9906


{
  "in_active_chain": true,
  "txid": "75c83da6ddf052405b5629fd30609783bd002ba80db3a947c52e13b8779022b5",
  "hash": "8baeff24369ead1589d1c90b3c6dd9162b0798e1102697163384179e1b211477",
  "version": 2,
  "size": 222,
  "vsize": 141,
  "weight": 561,
  "locktime": 2715166,
  "vin": [
    {
      "ismweb": false,
      "txid": "2d7d107e05b9db7c9b226c94ea9d0101330d3d76a7d799cb6f045cb72994bbf2",
      "vout": 1,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402206eaaa210752ca3418606bca1883b563e7b40c8488c50ade9c542d80f131c20a302202ba50d08ffcba7b5e65251969861621064ce3c4b6d61b3e1236b56c15ef124b101",
        "02ae77a4757d225d777d3d4320c2678864ff3608bee5a326149358d6a6edb07418"
      ],
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "ismweb": false,
      "value": 0.00010147,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 4f154d4e85d1cae0a8ee766b6a0b37c2905e6b94",
        "hex": "00144f154d4e85d1cae0a8ee766b6a0b37c2905e6b94",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "ltc1qfu256n59689wp28wwe4k5zehc2g9u6u5p35vg7"
        ]
      }
    },
    {
      "ismweb": false,
      "value": 0.00043344,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 56e9c0c2cf6de4fbe76bf10bdeabedbf3de33539",
        "hex": "001456e9c0c2cf6de4fbe76bf10bdeabedbf3de33539",
        "reqSigs": 1,
        "type": "witness_v0_keyhash",
        "addresses": [
          "ltc1q2m5upsk0dhj0hemt7y9aa2ldhu77xdfe9ztmru"
        ]
      }
    }
  ],
  "hex": "02000000000101f2bb9429b75c046fcb99d7a7763d0d3301019dea946c229b7cdbb9057e107d2d0100000000feffffff02a3270000000000001600144f154d4e85d1cae0a8ee766b6a0b37c2905e6b9450a900000000000016001456e9c0c2cf6de4fbe76bf10bdeabedbf3de335390247304402206eaaa210752ca3418606bca1883b563e7b40c8488c50ade9c542d80f131c20a302202ba50d08ffcba7b5e65251969861621064ce3c4b6d61b3e1236b56c15ef124b1012102ae77a4757d225d777d3d4320c2678864ff3608bee5a326149358d6a6edb074181e6e2900",
  "blockhash": "9a03b9c095c170b270073b54da293be64dec9a90ed065cce562cf065ff6a9906",
  "confirmations": 7,
  "time": 1720211910,
  "blocktime": 1720211910
}

in a world of criminals who operate above the law
one man can make a difference and you are going to be that man
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!