Search in sources :

Example 46 with TypeReference

use of org.fisco.bcos.web3j.abi.TypeReference in project web3sdk by FISCO-BCOS.

the class ContractAbiUtil method decodeEvent.

/**
 * @param log
 * @param abiDefinition
 * @return
 * @throws BaseException
 */
public static EventValues decodeEvent(Log log, AbiDefinition abiDefinition) throws BaseException {
    List<TypeReference<?>> finalOutputs = paramFormat(abiDefinition.getInputs());
    Event event = new Event(abiDefinition.getName(), finalOutputs);
    EventValues eventValues = Contract.staticExtractEventParameters(event, log);
    return eventValues;
}
Also used : EventValues(org.fisco.bcos.web3j.abi.EventValues) Event(org.fisco.bcos.web3j.abi.datatypes.Event) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Example 47 with TypeReference

use of org.fisco.bcos.web3j.abi.TypeReference in project web3sdk by FISCO-BCOS.

the class CallContractTest method testAsyncCallContract.

private static void testAsyncCallContract(CallContract callContract, String address) {
    TransactionCallback callback = new TransactionCallback();
    TransactionReceipt receipt;
    callContract.asyncSendTransaction(callback, gasPrice, gasLimit, address, "setAndget", new Utf8String("hello world"), new Int256(10086));
    try {
        callback.semaphore.acquire(1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        System.out.println(e.getLocalizedMessage());
    }
    receipt = callback.receipt;
    List<TypeReference<?>> referencesList = Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
    }, new TypeReference<Int256>() {
    });
    List<Type> returnList1 = FunctionReturnDecoder.decode(receipt.getOutput(), Utils.convert(referencesList));
    System.out.println("async call setAndget: " + (String) returnList1.get(0).getValue() + ", " + (BigInteger) returnList1.get(1).getValue());
    callContract.asyncSendTransaction(callback, address, "setAndget", new Utf8String("hello world"), new Int256(10086));
    try {
        callback.semaphore.acquire(1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        System.out.println(e.getLocalizedMessage());
    }
    receipt = callback.receipt;
    referencesList = Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
    }, new TypeReference<Int256>() {
    });
    List<Type> returnList2 = FunctionReturnDecoder.decode(receipt.getOutput(), Utils.convert(referencesList));
    System.out.println("default async call setAndget: " + (String) returnList2.get(0).getValue() + ", " + (BigInteger) returnList2.get(1).getValue());
}
Also used : TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Utf8String(org.fisco.bcos.web3j.abi.datatypes.Utf8String) Int256(org.fisco.bcos.web3j.abi.datatypes.generated.Int256) Type(org.fisco.bcos.web3j.abi.datatypes.Type) BigInteger(java.math.BigInteger) TypeReference(org.fisco.bcos.web3j.abi.TypeReference)

Aggregations

TypeReference (org.fisco.bcos.web3j.abi.TypeReference)47 Type (org.fisco.bcos.web3j.abi.datatypes.Type)45 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)42 Function (org.fisco.bcos.web3j.abi.datatypes.Function)38 Tuple1 (org.fisco.bcos.web3j.tuples.generated.Tuple1)26 EncryptType (org.fisco.bcos.web3j.crypto.EncryptType)11 Int256 (org.fisco.bcos.web3j.abi.datatypes.generated.Int256)10 ArrayList (java.util.ArrayList)9 NamedType (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType)9 Bool (org.fisco.bcos.web3j.abi.datatypes.Bool)8 DynamicBytes (org.fisco.bcos.web3j.abi.datatypes.DynamicBytes)8 Bytes32 (org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32)8 Address (org.fisco.bcos.web3j.abi.datatypes.Address)7 Uint256 (org.fisco.bcos.web3j.abi.datatypes.generated.Uint256)7 Test (org.junit.Test)7 Event (org.fisco.bcos.web3j.abi.datatypes.Event)6 AbiDefinition (org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition)6 Tuple2 (org.fisco.bcos.web3j.tuples.generated.Tuple2)6 List (java.util.List)5 DynamicArray (org.fisco.bcos.web3j.abi.datatypes.DynamicArray)5