Merge branch 'upgrade-schema-2020-03' of https://github.com/AlphaWallet/alpha-wallet-android into upgrade-schema-2020-03
commit
5c59c5c749
@ -0,0 +1,60 @@ |
||||
package com.alphawallet.token.entity; |
||||
|
||||
import java.math.BigInteger; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* Created by JB on 21/03/2020. |
||||
*/ |
||||
public class EventDefinition |
||||
{ |
||||
public ContractInfo originContract; |
||||
public String attributeId; //TransactionResult: method
|
||||
public String eventName; |
||||
public Module eventModule; |
||||
public String filter; |
||||
public String select; |
||||
public BigInteger readBlock; |
||||
public boolean hasNewEvent = false; |
||||
|
||||
public String getFilterTopicValue() |
||||
{ |
||||
// (\+\d{4}|\-\d{4})
|
||||
Matcher m = Pattern.compile("\\$\\{([^}]+)\\}").matcher(filter); |
||||
String item = m.find() ? m.group(1) : null; |
||||
return item; |
||||
} |
||||
|
||||
public String getFilterTopicIndex() |
||||
{ |
||||
String[] item = filter.split("="); |
||||
return item[0]; |
||||
} |
||||
|
||||
public int getTopicIndex(String filterTopic) |
||||
{ |
||||
if (eventModule == null || filterTopic == null) return -1; |
||||
return eventModule.getTopicIndex(filterTopic); |
||||
} |
||||
|
||||
public int getSelectIndex(boolean indexed) |
||||
{ |
||||
int index = 0; |
||||
boolean found = false; |
||||
for (String label : eventModule.getArgNames(indexed)) |
||||
{ |
||||
if (label.equals(select)) |
||||
{ |
||||
found = true; |
||||
break; |
||||
} |
||||
else |
||||
{ |
||||
index++; |
||||
} |
||||
} |
||||
|
||||
return found ? index : -1; |
||||
} |
||||
} |
@ -0,0 +1,89 @@ |
||||
package com.alphawallet.token.entity; |
||||
|
||||
import org.w3c.dom.Element; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by JB on 20/03/2020. |
||||
*/ |
||||
public class Module |
||||
{ |
||||
public final ContractInfo contractInfo; |
||||
public List<SequenceElement> sequence = new ArrayList<>(); |
||||
|
||||
public Module(ContractInfo info) |
||||
{ |
||||
contractInfo = info; |
||||
} |
||||
|
||||
public void addSequenceElement(Element element, String sequenceName) throws Exception |
||||
{ |
||||
SequenceElement se = new SequenceElement(); |
||||
String indexed = element.getAttribute("ethereum:indexed"); |
||||
se.indexed = indexed != null && indexed.equalsIgnoreCase("true"); |
||||
se.type = element.getAttribute("ethereum:type"); |
||||
se.name = element.getAttribute("name"); |
||||
sequence.add(se); |
||||
|
||||
if (se.type == null) |
||||
{ |
||||
throw new Exception("Malformed sequence element in: " + sequenceName + " name: " + se.name); |
||||
} |
||||
else if (se.name == null) |
||||
{ |
||||
throw new Exception("Malformed sequence element in: " + sequenceName + " type: " + se.type); |
||||
} |
||||
} |
||||
|
||||
|
||||
public List<SequenceElement> getSequenceArgs() |
||||
{ |
||||
return sequence; |
||||
} |
||||
|
||||
public List<String> getArgNames(boolean indexed) |
||||
{ |
||||
List<String> argNameIndexedList = new ArrayList<>(); |
||||
for (SequenceElement se : sequence) |
||||
{ |
||||
if (se.indexed == indexed) |
||||
{ |
||||
argNameIndexedList.add(se.name); |
||||
} |
||||
} |
||||
|
||||
return argNameIndexedList; |
||||
} |
||||
|
||||
int getTopicIndex(String filterTopic) |
||||
{ |
||||
int topicIndex = -1; |
||||
int currentIndex = 0; |
||||
for (SequenceElement se : sequence) |
||||
{ |
||||
if (se.indexed) |
||||
{ |
||||
if (se.name.equals(filterTopic)) |
||||
{ |
||||
topicIndex = currentIndex; |
||||
break; |
||||
} |
||||
else |
||||
{ |
||||
currentIndex++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
return topicIndex; |
||||
} |
||||
|
||||
public class SequenceElement |
||||
{ |
||||
public String name; |
||||
public String type; |
||||
public boolean indexed; |
||||
} |
||||
} |
Loading…
Reference in new issue