refactor
This commit is contained in:
parent
6b50ca4921
commit
4d04f7a787
|
@ -3,21 +3,22 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.tcpid</groupId>
|
||||
<artifactId>opret-parent</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<artifactId>opret-parent</artifactId>
|
||||
|
||||
<version>0.0.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>opret-testapp</artifactId>
|
||||
<repositories>
|
||||
<?-- <repositories>
|
||||
<repository>
|
||||
<id>oss-sonatype</id>
|
||||
<name>oss-sonatype</name>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
--?>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bitcoinj</groupId>
|
||||
|
@ -137,4 +138,4 @@
|
|||
</issueManagement>
|
||||
<name>opretj testapp</name>
|
||||
<url>https://github.com/bitcoinj/bitcoinj</url>
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
@ -21,10 +21,11 @@ import org.bitcoinj.wallet.SendRequest;
|
|||
import org.libsodium.jni.crypto.Hash;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tcpid.key.MasterSigningKey;
|
||||
import org.tcpid.opretj.OPRETECParser;
|
||||
import org.tcpid.opretj.OPRETWallet;
|
||||
import org.tcpid.opretj.OPRETWalletAppKit;
|
||||
import org.tcpid.ec.MasterSigningKey;
|
||||
import org.tcpid.ec.Parser;
|
||||
import org.tcpid.ec.RevokeBabuDB;
|
||||
import org.tcpid.opretj.Wallet;
|
||||
import org.tcpid.opretj.WalletAppKit;
|
||||
|
||||
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 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.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 String[] cmds = { "help", "quit", "exit", "balance", "receive", "empty", "opret" };
|
||||
reader.addCompleter(new StringsCompleter(cmds));
|
||||
|
@ -173,8 +174,8 @@ public class App {
|
|||
}
|
||||
|
||||
final NetworkParameters params = net.value(opts).get();
|
||||
|
||||
final OPRETECParser bs = new OPRETECParser();
|
||||
final RevokeBabuDB revokedb = new RevokeBabuDB("revokedb");
|
||||
final Parser bs = new Parser(revokedb);
|
||||
|
||||
final boolean chk = bs.cryptoSelfTest();
|
||||
if (chk) {
|
||||
|
@ -184,7 +185,7 @@ public class App {
|
|||
System.exit(-1);
|
||||
}
|
||||
|
||||
bs.addOPRETECRevokeEventListener((key) -> {
|
||||
bs.addRevokeEventListener((key) -> {
|
||||
System.out.println("Revoked Key: " + Utils.HEX.encode(key.toBytes()));
|
||||
});
|
||||
|
||||
|
@ -199,7 +200,7 @@ public class App {
|
|||
|
||||
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() {
|
||||
@Override
|
||||
|
@ -230,7 +231,7 @@ public class App {
|
|||
System.exit(-1);
|
||||
}
|
||||
|
||||
final OPRETWallet wallet = kit.opretwallet();
|
||||
final Wallet wallet = kit.opretwallet();
|
||||
|
||||
wallet.addCoinsReceivedEventListener((wallet1, tx, prevBalance, newBalance) -> {
|
||||
final Coin c = tx.getValue(wallet1);
|
||||
|
@ -276,12 +277,12 @@ public class App {
|
|||
kit.awaitTerminated();
|
||||
}
|
||||
|
||||
private static boolean sendOPReturn(final OPRETWalletAppKit kit, final PrintWriter output) {
|
||||
final OPRETWallet wallet = kit.opretwallet();
|
||||
private static boolean sendOPReturn(final WalletAppKit kit, final PrintWriter output) {
|
||||
final Wallet wallet = kit.opretwallet();
|
||||
final NetworkParameters params = wallet.getNetworkParameters();
|
||||
|
||||
final Transaction t = new Transaction(params);
|
||||
final Script script = OPRETECParser.getRevokeScript(SK);
|
||||
final Script script = Parser.getRevokeScript(SK);
|
||||
t.addOutput(Coin.ZERO, script);
|
||||
final SendRequest request = SendRequest.forTx(t);
|
||||
request.ensureMinRequiredFee = true;
|
||||
|
|
|
@ -7,7 +7,29 @@
|
|||
<version>0.0.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>opretj</artifactId>
|
||||
|
||||
<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>
|
||||
<id>oss-sonatype</id>
|
||||
<name>oss-sonatype</name>
|
||||
|
@ -39,12 +61,20 @@
|
|||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.joshjdevl.libsodiumjni</groupId>
|
||||
<artifactId>libsodium-jni</artifactId>
|
||||
<version>1.0.2-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.xtreemfs.babudb</groupId>
|
||||
<artifactId>babudb-core</artifactId>
|
||||
<version>0.5.6</version>
|
||||
<classifier>shaded</classifier>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.tcpid.key;
|
||||
package org.tcpid.ec;
|
||||
|
||||
import static org.libsodium.jni.NaCl.sodium;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.tcpid.key;
|
||||
package org.tcpid.ec;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package org.tcpid.key;
|
||||
package org.tcpid.ec;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.tcpid.opretj.OPRETTransaction;
|
||||
import org.tcpid.opretj.Transaction;
|
||||
|
||||
public class MasterVerifyKey extends VerifyKey {
|
||||
private final LinkedList<VerifyKey> subkeys = new LinkedList<>();
|
||||
|
@ -31,7 +31,7 @@ public class MasterVerifyKey extends VerifyKey {
|
|||
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()) {
|
||||
throw new IndexOutOfBoundsException("Subkey list is not empty");
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.tcpid.opretj;
|
||||
package org.tcpid.ec;
|
||||
|
||||
import static org.bitcoinj.script.ScriptOpCodes.OP_RETURN;
|
||||
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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tcpid.key.HMACSHA512256;
|
||||
import org.tcpid.key.MasterSigningKey;
|
||||
import org.tcpid.key.MasterVerifyKey;
|
||||
import org.tcpid.key.SigningKey;
|
||||
import org.tcpid.key.VerifyKey;
|
||||
import org.tcpid.opretj.BaseHandler;
|
||||
import org.tcpid.opretj.Transaction;
|
||||
|
||||
import com.google.common.primitives.Bytes;
|
||||
|
||||
public class OPRETECParser extends OPRETBaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OPRETECParser.class);
|
||||
public class Parser extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(Parser.class);
|
||||
public static final Hash HASH = new Hash();
|
||||
|
||||
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_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) {
|
||||
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, OPRETTransaction> transHashMap = Collections.synchronizedMap(new HashMap<>());
|
||||
protected final Map<List<Byte>, List<OPRETTransaction>> transA1HashMap = Collections
|
||||
protected final Map<Sha256Hash, Transaction> transHashMap = Collections.synchronizedMap(new HashMap<>());
|
||||
protected final Map<List<Byte>, List<Transaction>> transA1HashMap = Collections
|
||||
.synchronizedMap(new HashMap<>());
|
||||
protected final Map<List<Byte>, List<OPRETTransaction>> transA2HashMap = Collections
|
||||
protected final Map<List<Byte>, List<Transaction>> transA2HashMap = Collections
|
||||
.synchronizedMap(new HashMap<>());
|
||||
protected final Map<List<Byte>, List<OPRETTransaction>> transA3HashMap = Collections
|
||||
protected final Map<List<Byte>, List<Transaction>> transA3HashMap = Collections
|
||||
.synchronizedMap(new HashMap<>());
|
||||
protected final Map<List<Byte>, List<OPRETTransaction>> transA4HashMap = Collections
|
||||
protected final Map<List<Byte>, List<Transaction>> transA4HashMap = Collections
|
||||
.synchronizedMap(new HashMap<>());
|
||||
protected final Map<List<Byte>, List<OPRETTransaction>> trans51HashMap = Collections
|
||||
protected final Map<List<Byte>, List<Transaction>> trans51HashMap = Collections
|
||||
.synchronizedMap(new HashMap<>());
|
||||
protected final Map<List<Byte>, List<OPRETTransaction>> trans52HashMap = Collections
|
||||
protected final Map<List<Byte>, List<Transaction>> trans52HashMap = Collections
|
||||
.synchronizedMap(new HashMap<>());
|
||||
|
||||
protected final Map<List<Byte>, List<MasterVerifyKey>> verifyKeys = Collections.synchronizedMap(new HashMap<>());
|
||||
|
||||
private final CopyOnWriteArrayList<ListenerRegistration<OPRETECEventListener>> opReturnChangeListeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
/**
|
||||
* 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 addRevokeEventListener(final RevokeEventListener listener) {
|
||||
revokeDB.addRevokeEventListener(listener);
|
||||
}
|
||||
|
||||
public void addVerifyKey(final MasterVerifyKey key, final long earliestTime) {
|
||||
|
@ -113,6 +108,7 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
verifyKeys.get(hash).add(key);
|
||||
logger.debug("Adding pkhash {}", key.getShortHash());
|
||||
addOPRET(key.getShortHash(), earliestTime);
|
||||
revokeDB.storeForCheck(key);
|
||||
}
|
||||
|
||||
public boolean cryptoSelfTest() {
|
||||
|
@ -163,7 +159,7 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean handleEC0F(final OPRETTransaction t) {
|
||||
private boolean handleEC0F(final Transaction t) {
|
||||
final byte[] sig = Bytes.toArray(t.opretData.get(1));
|
||||
if ((sig.length != 64)) {
|
||||
logger.debug("chunk 1 size != 64, but {}", sig.length);
|
||||
|
@ -197,12 +193,12 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean handleEC1C(final OPRETTransaction t) {
|
||||
private boolean handleEC1C(final Transaction t) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean handleEC1D(final OPRETTransaction t) {
|
||||
private boolean handleEC1D(final Transaction t) {
|
||||
final byte[] sig = Bytes.toArray(t.opretData.get(1));
|
||||
if ((sig.length != 64)) {
|
||||
logger.debug("chunk 1 size != 64, but {}", sig.length);
|
||||
|
@ -236,17 +232,17 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean handleEC51(final OPRETTransaction t) {
|
||||
private boolean handleEC51(final Transaction t) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean handleEC52(final OPRETTransaction t) {
|
||||
private boolean handleEC52(final Transaction t) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean handleECA1(final OPRETTransaction t1) {
|
||||
private boolean handleECA1(final Transaction t1) {
|
||||
// FIXME: refactor with handleECA2
|
||||
|
||||
logger.debug("handleECA1");
|
||||
|
@ -267,7 +263,7 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
}
|
||||
|
||||
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[] cipher = Bytes.concat(Arrays.copyOfRange(data1, 0, 48), Arrays.copyOfRange(data2, 0, 48));
|
||||
BigInteger nonce1 = BigInteger.ZERO;
|
||||
|
@ -321,14 +317,14 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
}
|
||||
}
|
||||
if (!transA1HashMap.containsKey(pkhash)) {
|
||||
transA1HashMap.put(pkhash, new ArrayList<OPRETTransaction>());
|
||||
transA1HashMap.put(pkhash, new ArrayList<Transaction>());
|
||||
}
|
||||
transA1HashMap.get(pkhash).add(t1);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean handleECA2(final OPRETTransaction t2) {
|
||||
private boolean handleECA2(final Transaction t2) {
|
||||
// FIXME: refactor with handleECA1
|
||||
logger.debug("handleECA2");
|
||||
final byte[] data2 = Bytes.toArray(t2.opretData.get(1));
|
||||
|
@ -349,7 +345,7 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
}
|
||||
|
||||
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[] cipher = Bytes.concat(Arrays.copyOfRange(data1, 0, 48), Arrays.copyOfRange(data2, 0, 48));
|
||||
BigInteger nonce1 = BigInteger.ZERO;
|
||||
|
@ -399,24 +395,24 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
}
|
||||
}
|
||||
if (!transA2HashMap.containsKey(pkhash)) {
|
||||
transA2HashMap.put(pkhash, new ArrayList<OPRETTransaction>());
|
||||
transA2HashMap.put(pkhash, new ArrayList<Transaction>());
|
||||
}
|
||||
transA2HashMap.get(pkhash).add(t2);
|
||||
logger.debug("nothing in A1 HashMap");
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean handleECA3(final OPRETTransaction t) {
|
||||
private boolean handleECA3(final Transaction t) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean handleECA4(final OPRETTransaction t) {
|
||||
private boolean handleECA4(final Transaction t) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean handleTransaction(final OPRETTransaction t) {
|
||||
protected boolean handleTransaction(final Transaction t) {
|
||||
logger.debug("checking {}", t.opretData);
|
||||
|
||||
if ((t.opretData.size() != 2) && (t.opretData.size() != 3) && (t.opretData.size() != 4)) {
|
||||
|
@ -465,7 +461,7 @@ public class OPRETECParser extends OPRETBaseHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void pushTransaction(final OPRETTransaction t) {
|
||||
public void pushTransaction(final Transaction 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
|
||||
* removed, false if that listener was never added.
|
||||
*/
|
||||
public boolean removeOPRETECRevokeEventListener(final OPRETECEventListener listener) {
|
||||
return ListenerRegistration.removeFromList(listener, opReturnChangeListeners);
|
||||
public boolean removeOPRETECRevokeEventListener(final RevokeEventListener listener) {
|
||||
return revokeDB.removeRevokeEventListener(listener);
|
||||
}
|
||||
|
||||
public void removeVerifyKey(final MasterVerifyKey key) {
|
115
opretj/src/main/java/org/tcpid/ec/RevokeBabuDB.java
Normal file
115
opretj/src/main/java/org/tcpid/ec/RevokeBabuDB.java
Normal 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;
|
||||
}
|
||||
}
|
11
opretj/src/main/java/org/tcpid/ec/RevokeDBInterface.java
Normal file
11
opretj/src/main/java/org/tcpid/ec/RevokeDBInterface.java
Normal 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);
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.tcpid.ec;
|
||||
|
||||
public interface RevokeEventListener {
|
||||
void onRevoke(MasterVerifyKey key);
|
||||
}
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.tcpid.key;
|
||||
package org.tcpid.ec;
|
||||
|
||||
import static org.libsodium.jni.NaCl.sodium;
|
||||
import static org.libsodium.jni.SodiumConstants.PUBLICKEY_BYTES;
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.tcpid.key;
|
||||
package org.tcpid.ec;
|
||||
|
||||
import static org.libsodium.jni.NaCl.sodium;
|
||||
import static org.libsodium.jni.SodiumConstants.PUBLICKEY_BYTES;
|
|
@ -15,9 +15,9 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.google.common.primitives.Bytes;
|
||||
|
||||
public abstract class OPRETBaseHandler implements OPRETHandlerInterface {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OPRETBaseHandler.class);
|
||||
private final CopyOnWriteArrayList<ListenerRegistration<OPRETChangeEventListener>> opReturnChangeListeners = new CopyOnWriteArrayList<ListenerRegistration<OPRETChangeEventListener>>();
|
||||
public abstract class BaseHandler implements HandlerInterface {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BaseHandler.class);
|
||||
private final CopyOnWriteArrayList<ListenerRegistration<ChangeEventListener>> opReturnChangeListeners = new CopyOnWriteArrayList<ListenerRegistration<ChangeEventListener>>();
|
||||
private final Map<List<Byte>, Long> magicBytes = Collections.synchronizedMap(new HashMap<>());
|
||||
|
||||
protected void addOPRET(final byte[] magic, final long earliestTime) {
|
||||
|
@ -33,9 +33,9 @@ public abstract class OPRETBaseHandler implements OPRETHandlerInterface {
|
|||
* given executor.
|
||||
*/
|
||||
@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.
|
||||
opReturnChangeListeners.add(new ListenerRegistration<OPRETChangeEventListener>(listener, executor));
|
||||
opReturnChangeListeners.add(new ListenerRegistration<ChangeEventListener>(listener, executor));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,7 +63,7 @@ public abstract class OPRETBaseHandler implements OPRETHandlerInterface {
|
|||
}
|
||||
|
||||
protected void queueOnOPRETChanged() {
|
||||
for (final ListenerRegistration<OPRETChangeEventListener> registration : opReturnChangeListeners) {
|
||||
for (final ListenerRegistration<ChangeEventListener> registration : opReturnChangeListeners) {
|
||||
registration.executor.execute(() -> registration.listener.onOPRETChanged());
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public abstract class OPRETBaseHandler implements OPRETHandlerInterface {
|
|||
* removed, false if that listener was never added.
|
||||
*/
|
||||
@Override
|
||||
public boolean removeOPRETChangeEventListener(final OPRETChangeEventListener listener) {
|
||||
public boolean removeOPRETChangeEventListener(final ChangeEventListener listener) {
|
||||
return ListenerRegistration.removeFromList(listener, opReturnChangeListeners);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
package org.tcpid.opretj;
|
||||
|
||||
public interface OPRETChangeEventListener {
|
||||
public interface ChangeEventListener {
|
||||
void onOPRETChanged();
|
||||
}
|
|
@ -4,11 +4,11 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public interface OPRETHandlerInterface {
|
||||
public interface HandlerInterface {
|
||||
|
||||
// void addOPRET(byte[] magic, long earliestTime);
|
||||
|
||||
void addOPRETChangeEventListener(Executor executor, OPRETChangeEventListener listener);
|
||||
void addOPRETChangeEventListener(Executor executor, ChangeEventListener listener);
|
||||
|
||||
long getEarliestElementCreationTime();
|
||||
|
||||
|
@ -18,8 +18,8 @@ public interface OPRETHandlerInterface {
|
|||
|
||||
// void removeOPRET(byte[] magic);
|
||||
|
||||
void pushTransaction(OPRETTransaction t);
|
||||
void pushTransaction(Transaction t);
|
||||
|
||||
boolean removeOPRETChangeEventListener(OPRETChangeEventListener listener);
|
||||
boolean removeOPRETChangeEventListener(ChangeEventListener listener);
|
||||
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package org.tcpid.opretj;
|
||||
|
||||
import org.tcpid.key.MasterVerifyKey;
|
||||
|
||||
public interface OPRETECEventListener {
|
||||
void onOPRETRevoke(MasterVerifyKey key);
|
||||
}
|
|
@ -9,7 +9,7 @@ import org.bitcoinj.core.Utils;
|
|||
|
||||
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;
|
||||
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.txHash = txHash;
|
||||
this.opretData = opret_data;
|
|
@ -18,7 +18,6 @@ import org.bitcoinj.core.Peer;
|
|||
import org.bitcoinj.core.ScriptException;
|
||||
import org.bitcoinj.core.Sha256Hash;
|
||||
import org.bitcoinj.core.StoredBlock;
|
||||
import org.bitcoinj.core.Transaction;
|
||||
import org.bitcoinj.core.TransactionOutput;
|
||||
import org.bitcoinj.core.Utils;
|
||||
import org.bitcoinj.core.VerificationException;
|
||||
|
@ -26,22 +25,21 @@ import org.bitcoinj.core.listeners.BlocksDownloadedEventListener;
|
|||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.ScriptChunk;
|
||||
import org.bitcoinj.wallet.KeyChainGroup;
|
||||
import org.bitcoinj.wallet.Wallet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
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 Logger logger = LoggerFactory.getLogger(OPRETWallet.class);
|
||||
private final HandlerInterface opbs;
|
||||
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<>());
|
||||
|
||||
public OPRETWallet(final NetworkParameters params, final KeyChainGroup keyChainGroup,
|
||||
final OPRETHandlerInterface bs) {
|
||||
public Wallet(final NetworkParameters params, final KeyChainGroup keyChainGroup,
|
||||
final HandlerInterface bs) {
|
||||
super(params, keyChainGroup);
|
||||
opbs = bs;
|
||||
}
|
||||
|
@ -84,7 +82,7 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
|
|||
}
|
||||
|
||||
@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());
|
||||
|
||||
if (pendingTransactions.containsValue(tx)) {
|
||||
|
@ -98,7 +96,7 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
|
|||
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 List<List<Byte>> myList = new ArrayList<>();
|
||||
|
||||
|
@ -147,7 +145,7 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
|
|||
return;
|
||||
}
|
||||
|
||||
for (final OPRETTransaction t : pendingTransactions.get(block.getHash()).values()) {
|
||||
for (final Transaction t : pendingTransactions.get(block.getHash()).values()) {
|
||||
t.setPartialMerkleTree(filteredBlock.getPartialMerkleTree());
|
||||
opbs.pushTransaction(t);
|
||||
}
|
||||
|
@ -161,7 +159,7 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
|
|||
}
|
||||
|
||||
@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 {
|
||||
|
||||
super.receiveFromBlock(tx, block, blockType, relativityOffset);
|
||||
|
@ -175,10 +173,10 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
|
|||
final Sha256Hash h = block.getHeader().getHash();
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
|
@ -5,27 +5,25 @@ import static com.google.common.base.Preconditions.checkState;
|
|||
import java.io.File;
|
||||
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.kits.WalletAppKit;
|
||||
import org.bitcoinj.store.BlockStore;
|
||||
import org.bitcoinj.store.BlockStoreException;
|
||||
import org.bitcoinj.store.SPVBlockStore;
|
||||
import org.bitcoinj.utils.Threading;
|
||||
import org.bitcoinj.wallet.Wallet;
|
||||
|
||||
public class OPRETWalletAppKit extends WalletAppKit {
|
||||
// private final Logger logger = LoggerFactory.getLogger(OPRETWallet.class);
|
||||
private final OPRETHandlerInterface opbs;
|
||||
public class WalletAppKit extends org.bitcoinj.kits.WalletAppKit {
|
||||
// private final Logger logger = LoggerFactory.getLogger(Wallet.class);
|
||||
private final HandlerInterface opbs;
|
||||
|
||||
public OPRETWalletAppKit(final NetworkParameters params, final File directory, final String filePrefix,
|
||||
final OPRETHandlerInterface bs) {
|
||||
public WalletAppKit(final NetworkParameters params, final File directory, final String filePrefix,
|
||||
final HandlerInterface bs) {
|
||||
super(params, directory, filePrefix);
|
||||
opbs = bs;
|
||||
walletFactory = (params1, keyChainGroup) -> new OPRETWallet(params1, keyChainGroup, opbs);
|
||||
walletFactory = (params1, keyChainGroup) -> new Wallet(params1, keyChainGroup, opbs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetupCompleted() {
|
||||
final OPRETWallet wallet = opretwallet();
|
||||
final Wallet wallet = opretwallet();
|
||||
opbs.addOPRETChangeEventListener(Threading.USER_THREAD, wallet);
|
||||
// TODO: remove
|
||||
wallet.reset();
|
||||
|
@ -36,11 +34,11 @@ public class OPRETWalletAppKit extends WalletAppKit {
|
|||
/*
|
||||
* 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");
|
||||
final Wallet w = wallet();
|
||||
if (w instanceof OPRETWallet) {
|
||||
return (OPRETWallet) w;
|
||||
final org.bitcoinj.wallet.Wallet w = wallet();
|
||||
if (w instanceof Wallet) {
|
||||
return (Wallet) w;
|
||||
} else {
|
||||
throw new RuntimeException("wallet != OPTRETWallet");
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.tcpid.opretj;
|
||||
package org.tcpid.ec;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -18,9 +18,9 @@ import org.libsodium.jni.crypto.Util;
|
|||
import org.libsodium.jni.encoders.Encoder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tcpid.key.HMACSHA512256;
|
||||
import org.tcpid.key.MasterSigningKey;
|
||||
import org.tcpid.key.MasterVerifyKey;
|
||||
import org.tcpid.ec.HMACSHA512256;
|
||||
import org.tcpid.ec.MasterSigningKey;
|
||||
import org.tcpid.ec.MasterVerifyKey;
|
||||
|
||||
import com.google.common.primitives.Bytes;
|
||||
|
66
opretj/src/test/java/org/tcpid/ec/TestDB.java
Normal file
66
opretj/src/test/java/org/tcpid/ec/TestDB.java
Normal 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 {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.tcpid.opretj;
|
||||
package org.tcpid.ec;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -15,7 +15,8 @@ import org.junit.Test;
|
|||
import org.libsodium.jni.encoders.Encoder;
|
||||
import org.slf4j.Logger;
|
||||
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;
|
||||
|
||||
|
@ -24,7 +25,7 @@ public class TestECA1 {
|
|||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.tcpid.opretj.OPRETECParser#pushTransaction(org.tcpid.opretj.OPRETTransaction)}.
|
||||
* {@link org.tcpid.ec.Parser#pushTransaction(org.tcpid.opretj.Transaction)}.
|
||||
*/
|
||||
@Test
|
||||
public void testPushTransaction() {
|
||||
|
@ -42,27 +43,27 @@ public class TestECA1 {
|
|||
opret_data.add(Bytes.asList(Encoder.HEX.decode("eca1")));
|
||||
opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 0, 48)));
|
||||
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.add(Bytes.asList(Encoder.HEX.decode("eca2")));
|
||||
opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 48, 96)));
|
||||
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.add(Bytes.asList(Encoder.HEX.decode("eca2")));
|
||||
opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 0, 48)));
|
||||
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.add(Bytes.asList(Encoder.HEX.decode("eca1")));
|
||||
opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 48, 96)));
|
||||
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);
|
||||
|
||||
|
@ -95,7 +96,7 @@ public class TestECA1 {
|
|||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.tcpid.opretj.OPRETECParser#pushTransaction(org.tcpid.opretj.OPRETTransaction)}.
|
||||
* {@link org.tcpid.ec.Parser#pushTransaction(org.tcpid.opretj.Transaction)}.
|
||||
*/
|
||||
@Test
|
||||
public void testPushTransactionWithNonce() {
|
||||
|
@ -113,15 +114,15 @@ public class TestECA1 {
|
|||
final byte[] byte1f = { (byte) 0x11 };
|
||||
opret_data.add(Bytes.asList(Bytes.concat(Arrays.copyOfRange(cipher, 0, 48), byte1f)));
|
||||
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.add(Bytes.asList(Encoder.HEX.decode("eca2")));
|
||||
opret_data.add(Bytes.asList(Arrays.copyOfRange(cipher, 48, 96)));
|
||||
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);
|
||||
|
|
@ -8,11 +8,11 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.google.common.primitives.Bytes;
|
||||
|
||||
public class OPRETSimpleLogger extends OPRETBaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OPRETSimpleLogger.class);
|
||||
public class SimpleLogger extends BaseHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SimpleLogger.class);
|
||||
|
||||
@Override
|
||||
public void pushTransaction(final OPRETTransaction t) {
|
||||
public void pushTransaction(final Transaction t) {
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
|
||||
for (final List<Byte> d : t.opretData) {
|
Loading…
Reference in a new issue