Skip to content

Commit

Permalink
Merge pull request #81 from nervosnetwork/release/v0.2.2
Browse files Browse the repository at this point in the history
Release/v0.2.2
  • Loading branch information
ashchan authored May 19, 2021
2 parents 8021ac7 + cc0c36e commit 5336138
Show file tree
Hide file tree
Showing 15 changed files with 445 additions and 235 deletions.
2 changes: 1 addition & 1 deletion .ckb-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.41.0
0.42.0-rc1
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
macOS | [Tippy.dmg](https://github.com/nervosnetwork/tippy/releases/download/${{ steps.get_tag.outputs.tag }}/Tippy.dmg) | <code>TODO</code>
Linux | [tippy-linux-x64.tar.gz](https://github.com/nervosnetwork/tippy/releases/download/${{ steps.get_tag.outputs.tag }}/tippy-linux-x64.tar.gz) | <code>TODO</code>
draft: true
prerelease: true
prerelease: false
- name: Output upload URL file
run: echo "${{ steps.create_release.outputs.upload_url }}" > upload_url.txt
- name: Save upload URL file
Expand Down
285 changes: 285 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,291 @@ brew install gdb --HEAD --build-from-source
brew install ttyd
```

## API

Tippy exposes a set of RPCs in JSON-RPC 2.0 protocols for controlling a devchain.

It also proxies API calls to the active running devchain for transparent CKB interactions.

The URL of Tippy RPC is <code>http://localhost:5000/api</code>.

### CKB RPCs

For CKB RPCs, simply call any API method with Tippy API URL. For example:

```
echo '{
"id": 2,
"jsonrpc": "2.0",
"method": "get_tip_block_number",
"params": []
}' \
| tr -d '\n' \
| curl -H 'content-type: application/json' -d @- \
http://localhost:5000/api
```

See [CKB JSON-RPC doc](https://docs.nervos.org/docs/reference/rpc) for more information.

### Tippy RPCs

#### Method `create_chain`
* `create_chain({assembler_lock_arg, genesis_issued_cells})`
* `assembler_lock_arg`(optional): Lock arg for block assembler (miner address).
* `genesis_issued_cells`(optional): An array of genesis issued cells. See example for the structure.
* result: `{ id, name }`

Create a devchain and set it as current active chain.

**Example**

Request

{
"id": "1",
"jsonrpc": "2.0",
"method": "create_chain",
"params": [
{
"assembler_lock_arg": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d8",
"genesis_issued_cells": [
{
"capacity": "0x5af3107a4000",
"lock": {
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
"args": "0xf2cb132b2f6849ef8abe57e98cddf713bb8d71cb",
"hash_type": "type"
}
}
]
}
]
}

Response

{
"jsonrpc": "2.0",
"id": "1",
"result": {
"id": 4,
"name": "CKB devchain"
}
}

#### Method `start_chain`

* `start_chain()`
* result: `"ok"`

Start the current active chain.

**Example**

Request

{
"id": "1",
"jsonrpc": "2.0",
"method": "start_chain",
"params": []
}

Response

{
"jsonrpc": "2.0",
"id": "1",
"result": "ok"
}

#### Method `stop_chain`

* `stop_chain()`
* result: `"ok"`

Stop the current active chain if it's running.

**Example**

Request

{
"id": "1",
"jsonrpc": "2.0",
"method": "stop_chain",
"params": []
}

Response

{
"jsonrpc": "2.0",
"id": "1",
"result": "ok"
}

#### Method `start_miner`

* `start_miner()`
* result: `"ok"`

Start the default miner.

**Example**

Request

{
"id": "1",
"jsonrpc": "2.0",
"method": "start_miner",
"params": []
}

Response

{
"jsonrpc": "2.0",
"id": "1",
"result": "ok"
}

#### Method `stop_miner`

* `stop_miner()`
* result: `"ok"`

Stop the current running default miner.

**Example**

Request

{
"id": "1",
"jsonrpc": "2.0",
"method": "stop_miner",
"params": []
}

Response

{
"jsonrpc": "2.0",
"id": "1",
"result": "ok"
}

#### Method `mine_blocks`

* `mine_blocks(number_of_blocks)`
* result: `"Wait for blocks to be mined."`

Mine `number_of_blocks` blocks at the interval of 1 second.

**Example**

Request

{
"id": "1",
"jsonrpc": "2.0",
"method": "mine_blocks",
"params": [3]
}

Response

{
"jsonrpc": "2.0",
"id": "1",
"result": "Wait for blocks to be mined."
}

#### Method `revert_blocks`

* `revert_blocks(number_of_blocks)`
* result: `"Reverted blocks."`

Mine `number_of_blocks` blocks at the interval of 1 second.

**Example**

Request

{
"id": "1",
"jsonrpc": "2.0",
"method": "revert_blocks",
"params": [3]
}

Response

{
"jsonrpc": "2.0",
"id": "1",
"result": "Reverted blocks."
}

#### Method `ban_transaction`

* `ban_transaction(tx_hash, type)`
* `tx_hash`: Tx hash of the transaction.
* `type`: Deny type, `propose` or `commit`.
* result: `"Added to denylist."`

Add a tx to denylist.

**Example**

Request

{
"id": "1",
"jsonrpc": "2.0",
"method": "ban_transaction",
"params": ["0x9a0580274e9921e04e139214b58ffc60df1625055ab7806ee635b56d329d7732", "propose"]
}

Response

{
"jsonrpc": "2.0",
"id": "1",
"result": "Added to denylist."
}


#### Method `unban_transaction`

* `unban_transaction(tx_hash, type)`
* `tx_hash`: Tx hash of the transaction.
* `type`: Deny type, `propose` or `commit`.
* result: `"Removed from denylist."`

Remove a tx from denylist.

**Example**

Request

{
"id": "1",
"jsonrpc": "2.0",
"method": "unban_transaction",
"params": ["0x9a0580274e9921e04e139214b58ffc60df1625055ab7806ee635b56d329d7732", "propose"]
}

Response

{
"jsonrpc": "2.0",
"id": "1",
"result": "Removed from denylist."
}

## Contributing

1. Fetch the codebase: `git clone https://github.com/nervosnetwork/tippy.git`
Expand Down
39 changes: 19 additions & 20 deletions src/Tippy.Ctrl/Process/BinariesInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ namespace Tippy.Ctrl.Process
{
internal class BinariesInfo
{
internal string Info { get; private set; } = "";
internal bool HasDebuggerDeps { get; private set; } = false;

internal string Info { get; private set; } = "";
internal bool HasDebuggerDeps { get; private set; } = false;
readonly List<string> binaries = new() { "ckb", "ckb-indexer", "ckb-debugger"/*, "ckb-cli"*/ };

internal void Refresh()
Expand Down Expand Up @@ -41,32 +40,32 @@ internal void Refresh()
}

if (!OperatingSystem.IsWindows())
{
{
RefreshDebuggerDeps();
}
}

void RefreshDebuggerDeps()
{
HasDebuggerDeps = true;
// BUGBUG: .Net won't find commands on M1 Mac which has homebrew location at `/opt/homebrew/bin`.
void RefreshDebuggerDeps()
{
HasDebuggerDeps = true;
// BUGBUG: .Net won't find commands on M1 Mac which has homebrew location at `/opt/homebrew/bin`.
foreach (var dep in new List<string>() { "gdb", "ttyd" })
{
try
{
System.Diagnostics.Process process = new();
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = dep;
process.StartInfo.Arguments = "--version";
process.StartInfo.WorkingDirectory = Core.Environment.GetAppDataFolder();
process.Start();
process.WaitForExit();
try
{
System.Diagnostics.Process process = new();
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = dep;
process.StartInfo.Arguments = "--version";
process.StartInfo.WorkingDirectory = Core.Environment.GetAppDataFolder();
process.Start();
process.WaitForExit();
}
catch
{
HasDebuggerDeps = false;
{
HasDebuggerDeps = false;
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Tippy.Ctrl/Process/CommandProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class CommandProcess

internal CommandProcess(ProcessInfo processInfo) => ProcessInfo = processInfo;

abstract protected void Configure();
protected abstract void Configure();

public bool IsRunning
{
Expand Down
12 changes: 6 additions & 6 deletions src/Tippy.Ctrl/Process/Debugger/DebuggerProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace Tippy.Ctrl.Process.Debugger
{
internal class DebuggerProcess : CommandProcess
{
private string ScriptHash;
private string ScriptGroupType;
private string TxFilePath;
private string IoType;
private int IoIndex;
private string? BinaryPath;
private readonly string ScriptHash;
private readonly string ScriptGroupType;
private readonly string TxFilePath;
private readonly string IoType;
private readonly int IoIndex;
private readonly string? BinaryPath;

public DebuggerProcess(ProcessInfo info, string scriptGroupType, string scriptHash, string txFilePath, string ioType, int ioIndex, string? binaryPath = null) : base(info)
{
Expand Down
Loading

0 comments on commit 5336138

Please sign in to comment.