Giter VIP home page Giter VIP logo

neon-wallet-db's Introduction

Neon Light Wallet Database API

This code runs a database for Neon that mirrors the NEO blockchain and serves several APIs that don't exist anywhere else (for example, an API to get claims and the full transaction history associated with an address).

STATUS: MainNet and TestNet are both fully synced and auto-updating.

How does this work?

This API and a MongoDB mirror of the Neo blockchain live on Heroku. The public API definition is in api/api.py. Code that manages keeping the database in sync with public nodes is in clock.py and api/blockchain.py.

APScheduler polls the blockchain every 5 seconds (to keep blocks up to date) and executes a repair process (for any potential missing blocks) every 5 minutes. The polling and repair logic are both executed by seperate worker processes under the Python rq library to avoid overloading the API. Both the number of wep api servers and the number of workers processing incoming transaction data can be scaled arbitrarily.

Overview of API

All APIs work on both MainNet (https://api.neonwallet.com) and TestNet (https://testnet-api.neonwallet.com).

Balance data

Given an address, return the current balance of NEO and GAS, as well as a list of transaction ids and amounts for unspent assets: https://api.neonwallet.com/v1/address/balance/{address}. Knowing these unspent transaction ids is important for light wallets because wallets need them to send assets!

For example:

curl http://testnet-api.neonwallet.com/v2/address/balance/ANrL4vPnQCCi5Mro4fqKK1rxrkxEHqmp2E

This will produce:

{
  "GAS": {
    "balance": 64.00325360000001,
    "unspent": [
      {
        "index": 1,
        "txid": "cbd5151931d5d49a209f41a6a012421573bb3e14fb3558bb649279c07499fdd3",
        "value": 8.0
      },
      {
        "index": 0,
        "txid": "4a38a701099bc61ec38bca03477a2e88d9077267a66062d675105df32ef9924c",
        "value": 10.0
      },
      ...
    ]
  },
  "NEO": {
    "balance": 55,
    "unspent": [
      {
        "index": 1,
        "txid": "9d3658842eb6e61f0913f28689f7977d48e931005c92fde4664dcdde8ea5a745",
        "value": 7
      },
      {
        "index": 1,
        "txid": "d999592d08d6059da23f9ec743574e9cf00d1411c187c96869dfd32decf79a2f",
        "value": 46
      },
      {
        "index": 0,
        "txid": "e391f7bb82a746abb93232d260926fff45c6ade4975dcae2dbd0002f302bdb77",
        "value": 1
      },
      ...
    ]
  },
  "address": "AdWDaCmhPmxgksr2iTVuGcLcncSouV6XGv",
  "net": "TestNet"
}

Transaction history

Get a record of how an account balance has changed over time across all transactions: http://testnet-api.neonwallet.com/v1/address/history/{address}

For example:

curl http://testnet-api.neonwallet.com/v2/address/history/ALpwWoxKLwbfCTkRpK2iXrXpaMHgWGcrDV

This produces:

{
  "address": "ALpwWoxKLwbfCTkRpK2iXrXpaMHgWGcrDV",
  "history": [
    {
      "GAS": 0.0,
      "NEO": 5,
      "block_index": 336090,
      "txid": "b7c998aabe80533b80d70218b6349f82c9f359bc291bc74b17169f1c4e8d2353"
    },
    {
      "GAS": 0.0,
      "NEO": 1,
      "block_index": 336076,
      "txid": "0cb30929530fa4b941f809b1f16e87124d22695fab9e339414812a06aa8b6867"
    },
    {
      "GAS": 0.0,
      "NEO": -2,
      "block_index": 336070,
      "txid": "84835bedd663672de4ad94950cbe51670a83d16cc996f011f704967a0d8ef14d"
    },
    {
      "GAS": 0.00366,
      "NEO": 0,
      "block_index": 336016,
      "txid": "ded12a239c828b6849606ca7f4f3a31b1048dec6bfc0da803374bcea68c7a1b0"
    },
    {
      "GAS": 0.0,
      "NEO": 0,
      "block_index": 336014,
      "txid": "0cde0c3ca9c7f8fe58193aca4f72be603c6422254e3e2e8edaeaab99ca018ba5"
    },
    ...,
    {
      "GAS": 10000.0,
      "NEO": 0,
      "block_index": 285873,
      "txid": "4787b4d5f02765b5d81c3b381e591aab6ea190b561ba4d89ab64c794c3d946f9"
    }
  ],
  "net": "TestNet"
}

Transaction data

Get detailed information about a transaction: http://api.neonwallet.com/v1/transaction/{txid}. This is identical to the structure returned by the Node CLI except that ContractTransactions have been augmented by vin_verbose with extra information about input transactions.

For example:

curl http://testnet-api.neonwallet.com/v2/transaction/ec4dc0092d5adf8cdf30eadf5116dbb6f138b2e35ca2f1a26d992d69388e0b95

This produces:

{
  "_id": {
    "$oid": "59700381048252991e506558"
  },
  "attributes": [],
  "block_index": 285873,
  "net_fee": "0",
  "scripts": [
    {
      "invocation": "40bcd8a5787e1027cda3cf03e9d1797bed93363ed3c3ff3b6162c0863ed1b5ad50b932a6cea6bd7ae01b6440dc3b509422614742891f0699454988c1b459c84330",
      "verification": "2102028a99826edc0c97d18e22b6932373d908d323aa7f92656a77ec26e8861699efac"
    }
  ],
  "size": 262,
  "sys_fee": "0",
  "txid": "ec4dc0092d5adf8cdf30eadf5116dbb6f138b2e35ca2f1a26d992d69388e0b95",
  "type": "ContractTransaction",
  "version": 0,
  "vin": [
    {
      "txid": "f584373e6a98a88a13b3a61423550063425b6ae2a95dc6b87b2e1e3f49fb3b98",
      "vout": 1
    }
  ],
  "vin_verbose": [
    {
      "address": "ALq7AWrhAueN6mJNqk6FHJjnsEoPRytLdW",
      "asset": "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b",
      "n": 1,
      "txid": "f584373e6a98a88a13b3a61423550063425b6ae2a95dc6b87b2e1e3f49fb3b98",
      "value": "9746"
    }
  ],
  "vout": [
    {
      "address": "ALpwWoxKLwbfCTkRpK2iXrXpaMHgWGcrDV",
      "asset": "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b",
      "n": 0,
      "value": "900"
    },
    {
      "address": "ALq7AWrhAueN6mJNqk6FHJjnsEoPRytLdW",
      "asset": "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b",
      "n": 1,
      "value": "8846"
    }
  ]
}

Claiming GAS

Current block explorers do not provide a list of the available claims for an address. The light wallet API supports this through: http://api.neonwallet.com/v1/address/claims/{address}

For example:

curl http://testnet-api.neonwallet.com/v1/address/claims/AJ3yzTLc5jebUskHtphKi1rb2FNoZjbpkz

This produces a json object where claims provides a list of available GAS claims and total_claim provides the total amount of GAS available to claim. These claims are denominated in units of GAS * 100000000 to support the format required by the network protocol. So you can divide these numbers by 100000000 to get the number of GAS the account would actually receive. For each claim object, value corresponds to the number of Neo that generated the claim, start and end correspond to the starting and ending block heights over which the GAS were generated, claim gives the amount of GAS to claim (divided by 100m), txid provides the id of the transaction that generates the claim, sysfee describes the additional network fees you will receive as part of the claim, and index provides the vout index for that transaction (necessary to submit a claim over the network).

For now, this API only supports "available claims". For more on this, see the documentation.

{
  "address": "AJ3yzTLc5jebUskHtphKi1rb2FNoZjbpkz",
  "claims": [
    {
      "claim": 23488,
      "end": 285098,
      "index": 0,
      "start": 283630,
      "sysfee": 0,
      "txid": "f07c0e6a867c7545dd8afdb49c287b368dec8056414dc0eea43c79fa7451bd49",
      "value": 2
    },
    {
      "claim": 192,
      "end": 285116,
      "index": 0,
      "start": 285104,
      "sysfee": 0,
      "txid": "c18bc2f861645f17eeb1adac441b22b354fe9967745da90eb86247226e553ab2",
      "value": 2
    },
    {
      "claim": 1200,
      "end": 285229,
      "index": 0,
      "start": 285154,
      "sysfee": 0,
      "txid": "26512df25fd21c0b491c01de6e7f07f801230a7e8357f249618f2f92c9e9691a",
      "value": 2
    },
    {
      "claim": 48,
      "end": 285239,
      "index": 0,
      "start": 285236,
      "sysfee": 0,
      "txid": "fc5c7bd07e80d45f1bc48a4bbeac54f46d89cfb3b4c1c670122eb41a9b0e80e6",
      "value": 2
    }
  ],
  "net": "TestNet",
  "past_claims": [],
  "total_claim": 24928
}

Node Status

See the status and block heights of nodes on the network: http://api.neonwallet.com/v1/network/nodes

For example:

{
  "net": "TestNet",
  "nodes": [
    {
      "block_height": 336401,
      "status": true,
      "url": "http://seed1.neo.org:20332"
    },
    {
      "block_height": 336401,
      "status": true,
      "url": "http://seed2.neo.org:20332"
    },
    {
      "block_height": 336401,
      "status": true,
      "url": "http://seed3.neo.org:20332"
    },
    {
      "block_height": 336401,
      "status": true,
      "url": "http://seed4.neo.org:20332"
    },
    {
      "block_height": 336401,
      "status": true,
      "url": "http://seed5.neo.org:20332"
    },
    {
      "block_height": 336401,
      "status": true,
      "url": "http://seed8.antshares.org:20332"
    }
  ]
}

neon-wallet-db's People

Contributors

ejhfast avatar evgenyboxer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neon-wallet-db's Issues

Improving Transaction History Struct

Problem: Currently the transaction history struct is not well defined.

  • Each entry can represent either a gas or neo transaction (Ok if we only have neo or gas, but bad if we have more assets)
  • No timestamp, although block index is a useful trait most wallets would likely prefer to have a human readable date for transaction time
  • No Transaction type (Differentiating between claim and send)
  • No attached addresses

Without these data fields I have to manually query for each transaction again using an RPC command to get additional details

Solution: Remodel each entry in the struct to look like this

{ transactionHistory: [
	entry : {
		blockIndex: Int
		timestamp: Int
		transactionType: String
		assetID: String
		amount: Double
		senderAddress: String
		recieverAddress: String
		transactionID: String
	}]	
}

This allows for a more detailed history, and will be easier to use in light clients. Also I'm wondering how this will work once RPX token is introduced

How to use neon-wallet-db with private db?

Hi everybody, Please help me out.

I tried connect to private net, but follwing error:

16:04:53 clock.1    |  Traceback (most recent call last):
16:04:53 clock.1    |    File "/Users/gyo/.anyenv/envs/pyenv/versions/3.6.5/lib/python3.6/site-packages/apscheduler/executors/base.py", line 125, in run_job
16:04:53 clock.1    |      retval = job.func(*job.args, **job.kwargs)
16:04:53 clock.1    |    File "clock.py", line 24, in syncBlockchain
16:04:53 clock.1    |      currBlock = getBlockCount(nodeAPI)["result"]
16:04:53 clock.1    |    File "/Users/gyo/dev/neo-hack/neon-wallet-db/api/blockchain.py", line 28, in getBlockCount
16:04:53 clock.1    |      return rpcRequest("getblockcount", [], nodeAPI)
16:04:53 clock.1    |    File "/Users/gyo/dev/neo-hack/neon-wallet-db/api/blockchain.py", line 17, in rpcRequest
16:04:53 clock.1    |      return requests.post(nodeAPI, json={"jsonrpc": "2.0", "method": method, "params": params, "id": 0}, timeout=5).json()
16:04:53 clock.1    |    File "/Users/gyo/.anyenv/envs/pyenv/versions/3.6.5/lib/python3.6/site-packages/requests/api.py", line 112, in post
16:04:53 clock.1    |      return request('post', url, data=data, json=json, **kwargs)
16:04:53 clock.1    |    File "/Users/gyo/.anyenv/envs/pyenv/versions/3.6.5/lib/python3.6/site-packages/requests/api.py", line 58, in request
16:04:53 clock.1    |      return session.request(method=method, url=url, **kwargs)
16:04:53 clock.1    |    File "/Users/gyo/.anyenv/envs/pyenv/versions/3.6.5/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
16:04:53 clock.1    |      resp = self.send(prep, **send_kwargs)
16:04:53 clock.1    |    File "/Users/gyo/.anyenv/envs/pyenv/versions/3.6.5/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
16:04:53 clock.1    |      r = adapter.send(request, **kwargs)
16:04:53 clock.1    |    File "/Users/gyo/.anyenv/envs/pyenv/versions/3.6.5/lib/python3.6/site-packages/requests/adapters.py", line 490, in send
16:04:53 clock.1    |      raise ConnectionError(err, request=request)
16:04:53 clock.1    |  requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine("±Ý\x00\x00version\x00\x00\x00\x00\x00'\x00\x00\x00\x9e+\x96\x87\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00<¿ÉZmOÜÓ\x0c \x0b/NEO:2.7.3/\x8cN\x00\x00\x01",))

