Terminal users access InfoChain

The terminal users can query or modify data stored in blockchain storage under an InfoChain group, according to InfoChain access interface, via one InfoChain node network.

Suppose the terminal user is a website developer, who want to use InfoChain as the data storage, he has known a node network name and related password from the node creator. Then he need to choose or develop a proper message transfer app to connect into InfoChain node network.

InfoChain has provided two message transfer apps to connect terminal users and InfoChain nodes.

Deliver

Terminal user can download Deliver from the menu Resource > Download, copy it to website sever or other PC that in the same intranet domain of the website server. There are two versions of Delivers, for linux(Ubuntu) and windows deployment.

There is a need to configure some parameters when launching for the first time, :

-n: the name of InfoChain node to connect to

-p: password of the node network

-P: Deliver listen port, if not assigned, listen post is 4321


For example, ./Deliver -n MyNodeABC -p 12345678

means this Deliver will listen on default port 4321, connect to node network which named as MyNodeABC, password is 12345678.

To run Deliver under linux, user must have administrator authority, and type in system password when it is mentioned to install n2n app. To run Deliver under windows, need to start a command line processor as administrator.

The terminal program's network administrator needs to configure firewall rules for Deliver to open UDP port 9999, and TCP ports 15793, 15794, and 15799.

CommDeliver

This app is for user who wish to try InfoChain function, or difficult to deploy Deliver. User no need to download and deploy this app to his device, just need to put some parameters in request. The following samples will provide more details.

Note: CommDeliver is a public message deliver, data will be transfered to a server with public URL, which other users can also access. For efficiency and security reason, developer should avoid using CommDeliver for official usage.


Now a developer can write his source code to access InfoChain. We provide some JavaScript samples to explain how to create InfoChain request.

Sample 1. Query user record via CommDeliver

<head>

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>:

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/sha256.js"></script>

<script src="https://InfoChain.link/Interface/js/Deliver.js"></script>

</head>

<script>

function CreateUser()

