Skip to content

Commit

Permalink
Update readme, examples for v0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
acktsap committed Feb 13, 2019
1 parent c4557e0 commit cc4fa26
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ This repository, heraj is java implementation for hera.

## Lastest

v0.10.0
v0.11.0

build with aergo-protobuf v0.10.0
build with aergo-protobuf v0.11.0

## Compatibility

* Aergo : v0.10.x
* Aergo : v0.11.x
* Java : JDK 6 or higher
* Android : Android 3.0 (API 11) or higher

Expand Down Expand Up @@ -47,17 +47,17 @@ If you just want a minimum one, use `heraj-transport`. Or need more feature, use
<dependency>
<groupId>io.aergo</groupId>
<artifactId>heraj-transport</artifactId>
<version>0.10.0</version>
<version>0.11.0</version>
</dependency>
<dependency>
<groupId>io.aergo</groupId>
<artifactId>heraj-wallet</artifactId>
<version>0.10.0</version>
<version>0.11.0</version>
</dependency>
<dependency>
<groupId>io.aergo</groupId>
<artifactId>heraj-smart-contract</artifactId>
<version>0.10.0</version>
<version>0.11.0</version>
</dependency>
</dependencies>
```
Expand All @@ -72,9 +72,9 @@ repositories {
...

dependencies {
implementation 'io.aergo:heraj-transport:0.10.0'
implementation 'io.aergo:heraj-wallet:0.10.0'
implementation 'io.aergo:heraj-smart-contract:0.10.0'
implementation 'io.aergo:heraj-transport:0.11.0'
implementation 'io.aergo:heraj-wallet:0.11.0'
implementation 'io.aergo:heraj-smart-contract:0.11.0'
}
```

Expand Down
24 changes: 16 additions & 8 deletions examples/src/main/java/hera/example/highlevel/BlockLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ protected void blockLookup() {
final BlockHash bestHash = wallet.getBestBlockHash();
final long bestHeight = wallet.getBestBlockHeight();

// lookup block by best block hash
// query block by best block hash
final Block blockByHash = wallet.getBlock(bestHash);
System.out.println("Block by hash: " + blockByHash);

// lookup block by best height
// query block by best height
final Block blockByHeight = wallet.getBlock(bestHeight);
System.out.println("Block by height: " + blockByHeight);

// lookup previous block by hash
// query previous block by hash
final Block previousBlock =
wallet.getBlock(blockByHash.getPreviousHash());
System.out.println("Previous block: " + previousBlock);
Expand All @@ -52,16 +52,24 @@ protected void blockHeaderLookup() {

// get best block hash, height
final BlockHash bestHash = wallet.getBestBlockHash();
final Block block = wallet.getBlock(bestHash);
final long bestHeight = wallet.getBestBlockHeight();

// query block header corresponding to the block hash
final BlockHeader blockHeaderByHash = wallet.getBlockHeader(bestHash);
System.out.println("Block header by hash: " + blockHeaderByHash);

// query block header corresponding to the block hash
final BlockHeader blockHeaderByHeight = wallet.getBlockHeader(bestHeight);
System.out.println("Block header by height: " + blockHeaderByHeight);

// lookup 10 block headers starting from best block backward with best block hash
// query 10 block headers starting from best block backward with best block hash
final List<BlockHeader> blockHeadersByHash =
wallet.listBlockHeaders(block.getHash(), 10);
wallet.listBlockHeaders(bestHash, 10);
System.out.println("Block headers by hash: " + blockHeadersByHash);

// lookup 10 block headers starting from best block backward with best block height
// query 10 block headers starting from best block backward with best block height
final List<BlockHeader> blockHeadersByHeight =
wallet.listBlockHeaders(block.getBlockNumber(), 10);
wallet.listBlockHeaders(bestHeight, 10);
System.out.println("Block headers by height: " + blockHeadersByHeight);

// close the client
Expand Down
5 changes: 3 additions & 2 deletions examples/src/main/java/hera/example/highlevel/SendAergo.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ protected void sendAergoWithSecure() throws Exception {
.withNonBlockingConnect()
.build(WalletType.Secure);

// bind keystore
final KeyStore keyStore = KeyStore.getInstance("JKS");
// here, make a new keystore
// if exists, load with input stream and password
final KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(null, null);

// bind keystore
wallet.bindKeyStore(keyStore);

// create an account
Expand Down
31 changes: 21 additions & 10 deletions examples/src/main/java/hera/example/lowlevel/BlockLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package hera.example.lowlevel;

import hera.api.model.Block;
import hera.api.model.BlockHash;
import hera.api.model.BlockHeader;
import hera.api.model.BlockchainStatus;
import hera.client.AergoClient;
Expand All @@ -21,18 +22,18 @@ protected void blockLookup() {
.withNonBlockingConnect()
.build();

// lookup current blockchain status
// query current blockchain status
final BlockchainStatus status = aergoClient.getBlockchainOperation().getBlockchainStatus();

// lookup block by best block hash
// query block by best block hash
final Block blockByHash = aergoClient.getBlockOperation().getBlock(status.getBestBlockHash());
System.out.println("Block by hash: " + blockByHash);

// lookup block by best height
// query block by best height
final Block blockByHeight = aergoClient.getBlockOperation().getBlock(status.getBestHeight());
System.out.println("Block by height: " + blockByHeight);

// lookup previous block by hash
// query previous block by hash
final Block previousBlock =
aergoClient.getBlockOperation().getBlock(blockByHash.getPreviousHash());
System.out.println("Previous block: " + previousBlock);
Expand All @@ -48,18 +49,28 @@ protected void blockHeaderLookup() {
.withNonBlockingConnect()
.build();

// lookup best block
// query best block
final BlockchainStatus status = aergoClient.getBlockchainOperation().getBlockchainStatus();
final Block block = aergoClient.getBlockOperation().getBlock(status.getBestBlockHash());
final BlockHash bestHash = status.getBestBlockHash();
final long bestHeight = status.getBestHeight();

// lookup 10 block headers starting from best block backward with best block hash
// query block header corresponding to the block hash
final BlockHeader blockHeaderByHash = aergoClient.getBlockOperation().getBlockHeader(bestHash);
System.out.println("Block header by hash: " + blockHeaderByHash);

// query block header corresponding to the block hash
final BlockHeader blockHeaderByHeight =
aergoClient.getBlockOperation().getBlockHeader(bestHeight);
System.out.println("Block header by height: " + blockHeaderByHeight);

// query 10 block headers starting from best block backward with best block hash
final List<BlockHeader> blockHeadersByHash =
aergoClient.getBlockOperation().listBlockHeaders(block.getHash(), 10);
aergoClient.getBlockOperation().listBlockHeaders(bestHash, 10);
System.out.println("Block headers by hash: " + blockHeadersByHash);

// lookup 10 block headers starting from best block backward with best block height
// query 10 block headers starting from best block backward with best block height
final List<BlockHeader> blockHeadersByHeight =
aergoClient.getBlockOperation().listBlockHeaders(block.getBlockNumber(), 10);
aergoClient.getBlockOperation().listBlockHeaders(bestHeight, 10);
System.out.println("Block headers by height: " + blockHeadersByHeight);

// close the client
Expand Down

0 comments on commit cc4fa26

Please sign in to comment.