feat: update event mechanism

add event type local and global, clients have to use contractID and topic to subscribe local event; allow clients to subscribe topics (will not be recorded)
This commit is contained in:
Frank.R.Wu 2021-10-31 23:07:15 +08:00
parent 1ce2d05992
commit 9553f2a783
14 changed files with 12198 additions and 15492 deletions

View File

@ -1,10 +1,23 @@
package org.bdware.sc.conn;
import io.netty.channel.Channel;
import io.netty.util.Timeout;
public abstract class ResultCallback {
// private static final Logger LOGGER = LogManager.getLogger(ResultCallback.class);
Timeout task;
private Channel channel;
public ResultCallback() {
}
public ResultCallback(Channel channel) {
this.channel = channel;
}
public Channel getChannel() {
return channel;
}
public abstract void onResult(String str);

View File

@ -3,19 +3,18 @@ package org.bdware.sc.node;
import org.antlr.v4.runtime.CommonTokenStream;
import org.bdware.sc.event.REvent.REventSemantics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import java.util.*;
import static org.bdware.sc.event.REvent.REventSemantics.AT_LEAST_ONCE;
public class ContractNode {
private final List<ImportNode> imports;
private final List<ClassNode> clzs;
private final List<FunctionNode> functions;
private final Map<String, FunctionNode> functionMap;
private final Set<String> dependentContracts;
public Map<String, REventSemantics> events;
public Map<String, REventSemantics> logs;
public List<AnnotationNode> annotations;
public boolean sigRequired;
public String memorySet;
@ -25,7 +24,6 @@ public class ContractNode {
List<LogType> logTypes;
YjsType yjsType;
boolean instrumentBranch;
private final Set<String> dependentContracts;
public ContractNode(String name) {
contractName = name;
@ -35,6 +33,7 @@ public class ContractNode {
functionMap = new HashMap<>();
isBundle = false;
events = new HashMap<>();
logs = new HashMap<>();
annotations = new ArrayList<>();
permission = new ArrayList<>();
instrumentBranch = false;
@ -119,8 +118,11 @@ public class ContractNode {
functionMap.put(fn.functionName, fn);
}
clzs.addAll(contract.clzs);
contract.events.forEach((e, s) -> this.events.put(e, s));
if (null != contract.permission) permission.addAll(contract.permission);
this.events.putAll(contract.events);
this.logs.putAll(contract.logs);
if (null != contract.permission) {
permission.addAll(contract.permission);
}
if (null != contract.annotations) {
annotations.addAll(contract.annotations);
}
@ -144,15 +146,12 @@ public class ContractNode {
dependentContracts.add(contractName);
}
public void addEvent(String eventName) {
this.events.put(eventName, REventSemantics.AT_LEAST_ONCE);
}
public void addEvent(String eventName, String semantics) {
public void addEvent(String eventName, String semantics, boolean isGlobal) {
Map<String, REventSemantics> pointer = (isGlobal ? this.events : this.logs);
try {
this.events.put(eventName, REventSemantics.valueOf(semantics));
pointer.put(eventName, REventSemantics.valueOf(semantics));
} catch (IllegalArgumentException | NullPointerException e) {
this.events.put(eventName, REventSemantics.AT_LEAST_ONCE);
pointer.put(eventName, AT_LEAST_ONCE);
}
}
@ -190,11 +189,11 @@ public class ContractNode {
this.yjsType = yjsType1;
}
public void setInstrumentBranch(boolean b) {
instrumentBranch = b;
}
public boolean getInstrumentBranch() {
return instrumentBranch;
}
public void setInstrumentBranch(boolean b) {
instrumentBranch = b;
}
}

View File

@ -1,5 +1,7 @@
package org.bdware.sc.visitor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.sc.node.*;
import org.bdware.sc.parser.YJSParser;
import org.bdware.sc.parser.YJSParser.*;
@ -9,7 +11,7 @@ import java.util.ArrayList;
import java.util.List;
public class ContractReader extends YJSParserBaseVisitor<ContractNode> {
// private static final Logger LOGGER = LogManager.getLogger(ContractReader.class);
private static final Logger LOGGER = LogManager.getLogger(ContractReader.class);
String fileName;
public ContractReader(String fileName) {
@ -101,11 +103,12 @@ public class ContractReader extends YJSParserBaseVisitor<ContractNode> {
} else if (null != clzOrFunction.eventDeclaration()) {
EventDeclarationContext event = clzOrFunction.eventDeclaration();
EventSemanticsContext eventSemanticsContext = event.eventSemantics();
if (null == eventSemanticsContext) {
node.addEvent(event.Identifier().getText());
} else {
node.addEvent(event.Identifier().getText(), eventSemanticsContext.getText());
}
EventGlobalOrLocalContext eventGlobalOrLocalContext = event.eventGlobalOrLocal();
String semantics = (null == eventSemanticsContext ? null : eventSemanticsContext.getText());
boolean isGlobal =
(null != eventGlobalOrLocalContext &&
eventGlobalOrLocalContext.getText().equals("global"));
node.addEvent(event.Identifier().getText(), semantics, isGlobal);
}
}
// ctx.getSourceInterval()

View File

@ -218,10 +218,12 @@ public class Contract extends SM2Verifiable implements Serializable {
this.Mask.put(FunctionName, Mask);
}
public long getBuildTime() {
return buildTime;
}
public void setBuildTime(long buildTime) {
this.buildTime = buildTime;
}
public long getBuildTime() { return buildTime; }
}

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -89,33 +89,35 @@ AtToken=88
AtLeastOnce=89
AtMostOnce=90
OnlyOnce=91
Class=92
Enum=93
Extends=94
Super=95
Const=96
Export=97
Import=98
Contract=99
Module=100
Oracle=101
Implements=102
Let=103
Private=104
Public=105
Interface=106
Package=107
Protected=108
Static=109
Yield=110
Identifier=111
StringLiteral=112
TemplateStringLiteral=113
WhiteSpaces=114
LineTerminator=115
HtmlComment=116
CDataComment=117
UnexpectedCharacter=118
Global=92
Local=93
Class=94
Enum=95
Extends=96
Super=97
Const=98
Export=99
Import=100
Contract=101
Module=102
Oracle=103
Implements=104
Let=105
Private=106
Public=107
Interface=108
Package=109
Protected=110
Static=111
Yield=112
Identifier=113
StringLiteral=114
TemplateStringLiteral=115
WhiteSpaces=116
LineTerminator=117
HtmlComment=118
CDataComment=119
UnexpectedCharacter=120
'['=4
']'=5
'('=6
@ -198,22 +200,24 @@ UnexpectedCharacter=118
'AT_LEAST_ONCE'=89
'AT_MOST_ONCE'=90
'ONLY_ONCE'=91
'class'=92
'enum'=93
'extends'=94
'super'=95
'const'=96
'export'=97
'import'=98
'contract'=99
'module'=100
'oracle'=101
'implements'=102
'let'=103
'private'=104
'public'=105
'interface'=106
'package'=107
'protected'=108
'static'=109
'yield'=110
'global'=92
'local'=93
'class'=94
'enum'=95
'extends'=96
'super'=97
'const'=98
'export'=99
'import'=100
'contract'=101
'module'=102
'oracle'=103
'implements'=104
'let'=105
'private'=106
'public'=107
'interface'=108
'package'=109
'protected'=110
'static'=111
'yield'=112

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -89,33 +89,35 @@ AtToken=88
AtLeastOnce=89
AtMostOnce=90
OnlyOnce=91
Class=92
Enum=93
Extends=94
Super=95
Const=96
Export=97
Import=98
Contract=99
Module=100
Oracle=101
Implements=102
Let=103
Private=104
Public=105
Interface=106
Package=107
Protected=108
Static=109
Yield=110
Identifier=111
StringLiteral=112
TemplateStringLiteral=113
WhiteSpaces=114
LineTerminator=115
HtmlComment=116
CDataComment=117
UnexpectedCharacter=118
Global=92
Local=93
Class=94
Enum=95
Extends=96
Super=97
Const=98
Export=99
Import=100
Contract=101
Module=102
Oracle=103
Implements=104
Let=105
Private=106
Public=107
Interface=108
Package=109
Protected=110
Static=111
Yield=112
Identifier=113
StringLiteral=114
TemplateStringLiteral=115
WhiteSpaces=116
LineTerminator=117
HtmlComment=118
CDataComment=119
UnexpectedCharacter=120
'['=4
']'=5
'('=6
@ -198,22 +200,24 @@ UnexpectedCharacter=118
'AT_LEAST_ONCE'=89
'AT_MOST_ONCE'=90
'ONLY_ONCE'=91
'class'=92
'enum'=93
'extends'=94
'super'=95
'const'=96
'export'=97
'import'=98
'contract'=99
'module'=100
'oracle'=101
'implements'=102
'let'=103
'private'=104
'public'=105
'interface'=106
'package'=107
'protected'=108
'static'=109
'yield'=110
'global'=92
'local'=93
'class'=94
'enum'=95
'extends'=96
'super'=97
'const'=98
'export'=99
'import'=100
'contract'=101
'module'=102
'oracle'=103
'implements'=104
'let'=105
'private'=106
'public'=107
'interface'=108
'package'=109
'protected'=110
'static'=111
'yield'=112

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff