Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change(block info)use "v2/bolcks/*id *height" interface to get block … #1

Open
wants to merge 1 commit into
base: dev_1.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 49 additions & 76 deletions app/src/main/java/asch/so/wallet/model/entity/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,32 @@
}
*/
public class Block {
private String id;
private int timestamp;
private int version;
private int height;
/* V1的字段
private String previousBlock;
private int numberOfTransactions;
private long totalAmount;
private long totalFee;
private long reward;
private int payloadLength;
private String payloadHash;
private String generatorPublicKey;
private String generatorId;
private String blockSignature;
private String confirmations;
private long totalForged;
*/

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public int getTimestamp() {
return timestamp;
}
private int version;
private String delegate;
private int height;
private String prevBlockId;
private int timestamp;
private int count;
private int fees;
private String payloadHash;
private long reward;
private String signature;
private String id;

public void setTimestamp(int timestamp) {
this.timestamp = timestamp;
}

public int getVersion() {
return version;
Expand All @@ -66,60 +60,52 @@ public void setVersion(int version) {
this.version = version;
}

public int getHeight() {
return height;
}

public void setHeight(int height) {
this.height = height;
public String getDelegate() {
return delegate;
}

public String getPreviousBlock() {
return previousBlock;
public void setDelegate(String delegate) {
this.delegate = delegate;
}

public void setPreviousBlock(String previousBlock) {
this.previousBlock = previousBlock;
public int getHeight() {
return height;
}

public int getNumberOfTransactions() {
return numberOfTransactions;
public void setHeight(int height) {
this.height = height;
}

public void setNumberOfTransactions(int numberOfTransactions) {
this.numberOfTransactions = numberOfTransactions;
public String getPrevBlockId() {
return prevBlockId;
}

public long getTotalAmount() {
return totalAmount;
public void setPrevBlockId(String prevBlockId) {
this.prevBlockId = prevBlockId;
}

public void setTotalAmount(long totalAmount) {
this.totalAmount = totalAmount;
public int getTimestamp() {
return timestamp;
}

public long getTotalFee() {
return totalFee;
public void setTimestamp(int timestamp) {
this.timestamp = timestamp;
}

public void setTotalFee(long totalFee) {
this.totalFee = totalFee;
public int getCount() {
return count;
}

public long getReward() {
return reward;
public void setCount(int count) {
this.count = count;
}

public void setReward(long reward) {
this.reward = reward;
public int getFees() {
return fees;
}

public int getPayloadLength() {
return payloadLength;
}

public void setPayloadLength(int payloadLength) {
this.payloadLength = payloadLength;
public void setFees(int fees) {
this.fees = fees;
}

public String getPayloadHash() {
Expand All @@ -130,43 +116,30 @@ public void setPayloadHash(String payloadHash) {
this.payloadHash = payloadHash;
}

public String getGeneratorPublicKey() {
return generatorPublicKey;
}

public void setGeneratorPublicKey(String generatorPublicKey) {
this.generatorPublicKey = generatorPublicKey;
public long getReward() {
return reward;
}

public String getGeneratorId() {
return generatorId;
public void setReward(long reward) {
this.reward = reward;
}

public void setGeneratorId(String generatorId) {
this.generatorId = generatorId;
public String getSignature() {
return signature;
}

public String getBlockSignature() {
return blockSignature;
public void setSignature(String signature) {
this.signature = signature;
}

public void setBlockSignature(String blockSignature) {
this.blockSignature = blockSignature;
public String getId() {
return id;
}

public String getConfirmations() {
return confirmations;
public void setId(String id) {
this.id = id;
}

public void setConfirmations(String confirmations) {
this.confirmations = confirmations;
}

public long getTotalForged() {
return totalForged;
}

public void setTotalForged(long totalForged) {
this.totalForged = totalForged;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void unSubscribe() {
@Override
public void loadBlockInfo(String tid) {
Subscription subscription = Observable.create((Observable.OnSubscribe<AschResult>) subscriber -> {
AschResult result = AschSDK.Block.getBlockById(tid,false);
AschResult result = AschSDK.Block.getBlockById(tid);
if (result != null && result.isSuccessful()) {
subscriber.onNext(result);
subscriber.onCompleted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ private void loadBlocks(int pageIndex, int pageSize,String idOrHeight) {
result = AschSDK.Block.queryBlocksV2(params);
}else{
if(isBlockHeight(idOrHeight)){
result = AschSDK.Block.getBlockByHeight(Integer.valueOf(idOrHeight),true);
result = AschSDK.Block.getBlockByHeight(Integer.valueOf(idOrHeight));
}else{
result = AschSDK.Block.getBlockById(idOrHeight,true);
result = AschSDK.Block.getBlockById(idOrHeight);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void loadBlocks(int pageIndex, int pageSize) {
.setOffset(offset)
.setLimit(limit);

AschResult result = AschSDK.Block.queryBlocks(params);
AschResult result = AschSDK.Block.queryBlocksV2(params);
if (result.isSuccessful()) {
JSONObject resultJSONObj = JSONObject.parseObject(result.getRawJson());
JSONArray blocksJsonArray = resultJSONObj.getJSONArray("blocks");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,19 @@ private void showDetail(Block blk){
String dateTime = TimeUtils.date2String(dateT,new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"));
date.setText(dateTime);
id.setText(blk.getId());
transaction.setText(blk.getNumberOfTransactions()+"");
money.setText(AppUtil.decimalFormat(AppUtil.decimalFromBigint(blk.getTotalAmount(), AppConstants.PRECISION))+" XAS");
cost.setText(AppUtil.decimalFormat(AppUtil.decimalFromBigint(blk.getTotalFee(), AppConstants.PRECISION))+" XAS");
transaction.setText(blk.getCount()+"");
cost.setText(AppUtil.decimalFormat(AppUtil.decimalFromBigint(blk.getFees(), AppConstants.PRECISION))+" XAS");
award.setText(AppUtil.decimalFormat(AppUtil.decimalFromBigint(blk.getReward(), AppConstants.PRECISION))+" XAS");
address.setText(blk.getGeneratorId());
public_key.setText(blk.getGeneratorPublicKey());
public_key.setText(blk.getDelegate());

/*已隐藏的,v2接口没有对应数据
//确认数
confirmationsTv.setText(blk.getConfirmations());
//总金额字段
money.setText(AppUtil.decimalFormat(AppUtil.decimalFromBigint(blk.getTotalAmount(), AppConstants.PRECISION))+" XAS");
//生产者地址
address.setText(blk.getGeneratorId());
*/
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_block_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@
/>
</LinearLayout>
<LinearLayout
android:visibility="visible"
android:visibility="gone"
android:gravity="center_vertical"
android:orientation="vertical"
android:layout_width="match_parent"
Expand Down
9 changes: 5 additions & 4 deletions asch-java/src/main/java/so/asch/sdk/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ public interface Block extends AschInterface {
//返回参数说明:
//success boole 是否成功获得response数据
//block json 区块详情
AschResult getBlockById(String id, boolean fullBlockInfo);
AschResult getBlockByHeight(long height, boolean fullBlockInfo);
AschResult getBlockById(String id);
AschResult getBlockByHeight(long height);
AschResult getBlockByHash(String hash, boolean fullBlockInfo);


//接口地址:/api/blocks
//请求方式:get
//支持格式:urlencoded
Expand All @@ -41,7 +40,9 @@ public interface Block extends AschInterface {
//success boole 是否成功获得response数据
//blocks Array 由区块详情json串构成的数组
//count integer 区块链高度
AschResult queryBlocks(BlockQueryParameters parameters);
//AschResult queryBlocks(BlockQueryParameters parameters);



//接口地址:/api/V2/blocks
//请求方式:get
Expand Down
2 changes: 1 addition & 1 deletion asch-java/src/main/java/so/asch/sdk/Dapp.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface Dapp extends AschInterface{
// success boole 是否成功获得response数据
// count integer 符合条件的总结果数目
// blocks Array 每个元素是一个block对象,对象里面包含block的id、height、产块受托人公钥等信息
AschResult queryBlocks(BlockQueryParameters parameters);
AschResult queryBlocksV2(BlockQueryParameters parameters);

// 2.1 根据地址获取dapp内账户信息
//
Expand Down
2 changes: 1 addition & 1 deletion asch-java/src/main/java/so/asch/sdk/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static void main(String[] args) {
}

private static boolean handleBlockTransactions(long height){
AschResult result = AschSDK.Block.getBlockByHeight(height, false);
AschResult result = AschSDK.Block.getBlockByHeight(height);
if (!result.isSuccessful()){
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ final static class Delegate{
}

final static class Block{
/**
* V1版本接口,未用
*/
static final String GET_BLOCK_INFO = "/api/blocks/get";
static final String GET_FULL_BLOCK_INFO = "/api/blocks/full";
static final String QUERY_BLOCKS = "/api/blocks/";
static final String QUERY_BLOCKS_V2 = "/api/V2/blocks";
/**
* 正在用的接口
*/
static final String QUERY_BLOCKS_V2 = "/api/V2/blocks/";
static final String GET_HEIGHT = "/api/blocks/getHeight";
static final String GET_FREE="/api/blocks/getFee";
static final String GET_MILESTONE = "/api/blocks/getMilestone";
Expand Down
43 changes: 19 additions & 24 deletions asch-java/src/main/java/so/asch/sdk/impl/BlockService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,21 @@

public class BlockService extends AschRESTService implements Block {
@Override
public AschResult getBlockById(String id, boolean fullBlockInfo) {
public AschResult getBlockById(String id) {
try {
Argument.notNull(id, "id is null");

ParameterMap parameters = new ParameterMap().put("id", id);
String url = fullBlockInfo ?
AschServiceUrls.Block.GET_FULL_BLOCK_INFO:
AschServiceUrls.Block.GET_BLOCK_INFO ;
ParameterMap parameters = new ParameterMap();
String url = AschServiceUrls.Block.QUERY_BLOCKS_V2+id;
return get(url, parameters);
} catch (Exception ex) {
return fail(ex);
}
}

@Override
public AschResult getBlockByHeight(long height, boolean fullBlockInfo) {
ParameterMap parameters = new ParameterMap().put("height", height);
String url = fullBlockInfo ?
AschServiceUrls.Block.GET_FULL_BLOCK_INFO:
AschServiceUrls.Block.GET_BLOCK_INFO ;
public AschResult getBlockByHeight(long height) {
ParameterMap parameters = new ParameterMap();
String url = AschServiceUrls.Block.QUERY_BLOCKS_V2+String.valueOf(height);
return get(url, parameters);
}

Expand All @@ -46,19 +41,19 @@ public AschResult getBlockByHash(String hash, boolean fullBlockInfo) {
}
}


@Override
public AschResult queryBlocks(BlockQueryParameters parameters) {
try {
//Argument.require(Validation.isValidBlockQueryParameters(parameters), "invalid parameters");

ParameterMap query = parametersFromObject(parameters);
return get(AschServiceUrls.Block.QUERY_BLOCKS, query);
}
catch (Exception ex){
return fail(ex);
}
}
// V1接口,暂时弃用
// @Override
// public AschResult queryBlocks(BlockQueryParameters parameters) {
// try {
// //Argument.require(Validation.isValidBlockQueryParameters(parameters), "invalid parameters");
//
// ParameterMap query = parametersFromObject(parameters);
// return get(AschServiceUrls.Block.QUERY_BLOCKS, query);
// }
// catch (Exception ex){
// return fail(ex);
// }
// }

@Override
public AschResult queryBlocksV2(BlockQueryParameters parameters) {
Expand Down
2 changes: 1 addition & 1 deletion asch-java/src/main/java/so/asch/sdk/impl/DappService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public AschResult getBlockHeight(String dappID) {
}

@Override
public AschResult queryBlocks(BlockQueryParameters parameters) {
public AschResult queryBlocksV2(BlockQueryParameters parameters) {
return null;
}

Expand Down