Web3j: Get value of transaction token transfered using Transaction Hash - spring-boot

With Web3j (not Web3js), how do I get the value of token transferred using transaction hash?

I found this example for web3j:
String transactionHash = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
TransactionReceipt transReceipt = web3j.ethGetTransactionReceipt(transactionHash).send().getTransactionReceipt();
Transaction transaction = ethTransaction.getResult();
int size = tokenImpl.getTransferEvents(transReceipt).size();
size = size -1;
BigInteger valueTransaction = tokenImpl.getTransferEvents(transReceipt).get(size).value;
The value will be recieved in BigInteger

Related

Cant get data from sql array with JDBC and HSQLDB

This code:
Array a=rs.getArray("curAccs");
ResultSet rs1=a.getResultSet();
int rs1size=rs1.getFetchSize();
return empty rs1, but a is ARRAY[221,222]
I also cant convert sql array to java
(Integer[])a2.getArray()
printing
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
How to fix it?
The array contents can be retrieved with these calls:
java.sql.Array a = rs.getArray("curAccs");
Object[] values = (Object[]) a.getArray();
Integer intValA = (Integer) values[0];
Integer intValB = (Integer) values[1];

Getting key value from key of hazelcast IMap

I put my object to hazelcast map using spring annotation:
#Cacheable(value = "cacheName", key = "{ #someId1,#someId2}")
public String generateValue(Long someId1, Long someId2)
I would like to invalidate object from cache based on condition placed on key of the Imap. I found that key is a ArrayList with size equal 2. That is expected result.
Set set = cache.keySet(); // this returns Set<ArrayList<Long>>
I try to set condition on key:
EntryObject e = new PredicateBuilder().getEntryObject();
Predicate predicateKey = e.key().get("__key#get(0)").equal(someId1).and(e.get("__key#get(1)").equal(someId2));
But invoking this predicate end up in failure:
Set<Long> idKeysToInvalidate = cache.keySet(predicateKey);
com.hazelcast.query.QueryException: java.lang.IllegalArgumentException: There is no suitable accessor for '__key#get(0)' on class 'class java.util.ArrayList'
at com.hazelcast.query.impl.getters.ReflectionHelper.createGetter(ReflectionHelper.java:176)
Did anyone encounter the same issue?
I haven't done it myself, at least on a key, but can you try __key#[0] otherwise see here: http://docs.hazelcast.org/docs/3.8/manual/html-single/index.html#querying-in-collections-and-arrays
I solved issue as below:
EntryObject e = new PredicateBuilder().getEntryObject();
List<Long> input = Arrays.asList(someId1, someId2);
Predicate predicateKey = e.key().get("hashCode").equal(input.hashCode());
Set<List> idKeysToInvalidate = cache.keySet(predicateKey);

Hashing session key

I'm attempting to hash a session key but I'm getting an error of cannot convert from string to byte[]
I'm assuming that the hash stores it in a byte array but why is it throwing errors on a session key variable.
var Sha1Hash = System.Security.Cryptography.SHA1.Create();
var hash = Sha1Hash.ComputeHash(HttpContext.Session.GetString(SessionKeyName));
You need to convert string (HttpContext.Session.GetString(SessionKeyName)) into byte array
var hash = Sha1Hash.ComputeHash(Encoding.ASCII.GetBytes(HttpContext.Session.GetString(SessionKeyName)));

Java8 stream average of object property in collection

I'm new to Java so if this has already been answered somewhere else then I either don't know enough to search for the correct things or I just couldn't understand the answers.
So the question being:
I have a bunch of objects in a list:
try(Stream<String> logs = Files.lines(Paths.get(args))) {
return logs.map(LogLine::parseLine).collect(Collectors.toList());
}
And this is how the properties are added:
LogLine line = new LogLine();
line.setUri(matcher.group("uri"));
line.setrequestDuration(matcher.group("requestDuration"));
....
How do I sort logs so that I end up with list where objects with same "uri" are displayed only once with average requestDuration.
Example:
object1.uri = 'uri1', object1.requestDuration = 20;
object2.uri = 'uri2', object2.requestDuration = 30;
object3.uri = 'uri1', object3.requestDuration = 50;
Result:
object1.uri = 'uri1', 35;
object2.uri = 'uri2', 30;
Thanks in advance!
Take a look at Collectors.groupingBy and Collectors.averagingDouble. In your case, you could use them as follows:
Map<String, Double> result = logLines.stream()
.collect(Collectors.groupingBy(
LogLine::getUri,
TreeMap::new,
Collectors.averagingDouble(LogLine::getRequestDuration)));
The Collectors.groupingBy method does what you want. It is overloaded, so that you can specify the function that returns the key to group elements by, the factory that creates the returned map (I'm using TreeMap here, because you want the entries ordered by key, in this case the URI), and a downstream collector, which collects the elements that match the key returned by the first parameter.
If you want an Integer instead of a Double value for the averages, consider using Collectors.averagingInt.
This assumes LogLine has getUri() and getRequestDuration() methods.

How to get the maximum value from local database in windows phone?

I need to get the maximum value from table that should belongs to particular category.
My code as follows :
private int getHighScores(int _playMode)
{
int maxScore = 0;
using (HangmanScoreDataContext hangmanDB = new HangmanScoreDataContext(#"isostore:/HangmanScoreDB.sdf"))
{
IQueryable<TbleHangmanScore> sqlQuery = hangmanDB._tbleHangman;
sqlQuery = sqlQuery.Where(p => p.playMode == _playMode);
maxScore = sqlQuery.AsQueryable().Max(p => p.score);
}
return maxScore;
}
I am getting error like
an unhandled exception of type 'system.stackoverflowexception' occurred in unknown module.
Except maximum value rest of the things working properly . How can i solve this issue ?
Edit : Problem arises only when the table contains zero numbers of records. Same problem when i trying to get the minimum value also.

Resources