From 0f17a4e5ab546b9238bbe8fd934f114a5348a73e Mon Sep 17 00:00:00 2001 From: George <61674316+forcodedancing@users.noreply.github.com> Date: Mon, 1 Jun 2020 17:07:50 +0800 Subject: [PATCH 1/3] Support Mini Token (#80) * add mini token features --- CHANGELOG.md | 5 + pom.xml | 2 +- .../binance/dex/api/client/BinanceDexApi.java | 40 ++++++ .../api/client/BinanceDexApiNodeClient.java | 67 +++++++++ .../api/client/BinanceDexApiRestClient.java | 26 ++++ .../dex/api/client/TransactionConverter.java | 134 ++++++++++++++---- .../dex/api/client/domain/MiniToken.java | 109 ++++++++++++++ .../binance/dex/api/client/domain/Token.java | 9 ++ .../domain/broadcast/MiniTokenIssue.java | 26 ++++ .../domain/broadcast/MiniTokenListing.java | 51 +++++++ .../domain/broadcast/MiniTokenSetURI.java | 41 ++++++ .../domain/broadcast/TinyTokenIssue.java | 26 ++++ .../api/client/domain/broadcast/TxType.java | 6 +- .../client/encoding/message/MessageType.java | 11 +- .../impl/BinanceDexApiNodeClientImpl.java | 30 ++++ .../impl/BinanceDexApiRestClientImpl.java | 85 +++++++++++ src/main/proto/dex.proto | 46 ++++++ .../encoding/message/TestRestClient.java | 52 ++++++- .../examples/BinanceDexWSApiExample.java | 4 +- .../examples/LocalEnvironmentExample.java | 53 +++++++ .../client/examples/NodeClientExample.java | 7 + 21 files changed, 798 insertions(+), 32 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 src/main/java/com/binance/dex/api/client/domain/MiniToken.java create mode 100644 src/main/java/com/binance/dex/api/client/domain/broadcast/MiniTokenIssue.java create mode 100644 src/main/java/com/binance/dex/api/client/domain/broadcast/MiniTokenListing.java create mode 100644 src/main/java/com/binance/dex/api/client/domain/broadcast/MiniTokenSetURI.java create mode 100644 src/main/java/com/binance/dex/api/client/domain/broadcast/TinyTokenIssue.java create mode 100644 src/test/java/com/binance/dex/api/client/examples/LocalEnvironmentExample.java diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b694498 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog +## 1.0.7 +CHAIN UPGRADE +* [\#110](https://github.com/binance-chain/java-sdk/pull/84) [RPC] [API] Add Pending match flag to Depth API response +* [\#115](https://github.com/binance-chain/java-sdk/pull/80) [RPC] [API] Support Mini Token \ No newline at end of file diff --git a/pom.xml b/pom.xml index fdbc174..d5616d3 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.binance.dex.api binance-dex-api-client - 1.0.6 + 1.0.7 2.6.0 diff --git a/src/main/java/com/binance/dex/api/client/BinanceDexApi.java b/src/main/java/com/binance/dex/api/client/BinanceDexApi.java index c6f5324..15523b9 100644 --- a/src/main/java/com/binance/dex/api/client/BinanceDexApi.java +++ b/src/main/java/com/binance/dex/api/client/BinanceDexApi.java @@ -85,4 +85,44 @@ Call getTransactions(@Query("address") String address, @Query(" @POST("api/v1/broadcast") Call> broadcast(@Query("sync") boolean sync, @Body RequestBody transaction); + + @GET("api/v1/mini/tokens") + Call> getMiniTokens(@Query("limit") Integer limit); + + @GET("api/v1/mini/markets") + Call> getMiniMarkets(@Query("limit") Integer limit); + + @GET("api/v1/mini/klines") + Call> getMiniCandlestickBars(@Query("symbol") String symbol, @Query("interval") String interval, + @Query("limit") Integer limit, @Query("startTime") Long startTime, + @Query("endTime") Long endTime); + + @GET("api/v1/mini/orders/open") + Call getMiniOpenOrders(@Query("address") String address, @Query("limit") Integer limit, + @Query("offset") Integer offset, @Query("symbol") String symbol, + @Query("total") Integer total); + + @GET("api/v1/mini/orders/closed") + Call getMiniClosedOrders(@Query("address") String address, @Query("end") Long end, + @Query("limit") Integer limit, @Query("offset") Integer offset, + @Query("side") Integer side, @Query("start") Long start, + @Query("status") List status, @Query("symbol") String symbol, + @Query("total") Integer total); + + @GET("api/v1/mini/orders/{id}") + Call getMiniOrder(@Path("id") String id); + + @GET("api/v1/mini/ticker/24hr") + Call> getMini24HrPriceStatistics(); + + @GET("api/v1/mini/ticker/24hr") + Call> getMini24HrPriceStatistics(@Query("symbol") String symbol); + + @GET("api/v1/mini/trades") + Call getMiniTrades(@Query("address") String address, + @Query("buyerOrderId") String buyerOrderId, @Query("end") Long end, + @Query("height") Long height, @Query("limit") Integer limit, + @Query("offset") Integer offset, @Query("quoteAsset") String quoteAsset, + @Query("sellerOrderId") String sellerOrderId, @Query("side") Integer side, + @Query("start") Long start, @Query("symbol") String symbol, @Query("total") Integer total); } diff --git a/src/main/java/com/binance/dex/api/client/BinanceDexApiNodeClient.java b/src/main/java/com/binance/dex/api/client/BinanceDexApiNodeClient.java index 398b782..be20e33 100644 --- a/src/main/java/com/binance/dex/api/client/BinanceDexApiNodeClient.java +++ b/src/main/java/com/binance/dex/api/client/BinanceDexApiNodeClient.java @@ -32,6 +32,8 @@ public interface BinanceDexApiNodeClient extends BinanceDexApiRestClient { AtomicSwap getSwapByID(String swapID); + MiniToken getMiniTokenInfoBySymbol(String symbol); + @Override default Time getTime() { throw new UnsupportedOperationException(); @@ -132,6 +134,71 @@ default TransactionPage getTransactions(TransactionsRequest request) { throw new UnsupportedOperationException(); } + @Override + default List getMiniTokens(Integer limit) { + throw new UnsupportedOperationException(); + } + + @Override + default List getMiniMarkets(Integer limit) { + throw new UnsupportedOperationException(); + } + + @Override + default List getMiniCandleStickBars(String symbol, CandlestickInterval interval) { + throw new UnsupportedOperationException(); + } + + @Override + default List getMiniCandleStickBars(String symbol, CandlestickInterval interval, Integer limit, Long startTime, Long endTime) { + throw new UnsupportedOperationException(); + } + + @Override + default OrderList getMiniOpenOrders(String address) { + throw new UnsupportedOperationException(); + } + + @Override + default OrderList getMiniOpenOrders(OpenOrdersRequest request) { + throw new UnsupportedOperationException(); + } + + @Override + default OrderList getMiniClosedOrders(String address) { + throw new UnsupportedOperationException(); + } + + @Override + default OrderList getMiniClosedOrders(ClosedOrdersRequest request) { + throw new UnsupportedOperationException(); + } + + @Override + default Order getMiniOrder(String id) { + throw new UnsupportedOperationException(); + } + + @Override + default List getMini24HrPriceStatistics() { + throw new UnsupportedOperationException(); + } + + @Override + default List getMini24HrPriceStatistics(String symbol) { + throw new UnsupportedOperationException(); + } + + @Override + default TradePage getMiniTrades() { + throw new UnsupportedOperationException(); + } + + @Override + default TradePage getMiniTrades(TradesRequest request) { + throw new UnsupportedOperationException(); + } + @Override default List newOrder(NewOrder newOrder, Wallet wallet, TransactionOption options, boolean sync) throws IOException, NoSuchAlgorithmException { throw new UnsupportedOperationException(); diff --git a/src/main/java/com/binance/dex/api/client/BinanceDexApiRestClient.java b/src/main/java/com/binance/dex/api/client/BinanceDexApiRestClient.java index 17706e4..5f8203c 100644 --- a/src/main/java/com/binance/dex/api/client/BinanceDexApiRestClient.java +++ b/src/main/java/com/binance/dex/api/client/BinanceDexApiRestClient.java @@ -60,6 +60,32 @@ public interface BinanceDexApiRestClient { TransactionPage getTransactions(TransactionsRequest request); + List getMiniTokens(Integer limit); + + List getMiniMarkets(Integer limit); + + List getMiniCandleStickBars(String symbol, CandlestickInterval interval); + + List getMiniCandleStickBars(String symbol, CandlestickInterval interval, Integer limit, Long startTime, Long endTime); + + OrderList getMiniOpenOrders(String address); + + OrderList getMiniOpenOrders(OpenOrdersRequest request); + + OrderList getMiniClosedOrders(String address); + + OrderList getMiniClosedOrders(ClosedOrdersRequest request); + + Order getMiniOrder(String id); + + List getMini24HrPriceStatistics(); + + List getMini24HrPriceStatistics(String symbol); + + TradePage getMiniTrades(); + + TradePage getMiniTrades(TradesRequest request); + List newOrder(NewOrder newOrder, Wallet wallet, TransactionOption options, boolean sync) throws IOException, NoSuchAlgorithmException; diff --git a/src/main/java/com/binance/dex/api/client/TransactionConverter.java b/src/main/java/com/binance/dex/api/client/TransactionConverter.java index 960ed76..7e7d6a2 100644 --- a/src/main/java/com/binance/dex/api/client/TransactionConverter.java +++ b/src/main/java/com/binance/dex/api/client/TransactionConverter.java @@ -5,6 +5,8 @@ import com.binance.dex.api.client.domain.broadcast.Burn; import com.binance.dex.api.client.domain.broadcast.CancelOrder; import com.binance.dex.api.client.domain.broadcast.CreateValidator; +import com.binance.dex.api.client.domain.broadcast.MiniTokenIssue; +import com.binance.dex.api.client.domain.broadcast.MiniTokenSetURI; import com.binance.dex.api.client.domain.broadcast.RemoveValidator; import com.binance.dex.api.client.domain.broadcast.Deposit; import com.binance.dex.api.client.domain.broadcast.Issue; @@ -12,6 +14,7 @@ import com.binance.dex.api.client.domain.broadcast.NewOrder; import com.binance.dex.api.client.domain.broadcast.SetAccountFlag; import com.binance.dex.api.client.domain.broadcast.SubmitProposal; +import com.binance.dex.api.client.domain.broadcast.TinyTokenIssue; import com.binance.dex.api.client.domain.broadcast.TokenFreeze; import com.binance.dex.api.client.domain.broadcast.TokenUnfreeze; import com.binance.dex.api.client.domain.broadcast.Transaction; @@ -37,7 +40,7 @@ public class TransactionConverter { private String hrp; - public TransactionConverter(String hrp){ + public TransactionConverter(String hrp) { this.hrp = hrp; } @@ -64,7 +67,7 @@ public List convert(com.binance.dex.api.client.domain.jsonrpc.Block transaction.setResultData(Optional.ofNullable(txMessage.getTx_result()).map(TxResult::getData).orElse(null)); transaction.setSource(stdTx.getSource()); transaction.setSequence(stdSignature.getSequence()); - fillTagsAndEvents(txMessage.getTx_result(),transaction); + fillTagsAndEvents(txMessage.getTx_result(), transaction); return transaction; }).filter(Objects::nonNull).collect(Collectors.toList()); } catch (InvalidProtocolBufferException e) { @@ -72,32 +75,32 @@ public List convert(com.binance.dex.api.client.domain.jsonrpc.Block } } - public void fillTagsAndEvents(TxResult txResult,Transaction transaction){ + public void fillTagsAndEvents(TxResult txResult, Transaction transaction) { boolean hasTags = txResult.getTags() != null && txResult.getTags().size() > 0; boolean hasEvents = txResult.getEvents() != null && txResult.getEvents().size() > 0 && txResult.getEvents().get(0).getAttributes() != null && txResult.getEvents().get(0).getAttributes().size() > 0; - if(hasTags && !hasEvents){ + if (hasTags && !hasEvents) { transaction.setTags(txResult.getTags()); List attributes = txResult.getTags().stream().map(this::convertOf).collect(Collectors.toList()); TxResult.Event event = new TxResult.Event(); event.setAttributes(attributes); transaction.setEvents(Collections.singletonList(event)); - }else if(hasEvents && !hasTags){ + } else if (hasEvents && !hasTags) { transaction.setEvents(txResult.getEvents()); List tags = txResult.getEvents().get(0).getAttributes().stream().map(this::convertOf).collect(Collectors.toList()); transaction.setTags(tags); } } - private TxResult.Attribute convertOf(TxResult.Tag tag){ + private TxResult.Attribute convertOf(TxResult.Tag tag) { TxResult.Attribute attribute = new TxResult.Attribute(); attribute.setKey(tag.getKey()); attribute.setValue(tag.getValue()); return attribute; } - private TxResult.Tag convertOf(TxResult.Attribute attribute){ + private TxResult.Tag convertOf(TxResult.Attribute attribute) { TxResult.Tag tag = new TxResult.Tag(); tag.setKey(attribute.getKey()); tag.setValue(attribute.getValue()); @@ -164,6 +167,14 @@ public Transaction convert(byte[] bytes) { return convertClaimHashTimerLock(bytes); case RefundHashTimerLockMsg: return convertRefundHashTimerLock(bytes); + case TinyTokenIssue: + return convertTinyTokenIssue(bytes); + case MiniTokenIssue: + return convertMiniTokenIssue(bytes); + case MiniTokenSetURI: + return convertMiniTokenSetURI(bytes); + case MiniTokenList: + return convertMiniTokenList(bytes); } return null; @@ -172,13 +183,14 @@ public Transaction convert(byte[] bytes) { } } + private Transaction convertRefundHashTimerLock(byte[] value) throws InvalidProtocolBufferException { byte[] array = new byte[value.length - 4]; System.arraycopy(value, 4, array, 0, array.length); RefundHashTimerLockMsg refundHtlMsg = RefundHashTimerLockMsg.parseFrom(array); RefundHashTimerLock refundHashTimerLock = new RefundHashTimerLock(); - refundHashTimerLock.setFrom(Crypto.encodeAddress(hrp,refundHtlMsg.getFrom().toByteArray())); + refundHashTimerLock.setFrom(Crypto.encodeAddress(hrp, refundHtlMsg.getFrom().toByteArray())); refundHashTimerLock.setSwapID(Hex.toHexString(refundHtlMsg.getSwapId().toByteArray())); Transaction transaction = new Transaction(); @@ -193,7 +205,7 @@ private Transaction convertClaimHashTimerLock(byte[] value) throws InvalidProtoc ClaimHashTimerLockMsg claimHtlMsg = ClaimHashTimerLockMsg.parseFrom(array); ClaimHashTimerLock claimHashTimerLock = new ClaimHashTimerLock(); - claimHashTimerLock.setFrom(Crypto.encodeAddress(hrp,claimHtlMsg.getFrom().toByteArray())); + claimHashTimerLock.setFrom(Crypto.encodeAddress(hrp, claimHtlMsg.getFrom().toByteArray())); claimHashTimerLock.setSwapID(Hex.toHexString(claimHtlMsg.getSwapId().toByteArray())); claimHashTimerLock.setRandomNumber(Hex.toHexString(claimHtlMsg.getRandomNumber().toByteArray())); @@ -209,7 +221,7 @@ private Transaction convertDepositHashTimerLock(byte[] value) throws InvalidProt DepositHashTimerLockMsg depositHtlMsg = DepositHashTimerLockMsg.parseFrom(array); DepositHashTimerLock depositHashTimerLock = new DepositHashTimerLock(); - depositHashTimerLock.setFrom(Crypto.encodeAddress(hrp,depositHtlMsg.getFrom().toByteArray())); + depositHashTimerLock.setFrom(Crypto.encodeAddress(hrp, depositHtlMsg.getFrom().toByteArray())); depositHashTimerLock.setAmount(depositHtlMsg.getAmountList().stream().map(Token::of).collect(Collectors.toList())); depositHashTimerLock.setSwapID(Hex.toHexString(depositHtlMsg.getSwapId().toByteArray())); @@ -226,8 +238,8 @@ private Transaction convertHashTimerLockTransfer(byte[] value) throws InvalidPro HashTimerLockTransferMsg htlTransferMsg = HashTimerLockTransferMsg.parseFrom(array); HashTimerLockTransfer hashTimerLockTransfer = new HashTimerLockTransfer(); - hashTimerLockTransfer.setFrom(Crypto.encodeAddress(hrp,htlTransferMsg.getFrom().toByteArray())); - hashTimerLockTransfer.setTo(Crypto.encodeAddress(hrp,htlTransferMsg.getTo().toByteArray())); + hashTimerLockTransfer.setFrom(Crypto.encodeAddress(hrp, htlTransferMsg.getFrom().toByteArray())); + hashTimerLockTransfer.setTo(Crypto.encodeAddress(hrp, htlTransferMsg.getTo().toByteArray())); hashTimerLockTransfer.setRecipientOtherChain(htlTransferMsg.getRecipientOtherChain()); hashTimerLockTransfer.setSenderOtherChain(htlTransferMsg.getSenderOtherChain()); hashTimerLockTransfer.setRandomNumberHash(Hex.toHexString(htlTransferMsg.getRandomNumberHash().toByteArray())); @@ -248,7 +260,7 @@ private Transaction convertSetAccountFlag(byte[] value) throws InvalidProtocolBu System.arraycopy(value, 4, array, 0, array.length); com.binance.dex.api.proto.SetAccountFlag setAccountFlag = com.binance.dex.api.proto.SetAccountFlag.parseFrom(array); SetAccountFlag saf = new SetAccountFlag(); - saf.setFromAddr(Crypto.encodeAddress(hrp,setAccountFlag.getFrom().toByteArray())); + saf.setFromAddr(Crypto.encodeAddress(hrp, setAccountFlag.getFrom().toByteArray())); saf.setFlags(setAccountFlag.getFlags()); Transaction transaction = new Transaction(); transaction.setTxType(TxType.SetAccountFlag); @@ -261,7 +273,7 @@ private Transaction convertTimeRelock(byte[] value) throws InvalidProtocolBuffer System.arraycopy(value, 4, array, 0, array.length); TimeRelock timeRelock = TimeRelock.parseFrom(array); com.binance.dex.api.client.domain.broadcast.TimeRelock trl = new com.binance.dex.api.client.domain.broadcast.TimeRelock(); - trl.setFromAddr(Crypto.encodeAddress(hrp,timeRelock.getFrom().toByteArray())); + trl.setFromAddr(Crypto.encodeAddress(hrp, timeRelock.getFrom().toByteArray())); trl.setLockId(timeRelock.getTimeLockId()); trl.setLockTime(Date.from(Instant.ofEpochSecond(timeRelock.getLockTime()))); trl.setDescription(timeRelock.getDescription()); @@ -283,7 +295,7 @@ private Transaction convertTimeUnlock(byte[] value) throws InvalidProtocolBuffer System.arraycopy(value, 4, array, 0, array.length); TimeUnlock timeUnlock = TimeUnlock.parseFrom(array); com.binance.dex.api.client.domain.broadcast.TimeUnlock tul = new com.binance.dex.api.client.domain.broadcast.TimeUnlock(); - tul.setFromAddr(Crypto.encodeAddress(hrp,timeUnlock.getFrom().toByteArray())); + tul.setFromAddr(Crypto.encodeAddress(hrp, timeUnlock.getFrom().toByteArray())); tul.setLockId(timeUnlock.getTimeLockId()); Transaction transaction = new Transaction(); @@ -297,7 +309,7 @@ private Transaction convertTimeLock(byte[] value) throws InvalidProtocolBufferEx System.arraycopy(value, 4, array, 0, array.length); TimeLock timeLock = TimeLock.parseFrom(array); com.binance.dex.api.client.domain.broadcast.TimeLock tl = new com.binance.dex.api.client.domain.broadcast.TimeLock(); - tl.setFromAddr(Crypto.encodeAddress(hrp,timeLock.getFrom().toByteArray())); + tl.setFromAddr(Crypto.encodeAddress(hrp, timeLock.getFrom().toByteArray())); tl.setDescription(timeLock.getDescription()); tl.setLockTime(Date.from(Instant.ofEpochSecond(timeLock.getLockTime()))); List amount = timeLock.getAmountList().stream().map(token -> { @@ -507,10 +519,10 @@ private Transaction convertDeposit(byte[] value) throws InvalidProtocolBufferExc Deposit deposit = new Deposit(); deposit.setProposalId(depositMessage.getProposalId()); - deposit.setDepositer(Crypto.encodeAddress(hrp,depositMessage.getDepositer().toByteArray())); - if(null != depositMessage.getAmountList()){ + deposit.setDepositer(Crypto.encodeAddress(hrp, depositMessage.getDepositer().toByteArray())); + if (null != depositMessage.getAmountList()) { deposit.setAmount(depositMessage.getAmountList().stream() - .map(com.binance.dex.api.client.encoding.message.Token::of).collect(Collectors.toList())); + .map(com.binance.dex.api.client.encoding.message.Token::of).collect(Collectors.toList())); } Transaction transaction = new Transaction(); transaction.setTxType(TxType.DEPOSIT); @@ -525,8 +537,8 @@ private Transaction convertCreateValidator(byte[] value) throws InvalidProtocolB RealCreateValidator realCreateValidator = RealCreateValidator.parseFrom(array); CreateValidator createValidator = new CreateValidator(); - createValidator.setDelegatorAddress(Crypto.encodeAddress(hrp,realCreateValidator.getCreateValidator().getDelegatorAddress().toByteArray())); - createValidator.setValidatorAddress(Crypto.encodeAddress(hrp,realCreateValidator.getCreateValidator().getValidatorAddress().toByteArray())); + createValidator.setDelegatorAddress(Crypto.encodeAddress(hrp, realCreateValidator.getCreateValidator().getDelegatorAddress().toByteArray())); + createValidator.setValidatorAddress(Crypto.encodeAddress(hrp, realCreateValidator.getCreateValidator().getValidatorAddress().toByteArray())); createValidator.setDelegation(com.binance.dex.api.client.encoding.message.Token.of(realCreateValidator.getCreateValidator().getDelegation())); createValidator.setProposalId(realCreateValidator.getProposalId()); @@ -542,9 +554,9 @@ private Transaction convertRemoveValidator(byte[] value) throws InvalidProtocolB com.binance.dex.api.proto.RemoveValidator removeValidatorMessage = com.binance.dex.api.proto.RemoveValidator.parseFrom(array); RemoveValidator removeValidator = new RemoveValidator(); - removeValidator.setLauncherAddr(Crypto.encodeAddress(hrp,removeValidatorMessage.getLauncherAddr().toByteArray())); - removeValidator.setValAddr(Crypto.encodeAddress(hrp,removeValidatorMessage.getValAddr().toByteArray())); - removeValidator.setValConsAddr(Crypto.encodeAddress(hrp,removeValidatorMessage.getValConsAddr().toByteArray())); + removeValidator.setLauncherAddr(Crypto.encodeAddress(hrp, removeValidatorMessage.getLauncherAddr().toByteArray())); + removeValidator.setValAddr(Crypto.encodeAddress(hrp, removeValidatorMessage.getValAddr().toByteArray())); + removeValidator.setValConsAddr(Crypto.encodeAddress(hrp, removeValidatorMessage.getValConsAddr().toByteArray())); removeValidator.setProposalId(removeValidatorMessage.getProposalId()); Transaction transaction = new Transaction(); @@ -564,7 +576,7 @@ private Transaction convertListing(byte[] value) throws InvalidProtocolBufferExc listing.setBaseAssetSymbol(listMessage.getBaseAssetSymbol()); listing.setQuoteAssetSymbol(listMessage.getQuoteAssetSymbol()); listing.setInitPrice(listMessage.getInitPrice()); - listing.setFromAddr(Crypto.encodeAddress(hrp,listMessage.getFrom().toByteArray())); + listing.setFromAddr(Crypto.encodeAddress(hrp, listMessage.getFrom().toByteArray())); Transaction transaction = new Transaction(); transaction.setTxType(TxType.LISTING); @@ -573,4 +585,76 @@ private Transaction convertListing(byte[] value) throws InvalidProtocolBufferExc } + private Transaction convertTinyTokenIssue(byte[] value) throws InvalidProtocolBufferException { + byte[] array = new byte[value.length - 4]; + System.arraycopy(value, 4, array, 0, array.length); + com.binance.dex.api.proto.TinyTokenIssue issueMessage = com.binance.dex.api.proto.TinyTokenIssue.parseFrom(array); + + TinyTokenIssue issue = new TinyTokenIssue(); + issue.setFrom(Crypto.encodeAddress(hrp, issueMessage.getFrom().toByteArray())); + issue.setName(issueMessage.getName()); + issue.setSymbol(issueMessage.getSymbol()); + issue.setTotalSupply(issueMessage.getTotalSupply()); + issue.setMintable(issueMessage.getMintable()); + issue.setTokenURI(issueMessage.getTokenUri()); + + Transaction transaction = new Transaction(); + transaction.setTxType(TxType.TINY_TOKEN_ISSUE); + transaction.setRealTx(issue); + return transaction; + } + + + private Transaction convertMiniTokenIssue(byte[] value) throws InvalidProtocolBufferException { + byte[] array = new byte[value.length - 4]; + System.arraycopy(value, 4, array, 0, array.length); + com.binance.dex.api.proto.MiniTokenIssue issueMessage = com.binance.dex.api.proto.MiniTokenIssue.parseFrom(array); + + MiniTokenIssue issue = new MiniTokenIssue(); + issue.setFrom(Crypto.encodeAddress(hrp, issueMessage.getFrom().toByteArray())); + issue.setName(issueMessage.getName()); + issue.setSymbol(issueMessage.getSymbol()); + issue.setTotalSupply(issueMessage.getTotalSupply()); + issue.setMintable(issueMessage.getMintable()); + issue.setTokenURI(issueMessage.getTokenUri()); + + Transaction transaction = new Transaction(); + transaction.setTxType(TxType.MINI_TOKEN_ISSUE); + transaction.setRealTx(issue); + return transaction; + } + + + private Transaction convertMiniTokenSetURI(byte[] value) throws InvalidProtocolBufferException { + byte[] array = new byte[value.length - 4]; + System.arraycopy(value, 4, array, 0, array.length); + com.binance.dex.api.proto.MiniTokenSetURI uriMessage = com.binance.dex.api.proto.MiniTokenSetURI.parseFrom(array); + + MiniTokenSetURI setURI = new MiniTokenSetURI(); + setURI.setFrom(Crypto.encodeAddress(hrp, uriMessage.getFrom().toByteArray())); + setURI.setSymbol(uriMessage.getSymbol()); + setURI.setTokenURI(uriMessage.getTokenUri()); + + Transaction transaction = new Transaction(); + transaction.setTxType(TxType.MINI_TOKEN_SET_URI); + transaction.setRealTx(setURI); + return transaction; + } + + private Transaction convertMiniTokenList(byte[] value) throws InvalidProtocolBufferException { + byte[] array = new byte[value.length - 4]; + System.arraycopy(value, 4, array, 0, array.length); + com.binance.dex.api.proto.MiniTokenList listMessage = com.binance.dex.api.proto.MiniTokenList.parseFrom(array); + + MiniTokenListing listing = new MiniTokenListing(); + listing.setFromAddr(Crypto.encodeAddress(hrp, listMessage.getFrom().toByteArray())); + listing.setBaseAssetSymbol(listMessage.getBaseAssetSymbol()); + listing.setQuoteAssetSymbol(listMessage.getQuoteAssetSymbol()); + listing.setInitPrice(listMessage.getInitPrice()); + + Transaction transaction = new Transaction(); + transaction.setTxType(TxType.MINI_TOKEN_LIST); + transaction.setRealTx(listing); + return transaction; + } } diff --git a/src/main/java/com/binance/dex/api/client/domain/MiniToken.java b/src/main/java/com/binance/dex/api/client/domain/MiniToken.java new file mode 100644 index 0000000..f9993c1 --- /dev/null +++ b/src/main/java/com/binance/dex/api/client/domain/MiniToken.java @@ -0,0 +1,109 @@ +package com.binance.dex.api.client.domain; + +import com.binance.dex.api.client.BinanceDexConstants; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.ToStringBuilder; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class MiniToken { + private String name; + private String symbol; + @JsonProperty("original_symbol") + private String originalSymbol; + @JsonProperty("total_supply") + private Long totalSupply; + @JsonProperty("token_type") + private Integer tokenType; + @JsonProperty("token_uri") + private String tokenURI; + private String owner; + private boolean mintable; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } + + public String getOriginalSymbol() { + return originalSymbol; + } + + public void setOriginalSymbol(String originalSymbol) { + this.originalSymbol = originalSymbol; + } + + public Long getTotalSupply() { + return totalSupply; + } + + public void setTotalSupply(Long totalSupply) { + this.totalSupply = totalSupply; + } + + public Integer getTokenType() { + return tokenType; + } + + public void setTokenType(Integer tokenType) { + this.tokenType = tokenType; + } + + public String getTokenURI() { + return tokenURI; + } + + public void setTokenURI(String tokenURI) { + this.tokenURI = tokenURI; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public boolean isMintable() { + return mintable; + } + + public void setMintable(boolean mintable) { + this.mintable = mintable; + } + + public void setTotalSupply(String totalSupply){ + if (totalSupply != null) { + if (totalSupply.indexOf('.') > 0) { + totalSupply = totalSupply.substring(0, totalSupply.indexOf('.')); + this.totalSupply = Long.parseLong(totalSupply) * 100000000L; + } + } + } + + @Override + public String toString() { + return new ToStringBuilder(this, BinanceDexConstants.BINANCE_DEX_TO_STRING_STYLE) + .append("name", name) + .append("symbol", symbol) + .append("originalSymbol", originalSymbol) + .append("totalSupply", totalSupply) + .append("tokenType", tokenType) + .append("tokenURI", tokenURI) + .append("owner", owner) + .append("mintable", mintable) + .toString(); + } +} diff --git a/src/main/java/com/binance/dex/api/client/domain/Token.java b/src/main/java/com/binance/dex/api/client/domain/Token.java index 30c5060..970eccd 100644 --- a/src/main/java/com/binance/dex/api/client/domain/Token.java +++ b/src/main/java/com/binance/dex/api/client/domain/Token.java @@ -75,4 +75,13 @@ public void setTotalSupply(Long totalSupply) { public Long getTotalSupply() { return totalSupply; } + + public void setTotalSupply(String totalSupply){ + if (totalSupply != null) { + if (totalSupply.indexOf('.') > 0) { + totalSupply = totalSupply.substring(0, totalSupply.indexOf('.')); + this.totalSupply = Long.parseLong(totalSupply) * 100000000L; + } + } + } } diff --git a/src/main/java/com/binance/dex/api/client/domain/broadcast/MiniTokenIssue.java b/src/main/java/com/binance/dex/api/client/domain/broadcast/MiniTokenIssue.java new file mode 100644 index 0000000..7edfd26 --- /dev/null +++ b/src/main/java/com/binance/dex/api/client/domain/broadcast/MiniTokenIssue.java @@ -0,0 +1,26 @@ +package com.binance.dex.api.client.domain.broadcast; + +public class MiniTokenIssue extends Issue { + private String tokenURI; + + public String getTokenURI() { + return tokenURI; + } + + public void setTokenURI(String tokenURI) { + this.tokenURI = tokenURI; + } + + @Override + public String toString() { + return "MiniTokenIssue{" + + "from='" + super.getFrom() + '\'' + + ", name='" + super.getName() + '\'' + + ", symbol='" + super.getSymbol() + '\'' + + ", totalSupply=" + super.getTotalSupply() + + ", tokenURI=" + tokenURI + + ", mintable=" + super.getMintable() + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/binance/dex/api/client/domain/broadcast/MiniTokenListing.java b/src/main/java/com/binance/dex/api/client/domain/broadcast/MiniTokenListing.java new file mode 100644 index 0000000..8476112 --- /dev/null +++ b/src/main/java/com/binance/dex/api/client/domain/broadcast/MiniTokenListing.java @@ -0,0 +1,51 @@ +package com.binance.dex.api.client.domain.broadcast; + +public class MiniTokenListing { + + private String fromAddr; + private String baseAssetSymbol; + private String quoteAssetSymbol; + private Long initPrice; + + public String getFromAddr() { + return fromAddr; + } + + public void setFromAddr(String fromAddr) { + this.fromAddr = fromAddr; + } + + public String getBaseAssetSymbol() { + return baseAssetSymbol; + } + + public void setBaseAssetSymbol(String baseAssetSymbol) { + this.baseAssetSymbol = baseAssetSymbol; + } + + public String getQuoteAssetSymbol() { + return quoteAssetSymbol; + } + + public void setQuoteAssetSymbol(String quoteAssetSymbol) { + this.quoteAssetSymbol = quoteAssetSymbol; + } + + public Long getInitPrice() { + return initPrice; + } + + public void setInitPrice(Long initPrice) { + this.initPrice = initPrice; + } + + @Override + public String toString() { + return "MiniTokenListing{" + + "fromAddr='" + fromAddr + '\'' + + ", baseAssetSymbol='" + baseAssetSymbol + '\'' + + ", quoteAssetSymbol='" + quoteAssetSymbol + '\'' + + ", initPrice=" + initPrice + + '}'; + } +} diff --git a/src/main/java/com/binance/dex/api/client/domain/broadcast/MiniTokenSetURI.java b/src/main/java/com/binance/dex/api/client/domain/broadcast/MiniTokenSetURI.java new file mode 100644 index 0000000..428852c --- /dev/null +++ b/src/main/java/com/binance/dex/api/client/domain/broadcast/MiniTokenSetURI.java @@ -0,0 +1,41 @@ +package com.binance.dex.api.client.domain.broadcast; + +public class MiniTokenSetURI { + + private String from; + private String symbol; + private String tokenURI; + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } + + public String getTokenURI() { + return tokenURI; + } + + public void setTokenURI(String tokenURI) { + this.tokenURI = tokenURI; + } + + @Override + public String toString() { + return "MiniTokenSetURI{" + + "from='" + from + '\'' + + ", symbol='" + symbol + '\'' + + ", tokenURI='" + tokenURI + '\'' + + '}'; + } +} diff --git a/src/main/java/com/binance/dex/api/client/domain/broadcast/TinyTokenIssue.java b/src/main/java/com/binance/dex/api/client/domain/broadcast/TinyTokenIssue.java new file mode 100644 index 0000000..617571b --- /dev/null +++ b/src/main/java/com/binance/dex/api/client/domain/broadcast/TinyTokenIssue.java @@ -0,0 +1,26 @@ +package com.binance.dex.api.client.domain.broadcast; + +public class TinyTokenIssue extends Issue { + private String tokenURI; + + public String getTokenURI() { + return tokenURI; + } + + public void setTokenURI(String tokenURI) { + this.tokenURI = tokenURI; + } + + @Override + public String toString() { + return "TinyTokenIssue{" + + "from='" + super.getFrom() + '\'' + + ", name='" + super.getName() + '\'' + + ", symbol='" + super.getSymbol() + '\'' + + ", totalSupply=" + super.getTotalSupply() + + ", tokenURI=" + tokenURI + + ", mintable=" + super.getMintable() + + '}'; + } + +} \ No newline at end of file diff --git a/src/main/java/com/binance/dex/api/client/domain/broadcast/TxType.java b/src/main/java/com/binance/dex/api/client/domain/broadcast/TxType.java index ca50fdd..03107b2 100644 --- a/src/main/java/com/binance/dex/api/client/domain/broadcast/TxType.java +++ b/src/main/java/com/binance/dex/api/client/domain/broadcast/TxType.java @@ -22,5 +22,9 @@ public enum TxType { HTL_TRANSFER, CLAIM_HTL, REFUND_HTL, - DEPOSIT_HTL + DEPOSIT_HTL, + TINY_TOKEN_ISSUE, + MINI_TOKEN_ISSUE, + MINI_TOKEN_SET_URI, + MINI_TOKEN_LIST } diff --git a/src/main/java/com/binance/dex/api/client/encoding/message/MessageType.java b/src/main/java/com/binance/dex/api/client/encoding/message/MessageType.java index b3bd921..7690ee2 100644 --- a/src/main/java/com/binance/dex/api/client/encoding/message/MessageType.java +++ b/src/main/java/com/binance/dex/api/client/encoding/message/MessageType.java @@ -5,7 +5,7 @@ import java.util.Arrays; /** - * Binance dex standard transactiont types. + * Binance dex standard transaction types. */ public enum MessageType { Send("2A2C87FA"), @@ -32,7 +32,14 @@ public enum MessageType { HashTimerLockTransferMsg("B33F9A24"), DepositHashTimerLockMsg("63986496"), ClaimHashTimerLockMsg("C1665300"), - RefundHashTimerLockMsg("3454A27C"); + RefundHashTimerLockMsg("3454A27C"), + + //mini token + TinyTokenIssue("ED2832D4"), + MiniTokenIssue("A3F16C41"), + MiniTokenSetURI("7B1D34E7"), + MiniTokenList("4C264019"); + private byte[] typePrefixBytes; MessageType(String typePrefix) { diff --git a/src/main/java/com/binance/dex/api/client/impl/BinanceDexApiNodeClientImpl.java b/src/main/java/com/binance/dex/api/client/impl/BinanceDexApiNodeClientImpl.java index e964d5b..f820b44 100644 --- a/src/main/java/com/binance/dex/api/client/impl/BinanceDexApiNodeClientImpl.java +++ b/src/main/java/com/binance/dex/api/client/impl/BinanceDexApiNodeClientImpl.java @@ -351,6 +351,23 @@ public List broadcast(String payload, boolean sync) { } } + @Override + public com.binance.dex.api.client.domain.MiniToken getMiniTokenInfoBySymbol(String symbol) { + try { + String pathWithSymbol = "\"mini-tokens/info/" + symbol + "\""; + JsonRpcResponse rpcResponse = BinanceDexApiClientGenerator.executeSync(binanceDexNodeApi.getTokenInfo(pathWithSymbol)); + checkRpcResult(rpcResponse); + byte[] value = rpcResponse.getResult().getResponse().getValue(); + int startIndex = getStartIndex(value); + byte[] array = new byte[value.length - startIndex]; + System.arraycopy(value, startIndex, array, 0, array.length); + MiniTokenInfo tokenInfo = MiniTokenInfo.parseFrom(array); + return convert(tokenInfo); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + protected Infos convert(NodeInfos nodeInfos) { Infos infos = new Infos(); @@ -404,6 +421,19 @@ protected com.binance.dex.api.client.domain.Token convert(TokenInfo tokenInfo) { return token; } + protected com.binance.dex.api.client.domain.MiniToken convert(MiniTokenInfo tokenInfo) { + com.binance.dex.api.client.domain.MiniToken token = new com.binance.dex.api.client.domain.MiniToken(); + token.setName(tokenInfo.getName()); + token.setOriginalSymbol(tokenInfo.getOriginalSymbol()); + token.setSymbol(tokenInfo.getSymbol()); + token.setOwner(Crypto.encodeAddress(hrp, tokenInfo.getOwner().toByteArray())); + token.setTotalSupply(tokenInfo.getTotalSupply()); + token.setMintable(tokenInfo.getMintable()); + token.setTokenType(tokenInfo.getTokenType()); + token.setTokenURI(tokenInfo.getTokenUri()); + return token; + } + protected List syncBroadcast(String requestBody, Wallet wallet) { try { JsonRpcResponse rpcResponse = BinanceDexApiClientGenerator.executeSync(binanceDexNodeApi.commitBroadcast(requestBody)); diff --git a/src/main/java/com/binance/dex/api/client/impl/BinanceDexApiRestClientImpl.java b/src/main/java/com/binance/dex/api/client/impl/BinanceDexApiRestClientImpl.java index 081d0e2..e6fa28b 100644 --- a/src/main/java/com/binance/dex/api/client/impl/BinanceDexApiRestClientImpl.java +++ b/src/main/java/com/binance/dex/api/client/impl/BinanceDexApiRestClientImpl.java @@ -179,6 +179,91 @@ private List broadcast(RequestBody requestBody, boolean syn } } + @Override + public List getMiniTokens(Integer limit) { + return BinanceDexApiClientGenerator.executeSync(binanceDexApi.getMiniTokens(limit)); + } + + @Override + public List getMiniMarkets(Integer limit) { + return BinanceDexApiClientGenerator.executeSync(binanceDexApi.getMiniMarkets(limit)); + } + + @Override + public List getMiniCandleStickBars(String symbol, CandlestickInterval interval) { + return getMiniCandleStickBars(symbol, interval, null, null, null); + } + + @Override + public List getMiniCandleStickBars(String symbol, CandlestickInterval interval, Integer limit, Long startTime, Long endTime) { + return BinanceDexApiClientGenerator.executeSync(binanceDexApi.getMiniCandlestickBars(symbol, interval.getIntervalId(), limit, startTime, endTime)); + } + + @Override + public OrderList getMiniOpenOrders(String address) { + OpenOrdersRequest request = new OpenOrdersRequest(); + request.setAddress(address); + return getMiniOpenOrders(request); + } + + @Override + public OrderList getMiniOpenOrders(OpenOrdersRequest request) { + return BinanceDexApiClientGenerator.executeSync( + binanceDexApi.getMiniOpenOrders(request.getAddress(), request.getLimit(), + request.getOffset(), request.getSymbol(), request.getTotal())); + } + + @Override + public OrderList getMiniClosedOrders(String address) { + ClosedOrdersRequest request = new ClosedOrdersRequest(); + request.setAddress(address); + return getMiniClosedOrders(request); + } + + @Override + public OrderList getMiniClosedOrders(ClosedOrdersRequest request) { + Integer side = request.getSide() == null ? null : (int)(request.getSide().toValue()); + List statusStrList = null; + if (request.getStatus() != null) + statusStrList = request.getStatus().stream().map(s -> s.name()).collect(Collectors.toList()); + return BinanceDexApiClientGenerator.executeSync( + binanceDexApi.getMiniClosedOrders(request.getAddress(), request.getEnd(), request.getLimit(), + request.getLimit(), side, request.getStart(), statusStrList, request.getSymbol(), + request.getTotal())); + } + + @Override + public Order getMiniOrder(String id) { + return BinanceDexApiClientGenerator.executeSync(binanceDexApi.getMiniOrder(id)); + } + + @Override + public List getMini24HrPriceStatistics() { + return BinanceDexApiClientGenerator.executeSync(binanceDexApi.getMini24HrPriceStatistics()); + } + + @Override + public List getMini24HrPriceStatistics(String symbol) { + return BinanceDexApiClientGenerator.executeSync(binanceDexApi.getMini24HrPriceStatistics(symbol)); + } + + @Override + public TradePage getMiniTrades() { + TradesRequest request = new TradesRequest(); + return getMiniTrades(request); + } + + @Override + public TradePage getMiniTrades(TradesRequest request) { + Integer side = request.getSide() == null ? null : (int)(request.getSide().toValue()); + return BinanceDexApiClientGenerator.executeSync( + binanceDexApi.getMiniTrades( + request.getAddress(), request.getBuyerOrderId(), + request.getEnd(), request.getHeight(), request.getLimit(), request.getOffset(), + request.getQuoteAsset(), request.getSellerOrderId(), side, + request.getStart(), request.getSymbol(), request.getTotal())); + } + public List newOrder(NewOrder newOrder, Wallet wallet, TransactionOption options, boolean sync) throws IOException, NoSuchAlgorithmException { wallet.ensureWalletIsReady(this); diff --git a/src/main/proto/dex.proto b/src/main/proto/dex.proto index a46f521..0f2df31 100644 --- a/src/main/proto/dex.proto +++ b/src/main/proto/dex.proto @@ -148,6 +148,16 @@ message TokenInfo{ bool mintable = 6; } +message MiniTokenInfo{ + string name = 1; + string symbol = 2; + string original_symbol = 3; + int64 total_supply = 4; + bytes owner = 5; + bool mintable = 6; + int32 token_type = 7; + string token_uri = 8; +} message DexFeeParam { // 0x495A5044 @@ -345,4 +355,40 @@ message RefundHashTimerLockMsg { // bytes from = 1; bytes swap_id = 2; +} + +//mini token issue +message TinyTokenIssue { + // ED2832D4 // hardcoded, object type prefix in 4 bytes + bytes from = 1; // issue token owner + string name = 2; + string symbol = 3; + int64 total_supply = 4; + bool mintable = 5; + string token_uri = 6; +} + +message MiniTokenIssue { + // A3F16C41 // hardcoded, object type prefix in 4 bytes + bytes from = 1; // issue token owner + string name = 2; + string symbol = 3; + int64 total_supply = 4; + bool mintable = 5; + string token_uri = 6; +} + +message MiniTokenSetURI { + // 7B1D34E7 // hardcoded, object type prefix in 4 bytes + bytes from = 1; // issue token owner + string symbol = 2; + string token_uri = 3; +} + +message MiniTokenList { + // 4C264019 // hardcoded, object type prefix in 4 bytes + bytes from = 1; + string base_asset_symbol = 2; + string quote_asset_symbol = 3; + int64 init_price = 4; } \ No newline at end of file diff --git a/src/test/java/com/binance/dex/api/client/encoding/message/TestRestClient.java b/src/test/java/com/binance/dex/api/client/encoding/message/TestRestClient.java index 92fa924..dec51f8 100644 --- a/src/test/java/com/binance/dex/api/client/encoding/message/TestRestClient.java +++ b/src/test/java/com/binance/dex/api/client/encoding/message/TestRestClient.java @@ -14,12 +14,14 @@ @Ignore("Manual run only") public class TestRestClient { private BinanceDexApiRestClient client = - BinanceDexApiClientFactory.newInstance().newRestClient(BinanceDexEnvironment.TEST_NET.getBaseUrl()); + BinanceDexApiClientFactory.newInstance().newRestClient("https://dex-api.fdgahl.cn"); private String address = "tbnb16hywxpvvkaz6cecjz89mf2w0da3vfeg6z6yky2"; private String symbol = "ADA.B-F2F_BNB"; + private String miniSymbol = "MSDK-400M_BNB"; + @Test public void testGetMarkets() { List mkts = client.getMarkets(1000); @@ -125,4 +127,52 @@ public void testGetFees() { List fees = client.getFees(); System.out.println(fees); } + + @Test + public void testGetMiniToken() { + List tokens = client.getMiniTokens(100); + System.out.println(tokens); + } + + @Test + public void testGetMiniMarkets() { + List mkts = client.getMiniMarkets(1000); + for (Market m : mkts) { + System.out.println(m); + } + } + + @Test + public void testGetMiniCandlestickBars() { + List klines = client.getMiniCandleStickBars(miniSymbol, CandlestickInterval.HOURLY); + System.out.println(klines); + + System.out.println(client.getMiniCandleStickBars(miniSymbol, CandlestickInterval.ONE_MINUTE, + 10, System.currentTimeMillis() - 24L * 60 * 60 * 1000L, null)); + } + + @Test + public void testGetMiniOpenOrders() { + System.out.println(client.getMiniOpenOrders(address)); + } + + @Test + public void testGetMiniClosedOrders() { + System.out.println(client.getMiniClosedOrders(address)); + } + + @Test + public void testGetMini24HrPriceStatistics() { + System.out.println(client.getMini24HrPriceStatistics()); + System.out.println(client.getMini24HrPriceStatistics(miniSymbol)); + } + + @Test + public void testGetMiniTrades() { + System.out.println(client.getMiniTrades()); + TradesRequest request = new TradesRequest(); + request.setAddress(address); + request.setLimit(10); + System.out.println(client.getMiniTrades(request)); + } } diff --git a/src/test/java/com/binance/dex/api/client/examples/BinanceDexWSApiExample.java b/src/test/java/com/binance/dex/api/client/examples/BinanceDexWSApiExample.java index b040617..f85465c 100644 --- a/src/test/java/com/binance/dex/api/client/examples/BinanceDexWSApiExample.java +++ b/src/test/java/com/binance/dex/api/client/examples/BinanceDexWSApiExample.java @@ -54,9 +54,9 @@ public void testNetInfo(){ @Test public void testBlockByHeight() { - BlockMeta.BlockMetaResult result = binanceDexWSApi.blockByHeight(13513018L); + BlockMeta.BlockMetaResult result = binanceDexWSApi.blockByHeight(18L); Assert.assertNotNull(result); - Assert.assertEquals(13513018L,result.getBlockMeta().getHeader().getHeight().longValue()); + Assert.assertEquals(18L,result.getBlockMeta().getHeader().getHeight().longValue()); } @Test diff --git a/src/test/java/com/binance/dex/api/client/examples/LocalEnvironmentExample.java b/src/test/java/com/binance/dex/api/client/examples/LocalEnvironmentExample.java new file mode 100644 index 0000000..40e0a99 --- /dev/null +++ b/src/test/java/com/binance/dex/api/client/examples/LocalEnvironmentExample.java @@ -0,0 +1,53 @@ +package com.binance.dex.api.client.examples; + +import com.binance.dex.api.client.BinanceDexApiClientFactory; +import com.binance.dex.api.client.BinanceDexApiNodeClient; +import com.binance.dex.api.client.BinanceDexEnvironment; +import com.binance.dex.api.client.domain.broadcast.Transaction; +import com.binance.dex.api.client.domain.broadcast.TxType; +import org.junit.Assert; + +import java.util.List; + +public class LocalEnvironmentExample { + public static void main(String[] args) { + BinanceDexEnvironment env = new BinanceDexEnvironment( + "http://seed-qa-s3.fdgahl.cn:80", + "", + "http://seed-qa-s3.fdgahl.cn:80", + "", + "tbnb"); + + + BinanceDexApiNodeClient binanceDexNodeApi = BinanceDexApiClientFactory.newInstance().newNodeRpcClient(env.getNodeUrl(), env.getHrp()); +// Long height = 225L; +// List transactions = binanceDexNodeApi.getBlockTransactions(height); +// Assert.assertNotNull(transactions); +// Assert.assertTrue(transactions.size() == 1); +// Assert.assertEquals(transactions.get(0).getTxType(), TxType.MINI_TOKEN_ISSUE); +// +// height = 228L; +// transactions = binanceDexNodeApi.getBlockTransactions(height); +// Assert.assertNotNull(transactions); +// Assert.assertTrue(transactions.size() == 1); +// Assert.assertEquals(transactions.get(0).getTxType(), TxType.MINI_TOKEN_LIST); + + Long height = 1892273L; + List transactions = binanceDexNodeApi.getBlockTransactions(height); + Assert.assertNotNull(transactions); + Assert.assertTrue(transactions.size() == 1); + Assert.assertEquals(transactions.get(0).getTxType(), TxType.TINY_TOKEN_ISSUE); + + height = 148L; + transactions = binanceDexNodeApi.getBlockTransactions(height); + Assert.assertNotNull(transactions); + Assert.assertTrue(transactions.size() == 1); + Assert.assertEquals(transactions.get(0).getTxType(), TxType.MINI_TOKEN_LIST); + + height = 4747L; + transactions = binanceDexNodeApi.getBlockTransactions(height); + Assert.assertNotNull(transactions); + Assert.assertTrue(transactions.size() == 1); + Assert.assertEquals(transactions.get(0).getTxType(), TxType.MINI_TOKEN_SET_URI); + } +} diff --git a/src/test/java/com/binance/dex/api/client/examples/NodeClientExample.java b/src/test/java/com/binance/dex/api/client/examples/NodeClientExample.java index 2c20c8a..4c8bd52 100644 --- a/src/test/java/com/binance/dex/api/client/examples/NodeClientExample.java +++ b/src/test/java/com/binance/dex/api/client/examples/NodeClientExample.java @@ -232,6 +232,13 @@ public void testGetTokenInfoBySymbol(){ Assert.assertEquals("BNB",token.getSymbol()); } + @Test + public void testGetMiniTokenInfoBySymbol(){ + MiniToken token = binanceDexNodeApi.getMiniTokenInfoBySymbol("AT10-1DEM"); + Assert.assertNotNull(token); + Assert.assertEquals("AT10-1DEM",token.getSymbol()); + } + @Test public void testGetFees() { List feesList = binanceDexNodeApi.getFees(); From b51fd9fef0151248876ba025bfdae82ebf1161d6 Mon Sep 17 00:00:00 2001 From: erhenglu <42333959+erhenglu@users.noreply.github.com> Date: Mon, 1 Jun 2020 17:25:53 +0800 Subject: [PATCH 2/3] add pending_match in depth response (#86) * add pending_match in depth response --- CHANGELOG.md | 4 ++-- .../binance/dex/api/client/domain/OrderBook.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b694498..85ba806 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog ## 1.0.7 CHAIN UPGRADE -* [\#110](https://github.com/binance-chain/java-sdk/pull/84) [RPC] [API] Add Pending match flag to Depth API response -* [\#115](https://github.com/binance-chain/java-sdk/pull/80) [RPC] [API] Support Mini Token \ No newline at end of file +* [\#86](https://github.com/binance-chain/java-sdk/pull/86) [RPC] [API] Add Pending match flag to Depth API response +* [\#80](https://github.com/binance-chain/java-sdk/pull/80) [RPC] [API] Support Mini Token \ No newline at end of file diff --git a/src/main/java/com/binance/dex/api/client/domain/OrderBook.java b/src/main/java/com/binance/dex/api/client/domain/OrderBook.java index ba9f9af..8ad403d 100644 --- a/src/main/java/com/binance/dex/api/client/domain/OrderBook.java +++ b/src/main/java/com/binance/dex/api/client/domain/OrderBook.java @@ -2,15 +2,20 @@ import com.binance.dex.api.client.BinanceDexConstants; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.builder.ToStringBuilder; import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) public class OrderBook { private List asks; private List bids; private long height; + @JsonProperty("pending_match") + private Boolean pendingMatch; public List getAsks() { return asks; @@ -36,12 +41,22 @@ public void setHeight(long height) { this.height = height; } + public boolean isPendingMatch() { + return pendingMatch; + } + + public void setPendingMatch(boolean pendingMatch) { + this.pendingMatch = pendingMatch; + } + @Override public String toString() { return new ToStringBuilder(this, BinanceDexConstants.BINANCE_DEX_TO_STRING_STYLE) .append("asks", asks) .append("bids", bids) .append("height", height) + .append("pendingMatch", pendingMatch) .toString(); } + } From b2ae92f0ace2e982eef6b4c683bea3ef85de8f04 Mon Sep 17 00:00:00 2001 From: George <61674316+forcodedancing@users.noreply.github.com> Date: Mon, 15 Jun 2020 19:59:39 +0800 Subject: [PATCH 3/3] update mvn artifact version (#87) --- README.md | 2 +- .../examples/LocalEnvironmentExample.java | 53 ------------------- .../client/examples/NodeClientExample.java | 35 ++++++++++-- 3 files changed, 32 insertions(+), 58 deletions(-) delete mode 100644 src/test/java/com/binance/dex/api/client/examples/LocalEnvironmentExample.java diff --git a/README.md b/README.md index 0dbb9c8..65b56a1 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ The Binance Chain Java SDK works as a lightweight Java library for interacting w com.binance.dex.api binance-dex-api-client - 1.0.4 + 1.0.7 ``` # Protobuf diff --git a/src/test/java/com/binance/dex/api/client/examples/LocalEnvironmentExample.java b/src/test/java/com/binance/dex/api/client/examples/LocalEnvironmentExample.java deleted file mode 100644 index 40e0a99..0000000 --- a/src/test/java/com/binance/dex/api/client/examples/LocalEnvironmentExample.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.binance.dex.api.client.examples; - -import com.binance.dex.api.client.BinanceDexApiClientFactory; -import com.binance.dex.api.client.BinanceDexApiNodeClient; -import com.binance.dex.api.client.BinanceDexEnvironment; -import com.binance.dex.api.client.domain.broadcast.Transaction; -import com.binance.dex.api.client.domain.broadcast.TxType; -import org.junit.Assert; - -import java.util.List; - -public class LocalEnvironmentExample { - public static void main(String[] args) { - BinanceDexEnvironment env = new BinanceDexEnvironment( - "http://seed-qa-s3.fdgahl.cn:80", - "", - "http://seed-qa-s3.fdgahl.cn:80", - "", - "tbnb"); - - - BinanceDexApiNodeClient binanceDexNodeApi = BinanceDexApiClientFactory.newInstance().newNodeRpcClient(env.getNodeUrl(), env.getHrp()); -// Long height = 225L; -// List transactions = binanceDexNodeApi.getBlockTransactions(height); -// Assert.assertNotNull(transactions); -// Assert.assertTrue(transactions.size() == 1); -// Assert.assertEquals(transactions.get(0).getTxType(), TxType.MINI_TOKEN_ISSUE); -// -// height = 228L; -// transactions = binanceDexNodeApi.getBlockTransactions(height); -// Assert.assertNotNull(transactions); -// Assert.assertTrue(transactions.size() == 1); -// Assert.assertEquals(transactions.get(0).getTxType(), TxType.MINI_TOKEN_LIST); - - Long height = 1892273L; - List transactions = binanceDexNodeApi.getBlockTransactions(height); - Assert.assertNotNull(transactions); - Assert.assertTrue(transactions.size() == 1); - Assert.assertEquals(transactions.get(0).getTxType(), TxType.TINY_TOKEN_ISSUE); - - height = 148L; - transactions = binanceDexNodeApi.getBlockTransactions(height); - Assert.assertNotNull(transactions); - Assert.assertTrue(transactions.size() == 1); - Assert.assertEquals(transactions.get(0).getTxType(), TxType.MINI_TOKEN_LIST); - - height = 4747L; - transactions = binanceDexNodeApi.getBlockTransactions(height); - Assert.assertNotNull(transactions); - Assert.assertTrue(transactions.size() == 1); - Assert.assertEquals(transactions.get(0).getTxType(), TxType.MINI_TOKEN_SET_URI); - } -} diff --git a/src/test/java/com/binance/dex/api/client/examples/NodeClientExample.java b/src/test/java/com/binance/dex/api/client/examples/NodeClientExample.java index 4c8bd52..c9ef431 100644 --- a/src/test/java/com/binance/dex/api/client/examples/NodeClientExample.java +++ b/src/test/java/com/binance/dex/api/client/examples/NodeClientExample.java @@ -47,10 +47,37 @@ public void testCommittedAccount(){ @Test public void testBlockTransactions() { + //Mini Issue + Long height = 87908207L; + List transactions = binanceDexNodeApi.getBlockTransactions(height); + Assert.assertNotNull(transactions); + Assert.assertTrue(transactions.size() == 1); + Assert.assertEquals(transactions.get(0).getTxType(), TxType.MINI_TOKEN_ISSUE); + + //Tiny Issue + height = 86888933L; + transactions = binanceDexNodeApi.getBlockTransactions(height); + Assert.assertNotNull(transactions); + Assert.assertTrue(transactions.size() == 1); + Assert.assertEquals(transactions.get(0).getTxType(), TxType.TINY_TOKEN_ISSUE); + + //List Mini + height = 86890587L; + transactions = binanceDexNodeApi.getBlockTransactions(height); + Assert.assertNotNull(transactions); + Assert.assertTrue(transactions.size() == 1); + Assert.assertEquals(transactions.get(0).getTxType(), TxType.MINI_TOKEN_LIST); + + //Set token uri + height = 86881980L; + transactions = binanceDexNodeApi.getBlockTransactions(height); + Assert.assertNotNull(transactions); + Assert.assertTrue(transactions.size() == 1); + Assert.assertEquals(transactions.get(0).getTxType(), TxType.MINI_TOKEN_SET_URI); //Transfer - Long height = 33896036L; - List transactions = binanceDexNodeApi.getBlockTransactions(height); + height = 33896036L; + transactions = binanceDexNodeApi.getBlockTransactions(height); Assert.assertNotNull(transactions); Assert.assertTrue(transactions.size() == 1); Assert.assertEquals(transactions.get(0).getTxType(), TxType.TRANSFER); @@ -234,9 +261,9 @@ public void testGetTokenInfoBySymbol(){ @Test public void testGetMiniTokenInfoBySymbol(){ - MiniToken token = binanceDexNodeApi.getMiniTokenInfoBySymbol("AT10-1DEM"); + MiniToken token = binanceDexNodeApi.getMiniTokenInfoBySymbol("TTT-873M"); Assert.assertNotNull(token); - Assert.assertEquals("AT10-1DEM",token.getSymbol()); + Assert.assertEquals("TTT-873M",token.getSymbol()); } @Test