{

var chain=new ChainRequest(“192.168.1.146",”4330”);

//var chain=new ChainRequest();

//chain.SetPhpServerFolder("./php");

var requestItems={};

requestItems[“Func”]=”CreateUser”;

requestItems[“UserName”]=”TestUser2”;

requestItems[“Password”]=”12345678”;

//requestItems[“PassHash”]=”XXXXX”;

chain.Request(requestItems,handleCreateResult,handleCreateFail);

}

function handleCreateResult(result_string)

{

alert(result_string);

}

function handleCreateFail(error_string)

{

alert(error_string);

}

</script>

The upper sample first creates a CommChainRequest object,which was defined in CommDeliver.js( the rest js files are required by CommDeliver.js ). Then defines a map requestItems, to query self ( with username “TestUser1” and password “11223344”) information, via node network with node name “MyTestNode1” and network password “password”.The items Password will be converted to hash string named “PassHash” in CommDeliver.js. All map items are mandatory in this request. The query is handled via function

chain.Request(items, handleQueryResult, handleQueryFail)

In this function, the first parameter request map is mandatory, rest parameters are optional.

HandleQueryResult is the call back function when query success, it’s format is

function HandleQueryResult(result_string, reqItems)

here result_string is JSON format query result string, reqItems is optional, is copy of requestItems in chain.Request() call.

HandleQueryFail is the call back function when query fail, it’s format is

function HandleQueryFail(error_string, reqItems)

here error_string is error description string, reqItems is optional, is copy of requestItems in chain.Request() call.

Sample 2, Create user record via Deliver

<head>

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>:

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/sha256.js"></script>

<script src="https://InfoChain.link/Interface/js/CommDeliver.js"></script>

</head>

<script>

function QueryUser()

{

var chain=new CommChainRequest();

var requestItems={};

requestItems[“Func”]=”QueryUser”;

requestItems[“UserName”]=”TestUser1”;

requestItems[“Password”]=”11223344”;

//requestItems[“PassHash”]=”XXXXX”;

requestItems[“NodeName”]=”MyTestNode1”;

requestItems[“NetPassword”]=”password”;

chain.Request(requestItems,HandleQueryResult,HandleQueryFail);

}

function HandleQueryResult(result_string)

{

alert(result_string);

}

function HandleQueryFail(error_string)

{

alert(error_string);

}

</script>

The upper sample first creates a ChainRequest object, which was defined in Deliver.js. Then defines a map requestItems, to create a user (with username “TestUser2” and password “12345678”) via deployed Deliver app.

The calling process and parameters definitions are similar as sample 1, except:

I. ChainRequest constructor format is ChainRequest(DeliverIP, DeliverPort), DeliverIP and DeliverPort are optional paratemers, means Deliver App’s IP and port, if them are not defined, means the ChainRequest object will connect to local host Deliver via port 4321.

II. If this website is https website, the https requests to Deliver are required being converted to http request to avoid the browser blocking it. Developer can download an auxiliary php file from the menu Resource > Download and deploy it to website server. By default, ChainRequest object supposes that ChainRequest.php is stored in the same folder as current webpage, if it is not stored there, need to call SetPhpServerFolder(phpPath) to assign the php store folder.

III. No need to define NodeName and NetPassword in request any more, because they are defined in Deliver.

Sample 3. Create record

<head>

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>:

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/sha256.js"></script>

<script src="https://InfoChain.link/Interface/js/Deliver.js"></script>

</head>

<script>

function CreateRecord()

{

var chain=new ChainRequest(“192.168.1.146",”4330”);

//var chain=new ChainRequest();

//chain.SetPhpServerFolder("./php");

var requestItems={};

requestItems[“Func”]=”CreateRecord”;

requestItems[“UserName”]=”TestUser2”;

requestItems[“Password”]=”12345678”;

//requestItems[“PassHash”]=”XXXXX”;

requestItems[“RecordType”]=”Private”;

requestItems[“RelatedUser”]=”TestUser1”;

requestItems[“Commodity_Name”]=”BookA”;

requestItems[“Commodity_ID”]=”10458998374”;

requestItems[“Commodity_Price”]=”$30”;

requestItems[“Sell_count”]=”3”;

requestItems[“Sell_time”]=”2023-06-21 13:30:40”;

chain.Request(requestItems,handleCreateResult,handleCreateFail);

}


function handleCreateResult(result_string)

{

alert(result_string);

}


function handleCreateFail(error_string)

{

alert(error_string);

}

</script>

The upper sample means to create a private record by User TestUser2, to store the information that someone sold 3 of this commodity (name BookA,ID 10458998374,price $30) at 2023-06-21 13:30:40.TestUser1 is related with record, can also modify it. In upper request, items Func,UserName,Password (or PassHash) and RelatedUser are mandatory, the rest items are defined and explained by the developer base on his business logic.

Sample 4. Change record

<head>

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>:

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/sha256.js"></script>

<script src="https://InfoChain.link/Interface/js/Deliver.js"></script>

</head>

<script>

function ChangeRecord()

{

var chain=new ChainRequest(“192.168.1.146",”4330”);

//var chain=new ChainRequest();

//chain.SetPhpServerFolder("./php");

var requestItems={};

requestItems[“Func”]=”ChangeRecord”;

requestItems[“UserName”]=”TestUser1”;

requestItems[“Password”]=”11223344”;

requestItems[“ID”]=”RD_20230621133040381”;

//requestItems[“PassHash”]=”XXXXX”;

requestItems[“RecordType”]=”Private”;

requestItems[“RelatedUser”]=”TestUser2,TestUser3”;

requestItems[“Commodity_Name”]=”BookA”;

requestItems[“Commodity_ID”]=”10458998374”;

requestItems[“Commodity_Price”]=”$30”;

requestItems[“Sell_count”]=”3”;

requestItems[“Sell_time”]=”2023-06-21 13:30:40”;

requestItems[“Deliver_address”]=”AA street, no. 4”;

requestItems[“Deliver_time”]=”2023-06-23 15:10:20”;

chain.Request(requestItems,handleCreateResult,handleCreateFail);

}


function handleCreateResult(result_string)

{

alert(result_string);

}

function handleCreateFail(error_string)

{

alert(error_string);

}

</script>

The upper sample means to TestUser1 try to change record with ID RD_20230621133040381, changed item related user from TestUser1 to TestUser1 and TestUser3 and add item deliver address and deliver time to this record.