source reformat
This commit is contained in:
parent
7953d1c32c
commit
8610793010
|
@ -1,6 +1,5 @@
|
||||||
package org.tcpid.opretj;
|
package org.tcpid.opretj;
|
||||||
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -21,7 +20,7 @@ public abstract class OPRETBaseHandler implements OPRETHandlerInterface {
|
||||||
private final Map<List<Byte>, Long> magicBytes = new HashMap<>();
|
private final Map<List<Byte>, Long> magicBytes = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOPRET(byte[] magic, long earliestTime) {
|
public void addOPRET(final byte[] magic, final long earliestTime) {
|
||||||
logger.debug("addMagicBytes: {} - Time {}", Utils.HEX.encode(magic), earliestTime);
|
logger.debug("addMagicBytes: {} - Time {}", Utils.HEX.encode(magic), earliestTime);
|
||||||
final List<Byte> blist = Bytes.asList(magic);
|
final List<Byte> blist = Bytes.asList(magic);
|
||||||
magicBytes.put(blist, earliestTime);
|
magicBytes.put(blist, earliestTime);
|
||||||
|
@ -34,7 +33,7 @@ public abstract class OPRETBaseHandler implements OPRETHandlerInterface {
|
||||||
* given executor.
|
* given executor.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addOPRETChangeEventListener(Executor executor, OPRETChangeEventListener listener) {
|
public void addOPRETChangeEventListener(final Executor executor, final OPRETChangeEventListener 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<OPRETChangeEventListener>(listener, executor));
|
||||||
}
|
}
|
||||||
|
@ -65,17 +64,12 @@ public abstract class OPRETBaseHandler implements OPRETHandlerInterface {
|
||||||
|
|
||||||
protected void queueOnOPRETChanged() {
|
protected void queueOnOPRETChanged() {
|
||||||
for (final ListenerRegistration<OPRETChangeEventListener> registration : opReturnChangeListeners) {
|
for (final ListenerRegistration<OPRETChangeEventListener> registration : opReturnChangeListeners) {
|
||||||
registration.executor.execute(new Runnable() {
|
registration.executor.execute(() -> registration.listener.onOPRETChanged());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
registration.listener.onOPRETChanged();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeOPRET(byte[] magic) {
|
public void removeOPRET(final byte[] magic) {
|
||||||
magicBytes.remove(Bytes.asList(magic));
|
magicBytes.remove(Bytes.asList(magic));
|
||||||
queueOnOPRETChanged();
|
queueOnOPRETChanged();
|
||||||
}
|
}
|
||||||
|
@ -85,7 +79,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(OPRETChangeEventListener listener) {
|
public boolean removeOPRETChangeEventListener(final OPRETChangeEventListener listener) {
|
||||||
return ListenerRegistration.removeFromList(listener, opReturnChangeListeners);
|
return ListenerRegistration.removeFromList(listener, opReturnChangeListeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.tcpid.opretj;
|
package org.tcpid.opretj;
|
||||||
|
|
||||||
|
|
||||||
public interface OPRETChangeEventListener {
|
public interface OPRETChangeEventListener {
|
||||||
void onOPRETChanged();
|
void onOPRETChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.tcpid.opretj;
|
package org.tcpid.opretj;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -30,32 +29,13 @@ public class OPRETECParser extends OPRETBaseHandler {
|
||||||
* scripts watched by this wallet change. The listener is executed by the
|
* scripts watched by this wallet change. The listener is executed by the
|
||||||
* given executor.
|
* given executor.
|
||||||
*/
|
*/
|
||||||
public void addOPRETECRevokeEventListener(OPRETECRevokeEventListener listener) {
|
public void addOPRETECRevokeEventListener(final OPRETECRevokeEventListener 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
|
opReturnChangeListeners
|
||||||
.add(new ListenerRegistration<OPRETECRevokeEventListener>(listener, Threading.USER_THREAD));
|
.add(new ListenerRegistration<OPRETECRevokeEventListener>(listener, Threading.USER_THREAD));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private boolean checkData(final OPRETTransaction t1, final OPRETTransaction t2) {
|
||||||
* Removes the given event listener object. Returns true if the listener was
|
|
||||||
* removed, false if that listener was never added.
|
|
||||||
*/
|
|
||||||
public boolean removeOPRETECRevokeEventListener(OPRETECRevokeEventListener listener) {
|
|
||||||
return ListenerRegistration.removeFromList(listener, opReturnChangeListeners);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void queueOnOPRETRevoke(final byte[] pkhash, final byte[] sig) {
|
|
||||||
for (final ListenerRegistration<OPRETECRevokeEventListener> registration : opReturnChangeListeners) {
|
|
||||||
registration.executor.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
registration.listener.onOPRETRevoke(pkhash, sig);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkData(OPRETTransaction t1, OPRETTransaction t2) {
|
|
||||||
final List<List<Byte>> opret_data = new ArrayList<>(t1.opretData);
|
final List<List<Byte>> opret_data = new ArrayList<>(t1.opretData);
|
||||||
opret_data.addAll(t2.opretData);
|
opret_data.addAll(t2.opretData);
|
||||||
logger.debug("checking {}", opret_data);
|
logger.debug("checking {}", opret_data);
|
||||||
|
@ -101,7 +81,7 @@ public class OPRETECParser extends OPRETBaseHandler {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleRevoke(OPRETTransaction t1, OPRETTransaction t2) {
|
private boolean handleRevoke(final OPRETTransaction t1, final OPRETTransaction t2) {
|
||||||
final byte[] pkhash = Bytes.toArray(t1.opretData.get(2));
|
final byte[] pkhash = Bytes.toArray(t1.opretData.get(2));
|
||||||
final byte[] sig = Bytes.concat(Bytes.toArray(t1.opretData.get(3)), Bytes.toArray(t2.opretData.get(3)));
|
final byte[] sig = Bytes.concat(Bytes.toArray(t1.opretData.get(3)), Bytes.toArray(t2.opretData.get(3)));
|
||||||
|
|
||||||
|
@ -133,4 +113,18 @@ public class OPRETECParser extends OPRETBaseHandler {
|
||||||
logger.info("block hash {}", blockHash);
|
logger.info("block hash {}", blockHash);
|
||||||
logger.info("Merkle Tree: {}", partialMerkleTree);
|
logger.info("Merkle Tree: {}", partialMerkleTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void queueOnOPRETRevoke(final byte[] pkhash, final byte[] sig) {
|
||||||
|
for (final ListenerRegistration<OPRETECRevokeEventListener> registration : opReturnChangeListeners) {
|
||||||
|
registration.executor.execute(() -> registration.listener.onOPRETRevoke(pkhash, sig));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the given event listener object. Returns true if the listener was
|
||||||
|
* removed, false if that listener was never added.
|
||||||
|
*/
|
||||||
|
public boolean removeOPRETECRevokeEventListener(final OPRETECRevokeEventListener listener) {
|
||||||
|
return ListenerRegistration.removeFromList(listener, opReturnChangeListeners);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.tcpid.opretj;
|
package org.tcpid.opretj;
|
||||||
|
|
||||||
|
|
||||||
public interface OPRETECRevokeEventListener {
|
public interface OPRETECRevokeEventListener {
|
||||||
void onOPRETRevoke(final byte[] pkhash, final byte[] sig);
|
void onOPRETRevoke(final byte[] pkhash, final byte[] sig);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.tcpid.opretj;
|
package org.tcpid.opretj;
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.tcpid.opretj;
|
package org.tcpid.opretj;
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.tcpid.opretj;
|
package org.tcpid.opretj;
|
||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.tcpid.opretj;
|
package org.tcpid.opretj;
|
||||||
|
|
||||||
|
|
||||||
import static org.bitcoinj.script.ScriptOpCodes.OP_RETURN;
|
import static org.bitcoinj.script.ScriptOpCodes.OP_RETURN;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -42,14 +41,15 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
|
||||||
private final Set<Sha256Hash> blocksToStore = new HashSet<>();
|
private final Set<Sha256Hash> blocksToStore = new HashSet<>();
|
||||||
protected final Map<Sha256Hash, Transaction> pendingTransactions;
|
protected final Map<Sha256Hash, Transaction> pendingTransactions;
|
||||||
|
|
||||||
public OPRETWallet(NetworkParameters params, KeyChainGroup keyChainGroup, OPRETHandlerInterface bs) {
|
public OPRETWallet(final NetworkParameters params, final KeyChainGroup keyChainGroup,
|
||||||
|
final OPRETHandlerInterface bs) {
|
||||||
super(params, keyChainGroup);
|
super(params, keyChainGroup);
|
||||||
opbs = bs;
|
opbs = bs;
|
||||||
pendingTransactions = new HashMap<Sha256Hash, Transaction>();
|
pendingTransactions = new HashMap<Sha256Hash, Transaction>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BloomFilter getBloomFilter(int size, double falsePositiveRate, long nTweak) {
|
public BloomFilter getBloomFilter(final int size, final double falsePositiveRate, final long nTweak) {
|
||||||
beginBloomFilterCalculation();
|
beginBloomFilterCalculation();
|
||||||
try {
|
try {
|
||||||
final BloomFilter filter = super.getBloomFilter(size, falsePositiveRate, nTweak);
|
final BloomFilter filter = super.getBloomFilter(size, falsePositiveRate, nTweak);
|
||||||
|
@ -86,7 +86,7 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPendingTransactionRelevant(Transaction tx) throws ScriptException {
|
public boolean isPendingTransactionRelevant(final Transaction tx) throws ScriptException {
|
||||||
logger.debug("isPendingTransactionRelevant {}", tx.getHashAsString());
|
logger.debug("isPendingTransactionRelevant {}", tx.getHashAsString());
|
||||||
|
|
||||||
if (pendingTransactions.containsValue(tx)) {
|
if (pendingTransactions.containsValue(tx)) {
|
||||||
|
@ -100,7 +100,7 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<List<Byte>> isTransactionOPReturn(Transaction tx) throws ScriptException {
|
public List<List<Byte>> isTransactionOPReturn(final 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<>();
|
||||||
|
|
||||||
|
@ -142,7 +142,8 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlocksDownloaded(Peer peer, Block block, FilteredBlock filteredBlock, int blocksLeft) {
|
public void onBlocksDownloaded(final Peer peer, final Block block, final FilteredBlock filteredBlock,
|
||||||
|
final int blocksLeft) {
|
||||||
if (!blocksToStore.contains(block.getHash())) {
|
if (!blocksToStore.contains(block.getHash())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -158,8 +159,8 @@ public class OPRETWallet extends Wallet implements BlocksDownloadedEventListener
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType,
|
public void receiveFromBlock(final Transaction tx, final StoredBlock block, final BlockChain.NewBlockType blockType,
|
||||||
int relativityOffset) throws VerificationException {
|
final int relativityOffset) throws VerificationException {
|
||||||
|
|
||||||
super.receiveFromBlock(tx, block, blockType, relativityOffset);
|
super.receiveFromBlock(tx, block, blockType, relativityOffset);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.tcpid.opretj;
|
package org.tcpid.opretj;
|
||||||
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -11,23 +10,17 @@ 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.KeyChainGroup;
|
|
||||||
import org.bitcoinj.wallet.Wallet;
|
import org.bitcoinj.wallet.Wallet;
|
||||||
import org.bitcoinj.wallet.WalletProtobufSerializer.WalletFactory;
|
|
||||||
|
|
||||||
public class OPRETWalletAppKit extends WalletAppKit {
|
public class OPRETWalletAppKit extends WalletAppKit {
|
||||||
// private final Logger logger = LoggerFactory.getLogger(OPRETWallet.class);
|
// private final Logger logger = LoggerFactory.getLogger(OPRETWallet.class);
|
||||||
private final OPRETHandlerInterface opbs;
|
private final OPRETHandlerInterface opbs;
|
||||||
|
|
||||||
public OPRETWalletAppKit(NetworkParameters params, File directory, String filePrefix, OPRETHandlerInterface bs) {
|
public OPRETWalletAppKit(final NetworkParameters params, final File directory, final String filePrefix,
|
||||||
|
final OPRETHandlerInterface bs) {
|
||||||
super(params, directory, filePrefix);
|
super(params, directory, filePrefix);
|
||||||
opbs = bs;
|
opbs = bs;
|
||||||
walletFactory = new WalletFactory() {
|
walletFactory = (params1, keyChainGroup) -> new OPRETWallet(params1, keyChainGroup, opbs);
|
||||||
@Override
|
|
||||||
public Wallet create(NetworkParameters params, KeyChainGroup keyChainGroup) {
|
|
||||||
return new OPRETWallet(params, keyChainGroup, opbs);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,9 +43,10 @@ public class OPRETWalletAppKit extends WalletAppKit {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BlockStore provideBlockStore(File file) throws BlockStoreException {
|
protected BlockStore provideBlockStore(final File file) throws BlockStoreException {
|
||||||
// TODO: save state
|
// TODO: save state
|
||||||
if (params.getId().equals(NetworkParameters.ID_REGTEST) || params.getId().equals(NetworkParameters.ID_TESTNET)) {
|
if (params.getId().equals(NetworkParameters.ID_REGTEST)
|
||||||
|
|| params.getId().equals(NetworkParameters.ID_TESTNET)) {
|
||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
}
|
}
|
||||||
return new SPVBlockStore(params, file);
|
return new SPVBlockStore(params, file);
|
||||||
|
|
Loading…
Reference in a new issue