Bitcoin Forum
December 05, 2016, 06:56:54 PM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Address transactions via json  (Read 1038 times)
SmokeAndMirrors
Full Member
***
Offline Offline

Activity: 168


View Profile
September 16, 2011, 09:45:27 PM
 #1

Greetings,

I've got a small project I've been asked to work on that involves fetching data from the block chain but in this scenario, it's not efficient to keep an updated block-chain on the end-users device.

I've done a few quick google searches but haven't come up with any web-services/sites that supply JSON involving block-chain data. I'm wondering if anyone is aware of one out there that supplies all of the ordinary involving addresses sending/receiving, tx's, etc. If so, a pointer in the right direction would be appreciated so I can talk to whoever is in control of the service to make sure this is alright with them.

Thanks,

Jay

Help Bitcoins by buying clothes, technology, books, etc. through people/stores that accept BTC. This will increase overall value of BTC as well as mitigate unnecessary bank transaction fees.

My address -
1EM9HGg1SEa5Bux1rVEPxGqGSfNTTc9EkC
1480964214
Hero Member
*
Offline Offline

Posts: 1480964214

View Profile Personal Message (Offline)

Ignore
1480964214
Reply with quote  #2

1480964214
Report to moderator
1480964214
Hero Member
*
Offline Offline

Posts: 1480964214

View Profile Personal Message (Offline)

Ignore
1480964214
Reply with quote  #2

1480964214
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1480964214
Hero Member
*
Offline Offline

Posts: 1480964214

View Profile Personal Message (Offline)

Ignore
1480964214
Reply with quote  #2

1480964214
Report to moderator
1480964214
Hero Member
*
Offline Offline

Posts: 1480964214

View Profile Personal Message (Offline)

Ignore
1480964214
Reply with quote  #2

1480964214
Report to moderator
theymos
Administrator
Legendary
*
expert
Online Online

Activity: 2492


View Profile
September 17, 2011, 12:17:14 AM
 #2

http://blockexplorer.com/q/mytransactions

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
SmokeAndMirrors
Full Member
***
Offline Offline

Activity: 168


View Profile
September 17, 2011, 01:26:15 AM
 #3

Thanks theymos. I was positive you had JSON responses for block-explorer. I couldn't find any info on it though and from the "everyday" site I'm used to, pulling up JSON requests and responses showed me no activity.

Anyway, I'm assuming you won't mind me using your server to pull info Smiley.


Help Bitcoins by buying clothes, technology, books, etc. through people/stores that accept BTC. This will increase overall value of BTC as well as mitigate unnecessary bank transaction fees.

My address -
1EM9HGg1SEa5Bux1rVEPxGqGSfNTTc9EkC
theymos
Administrator
Legendary
*
expert
Online Online

Activity: 2492


View Profile
September 17, 2011, 01:52:16 AM
 #4

Yeah, the /q pages are there for the benefit of automated services, so feel free to use them. Please use the caching features of that page where possible, though (HTTP ETag and the "block stop point"), and don't refresh data more than every few minutes.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
SmokeAndMirrors
Full Member
***
Offline Offline

Activity: 168


View Profile
September 20, 2011, 12:22:15 AM
 #5

I spent a few hours writing the client code to pull the JSON objects based on user address input yesterday. I hadn't really looked too much at the json structure as it seemed pretty straight-forward but after running the application I've found some problems.

http://blockexplorer.com/q/mytransactions/1BRBDedwsCgCF7yXqmEyzoaFpN8Lj8DpFo

The address I'm looking to grab info for is posted in the link above.

