forked from icon-project/xcall-multi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7dae72
commit 5f070b0
Showing
28 changed files
with
2,412 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# https://help.github.com/articles/dealing-with-line-endings/ | ||
# | ||
# Linux start script should use lf | ||
/gradlew text eol=lf | ||
|
||
# These are Windows script files and should use crlf | ||
*.bat text eol=crlf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Ignore Gradle project-specific cache directory | ||
.gradle | ||
|
||
# Ignore Gradle build output directory | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
dependencies { | ||
compileOnly 'foundation.icon:javaee-api:0.9.6' | ||
implementation 'com.github.sink772:javaee-tokens:0.6.4' | ||
testImplementation 'foundation.icon:javaee-unittest:0.10.0' | ||
testImplementation 'org.mockito:mockito-core:4.8.0' | ||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0' | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0' | ||
} | ||
|
||
optimizedJar { | ||
mainClassName = 'network.icon.intent.Intent' | ||
archivesBaseName = "intent" + 1 + ".jar" | ||
from { | ||
configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it) } | ||
} | ||
|
||
} | ||
|
||
deployJar { | ||
endpoints { | ||
local { | ||
uri = 'http://localhost:9080/api/v3' | ||
nid = 0x3 | ||
} | ||
} | ||
|
||
keystore = rootProject.hasProperty('keystoreName') ? "$keystoreName" : '' | ||
password = rootProject.hasProperty('keystorePass') ? "$keystorePass" : '' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
|
||
|
63 changes: 63 additions & 0 deletions
63
...vascore/Intent_Contracts/app/src/main/java/network/icon/intent/GeneralizedConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package network.icon.intent; | ||
|
||
import java.math.BigInteger; | ||
|
||
import network.icon.intent.constants.Constant; | ||
import score.Address; | ||
import score.BranchDB; | ||
import score.Context; | ||
import score.DictDB; | ||
import score.VarDB; | ||
import score.annotation.EventLog; | ||
import score.annotation.External; | ||
|
||
public class GeneralizedConnection { | ||
private final BranchDB<String, DictDB<BigInteger, Boolean>> receipts = Context.newBranchDB(Constant.RECEIPTS, | ||
Boolean.class); | ||
protected final VarDB<Address> relayAddress = Context.newVarDB(Constant.RELAY_ADDRESS, Address.class); | ||
private final VarDB<BigInteger> connSn = Context.newVarDB(Constant.CONN_SN, BigInteger.class); | ||
|
||
@EventLog(indexed = 3) | ||
public void Message(String targetNetwork, BigInteger sn, byte[] _msg) { | ||
} | ||
|
||
protected void _sendMessage( | ||
String to, | ||
byte[] _msg) { | ||
connSn.set(connSn.getOrDefault(BigInteger.ZERO).add(BigInteger.ONE)); | ||
Message(to, connSn.get(), _msg); | ||
} | ||
|
||
protected void _recvMessage(String srcNetwork, BigInteger _connSn) { | ||
onlyRelay(); | ||
Context.require(receipts.at(srcNetwork).getOrDefault(_connSn, false).equals(false), "Duplicate Message"); | ||
receipts.at(srcNetwork).set(_connSn, true); | ||
} | ||
|
||
@External | ||
public void setAdmin(Address _address) { | ||
onlyRelay(); | ||
relayAddress.set(_address); | ||
} | ||
|
||
@External | ||
public boolean getReceipt( | ||
String srcNetwork, | ||
BigInteger _connSn) { | ||
return receipts.at(srcNetwork).getOrDefault(_connSn, false); | ||
} | ||
|
||
@External | ||
public Address admin() { | ||
return relayAddress.get(); | ||
} | ||
|
||
public BigInteger getConnSn() { | ||
return connSn.getOrDefault(BigInteger.ZERO); | ||
} | ||
|
||
void onlyRelay() { | ||
Context.require(Context.getCaller().equals(relayAddress.get()), "OnlyRelayer"); | ||
} | ||
|
||
} |
Oops, something went wrong.