Updated on 2026-08-14

This commit is contained in:
Tangem 2024-02-07 16:37:03 +04:00
parent e239275ca8
commit 6d7042f24c
14 changed files with 3748 additions and 1 deletions

View file

@ -0,0 +1,270 @@
package com.tangem.lib.visa;
import org.web3j.abi.EventEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Event;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Utf8String;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.abi.datatypes.generated.Uint8;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
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;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import io.reactivex.Flowable;
/**
* <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 1.5.0.
*/
@SuppressWarnings("rawtypes")
class ERC20 extends Contract {
public static final String BINARY = "Bin file was not provided";
public static final String FUNC_ALLOWANCE = "allowance";
public static final String FUNC_APPROVE = "approve";
public static final String FUNC_BALANCEOF = "balanceOf";
public static final String FUNC_DECIMALS = "decimals";
public static final String FUNC_NAME = "name";
public static final String FUNC_SYMBOL = "symbol";
public static final String FUNC_TOTALSUPPLY = "totalSupply";
public static final String FUNC_TRANSFER = "transfer";
public static final String FUNC_TRANSFERFROM = "transferFrom";
public static final Event APPROVAL_EVENT = new Event("Approval",
Arrays.asList(new TypeReference<Address>(true) {
}, new TypeReference<Address>(true) {
}, new TypeReference<Uint256>() {
}));
public static final Event TRANSFER_EVENT = new Event("Transfer",
Arrays.asList(new TypeReference<Address>(true) {
}, new TypeReference<Address>(true) {
}, new TypeReference<Uint256>() {
}));
@Deprecated
protected ERC20(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
protected ERC20(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
@Deprecated
protected ERC20(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
protected ERC20(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
}
public static List<ApprovalEventResponse> getApprovalEvents(TransactionReceipt transactionReceipt) {
List<EventValuesWithLog> valueList = staticExtractEventParametersWithLog(APPROVAL_EVENT, transactionReceipt);
ArrayList<ApprovalEventResponse> responses = new ArrayList<ApprovalEventResponse>(valueList.size());
for (EventValuesWithLog eventValues : valueList) {
ApprovalEventResponse typedResponse = new ApprovalEventResponse();
typedResponse.log = eventValues.getLog();
typedResponse.owner = (String) eventValues.getIndexedValues().get(0).getValue();
typedResponse.spender = (String) eventValues.getIndexedValues().get(1).getValue();
typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
responses.add(typedResponse);
}
return responses;
}
public static ApprovalEventResponse getApprovalEventFromLog(Log log) {
EventValuesWithLog eventValues = staticExtractEventParametersWithLog(APPROVAL_EVENT, log);
ApprovalEventResponse typedResponse = new ApprovalEventResponse();
typedResponse.log = log;
typedResponse.owner = (String) eventValues.getIndexedValues().get(0).getValue();
typedResponse.spender = (String) eventValues.getIndexedValues().get(1).getValue();
typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
return typedResponse;
}
public static List<TransferEventResponse> getTransferEvents(TransactionReceipt transactionReceipt) {
List<EventValuesWithLog> valueList = staticExtractEventParametersWithLog(TRANSFER_EVENT, transactionReceipt);
ArrayList<TransferEventResponse> responses = new ArrayList<TransferEventResponse>(valueList.size());
for (EventValuesWithLog eventValues : valueList) {
TransferEventResponse typedResponse = new TransferEventResponse();
typedResponse.log = eventValues.getLog();
typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
typedResponse.to = (String) eventValues.getIndexedValues().get(1).getValue();
typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
responses.add(typedResponse);
}
return responses;
}
@Deprecated
public static ERC20 load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return new ERC20(contractAddress, web3j, credentials, gasPrice, gasLimit);
}
@Deprecated
public static ERC20 load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return new ERC20(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
public static TransferEventResponse getTransferEventFromLog(Log log) {
EventValuesWithLog eventValues = staticExtractEventParametersWithLog(TRANSFER_EVENT, log);
TransferEventResponse typedResponse = new TransferEventResponse();
typedResponse.log = log;
typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
typedResponse.to = (String) eventValues.getIndexedValues().get(1).getValue();
typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
return typedResponse;
}
public static ERC20 load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
return new ERC20(contractAddress, web3j, credentials, contractGasProvider);
}
public static ERC20 load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
return new ERC20(contractAddress, web3j, transactionManager, contractGasProvider);
}
public Flowable<TransferEventResponse> transferEventFlowable(EthFilter filter) {
return web3j.ethLogFlowable(filter).map(log -> getTransferEventFromLog(log));
}
public Flowable<TransferEventResponse> transferEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
filter.addSingleTopic(EventEncoder.encode(TRANSFER_EVENT));
return transferEventFlowable(filter);
}
public Flowable<ApprovalEventResponse> approvalEventFlowable(EthFilter filter) {
return web3j.ethLogFlowable(filter).map(log -> getApprovalEventFromLog(log));
}
public Flowable<ApprovalEventResponse> approvalEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
filter.addSingleTopic(EventEncoder.encode(APPROVAL_EVENT));
return approvalEventFlowable(filter);
}
public RemoteFunctionCall<BigInteger> allowance(String owner, String spender) {
final Function function = new Function(FUNC_ALLOWANCE,
Arrays.asList(new Address(160, owner),
new Address(160, spender)),
List.of(new TypeReference<Uint256>() {
}));
return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}
public RemoteFunctionCall<TransactionReceipt> approve(String spender, BigInteger value) {
final Function function = new Function(
FUNC_APPROVE,
Arrays.asList(new Address(160, spender),
new Uint256(value)),
Collections.emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteFunctionCall<BigInteger> balanceOf(String account) {
final Function function = new Function(FUNC_BALANCEOF,
List.of(new Address(160, account)),
List.of(new TypeReference<Uint256>() {
}));
return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}
public RemoteFunctionCall<BigInteger> decimals() {
final Function function = new Function(FUNC_DECIMALS,
List.of(),
List.of(new TypeReference<Uint8>() {
}));
return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}
public RemoteFunctionCall<String> name() {
final Function function = new Function(FUNC_NAME,
List.of(),
List.of(new TypeReference<Utf8String>() {
}));
return executeRemoteCallSingleValueReturn(function, String.class);
}
public RemoteFunctionCall<String> symbol() {
final Function function = new Function(FUNC_SYMBOL,
List.of(),
List.of(new TypeReference<Utf8String>() {
}));
return executeRemoteCallSingleValueReturn(function, String.class);
}
public RemoteFunctionCall<BigInteger> totalSupply() {
final Function function = new Function(FUNC_TOTALSUPPLY,
List.of(),
List.of(new TypeReference<Uint256>() {
}));
return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}
public RemoteFunctionCall<TransactionReceipt> transfer(String to, BigInteger value) {
final Function function = new Function(
FUNC_TRANSFER,
Arrays.asList(new Address(160, to),
new Uint256(value)),
Collections.emptyList());
return executeRemoteCallTransaction(function);
}
public RemoteFunctionCall<TransactionReceipt> transferFrom(String from, String to, BigInteger value) {
final Function function = new Function(
FUNC_TRANSFERFROM,
Arrays.asList(new Address(160, from),
new Address(160, to),
new Uint256(value)),
Collections.emptyList());
return executeRemoteCallTransaction(function);
}
public static class ApprovalEventResponse extends BaseEventResponse {
public String owner;
public String spender;
public BigInteger value;
}
public static class TransferEventResponse extends BaseEventResponse {
public String from;
public String to;
public BigInteger value;
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long