Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API reorg: RholangCrypto, REV, ... #66

Merged
merged 36 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dd8d17c
prune obsolete examples/payment
dckc Apr 8, 2019
5283f9a
tools.rho: oops: export tweak
dckc Apr 8, 2019
1ce2a43
SignDeployment works with rclient register
dckc Apr 8, 2019
2cd6fbc
API re-org in preparation for docs
dckc Apr 10, 2019
7c5a820
document testAll
dckc Apr 12, 2019
a51cd4a
protobuf: never mind messages.js
dckc Apr 12, 2019
027aca3
API docs, reorg (esp. RholangCrypto) (WIP)
dckc Apr 12, 2019
0ba6581
docs: re-build
dckc Apr 12, 2019
be436cb
update protobuf version doc
dckc Apr 12, 2019
2657419
API re-org: REV story with RevAddress, SignDeployment
dckc Apr 12, 2019
f197c9a
RholangCrypto story style doctest
dckc Apr 12, 2019
47f9d33
docs: regenerate
dckc Apr 12, 2019
78534b5
testRNode: catch connection failure etc.
dckc Apr 12, 2019
a949905
REV: add date to vault cite
dckc Apr 12, 2019
3c3d4a3
RNode: doctests
dckc Apr 12, 2019
a6dc377
docs: index; add build:docs-html script
dckc Apr 12, 2019
53847fc
rclient: prune obsolete claim code
dckc Apr 13, 2019
3a562a3
proxy: fix signed deploy handling
dckc Apr 13, 2019
d21c9ae
parse / validate REV addresses
dckc Apr 13, 2019
7b67680
example for RevAddress.parse
dckc Apr 13, 2019
39aac41
docs: regenerate
dckc Apr 13, 2019
eb1532a
package.json: prune obsolete jest ref
dckc Apr 13, 2019
6b12738
bump version to 0.9.2-beta.3 for API reorg
dckc Apr 13, 2019
4cffba1
CONTRIBUTING: struggles with extracting API docs are over
dckc Apr 13, 2019
9cc4bcc
factor grpcMock out of doctest-settings
dckc Apr 13, 2019
5cc78f8
README: link markup
dckc Apr 13, 2019
eeca5a4
docs: regen
dckc Apr 13, 2019
3773b3c
udpate README; require('rchain-api') in examples
dckc Apr 13, 2019
e54b34e
API docs: regen
dckc Apr 13, 2019
241742b
RHOCore doctest; re-export protobuf types (0.9.2-beta.4)
dckc Apr 14, 2019
5878af2
API docs: regen
dckc Apr 14, 2019
60ddae6
protobuf naming for showBlocks, showBlock, previewPrivateNames
dckc Apr 14, 2019
02e191f
API docs: regen
dckc Apr 14, 2019
cc3e213
Remove outdated interfaces file from flow config.
JoshOrndorff Apr 16, 2019
8e4f1d6
getBlock -> showBlock
JoshOrndorff Apr 16, 2019
86b3cb0
Update package lock to 0.9.2-beta.4
JoshOrndorff Apr 16, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[include]

[libs]
interfaces/
protobuf/interfaces/

[lints]
Expand Down
28 changes: 28 additions & 0 deletions .markdown-doctest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* global module, require, Buffer */

const assert = require('assert');

const rchain = require('.');
const { grpcMock } = require('./test/testRNode');
const { RHOCore, RhoTypes, RNode, RholangCrypto, REV, Hex, Ed25519keyPair } = rchain;


function config(env, grpcAccess) {
const grpc = env.NODE_ENV === 'production' ? grpcAccess() : grpcMock();
console.log('doctest env:', env.NODE_ENV || 'dev');

return {
babel: false,
require: {
url: require('url'),
grpc: grpc,
'rchain-api': { RHOCore, RhoTypes, RNode, RholangCrypto, REV, Hex, Ed25519keyPair },
},
globals: {
assert, Buffer,
},
};
}

/* global process */
module.exports = config(process.env, () => require('grpc'));
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ cache:
- "node_modules"
- "rclient/node_modules"
script:
- npm test
- npm run flow-check
- npm run lint
- npm run check
49 changes: 22 additions & 27 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# Code Conventions and Design Notes

All contributions should pass these checks (as noted in
`.travis.yml`):
As noted in `.travis.yml`, all contributions must pass `npm run check`,
which runs `test`, `lint`, etc. The `test` check is conventional unit tests.

```yaml
- npm test
- npm run flow-check
- npm run lint
```
Contributions should also pass `npm run integrationTest`, which
requires a running validator node (see below).

The `test` check is conventional unit tests.
To run both the offline and online tests, use `npm run testAll`.


