Skip to content

Commit

Permalink
update with master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
unclezoro committed Jul 3, 2020
2 parents dc71547 + b2ae92f commit 5cf715f
Show file tree
Hide file tree
Showing 20 changed files with 766 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog
## 1.1.0
CHAIN UPGRADE
* [\#88](https://github.com/binance-chain/java-sdk/pull/88) [RPC] [API] enable side chain governance transaction
* [\#89](https://github.com/binance-chain/java-sdk/pull/89) [RPC] [API] enable side chain unbind transaction, and modify the structure of claimMsg

## 1.0.7
CHAIN UPGRADE
* [\#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
40 changes: 40 additions & 0 deletions src/main/java/com/binance/dex/api/client/BinanceDexApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,44 @@ Call<TransactionPage> getTransactions(@Query("address") String address, @Query("

@POST("api/v1/broadcast")
Call<List<TransactionMetadata>> broadcast(@Query("sync") boolean sync, @Body RequestBody transaction);

@GET("api/v1/mini/tokens")
Call<List<MiniToken>> getMiniTokens(@Query("limit") Integer limit);

@GET("api/v1/mini/markets")
Call<List<Market>> getMiniMarkets(@Query("limit") Integer limit);

@GET("api/v1/mini/klines")
Call<List<Candlestick>> 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<OrderList> 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<OrderList> 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<String> status, @Query("symbol") String symbol,
@Query("total") Integer total);

@GET("api/v1/mini/orders/{id}")
Call<Order> getMiniOrder(@Path("id") String id);

@GET("api/v1/mini/ticker/24hr")
Call<List<TickerStatistics>> getMini24HrPriceStatistics();

@GET("api/v1/mini/ticker/24hr")
Call<List<TickerStatistics>> getMini24HrPriceStatistics(@Query("symbol") String symbol);

@GET("api/v1/mini/trades")
Call<TradePage> 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public interface BinanceDexApiNodeClient extends BinanceDexApiRestClient {

AtomicSwap getSwapByID(String swapID);

MiniToken getMiniTokenInfoBySymbol(String symbol);

@Override
default Time getTime() {
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -139,6 +141,71 @@ default TransactionPage getTransactions(TransactionsRequest request) {
throw new UnsupportedOperationException();
}

@Override
default List<MiniToken> getMiniTokens(Integer limit) {
throw new UnsupportedOperationException();
}

@Override
default List<Market> getMiniMarkets(Integer limit) {
throw new UnsupportedOperationException();
}

@Override
default List<Candlestick> getMiniCandleStickBars(String symbol, CandlestickInterval interval) {
throw new UnsupportedOperationException();
}

@Override
default List<Candlestick> 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<TickerStatistics> getMini24HrPriceStatistics() {
throw new UnsupportedOperationException();
}

@Override
default List<TickerStatistics> 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<TransactionMetadata> newOrder(NewOrder newOrder, Wallet wallet, TransactionOption options, boolean sync) throws IOException, NoSuchAlgorithmException {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@ public interface BinanceDexApiRestClient {

TransactionPage getTransactions(TransactionsRequest request);

List<MiniToken> getMiniTokens(Integer limit);

List<Market> getMiniMarkets(Integer limit);

List<Candlestick> getMiniCandleStickBars(String symbol, CandlestickInterval interval);

List<Candlestick> 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<TickerStatistics> getMini24HrPriceStatistics();

List<TickerStatistics> getMini24HrPriceStatistics(String symbol);

TradePage getMiniTrades();

TradePage getMiniTrades(TradesRequest request);

List<TransactionMetadata> newOrder(NewOrder newOrder, Wallet wallet, TransactionOption options, boolean sync)
throws IOException, NoSuchAlgorithmException;

Expand Down
83 changes: 83 additions & 0 deletions src/main/java/com/binance/dex/api/client/TransactionConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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;
Expand All @@ -18,6 +20,7 @@
import com.binance.dex.api.client.domain.broadcast.SideSubmitProposal;
import com.binance.dex.api.client.domain.broadcast.SideVote;
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;
Expand Down Expand Up @@ -218,6 +221,14 @@ public Transaction convert(byte[] bytes) {
return convertBscSubmitEvidence(bytes);
case SideChainUnJail:
return convertSideChainUnJail(bytes);
case TinyTokenIssue:
return convertTinyTokenIssue(bytes);
case MiniTokenIssue:
return convertMiniTokenIssue(bytes);
case MiniTokenSetURI:
return convertMiniTokenSetURI(bytes);
case MiniTokenList:
return convertMiniTokenList(bytes);
}
return null;
} catch (Exception e) {
Expand Down Expand Up @@ -1025,4 +1036,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;
}
}
109 changes: 109 additions & 0 deletions src/main/java/com/binance/dex/api/client/domain/MiniToken.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading

0 comments on commit 5cf715f

Please sign in to comment.