我真的很感激有人能帮忙...
我为两个智能合约(SheepHelper和SheepFactory)生成了java智能合约包装器。当我尝试在android中使用这些方法时,我只能返回TransactionReciep对象(即使是视图函数)
因此,我无法读取智能合约中包含的任何数据。
任何帮助都将不胜感激!
智能合约:
牧羊助手. sol
pragma solidity ^0.6;
import "./sheepFactory.sol";
contract SheepHelper is SheepFactory {
modifier onlyOwnerOf(uint _sheepId){
require(msg.sender == sheepToOwner[_sheepId]);
_;
}
function getSheepsByOwner(address _owner) external view returns(uint[] memory) {
uint[] memory result = new uint[](ownerSheepCount[_owner]);
uint counter = 0;
for (uint i = 0; i < sheeps.length; i++) {
if (sheepToOwner[i] == _owner) {
result[counter] = i;
counter++;
}
}
return result;
}
function getSheepById(uint _sheepId) public view returns(string memory, uint, uint, uint, string memory){
Sheep memory sheep = sheeps[_sheepId];
return (sheep.name, sheep.hp, sheep.dp, sheep.dna, sheep.imageAsset);
}
function getSheepTotal() external view returns (uint){
return sheepCount;
}
function findMySheepTotal() external view returns (uint){
return sheepCount;
}
}
羊厂
pragma solidity ^0.6;
contract SheepFactory{
event NewSheep(uint sheepId, string name, uint dna, uint hp, uint dp, string imageAsset);
uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;
uint statModulus = 10 ** 1;
struct Sheep {
string name;
uint dna;
uint hp;
uint dp;
string imageAsset;
}
Sheep[] public sheeps;
uint sheepCount = 0;
mapping (uint => address) public sheepToOwner;
mapping (address => uint) ownerSheepCount;
function _createSheep(string memory _name, uint _dna, uint16 _hp, uint16 _dp) internal {
string memory sheepPic = "https://image.shutterstock.com/image-vector/cute-funny-cartoon-kick-sheep-600w-1577287216.jpg";
sheeps.push(Sheep(_name, _dna, _hp, _dp, sheepPic));
sheepCount++;
uint id = sheeps.length - 1;
sheepToOwner[id] = tx.origin;
ownerSheepCount[msg.sender]++;
emit NewSheep(id, _name, _dna, _hp, _dp, sheepPic);
}
function _generateRandomDna(string memory _str) private view returns (uint) {
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}
function _generateRandomStats(string memory _str, uint _statModifier) private view returns (uint) {
uint rand = uint(keccak256(abi.encodePacked(_str)));
return (rand % statModulus) + _statModifier;
}
function createRandomSheep(string memory _name) public {
//require(ownerSheepCount[msg.sender] == 0);
uint randDna = _generateRandomDna(_name);
uint16 randHp = 2;//_generateRandomStats(_name, 1);
uint16 randDp = 1;//_generateRandomStats(_name, 0);
randDna = randDna - randDna % 100;
_createSheep(_name, randDna, randHp, randDp);
}
}
SheepHelper.java
package com.ogma;
import io.reactivex.Flowable;
import io.reactivex.functions.Function;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.web3j.abi.EventEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Event;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.Utf8String;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.RemoteFunctionCall;
import org.web3j.protocol.core.methods.request.EthFilter;
import org.web3j.protocol.core.methods.response.BaseEventResponse;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;
import org.web3j.tx.gas.ContractGasProvider;
/**
* <p>Auto generated code.
* <p><strong>Do not modify!</strong>
* <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
* or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the
* <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
*
* <p>Generated with web3j version 4.5.12.
*/
@SuppressWarnings("rawtypes")
public class SheepHelper extends Contract {
public static final String BINARY = =<"Binary removed for Char Limit">;
public static final String FUNC_CREATERANDOMSHEEP = "createRandomSheep";
public static final String FUNC_FINDMYSHEEPTOTAL = "findMySheepTotal";
public static final String FUNC_GETSHEEPBYID = "getSheepById";
public static final String FUNC_GETSHEEPTOTAL = "getSheepTotal";
public static final String FUNC_GETSHEEPSBYOWNER = "getSheepsByOwner";
public static final String FUNC_SHEEPTOOWNER = "sheepToOwner";
public static final String FUNC_SHEEPS = "sheeps";
public static final Event NEWSHEEP_EVENT = new Event("NewSheep",
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}, new TypeReference<Utf8String>() {}));
;
@Deprecated
protected SheepHelper(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
protected SheepHelper(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
@Deprecated
protected SheepHelper(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
protected SheepHelper(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
}
public List<NewSheepEventResponse> getNewSheepEvents(TransactionReceipt transactionReceipt) {
List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(NEWSHEEP_EVENT, transactionReceipt);
ArrayList<NewSheepEventResponse> responses = new ArrayList<NewSheepEventResponse>(valueList.size());
for (Contract.EventValuesWithLog eventValues : valueList) {
NewSheepEventResponse typedResponse = new NewSheepEventResponse();
typedResponse.log = eventValues.getLog();
typedResponse.sheepId = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
typedResponse.name = (String) eventValues.getNonIndexedValues().get(1).getValue();
typedResponse.dna = (BigInteger) eventValues.getNonIndexedValues().get(2).getValue();
typedResponse.hp = (BigInteger) eventValues.getNonIndexedValues().get(3).getValue();
typedResponse.dp = (BigInteger) eventValues.getNonIndexedValues().get(4).getValue();
typedResponse.imageAsset = (String) eventValues.getNonIndexedValues().get(5).getValue();
responses.add(typedResponse);
}
return responses;
}
public Flowable<NewSheepEventResponse> newSheepEventFlowable(EthFilter filter) {
return web3j.ethLogFlowable(filter).map(new Function<Log, NewSheepEventResponse>() {
@Override
public NewSheepEventResponse apply(Log log) {
Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(NEWSHEEP_EVENT, log);
NewSheepEventResponse typedResponse = new NewSheepEventResponse();
typedResponse.log = log;
typedResponse.sheepId = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
typedResponse.name = (String) eventValues.getNonIndexedValues().get(1).getValue();
typedResponse.dna = (BigInteger) eventValues.getNonIndexedValues().get(2).getValue();
typedResponse.hp = (BigInteger) eventValues.getNonIndexedValues().get(3).getValue();
typedResponse.dp = (BigInteger) eventValues.getNonIndexedValues().get(4).getValue();
typedResponse.imageAsset = (String) eventValues.getNonIndexedValues().get(5).getValue();
return typedResponse;
}
});
}
public Flowable<NewSheepEventResponse> newSheepEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
filter.addSingleTopic(EventEncoder.encode(NEWSHEEP_EVENT));
return newSheepEventFlowable(filter);
}
public RemoteFunctionCall<TransactionReceipt> createRandomSheep(String _name) {
final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
FUNC_CREATERANDOMSHEEP,
Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(_name)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteFunctionCall<TransactionReceipt> findMySheepTotal() {
final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
FUNC_FINDMYSHEEPTOTAL,
Arrays.<Type>asList(),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteFunctionCall<TransactionReceipt> getSheepById(BigInteger _sheepId) {
final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
FUNC_GETSHEEPBYID,
Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(_sheepId)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteFunctionCall<TransactionReceipt> getSheepTotal() {
final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
FUNC_GETSHEEPTOTAL,
Arrays.<Type>asList(),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteFunctionCall<TransactionReceipt> getSheepsByOwner(String _owner) {
final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
FUNC_GETSHEEPSBYOWNER,
Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, _owner)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteFunctionCall<TransactionReceipt> sheepToOwner(BigInteger param0) {
final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
FUNC_SHEEPTOOWNER,
Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(param0)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteFunctionCall<TransactionReceipt> sheeps(BigInteger param0) {
final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
FUNC_SHEEPS,
Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(param0)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
@Deprecated
public static SheepHelper load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return new SheepHelper(contractAddress, web3j, credentials, gasPrice, gasLimit);
}
@Deprecated
public static SheepHelper load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return new SheepHelper(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
public static SheepHelper load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
return new SheepHelper(contractAddress, web3j, credentials, contractGasProvider);
}
public static SheepHelper load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
return new SheepHelper(contractAddress, web3j, transactionManager, contractGasProvider);
}
public static RemoteCall<SheepHelper> deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
return deployRemoteCall(SheepHelper.class, web3j, credentials, contractGasProvider, BINARY, "");
}
@Deprecated
public static RemoteCall<SheepHelper> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return deployRemoteCall(SheepHelper.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
}
public static RemoteCall<SheepHelper> deploy(Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
return deployRemoteCall(SheepHelper.class, web3j, transactionManager, contractGasProvider, BINARY, "");
}
@Deprecated
public static RemoteCall<SheepHelper> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return deployRemoteCall(SheepHelper.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
}
public static class NewSheepEventResponse extends BaseEventResponse {
public BigInteger sheepId;
public String name;
public BigInteger dna;
public BigInteger hp;
public BigInteger dp;
public String imageAsset;
}
}
SheepFactory.java
package com.ogma;
(... Imports ...)
/**
* <p>Auto generated code.
* <p><strong>Do not modify!</strong>
* <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
* or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the
* <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
*
* <p>Generated with web3j version 4.5.12.
*/
@SuppressWarnings("rawtypes")
public class SheepFactory extends Contract {
public static final String BINARY = "608060405260106000908155662386f26fc10000600155600a60025560045534801561002a57600080fd5b506107e78061003a6000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063541ce3a71461004657806380a6659814610156578063adb0e41d146101fe575b600080fd5b6100636004803603602081101561005c57600080fd5b5035610237565b604051808060200186815260200185815260200184815260200180602001838103835288818151815260200191508051906020019080838360005b838110156100b657818101518382015260200161009e565b50505050905090810190601f1680156100e35780820380516001836020036101000a031916815260200191505b50838103825284518152845160209182019186019080838360005b838110156101165781810151838201526020016100fe565b50505050905090810190601f1680156101435780820380516001836020036101000a031916815260200191505b5097505050505050505060405180910390f35b6101fc6004803603602081101561016c57600080fd5b81019060208101813564010000000081111561018757600080fd5b82018360208201111561019957600080fd5b803590602001918460018302840111640100000000831117156101bb57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610397945050505050565b005b61021b6004803603602081101561021457600080fd5b50356103c0565b604080516001600160a01b039092168252519081900360200190f35b6003818154811061024457fe5b60009182526020918290206005919091020180546040805160026001841615610100026000190190931692909204601f8101859004850283018501909152808252919350918391908301828280156102dd5780601f106102b2576101008083540402835291602001916102dd565b820191906000526020600020905b8154815290600101906020018083116102c057829003601f168201915b505050505090806001015490806002015490806003015490806004018054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561038d5780601f106103625761010080835404028352916020019161038d565b820191906000526020600020905b81548152906001019060200180831161037057829003601f168201915b5050505050905085565b60006103a2826103db565b6064810690039050600260016103ba84848484610464565b50505050565b6005602052600090815260409020546001600160a01b031681565b600080826040516020018082805190602001908083835b602083106104115780518252601f1990920191602091820191016103f2565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040528051906020012060001c9050600154818161045c57fe5b069392505050565b60606040518060800160405280605d8152602001610755605d91396040805160a081018252878152602080820188905261ffff808816938301939093529185166060820152608081018390526003805460018101825560009190915281518051949550919360059091027fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b01926104ff9284929101906106b9565b50602082810151600183015560408301516002830155606083015160038301556080830151805161053692600485019201906106b9565b505060048054600190810190915560035460001901600081815260056020908152604080832080546001600160a01b03191632179055338352600682528083208054909501909455835183815293840189905261ffff80891660608601528716608085015260c08482018181528b51918601919091528a519395507f4879619f7ff9493ef67b03bd003b4128af5d0d3fc86f27ec4d03017d481365159486948c948c948c948c948c949093919260a085019260e0860192918b0191908190849084905b838110156106115781810151838201526020016105f9565b50505050905090810190601f16801561063e5780820380516001836020036101000a031916815260200191505b50838103825284518152845160209182019186019080838360005b83811015610671578181015183820152602001610659565b50505050905090810190601f16801561069e5780820380516001836020036101000a031916815260200191505b509850505050505050505060405180910390a1505050505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106106fa57805160ff1916838001178555610727565b82800160010185558215610727579182015b8281111561072757825182559160200191906001019061070c565b50610733929150610737565b5090565b61075191905b80821115610733576000815560010161073d565b9056fe68747470733a2f2f696d6167652e7368757474657273746f636b2e636f6d2f696d6167652d766563746f722f637574652d66756e6e792d636172746f6f6e2d6b69636b2d73686565702d363030772d313537373238373231362e6a7067a26469706673582212204d02f4b6883942903f1176e17fdaa2394ffa7779293cdca4fef2eb24f3f15e8164736f6c63430006010033";
public static final String FUNC_CREATERANDOMSHEEP = "createRandomSheep";
public static final String FUNC_SHEEPTOOWNER = "sheepToOwner";
public static final String FUNC_SHEEPS = "sheeps";
public static final Event NEWSHEEP_EVENT = new Event("NewSheep",
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}, new TypeReference<Utf8String>() {}));
;
@Deprecated
protected SheepFactory(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
protected SheepFactory(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
@Deprecated
protected SheepFactory(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
protected SheepFactory(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
}
public List<NewSheepEventResponse> getNewSheepEvents(TransactionReceipt transactionReceipt) {
List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(NEWSHEEP_EVENT, transactionReceipt);
ArrayList<NewSheepEventResponse> responses = new ArrayList<NewSheepEventResponse>(valueList.size());
for (Contract.EventValuesWithLog eventValues : valueList) {
NewSheepEventResponse typedResponse = new NewSheepEventResponse();
typedResponse.log = eventValues.getLog();
typedResponse.sheepId = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
typedResponse.name = (String) eventValues.getNonIndexedValues().get(1).getValue();
typedResponse.dna = (BigInteger) eventValues.getNonIndexedValues().get(2).getValue();
typedResponse.hp = (BigInteger) eventValues.getNonIndexedValues().get(3).getValue();
typedResponse.dp = (BigInteger) eventValues.getNonIndexedValues().get(4).getValue();
typedResponse.imageAsset = (String) eventValues.getNonIndexedValues().get(5).getValue();
responses.add(typedResponse);
}
return responses;
}
public Flowable<NewSheepEventResponse> newSheepEventFlowable(EthFilter filter) {
return web3j.ethLogFlowable(filter).map(new Function<Log, NewSheepEventResponse>() {
@Override
public NewSheepEventResponse apply(Log log) {
Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(NEWSHEEP_EVENT, log);
NewSheepEventResponse typedResponse = new NewSheepEventResponse();
typedResponse.log = log;
typedResponse.sheepId = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
typedResponse.name = (String) eventValues.getNonIndexedValues().get(1).getValue();
typedResponse.dna = (BigInteger) eventValues.getNonIndexedValues().get(2).getValue();
typedResponse.hp = (BigInteger) eventValues.getNonIndexedValues().get(3).getValue();
typedResponse.dp = (BigInteger) eventValues.getNonIndexedValues().get(4).getValue();
typedResponse.imageAsset = (String) eventValues.getNonIndexedValues().get(5).getValue();
return typedResponse;
}
});
}
public Flowable<NewSheepEventResponse> newSheepEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
filter.addSingleTopic(EventEncoder.encode(NEWSHEEP_EVENT));
return newSheepEventFlowable(filter);
}
public RemoteFunctionCall<TransactionReceipt> createRandomSheep(String _name) {
final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
FUNC_CREATERANDOMSHEEP,
Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(_name)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteFunctionCall<TransactionReceipt> sheepToOwner(BigInteger param0) {
final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
FUNC_SHEEPTOOWNER,
Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(param0)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteFunctionCall<TransactionReceipt> sheeps(BigInteger param0) {
final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
FUNC_SHEEPS,
Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(param0)),
Collections.<TypeReference<?>>emptyList());
return executeRemoteCallTransaction(function);
}
@Deprecated
public static SheepFactory load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return new SheepFactory(contractAddress, web3j, credentials, gasPrice, gasLimit);
}
@Deprecated
public static SheepFactory load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return new SheepFactory(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
public static SheepFactory load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
return new SheepFactory(contractAddress, web3j, credentials, contractGasProvider);
}
public static SheepFactory load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
return new SheepFactory(contractAddress, web3j, transactionManager, contractGasProvider);
}
public static RemoteCall<SheepFactory> deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
return deployRemoteCall(SheepFactory.class, web3j, credentials, contractGasProvider, BINARY, "");
}
@Deprecated
public static RemoteCall<SheepFactory> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return deployRemoteCall(SheepFactory.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
}
public static RemoteCall<SheepFactory> deploy(Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
return deployRemoteCall(SheepFactory.class, web3j, transactionManager, contractGasProvider, BINARY, "");
}
@Deprecated
public static RemoteCall<SheepFactory> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return deployRemoteCall(SheepFactory.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
}
public static class NewSheepEventResponse extends BaseEventResponse {
public BigInteger sheepId;
public String name;
public BigInteger dna;
public BigInteger hp;
public BigInteger dp;
public String imageAsset;
}
}
您生成的合约包装器是正确的。要访问您的合同数据,您必须使用包含名称事件
的方法。以太坊虚拟机将合约交互作为事件处理,并将其存储在日志中。
要获取所有过去的绵羊事件并收听新的绵羊事件,请使用:
sheepContract.newSheepFlowable(DefaultBlockParameterName.EARLIEST,
DefaultBlockParameterName.LATEST).subscribe(response -> {
/*doSomthing with response (which is of type NewSheepEventResponse )*/
});
您还可以使用web3j获取所有sheep事件。E、 g.如果您想查看所有过去的绵羊活动,请使用:
java prettyprint-override">EthFilter ethFilter = new EthFilter(DefaultBlockParameterName.EARLIEST,
DefaultBlockParameterName.LATEST, sheepContract.getContractAddress());
ethFilter.addSingleTopic(EventEncoder.encode(contract.NEWSHEEP_EVENT));
EthLog newSheepEventLog = web3j.ethGetLogs(ethFilter).send();
我想写一些这样的代码: 但是,javadoc不清楚应该使用哪个方法初始化,即哪个方法将生成: :“返回Java语言规范定义的基础类的标准名称。如果基础类没有标准名称(即,如果它是本地或匿名类,或者组件类型没有标准名称的数组),则返回null。” :“以字符串形式返回由该类对象表示的实体(类、接口、数组类、基元类型或void)的名称。如果该类对象表示的引用类型不是数组类型,则返回由Java™ 语言规
我将生成的salt前缀存储到加密文件。密码不存储,只有用户知道。 解决方案奏效了。我的问题是,今天这个解决方案是否足够好和安全?
所以我有一个Java应用程序,它使用一个固定的线程池来执行一些代码。此代码包括使用输出到系统的第三方库。犯错误当我让这段代码执行单线程时,我“重定向”了系统。错误为最终打印到log4j日志的打印流。基本上是这样的: 这按预期工作。输出打印到日志文件而不是控制台,我可以通过更改log4j配置完全删除输出。完美。 当我开始添加多线程时,我做了一些研究,遇到了这样一个问题:在多线程Java程序中,每个线
本文向大家介绍JFreeChart折线图的生成方法,包括了JFreeChart折线图的生成方法的使用技巧和注意事项,需要的朋友参考一下 JFreeChart是JAVA平台上的一个开放的图表绘制类库。它完全使用JAVA语言编写,是为applications, applets, servlets 以及JSP等使用所设计。JFreeChart可生成饼图(pie charts)、柱状图(bar chart
问题内容: 如果我想将的结果(即对象)与需要字典或类映射对象的方法一起使用(请参见collections.Mapping),那么正确的方法是什么? “进入”对象并使用其属性是否合适? 我认为答案是否定的:闻起来像执行公约,而不是一个接口,方式或或似乎是。 问题答案: 您可以使用 vars() 访问名称空间的字典: 您可以根据需要直接修改字典: 是的,可以访问__dict__属性。这是定义明确,经过
本文向大家介绍php生成图片缩略图的方法,包括了php生成图片缩略图的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了php生成图片缩略图的方法。分享给大家供大家参考。具体如下: 这里需要用到GD2 library 希望本文所述对大家的php程序设计有所帮助。