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

View File

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

View File

@ -218,10 +218,12 @@ public class Contract extends SM2Verifiable implements Serializable {
this.Mask.put(FunctionName, Mask); this.Mask.put(FunctionName, Mask);
} }
public long getBuildTime() {
return buildTime;
}
public void setBuildTime(long buildTime) { public void setBuildTime(long buildTime) {
this.buildTime = 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 AtLeastOnce=89
AtMostOnce=90 AtMostOnce=90
OnlyOnce=91 OnlyOnce=91
Class=92 Global=92
Enum=93 Local=93
Extends=94 Class=94
Super=95 Enum=95
Const=96 Extends=96
Export=97 Super=97
Import=98 Const=98
Contract=99 Export=99
Module=100 Import=100
Oracle=101 Contract=101
Implements=102 Module=102
Let=103 Oracle=103
Private=104 Implements=104
Public=105 Let=105
Interface=106 Private=106
Package=107 Public=107
Protected=108 Interface=108
Static=109 Package=109
Yield=110 Protected=110
Identifier=111 Static=111
StringLiteral=112 Yield=112
TemplateStringLiteral=113 Identifier=113
WhiteSpaces=114 StringLiteral=114
LineTerminator=115 TemplateStringLiteral=115
HtmlComment=116 WhiteSpaces=116
CDataComment=117 LineTerminator=117
UnexpectedCharacter=118 HtmlComment=118
CDataComment=119
UnexpectedCharacter=120
'['=4 '['=4
']'=5 ']'=5
'('=6 '('=6
@ -198,22 +200,24 @@ UnexpectedCharacter=118
'AT_LEAST_ONCE'=89 'AT_LEAST_ONCE'=89
'AT_MOST_ONCE'=90 'AT_MOST_ONCE'=90
'ONLY_ONCE'=91 'ONLY_ONCE'=91
'class'=92 'global'=92
'enum'=93 'local'=93
'extends'=94 'class'=94
'super'=95 'enum'=95
'const'=96 'extends'=96
'export'=97 'super'=97
'import'=98 'const'=98
'contract'=99 'export'=99
'module'=100 'import'=100
'oracle'=101 'contract'=101
'implements'=102 'module'=102
'let'=103 'oracle'=103
'private'=104 'implements'=104
'public'=105 'let'=105
'interface'=106 'private'=106
'package'=107 'public'=107
'protected'=108 'interface'=108
'static'=109 'package'=109
'yield'=110 '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 AtLeastOnce=89
AtMostOnce=90 AtMostOnce=90
OnlyOnce=91 OnlyOnce=91
Class=92 Global=92
Enum=93 Local=93
Extends=94 Class=94
Super=95 Enum=95
Const=96 Extends=96
Export=97 Super=97
Import=98 Const=98
Contract=99 Export=99
Module=100 Import=100
Oracle=101 Contract=101
Implements=102 Module=102
Let=103 Oracle=103
Private=104 Implements=104
Public=105 Let=105
Interface=106 Private=106
Package=107 Public=107
Protected=108 Interface=108
Static=109 Package=109
Yield=110 Protected=110
Identifier=111 Static=111
StringLiteral=112 Yield=112
TemplateStringLiteral=113 Identifier=113
WhiteSpaces=114 StringLiteral=114
LineTerminator=115 TemplateStringLiteral=115
HtmlComment=116 WhiteSpaces=116
CDataComment=117 LineTerminator=117
UnexpectedCharacter=118 HtmlComment=118
CDataComment=119
UnexpectedCharacter=120
'['=4 '['=4
']'=5 ']'=5
'('=6 '('=6
@ -198,22 +200,24 @@ UnexpectedCharacter=118
'AT_LEAST_ONCE'=89 'AT_LEAST_ONCE'=89
'AT_MOST_ONCE'=90 'AT_MOST_ONCE'=90
'ONLY_ONCE'=91 'ONLY_ONCE'=91
'class'=92 'global'=92
'enum'=93 'local'=93
'extends'=94 'class'=94
'super'=95 'enum'=95
'const'=96 'extends'=96
'export'=97 'super'=97
'import'=98 'const'=98
'contract'=99 'export'=99
'module'=100 'import'=100
'oracle'=101 'contract'=101
'implements'=102 'module'=102
'let'=103 'oracle'=103
'private'=104 'implements'=104
'public'=105 'let'=105
'interface'=106 'private'=106
'package'=107 'public'=107
'protected'=108 'interface'=108
'static'=109 'package'=109
'yield'=110 '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