/ archive / Web3.js_and_Jail.md
Web3.js_and_Jail.md
 1  # Jail
 2  
 3  It is a cells manager. It keeps track of all cells created during the
 4  application execution. It also creates and initializes cells with
 5  JavaScript code.
 6  
 7  # Cell
 8  
 9  A cell is a JavaScript execution context with a few utilities. Each cell
10  is initialized by `Jail` using `Jail.Parse` method.
11  
12  Cell’s JS execution context is initialized with `web3`
13  (https://github.com/ethereum/web3.js) and any JS code provided to
14  `jail.Parse`.
15  
16  `web3` is initialized with a provider which is called `jeth` and is
17  constructed in Go code in `jail.Parse`. Thus, it defines a bridge
18  between `web3` and `status-go`.
19  
20  `jeth`, as a provider, must implement `send` and `sendAsync` methods.
21  Both of them are registered in `registerHandlers` function. Effectively,
22  `jeth.send` calls `jail.Send` while `jeth.sendAsync` calls `jail.Send`
23  as well, but in a goroutine. The result is returned via a callback.
24  
25  For instance, let’s take a look at what happens when one executes a
26  synchronous call `web3.eth.blockNumber`:
27  
28  1.  `web3` translates this call to a JSON-RPC method `eth_blockNumber`,
29  2.  Provider is used to make a HTTP or IPC call: `jeth.send`,
30  3.  `jail.Send` is effectively called as it’s in `jeth.send`
31      implementation,
32  4.  `rpc.Client.CallContext` is called with a method and params,
33  5.  Response is returned back to the JS code.