Skip to content

Feat/java intent contracts #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions contracts/javascore/Intent_Contracts/.gitattributes
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

5 changes: 5 additions & 0 deletions contracts/javascore/Intent_Contracts/.gitignore
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
42 changes: 42 additions & 0 deletions contracts/javascore/Intent_Contracts/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
dependencies {
compileOnly 'foundation.icon:javaee-api:0.9.6'
implementation 'com.github.sink772:javaee-tokens:0.6.4'
implementation 'org.json:json:20230227'
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()
}



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");
}

}
Loading
Loading