Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

Nitro Examples

Nitro Protocol Examples

Nitro RPC

Those application leverage the NitroRPC Asynchronous protocol

NitroRPC Request

In this example, the client is calling a method named "subtract" with positional parameters:

{
"req": [1001, "subtract", [42, 23], 1741344819012],
"sig": "0xa0ad67f51cc73aee5b874ace9bc2e2053488bde06de257541e05fc58fd8c4f149cca44f1c702fcbdbde0aa09bcd24456f465e5c3002c011a3bc0f317df7777d2"
}
  • req: rpc message payload [request_id, method, params, ts]
  • sig: payload client signature

The millisecond timestamp was returned previously from the server, it is used as a height for proof of history

NitroRPC Response Example

For a successful invocation, the server might respond like this:

{
"res": [1001, "subtract", [19], 1741344819814],
"sig": "0xd73268362b04516451ec52170f5c8ca189d35d9ac5e9041c156c9f0faf9aebd2891309e3b2b5d8788578ab3449c96f7aa81aefb25482b53f02bac42c65f806e5"
}
  • res: rpc message payload [request_id, method, params, ts]
  • sig: payload server response signature

ts: server response with latest timestamp

NitroCalc

Objectives of the prototype is to define opening, checkpoint, dispute and finalize of channel.

State storage example

-- Table to store RPC messagesCREATETABLErpc_states (
id SERIALPRIMARY KEY,
ts BIGINT,
req_id INTEGERNOT NULL,
method VARCHAR(255) NOT NULL,
params JSONB NOT NULL,
client_sig VARCHAR(128),
server_sig VARCHAR(128),
UNIQUE (request_id)
);

TODO:

  • Create AppData in solidity
  • Create NitroApp to validate states including AppData
  • Create Protobuf description of NitroRPC Request / Response
  • Include NitroRPC types into gRPC and generate client and server
  • Implement methods: add(int), sub(int), mul(int), mod(int) starting from 0
  • Create a simplified NitroCalc Service using sqlite for state (in go)
  • Finally, we can import nitro pkg, and client or server can pack and sqlite state and call nitro of on-chain channel operations.

Markdown Table Example

IDTimestamp (ts)MethodRequest ArgumentsResponse Arguments
10021741344820000open_channel[100][chanId]
10031741344821000add[50][50]
10041741344822000mul[2][100]
10051741344823000sub[10][90]
10061741344820000close_channel[nitro_state][mutually_signed_state]

And create a unhappy case

NitroBet

An idea of an app with external event, could be Alice and Bob start both with $100 they continuous add money to their bet and a outcome of the bet would determine the winner

To explore

About

Nitro Protocol Examples

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages