public class Block {
- public Integer bits;
+ public String hash;
- public String difficulty;
+ public Integer size;
- public String hash;
+ public Integer version;
public Integer height;
- public Integer nonce;
-
@SerializedName("previous_block_hash")
public String previousBlockHash;
- public Integer size;
-
public Integer timestamp;
+ public Integer nonce;
+
+ public long bits;
+
+ public String difficulty;
+
@SerializedName("transaction_merkle_root")
public String transactionsMerkleRoot;
public List<BlockTx> transactions;
- public Integer version;
private static Logger logger = Logger.getLogger(Block.class);
* @throws BytomException
*/
public Block getBlock(Client client) throws BytomException {
+
Block block = client.request("get-block", this, Block.class);
logger.info("get-block:");
/**
* List of specified inputs for a transaction.
*/
+ @SerializedName("inputs")
private List<AnnotatedInput> inputs;
/**
* List of specified outputs for a transaction.
*/
+ @SerializedName("outputs")
private List<AnnotatedOutput> outputs;
}
* The definition of the asset being issued or spent (possibly null).
*/
@SerializedName("asset_definition")
- private String assetDefinition;
+ private Map<String, Object> assetDefinition;
/**
* The id of the asset being issued or spent.
/**
* The number of units of the asset being controlled.
*/
- private Integer amount;
+ private long amount;
/**
* The definition of the asset being controlled (possibly null).
*/
@SerializedName("asset_definition")
- private String assetDefinition;
+ private Map<String, Object> assetDefinition;
/**
* The id of the asset being controlled.
package io.bytom;
+import com.google.gson.Gson;
import com.squareup.okhttp.*;
+import io.bytom.api.Block;
import org.junit.Test;
import java.io.IOException;
System.out.println(response.body().string());
}
+
+ @Test
+ public void testBlockGet() throws Exception {
+ String postBody = "{\n" +
+ " \"hash\": \"37eabf4d321f43b930f52b3af2e53b2ad2dbb234949e778213a4a54e4be04ea8\",\n" +
+ " \"size\": 388,\n" +
+ " \"version\": 1,\n" +
+ " \"height\": 158,\n" +
+ " \"previous_block_hash\": \"2cfa73d6ed14a7fcb3a8ccc2d4c45b0fd4c7754ec6fafaa0964045c23e2131cd\",\n" +
+ " \"timestamp\": 1527241075,\n" +
+ " \"nonce\": 0,\n" +
+ " \"bits\": 2305843009214532812,\n" +
+ " \"difficulty\": \"5789598940468732338727519302629705571043137272394850465663635070376277442560\",\n" +
+ " \"transaction_merkle_root\": \"62755c4770374e696c4fecd94e022ccf6f2adc00f409ac694a5cb92fe02353eb\",\n" +
+ " \"transaction_status_hash\": \"c9c377e5192668bc0a367e4a4764f11e7c725ecced1d7b6a492974fab1b6d5bc\",\n" +
+ " \"transactions\": [\n" +
+ " {\n" +
+ " \"id\": \"5c38b8107d53cbfebd19adbd11f2839d914099a74e491f1cf75f8b18320c84e2\",\n" +
+ " \"version\": 1,\n" +
+ " \"size\": 77,\n" +
+ " \"time_range\": 0,\n" +
+ " \"inputs\": [\n" +
+ " {\n" +
+ " \"type\": \"coinbase\",\n" +
+ " \"asset_id\": \"0000000000000000000000000000000000000000000000000000000000000000\",\n" +
+ " \"asset_definition\": {},\n" +
+ " \"amount\": 0,\n" +
+ " \"arbitrary\": \"c29e\"\n" +
+ " }\n" +
+ " ],\n" +
+ " \"outputs\": [\n" +
+ " {\n" +
+ " \"type\": \"control\",\n" +
+ " \"id\": \"9acda4f2bd83c7114a8837b596860df773a7e61b1d6b0a774addda1473361ad4\",\n" +
+ " \"position\": 0,\n" +
+ " \"asset_id\": \"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\",\n" +
+ " \"asset_definition\": {},\n" +
+ " \"amount\": 41250000000,\n" +
+ " \"control_program\": \"001412a47b53b3bbdaf9f3510e1d8c19d69f81ca9142\",\n" +
+ " \"address\": \"sm1qz2j8k5anh0d0nu63pcwccxwkn7qu4y2zjwaj5h\"\n" +
+ " }\n" +
+ " ],\n" +
+ " \"status_fail\": false\n" +
+ " }\n" +
+ " ]\n" +
+ " }";
+ Gson gson = new Gson();
+ Block block = gson.fromJson(postBody, Block.class);
+ }
}
--- /dev/null
+package io.bytom.integration;
+
+import io.bytom.TestUtils;
+import io.bytom.api.Asset;
+import io.bytom.api.Block;
+import io.bytom.api.Wallet;
+import io.bytom.exception.BytomException;
+import io.bytom.http.Client;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class BlockTest {
+
+ static Client client;
+
+ static {
+ try {
+ client = TestUtils.generateClient();
+ } catch (BytomException e) {
+ e.printStackTrace();
+ }
+ }
+
+ 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);
+ }
+
+ @Test
+ public void testBlockHashGet() throws Exception {
+ String blockHash = Block.getBlockHash(client);
+ Assert.assertNotNull(blockHash);
+ }
+
+ @Test
+ public void testBlockGet() throws Exception {
+ int height = Block.getBlockCount(client);
+ String blockHash = Block.getBlockHash(client);
+
+ block = new Block.QueryBuilder()
+ .setBlockHeight(height)
+ .setBlockHash(blockHash)
+ .getBlock(client);
+ }
+
+ @Test
+ public void testBlockHeader() throws Exception {
+ int height = Block.getBlockCount(client);
+ String blockHash = Block.getBlockHash(client);
+
+ blockHeader = new Block.QueryBuilder()
+ .setBlockHeight(height)
+ .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);
+ }
+
+}
--- /dev/null
+package io.bytom.integration;
+
+import io.bytom.TestUtils;
+import io.bytom.api.Account;
+import io.bytom.api.Address;
+import io.bytom.api.Message;
+import io.bytom.api.Wallet;
+import io.bytom.exception.BytomException;
+import io.bytom.http.Client;
+import org.junit.Test;
+
+import java.util.List;
+
+public class MessageTest {
+
+ static Client client;
+
+ static {
+ try {
+ client = TestUtils.generateClient();
+ } catch (BytomException e) {
+ e.printStackTrace();
+ }
+ }
+
+ static Message message;
+
+ @Test
+ public void testMessageSign() throws Exception {
+
+ String id = "0E6K7AFF00A02";
+ String alias = "test";
+ Account.AddressBuilder addressBuilder = new Account.AddressBuilder()
+ .setAccountId(id)
+ .setAccountAlias(alias);
+ List<Address> addressList = addressBuilder.list(client);
+
+ String address = addressList.get(0).address;
+
+ message = new Message.SignBuilder()
+ .setAddress("sm1qz2j8k5anh0d0nu63pcwccxwkn7qu4y2zjwaj5h")
+ .setMessage("this is a test message")
+ .setPassword("123456")
+ .sign(client);
+ }
+
+
+}
--- /dev/null
+package io.bytom.integration;
+
+import io.bytom.TestUtils;
+import io.bytom.api.Key;
+import io.bytom.api.Wallet;
+import io.bytom.exception.BytomException;
+import io.bytom.http.Client;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class WalletTest {
+
+ static Client client;
+
+ static {
+ try {
+ client = TestUtils.generateClient();
+ } catch (BytomException e) {
+ e.printStackTrace();
+ }
+ }
+
+ static Wallet wallet;
+
+ @Test
+ public void testWalletBackUp() throws Exception {
+
+ wallet = Wallet.backupWallet(client);
+ }
+
+ @Test
+ public void testWallerRestore() throws Exception {
+ // get wallet object
+ wallet = Wallet.backupWallet(client);
+ //restore
+ Wallet.restoreWallet(client, wallet.accountImage, wallet.assetImage, wallet.keyImages);
+ }
+
+
+
+}