use of org.web3j.protocol.core.DefaultBlockParameter in project Ethernity-Wallet-Android by kris-krytech.
the class ERC721Token method updateBalance.
/**
* Uses both events and balance call. Each call to updateBalance uses 3 Node calls:
* 1. Get new Transfer events since last call
* 2.
* <p>
* Once we have the current balance for potential tokens the database is updated to reflect the current status
* <p>
* Note that this function is used even for contracts covered by OpenSea: This is because we could be looking at
* a contract 'join' between successive opensea reads. With accounts with huge quantity of NFT, this happens a lot
*
* @param realm
* @return
*/
@Override
public BigDecimal updateBalance(Realm realm) {
// first get current block
SyncDef sync = eventSync.getSyncDef(realm);
if (sync == null)
return balance;
DefaultBlockParameter startBlock = DefaultBlockParameter.valueOf(sync.eventReadStartBlock);
DefaultBlockParameter endBlock = DefaultBlockParameter.valueOf(sync.eventReadEndBlock);
if (sync.eventReadEndBlock.compareTo(BigInteger.valueOf(-1L)) == 0)
endBlock = DefaultBlockParameterName.LATEST;
// take a note of the current block#
BigInteger currentBlock = TransactionsService.getCurrentBlock(tokenInfo.chainId);
try {
final Web3j web3j = TokenRepository.getWeb3jService(tokenInfo.chainId);
Pair<Integer, HashSet<BigInteger>> evRead = eventSync.processTransferEvents(web3j, getTransferEvents(), startBlock, endBlock, realm);
// means our event read was fine
eventSync.updateEventReads(realm, sync, currentBlock, evRead.first);
HashSet<BigInteger> tokenIdsHeld = checkBalances(web3j, evRead.second);
// should we check existing assets too?
// add to realm
updateRealmBalance(realm, tokenIdsHeld);
return new BigDecimal(tokenIdsHeld.size());
} catch (LogOverflowException e) {
// handle log read overflow; reduce search size
if (eventSync.handleEthLogError(e.error, startBlock, endBlock, sync, realm)) {
// recurse until we find a good value
updateBalance(realm);
}
} catch (Exception e) {
Timber.w(e);
}
return balance;
}
use of org.web3j.protocol.core.DefaultBlockParameter in project Ethernity-Wallet-Android by kris-krytech.
the class SignCallbackJSInterface method ethCall.
@JavascriptInterface
public void ethCall(int callbackId, String recipient) {
try {
JSONObject json = new JSONObject(recipient);
DefaultBlockParameter defaultBlockParameter;
String to = json.has("to") ? json.getString("to") : ZERO_ADDRESS;
String payload = json.has("data") ? json.getString("data") : "0x";
String value = json.has("value") ? json.getString("value") : null;
String gasLimit = json.has("gas") ? json.getString("gas") : null;
// TODO: Take block param from query if present
defaultBlockParameter = DefaultBlockParameterName.LATEST;
Web3Call call = new Web3Call(new Address(to), defaultBlockParameter, payload, value, gasLimit, callbackId);
webView.post(() -> onEthCallListener.onEthCall(call));
} catch (Exception e) {
//
}
}
use of org.web3j.protocol.core.DefaultBlockParameter in project besu by hyperledger.
the class ContractOperations method getCode.
public static String getCode(final Quorum web3j, final String contractAddress) throws IOException {
final DefaultBlockParameter blockParam = DefaultBlockParameter.valueOf(DefaultBlockParameterName.LATEST.toString());
final EthGetCode codeResult = web3j.ethGetCode(contractAddress, blockParam).send();
assertThat(codeResult.getCode()).withFailMessage("Code for contractAddress not found.").isNotEmpty();
return codeResult.getCode();
}
use of org.web3j.protocol.core.DefaultBlockParameter in project web3j by web3j.
the class RequestTest method testParityListAccountsWithAccountOffsetWithBlockTag.
@Test
public void testParityListAccountsWithAccountOffsetWithBlockTag() throws Exception {
BigInteger maxQuantityReturned = BigInteger.valueOf(100);
DefaultBlockParameter blockParameter = DefaultBlockParameterName.LATEST;
web3j.parityListAccounts(maxQuantityReturned, "0x407d73d8a49eeb85d32cf465507dd71d507100c1", blockParameter).send();
verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"parity_listAccounts\"," + "\"params\":[100,\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\"latest\"],\"id\":1}");
}
use of org.web3j.protocol.core.DefaultBlockParameter in project alpha-wallet-android by AlphaWallet.
the class ERC1155Token method updateBalance.
/**
* Uses both events and balance call. Each call to updateBalance uses 3 Node calls:
* 1. Get new TransferSingle events since last call
* 2. Get new TransferBatch events since last call
* 3. Call ERC1155 contract function balanceOfBatch on all tokenIds
*
* Once we have the current balance for potential tokens the database is updated to reflect the current status
*
* Note that this function is used even for contracts covered by OpenSea: This is because we could be looking at
* a contract 'join' between successive opensea reads. With accounts with huge quantity of NFT, this happens a lot
*
* @param realm
* @return
*/
@Override
public BigDecimal updateBalance(Realm realm) {
SyncDef sync = eventSync.getSyncDef(realm);
if (sync == null)
return balance;
DefaultBlockParameter startBlock = DefaultBlockParameter.valueOf(sync.eventReadStartBlock);
DefaultBlockParameter endBlock = DefaultBlockParameter.valueOf(sync.eventReadEndBlock);
if (sync.eventReadEndBlock.compareTo(BigInteger.valueOf(-1L)) == 0)
endBlock = DefaultBlockParameterName.LATEST;
// take a note of the current block#
BigInteger currentBlock = TransactionsService.getCurrentBlock(tokenInfo.chainId);
try {
final Web3j web3j = TokenRepository.getWeb3jService(tokenInfo.chainId);
Pair<Integer, Pair<HashSet<BigInteger>, HashSet<BigInteger>>> evRead = eventSync.processTransferEvents(web3j, getBalanceUpdateEvents(), startBlock, endBlock, realm);
Pair<Integer, Pair<HashSet<BigInteger>, HashSet<BigInteger>>> batchRead = eventSync.processTransferEvents(web3j, getBatchBalanceUpdateEvents(), startBlock, endBlock, realm);
// All tokenIds which have passed through the owner address
evRead.second.first.addAll(evRead.second.second);
evRead.second.first.addAll(batchRead.second.first);
evRead.second.first.addAll(batchRead.second.second);
// combine the tokenIds with existing assets
evRead.second.first.addAll(assets.keySet());
// update balances of all
List<Uint256> balances = fetchBalances(evRead.second.first);
// update realm
updateRealmBalance(realm, evRead.second.first, balances);
// update read points
// means our event read was fine
eventSync.updateEventReads(realm, sync, currentBlock, evRead.first);
} catch (LogOverflowException e) {
// handle log read overflow; reduce search size
if (eventSync.handleEthLogError(e.error, startBlock, endBlock, sync, realm)) {
// recurse until we find a good value
updateBalance(realm);
}
} catch (Exception e) {
Timber.e(e);
}
return new BigDecimal(assets.keySet().size());
}
Aggregations