• R/O
  • HTTP
  • SSH
  • HTTPS

bytom-java-sdk: Commit

Official Java SDK for Bytom


Commit MetaInfo

Révision13b179e37b3bbcbf9be6472629d475b7da05b290 (tree)
l'heure2021-07-13 17:36:38
Auteurdoraemon <wyjDoraemon@163....>
Commiterdoraemon

Message de Log

java 2.0 sdk

Change Summary

Modification

--- 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 class Account {
7171 /**
7272 * delete-account
7373 * @param client client object that makes requests to the core
74- * @param account_info account_info
74+ * @param account_alias account_alias
7575 * @throws BytomException BytomException
7676 */
77- public static void delete(Client client, String account_info) throws BytomException {
77+ public static void deleteByAccountAlias(Client client, String account_alias) throws BytomException {
7878 Map<String, String> req = new HashMap<>();
79- req.put("account_info", account_info);
79+ req.put("account_alias", account_alias);
80+ client.request("delete-account", req);
81+ }
82+
83+ /**
84+ * delete-account
85+ * @param client client object that makes requests to the core
86+ * @param account_id account_id
87+ * @throws BytomException BytomException
88+ */
89+
90+ public static void deleteByAccountID(Client client,String account_id) throws BytomException {
91+ Map<String, String> req = new HashMap<>();
92+ req.put("account_id", account_id);
8093 client.request("delete-account", req);
8194 }
8295
--- 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 io.bytom.http.Client;
77 import org.apache.log4j.Logger;
88
99 import java.util.List;
10-import java.util.Map;
1110
1211 public class Block {
1312
@@ -24,18 +23,9 @@ public class Block {
2423
2524 public Integer timestamp;
2625
27- public Integer nonce;
28-
29- public long bits;
30-
31- public String difficulty;
32-
3326 @SerializedName("transaction_merkle_root")
3427 public String transactionsMerkleRoot;
3528
36- @SerializedName("transaction_status_hash")
37- public String transactionStatusHash;
38-
3929 public List<Transaction> transactions;
4030
4131
@@ -133,40 +123,6 @@ public class Block {
133123 return blockHeader;
134124 }
135125
136- /**
137- * Call get-difficulty api
138- *
139- * @param client
140- * @return
141- * @throws BytomException
142- */
143- public BlockDifficulty getBlockDifficulty(Client client) throws BytomException {
144- BlockDifficulty blockDifficulty =
145- client.request("get-difficulty", this, BlockDifficulty.class);
146-
147- logger.info("get-difficulty:");
148- logger.info(blockDifficulty.toJson());
149-
150- return blockDifficulty;
151- }
152-
153- /**
154- * Call get-hash-rate api
155- *
156- * @param client
157- * @return
158- * @throws BytomException
159- */
160- public BlockHashRate getHashRate(Client client) throws BytomException {
161- BlockHashRate blockHashRate =
162- client.request("get-hash-rate", this, BlockHashRate.class);
163-
164- logger.info("get-hash-rate:");
165- logger.info(blockHashRate.toJson());
166-
167- return blockHashRate;
168- }
169-
170126 }
171127
172128 public static class BlockHeader {
@@ -183,27 +139,4 @@ public class Block {
183139
184140 }
185141
186- public static class BlockDifficulty {
187- public String hash;
188- public Integer height;
189- public Integer bits;
190- public String difficulty;
191-
192- public String toJson() {
193- return Utils.serializer.toJson(this);
194- }
195-
196-
197- }
198-
199- public static class BlockHashRate {
200- public String hash;
201- public Integer height;
202- public Integer hash_rate;
203-
204- public String toJson() {
205- return Utils.serializer.toJson(this);
206- }
207-
208- }
209142 }
--- a/java-sdk/src/main/java/io/bytom/api/CoreConfig.java
+++ b/java-sdk/src/main/java/io/bytom/api/CoreConfig.java
@@ -60,6 +60,12 @@ public class CoreConfig {
6060 public boolean mining;
6161
6262 /**
63+ * nodeXPub, the node xpub.
64+ */
65+ @SerializedName("node_xpub")
66+ public String nodeXPub;
67+
68+ /**
6369 * peer_count, current count of connected peers.
6470 */
6571 @SerializedName("peer_count")
@@ -78,6 +84,12 @@ public class CoreConfig {
7884 public long highestBlock;
7985
8086 /**
87+ * finalized_block, finalized block of the connected peers.
88+ */
89+ @SerializedName("finalized_block")
90+ public long finalizedBlock;
91+
92+ /**
8193 * network_id, network id.
8294 */
8395 @SerializedName("network_id")
--- a/java-sdk/src/main/java/io/bytom/api/Transaction.java
+++ b/java-sdk/src/main/java/io/bytom/api/Transaction.java
@@ -48,12 +48,6 @@ public class Transaction {
4848 public int blockHeight;
4949
5050 /**
51- * whether the state of the request has failed.
52- */
53- @SerializedName("status_fail")
54- public boolean statusFail;
55-
56- /**
5751 * List of specified inputs for a transaction.
5852 */
5953 public List<Input> inputs;
@@ -106,6 +100,11 @@ public class Transaction {
106100 return client.request("build-transaction", this, Template.class);
107101 }
108102
103+ public List<Template> buildChainTx(Client client) throws BytomException {
104+ Type listType = new ParameterizedTypeImpl(List.class, new Class[]{Template.class});
105+ return client.request("build-chain-transactions", this, listType);
106+ }
107+
109108 /**
110109 * Default constructor initializes actions list.
111110 */
@@ -275,7 +274,6 @@ public class Transaction {
275274
276275 return templateResult;
277276 }
278-
279277 }
280278
281279 /**
--- a/java-sdk/src/test/java/io/bytom/integration/AccessTokenTest.java
+++ b/java-sdk/src/test/java/io/bytom/integration/AccessTokenTest.java
@@ -33,7 +33,13 @@ public class AccessTokenTest {
3333
3434 @Test
3535 public void testTokenCheck() throws Exception {
36- String secret = "5e37378eb59de6b10e60f2247ebf71c4955002e75e0cd31ede3bf48813a0a799";
36+ String secret = "dad13ed9f34ffd063cd34abb2320fbbb5c768db4588e319f4444109944b65218";
3737 AccessToken.check(client, "sheng", secret);
3838 }
39+
40+ @Test
41+ public void testDeleteCheck() throws Exception {
42+ String secret = "dad13ed9f34ffd063cd34abb2320fbbb5c768db4588e319f4444109944b65218";
43+ AccessToken.delete(client, "sheng");
44+ }
3945 }
--- a/java-sdk/src/test/java/io/bytom/integration/AccountTest.java
+++ b/java-sdk/src/test/java/io/bytom/integration/AccountTest.java
@@ -26,10 +26,6 @@ public class AccountTest {
2626 List<String> root_xpubs = new ArrayList<>();
2727 root_xpubs.add("c4b25825e92cd8623de4fd6a35952ad0efb2ed215fdb1b40754f0ed12eff7827d147d1e8b003601ba2f78a4a84dcc77e93ed282633f2679048c5d5ac5ea10cb5");
2828
29-
30-// Key.Builder builder = new Key.Builder().setAlias(alias).setPassword(password);
31-// key = Key.create(client, builder);
32-
3329 Account.Builder builder = new Account.Builder().setAlias(alias).setQuorum(quorum).setRootXpub(root_xpubs);
3430 account = Account.create(client, builder);
3531
@@ -47,9 +43,9 @@ public class AccountTest {
4743 public void testAccountDelete() throws Exception {
4844 client = TestUtils.generateClient();
4945 List<Account> accountList = Account.list(client);
50- String alias = accountList.get(accountList.size()-1).alias;
46+ Account lastAccount = accountList.get(accountList.size()-1);
5147 //delete the last Account Object
52- Account.delete(client, alias);
48+ Account.deleteByAccountAlias(client, lastAccount.alias);
5349 }
5450
5551 @Test
--- a/java-sdk/src/test/java/io/bytom/integration/BlockTest.java
+++ b/java-sdk/src/test/java/io/bytom/integration/BlockTest.java
@@ -23,19 +23,17 @@ public class BlockTest {
2323
2424 static Block block;
2525 static Block.BlockHeader blockHeader;
26- static Block.BlockDifficulty blockDifficulty;
27- static Block.BlockHashRate blockHashRate;
2826
2927 @Test
3028 public void testBlockCountGet() throws Exception {
3129 int count = Block.getBlockCount(client);
32- Assert.assertEquals(158, count);
30+ System.out.println(count);
3331 }
3432
3533 @Test
3634 public void testBlockHashGet() throws Exception {
3735 String blockHash = Block.getBlockHash(client);
38- Assert.assertNotNull(blockHash);
36+ System.out.println(blockHash);
3937 }
4038
4139 @Test
@@ -59,27 +57,4 @@ public class BlockTest {
5957 .setBlockHash(blockHash)
6058 .getBlockHeader(client);
6159 }
62-
63- @Test
64- public void testBlockDifficulty() throws Exception {
65- int height = Block.getBlockCount(client);
66- String blockHash = Block.getBlockHash(client);
67-
68- blockDifficulty = new Block.QueryBuilder()
69- .setBlockHeight(height)
70- .setBlockHash(blockHash)
71- .getBlockDifficulty(client);
72- }
73-
74- @Test
75- public void testBlockHashRate() throws Exception {
76- int height = Block.getBlockCount(client);
77- String blockHash = Block.getBlockHash(client);
78-
79- blockHashRate = new Block.QueryBuilder()
80- .setBlockHeight(height)
81- .setBlockHash(blockHash)
82- .getHashRate(client);
83- }
84-
8560 }
--- a/java-sdk/src/test/java/io/bytom/integration/CoreConfigTest.java
+++ b/java-sdk/src/test/java/io/bytom/integration/CoreConfigTest.java
@@ -35,6 +35,4 @@ public class CoreConfigTest {
3535 Assert.assertNotNull(gasRate);
3636 }
3737
38-
39-
4038 }
--- a/java-sdk/src/test/java/io/bytom/integration/KeyTest.java
+++ b/java-sdk/src/test/java/io/bytom/integration/KeyTest.java
@@ -33,8 +33,7 @@ public class KeyTest {
3333
3434 @Test
3535 public void testClientKeyList() throws Exception {
36- //client = TestUtils.generateClient();
37- client = new Client("http://127.0.0.1:9888/");
36+ client = TestUtils.generateClient();
3837 List<Key> keyList = Key.list(client);
3938 }
4039
--- a/java-sdk/src/test/java/io/bytom/integration/RawTransactionTest.java
+++ b/java-sdk/src/test/java/io/bytom/integration/RawTransactionTest.java
@@ -25,7 +25,7 @@ public class RawTransactionTest {
2525
2626 @Test
2727 public void testRawTxDecode() throws Exception {
28- String rawTxId = "070100010161015f30e052cd50e385951936c08fb5642bd12b727da958960249ddad8c9a77e5371fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8099c4d59901000116001412a47b53b3bbdaf9f3510e1d8c19d69f81ca91426302405a8b5adebd2ab63ba1ac55a7bbadc1fe246806c37732df0442b827fa4e06058137711d9d012becdc9de507a8ad0de0dd50780c0503c0dcff2dc03d7592e31a08206e1efce70e2b29efa348aec7c148edc2beb72edc0d4422a03cfb0f40e6e4cfc602013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80d3bdc6980101160014a9c0ea4abe4d09546197bac3c86f4dd39fde1afb00013cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8084af5f011600144cc6edb1f4077c740e0201bb3688e6efba4a098c00";
28+ String rawTxId = "070100010161015f4894fb81ee71b343a1990dae5655cb99d74abf99d16cf06aad6a3095865ccf9bfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed8fcf5050001160014e933e5a0545c63ff2c28eaedb47c831cac3b16cf006302408b50ffb295d4571e320d3d28982e42ba61d939210be8b5dc4e0d5cd2f45f2b79fb06d98b6f6024208fe9194878e6824c70811f44a1f4fc911f37fd8604de05062006ec50c0c335cd6c4d06b08d12f89ca5af3bd099b159544d4c8818e7c9d6b8af0201003effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaeadaea30501160014e933e5a0545c63ff2c28eaedb47c831cac3b16cf000001003dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd0d1894901160014d69556c7ae252fbcc38fd34a34a3ba21dd0537c10000";
2929 rawTransaction = RawTransaction.decode(client, rawTxId);
3030 Assert.assertNotNull(rawTransaction);
3131 }
--- a/java-sdk/src/test/java/io/bytom/integration/TransactionTest.java
+++ b/java-sdk/src/test/java/io/bytom/integration/TransactionTest.java
@@ -62,7 +62,7 @@ public class TransactionTest {
6262 logger.info("receiver-address:" + receiverAddress.toJson());
6363
6464 senderAsset = new Asset.QueryBuilder().list(client).get(0);
65- receiverAsset = new Asset.QueryBuilder().list(client).get(1);
65+ receiverAsset = new Asset.QueryBuilder().list(client).get(0);
6666 logger.info("senderAsset:" + senderAsset.toJson());
6767 logger.info("receiverAsset:" + receiverAsset.toJson());
6868 }
Afficher sur ancien navigateur de dépôt.