osagga / insight-api

The bitcoin blockchain API powering Insight
https://github.com/bitpay/insight
2 stars 3 forks source link

Getting Invalid Address when looking up bcash address or legacy #2

Open haydencarlson opened 6 years ago

haydencarlson commented 6 years ago

Got my node syncing now, I noticed that when I try to make a request to [insight_host_url]/api/addr/bitcoincash:qzq2myx5qdvplgalgcyx4ydjm82pyhdkcyga74fzrw for example I'm getting an Invalid address. Code:-5

My bitcoin.conf

server=1
whitelist=127.0.0.1
txindex=1
addressindex=1
timestampindex=1
spentindex=1
zmqpubrawtx=tcp://127.0.0.1:28332
zmqpubhashblock=tcp://127.0.0.1:28332
rpcallowip=127.0.0.1
rpcuser=bitcoin
rpcpassword=local321
uacomment=bitcore
usecashaddr=0

Then when trying to use the same url to look up the legacy address equivalent I get

Invalid address: Address has mismatched network type.. Code:1

bitcore-node.json

{
  "network": "livenet",
  "port": 3024,
  "services": [
    "bitcoind",
    "insight-ui",
    "insight-api",
    "web"
  ],
  "servicesConfig": {
    "insight-ui": {
      "routePrefix": "",
      "apiPrefix": "api"
    },
    "insight-api": {
      "routePrefix": "api",
      "disableRateLimiter": true
    },
    "bitcoind": {
      "spawn": {
        "datadir": "/home/[user]/.bitcoin",
        "exec": "/usr/local/bin/bitcoind"
      }
    }
  }
}
osagga commented 6 years ago

So I can't seem to be able to reproduce your problem, on my end, when I query the same API endpoint I get the following:

curl -s [insight_host_url]/api/addr/bitcoincash:qzq2myx5qdvplgalgcyx4ydjm82pyhdkcyga74fzrw | json_pp 
{
   "transactions" : [],
   "balanceSat" : 0,
   "totalSentSat" : 0,
   "totalReceivedSat" : 0,
   "unconfirmedBalance" : 0,
   "balance" : 0,
   "addrStr" : "bitcoincash:qzq2myx5qdvplgalgcyx4ydjm82pyhdkcyga74fzrw",
   "unconfirmedBalanceSat" : 0,
   "txApperances" : 0,
   "totalSent" : 0,
   "totalReceived" : 0,
   "unconfirmedTxApperances" : 0
}

My node is not fully synced on mainnet, that's why the values are 0 I believe, I have heavily tested the api on regtest and it seems to work fine with BCH addresses.

So can you confirm that you're using the right insight-api?

haydencarlson commented 6 years ago
{
  "description": "A full Bitcoin node build with Bitcore",
  "repository": "https://github.com/user/project",
  "license": "MIT",
  "readme": "README.md",
  "dependencies": {
    "bitcore-lib": "^v0.13.19",
    "bitcore-node": "^3.1.3",
    "insight-api": "github:osagga/insight-api#cash_v4",
    "insight-ui": "^0.4.0"
  }
}

My node isn't fully synced yet. I followed this https://github.com/osagga/bch-bitcore-setup/blob/master/README.md exactly.

osagga commented 6 years ago

That's weird, what do you get when you try the tx api? What address format do you get back?

curl -s [url]/api/tx/ab60ec9c476cfe9efe97307203e1847067c229f851540e69c55d4c9c6685517a | json_pp 
{
   "version" : 1,
   "locktime" : 0,
   "confirmations" : 4365,
   "fees" : 0,
   "blocktime" : 1341156887,
   "time" : 1341156887,
   "blockhash" : "000000000000001a3097cd08b7eb04e2aa14408518ca6cf2dbf606b9127bfec0",
   "vin" : [
      {
         "value" : 10,
         "txid" : "c4a753b83178bac1a01dc80041a900b20e0dd3c93d5bca094afe6cf7bb30aac9",
         "vout" : 1,
         "scriptSig" : {
            "hex" : "493046022100fb90cb0cb4cf35c7025cce7d5981894b6c47894e03c18465737adda95d5beb55022100ee6e117e4c2f0deb6707261baf5bd97f30afcb3421064b0e93c722e76917b23f014104453cb306d76ed4edbe5c639d5773fbf30a6f3960a920324719341def48e2d23b98f0a2381338749602de9ad68259f5f39ef7525b93044ceea11cd95e8f723bbe",
            "asm" : "3046022100fb90cb0cb4cf35c7025cce7d5981894b6c47894e03c18465737adda95d5beb55022100ee6e117e4c2f0deb6707261baf5bd97f30afcb3421064b0e93c722e76917b23f[ALL] 04453cb306d76ed4edbe5c639d5773fbf30a6f3960a920324719341def48e2d23b98f0a2381338749602de9ad68259f5f39ef7525b93044ceea11cd95e8f723bbe"
         },
         "n" : 0,
         "valueSat" : 1000000000,
         "addr" : "bitcoincash:qpjmgrxqsmjuvxhhrwwzu9ezzlpwy209my98krr4ty",
         "sequence" : 4294967295,
         "doubleSpentTxID" : null
      }
   ],
   "valueOut" : 10,
   "blockheight" : 187049,
   "size" : 259,
   "txid" : "ab60ec9c476cfe9efe97307203e1847067c229f851540e69c55d4c9c6685517a",
   "valueIn" : 10,
   "vout" : [
      {
         "spentTxId" : null,
         "value" : "0.03000000",
         "n" : 0,
         "spentHeight" : null,
         "scriptPubKey" : {
            "type" : "pubkeyhash",
            "addresses" : [
               "bitcoincash:qqatunvyca6qtwhgu6q87k3qw2r6ccqungtelylyqg"
            ],
            "asm" : "OP_DUP OP_HASH160 3abe4d84c77405bae8e6807f5a207287ac601c9a OP_EQUALVERIFY OP_CHECKSIG",
            "hex" : "76a9143abe4d84c77405bae8e6807f5a207287ac601c9a88ac"
         },
         "spentIndex" : null
      },
      {
         "value" : "9.97000000",
         "spentTxId" : "8f66673a83e7acc3fa23a01c7f57ad89aeb7bac77fc4707738c261135ec602ff",
         "n" : 1,
         "spentHeight" : 187547,
         "spentIndex" : 0,
         "scriptPubKey" : {
            "hex" : "76a91479b27a500cd55b307453c1f7372ccb30cb33bd4b88ac",
            "addresses" : [
               "bitcoincash:qpumy7jspn24kvr520qlwdevevcvkvaafvhj7j9zd2"
            ],
            "asm" : "OP_DUP OP_HASH160 79b27a500cd55b307453c1f7372ccb30cb33bd4b OP_EQUALVERIFY OP_CHECKSIG",
            "type" : "pubkeyhash"
         }
      }
   ]
}
haydencarlson commented 6 years ago

