Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 2 additions & 19 deletions java-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<dependency>
<groupId>io.bytom</groupId>
<artifactId>java-sdk</artifactId>
<version>1.0.2</version>
</dependency>
```

### 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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
23 changes: 18 additions & 5 deletions java-sdk/src/main/java/io/bytom/api/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,25 @@ public static List<Account> 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<String, String> 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<String, String> req = new HashMap<>();
req.put("account_id", account_id);
client.request("delete-account", req);
}

Expand Down Expand Up @@ -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;
Expand Down
67 changes: 0 additions & 67 deletions java-sdk/src/main/java/io/bytom/api/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.apache.log4j.Logger;

import java.util.List;
import java.util.Map;

public class Block {

Expand All @@ -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<Transaction> transactions;


Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}

}
}
76 changes: 67 additions & 9 deletions java-sdk/src/main/java/io/bytom/api/CoreConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
}
}
12 changes: 5 additions & 7 deletions java-sdk/src/main/java/io/bytom/api/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -106,6 +100,11 @@ public Template build(Client client) throws BytomException {
return client.request("build-transaction", this, Template.class);
}

public List<Template> buildChainTx(Client client) throws BytomException {
Type listType = new ParameterizedTypeImpl(List.class, new Class[]{Template.class});
return client.request("build-chain-transactions", this, listType);
}

/**
* Default constructor initializes actions list.
*/
Expand Down Expand Up @@ -275,7 +274,6 @@ public Template sign(Client client, Template template,

return templateResult;
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ public void testTokenList() throws Exception {

@Test
public void testTokenCheck() throws Exception {
String secret = "5e37378eb59de6b10e60f2247ebf71c4955002e75e0cd31ede3bf48813a0a799";
String secret = "dad13ed9f34ffd063cd34abb2320fbbb5c768db4588e319f4444109944b65218";
AccessToken.check(client, "sheng", secret);
}

@Test
public void testDeleteCheck() throws Exception {
String secret = "dad13ed9f34ffd063cd34abb2320fbbb5c768db4588e319f4444109944b65218";
AccessToken.delete(client, "sheng");
}
}
8 changes: 2 additions & 6 deletions java-sdk/src/test/java/io/bytom/integration/AccountTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public void testAccountCreate() throws Exception {
List<String> root_xpubs = new ArrayList<>();
root_xpubs.add("c4b25825e92cd8623de4fd6a35952ad0efb2ed215fdb1b40754f0ed12eff7827d147d1e8b003601ba2f78a4a84dcc77e93ed282633f2679048c5d5ac5ea10cb5");


// Key.Builder builder = new Key.Builder().setAlias(alias).setPassword(password);
// key = Key.create(client, builder);

Account.Builder builder = new Account.Builder().setAlias(alias).setQuorum(quorum).setRootXpub(root_xpubs);
account = Account.create(client, builder);

Expand All @@ -47,9 +43,9 @@ public void testAccountList() throws Exception {
public void testAccountDelete() throws Exception {
client = TestUtils.generateClient();
List<Account> accountList = Account.list(client);
String alias = accountList.get(accountList.size()-1).alias;
Account lastAccount = accountList.get(accountList.size()-1);
//delete the last Account Object
Account.delete(client, alias);
Account.deleteByAccountAlias(client, lastAccount.alias);
}

@Test
Expand Down
29 changes: 2 additions & 27 deletions java-sdk/src/test/java/io/bytom/integration/BlockTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ public class BlockTest {

static Block block;
static Block.BlockHeader blockHeader;
static Block.BlockDifficulty blockDifficulty;
static Block.BlockHashRate blockHashRate;

@Test
public void testBlockCountGet() throws Exception {
int count = Block.getBlockCount(client);
Assert.assertEquals(158, count);
System.out.println(count);
}

@Test
public void testBlockHashGet() throws Exception {
String blockHash = Block.getBlockHash(client);
Assert.assertNotNull(blockHash);
System.out.println(blockHash);
}

@Test
Expand All @@ -59,27 +57,4 @@ public void testBlockHeader() throws Exception {
.setBlockHash(blockHash)
.getBlockHeader(client);
}

@Test
public void testBlockDifficulty() throws Exception {
int height = Block.getBlockCount(client);
String blockHash = Block.getBlockHash(client);

blockDifficulty = new Block.QueryBuilder()
.setBlockHeight(height)
.setBlockHash(blockHash)
.getBlockDifficulty(client);
}

@Test
public void testBlockHashRate() throws Exception {
int height = Block.getBlockCount(client);
String blockHash = Block.getBlockHash(client);

blockHashRate = new Block.QueryBuilder()
.setBlockHeight(height)
.setBlockHash(blockHash)
.getHashRate(client);
}

}
Loading