Skip to content

Commit

Permalink
contract sdk interface
Browse files Browse the repository at this point in the history
  • Loading branch information
MIMIEYES committed Nov 23, 2018
1 parent c3ae72e commit 041ddb9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,9 @@ private byte[] handleContractTransferTxs(CallContractTransaction tx, ContractRes

// 如果合约转账(从合约转出)出现错误,整笔合约交易视作合约执行失败
if (!isCorrectContractTransfer) {
Log.error("contract transfer execution failed, reason: {}", contractResult.getErrorMessage());
if(Log.isDebugEnabled()) {
Log.debug("contract transfer execution failed, reason: {}", contractResult.getErrorMessage());
}
// 执行合约产生的状态根回滚到上一个世界状态
stateRoot = preStateRoot;
contractResult.setStateRoot(stateRoot);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* MIT License
* <p>
* Copyright (c) 2017-2018 nuls.io
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.nuls.contract.rpc.model;


import io.nuls.accout.ledger.rpc.dto.TransactionCreatedReturnInfo;

/**
* @author: PierreLuo
* @date: 2018/11/22
*/
public class ContractTransactionCreatedReturnInfo extends TransactionCreatedReturnInfo {

private String contractAddress;

public ContractTransactionCreatedReturnInfo(TransactionCreatedReturnInfo info, String contractAddress) {
super(info.getHash(), info.getTxHex(), info.getInputs(), info.getOutputs());
this.contractAddress = contractAddress;
}

public String getContractAddress() {
return contractAddress;
}

public void setContractAddress(String contractAddress) {
this.contractAddress = contractAddress;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import io.nuls.contract.rpc.form.transaction.CallContractTx;
import io.nuls.contract.rpc.form.transaction.CreateContractTx;
import io.nuls.contract.rpc.form.transaction.DeleteContractTx;
import io.nuls.contract.rpc.model.ContractTransactionCreatedReturnInfo;
import io.nuls.contract.util.ContractUtil;
import io.nuls.core.tools.calc.LongUtils;
import io.nuls.core.tools.crypto.Hex;
Expand All @@ -63,6 +64,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -170,7 +172,7 @@ public RpcClientResult createContractTx(
return Result.getFailed(TransactionErrorCode.DATA_SIZE_ERROR).toRpcClientResult();
}

return this.buildReturnInfo(tx);
return this.buildReturnInfo(tx, AddressTool.getStringAddressByBytes(contractAddressBytes));
}

@POST
Expand Down Expand Up @@ -272,7 +274,7 @@ public RpcClientResult callContractTx(
return Result.getFailed(TransactionErrorCode.DATA_SIZE_ERROR).toRpcClientResult();
}

return this.buildReturnInfo(tx);
return this.buildReturnInfo(tx, contractAddress);
}


Expand Down Expand Up @@ -340,14 +342,14 @@ public RpcClientResult deleteContractTx(
return Result.getFailed(TransactionErrorCode.DATA_SIZE_ERROR).toRpcClientResult();
}

return this.buildReturnInfo(tx);
return this.buildReturnInfo(tx, contractAddress);
}

private RpcClientResult buildReturnInfo(Transaction tx) {
private RpcClientResult buildReturnInfo(Transaction tx, String contractAddress) {
try {
TransactionCreatedReturnInfo returnInfo = LedgerRpcUtil.makeReturnInfo(tx);
Map<String, TransactionCreatedReturnInfo> data = new HashMap<>();
data.put("value", returnInfo);
Map<String, ContractTransactionCreatedReturnInfo> data = new LinkedHashMap<>();
data.put("value", new ContractTransactionCreatedReturnInfo(returnInfo, contractAddress));
return Result.getSuccess().setData(data).toRpcClientResult();
} catch (IOException e) {
Log.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ public Result<List<Entry<byte[], byte[]>>> batchSaveAndDeleteUTXO(List<Entry<byt
byte[] deleteUtxo;
if(utxosToDelete != null) {
for (byte[] key : utxosToDelete) {
/*deleteUtxo = getUTXO(key);
// 函数返回将要删除的UTXO
if(deleteUtxo != null) {
deleteUtxoEntryList.add(new Entry<byte[], byte[]>(key, deleteUtxo));
}*/
batch.delete(key);
}
}
Expand Down

0 comments on commit 041ddb9

Please sign in to comment.