diff --git a/src/main/java/com/cobo/custody/api/client/CoboMPCApiRestClient.java b/src/main/java/com/cobo/custody/api/client/CoboMPCApiRestClient.java index 6707fa4..0c54b0b 100644 --- a/src/main/java/com/cobo/custody/api/client/CoboMPCApiRestClient.java +++ b/src/main/java/com/cobo/custody/api/client/CoboMPCApiRestClient.java @@ -1,10 +1,7 @@ package com.cobo.custody.api.client; import com.cobo.custody.api.client.domain.ApiResponse; -import com.cobo.custody.api.client.domain.account.MPCAddressList; -import com.cobo.custody.api.client.domain.account.MPCAddresses; -import com.cobo.custody.api.client.domain.account.MPCChains; -import com.cobo.custody.api.client.domain.account.MPCCoins; +import com.cobo.custody.api.client.domain.account.*; import com.cobo.custody.api.client.domain.asset.MPCUnspentInputs; import com.cobo.custody.api.client.domain.asset.MPCWalletAsset; import com.cobo.custody.api.client.domain.transaction.*; @@ -13,25 +10,37 @@ public interface CoboMPCApiRestClient { ApiResponse getSupportedChains(); + ApiResponse getSupportedCoins(String chainCode); ApiResponse getMainAddress(String chainCode); ApiResponse batchGenerateAddresses(String chainCode, int count); - ApiResponse getAddressList(String chainCode, int pageIndex, int pageLength, Integer sortFlag); - ApiResponse getWalletAssetList(String address, String chainCode); + + ApiResponse getAddressList(String chainCode, String startId, String endId, Integer limit, Integer sort); + + ApiResponse getBalance(String address, String chainCode, String coin); + + ApiResponse listBalances(String coin, Integer pageIndex, Integer pageLength); + + ApiResponse listSpendable(String coin, String address); + ApiResponse getWalletUnspentInputList(String address, String coin); + ApiResponse createTransaction(String coin, String requestId, String fromAddr, String toAddr, BigInteger amount, String toAddressDetails, BigInteger fee, BigInteger gasPrice, BigInteger gasLimit, - String extraParameters); + Integer operation, String extraParameters); - ApiResponse speedUpTransaction(String coboId, BigInteger fee, BigInteger gasPrice, BigInteger gasLimit); + ApiResponse speedUpTransaction(String coboId, String requestId, BigInteger fee, BigInteger gasPrice, BigInteger gasLimit); - ApiResponse dropTransaction(String coboId, BigInteger fee, BigInteger gasPrice, BigInteger gasLimit); + ApiResponse dropTransaction(String coboId, String requestId, BigInteger fee, BigInteger gasPrice, BigInteger gasLimit); ApiResponse getTransactionByRequestIds(String requestIds, Integer status); + ApiResponse getTransactionByCoboIds(String coboIds, Integer status); + ApiResponse getTransactionByTxHash(String txId, Integer transactionType); + ApiResponse listWalletTransactions(Long startTime, Long endTime, Integer status, String order, Integer transactionType, String coins, String fromAddr, String toAddr, Integer limit); diff --git a/src/main/java/com/cobo/custody/api/client/domain/account/MPCBalance.java b/src/main/java/com/cobo/custody/api/client/domain/account/MPCBalance.java new file mode 100644 index 0000000..0678fa0 --- /dev/null +++ b/src/main/java/com/cobo/custody/api/client/domain/account/MPCBalance.java @@ -0,0 +1,25 @@ +package com.cobo.custody.api.client.domain.account; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class MPCBalance { + @JsonProperty(value = "coin_data") + private List coinData; + + public List getCoinData() { + return coinData; + } + + public void setCoinData(List coinData) { + this.coinData = coinData; + } + + @Override + public String toString() { + return "{" + + "coinData=" + coinData + + '}'; + } +} diff --git a/src/main/java/com/cobo/custody/api/client/domain/account/MPCCoinBalanceDetail.java b/src/main/java/com/cobo/custody/api/client/domain/account/MPCCoinBalanceDetail.java new file mode 100644 index 0000000..de81adc --- /dev/null +++ b/src/main/java/com/cobo/custody/api/client/domain/account/MPCCoinBalanceDetail.java @@ -0,0 +1,96 @@ +package com.cobo.custody.api.client.domain.account; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class MPCCoinBalanceDetail { + @JsonProperty(value = "address") + private String address; + + @JsonProperty(value = "coin") + private String coin; + + @JsonProperty(value = "chain_code") + private String chainCode; + + @JsonProperty(value = "display_code") + private String displayCode; + + @JsonProperty(value = "description") + private String description; + + @JsonProperty(value = "balance") + private String balance; + + @JsonProperty(value = "decimal") + private Integer decimal; + + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getCoin() { + return coin; + } + + public void setCoin(String coin) { + this.coin = coin; + } + + public String getChainCode() { + return chainCode; + } + + public void setChainCode(String chainCode) { + this.chainCode = chainCode; + } + + public String getDisplayCode() { + return displayCode; + } + + public void setDisplayCode(String displayCode) { + this.displayCode = displayCode; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getBalance() { + return balance; + } + + public void setBalance(String balance) { + this.balance = balance; + } + + public Integer getDecimal() { + return decimal; + } + + public void setDecimal(Integer decimal) { + this.decimal = decimal; + } + + @Override + public String toString() { + return "{" + + "address='" + address + '\'' + + ", coin='" + coin + '\'' + + ", chainCode='" + chainCode + '\'' + + ", displayCode='" + displayCode + '\'' + + ", description='" + description + '\'' + + ", balance='" + balance + '\'' + + ", decimal=" + decimal + + '}'; + } +} diff --git a/src/main/java/com/cobo/custody/api/client/domain/account/MPCListBalances.java b/src/main/java/com/cobo/custody/api/client/domain/account/MPCListBalances.java new file mode 100644 index 0000000..8d2452c --- /dev/null +++ b/src/main/java/com/cobo/custody/api/client/domain/account/MPCListBalances.java @@ -0,0 +1,37 @@ +package com.cobo.custody.api.client.domain.account; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class MPCListBalances { + @JsonProperty(value = "coin_data") + private List coinData; + + @JsonProperty(value = "total") + private Integer total; + + public List getCoinData() { + return coinData; + } + + public void setCoinData(List coinData) { + this.coinData = coinData; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + @Override + public String toString() { + return "{" + + "coinData=" + coinData + + ", total=" + total + + '}'; + } +} diff --git a/src/main/java/com/cobo/custody/api/client/domain/account/MPCListSpendable.java b/src/main/java/com/cobo/custody/api/client/domain/account/MPCListSpendable.java new file mode 100644 index 0000000..627bc76 --- /dev/null +++ b/src/main/java/com/cobo/custody/api/client/domain/account/MPCListSpendable.java @@ -0,0 +1,25 @@ +package com.cobo.custody.api.client.domain.account; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class MPCListSpendable { + @JsonProperty(value = "utxos") + private List utxos; + + public List getUtxos() { + return utxos; + } + + public void setUtxos(List utxos) { + this.utxos = utxos; + } + + @Override + public String toString() { + return "{" + + "utxos=" + utxos + + '}'; + } +} diff --git a/src/main/java/com/cobo/custody/api/client/domain/account/UTXO.java b/src/main/java/com/cobo/custody/api/client/domain/account/UTXO.java new file mode 100644 index 0000000..9f8db93 --- /dev/null +++ b/src/main/java/com/cobo/custody/api/client/domain/account/UTXO.java @@ -0,0 +1,78 @@ +package com.cobo.custody.api.client.domain.account; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class UTXO { + @JsonProperty(value = "tx_hash") + private String txHash; + @JsonProperty(value = "vout_n") + private Integer voutN; + @JsonProperty(value = "address") + private String address; + @JsonProperty(value = "amount") + private Integer amount; + @JsonProperty(value = "is_coinbase") + private Boolean isCoinbase; + @JsonProperty(value = "confirmed_number") + private Integer confirmedNumber; + + public String getTxHash() { + return txHash; + } + + public void setTxHash(String txHash) { + this.txHash = txHash; + } + + public Integer getVoutN() { + return voutN; + } + + public void setVoutN(Integer voutN) { + this.voutN = voutN; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public Integer getAmount() { + return amount; + } + + public void setAmount(Integer amount) { + this.amount = amount; + } + + public Boolean getCoinbase() { + return isCoinbase; + } + + public void setCoinbase(Boolean coinbase) { + isCoinbase = coinbase; + } + + public Integer getConfirmedNumber() { + return confirmedNumber; + } + + public void setConfirmedNumber(Integer confirmedNumber) { + this.confirmedNumber = confirmedNumber; + } + + @Override + public String toString() { + return "{" + + "txHash='" + txHash + '\'' + + ", voutN=" + voutN + + ", address='" + address + '\'' + + ", amount=" + amount + + ", isCoinbase=" + isCoinbase + + ", confirmedNumber=" + confirmedNumber + + '}'; + } +} diff --git a/src/main/java/com/cobo/custody/api/client/impl/CoboMPCApiRestClientImpl.java b/src/main/java/com/cobo/custody/api/client/impl/CoboMPCApiRestClientImpl.java index bbce636..67aeda8 100644 --- a/src/main/java/com/cobo/custody/api/client/impl/CoboMPCApiRestClientImpl.java +++ b/src/main/java/com/cobo/custody/api/client/impl/CoboMPCApiRestClientImpl.java @@ -47,15 +47,21 @@ public ApiResponse batchGenerateAddresses(String chainCode, int } @Override - public ApiResponse getAddressList(String chainCode, int pageIndex, int pageLength, Integer sortFlag) { - return executeSync(coboMPCApiService.getAddressList(chainCode, pageIndex, pageLength, sortFlag)); + public ApiResponse getAddressList(String chainCode, String startId, String endId, Integer limit, Integer sort) { + return executeSync(coboMPCApiService.getAddressList(chainCode, startId, endId, limit, sort)); } - @Override - public ApiResponse getWalletAssetList(String address, String chainCode) { - return executeSync(coboMPCApiService.getWalletAssetList(address, chainCode)); + public ApiResponse getBalance(String address, String chainCode, String coin) { + return executeSync(coboMPCApiService.getBalance(address, chainCode, coin)); + } + + public ApiResponse listBalances(String coin, Integer pageIndex, Integer pageLength) { + return executeSync(coboMPCApiService.listBalances(coin, pageIndex, pageLength)); } + public ApiResponse listSpendable(String coin, String address) { + return executeSync(coboMPCApiService.listSpendable(coin, address)); + } @Override public ApiResponse getWalletUnspentInputList(String address, String coin) { @@ -65,19 +71,19 @@ public ApiResponse getWalletUnspentInputList(String address, S @Override public ApiResponse createTransaction(String coin, String requestId, String fromAddr, String toAddr, BigInteger amount, String toAddressDetails, BigInteger fee, BigInteger gasPrice, BigInteger gasLimit, - String extraParameters) { + Integer operation, String extraParameters) { return executeSync(coboMPCApiService.createTransaction(coin, requestId, fromAddr, toAddr, amount, - toAddressDetails, fee, gasPrice, gasLimit, extraParameters)); + toAddressDetails, fee, gasPrice, gasLimit, operation, extraParameters)); } @Override - public ApiResponse speedUpTransaction(String coboId, BigInteger fee, BigInteger gasPrice, BigInteger gasLimit) { - return executeSync(coboMPCApiService.speedUpTransaction(coboId, fee, gasPrice, gasLimit)); + public ApiResponse speedUpTransaction(String coboId, String requestId, BigInteger fee, BigInteger gasPrice, BigInteger gasLimit) { + return executeSync(coboMPCApiService.speedUpTransaction(coboId, requestId, fee, gasPrice, gasLimit)); } @Override - public ApiResponse dropTransaction(String coboId, BigInteger fee, BigInteger gasPrice, BigInteger gasLimit) { - return executeSync(coboMPCApiService.dropTransaction(coboId, fee, gasPrice, gasLimit)); + public ApiResponse dropTransaction(String coboId, String requestId, BigInteger fee, BigInteger gasPrice, BigInteger gasLimit) { + return executeSync(coboMPCApiService.dropTransaction(coboId, requestId, fee, gasPrice, gasLimit)); } @Override diff --git a/src/main/java/com/cobo/custody/api/client/impl/CoboMPCApiService.java b/src/main/java/com/cobo/custody/api/client/impl/CoboMPCApiService.java index 3747fda..e133522 100644 --- a/src/main/java/com/cobo/custody/api/client/impl/CoboMPCApiService.java +++ b/src/main/java/com/cobo/custody/api/client/impl/CoboMPCApiService.java @@ -1,10 +1,7 @@ package com.cobo.custody.api.client.impl; import com.cobo.custody.api.client.domain.ApiResponse; -import com.cobo.custody.api.client.domain.account.MPCAddressList; -import com.cobo.custody.api.client.domain.account.MPCAddresses; -import com.cobo.custody.api.client.domain.account.MPCChains; -import com.cobo.custody.api.client.domain.account.MPCCoins; +import com.cobo.custody.api.client.domain.account.*; import com.cobo.custody.api.client.domain.asset.MPCUnspentInputs; import com.cobo.custody.api.client.domain.asset.MPCWalletAsset; import com.cobo.custody.api.client.domain.transaction.*; @@ -30,13 +27,24 @@ Call> batchGenerateAddresses(@Field("chain_code") St @GET("/v1/custody/mpc/list_addresses/") Call> getAddressList(@Query("chain_code") String chainCode, - @Query("page_index") int pageIndex, - @Query("page_length") int pageLength, - @Query("sort_flag") Integer sortFlag); - - @GET("/v1/custody/mpc/list_assets/") - Call> getWalletAssetList(@Query("address") String address, - @Query("chain_code") String chainCode); + @Query("start_id") String startId, + @Query("end_id") String endId, + @Query("limit") Integer limit, + @Query("sort") Integer sort); + + @GET("/v1/custody/mpc/get_balance/") + Call> getBalance(@Query("address") String address, + @Query("chain_code") String chainCode, + @Query("coin") String coin); + + @GET("/v1/custody/mpc/list_balances/") + Call> listBalances(@Query("coin") String coin, + @Query("page_index") Integer pageIndex, + @Query("page_length") Integer pageLength); + + @GET("/v1/custody/mpc/list_spendable/") + Call> listSpendable(@Query("coin") String coin, + @Query("address") String address); @GET("/v1/custody/mpc/list_unspent_inputs/") Call> getWalletUnspentInputList(@Query("address") String address, @@ -53,11 +61,13 @@ Call> createTransaction(@Field("coin") String co @Field("fee") BigInteger fee, @Field("gas_price") BigInteger gasPrice, @Field("gas_limit") BigInteger gasLimit, + @Field("operation") Integer operation, @Field("extra_parameters") String extraParameters); @FormUrlEncoded @POST("/v1/custody/mpc/speedup_transaction/") Call> speedUpTransaction(@Field("cobo_id") String coboId, + @Field("request_id") String requestId, @Field("fee") BigInteger fee, @Field("gas_price") BigInteger gasPrice, @Field("gas_limit") BigInteger gasLimit); @@ -65,17 +75,18 @@ Call> speedUpTransaction(@Field("cobo_id") Strin @FormUrlEncoded @POST("/v1/custody/mpc/drop_transaction/") Call> dropTransaction(@Field("cobo_id") String coboId, + @Field("request_id") String requestId, @Field("fee") BigInteger fee, @Field("gas_price") BigInteger gasPrice, @Field("gas_limit") BigInteger gasLimit); @GET("/v1/custody/mpc/transactions_by_request_ids/") Call> getTransactionsByRequestIds(@Query("request_ids") String requestIds, - @Query("status") Integer status); + @Query("status") Integer status); @GET("/v1/custody/mpc/transactions_by_cobo_ids/") Call> getTransactionsByCoboIds(@Query("cobo_ids") String coboIds, - @Query("status") Integer status); + @Query("status") Integer status); @GET("/v1/custody/mpc/transactions_by_tx_hash/") Call> getTransactionByTxhash(@Query("tx_hash") String txHash, @@ -97,7 +108,7 @@ Call> estimateFee(@Query("coin") String coin, @Query("amount") BigInteger amount, @Query("address") String address); - @GET("/v1/custody/mpc/list_requests/") + @GET("/v1/custody/mpc/list_tss_node_requests/") Call> listRequests(@Query("request_type") Integer requestType, - @Query("status") Integer status); + @Query("status") Integer status); } diff --git a/src/test/java/com/cobo/custody/api/client/impl/CoboMPCApiRestClientImplTest.java b/src/test/java/com/cobo/custody/api/client/impl/CoboMPCApiRestClientImplTest.java index 3d77acc..69ad39e 100644 --- a/src/test/java/com/cobo/custody/api/client/impl/CoboMPCApiRestClientImplTest.java +++ b/src/test/java/com/cobo/custody/api/client/impl/CoboMPCApiRestClientImplTest.java @@ -19,7 +19,7 @@ public class CoboMPCApiRestClientImplTest { private String MPCAPISecret = ""; private CoboMPCApiRestClient mpcClient; - private Env TestEnv= Env.SANDBOX; + private Env TestEnv = Env.SANDBOX; @BeforeEach public void setUp() throws Exception { @@ -62,19 +62,31 @@ public void testBatchGenerateAddress() { @Test public void testGetAddressList() { String chainCode = "GETH"; - int pageIndex = 1; - int pageLength = 10; - Integer sortFlag = 0; - ApiResponse res = mpcClient.getAddressList(chainCode, pageIndex, pageLength, sortFlag); + String startId = "1"; + String endId = "100000"; + int limit = 50; + int sort = 1; + ApiResponse res = mpcClient.getAddressList(chainCode, startId, endId, limit, sort); System.out.println(res.getResult()); assertTrue(res.isSuccess()); } @Test - public void testGetWalletAssetList() { + public void testGetBalance() { String address = "0x4897e732734a7b4265cf48201b0ad2adb06657ba"; - String chainCode = "GETH"; - ApiResponse res = mpcClient.getWalletAssetList(address, chainCode); + String chainCode = null; + String coin = "GETH"; + ApiResponse res = mpcClient.getBalance(address, chainCode, coin); + System.out.println(res.getResult()); + assertTrue(res.isSuccess()); + } + + @Test + public void testListBalances() { + String coin = "GETH"; + Integer pageIndex = 1; + Integer pageLength = 50; + ApiResponse res = mpcClient.listBalances(coin, pageIndex, pageLength); System.out.println(res.getResult()); assertTrue(res.isSuccess()); } @@ -90,9 +102,10 @@ public void testCreateTransaction() { BigInteger fee = null; BigInteger gasPrice = null; BigInteger gasLimit = null; + Integer operation = null; String extraParameters = null; ApiResponse res = mpcClient.createTransaction(coin, requestId, fromAddr, toAddr, amount, - toAddressDetails, fee, gasPrice, gasLimit, extraParameters); + toAddressDetails, fee, gasPrice, gasLimit, operation, extraParameters); System.out.println(res.getResult()); assertTrue(res.isSuccess()); } @@ -140,4 +153,13 @@ public void testListRequests() { System.out.println(res.getResult()); assertTrue(res.isSuccess()); } + + @Test + public void listSpendable(){ + String coin = "BTC"; + String address = null; + ApiResponse res = mpcClient.listSpendable(coin, address); + System.out.println(res.getResult()); + assertTrue(res.isSuccess()); + } }