Giter Site home page Giter Site logo

jamescoxon / nano_callback_system Goto Github PK

View Code? Open in Web Editor NEW
24.0 5.0 3.0 11.94 MB

Server and Clients for a Nano Callback Notification System - for example for use on esp32 to trigger a USB charger based on a fixed payment of Nano

Python 62.50% C++ 37.50%
nanocurrency

nano_callback_system's Introduction

Nano_Callback_System

Introduction

This is a simple system for detecting new blocks being sent to a Nano address, this is achieved by a server script which listens for new blocks via the Nano node callback and then can be setup to forward the block details over a websocket connection to listening clients. By using the node callback you can trigger an event as soon as a block is seen (and voted on) on devices and systems that don't have the capacity or the need to run a full node for example embedded systems. The system works in this order:

  • The 'client' system connects to the 'server' via a websockets connection and sends a json containing a Nano address to track.
  • The server adds this Nano address to an internal dictionary
  • The server monitors the callback and if it sees a transaction being sent to any of the addresses in its internal dictionary it then forwards this block to the client over the websockets connection.

Currently a test server is running: ws://yapraiwallet.space/call (currently does not require an API key, just use "0")

Why and Why Nano?

You don't need to hold a wallet (either full or light) on a device that just needs to initiate an action based on a Nano transaction, just need to detect the incoming block and trigger the action. Nano is ideal for this as its feeless and fast enough to do this all in real time, the user will get a very quick response back from the device/system. In theory you could do the same with any crypto however you won't get the same advantages.

Use Cases

Embedded Hardware

An internet connected embedded hardware device can connect via websockets to the callback server and monitor for activity of a particular address, this allows a low powered device not to need a full node to function.

Example 1 - a Nano controlled parking meter:

  • The local council could create a Nano address assigned to a particular device on their Nano node (they hold the private key securely)
  • A internet connected parking meter could connect to the callback server and monitor for send transactions to this address
  • A user would scan a QR code on the parking meter and send a fixed amount to the parking meters address
  • The callback server would detect the incoming send block and push this block to the parking meter
  • The parking meter checks the block and amount and if correct will trigger the parking meter to turn on
  • The council's Nano node processes the pending blocks in their own time.

Example 2 - USB charger in an airport paid for with Nano

  • Prototype is based on ESP32 Heltec WiFi board with SSD1306 OLED screen
  • User connects a device to the USB port
  • User sends a set amount of Nano to the displayed address (scan the QR code)
  • The callback server detects the incoming send block and pushes the data over the websockets connection to the ESP32
  • The device checks the block and turns on the USB port (time depends on amount of Nano sent)
  • This has been implemented, see arduino_esp32 for more infomation.

usbcharger1

Desktop Notifications

Requirements - python3.7

OS X

pip3 install pync asyncio websockets json decimal

python3 osx_client.py ws://yapraiwallet.space/call 0 xrb_1w4h9mk7nyzjdy8bt3o5u46uwrpdt6e4xaosja7yduz55jfiecmirdxhnz9z

This will run a python script that connects to the callback server and waits for a transaction to the address you've inputed.

osx_screenshot

Windows

On Windows if you install win10toast you can have pop up notifications of transactions. Installation depends on how you have installed python on your windows system (may need to execute the script using powershell).

python3 nano_iot_client.py ws://yapraiwallet.space/call 0 xrb_1w4h9mk7nyzjdy8bt3o5u46uwrpdt6e4xaosja7yduz55jfiecmirdxhnz9z

Linux

The linux python client will only show blocks in the terminal. python3 nano_iot_client.py ws://yapraiwallet.space/call 0 xrb_1w4h9mk7nyzjdy8bt3o5u46uwrpdt6e4xaosja7yduz55jfiecmirdxhnz9z

Status

Currently the system lacks any true authentication or security however this is something that will be implemented, it will be up to the service provider to decided how much they want to implement (it may be acceptable to have less security if your transactions are very small). Authentication will likely include the use of an api key but also will add the ability to actually track the account and check the hash/state blocks themselves.

nano_callback_system's People

Contributors

jamescoxon 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

Watchers

 avatar  avatar  avatar  avatar  avatar

nano_callback_system's Issues

Callback response formatting

Awesome service! About the issue, the response string contains some characters that make it difficult for JSON libraries to parse it properly:

  • some extra \n
  • \" instead of "
  • "{ instead of {
  • }" instead of }

This is the response I get:

{"hash": "A3B74654AC5BEBCA1EAD3EDEDAC4EA73A907B30CF9724E20987F0ACD4C78BB55", "account": "xrb_38j81fhhd4qn58k8sps5drn3ubqymcyx7jw5ixftg57kxdem5qbt4h3cnnng", "block": "{\n    \"type\": \"state\",\n    \"account\": \"xrb_38j81fhhd4qn58k8sps5drn3ubqymcyx7jw5ixftg57kxdem5qbt4h3cnnng\",\n    \"previous\": \"78AEF801FA0C714531DB78301B78AD0E67718A38CCECE6DFAC2B64C4190C110A\",\n    \"representative\": \"xrb_1ywcdyz7djjdaqbextj4wh1db3wykze5ueh9wnmbgrcykg3t5k1se7zyjf95\",\n    \"balance\": \"150567889999999999999999998\",\n    \"link\": \"BC692F56B8B5CDA7B325E1DA47BE2D22477C7D1BE29CF31A271F66358437C5A2\",\n    \"link_as_account\": \"xrb_3h5b7xddjfgfnyskdrgtayz4tak9hjyjqrnwyef4g9u88p45hjf4zdibbm5o\",\n    \"signature\": \"A7DABA9DD30D5FB16633F74D84CB6B506BF9322FC5271CDC7EF29524CAA3CDB48D4F5C39DBFD7E16C96651CBEAC3848621CC16DC8C0FF6F7D43C737EF01D5101\",\n    \"work\": \"80000000008b56f6\"\n}\n", "is_send": "true", "amount": "10000000000000000000000000"}

This is the response I expect:

{"hash": "A3B74654AC5BEBCA1EAD3EDEDAC4EA73A907B30CF9724E20987F0ACD4C78BB55", "account": "xrb_38j81fhhd4qn58k8sps5drn3ubqymcyx7jw5ixftg57kxdem5qbt4h3cnnng", "block": { "type": "state", "account": "xrb_38j81fhhd4qn58k8sps5drn3ubqymcyx7jw5ixftg57kxdem5qbt4h3cnnng", "previous": "78AEF801FA0C714531DB78301B78AD0E67718A38CCECE6DFAC2B64C4190C110A", "representative": "xrb_1ywcdyz7djjdaqbextj4wh1db3wykze5ueh9wnmbgrcykg3t5k1se7zyjf95", "balance": "150567889999999999999999998", "link": "BC692F56B8B5CDA7B325E1DA47BE2D22477C7D1BE29CF31A271F66358437C5A2", "link_as_account": "xrb_3h5b7xddjfgfnyskdrgtayz4tak9hjyjqrnwyef4g9u88p45hjf4zdibbm5o", "signature": "A7DABA9DD30D5FB16633F74D84CB6B506BF9322FC5271CDC7EF29524CAA3CDB48D4F5C39DBFD7E16C96651CBEAC3848621CC16DC8C0FF6F7D43C737EF01D5101", "work": "80000000008b56f6"}, "is_send": "true", "amount": "10000000000000000000000000"}

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.