My env

# install neo-privatenet-docker, neo-python and run it,  and, curl is successed.
$ curl -X POST http://127.0.0.1:20332 -d '{"jsonrpc":"2.0","method":"getblockcount", "id":1}'
{"jsonrpc": "2.0", "id": 1, "result": 464}

Gas never arrived after sending!

Hello, hope this is the right place for this question.
I'm using the Neon Wallet to generate GAS. I sent some last week and it still hasn't arrived.
When I look in the NEO Tracker the transaction ID is there but it says "Unspent"
How do I get this to go through?
Thanks for any help!

Address transactions response only returns up to 25 transaction records.

Informed and forward from neon-js Issue 23.

The http://testnet-api.neonwallet.com/v2/address/history/{address} API endpoint only returns up to 25 transaction records regardless of numbers of transactions within an address. Method also doesn't seems to take optional parameters for pagination supports.

To replicate:

  • Attempt to fetch transaction details of address ALfnhLg7rUyL6Jr98bzzoxz5J7m64fbR4s from TESTNET by request to http://testnet-api.neonwallet.com/v2/address/history/ALfnhLg7rUyL6Jr98bzzoxz5J7m64fbR4s.
  • Notice the result array length at 25, despite https://neoscan-testnet.io/address/ALfnhLg7rUyL6Jr98bzzoxz5J7m64fbR4s shows there are 1000+ transaction records.

Websockets?

Any chance of websocket support for balance changes?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.