## Static Typechecking: flow
Expand All @@ -19,18 +16,26 @@ flow-check` script does a complete check and `npm run flow-status`
does an incremental check.


## RChain Validator Node for Integration testing
0## RChain Validator Node for Integration testing

One way to provide a validator node for testing, provided you're OK
with the security risks around `--net host`, is:
with the security risks around `--net host`, is to first have
the node start up and generate some random validator keys:

```bash
docker run --rm --net host -v$HOME/.rnode:/var/lib/rnode \
rchain/rnode run -s
```

Then grab one of the secret keys for use as a validator private key:

```bash
$ docker run --rm -it --net host coop.rchain/rnode:0.7.1 run -s
first_key=$(cat $(ls ~/.rnode/genesis/*.sk|head -1))

docker run --rm --net host -v$HOME/.rnode:/var/lib/rnode \
rchain/rnode run -s --validator-private-key $first_key
```

This presumes you've built `coop.rchain/rnode` per `DEVELOPER.md` in
rchain/rchain.

## Code Style: airbnb

Expand Down Expand Up @@ -77,19 +82,9 @@ All of our protobuf encoding and decoding is done using [protobuf.js](https://gi

![protobuf.js diagram](https://camo.githubusercontent.com/f090df881cc6c82ecb7c5d09c9fad550fdfd153e/687474703a2f2f64636f64652e696f2f70726f746f6275662e6a732f746f6f6c7365742e737667)

## Struggles with extracting API doc

We don't use classes (TODO: cite explanation as to why not)
but neither of the relevant recipies seem to work:

> Many libraries and frameworks have special 'class constructor
> methods' that accept an object as an input and return a class with
> that object's properties as prototype properties.

https://github.com/documentationjs/documentation/blob/master/docs/RECIPES.md#class-factories-using-lends


We'd like to use these scripts in our `package.json`:
## Extracting API doc

"doc": "node ./node_modules/.bin/documentation build --github rnodeAPI.js -f html -o docs",
"doc-watch": "node ./node_modules/.bin/documentation serve --watch --github rnodeAPI.js"
We use [documentation.js](https://documentation.js.org/) to build API
docs (docs/index.md) from sources. Use the `docs-watch`, `build:docs`,
or `build:docs-html` npm scripts.
78 changes: 39 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,59 @@ The [RChain Cooperative][1] is developing a decentralized, economically sustaina


## Quickstart
### Find an RChain node whose grpc endpoint you can use.
At the moment that likely means [running your own RNode](2). We're working on a community node at rnode-test.rhobot.net

Make note of your RNode's hostname and gRPC port. If you're not sure, `localhost` and `40401` are good guesses.
Install with `npm install rchain-community/rchain-api`. Then, with
rnode on `localhost`, you can get current block info:

[2]: https://rchain.atlassian.net/wiki/spaces/CORE/pages/428376065/User+guide+for+running+RNode

### Grab RChain-API
Clone this repository with eg `git clone https://github.com/JoshOrndorff/RChain-API`

And install dependencies with `npm install`
```js
const grpc = require('grpc');
const { RNode, Ed25519keyPair, Hex, REV } = require('rchain-api');

### (Recommended) Run the integration test
const rnode = RNode(grpc, { host: 'localhost', port: 40401 });
rnode.showBlocks()
.then((blocks) => { assert.ok(blocks[0].blockHash); });
```

Run `rnodeAPI.js` with _host_ and _port_ arguments, as in: `node rnodeAPI.js rnode-test.rhobot.net 50000`.
If your node is a validator and you have a key to authorize payment, you can deploy code:

You should see something like:
```js
const grpc = require('grpc');
const { RNode, Ed25519keyPair, Hex, REV } = require('rchain-api');

```
stuffToSign serialized {
"type": "Buffer",
"data": "0a300a110a0f2a031a01784a08000000000000000012112a051a036162634a0800000000000000002a0800000000000000004a080000000000000000"
}
...
doDeploy result: { success: true, message: 'Success!' }
@@createBlock(): {
"block": {
"blockHash": {
"type": "Buffer",
"data": "3c5d97e2627432026b6d4a17c8027afb95b72e8d08a936d785b58459eff5859e"
```
const rnode = RNode(grpc, { host: 'localhost', port: 40401 });

### Deploy contract to RNode
There are not yet nice truffle-style build tools, so you will probably deploy your code directly using the `rnode deploy` thin client or using RChain-API itself.

```javascript
const myNode = RNode('localhost', 40401);
rchain.doDeploy({
term: '@"aliceUpdates"!("Having fun traveling!")',
timestamp: clock().valueOf(),
// from: '0x1',
// nonce: 0,
})
const term = '@"world"!("Hello!")';
const myKey = Ed25519keyPair(Hex.decode('11'.repeat(32)));
const timestamp = new Date('2019-04-12T17:59:29.274Z').valueOf();
const info = REV.SignDeployment.sign(myKey, { timestamp, term, phloLimit: 10000, phloPrice: 1 });
rnode.doDeploy(info, true).then((message) => { assert(message.startsWith('Success')); });
```

## API

[./docs/](./docs/index.md)


## Getting access to an RChain node

Choices include:

- [RChain testnet][testnet] nodes such as `node4.testnet.rchain-dev.tk`
- a community node at `rnode-test.rhobot.net`
- [running your own RNode][2]

[testnet]: https://rchain.atlassian.net/wiki/spaces/CORE/pages/678756429/RChain+public+testnet+information
[2]: https://rchain.atlassian.net/wiki/spaces/CORE/pages/428376065/User+guide+for+running+RNode


### RChain gRPC protobuf compatibility

[protobuf][proto]: v0.9.1 bf1b2c6 Mar 28, 2019

[proto]: https://github.com/rchain/rchain/tree/bf1b2c6c6662515403c0a429e8c9fa25edd64638/models/src/main/protobuf


## Examples and Related Projects
* [Nth Caller](https://github.com/JoshOrndorff/nth-caller-game) a minimal RChain-based dApp game that uses RChain-API
* [Status](https://github.com/JoshOrndorff/RChain-Status) a moderately complex dapp that uses more RChain-API features as well as [RSign](https://github.com/dckc/RSign)
Expand All @@ -66,12 +69,9 @@ rchain.doDeploy({
* [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 gRPC protobuf compatibility
* Commit hash [51d9323](https://github.com/rchain/rchain/tree/dev/models/src/main/protobuf) Jan 3, 2019


## License
Copyright 2018 RChain Cooperative
Copyright 2018-2019 RChain Cooperative

Apache 2.0 License (See LICENSE.txt)

Expand Down
8 changes: 8 additions & 0 deletions docs/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
toc:
- RNode
- RHOCore
- REV
- RholangCrypto
- RegistryProxy
- Ed25519keyPair
- Hex
Loading