Quote
  "5364f255f2bedab01d78b088bf739449af2392eb0cdccbc9a508e24d4048e57b":{
    "hash":"5364f255f2bedab01d78b088bf739449af2392eb0cdccbc9a508e24d4048e57b",
    "ver":1,
    "vin_sz":1,
    "vout_sz":2,
    "lock_time":0,
    "size":258,
    "in":[
      {
        "prev_out":{
          "hash":"76296cc2bad250fd01226602cd9e7cc180d6462a1e63ed142ee26eefb2a69a8c",
          "n":0
        },
        "scriptSig":"3045022100e950367685c977f79e46d90b6f58d31b1263abce437037243b9afbd67144da0702202 76bf04bee7a40fc8fea4d5becef7cf39cdbbaa19536f1ee43d8cf9ebde844b201 0488f70e4fa004235ec7bfa687ba12a9acc2c8c2df161337e51671f8802f76db72d331cea22aea3 f1c9fed8b4d03f190acb0f80085a65ec34dae480799c4eb8843",
        "address":"167MG7Mq1bXxktqeVDeoY9gnGXSSkCNVyC"
      }
    ],
    "out":[
      {
        "value":"964.47580385",
        "scriptPubKey":"OP_DUP OP_HASH160 ebd685ad5caa1c62b6fa17a8e691c2a6e962e307 OP_EQUALVERIFY OP_CHECKSIG",
        "address":"1NVznLrSGAqE6uKDfyczTSzPPDmqmCnhp6"
      },
      {
        "value":"0.01000000",
        "scriptPubKey":"OP_DUP OP_HASH160 7243c542a72b7533cbd9b545ad194e8c61e97c8f OP_EQUALVERIFY OP_CHECKSIG",
        "address":"1BRBDedwsCgCF7yXqmEyzoaFpN8Lj8DpFo"
      }
    ],
    "block":"00000000000005990e6ef142e98ea7404432c87fbfe226d542e2d94f97912b3b",
    "blocknumber":"132376",
    "time":"2011-06-21 20:51:45"
  }

In this object, the address sending is from slush's pool from an old mining payment transaction. This is easily handled by my program due to received JSON transactions containing the address that received as well as the value of bitcoins that was received. It's a simple loop "out" array, if address matches userDefinedAddress, it adds this to the users total balance according to that address.

However, then we've got another scenario such as:
Quote
"in":[
      {
        "prev_out":{
          "hash":"80b65fb137803cc143807341eccf151eb54b662931e72aeaf59d9ec87a32ff53",
          "n":0
        },
        "scriptSig":"3045022100b05e1c0104d8b0c2034eede70bedea4eb91b3bd079f107754456d5d1c808f36602200 ddbd1bf68d559940709d9781201074237ba3fd2ee81ce727e180b306940c88201 04a8f2a5c0a60e01d5fc4da66299fe5d601f2a134f97f20d7b2a4f50b52a27fe5c942942ced1a50 8e05fb8a10838d5986fdd1e1d658bd708ea5a672befe4b28c9b",
        "address":"1LNsGtdBbb2gQecUMaRE2jPJaMfAgfXyoe"
      },
      {
        "prev_out":{
          "hash":"e0375ae5c22f0ebc137885f6de4cd6b9cd6d0714e92e10e0d2c2e81d9f53789a",
          "n":1
        },
        "scriptSig":"3045022100f955fcc73c4fa5cda6ad35673bab66cafc335b8d96a60a2f6220c2249632c2bd02204 ac33952b13cebaf36de9426222d71bbc7f5656afad07685ebd72e4215bba67f01 04d960ac87d8e276c6cf45a50e302ba0280dd44789d72d9dc7a7e7f00ed6b27713a18a9bcff008f e836c090d7ab377450f11fe7c7f2c9d825de1e3b8e929960244",
        "address":"1BRBDedwsCgCF7yXqmEyzoaFpN8Lj8DpFo"
      },
      {
        "prev_out":{
          "hash":"c2b313d7606832ca0a9cfe2744fa7f9be0ed35342e80c8c5d053b8fb2f1bf622",
          "n":0
        },
        "scriptSig":"30450220171a33d6237d19612f066699d8e7edff5abcba0fba7ad7591143da1afe791938022100a afdd6327f61757e86b1db0d38a4f064e0310ec760d92c10324db2be9254006a01 04ba3c254507d86cfd496ab75f2cb53d4d3f32ef6532fd63accdeb9f03657f25c45a46112440670 49b4c266872d24b59f9c2f9bec7b027248ad425694e35d9e2ea",
        "address":"1N6QUXuRpmE47DtTgooxoHvGFhqTENpRwT"
      },
      {
        "prev_out":{
          "hash":"c95da3b07ef2e5ba0280f355052608a7d6bfbd82761b0826a391298b4a74ffe8",
          "n":1
        },
        "scriptSig":"304402206fb4b85dc933ea74067ee15592222d5940085ffce662efff4e038e8c7f03ef14022031c f7e8cfcd30a5bf8e7ace62f5ed7c3188c12fa6fcf8b0e357235370f1c954201 0427a2ccdc339b71fb566693906992a7ea21d036e6c1bfac9024f448dc078f3a1f5c4da514026cc 8ae3ddf8b04c13ac95b9137ec82acfae6d902bf3425626333d5",
        "address":"1DTPVDjrnErTijcA2kiF4Y5zYhLpP5faAn"
      }
    ],
    "out":[
      {
        "value":"0.02250000",
        "scriptPubKey":"OP_DUP OP_HASH160 f2abb7568576013fbe9e6d9245ed7a5acb1c46df OP_EQUALVERIFY OP_CHECKSIG",
        "address":"1P88EUL7Z92NEaHbreJ3FBhZ1YcF1EDBrb"
      },
      {
        "value":"1.20000000",
        "scriptPubKey":"OP_DUP OP_HASH160 54e386c0467794e66ef9ce76b4bbdee203a40b1b OP_EQUALVERIFY OP_CHECKSIG",
        "address":"18jrKvYbjCH9VkW6AVN9Lk99VyrYt8WNjW"
      }
    ]

