<commit_before>var http = require('http');
var pb = require("protobufjs");

var builder = pb.loadProtoFile("./appinit.proto"),
    app = builder.build("appinit");

function Deploy(id, params) {

    var post_data = JSON.stringify({
        'jsonrpc': '2.0',
        'method': 'deploy',
        'params': {
            'type': 1,
            'chaincodeID': id,
            'ctorMsg': {
                'function':'init',
                'args':[new app.Init(params).toBase64()]
            }
        },
        "id": 1
    });
    console.log(post_data);
    post(post_data, '/chaincode',function(body) {
        var resp = JSON.parse(body);
        console.log(resp.result.message);
    });
}

function post(pdata, path) {
    var post_options = {
        host: 'localhost',
        port: '3000',
        path: path,
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        }
    };

    var post_req = http.request(post_options, function(res) {
        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            console.log('Response: ' + chunk);
        });
    });

    // post the data
    post_req.write(pdata);
    post_req.end();

}

Deploy(
    {
        'name': 'mycc'
    },
    {
        'partyA': {
            'entity': 'foo',
            'value': 100
        },
        'partyB': {
            'entity': 'bar',
            'value': 100
        }
    }
);<commit_msg>Develop the client further<commit_after>var http = require('http');
var pb = require("protobufjs");

var builder = pb.newBuilder({ convertFieldsToCamelCase: true });

pb.loadProtoFile("./appinit.proto", builder);
var init = builder.build("appinit");

pb.loadProtoFile("./org.hyperledger.chaincode.example02.proto", builder);
var app = builder.build("org.hyperledger.chaincode.example02");

function Deploy(id, params) {

    invoke('deploy', id, 'init', new init.Init(params), function(res) {
        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            var resp = JSON.parse(chunk);
            console.log('Response: ' + chunk);
        });

    });
}

function CheckBalance(id, params) {

    invoke('query', id, 'org.hyperledger.chaincode.example02/query/1', new app.Entity(params), function(res) {
        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            var resp = JSON.parse(chunk);
            if (resp.result.status == "OK") {
                var result = app.BalanceResult.decode64(resp.result.message);
                console.log("BalanceResult: " + result.balance);
            } else {
                console.log('ERROR: ' + chunk);
            }
        });

    });
}

function invoke(method, id, func, args, cb) {
    var post_data = JSON.stringify({
        'jsonrpc': '2.0',
        'method': method,
        'params': {
            'type': 3,
            'chaincodeID': id,
            'ctorMsg': {
                'function': func,
                'args':[args.toBase64()]
            }
        },
        "id": 1
    });
    console.log(post_data);
    post(post_data, '/chaincode', cb);
}

function post(pdata, path, cb) {
    var post_options = {
        host: 'localhost',
        port: '3000',
        path: path,
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        }
    };

    var post_req = http.request(post_options, cb);

    // post the data
    post_req.write(pdata);
    post_req.end();

}

Deploy(
    {
        'name': 'mycc'
    },
    {
        'partyA': {
            'entity': 'foo',
            'value': 100
        },
        'partyB': {
            'entity': 'bar',
            'value': 100
        }
    }
);

CheckBalance(
    {
        'name': 'mycc'
    },
    {
        "id": "foo"
    }
);
{'fraction_non_alphanumeric': 0.16600581549035157, 'fraction_numerical': 0.011630980703145652, 'mean_word_length': 1.7946824224519942, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '346514', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1186, 'n_words': 224}