filecoin-network-viz icon indicating copy to clipboard operation
filecoin-network-viz copied to clipboard

Events

Open nicola opened this issue 8 years ago • 2 comments

NewBlockMined BroadcastBlock AddAsk AddBid MakeDeal SendFile BroadcastTxn SendPayment Connected MinerJoins MinerLeaves ClientJoins ClientLeaves

nicola avatar Apr 19 '18 15:04 nicola

You'll get an HTTP endpoint that pumps out a stream of ndjson (newline delimited JSON), as such:

{"type": "NewBlockMined", "from": "mineraddr1", "to": "all", "block": "<blockCID>"}
{"type": "BroadcastBlock", "from": "mineraddr1", "to": "mineraddr2", "block": "<blockCID>"}
{"type": "AddAsk", "from": "mineraddr1", "to": "all", "tx": "<askTxCID>", "price": "<priceInFIL>", "size": "<sizeInBytes>"}
{"type": "AddBid", "from": "mineraddr1", "to": "all", "tx": "<bidTxCID>", "price": "<priceInFIL>", "size": "<sizeInBytes>"}
{"type": "MakeDeal", "from": "mineraddr1", "to": "mineraddr2", "tx": "<dealTxCID>", "price": "<priceInFIL>", "size": "<sizeInBytes>"}
{"type": "SendFile", "from": "mineraddr1", "to": "mineraddr2", "size": "<sizeInBytes>"}
{"type": "BroadcastTxn", "from": "mineraddr1", "to": "all", "tx": "<txCID>", "txfee": "<txfeeInFIL>"}
{"type": "SendPayment", "from": "mineraddr1", "to": "mineraddr2", "tx": "<txCID>", "value": "<valueInFIL>"}
{"type": "Connected", "from": "mineraddr1", "to": "mineraddr2"}
{"type": "MinerJoins", "from": "mineraddr1"}
{"type": "MinerLeaves", "from": "mineraddr1"}
{"type": "ClientJoins", "from": "mineraddr1"}
{"type": "ClientLeaves", "from": "mineraddr1"}

GUARANTEES:

  • valid, correct ndjson
  • valid, correct json objects
  • always has type key, distinguishes event type
  • always has from key, origin node
  • alwyas uses to when there are other nodes involved
  • uses "to": "all" for broadcasts (to all other nodes)
  • always puts integers in strings (parse them) because json floats suck.

NON GUARANTEES:

  • events MAY be out of order ("ClientLeaves" before a "ClientJoins").
  • events MAY include an unlisted event type (just ignore it)
  • events endpoint MAY never terminate/return (process it as a stream)

You should be able to consume it with ndjson or oboe if you wanna be fancy: http://oboejs.com/examples

jbenet avatar Apr 19 '18 20:04 jbenet

i can change it to make it nicer for you. and i can write the js browser side that parses it and emits the events for you.

jbenet avatar Apr 19 '18 20:04 jbenet