Hive Developer logo

Hive Developer Portal

RB: Edit Content Patching

Patching changes to a post on Hive.

Full, runnable src of Edit Content Patching can be downloaded as part of: tutorials/ruby (or download just this tutorial: devportal-master-tutorials-ruby-12_edit_content_patching.zip).

Intro

This tutorial will show a technique for efficiently editing a post by only broadcasting changes to the post body.

Also see:

Script

edit_content_patching.rb

This script will take an existing post and append a new line by broadcasting a comment operation containing a diff instruction. This instruction will tell the blockchain to append new content to the end of the body of the original comment.

Because this is a live example, we set broadcast to false so that it only runs if you modify the example and set broadcast to true.

As stated earlier, you will need to change broadcast to true. You can also set other values to test this script on other post:

To Run

First, set up your workstation using the steps provided in Getting Started. Then you can create and execute the script (or clone from this repository):

You can launch a local testnet, with port 8090 mapped locally to the docker container:

docker run -d -p 8090:8090 inertia/tintoy:latest

For details on running a local testnet, see: Setting Up a Testnet

git clone https://gitlab.syncad.com/hive/devportal.git
cd devportal/tutorials/ruby/12_edit_content_patching
bundle install
ruby edit_content_patching.rb

Example Output

Changes:
@@ -26,8 +26,26 @@
  edited)
+%0AAppended content.
{
  "jsonrpc": "2.0",
  "result": {
    "id": "f327acc1c51d907a9ba9bfac70e6fc9e99ab2865",
    "block_num": 23035803,
    "trx_num": 0,
    "expired": false
  },
  "id": 1
}

The response we get after broadcasting (if enabled) the transaction gives us the transaction id (f327acc...), block number (22867626), and the transaction number of that block (0).