quantadex / distributed_quanta_bridge

The distributed version of the quanta bridge
1 stars 0 forks source link

Notify deposit/withdrawal #56

Open quocble opened 5 years ago

quocble commented 5 years ago

Motivation

We need to let users know when the deposit has come in because it is an asynchronous behavior. Letting them know in timing manner, they can take action like trading, and build trust with the user.

Design

We'll design it as a [ Source ] -->[Process]-> [Sink] model so it decouples with the crosschain itself.

http://faculty.babson.edu/dewire/Readings/dfddiag.htm https://en.wikipedia.org/wiki/Webhook https://robinhood.engineering/thorn-easy-webhooks-for-python-82a78e170bdb https://stripe.com/docs/webhooks https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_post

The source in this case is the rest api to get the history. /api/history

The process is the code that that tracks whether it needs to send the notifications.

The sink is the location where the data is being sent to. Email is the primary sink, but we need to support push notification as well if the user uses the app. Telegram might be a good alternative way the user as well.

Pseudocode

call rest api at last_cursor
loop through data {
   check if deposit/withdrawal was previously sent
   if not sent {
       send to each sink.
       catch error properly so that this loop this not break.
       throw exception if it's fatal such as connection failure to the sinks api.
       mark the tx as sent. (type, tx, blockhash)
   }
}

The application is stateless. States information such as cursor & history data must be stored in a remote database. We can use dynamodb or postgres for this purpose.

Retry logic

https://stripe.com/docs/webhooks/best-practices#events-and-retries

Email API

Refer to SES email credentials

Push notification API

Refer to Android push notification API. Requires a push registration API.

Operations

This is to be run every 5 minutes as a job. Make this flexible so that it can be deployed on Lambda scheduled services.

Definitions:

RequestMsg {
    url    string
    events []eventType
}

ResponseMsg {
    id     string
    url    string
    events []eventType
    links  []linkDescription
}

eventType {
    name        string
    description string
}

linkDescription {
    href   string
    rel    string
    method string
}

events - Deposit.Pending
       - Deposit.Wait_For_Confirmation
       - Deposit.Confirmed
       - Deposit.Failed

       - Withdrawal.Added_To_Queue
       - Withdrawal.In_Consensus
       - Withdrawal.Submitted
       - Withdrawal.Failed
       - Withdrawal.Confirmed

webhooks {
    id string
    url string
    events []eventType
    links []linkDescription
}