From bfd00e3b08f6db4ac3e256d0ab90b2a7870c41a7 Mon Sep 17 00:00:00 2001 From: Robert Valentyne Date: Sun, 17 Dec 2017 21:12:25 +0000 Subject: [PATCH] Initial commit --- .gitignore | 22 +------ examples-java.iml | 12 ++++ src/io/github/rob__/Domain.java | 83 +++++++++++++++++++++++++++ src/io/github/rob__/HelloWorld.java | 12 ++++ src/io/github/rob__/LockContract.java | 18 ++++++ 5 files changed, 126 insertions(+), 21 deletions(-) create mode 100644 examples-java.iml create mode 100644 src/io/github/rob__/Domain.java create mode 100644 src/io/github/rob__/HelloWorld.java create mode 100644 src/io/github/rob__/LockContract.java diff --git a/.gitignore b/.gitignore index 6143e53..e3ed2b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,2 @@ -# Compiled class file *.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* +.idea \ No newline at end of file diff --git a/examples-java.iml b/examples-java.iml new file mode 100644 index 0000000..0d9143e --- /dev/null +++ b/examples-java.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/io/github/rob__/Domain.java b/src/io/github/rob__/Domain.java new file mode 100644 index 0000000..3d9c6ca --- /dev/null +++ b/src/io/github/rob__/Domain.java @@ -0,0 +1,83 @@ +package io.github.rob__; + +import org.neo.smartcontract.framework.SmartContract; +import org.neo.smartcontract.framework.services.neo.Blockchain; +import org.neo.smartcontract.framework.services.neo.Runtime; +import org.neo.smartcontract.framework.services.neo.Storage; + +public class Domain extends SmartContract { + + public static Object Main(String operation, Object[] args) { + String domain = (String) args[0]; + + if (operation == "query") { + return Query(domain); + } + + if (operation == "register") { + return Register(domain, (byte[]) args[1]); + } + + if (operation == "transfer") { + return Transfer(domain, (byte[]) args[1]); + } + + if (operation == "delete") { + return Delete(domain); + } + + return false; + } + + private static byte[] Query(String domain) { + return Storage.get(Storage.currentContext(), domain); + } + + private static boolean Register(String domain, byte[] owner) { + if (!Runtime.checkWitness(owner)) { + return false; + } + + byte[] value = Storage.get(Storage.currentContext(), domain); + if (value != null) { + return false; + } + + Storage.put(Storage.currentContext(), domain, owner); + return true; + } + + private static boolean Transfer(String domain, byte[] to) { + if (!Runtime.checkWitness(to)) { + return false; + } + + byte[] from = Storage.get(Storage.currentContext(), domain); + + if (from == null) { + return false; + } + + if (!Runtime.checkWitness(from)) { + return false; + } + + Storage.put(Storage.currentContext(), domain, to); + return true; + } + + private static boolean Delete(String domain) { + byte[] owner = Storage.get(Storage.currentContext(), domain); + + if (owner == null) { + return false; + } + + if (!Runtime.checkWitness(owner)) { + return false; + } + + Storage.delete(Storage.currentContext(), domain); + return true; + } +} diff --git a/src/io/github/rob__/HelloWorld.java b/src/io/github/rob__/HelloWorld.java new file mode 100644 index 0000000..e20bfb5 --- /dev/null +++ b/src/io/github/rob__/HelloWorld.java @@ -0,0 +1,12 @@ +package io.github.rob__; + +import org.neo.smartcontract.framework.SmartContract; +import org.neo.smartcontract.framework.services.neo.Storage; + +public class HelloWorld extends SmartContract { + + public static byte[] Main(String[] args) { + Storage.put(Storage.currentContext(), "Greeting", "Hello World!"); + return Storage.get(Storage.currentContext(), "Greeting"); + } +} diff --git a/src/io/github/rob__/LockContract.java b/src/io/github/rob__/LockContract.java new file mode 100644 index 0000000..aa8eefa --- /dev/null +++ b/src/io/github/rob__/LockContract.java @@ -0,0 +1,18 @@ +package io.github.rob__; + +import org.neo.smartcontract.framework.SmartContract; +import org.neo.smartcontract.framework.services.neo.Blockchain; +import org.neo.smartcontract.framework.services.neo.Header; + +public class LockContract extends SmartContract { + + public static boolean Main(int timestamp, byte[] publicKey, byte[] signature) { + Header header = Blockchain.getHeader(Blockchain.height()); + + if (header.timestamp() < timestamp) { + return false; + } + + return verifySignature(signature, publicKey); + } +}