Skip to content

Commit

Permalink
Fix a minor subscription API issue
Browse files Browse the repository at this point in the history
  • Loading branch information
guiguan committed Jul 10, 2020
1 parent 93bc39c commit cf536a5
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ tpCH, errCH := api.SubscribeTrieProof(ctx, cli, id, triePf.GetId())
for tp := range tpCH {
log.Printf("Anchoring proof: %s\n", tp.GetStatus())
triePf = tp

if tp.GetStatus() == anchorPB.Batch_ERROR {
return errors.New(tp.GetError())
}
}

// always check error from the error channel
Expand Down
7 changes: 6 additions & 1 deletion cmd/proofable-cli/cmd/cmd_create_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
* @Author: guiguan
* @Date: 2019-09-16T16:21:53+10:00
* @Last modified by: guiguan
* @Last modified time: 2020-07-07T10:40:57+10:00
* @Last modified time: 2020-07-10T15:08:44+10:00
*/

package cmd

import (
"bytes"
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -167,6 +168,10 @@ By default, if the path is a directory, the proof will be created under the dire
for tp := range tpCH {
colorcli.Printf("Anchoring proof: %s\n", tp.GetStatus())
triePf = tp

if tp.GetStatus() == anchorPB.Batch_ERROR {
return errors.New(tp.GetError())
}
}

err = <-errCH
Expand Down
7 changes: 6 additions & 1 deletion docs/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
* @Author: guiguan
* @Date: 2020-03-31T12:29:46+11:00
* @Last modified by: guiguan
* @Last modified time: 2020-07-09T13:48:44+10:00
* @Last modified time: 2020-07-10T15:31:33+10:00
*/

package main

import (
"context"
"encoding/hex"
"errors"
"fmt"
"log"
"time"
Expand Down Expand Up @@ -84,6 +85,10 @@ func main() {
for tp := range tpCH {
log.Printf("Anchoring proof: %s\n", tp.GetStatus())
triePf = tp

if tp.GetStatus() == anchorPB.Batch_ERROR {
return errors.New(tp.GetError())
}
}

// always check error from the error channel
Expand Down
4 changes: 4 additions & 0 deletions node_sdk/docs/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ for await (const tp of client.subscribeTrieProof(
)) {
console.log("Anchoring proof: %s", Batch.StatusName[tp.getStatus()]);
trieProof = tp;

if (tp.getStatus() === Batch.Status.ERROR) {
throw new Error(tp.getError());
}
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h3>key<wbr>Values</h3>
<div class="tsd-signature tsd-kind-icon">key<wbr>Values<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{ </span>changed<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">; </span>missing<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">; </span>passed<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">; </span>total<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">; </span>untracked<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol"> }</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/SouthbankSoftware/proofable/blob/master/node_sdk/src/api/helpers.ts#L126">src/api/helpers.ts:126</a></li>
<li>Defined in <a href="https://github.com/SouthbankSoftware/proofable/blob/master/node_sdk/src/api/helpers.ts#L130">src/api/helpers.ts:130</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand Down Expand Up @@ -125,7 +125,7 @@ <h3>proof</h3>
<div class="tsd-signature tsd-kind-icon">proof<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">{ </span>anchorType<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>blockNumber<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>blockTime<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">; </span>blockTimeNano<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">; </span>blockTimeString<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>error<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>id<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>root<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>txnId<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>txnUri<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>verified<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> }</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/SouthbankSoftware/proofable/blob/master/node_sdk/src/api/helpers.ts#L113">src/api/helpers.ts:113</a></li>
<li>Defined in <a href="https://github.com/SouthbankSoftware/proofable/blob/master/node_sdk/src/api/helpers.ts#L117">src/api/helpers.ts:117</a></li>
</ul>
</aside>
<div class="tsd-type-declaration">
Expand Down Expand Up @@ -173,7 +173,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> trie</h3>
<div class="tsd-signature tsd-kind-icon">trie<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-symbol">{ </span>id<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span>root<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> }</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/SouthbankSoftware/proofable/blob/master/node_sdk/src/api/helpers.ts#L109">src/api/helpers.ts:109</a></li>
<li>Defined in <a href="https://github.com/SouthbankSoftware/proofable/blob/master/node_sdk/src/api/helpers.ts#L113">src/api/helpers.ts:113</a></li>
</ul>
</aside>
</section>
Expand Down
2 changes: 1 addition & 1 deletion node_sdk/package-lock.json

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

2 changes: 1 addition & 1 deletion node_sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "proofable",
"version": "0.2.4",
"version": "0.2.5",
"description": "Proofable Node SDK",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 5 additions & 1 deletion node_sdk/src/api/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @Author: guiguan
* @Date: 2020-07-02T11:42:17+10:00
* @Last modified by: guiguan
* @Last modified time: 2020-07-07T11:09:21+10:00
* @Last modified time: 2020-07-10T15:22:06+10:00
*/

import util from "util";
Expand Down Expand Up @@ -100,6 +100,10 @@ export async function anchorTrie(
outputProgress &&
console.log("Anchoring proof: %s", Batch.StatusName[tp.getStatus()]);
trieProof = tp;

if (tp.getStatus() === Batch.Status.ERROR) {
throw new Error(tp.getError());
}
}

return trieProof;
Expand Down
6 changes: 5 additions & 1 deletion node_sdk/src/examples/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @Author: Koustubh Gaikwad
* @Date: 2020-06-19T09:26:20+10:00
* @Last modified by: guiguan
* @Last modified time: 2020-07-08T10:51:08+10:00
* @Last modified time: 2020-07-10T15:28:33+10:00
*/

const {
Expand Down Expand Up @@ -89,6 +89,10 @@ const client = newAPIClient(API_PROOFABLE_ENDPOINT);
)) {
console.log("Anchoring proof: %s", Batch.StatusName[tp.getStatus()]);
trieProof = tp;

if (tp.getStatus() === Batch.Status.ERROR) {
throw new Error(tp.getError());
}
}

// verify the proof
Expand Down
6 changes: 5 additions & 1 deletion node_sdk/src/examples/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @Author: Koustubh Gaikwad
* @Date: 2020-06-19T09:26:20+10:00
* @Last modified by: guiguan
* @Last modified time: 2020-07-08T10:51:08+10:00
* @Last modified time: 2020-07-10T15:27:56+10:00
*/

import {
Expand Down Expand Up @@ -89,6 +89,10 @@ const client = newAPIClient(API_PROOFABLE_ENDPOINT);
)) {
console.log("Anchoring proof: %s", Batch.StatusName[tp.getStatus()]);
trieProof = tp;

if (tp.getStatus() === Batch.Status.ERROR) {
throw new Error(tp.getError());
}
}

// verify the proof
Expand Down
2 changes: 1 addition & 1 deletion node_sdk/src/examples/typescript_basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @Author: guiguan
* @Date: 2020-07-02T23:16:27+10:00
* @Last modified by: guiguan
* @Last modified time: 2020-07-08T10:51:09+10:00
* @Last modified time: 2020-07-10T15:26:32+10:00
*/

import _ from "lodash";
Expand Down

0 comments on commit cf536a5

Please sign in to comment.