-
Notifications
You must be signed in to change notification settings - Fork 3
[proposal] redis channel API for address updates #3
Description
It would be great if one could subscribe to a Redis channel (within the same Redis DB that the rexplorer is writing to), in the following way:
$ redis-cli subscribe tfchain:standard:updates:addresses
1) "subscribe"
2) "tfchain:standard:updates:addresses"
3) (integer) 1
Such that the rexplorer can use this channel to publish update messages, so the subscriber can know when a relevant address is updated, and can get the updated data for that address if required.
The message of the <chainName>:<networkName>:updates:addresses channel would be in a well-defined public JSON format:
{
// the address that has been updated
"address": "01bb7338ff7732935e0a1bd277f49f3addd98104fef6d319bea301299397032236b38a19e0230b",
// one or multiple updates that have happened
//
// property defines the kind of property has been updated:
// * if it is a plain (GET-able) property, `value` will be defined with the new value
// * if it is a Redis Set, `member` will be defined, with for each member if its value and if it has been added or removed
// * if it is a Redis HashMap, `fields` will be defined, with for each field if its key has been removed,
// the value of a hash map field is only returned in ase the field has been added or modified
"updates": [
// balance def
{"property": "balance", "value": {
"locked": "0",
"unlocked": "12578000000000",
}},
{"property": "multisig.addresses", "members": [
{"member":"0359aaaa311a10efd7762953418b828bfe2d4e2111dfe6aaf82d4adf6f2fb385688d7f86510d37", "action": "added"}]},
]},
{"property": "outputs.locked", "fields": [
{
"key":"4e0123c579c5ce3ac28f129fd99324ded600150b93ea0b1ab5d00f199dfd5bdb",
"action": "added",
"value": {"value": "12578000000000", "condition":{...}},
},
{
"key":"defcafe53638e41afa8cbabcd7e2c7a19648ca2ecb8bbe85251c31cbcdd13d92",
"action": "modified",
"value": {"value": "428000000000", "condition":{...}},
},
{"key":"01448cb5c47303fc99e7ded364a1fb82b61e2302247006ebf613e738d384e5476eaf3fe722a3b3", "action": "removed"}]},
]}
]
}While the update should contain enough to keep the content of a subscriber up to date, it can always get the full data by getting it manually from redis, using the given address (and updated property key) to get the full property data (or even multiple properties should that be desired).
The goal of this feature is to prevent the consumer of the redis-dumped data of having to poll every 2 minutes for updates on all addresses, and instead being able to listen to updates.
On top of that Redis channels allow multiple subscribers which all get the same content. See for more information about the Pub/Sub Redis topic: https://redis.io/topics/pubsub
We could also define a channel for block updates:
$ redis-cli subscribe tfchain:standard:updates:blocks
1) "subscribe"
2) "tfchain:standard:updates: blocks"
3) (integer) 1
Such that a subscriber can keep up to date with the block height and statistics.
The message of the <chainName>:<networkName>:updates:blocks channel would be in a well-defined public JSON format:
{
"direction": "apply", // or "revert"
// only stats which have been modified are returned
"updatedStats": {
"timestamp": 1533670089,
"blockHeight": 76824,
"txCount": 77139,
"minerPayoutCount": 77062,
"minerPayouts": "76855400000001",
"coins": "695175855400000001"
}
}