use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.
the class CallContract method sendTransaction.
public TransactionReceipt sendTransaction(BigInteger gasPrice, BigInteger gasLimit, String contractAddress, String funcName, Type... args) {
final Function function = new Function(funcName, Arrays.<Type>asList(args), Collections.<TypeReference<?>>emptyList());
TransactionReceipt transactionReceipt = new TransactionReceipt();
try {
ExecuteTransaction executeTransaction = new ExecuteTransaction(contractAddress, web3j, credentials, gasPrice, gasLimit);
transactionReceipt = executeTransaction.send(function);
String status = transactionReceipt.getStatus();
transactionReceipt.setMessage(StatusCode.getStatusMessage(status));
} catch (Exception e) {
transactionReceipt.setStatus(StatusCode.ExceptionCatched);
transactionReceipt.setMessage(e.getMessage());
transactionReceipt.setOutput("0x");
}
return transactionReceipt;
}
use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.
the class CallContract method call.
public CallResult call(String contractAddress, String funcName, Type... args) {
final Function function = new Function(funcName, Arrays.<Type>asList(args), Collections.<TypeReference<?>>emptyList());
String data = FunctionEncoder.encode(function);
Call ethCall;
try {
ethCall = web3j.call(Transaction.createEthCallTransaction(credentials.getAddress(), contractAddress, data), DefaultBlockParameterName.LATEST).send();
} catch (Exception e) {
return new CallResult(StatusCode.ExceptionCatched, e.getMessage(), "0x");
}
Call.CallOutput callOutput = ethCall.getValue();
if (callOutput != null) {
return new CallResult(callOutput.getStatus(), StatusCode.getStatusMessage(callOutput.getStatus()), callOutput.getOutput());
} else {
return new CallResult(StatusCode.ErrorInRPC, StatusCode.getStatusMessage(StatusCode.ErrorInRPC), "0x");
}
}
use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.
the class CallContract method sendTransaction.
public TransactionReceipt sendTransaction(String contractAddress, String funcName, Type... args) {
final Function function = new Function(funcName, Arrays.<Type>asList(args), Collections.<TypeReference<?>>emptyList());
TransactionReceipt transactionReceipt = new TransactionReceipt();
try {
ExecuteTransaction executeTransaction = new ExecuteTransaction(contractAddress, web3j, credentials, gasPrice, gasLimit);
transactionReceipt = executeTransaction.send(function);
String status = transactionReceipt.getStatus();
transactionReceipt.setMessage(StatusCode.getStatusMessage(status));
} catch (Exception e) {
transactionReceipt.setStatus(StatusCode.ExceptionCatched);
transactionReceipt.setMessage(e.getMessage());
transactionReceipt.setOutput("0x");
}
return transactionReceipt;
}
use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.
the class Ok method trans.
public void trans(BigInteger num, TransactionSucCallback callback) {
final Function function = new Function(FUNC_TRANS, Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.generated.Uint256(num)), Collections.<TypeReference<?>>emptyList());
asyncExecuteTransaction(function, callback);
}
use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.
the class TransactionDecoderTest method testSimpleParams1.
@Test
public void testSimpleParams1() throws JsonProcessingException, TransactionException, BaseException {
/*
function test(uint256 _u,int256 _i,bool _b,address _addr,bytes32 _bs32, string _s,bytes _bs) public constant returns (uint256,int256,bool,address,bytes32,string,bytes)
*/
TransactionDecoder decode = TransactionDecoderFactory.buildTransactionDecoder("[{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"name\":\"_i\",\"type\":\"int256[4]\"},{\"name\":\"_b\",\"type\":\"bool[4]\"},{\"name\":\"_addr\",\"type\":\"address[4]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"name\":\"_s\",\"type\":\"string[4]\"},{\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[2]\"},{\"name\":\"\",\"type\":\"int256[2]\"},{\"name\":\"\",\"type\":\"bool[2]\"},{\"name\":\"\",\"type\":\"address[2]\"},{\"name\":\"\",\"type\":\"bytes32[2]\"},{\"name\":\"\",\"type\":\"string[2]\"},{\"name\":\"\",\"type\":\"bytes[2]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256\"},{\"name\":\"_i\",\"type\":\"int256\"},{\"name\":\"_b\",\"type\":\"bool\"},{\"name\":\"_addr\",\"type\":\"address\"},{\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"name\":\"_s\",\"type\":\"string\"},{\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"int256\"},{\"name\":\"\",\"type\":\"bool\"},{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"\",\"type\":\"string\"},{\"name\":\"\",\"type\":\"bytes\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_u\",\"type\":\"uint256[]\"},{\"name\":\"_i\",\"type\":\"int256[]\"},{\"name\":\"_b\",\"type\":\"bool[]\"},{\"name\":\"_addr\",\"type\":\"address[]\"},{\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"name\":\"_s\",\"type\":\"string[]\"},{\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"},{\"name\":\"\",\"type\":\"int256[]\"},{\"name\":\"\",\"type\":\"bool[]\"},{\"name\":\"\",\"type\":\"address[]\"},{\"name\":\"\",\"type\":\"bytes32[]\"},{\"name\":\"\",\"type\":\"string[]\"},{\"name\":\"\",\"type\":\"bytes[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes\"}],\"name\":\"TestEventSimpleParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[]\"}],\"name\":\"TestEventDArrayParams\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_u\",\"type\":\"uint256[4]\"},{\"indexed\":false,\"name\":\"_i\",\"type\":\"int256[4]\"},{\"indexed\":false,\"name\":\"_b\",\"type\":\"bool[4]\"},{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address[4]\"},{\"indexed\":false,\"name\":\"_bs32\",\"type\":\"bytes32[4]\"},{\"indexed\":false,\"name\":\"_s\",\"type\":\"string[4]\"},{\"indexed\":false,\"name\":\"_bs\",\"type\":\"bytes[4]\"}],\"name\":\"TestEventSArrayParams\",\"type\":\"event\"}]", "");
List<Type> test1Params = Arrays.asList(new Uint256(0), new Int256(0), new Bool(false), new Address("0x0"), new Bytes32(" ".getBytes()), new Utf8String(""), new DynamicBytes("".getBytes()));
Function test1 = new Function("test", test1Params, Collections.<TypeReference<?>>emptyList());
String resultInputJson = decode.decodeInputReturnJson(FunctionEncoder.encode(test1));
InputAndOutputResult inputAndOutputResult = decode.decodeInputReturnObject(FunctionEncoder.encode(test1));
List<ResultEntity> resultInputList = inputAndOutputResult.getResult();
List<Type> resultInputListType = transEntitytoType(resultInputList);
assertThat(resultInputJson, is("{\"function\":\"test(uint256,int256,bool,address,bytes32,string,bytes)\",\"methodID\":\"0x58a12c20\",\"result\":[{\"name\":\"_u\",\"type\":\"uint256\",\"data\":0},{\"name\":\"_i\",\"type\":\"int256\",\"data\":0},{\"name\":\"_b\",\"type\":\"bool\",\"data\":false},{\"name\":\"_addr\",\"type\":\"address\",\"data\":\"0x0000000000000000000000000000000000000000\"},{\"name\":\"_bs32\",\"type\":\"bytes32\",\"data\":\"\"},{\"name\":\"_s\",\"type\":\"string\",\"data\":\"\"},{\"name\":\"_bs\",\"type\":\"bytes\",\"data\":\"\"}]}"));
assertThat(resultInputListType, is(test1Params));
String resultOutputJson = decode.decodeOutputReturnJson(FunctionEncoder.encode(test1), FunctionEncoder.encodeConstructor(test1Params));
InputAndOutputResult inputAndOutputResult2 = decode.decodeOutputReturnObject(FunctionEncoder.encode(test1), FunctionEncoder.encodeConstructor(test1Params));
List<ResultEntity> resultOutputList = inputAndOutputResult2.getResult();
List<Type> resultOutputListType = transEntitytoType(resultOutputList);
assertThat(resultOutputJson, is("{\"function\":\"test(uint256,int256,bool,address,bytes32,string,bytes)\",\"methodID\":\"0x58a12c20\",\"result\":[{\"name\":\"\",\"type\":\"uint256\",\"data\":0},{\"name\":\"\",\"type\":\"int256\",\"data\":0},{\"name\":\"\",\"type\":\"bool\",\"data\":false},{\"name\":\"\",\"type\":\"address\",\"data\":\"0x0000000000000000000000000000000000000000\"},{\"name\":\"\",\"type\":\"bytes32\",\"data\":\"\"},{\"name\":\"\",\"type\":\"string\",\"data\":\"\"},{\"name\":\"\",\"type\":\"bytes\",\"data\":\"\"}]}"));
assertThat(resultOutputListType, is(test1Params));
}
Aggregations