KKSU
2024-04-28 673d9890158a00c42a0cb187d7f40b599d272da9
src/main/java/cc/mrbird/febs/dapp/chain/EthUsdtContract.java
@@ -3,6 +3,8 @@
import io.reactivex.Flowable;
import io.reactivex.functions.Function;
import org.web3j.abi.EventEncoder;
import org.web3j.abi.EventValues;
import org.web3j.abi.FunctionReturnDecoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.*;
import org.web3j.abi.datatypes.generated.Uint256;
@@ -146,6 +148,67 @@
    public static final Event TRANSFER_EVENT = new Event("Transfer",
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true) {}, new TypeReference<Address>(true) {}, new TypeReference<Uint256>() {}));
    ;
    /**
     *        {
     *       "anonymous": false,
     *       "inputs": [
     *                        {
     *             "indexed": false,
     *             "internalType": "address",
     *             "name": "adr",
     *             "type": "address"
     *            },
     *            {
     *             "indexed": false,
     *             "internalType": "uint256",
     *             "name": "amount",
     *             "type": "uint256"
     *            },
     *            {
     *             "indexed": false,
     *             "internalType": "uint256",
     *             "name": "price",
     *             "type": "uint256"
     *            },
     *            {
     *             "indexed": false,
     *             "internalType": "uint256",
     *             "name": "sameCoin",
     *             "type": "uint256"
     *            },
     *            {
     *             "indexed": false,
     *             "internalType": "uint256",
     *             "name": "finxMineCoin",
     *             "type": "uint256"
     *            },
     *            {
     *             "indexed": false,
     *             "internalType": "uint256",
     *             "name": "lastMineTime",
     *             "type": "uint256"
     *            },
     *            {
     *             "indexed": false,
     *             "internalType": "uint256",
     *             "name": "thisMineTime",
     *             "type": "uint256"
     *            }
     *       ],
     *       "name": "CoinReward",
     *       "type": "event"
     *    }
     */
    public static final Event COINREWARD_EVENT = new Event("CoinReward",
            Arrays.<TypeReference<?>>asList(
                    new TypeReference<Address>(false) {},
                    new TypeReference<Uint256>(false) {},
                    new TypeReference<Uint256>(false) {},
                    new TypeReference<Uint256>(false) {},
                    new TypeReference<Uint256>(false) {},
                    new TypeReference<Uint256>(false) {},
                    new TypeReference<Uint256>(false) {}));
    ;
    @Deprecated
@@ -317,6 +380,55 @@
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(TRANSFER_EVENT));
        return transferEventFlowable(filter);
    }
    public Flowable<CoinRewardEventResponse> coinRewardEventFlowable(EthFilter filter) {
        return web3j.ethLogFlowable(filter).map(new Function<Log, CoinRewardEventResponse>() {
            @Override
            public CoinRewardEventResponse apply(Log log) {
                final List<String> topics = log.getTopics();
                String encodedEventSignature = EventEncoder.encode(COINREWARD_EVENT);
                if (topics == null || topics.size() == 0 || !topics.get(0).equals(encodedEventSignature)) {
                    return null;
                }
                List<Type> indexedValues = new ArrayList<>();
                List<Type> nonIndexedValues =
                        FunctionReturnDecoder.decode(log.getData(), COINREWARD_EVENT.getNonIndexedParameters());
                List<TypeReference<Type>> indexedParameters = COINREWARD_EVENT.getIndexedParameters();
                for (int i = 0; i < indexedParameters.size(); i++) {
                    Type value =
                            FunctionReturnDecoder.decodeIndexedValue(
                                    topics.get(i + 1), indexedParameters.get(i));
                    indexedValues.add(value);
                }
                final EventValues eventValues = new EventValues(indexedValues, nonIndexedValues);
//                EventValuesWithLog eventValues = extractEventParametersWithLog(COINREWARD_EVENT, log);
                CoinRewardEventResponse typedResponse = new CoinRewardEventResponse();
                if(eventValues!=null){
                    typedResponse.adr = (String) eventValues.getNonIndexedValues().get(0).getValue();
                    typedResponse.amount = (BigInteger) eventValues.getNonIndexedValues().get(1).getValue();
                    typedResponse.price = (BigInteger) eventValues.getNonIndexedValues().get(2).getValue();
                    typedResponse.sameCoin = (BigInteger) eventValues.getNonIndexedValues().get(3).getValue();
                    typedResponse.finxMineCoin = (BigInteger) eventValues.getNonIndexedValues().get(4).getValue();
                    typedResponse.lastMineTime = (BigInteger) eventValues.getNonIndexedValues().get(5).getValue();
                    typedResponse.thisMineTime = (BigInteger) eventValues.getNonIndexedValues().get(6).getValue();
                }
                return typedResponse;
            }
        });
    }
    public static void main(String[] args) {
        System.out.println(EventEncoder.encode(COINREWARD_EVENT));
    }
    public Flowable<CoinRewardEventResponse> coinRewardEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(TRANSFER_EVENT));
        return coinRewardEventFlowable(filter);
    }
    public RemoteFunctionCall<BigInteger> allowance(String tokenOwner, String spender) {
@@ -717,4 +829,15 @@
        public BigInteger tokens;
    }
    public static class CoinRewardEventResponse extends BaseEventResponse {
        public String adr;
        public BigInteger amount;
        public BigInteger price;
        public BigInteger sameCoin;
        public BigInteger finxMineCoin;
        public BigInteger lastMineTime;
        public BigInteger thisMineTime;
    }
}