@osagga

{
"txid": "4ed90810ad36108cf2af9879ca2ee77ad1c3353895b7ad06ea9cf86663bcd881",
"version": 1,
"locktime": 0,
"vin": [
{
"txid": "8f21d67cde7e51da6875ad304cdfbd5c4674626c09627ca2dca5f2bec8c61436",
"vout": 1,
"sequence": 4294967295,
"n": 0,
"scriptSig": {
"hex": "473044022047c78d2220d997cad2d0ff73d68c3bfdbb78385d952e75a0f5c0c7979249e19602200759efe4b7230eefb4a7abda595011f815caba7854895cdc2c5eb2af292b6b2b0141044f9707e51efe5353c789ee0cb4e4ad46a678a89ff890e4bc701bf18318f6515a40e4efeeb546530062464b884b8d9bad325446eab099fe65a387d084c858fa01",
"asm": "3044022047c78d2220d997cad2d0ff73d68c3bfdbb78385d952e75a0f5c0c7979249e19602200759efe4b7230eefb4a7abda595011f815caba7854895cdc2c5eb2af292b6b2b[ALL] 044f9707e51efe5353c789ee0cb4e4ad46a678a89ff890e4bc701bf18318f6515a40e4efeeb546530062464b884b8d9bad325446eab099fe65a387d084c858fa01"
},
"addr": "bitcoincash:qz6ulg6u3wpl0hd9wxevf7slr45dcpz6z5hpjfhu8v",
"valueSat": 208658264,
"value": 2.08658264,
"doubleSpentTxID": null
}
],
"vout": [
{
"value": "0.01000000",
"n": 0,
"scriptPubKey": {
"hex": "76a9149674483892cfeb0ed17daf7c2f98daef24245bd288ac",
"asm": "OP_DUP OP_HASH160 9674483892cfeb0ed17daf7c2f98daef24245bd2 OP_EQUALVERIFY OP_CHECKSIG",
"addresses": [
"bitcoincash:qzt8gjpcjt87krk30khhctucmthjgfzm6ggfq3edry"
],
"type": "pubkeyhash"
},
"spentTxId": null,
"spentIndex": null,
"spentHeight": null
},
{
"value": "2.06658264",
"n": 1,
"scriptPubKey": {
"hex": "76a914b5cfa35c8b83f7dda571b2c4fa1f1d68dc045a1588ac",
"asm": "OP_DUP OP_HASH160 b5cfa35c8b83f7dda571b2c4fa1f1d68dc045a15 OP_EQUALVERIFY OP_CHECKSIG",
"addresses": [
"bitcoincash:qz6ulg6u3wpl0hd9wxevf7slr45dcpz6z5hpjfhu8v"
],
"type": "pubkeyhash"
},
"spentTxId": "7cba0c4192df02f2c62d833be7d3ab2bcb5a95e4ad9e4e624e9c3c4199600098",
"spentIndex": 0,
"spentHeight": 325505
}
],
"blockhash": "0000000000000000169ba219b79ee6fde850c4909f42d7882e81c73485036dbc",
"blockheight": 325493,
"confirmations": 78,
"time": 1413412614,
"blocktime": 1413412614,
"valueOut": 2.07658264,
"size": 257,
"valueIn": 2.08658264,
"fees": 0.01
}
haydencarlson commented 6 years ago

@osagga Which node repo are you using?

osagga commented 6 years ago

@haydencarlson So I'm using the bitcore node from npm (just as shown in the guide), it matches bitcore-node: 3.1.3 from the Github repo. As for bitcoin-abc, you need to build the custom one from source. I also have this repo with pre-compiled bitcoin-abc binaries that I built for myself. You can give it a try, but building from source is safer.

osagga commented 6 years ago

@haydencarlson I was able to reproduce the problem on Ubuntu, I'll keep you updated if I fix it. I have been testing the API on CentOS, and it seems to work fine. Let me know if you can identify where the error is thrown from.

haydencarlson commented 6 years ago

@osagga Ok cool, I'll check it out today. I am on ubuntu so it must be ubuntu specific.

The machine is running Ubuntu 18.04

haydencarlson commented 6 years ago

@osagga I ended up using CentOS aswell. It works fine on CentOS like you said.