Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API exposure - RESTful API and socket.io-based push Events #280

Closed
wants to merge 10 commits into from
Closed

API exposure - RESTful API and socket.io-based push Events #280

wants to merge 10 commits into from

Conversation

ezdac
Copy link
Contributor

@ezdac ezdac commented Dec 6, 2016

this provides the initial ideas of the API-exposure.

what this PR implements:

  • @expose decorated methods can be called via http-requests (REST-style URLs)
  • return-data from synchronous methods is included in the respond message "result": data
  • asynchronous methods provide a callback-id in their respond message, but "result": null
  • the callbacks for asynchronous methods are automatically generated in the Dispatcher-class
  • the callback-id is later on used to publish an event to a websocket (socket.io protocol)

what is still TO DO:

  • all relevant state changes (incoming transfers, channel closing, etc) trigger such an event, which then gets passed to the connected client's websocket

closes #10
related #207

@ezdac ezdac mentioned this pull request Dec 15, 2016
5 tasks
@hackaugusto
Copy link
Contributor

Should we merge this PR or wait for the changes as defined in #10 ?

@ezdac
Copy link
Contributor Author

ezdac commented Dec 19, 2016

let's wait for the changes in #10 , I will push to this PR directly and rename it accordingly

This is the server for the API exposure.
All methods marked by the @expose decorator will be available
via http-requests at the given REST endpoint,
once the Dispatcher is initialized and the server is running.
Synchronous methods will return their return-value immediately
in the request's respond message.
Asynchronous methods will not return their return value,
but rather a unique callback-id, that will later be used
in a 'rpc_response' Event via socket.io for evaluation.

The response is structured like this:

{
    callback_id: value or None if Synchronous
    method= str (the methods name)
    result= value or None if Asynchronous
}

Clients should also connect to the websocket
that is used for push-Notifications ('Events')
via the socket.io protocol.
Without the connection to the socket,
asynchronous calls over http-requests will be initiated,
but the client has no knowledge about the success of the call.
Also externally initiated state-changes such as channel-opening
or incoming transfers will not be observed by the client,
if he doesn't want to pull this information constantly.

Events are structured like this:

    Event:      'rpc_response'
    namespace:  '/'
    data:       {
                    callback_id: <int>,
                    procedure: <str>,
                    status: <bool>
                }

closes #10
related issue: #207
from ethereum.transactions import Transaction
from ethereum.utils import denoms, int_to_big_endian, encode_hex, normalize_address
<<<<<<< 4c31f51f14f0b23ec72f06c4605e9944fbe60a20
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: don't get distracted while rebasing


log = slogging.get_logger(__name__) # pylint: disable=invalid-name

DEFAULT_REVEAL_TIMEOUT = 30
DEFAULT_SETTLE_TIMEOUT = DEFAULT_REVEAL_TIMEOUT * 20

EventListener = namedtuple('EventListener', ('event_name', 'filter_', 'translator'))
Copy link
Contributor Author

@ezdac ezdac Jan 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful: this and every related peace of code didn't make it in my pull-rebase from origin/master (somehow).
If I cannot rewind this easily, it has to be cherrypicked and reimplemented again!

@LefterisJP
Copy link
Contributor

Superseded by both #388 and #408

@LefterisJP LefterisJP closed this Mar 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raiden RESTful API
3 participants