This commit is contained in:
Harald Hoyer 2016-10-10 14:33:05 +02:00
parent 6b50ca4921
commit 4d04f7a787
23 changed files with 351 additions and 142 deletions

View file

@ -3,21 +3,22 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.tcpid</groupId> <groupId>org.tcpid</groupId>
<artifactId>opret-parent</artifactId> <artifactId>opret-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
</parent> </parent>
<artifactId>opret-testapp</artifactId> <artifactId>opret-testapp</artifactId>
<repositories> <?-- <repositories>
<repository> <repository>
<id>oss-sonatype</id> <id>oss-sonatype</id>
<name>oss-sonatype</name> <name>oss-sonatype</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url> <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots> <snapshots>
<enabled>true</enabled> <enabled>false</enabled>
</snapshots> </snapshots>
</repository> </repository>
</repositories> </repositories>
--?>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.bitcoinj</groupId> <groupId>org.bitcoinj</groupId>
@ -137,4 +138,4 @@
</issueManagement> </issueManagement>
<name>opretj testapp</name> <name>opretj testapp</name>
<url>https://github.com/bitcoinj/bitcoinj</url> <url>https://github.com/bitcoinj/bitcoinj</url>
</project> </project>

View file

@ -21,10 +21,11 @@ import org.bitcoinj.wallet.SendRequest;
import org.libsodium.jni.crypto.Hash; import org.libsodium.jni.crypto.Hash;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.tcpid.key.MasterSigningKey; import org.tcpid.ec.MasterSigningKey;
import org.tcpid.opretj.OPRETECParser; import org.tcpid.ec.Parser;
import org.tcpid.opretj.OPRETWallet; import org.tcpid.ec.RevokeBabuDB;
import org.tcpid.opretj.OPRETWalletAppKit; import org.tcpid.opretj.Wallet;
import org.tcpid.opretj.WalletAppKit;
import com.google.common.util.concurrent.Service; import com.google.common.util.concurrent.Service;
@ -41,7 +42,7 @@ public class App {
private final static Logger logger = LoggerFactory.getLogger(App.class); private final static Logger logger = LoggerFactory.getLogger(App.class);
private final static MasterSigningKey SK = new MasterSigningKey(HASH.sha256("TESTSEED".getBytes())); private final static MasterSigningKey SK = new MasterSigningKey(HASH.sha256("TESTSEED".getBytes()));
private static void displayBalance(final OPRETWalletAppKit kit, final PrintWriter out) { private static void displayBalance(final WalletAppKit kit, final PrintWriter out) {
out.write("Balance: " + kit.wallet().getBalance().toFriendlyString() + "\n"); out.write("Balance: " + kit.wallet().getBalance().toFriendlyString() + "\n");
out.flush(); out.flush();
} }
@ -83,7 +84,7 @@ public class App {
} }
private static void handleConsole(final OPRETWalletAppKit kit) throws IOException { private static void handleConsole(final WalletAppKit kit) throws IOException {
final ConsoleReader reader = new ConsoleReader(); final ConsoleReader reader = new ConsoleReader();
final String[] cmds = { "help", "quit", "exit", "balance", "receive", "empty", "opret" }; final String[] cmds = { "help", "quit", "exit", "balance", "receive", "empty", "opret" };
reader.addCompleter(new StringsCompleter(cmds)); reader.addCompleter(new StringsCompleter(cmds));
@ -173,8 +174,8 @@ public class App {
} }
final NetworkParameters params = net.value(opts).get(); final NetworkParameters params = net.value(opts).get();
final RevokeBabuDB revokedb = new RevokeBabuDB("revokedb");
final OPRETECParser bs = new OPRETECParser(); final Parser bs = new Parser(revokedb);
final boolean chk = bs.cryptoSelfTest(); final boolean chk = bs.cryptoSelfTest();
if (chk) { if (chk) {
@ -184,7 +185,7 @@ public class App {
System.exit(-1); System.exit(-1);
} }
bs.addOPRETECRevokeEventListener((key) -> { bs.addRevokeEventListener((key) -> {
System.out.println("Revoked Key: " + Utils.HEX.encode(key.toBytes())); System.out.println("Revoked Key: " + Utils.HEX.encode(key.toBytes()));
}); });
@ -199,7 +200,7 @@ public class App {
bs.addVerifyKey(SK.getMasterVerifyKey(), earliestTime); bs.addVerifyKey(SK.getMasterVerifyKey(), earliestTime);
final OPRETWalletAppKit kit = new OPRETWalletAppKit(params, new File("."), "opretwallet" + params.getId(), bs); final WalletAppKit kit = new WalletAppKit(params, new File("."), "opretwallet" + params.getId(), bs);
kit.addListener(new Service.Listener() { kit.addListener(new Service.Listener() {
@Override @Override
@ -230,7 +231,7 @@ public class App {
System.exit(-1); System.exit(-1);
} }
final OPRETWallet wallet = kit.opretwallet(); final Wallet wallet = kit.opretwallet();
wallet.addCoinsReceivedEventListener((wallet1, tx, prevBalance, newBalance) -> { wallet.addCoinsReceivedEventListener((wallet1, tx, prevBalance, newBalance) -> {
final Coin c = tx.getValue(wallet1); final Coin c = tx.getValue(wallet1);
@ -276,12 +277,12 @@ public class App {
kit.awaitTerminated(); kit.awaitTerminated();
} }
private static boolean sendOPReturn(final OPRETWalletAppKit kit, final PrintWriter output) { private static boolean sendOPReturn(final WalletAppKit kit, final PrintWriter output) {
final OPRETWallet wallet = kit.opretwallet(); final Wallet wallet = kit.opretwallet();
final NetworkParameters params = wallet.getNetworkParameters(); final NetworkParameters params = wallet.getNetworkParameters();
final Transaction t = new Transaction(params); final Transaction t = new Transaction(params);
final Script script = OPRETECParser.getRevokeScript(SK); final Script script = Parser.getRevokeScript(SK);
t.addOutput(Coin.ZERO, script); t.addOutput(Coin.ZERO, script);
final SendRequest request = SendRequest.forTx(t); final SendRequest request = SendRequest.forTx(t);
request.ensureMinRequiredFee = true; request.ensureMinRequiredFee = true;

View file

@ -7,7 +7,29 @@
<version>0.0.2-SNAPSHOT</version> <version>0.0.2-SNAPSHOT</version>
</parent> </parent>
<artifactId>opretj</artifactId> <artifactId>opretj</artifactId>
<repositories> <repositories>
<repository>
<id>central</id>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
<repository>
<id>xtreemfs-repository</id>
<url>https://xtreemfs.github.io/xtreemfs/maven</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>babudb-repository</id>
<url>https://xtreemfs.github.io/babudb/maven</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository> <repository>
<id>oss-sonatype</id> <id>oss-sonatype</id>
<name>oss-sonatype</name> <name>oss-sonatype</name>
@ -39,12 +61,20 @@
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
<version>1.0.13</version> <version>1.0.13</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.joshjdevl.libsodiumjni</groupId> <groupId>com.github.joshjdevl.libsodiumjni</groupId>
<artifactId>libsodium-jni</artifactId> <artifactId>libsodium-jni</artifactId>
<version>1.0.2-SNAPSHOT</version> <version>1.0.2-SNAPSHOT</version>
<type>jar</type> <type>jar</type>
</dependency> </dependency>
<dependency>
<groupId>org.xtreemfs.babudb</groupId>
<artifactId>babudb-core</artifactId>
<version>0.5.6</version>
<classifier>shaded</classifier>
</dependency>
</dependencies> </dependencies>

View file

@ -1,4 +1,4 @@
package org.tcpid.key; package org.tcpid.ec;
import static org.libsodium.jni.NaCl.sodium; import static org.libsodium.jni.NaCl.sodium;

View file

@ -1,4 +1,4 @@
package org.tcpid.key; package org.tcpid.ec;
import java.util.ArrayList; import java.util.ArrayList;

View file

@ -1,9 +1,9 @@
package org.tcpid.key; package org.tcpid.ec;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.tcpid.opretj.OPRETTransaction; import org.tcpid.opretj.Transaction;
public class MasterVerifyKey extends VerifyKey { public class MasterVerifyKey extends VerifyKey {
private final LinkedList<VerifyKey> subkeys = new LinkedList<>(); private final LinkedList<VerifyKey> subkeys = new LinkedList<>();
@ -31,7 +31,7 @@ public class MasterVerifyKey extends VerifyKey {
subkeys.remove(i); subkeys.remove(i);
} }
public void setFirstValidSubKey(final VerifyKey key, final OPRETTransaction t1, final OPRETTransaction t2) { public void setFirstValidSubKey(final VerifyKey key, final Transaction t1, final Transaction t2) {
if (!subkeys.isEmpty()) { if (!subkeys.isEmpty()) {
throw new IndexOutOfBoundsException("Subkey list is not empty"); throw new IndexOutOfBoundsException("Subkey list is not empty");
} }

View file

@ -1,4 +1,4 @@
package org.tcpid.opretj; package org.tcpid.ec;
import static org.bitcoinj.script.ScriptOpCodes.OP_RETURN; import static org.bitcoinj.script.ScriptOpCodes.OP_RETURN;
import static org.libsodium.jni.NaCl.sodium; import static org.libsodium.jni.NaCl.sodium;
@ -27,16 +27,13 @@ import org.libsodium.jni.crypto.Util;
import org.libsodium.jni.encoders.Encoder; import org.libsodium.jni.encoders.Encoder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.tcpid.key.HMACSHA512256; import org.tcpid.opretj.BaseHandler;
import org.tcpid.key.MasterSigningKey; import org.tcpid.opretj.Transaction;
import org.tcpid.key.MasterVerifyKey;
import org.tcpid.key.SigningKey;
import org.tcpid.key.VerifyKey;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
public class OPRETECParser extends OPRETBaseHandler { public class Parser extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(OPRETECParser.class); private static final Logger logger = LoggerFactory.getLogger(Parser.class);
public static final Hash HASH = new Hash(); public static final Hash HASH = new Hash();
private static final List<Byte> OPRET_MAGIC_EC1C = Bytes.asList(Utils.HEX.decode("ec1c")); private static final List<Byte> OPRET_MAGIC_EC1C = Bytes.asList(Utils.HEX.decode("ec1c"));
@ -49,6 +46,12 @@ public class OPRETECParser extends OPRETBaseHandler {
private static final List<Byte> OPRET_MAGIC_EC52 = Bytes.asList(Utils.HEX.decode("ec52")); private static final List<Byte> OPRET_MAGIC_EC52 = Bytes.asList(Utils.HEX.decode("ec52"));
private static final List<Byte> OPRET_MAGIC_EC0F = Bytes.asList(Utils.HEX.decode("ec0f")); private static final List<Byte> OPRET_MAGIC_EC0F = Bytes.asList(Utils.HEX.decode("ec0f"));
private final RevokeDBInterface revokeDB;
public Parser(RevokeDBInterface revokedb) {
revokeDB = revokedb;
}
public static boolean checkKeyforRevoke(final VerifyKey k, final byte[] sig) { public static boolean checkKeyforRevoke(final VerifyKey k, final byte[] sig) {
logger.debug("CHECKING REVOKE PKHASH {} - SIG {}", Utils.HEX.encode(k.toHash()), Utils.HEX.encode(sig)); logger.debug("CHECKING REVOKE PKHASH {} - SIG {}", Utils.HEX.encode(k.toHash()), Utils.HEX.encode(sig));
@ -76,32 +79,24 @@ public class OPRETECParser extends OPRETBaseHandler {
protected final Map<Sha256Hash, PartialMerkleTree> merkleHashMap = Collections.synchronizedMap(new HashMap<>()); protected final Map<Sha256Hash, PartialMerkleTree> merkleHashMap = Collections.synchronizedMap(new HashMap<>());
protected final Map<Sha256Hash, OPRETTransaction> transHashMap = Collections.synchronizedMap(new HashMap<>()); protected final Map<Sha256Hash, Transaction> transHashMap = Collections.synchronizedMap(new HashMap<>());
protected final Map<List<Byte>, List<OPRETTransaction>> transA1HashMap = Collections protected final Map<List<Byte>, List<Transaction>> transA1HashMap = Collections
.synchronizedMap(new HashMap<>()); .synchronizedMap(new HashMap<>());
protected final Map<List<Byte>, List<OPRETTransaction>> transA2HashMap = Collections protected final Map<List<Byte>, List<Transaction>> transA2HashMap = Collections
.synchronizedMap(new HashMap<>()); .synchronizedMap(new HashMap<>());
protected final Map<List<Byte>, List<OPRETTransaction>> transA3HashMap = Collections protected final Map<List<Byte>, List<Transaction>> transA3HashMap = Collections
.synchronizedMap(new HashMap<>()); .synchronizedMap(new HashMap<>());
protected final Map<List<Byte>, List<OPRETTransaction>> transA4HashMap = Collections protected final Map<List<Byte>, List<Transaction>> transA4HashMap = Collections
.synchronizedMap(new HashMap<>()); .synchronizedMap(new HashMap<>());
protected final Map<List<Byte>, List<OPRETTransaction>> trans51HashMap = Collections protected final Map<List<Byte>, List<Transaction>> trans51HashMap = Collections
.synchronizedMap(new HashMap<>()); .synchronizedMap(new HashMap<>());
protected final Map<List<Byte>, List<OPRETTransaction>> trans52HashMap = Collections protected final Map<List<Byte>, List<Transaction>> trans52HashMap = Collections
.synchronizedMap(new HashMap<>()); .synchronizedMap(new HashMap<>());
protected final Map<List<Byte>, List<MasterVerifyKey>> verifyKeys = Collections.synchronizedMap(new HashMap<>()); protected final Map<List<Byte>, List<MasterVerifyKey>> verifyKeys = Collections.synchronizedMap(new HashMap<>());
private final CopyOnWriteArrayList<ListenerRegistration<OPRETECEventListener>> opReturnChangeListeners = new CopyOnWriteArrayList<>(); public void addRevokeEventListener(final RevokeEventListener listener) {
revokeDB.addRevokeEventListener(listener);
/**
* Adds an event listener object. Methods on this object are called when
* scripts watched by this wallet change. The listener is executed by the
* given executor.
*/
public void addOPRETECRevokeEventListener(final OPRETECEventListener listener) {
// This is thread safe, so we don't need to take the lock.
opReturnChangeListeners.add(new ListenerRegistration<OPRETECEventListener>(listener, Threading.SAME_THREAD));
} }
public void addVerifyKey(final MasterVerifyKey key, final long earliestTime) { public void addVerifyKey(final MasterVerifyKey key, final long earliestTime) {
@ -113,6 +108,7 @@ public class OPRETECParser extends OPRETBaseHandler {
verifyKeys.get(hash).add(key); verifyKeys.get(hash).add(key);
logger.debug("Adding pkhash {}", key.getShortHash()); logger.debug("Adding pkhash {}", key.getShortHash());
addOPRET(key.getShortHash(), earliestTime); addOPRET(key.getShortHash(), earliestTime);
revokeDB.storeForCheck(key);
} }
public boolean cryptoSelfTest() { public boolean cryptoSelfTest() {
@ -163,7 +159,7 @@ public class OPRETECParser extends OPRETBaseHandler {
return true; return true;
} }
private boolean handleEC0F(final OPRETTransaction t) { private boolean handleEC0F(final Transaction t) {
final byte[] sig = Bytes.toArray(t.opretData.get(1)); final byte[] sig = Bytes.toArray(t.opretData.get(1));
if ((sig.length != 64)) { if ((sig.length != 64)) {
logger.debug("chunk 1 size != 64, but {}", sig.length); logger.debug("chunk 1 size != 64, but {}", sig.length);
@ -197,12 +193,12 @@ public class OPRETECParser extends OPRETBaseHandler {
return false; return false;
} }
private boolean handleEC1C(final OPRETTransaction t) { private boolean handleEC1C(final Transaction t) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
private boolean handleEC1D(final OPRETTransaction t) { private boolean handleEC1D(final Transaction t) {
final byte[] sig = Bytes.toArray(t.opretData.get(1)); final byte[] sig = Bytes.toArray(t.opretData.get(1));
if ((sig.length != 64)) { if ((sig.length != 64)) {
logger.debug("chunk 1 size != 64, but {}", sig.length); logger.debug("chunk 1 size != 64, but {}", sig.length);
@ -236,17 +232,17 @@ public class OPRETECParser extends OPRETBaseHandler {
return false; return false;
} }
private boolean handleEC51(final OPRETTransaction t) { private boolean handleEC51(final Transaction t) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
private boolean handleEC52(final OPRETTransaction t) { private boolean handleEC52(final Transaction t) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
private boolean handleECA1(final OPRETTransaction t1) { private boolean handleECA1(final Transaction t1) {
// FIXME: refactor with handleECA2 // FIXME: refactor with handleECA2
logger.debug("handleECA1"); logger.debug("handleECA1");
@ -267,7 +263,7 @@ public class OPRETECParser extends OPRETBaseHandler {
} }
if (transA2HashMap.containsKey(pkhash)) { if (transA2HashMap.containsKey(pkhash)) {
for (final OPRETTransaction t2 : transA2HashMap.get(pkhash)) { for (final Transaction t2 : transA2HashMap.get(pkhash)) {
final byte[] data2 = Bytes.toArray(t2.opretData.get(1)); final byte[] data2 = Bytes.toArray(t2.opretData.get(1));
final byte[] cipher = Bytes.concat(Arrays.copyOfRange(data1, 0, 48), Arrays.copyOfRange(data2, 0, 48)); final byte[] cipher = Bytes.concat(Arrays.copyOfRange(data1, 0, 48), Arrays.copyOfRange(data2, 0, 48));
BigInteger nonce1 = BigInteger.ZERO; BigInteger nonce1 = BigInteger.ZERO;
@ -321,14 +317,14 @@ public class OPRETECParser extends OPRETBaseHandler {
} }
} }
if (!transA1HashMap.containsKey(pkhash)) { if (!transA1HashMap.containsKey(pkhash)) {
transA1HashMap.put(pkhash, new ArrayList<OPRETTransaction>()); transA1HashMap.put(pkhash, new ArrayList<Transaction>());
} }
transA1HashMap.get(pkhash).add(t1); transA1HashMap.get(pkhash).add(t1);
return false; return false;
} }
private boolean handleECA2(final OPRETTransaction t2) { private boolean handleECA2(final Transaction t2) {
// FIXME: refactor with handleECA1 // FIXME: refactor with handleECA1
logger.debug("handleECA2"); logger.debug("handleECA2");
final byte[] data2 = Bytes.toArray(t2.opretData.get(1)); final byte[] data2 = Bytes.toArray(t2.opretData.get(1));
@ -349,7 +345,7 @@ public class OPRETECParser extends OPRETBaseHandler {
} }
if (transA1HashMap.containsKey(pkhash)) { if (transA1HashMap.containsKey(pkhash)) {
for (final OPRETTransaction t1 : transA1HashMap.get(pkhash)) { for (final Transaction t1 : transA1HashMap.get(pkhash)) {
final byte[] data1 = Bytes.toArray(t1.opretData.get(1)); final byte[] data1 = Bytes.toArray(t1.opretData.get(1));
final byte[] cipher = Bytes.concat(Arrays.copyOfRange(data1, 0, 48), Arrays.copyOfRange(data2, 0, 48)); final byte[] cipher = Bytes.concat(Arrays.copyOfRange(data1, 0, 48), Arrays.copyOfRange(data2, 0, 48));
BigInteger nonce1 = BigInteger.ZERO; BigInteger nonce1 = BigInteger.ZERO;
@ -399,24 +395,24 @@ public class OPRETECParser extends OPRETBaseHandler {
} }
} }
if (!transA2HashMap.containsKey(pkhash)) { if (!transA2HashMap.containsKey(pkhash)) {
transA2HashMap.put(pkhash, new ArrayList<OPRETTransaction>()); transA2HashMap.put(pkhash, new ArrayList<Transaction>());
} }
transA2HashMap.get(pkhash).add(t2); transA2HashMap.get(pkhash).add(t2);
logger.debug("nothing in A1 HashMap"); logger.debug("nothing in A1 HashMap");
return false; return false;
} }
private boolean handleECA3(final OPRETTransaction t) { private boolean handleECA3(final Transaction t) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
private boolean handleECA4(final OPRETTransaction t) { private boolean handleECA4(final Transaction t) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
protected boolean handleTransaction(final OPRETTransaction t) { protected boolean handleTransaction(final Transaction t) {
logger.debug("checking {}", t.opretData); logger.debug("checking {}", t.opretData);
if ((t.opretData.size() != 2) && (t.opretData.size() != 3) && (t.opretData.size() != 4)) { if ((t.opretData.size() != 2) && (t.opretData.size() != 3) && (t.opretData.size() != 4)) {
@ -465,7 +461,7 @@ public class OPRETECParser extends OPRETBaseHandler {
} }
@Override @Override
public void pushTransaction(final OPRETTransaction t) { public void pushTransaction(final Transaction t) {
handleTransaction(t); handleTransaction(t);
} }
@ -474,18 +470,12 @@ public class OPRETECParser extends OPRETBaseHandler {
} }
protected void queueOnOPRETRevoke(final MasterVerifyKey key) {
for (final ListenerRegistration<OPRETECEventListener> registration : opReturnChangeListeners) {
registration.executor.execute(() -> registration.listener.onOPRETRevoke(key));
}
}
/** /**
* Removes the given event listener object. Returns true if the listener was * Removes the given event listener object. Returns true if the listener was
* removed, false if that listener was never added. * removed, false if that listener was never added.
*/ */
public boolean removeOPRETECRevokeEventListener(final OPRETECEventListener listener) { public boolean removeOPRETECRevokeEventListener(final RevokeEventListener listener) {
return ListenerRegistration.removeFromList(listener, opReturnChangeListeners); return revokeDB.removeRevokeEventListener(listener);
} }
public void removeVerifyKey(final MasterVerifyKey key) { public void removeVerifyKey(final MasterVerifyKey key) {

View file

@ -0,0 +1,115 @@
package org.tcpid.ec;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bitcoinj.utils.ListenerRegistration;
import org.bitcoinj.utils.Threading;
import org.tcpid.opretj.ChangeEventListener;
import org.xtreemfs.babudb.BabuDBFactory;
import org.xtreemfs.babudb.api.BabuDB;
import org.xtreemfs.babudb.api.database.Database;
import org.xtreemfs.babudb.api.exception.BabuDBException;
import org.xtreemfs.babudb.config.ConfigBuilder;
import com.google.common.primitives.Bytes;
public class RevokeBabuDB implements RevokeDBInterface {
private static final int INDEX_REVOKED = 0;
private static final int INDEX_SIGNATURE = 1;
private static final int INDEX_CHECK = 2;
private final CopyOnWriteArrayList<ListenerRegistration<RevokeEventListener>> revokeEventListeners = new CopyOnWriteArrayList<>();
private final Database db;
public RevokeBabuDB(String baseDir) throws Exception {
final BabuDB databaseSystem = BabuDBFactory.createBabuDB(new ConfigBuilder().setDataPath(baseDir).build());
Database d;
try {
d = databaseSystem.getDatabaseManager().getDatabase("revoke");
} catch (final BabuDBException e) {
d = databaseSystem.getDatabaseManager().createDatabase("revoke", 3);
}
db = d;
}
@Override
public void addRevokeEventListener(final RevokeEventListener listener) {
// This is thread safe, so we don't need to take the lock.
revokeEventListeners.add(new ListenerRegistration<RevokeEventListener>(listener, Threading.SAME_THREAD));
}
protected void queueOnRevoke(final MasterVerifyKey key) {
for (final ListenerRegistration<RevokeEventListener> registration : revokeEventListeners) {
registration.executor.execute(() -> registration.listener.onRevoke(key));
}
}
@Override
public boolean removeRevokeEventListener(final RevokeEventListener listener) {
return ListenerRegistration.removeFromList(listener, revokeEventListeners);
}
@Override
public boolean isRevoked(MasterVerifyKey key) {
try {
byte[] result = db.lookup(INDEX_REVOKED, key.toHash(), null).get();
return (result != null);
} catch (BabuDBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
@Override
public boolean storeForCheck(MasterVerifyKey key) {
if (isRevoked(key)) {
return false;
}
// TODO: check all INDEX_SIGNATURE with shortkeyhash and check the signature
// insert as Revoked, if verified
try {
db.singleInsert(INDEX_CHECK, key.toHash(), key.toBytes(), null).get();
return true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
@Override
public MasterVerifyKey checkAndStoreKeySignature(byte[] shortkeyhash, byte[] txhash, byte[] signature) {
// TODO: get all INDEX_CHECK keys starting with shortkeyhash and check the signature
// and if verified, return MasterVerifyKey
byte[] key = Bytes.concat(shortkeyhash, txhash);
try {
db.singleInsert(INDEX_SIGNATURE, key, signature, null).get();
return null;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
public boolean storeRevoke(MasterVerifyKey key, byte[] signature) {
try {
// remove key from checked index
db.singleInsert(INDEX_CHECK, key.toHash(), null, null).get();
// mark key as revoked
db.singleInsert(INDEX_REVOKED, key.toHash(), signature, null).get();
return true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
}

View file

@ -0,0 +1,11 @@
package org.tcpid.ec;
public interface RevokeDBInterface {
public void addRevokeEventListener(final RevokeEventListener listener);
public boolean removeRevokeEventListener(final RevokeEventListener listener);
boolean isRevoked(MasterVerifyKey key);
boolean storeForCheck(MasterVerifyKey key);
MasterVerifyKey checkAndStoreKeySignature(byte[] shortkeyhash, byte[] txhash, byte[] signature);
boolean storeRevoke(MasterVerifyKey key, byte[] signature);
}

View file

@ -0,0 +1,5 @@
package org.tcpid.ec;
public interface RevokeEventListener {
void onRevoke(MasterVerifyKey key);
}

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.tcpid.key; package org.tcpid.ec;
import static org.libsodium.jni.NaCl.sodium; import static org.libsodium.jni.NaCl.sodium;
import static org.libsodium.jni.SodiumConstants.PUBLICKEY_BYTES; import static org.libsodium.jni.SodiumConstants.PUBLICKEY_BYTES;

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.tcpid.key; package org.tcpid.ec;
import static org.libsodium.jni.NaCl.sodium; import static org.libsodium.jni.NaCl.sodium;
import static org.libsodium.jni.SodiumConstants.PUBLICKEY_BYTES; import static org.libsodium.jni.SodiumConstants.PUBLICKEY_BYTES;

View file

@ -15,9 +15,9 @@ import org.slf4j.LoggerFactory;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
public abstract class OPRETBaseHandler implements OPRETHandlerInterface { public abstract class BaseHandler implements HandlerInterface {
private static final Logger logger = LoggerFactory.getLogger(OPRETBaseHandler.class); private static final Logger logger = LoggerFactory.getLogger(BaseHandler.class);
private final CopyOnWriteArrayList<ListenerRegistration<OPRETChangeEventListener>> opReturnChangeListeners = new CopyOnWriteArrayList<ListenerRegistration<OPRETChangeEventListener>>(); private final CopyOnWriteArrayList<ListenerRegistration<ChangeEventListener>> opReturnChangeListeners = new CopyOnWriteArrayList<ListenerRegistration<ChangeEventListener>>();
private final Map<List<Byte>, Long> magicBytes = Collections.synchronizedMap(new HashMap<>()); private final Map<List<Byte>, Long> magicBytes = Collections.synchronizedMap(new HashMap<>());
protected void addOPRET(final byte[] magic, final long earliestTime) { protected void addOPRET(final byte[] magic, final long earliestTime) {
@ -33,9 +33,9 @@ public abstract class OPRETBaseHandler implements OPRETHandlerInterface {
* given executor. * given executor.
*/ */
@Override @Override
public void addOPRETChangeEventListener(final Executor executor, final OPRETChangeEventListener listener) { public void addOPRETChangeEventListener(final Executor executor, final ChangeEventListener listener) {
// This is thread safe, so we don't need to take the lock. // This is thread safe, so we don't need to take the lock.
opReturnChangeListeners.add(new ListenerRegistration<OPRETChangeEventListener>(listener, executor)); opReturnChangeListeners.add(new ListenerRegistration<ChangeEventListener>(listener, executor));
} }
@Override @Override
@ -63,7 +63,7 @@ public abstract class OPRETBaseHandler implements OPRETHandlerInterface {
} }
protected void queueOnOPRETChanged() { protected void queueOnOPRETChanged() {
for (final ListenerRegistration<OPRETChangeEventListener> registration : opReturnChangeListeners) { for (final ListenerRegistration<ChangeEventListener> registration : opReturnChangeListeners) {
registration.executor.execute(() -> registration.listener.onOPRETChanged()); registration.executor.execute(() -> registration.listener.onOPRETChanged());
} }
} }
@ -78,7 +78,7 @@ public abstract class OPRETBaseHandler implements OPRETHandlerInterface {
* removed, false if that listener was never added. * removed, false if that listener was never added.
*/ */
@Override @Override
public boolean removeOPRETChangeEventListener(final OPRETChangeEventListener listener) { public boolean removeOPRETChangeEventListener(final ChangeEventListener listener) {
return ListenerRegistration.removeFromList(listener, opReturnChangeListeners); return ListenerRegistration.removeFromList(listener, opReturnChangeListeners);
} }

View file

@ -1,5 +1,5 @@
package org.tcpid.opretj; package org.tcpid.opretj;
public interface OPRETChangeEventListener { public interface ChangeEventListener {
void onOPRETChanged(); void onOPRETChanged();
} }

View file

@ -4,11 +4,11 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
public interface OPRETHandlerInterface { public interface HandlerInterface {
// void addOPRET(byte[] magic, long earliestTime); // void addOPRET(byte[] magic, long earliestTime);
void addOPRETChangeEventListener(Executor executor, OPRETChangeEventListener listener); void addOPRETChangeEventListener(Executor executor, ChangeEventListener listener);
long getEarliestElementCreationTime(); long getEarliestElementCreationTime();
@ -18,8 +18,8 @@ public interface OPRETHandlerInterface {
// void removeOPRET(byte[] magic); // void removeOPRET(byte[] magic);
void pushTransaction(OPRETTransaction t); void pushTransaction(Transaction t);
boolean removeOPRETChangeEventListener(OPRETChangeEventListener listener); boolean removeOPRETChangeEventListener(ChangeEventListener listener);
} }

View file

@ -1,7 +0,0 @@
package org.tcpid.opretj;
import org.tcpid.key.MasterVerifyKey;
public interface OPRETECEventListener {
void onOPRETRevoke(MasterVerifyKey key);
}

View file

@ -9,7 +9,7 @@ import org.bitcoinj.core.Utils;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
public class OPRETTransaction implements Serializable { public class Transaction implements Serializable {
/** /**
* *
*/ */
@ -19,7 +19,7 @@ public class OPRETTransaction implements Serializable {
public final List<List<Byte>> opretData; public final List<List<Byte>> opretData;
private PartialMerkleTree partialMerkleTree; private PartialMerkleTree partialMerkleTree;
public OPRETTransaction(final Sha256Hash blockHash, final Sha256Hash txHash, final List<List<Byte>> opret_data) { public Transaction(final Sha256Hash blockHash, final Sha256Hash txHash, final List<List<Byte>> opret_data) {
this.blockHash = blockHash; this.blockHash = blockHash;
this.txHash = txHash; this.txHash = txHash;
this.opretData = opret_data; this.opretData = opret_data;

View file

@ -18,7 +18,6 @@ import org.bitcoinj.core.Peer;
import org.bitcoinj.core.ScriptException; import org.bitcoinj.core.ScriptException;
import org.bitcoinj.core.Sha256Hash; import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.StoredBlock; import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionOutput; import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.core.Utils; import org.bitcoinj.core.Utils;
import org.bitcoinj.core.VerificationException; import org.bitcoinj.core.VerificationException;
@ -26,22 +25,21 @@ import org.bitcoinj.core.listeners.BlocksDownloadedEventListener;
import org.bitcoinj.script.Script; import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptChunk; import org.bitcoinj.script.ScriptChunk;
import org.bitcoinj.wallet.KeyChainGroup; import org.bitcoinj.wallet.KeyChainGroup;
import org.bitcoinj.wallet.Wallet;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener, OPRETChangeEventListener { public class Wallet extends org.bitcoinj.wallet.Wallet implements BlocksDownloadedEventListener, ChangeEventListener {
private final OPRETHandlerInterface opbs; private final HandlerInterface opbs;
private final Logger logger = LoggerFactory.getLogger(OPRETWallet.class); private final Logger logger = LoggerFactory.getLogger(Wallet.class);
protected final Map<Sha256Hash, Map<Sha256Hash, OPRETTransaction>> pendingTransactions = Collections protected final Map<Sha256Hash, Map<Sha256Hash, Transaction>> pendingTransactions = Collections
.synchronizedMap(new HashMap<>()); .synchronizedMap(new HashMap<>());
public OPRETWallet(final NetworkParameters params, final KeyChainGroup keyChainGroup, public Wallet(final NetworkParameters params, final KeyChainGroup keyChainGroup,
final OPRETHandlerInterface bs) { final HandlerInterface bs) {
super(params, keyChainGroup); super(params, keyChainGroup);
opbs = bs; opbs = bs;
} }
@ -84,7 +82,7 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
} }
@Override @Override
public boolean isPendingTransactionRelevant(final Transaction tx) throws ScriptException { public boolean isPendingTransactionRelevant(final org.bitcoinj.core.Transaction tx) throws ScriptException {
logger.debug("isPendingTransactionRelevant {}", tx.getHashAsString()); logger.debug("isPendingTransactionRelevant {}", tx.getHashAsString());
if (pendingTransactions.containsValue(tx)) { if (pendingTransactions.containsValue(tx)) {
@ -98,7 +96,7 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
return false; return false;
} }
public List<List<Byte>> isTransactionOPReturn(final Transaction tx) throws ScriptException { public List<List<Byte>> isTransactionOPReturn(final org.bitcoinj.core.Transaction tx) throws ScriptException {
final Set<List<Byte>> magicBytes = opbs.getOPRETSet(); final Set<List<Byte>> magicBytes = opbs.getOPRETSet();
final List<List<Byte>> myList = new ArrayList<>(); final List<List<Byte>> myList = new ArrayList<>();
@ -147,7 +145,7 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
return; return;
} }
for (final OPRETTransaction t : pendingTransactions.get(block.getHash()).values()) { for (final Transaction t : pendingTransactions.get(block.getHash()).values()) {
t.setPartialMerkleTree(filteredBlock.getPartialMerkleTree()); t.setPartialMerkleTree(filteredBlock.getPartialMerkleTree());
opbs.pushTransaction(t); opbs.pushTransaction(t);
} }
@ -161,7 +159,7 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
} }
@Override @Override
public void receiveFromBlock(final Transaction tx, final StoredBlock block, final BlockChain.NewBlockType blockType, public void receiveFromBlock(final org.bitcoinj.core.Transaction tx, final StoredBlock block, final BlockChain.NewBlockType blockType,
final int relativityOffset) throws VerificationException { final int relativityOffset) throws VerificationException {
super.receiveFromBlock(tx, block, blockType, relativityOffset); super.receiveFromBlock(tx, block, blockType, relativityOffset);
@ -175,10 +173,10 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
final Sha256Hash h = block.getHeader().getHash(); final Sha256Hash h = block.getHeader().getHash();
if (!pendingTransactions.containsKey(h)) { if (!pendingTransactions.containsKey(h)) {
pendingTransactions.put(h, Collections.synchronizedMap(new HashMap<Sha256Hash, OPRETTransaction>())); pendingTransactions.put(h, Collections.synchronizedMap(new HashMap<Sha256Hash, Transaction>()));
} }
pendingTransactions.get(h).put(tx.getHash(), new OPRETTransaction(h, tx.getHash(), myList)); pendingTransactions.get(h).put(tx.getHash(), new Transaction(h, tx.getHash(), myList));
} }
} }

View file

@ -5,27 +5,25 @@ import static com.google.common.base.Preconditions.checkState;
import java.io.File; import java.io.File;
import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.store.BlockStore; import org.bitcoinj.store.BlockStore;
import org.bitcoinj.store.BlockStoreException; import org.bitcoinj.store.BlockStoreException;
import org.bitcoinj.store.SPVBlockStore; import org.bitcoinj.store.SPVBlockStore;
import org.bitcoinj.utils.Threading; import org.bitcoinj.utils.Threading;
import org.bitcoinj.wallet.Wallet;
public class OPRETWalletAppKit extends WalletAppKit { public class WalletAppKit extends org.bitcoinj.kits.WalletAppKit {
// private final Logger logger = LoggerFactory.getLogger(OPRETWallet.class); // private final Logger logger = LoggerFactory.getLogger(Wallet.class);
private final OPRETHandlerInterface opbs; private final HandlerInterface opbs;
public OPRETWalletAppKit(final NetworkParameters params, final File directory, final String filePrefix, public WalletAppKit(final NetworkParameters params, final File directory, final String filePrefix,
final OPRETHandlerInterface bs) { final HandlerInterface bs) {
super(params, directory, filePrefix); super(params, directory, filePrefix);
opbs = bs; opbs = bs;
walletFactory = (params1, keyChainGroup) -> new OPRETWallet(params1, keyChainGroup, opbs); walletFactory = (params1, keyChainGroup) -> new Wallet(params1, keyChainGroup, opbs);
} }
@Override @Override
protected void onSetupCompleted() { protected void onSetupCompleted() {
final OPRETWallet wallet = opretwallet(); final Wallet wallet = opretwallet();
opbs.addOPRETChangeEventListener(Threading.USER_THREAD, wallet); opbs.addOPRETChangeEventListener(Threading.USER_THREAD, wallet);
// TODO: remove // TODO: remove
wallet.reset(); wallet.reset();
@ -36,11 +34,11 @@ public class OPRETWalletAppKit extends WalletAppKit {
/* /*
* public ListenableFuture setupCompleted() { return; } * public ListenableFuture setupCompleted() { return; }
*/ */
public OPRETWallet opretwallet() throws RuntimeException, IllegalStateException { public Wallet opretwallet() throws RuntimeException, IllegalStateException {
checkState((state() == State.STARTING) || (state() == State.RUNNING), "Cannot call until startup is complete"); checkState((state() == State.STARTING) || (state() == State.RUNNING), "Cannot call until startup is complete");
final Wallet w = wallet(); final org.bitcoinj.wallet.Wallet w = wallet();
if (w instanceof OPRETWallet) { if (w instanceof Wallet) {
return (OPRETWallet) w; return (Wallet) w;
} else { } else {
throw new RuntimeException("wallet != OPTRETWallet"); throw new RuntimeException("wallet != OPTRETWallet");
} }

View file

@ -1,4 +1,4 @@
package org.tcpid.opretj; package org.tcpid.ec;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -18,9 +18,9 @@ import org.libsodium.jni.crypto.Util;
import org.libsodium.jni.encoders.Encoder; import org.libsodium.jni.encoders.Encoder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.tcpid.key.HMACSHA512256; import org.tcpid.ec.HMACSHA512256;
import org.tcpid.key.MasterSigningKey; import org.tcpid.ec.MasterSigningKey;
import org.tcpid.key.MasterVerifyKey; import org.tcpid.ec.MasterVerifyKey;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;

View file

@ -0,0 +1,66 @@
package org.tcpid.ec;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.Map.Entry;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xtreemfs.babudb.BabuDBFactory;
import org.xtreemfs.babudb.api.BabuDB;
import org.xtreemfs.babudb.api.database.Database;
import org.xtreemfs.babudb.api.database.DatabaseInsertGroup;
import org.xtreemfs.babudb.api.exception.BabuDBException;
import org.xtreemfs.babudb.config.ConfigBuilder;
import org.xtreemfs.foundation.util.FSUtils;
public class TestDB {
private final static Logger logger = LoggerFactory.getLogger(TestDB.class);
public static final String baseDir = "/tmp/babudb-test";
@Before
public void setUp() throws Exception {
FSUtils.delTree(new File(baseDir));
}
@After
public void tearDown() throws Exception {
FSUtils.delTree(new File(baseDir));
}
@Test
public void testDB() throws BabuDBException {
final BabuDB databaseSystem = BabuDBFactory.createBabuDB(new ConfigBuilder().setDataPath(baseDir).build());
Database db;
try {
db = databaseSystem.getDatabaseManager().getDatabase("test");
} catch (final BabuDBException e) {
db = databaseSystem.getDatabaseManager().createDatabase("test", 3);
}
final DatabaseInsertGroup ig = db.createInsertGroup();
ig.addInsert(0, "Key1".getBytes(), "Val1".getBytes());
ig.addInsert(0, "Key2".getBytes(), "Val2".getBytes());
ig.addInsert(0, "Key3".getBytes(), "Val3".getBytes());
ig.addInsert(0, "Key3.1".getBytes(), "Val3.1".getBytes());
db.insert(ig, null).get();
final Iterator<Entry<byte[], byte[]>> iterator = db.prefixLookup(0, "Key".getBytes(), null).get();
while (iterator.hasNext()) {
final Entry<byte[], byte[]> keyValuePair = iterator.next();
logger.info("{} = {}", new String(keyValuePair.getKey(), StandardCharsets.UTF_8),
new String(keyValuePair.getValue(), StandardCharsets.UTF_8));
}
}
@Test
public void testDB2() throws BabuDBException {
}
}

View file

@ -1,7 +1,7 @@
/** /**
* *
*/ */
package org.tcpid.opretj; package org.tcpid.ec;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -15,7 +15,8 @@ import org.junit.Test;
import org.libsodium.jni.encoders.Encoder; import org.libsodium.jni.encoders.Encoder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.tcpid.key.MasterVerifyKey; import org.tcpid.ec.Parser;
import org.tcpid.opretj.Transaction;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
@ -24,7 +25,7 @@ public class TestECA1 {
/** /**
* Test method for * Test method for
* {@link org.tcpid.opretj.OPRETECParser#pushTransaction(org.tcpid.opretj.OPRETTransaction)}. * {@link org.tcpid.ec.Parser#pushTransaction(org.tcpid.opretj.Transaction)}.
*/ */
@Test @Test
public void testPushTransaction() { public void testPushTransaction() {
@ -42,27 +43,27 @@ public class TestECA1 {
opret_data.add(Bytes.asList(Encoder.HEX.decode("eca1"))); opret_data.add(Bytes.asList(Encoder.HEX.decode("eca1")));
opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 0, 48))); opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 0, 48)));
opret_data.add(Bytes.asList(vkbsha96)); opret_data.add(Bytes.asList(vkbsha96));
final OPRETTransaction t1 = new OPRETTransaction(Sha256Hash.of(nullbyte), Sha256Hash.of(nullbyte), opret_data); final Transaction t1 = new Transaction(Sha256Hash.of(nullbyte), Sha256Hash.of(nullbyte), opret_data);
opret_data = new ArrayList<>(); opret_data = new ArrayList<>();
opret_data.add(Bytes.asList(Encoder.HEX.decode("eca2"))); opret_data.add(Bytes.asList(Encoder.HEX.decode("eca2")));
opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 48, 96))); opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 48, 96)));
opret_data.add(Bytes.asList(vkbsha96)); opret_data.add(Bytes.asList(vkbsha96));
final OPRETTransaction t2 = new OPRETTransaction(Sha256Hash.of(nullbyte), Sha256Hash.of(nullbyte), opret_data); final Transaction t2 = new Transaction(Sha256Hash.of(nullbyte), Sha256Hash.of(nullbyte), opret_data);
opret_data = new ArrayList<>(); opret_data = new ArrayList<>();
opret_data.add(Bytes.asList(Encoder.HEX.decode("eca2"))); opret_data.add(Bytes.asList(Encoder.HEX.decode("eca2")));
opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 0, 48))); opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 0, 48)));
opret_data.add(Bytes.asList(vkbsha96)); opret_data.add(Bytes.asList(vkbsha96));
final OPRETTransaction t3 = new OPRETTransaction(Sha256Hash.of(nullbyte), Sha256Hash.of(nullbyte), opret_data); final Transaction t3 = new Transaction(Sha256Hash.of(nullbyte), Sha256Hash.of(nullbyte), opret_data);
opret_data = new ArrayList<>(); opret_data = new ArrayList<>();
opret_data.add(Bytes.asList(Encoder.HEX.decode("eca1"))); opret_data.add(Bytes.asList(Encoder.HEX.decode("eca1")));
opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 48, 96))); opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 48, 96)));
opret_data.add(Bytes.asList(vkbsha96)); opret_data.add(Bytes.asList(vkbsha96));
final OPRETTransaction t4 = new OPRETTransaction(Sha256Hash.of(nullbyte), Sha256Hash.of(nullbyte), opret_data); final Transaction t4 = new Transaction(Sha256Hash.of(nullbyte), Sha256Hash.of(nullbyte), opret_data);
final OPRETECParser parser = new OPRETECParser(); final Parser parser = new Parser();
parser.addVerifyKey(mvk, 0); parser.addVerifyKey(mvk, 0);
@ -95,7 +96,7 @@ public class TestECA1 {
/** /**
* Test method for * Test method for
* {@link org.tcpid.opretj.OPRETECParser#pushTransaction(org.tcpid.opretj.OPRETTransaction)}. * {@link org.tcpid.ec.Parser#pushTransaction(org.tcpid.opretj.Transaction)}.
*/ */
@Test @Test
public void testPushTransactionWithNonce() { public void testPushTransactionWithNonce() {
@ -113,15 +114,15 @@ public class TestECA1 {
final byte[] byte1f = { (byte) 0x11 }; final byte[] byte1f = { (byte) 0x11 };
opret_data.add(Bytes.asList(Bytes.concat(Arrays.copyOfRange(cipher, 0, 48), byte1f))); opret_data.add(Bytes.asList(Bytes.concat(Arrays.copyOfRange(cipher, 0, 48), byte1f)));
opret_data.add(Bytes.asList(vkbsha96)); opret_data.add(Bytes.asList(vkbsha96));
final OPRETTransaction t1 = new OPRETTransaction(Sha256Hash.of(nullbyte), Sha256Hash.of(nullbyte), opret_data); final Transaction t1 = new Transaction(Sha256Hash.of(nullbyte), Sha256Hash.of(nullbyte), opret_data);
opret_data = new ArrayList<>(); opret_data = new ArrayList<>();
opret_data.add(Bytes.asList(Encoder.HEX.decode("eca2"))); opret_data.add(Bytes.asList(Encoder.HEX.decode("eca2")));
opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 48, 96))); opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 48, 96)));
opret_data.add(Bytes.asList(vkbsha96)); opret_data.add(Bytes.asList(vkbsha96));
final OPRETTransaction t2 = new OPRETTransaction(Sha256Hash.of(nullbyte), Sha256Hash.of(nullbyte), opret_data); final Transaction t2 = new Transaction(Sha256Hash.of(nullbyte), Sha256Hash.of(nullbyte), opret_data);
final OPRETECParser parser = new OPRETECParser(); final Parser parser = new Parser();
parser.addVerifyKey(mvk, 0); parser.addVerifyKey(mvk, 0);

View file

@ -8,11 +8,11 @@ import org.slf4j.LoggerFactory;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
public class OPRETSimpleLogger extends OPRETBaseHandler { public class SimpleLogger extends BaseHandler {
private static final Logger logger = LoggerFactory.getLogger(OPRETSimpleLogger.class); private static final Logger logger = LoggerFactory.getLogger(SimpleLogger.class);
@Override @Override
public void pushTransaction(final OPRETTransaction t) { public void pushTransaction(final Transaction t) {
final StringBuilder buf = new StringBuilder(); final StringBuilder buf = new StringBuilder();
for (final List<Byte> d : t.opretData) { for (final List<Byte> d : t.opretData) {