Skip to content

Commit

Permalink
Merge pull request #26 from crypto-coder/npm
Browse files Browse the repository at this point in the history
Update protobuf to 0.7.1 / repackage for NPM
  • Loading branch information
JoshOrndorff authored Oct 22, 2018
2 parents b465fce + eb06530 commit e74dad2
Show file tree
Hide file tree
Showing 16 changed files with 8,847 additions and 24,358 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ For now see the integration test examples in rnodeAPI.js
* [RSign](https://github.com/dckc/RSign) A chrome extension for generating client-side signatures akin to metamask
* [node-client](https://github.com/rchain/rchain/tree/dev/node-client) A similar but less mature RChain API written in python

## RChain Protocol Buffer Dependency
* Commit hash [27d722e](https://github.com/rchain/rchain/tree/dev/models/src/main/protobuf)


## License
Copyright 2018 RChain Cooperative

Expand Down
26 changes: 13 additions & 13 deletions RHOCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ exports.fromJSData = fromJSData;
function fromJSData(data /*: mixed */) /* : IPar */ {
function expr1(kv /*: IPar*/) { return { exprs: [kv] }; }

function recur(x) {
function recur(x) /*: IPar */{
switch (typeof x) {
case 'boolean':
return expr1({ g_bool: x, expr_instance: 'g_bool' });
return expr1({ g_bool: x });
case 'number':
// ISSUE: only integers
return expr1({ g_int: x, expr_instance: 'g_int' });
return expr1({ g_int: x });
case 'string':
return expr1({ g_string: x, expr_instance: 'g_string' });
return expr1({ g_string: x });
case 'object':
if (x === null) {
return {};
Expand All @@ -42,15 +42,12 @@ function fromJSData(data /*: mixed */) /* : IPar */ {
// [1, 2, 2] is a process with one exprs, which is a list
// The list has one 3 items, each of which is a process
// with one exprs, which is an int.
return expr1({
e_list_body: { ps: items.map(recur) },
expr_instance: 'e_list_body',
});
return expr1({ e_list_body: { ps: items.map(recur) } });
}

function keysValues(obj) {
function keysValues(obj) /*: IPar */ {
const sends /*: ISend[] */ = Object.keys(obj).sort().map((k) => {
const chan /*: IChannel */ = { quote: expr1({ g_string: k, expr_instance: 'g_string' }) };
const chan /*: IPar */ = expr1({ g_string: k });
return { chan, data: [recur(obj[k])] };
});
return { sends };
Expand Down Expand Up @@ -100,7 +97,7 @@ function toJSData(par /*: IPar */) /*: Json */{
throw new Error(`not RHOCore? ${JSON.stringify(ex)}`);
} else if (p.sends) {
const props = p.sends.map((s) => {
const key = recur((s.chan || {}).quote || {});
const key = recur(s.chan || {});
if (typeof key !== 'string') { throw new Error(`not RHOCore? ${JSON.stringify(key)}`); }
const val = recur((s.data || [{}])[0]);
return { k: key, v: val };
Expand Down Expand Up @@ -128,7 +125,7 @@ exports.toRholang = toRholang;
function toRholang(par /*: IPar */) /*: string */ {
const src = x => JSON.stringify(x);

function recur(p) {
function recur(p /*: IPar */) {
if (p.exprs && p.exprs.length > 0) {
if (p.exprs.length > 1) {
throw new Error(`${p.exprs.length} exprs not part of RHOCore`);
Expand All @@ -143,14 +140,17 @@ function toRholang(par /*: IPar */) /*: string */ {
if (typeof ex.g_string !== 'undefined') {
return src(ex.g_string);
}
if (typeof ex.g_uri !== 'undefined') {
return src(ex.g_uri);
}
if (typeof ex.e_list_body !== 'undefined' && ex.e_list_body !== null
&& Array.isArray(ex.e_list_body.ps)) {
const items /*: string[] */= (ex.e_list_body.ps || []).map(recur);
return `[${items.join(', ')}]`;
}
throw new Error(`not RHOCore? ${JSON.stringify(ex)}`);
} else if (p.sends) {
const ea = s => `@${recur((s.chan || {}).quote || {})}!(${(s.data || []).map(recur).join(', ')})`;
const ea = s => `@${recur(s.chan || {})}!(${(s.data || []).map(recur).join(', ')})`;
return p.sends.map(ea).join(' | ');
} else {
// TODO: check that everything else is empty
Expand Down
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{
"name": "rchain-api",
"version": "0.1.11",
"version": "0.7.1",
"description": "RChain client for node.js",
"main": "rnodeAPI.js",
"scripts": {
"testAll": "npm run check && npm run integrationTest",
"check": "npm run test && npm run lint && npm run flow-check",
"test": "node test/testRHOCore.js; node test/testRNode.js; node test/testSigning.js",
"integrationTest": "node rnodeAPI.js",
"integrationTest": "node test/testRNode.js --net && node test/liveRHOCoreTest.js && node rnodeAPI.js",
"flow-check": "flow check --from emacs",
"flow-status": "flow status --from emacs",
"lint": "eslint *.js **/*.js --format unix --ignore-pattern interfaces/ --ignore-pattern node_modules/ --ignore-pattern protobuf/"
},
"config": {
"host": "localhost",
"port": "40401"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dckc/RChain-API.git"
Expand All @@ -20,19 +26,21 @@
"blockchain",
"rholang"
],
"author": "Dan Connolly",
"contributors": [
"Dan Connolly <[email protected]> (http://www.madmode.com)",
"Joshy Orndorff"
"Joshy Orndorff",
"Chris Williams"
],
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/dckc/RChain-API/issues"
},
"homepage": "https://github.com/dckc/RChain-API#readme",
"dependencies": {
"grpc": "^1.13.1",
"@grpc/proto-loader": "^0.3.0",
"blake2": "^2.0.1",
"grpc": "^1.13.1",
"js-sha3": "^0.8.0",
"protobufjs": "^6.8.8",
"remote-origin-url": "^1.0.0",
"tweetnacl": "^1.0.0"
Expand Down
41 changes: 27 additions & 14 deletions protobuf/CasperMessage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ service DeployService {
rpc addBlock(BlockMessage) returns (DeployServiceResponse) {}
rpc createBlock(google.protobuf.Empty) returns (DeployServiceResponse) {}
rpc showBlock(BlockQuery) returns (BlockQueryResponse) {}
rpc showBlocks(google.protobuf.Empty) returns (stream BlockInfo) {}
rpc listenForDataAtName(Channel) returns (ListeningNameDataResponse) {}
rpc listenForContinuationAtName(Channels) returns (ListeningNameContinuationResponse) {}
rpc showMainChain(BlocksQuery) returns (stream BlockInfoWithoutTuplespace) {}
rpc showBlocks(BlocksQuery) returns (stream BlockInfoWithoutTuplespace) {}
rpc listenForDataAtName(DataAtNameQuery) returns (ListeningNameDataResponse) {}
rpc listenForContinuationAtName(ContinuationAtNameQuery) returns (ListeningNameContinuationResponse) {}
}

message PhloLimit {
int64 value = 1;
}

message PhloPrice {
int64 value = 1;
}

message DeployData {
Expand All @@ -34,8 +43,8 @@ message DeployData {
bytes sig = 4; //signature of (hash(term) + timestamp) using private key
string sigAlgorithm = 5; // name of the algorithm used to sign
string from = 6; //wallet address which will be used to pay for the deployment
int32 phloPrice = 7; //phlo price
int32 phloLimit = 8; //phlo limit for the deployment
PhloPrice phloPrice = 7; //phlo price
PhloLimit phloLimit = 8; //phlo limit for the deployment
int32 nonce = 9; //nonce for transaction made against `from` wallet
}

Expand All @@ -51,8 +60,18 @@ message BlockQuery {
string hash = 1;
}

message Channels {
repeated Channel channels = 1;
message BlocksQuery {
int32 depth = 1;
}

message DataAtNameQuery {
int32 depth = 1;
Par name = 2;
}

message ContinuationAtNameQuery {
int32 depth = 1;
repeated Par names = 2;
}

message DeployServiceResponse {
Expand Down Expand Up @@ -96,12 +115,6 @@ message WaitingContinuationInfo {
Par postBlockContinuation = 2;
}

message BlocksResponse {
string status = 1;
repeated BlockInfo blocks = 2;
int64 length = 3;
}

message BlockInfoWithoutTuplespace {
string blockHash = 1;
string blockSize = 2;
Expand Down Expand Up @@ -255,7 +268,7 @@ message CommEvent {

message Bond {
bytes validator = 1;
int32 stake = 2;
int64 stake = 2;
}
// --------- End Core Protocol --------

Expand Down
1 change: 1 addition & 0 deletions protobuf/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Automatically fetch .proto files

WGET=wget
PERL=perl
PBJS=../node_modules/.bin/pbjs
PBTS=../node_modules/.bin/pbts

Expand Down
Loading

0 comments on commit e74dad2

Please sign in to comment.