diff --git a/java-sdk/README.md b/java-sdk/README.md index f2984a6..cf062b5 100644 --- a/java-sdk/README.md +++ b/java-sdk/README.md @@ -7,23 +7,6 @@ at [Bytom wiki](https://github.com/Bytom/bytom/wiki/API-Reference) ## Installation -There are various ways to install and use this sdk. We'll provide three ways to get it. Note that the bytom-sdk requires JAVA 7 or newer. - -### Apache Maven - -```xml - - io.bytom - java-sdk - 1.0.2 - -``` - -### Gradle/Grails -```xml -compile 'io.bytom:bytom-sdk:1.0.2' -``` - ### Building from source code To clone, compile, and install in your local maven repository (or copy the artifacts from the target/ directory to wherever you need them): @@ -62,7 +45,7 @@ Client client = Client.generateClient(); * [`Secondly sign the transaction`](#secondly-sign-the-transaction) * [`Finally submit the transaction`](#finally-submit-the-transaction) -> For more details, see [API methods](https://github.com/Bytom/java-sdk/blob/master/doc/index.md#api-methods) +> For more details, see [API methods](https://github.com/Bytom/bytom-java-sdk/blob/master/java-sdk/doc/index.md#api-methods) ### Create a key @@ -113,7 +96,7 @@ receiverAsset = builder.create(client); ### Issue asset -For more transaction details, see [transactions](https://github.com/Bytom/java-sdk/blob/master/doc/transactions.md) +For more transaction details, see [transactions](https://github.com/Bytom/bytom-java-sdk/blob/master/java-sdk/doc/transactions.md) #### Firstly build the transaction diff --git a/java-sdk/src/main/java/io/bytom/api/Account.java b/java-sdk/src/main/java/io/bytom/api/Account.java index c84e526..a62d090 100644 --- a/java-sdk/src/main/java/io/bytom/api/Account.java +++ b/java-sdk/src/main/java/io/bytom/api/Account.java @@ -71,12 +71,25 @@ public static List list(Client client) throws BytomException { /** * delete-account * @param client client object that makes requests to the core - * @param account_info account_info + * @param account_alias account_alias * @throws BytomException BytomException */ - public static void delete(Client client, String account_info) throws BytomException { + public static void deleteByAccountAlias(Client client, String account_alias) throws BytomException { Map req = new HashMap<>(); - req.put("account_info", account_info); + req.put("account_alias", account_alias); + client.request("delete-account", req); + } + + /** + * delete-account + * @param client client object that makes requests to the core + * @param account_id account_id + * @throws BytomException BytomException + */ + + public static void deleteByAccountID(Client client,String account_id) throws BytomException { + Map req = new HashMap<>(); + req.put("account_id", account_id); client.request("delete-account", req); } @@ -214,8 +227,8 @@ public static class Address { @SerializedName("change") public Boolean change; - @SerializedName("vaild") - public Boolean vaild; + @SerializedName("valid") + public Boolean valid; @SerializedName("is_local") public Boolean is_local; diff --git a/java-sdk/src/main/java/io/bytom/api/Block.java b/java-sdk/src/main/java/io/bytom/api/Block.java index 3af14dc..0d6817e 100644 --- a/java-sdk/src/main/java/io/bytom/api/Block.java +++ b/java-sdk/src/main/java/io/bytom/api/Block.java @@ -7,7 +7,6 @@ import org.apache.log4j.Logger; import java.util.List; -import java.util.Map; public class Block { @@ -24,18 +23,9 @@ public class Block { public Integer timestamp; - public Integer nonce; - - public long bits; - - public String difficulty; - @SerializedName("transaction_merkle_root") public String transactionsMerkleRoot; - @SerializedName("transaction_status_hash") - public String transactionStatusHash; - public List transactions; @@ -133,40 +123,6 @@ public BlockHeader getBlockHeader(Client client) throws BytomException { return blockHeader; } - /** - * Call get-difficulty api - * - * @param client - * @return - * @throws BytomException - */ - public BlockDifficulty getBlockDifficulty(Client client) throws BytomException { - BlockDifficulty blockDifficulty = - client.request("get-difficulty", this, BlockDifficulty.class); - - logger.info("get-difficulty:"); - logger.info(blockDifficulty.toJson()); - - return blockDifficulty; - } - - /** - * Call get-hash-rate api - * - * @param client - * @return - * @throws BytomException - */ - public BlockHashRate getHashRate(Client client) throws BytomException { - BlockHashRate blockHashRate = - client.request("get-hash-rate", this, BlockHashRate.class); - - logger.info("get-hash-rate:"); - logger.info(blockHashRate.toJson()); - - return blockHashRate; - } - } public static class BlockHeader { @@ -183,27 +139,4 @@ public String toJson() { } - public static class BlockDifficulty { - public String hash; - public Integer height; - public Integer bits; - public String difficulty; - - public String toJson() { - return Utils.serializer.toJson(this); - } - - - } - - public static class BlockHashRate { - public String hash; - public Integer height; - public Integer hash_rate; - - public String toJson() { - return Utils.serializer.toJson(this); - } - - } } diff --git a/java-sdk/src/main/java/io/bytom/api/CoreConfig.java b/java-sdk/src/main/java/io/bytom/api/CoreConfig.java index 3334773..babbf92 100644 --- a/java-sdk/src/main/java/io/bytom/api/CoreConfig.java +++ b/java-sdk/src/main/java/io/bytom/api/CoreConfig.java @@ -60,22 +60,22 @@ public static class NetInfo { public boolean mining; /** - * peer_count, current count of connected peers. + * nodeXPub, the node xpub. */ - @SerializedName("peer_count") - public int peerCount; + @SerializedName("node_xpub") + public String nodeXPub; /** - * current_block, current block height in the node's blockchain. + * peer_count, current count of connected peers. */ - @SerializedName("current_block") - public long currentBlock; + @SerializedName("peer_count") + public int peerCount; /** - * highest_block, current highest block of the connected peers. + * highest_height, current highest block of the connected peers. */ - @SerializedName("highest_block") - public long highestBlock; + @SerializedName("highest_height") + public long highestHeight; /** * network_id, network id. @@ -93,4 +93,62 @@ public String toJson() { return Utils.serializer.toJson(this); } } + + /** + * Call chain-status api + * + * @param client + * @return + * @throws BytomException + */ + public static ChainStatus getChainStatus(Client client) throws BytomException { + ChainStatus chainStatus = client.request("chain-status", null, ChainStatus.class); + + logger.info("chain-status:"); + logger.info(chainStatus.toJson()); + + return chainStatus; + } + + public static class ChainStatus { + /** + * current_height, current block height in the node's blockchain. + */ + @SerializedName("current_height") + public long currentHeight; + + /** + * current_hash, current block hash in the node's blockchain. + */ + @SerializedName("current_hash") + public String currentHash; + + /** + * finalized_height, finalized block height in the node's blockchain. + */ + @SerializedName("finalized_height") + public long finalizedHeight; + + /** + * finalized_hash, finalized block hash in the node's blockchain. + */ + @SerializedName("finalized_hash") + public String finalizedHash; + + /** + * justified_height, justified block height in the node's blockchain. + */ + @SerializedName("justified_height") + public long justifiedHeight; + + /** + * justified_hash, justified block hash in the node's blockchain. + */ + @SerializedName("justified_hash") + public String justifiedHash; + + public String toJson() { + return Utils.serializer.toJson(this); + } + } } diff --git a/java-sdk/src/main/java/io/bytom/api/Transaction.java b/java-sdk/src/main/java/io/bytom/api/Transaction.java index 42accee..d6b6155 100644 --- a/java-sdk/src/main/java/io/bytom/api/Transaction.java +++ b/java-sdk/src/main/java/io/bytom/api/Transaction.java @@ -47,12 +47,6 @@ public class Transaction { @SerializedName("block_height") public int blockHeight; - /** - * whether the state of the request has failed. - */ - @SerializedName("status_fail") - public boolean statusFail; - /** * List of specified inputs for a transaction. */ @@ -106,6 +100,11 @@ public Template build(Client client) throws BytomException { return client.request("build-transaction", this, Template.class); } + public List