Now in this JSON object, I'm seeing addresses that have no connection to what I'm trying to look for. I'm finding addresses and sent/received bitcoin transactions that aren't made by my address or even my own bitcoin client. In fact, as far as I know, these "grouped" transactions have absolutely nothing to do with me aside from being involved in the same block.

In short, I'm wondering where this:
Quote
"prev_out":{
          "hash":"80b65fb137803cc143807341eccf151eb54b662931e72aeaf59d9ec87a32ff53",
          "n":0
        },
        "scriptSig":"3045022100b05e1c0104d8b0c2034eede70bedea4eb91b3bd079f107754456d5d1c808f36602200 ddbd1bf68d559940709d9781201074237ba3fd2ee81ce727e180b306940c88201 04a8f2a5c0a60e01d5fc4da66299fe5d601f2a134f97f20d7b2a4f50b52a27fe5c942942ced1a50 8e05fb8a10838d5986fdd1e1d658bd708ea5a672befe4b28c9b",
        "address":"1LNsGtdBbb2gQecUMaRE2jPJaMfAgfXyoe"
and this:
Quote
{
        "value":"0.02250000",
        "scriptPubKey":"OP_DUP OP_HASH160 f2abb7568576013fbe9e6d9245ed7a5acb1c46df OP_EQUALVERIFY OP_CHECKSIG",
        "address":"1P88EUL7Z92NEaHbreJ3FBhZ1YcF1EDBrb"
      }

are coming from. It would be a different story if I had a way for my application to verify that these addresses are in relation to userDefinedAddress in some way, but in this case the only info I have to go off of is what JSON objects are telling me.

Receiving is not an issue. It's working completely fine, but when I've got multiple sent transactions from my address and another, my program can't tell which one is from my address and which one is from the "random" address.

Help Bitcoins by buying clothes, technology, books, etc. through people/stores that accept BTC. This will increase overall value of BTC as well as mitigate unnecessary bank transaction fees.

My address -
1EM9HGg1SEa5Bux1rVEPxGqGSfNTTc9EkC
theymos
Administrator
Legendary
*
expert
Online Online

Activity: 2492


View Profile
September 20, 2011, 04:11:37 AM
 #6

To get a transaction's sent value:
- Collect all prev_out structures for each "in" that is associated with one of your addresses
- For each prev_out that you have collected, find output number n in transaction with hash. The value of this output is the input's value. This transaction will exist either in your local transaction database (if you're using block hash stops), or earlier in the same mytransactions output.

The "in"s and "out"s that are not associated with your addresses can be ignored in your case.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!