mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-12 18:25:51 +00:00
Remove concept of stateful transaction signers.
This commit is contained in:
parent
ade58d2c19
commit
9d6090a7ea
@ -40,7 +40,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
* some local API or something else.
|
||||
* </p>
|
||||
*/
|
||||
public abstract class CustomTransactionSigner extends StatelessTransactionSigner {
|
||||
public abstract class CustomTransactionSigner implements TransactionSigner {
|
||||
private static final Logger log = LoggerFactory.getLogger(CustomTransactionSigner.class);
|
||||
|
||||
@Override
|
||||
|
@ -42,7 +42,7 @@ import org.slf4j.LoggerFactory;
|
||||
* the same derivation path.</p>
|
||||
* <p>This signer always uses {@link Transaction.SigHash#ALL} signing mode.</p>
|
||||
*/
|
||||
public class LocalTransactionSigner extends StatelessTransactionSigner {
|
||||
public class LocalTransactionSigner implements TransactionSigner {
|
||||
private static final Logger log = LoggerFactory.getLogger(LocalTransactionSigner.class);
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
|
||||
* In MissingSigsMode.THROW mode this signer will throw an exception. It would be MissingSignatureException
|
||||
* for P2SH or MissingPrivateKeyException for other transaction types.
|
||||
*/
|
||||
public class MissingSigResolutionSigner extends StatelessTransactionSigner {
|
||||
public class MissingSigResolutionSigner implements TransactionSigner {
|
||||
private static final Logger log = LoggerFactory.getLogger(MissingSigResolutionSigner.class);
|
||||
|
||||
public Wallet.MissingSigsMode missingSigsMode = Wallet.MissingSigsMode.USE_DUMMY_SIG;
|
||||
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 Kosta Korenkov
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.bitcoinj.signers;
|
||||
|
||||
/**
|
||||
* A signer that doesn't have any state to be serialized.
|
||||
*/
|
||||
public abstract class StatelessTransactionSigner implements TransactionSigner {
|
||||
@Override
|
||||
public void deserialize(byte[] data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize() {
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
@ -67,16 +67,6 @@ public interface TransactionSigner {
|
||||
*/
|
||||
boolean isReady();
|
||||
|
||||
/**
|
||||
* Returns byte array of data representing state of this signer. It's used to serialize/deserialize this signer
|
||||
*/
|
||||
byte[] serialize();
|
||||
|
||||
/**
|
||||
* Uses given byte array of data to reconstruct internal state of this signer
|
||||
*/
|
||||
void deserialize(byte[] data);
|
||||
|
||||
/**
|
||||
* Signs given transaction's inputs.
|
||||
* Returns true if signer is compatible with given transaction (can do something meaningful with it).
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -241,7 +241,7 @@ public class Wallet extends BaseTaggableObject
|
||||
private final HashMap<String, WalletExtension> extensions;
|
||||
|
||||
// Objects that perform transaction signing. Applied subsequently one after another
|
||||
@GuardedBy("lock") private List<TransactionSigner> signers;
|
||||
@GuardedBy("lock") private volatile List<TransactionSigner> signers;
|
||||
|
||||
// If this is set then the wallet selects spendable candidate outputs from a UTXO provider.
|
||||
@Nullable private volatile UTXOProvider vUTXOProvider;
|
||||
|
@ -32,8 +32,6 @@ import org.bitcoinj.crypto.KeyCrypter;
|
||||
import org.bitcoinj.crypto.KeyCrypterScrypt;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.ScriptException;
|
||||
import org.bitcoinj.signers.LocalTransactionSigner;
|
||||
import org.bitcoinj.signers.TransactionSigner;
|
||||
import org.bitcoinj.utils.ExchangeRate;
|
||||
import org.bitcoinj.utils.Fiat;
|
||||
import org.bitcoinj.wallet.Protos.Wallet.EncryptionType;
|
||||
@ -235,16 +233,6 @@ public class WalletProtobufSerializer {
|
||||
walletBuilder.addTags(tag);
|
||||
}
|
||||
|
||||
for (TransactionSigner signer : wallet.getTransactionSigners()) {
|
||||
// do not serialize LocalTransactionSigner as it's being added implicitly
|
||||
if (signer instanceof LocalTransactionSigner)
|
||||
continue;
|
||||
Protos.TransactionSigner.Builder protoSigner = Protos.TransactionSigner.newBuilder();
|
||||
protoSigner.setClassName(signer.getClass().getName());
|
||||
protoSigner.setData(ByteString.copyFrom(signer.serialize()));
|
||||
walletBuilder.addTransactionSigners(protoSigner);
|
||||
}
|
||||
|
||||
// Populate the wallet version.
|
||||
walletBuilder.setVersion(wallet.getVersion());
|
||||
|
||||
@ -567,18 +555,6 @@ public class WalletProtobufSerializer {
|
||||
wallet.setTag(tag.getTag(), tag.getData());
|
||||
}
|
||||
|
||||
for (Protos.TransactionSigner signerProto : walletProto.getTransactionSignersList()) {
|
||||
try {
|
||||
Class signerClass = Class.forName(signerProto.getClassName());
|
||||
TransactionSigner signer = (TransactionSigner)signerClass.newInstance();
|
||||
signer.deserialize(signerProto.getData().toByteArray());
|
||||
wallet.addTransactionSigner(signer);
|
||||
} catch (Exception e) {
|
||||
throw new UnreadableWalletException("Unable to deserialize TransactionSigner instance: " +
|
||||
signerProto.getClassName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (walletProto.hasVersion()) {
|
||||
wallet.setVersion(walletProto.getVersion());
|
||||
}
|
||||
|
@ -332,16 +332,6 @@ message Tag {
|
||||
required bytes data = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data required to reconstruct TransactionSigner.
|
||||
*/
|
||||
message TransactionSigner {
|
||||
// fully qualified class name of TransactionSigner implementation
|
||||
required string class_name = 1;
|
||||
// arbitrary data required for signer to function
|
||||
optional bytes data = 2;
|
||||
}
|
||||
|
||||
/** A bitcoin wallet */
|
||||
message Wallet {
|
||||
/**
|
||||
@ -395,8 +385,7 @@ message Wallet {
|
||||
|
||||
repeated Tag tags = 16;
|
||||
|
||||
// transaction signers added to the wallet
|
||||
repeated TransactionSigner transaction_signers = 17;
|
||||
// (field number 17 was used by transaction_signers)
|
||||
|
||||
// Next tag: 18
|
||||
}
|
||||
|
@ -34,17 +34,6 @@ public class NopTransactionSigner implements TransactionSigner {
|
||||
return isReady;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize() {
|
||||
return isReady ? new byte[]{1} : new byte[]{0};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(byte[] data) {
|
||||
if (data.length > 0)
|
||||
isReady = data[0] == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean signInputs(ProposedTransaction t, KeyBag keyBag) {
|
||||
return false;
|
||||
|
@ -42,7 +42,6 @@ import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.ScriptBuilder;
|
||||
import org.bitcoinj.script.ScriptChunk;
|
||||
import org.bitcoinj.script.ScriptPattern;
|
||||
import org.bitcoinj.signers.StatelessTransactionSigner;
|
||||
import org.bitcoinj.signers.TransactionSigner;
|
||||
import org.bitcoinj.store.BlockStoreException;
|
||||
import org.bitcoinj.store.MemoryBlockStore;
|
||||
@ -3319,16 +3318,6 @@ public class WalletTest extends TestWithWallet {
|
||||
wallet.addTransactionSigner(new NopTransactionSigner(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transactionSignersShouldBeSerializedAlongWithWallet() throws Exception {
|
||||
TransactionSigner signer = new NopTransactionSigner(true);
|
||||
wallet.addTransactionSigner(signer);
|
||||
assertEquals(2, wallet.getTransactionSigners().size());
|
||||
wallet = roundTrip(wallet);
|
||||
assertEquals(2, wallet.getTransactionSigners().size());
|
||||
assertTrue(wallet.getTransactionSigners().get(1).isReady());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void watchingMarriedWallet() throws Exception {
|
||||
DeterministicKey watchKey = wallet.getWatchingKey();
|
||||
@ -3340,7 +3329,7 @@ public class WalletTest extends TestWithWallet {
|
||||
final DeterministicKeyChain keyChain = new DeterministicKeyChain(new SecureRandom());
|
||||
DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, keyChain.getWatchingKey().serializePubB58(UNITTEST), UNITTEST);
|
||||
|
||||
TransactionSigner signer = new StatelessTransactionSigner() {
|
||||
TransactionSigner signer = new TransactionSigner() {
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user