Skip to content
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

Feat/java intent contracts #8

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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/.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

7 changes: 7 additions & 0 deletions contracts/javascore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ignore Gradle project-specific cache directory
.gradle
gradle.properties
.keystores

# Ignore Gradle build output directory
build
Empty file removed contracts/javascore/.gitkeep
Empty file.
36 changes: 0 additions & 36 deletions contracts/javascore/README.md

This file was deleted.

55 changes: 55 additions & 0 deletions contracts/javascore/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
dependencies {
compileOnly 'foundation.icon:javaee-api:0.9.6'
implementation 'foundation.icon:javaee-scorex:0.5.2'
implementation 'com.github.sink772:javaee-tokens:0.6.4'
implementation 'com.github.sink772:minimal-json:0.9.7'
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"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from {
configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it)
}
}
}

deployJar {
endpoints {
local {
uri = 'http://localhost:9080/api/v3'
nid = 0x3
}
mainnet {
uri = 'https://ctz.solidwallet.io/api/v3'
nid = 0x1
to = 'cx55f6ac86d82a14022c338c8c0033eeceeeab382d'
}
}

keystore = rootProject.hasProperty('keystoreName') ? "$keystoreName" : ''
password = rootProject.hasProperty('keystorePass') ? "$keystorePass" : ''
parameters {
arg("_nid", "0x1.icon")
arg("_protocolFee", "10")
arg("_feeHandler", "hx35e504e72af8b895dd5c19f8fc7aafc564403341")
arg("_relayer", "hxb3eca4ce3a2489361579a85d84d0c0475143d3b5")
}
}

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 {
protected 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);
protected final VarDB<BigInteger> connSn = Context.newVarDB(Constant.CONN_SN, BigInteger.class);

@EventLog(indexed = 2)
public void Message(String targetNetwork, BigInteger connSn, 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(readonly = true)
public boolean getReceipts(
String srcNetwork,
BigInteger _connSn) {
return receipts.at(srcNetwork).getOrDefault(_connSn, false);
}

@External(readonly = true)
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